]>
Commit | Line | Data |
---|---|---|
55682965 JB |
1 | /* |
2 | * This is the new netlink-based wireless configuration interface. | |
3 | * | |
026331c4 | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
2740f0cf | 5 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
0c9ca11b | 6 | * Copyright 2015-2016 Intel Deutschland GmbH |
55682965 JB |
7 | */ |
8 | ||
9 | #include <linux/if.h> | |
10 | #include <linux/module.h> | |
11 | #include <linux/err.h> | |
5a0e3ad6 | 12 | #include <linux/slab.h> |
55682965 JB |
13 | #include <linux/list.h> |
14 | #include <linux/if_ether.h> | |
15 | #include <linux/ieee80211.h> | |
16 | #include <linux/nl80211.h> | |
17 | #include <linux/rtnetlink.h> | |
18 | #include <linux/netlink.h> | |
2a519311 | 19 | #include <linux/etherdevice.h> |
463d0183 | 20 | #include <net/net_namespace.h> |
55682965 JB |
21 | #include <net/genetlink.h> |
22 | #include <net/cfg80211.h> | |
463d0183 | 23 | #include <net/sock.h> |
2a0e047e | 24 | #include <net/inet_connection_sock.h> |
55682965 JB |
25 | #include "core.h" |
26 | #include "nl80211.h" | |
b2e1b302 | 27 | #include "reg.h" |
e35e4d28 | 28 | #include "rdev-ops.h" |
55682965 | 29 | |
5fb628e9 JM |
30 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
31 | struct genl_info *info, | |
32 | struct cfg80211_crypto_settings *settings, | |
33 | int cipher_limit); | |
34 | ||
f84f771d | 35 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 | 36 | struct genl_info *info); |
f84f771d | 37 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
38 | struct genl_info *info); |
39 | ||
55682965 JB |
40 | /* the netlink family */ |
41 | static struct genl_family nl80211_fam = { | |
fb4e1568 MH |
42 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
43 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ | |
44 | .hdrsize = 0, /* no private header */ | |
45 | .version = 1, /* no particular meaning now */ | |
55682965 | 46 | .maxattr = NL80211_ATTR_MAX, |
463d0183 | 47 | .netnsok = true, |
4c476991 JB |
48 | .pre_doit = nl80211_pre_doit, |
49 | .post_doit = nl80211_post_doit, | |
55682965 JB |
50 | }; |
51 | ||
2a94fe48 JB |
52 | /* multicast groups */ |
53 | enum nl80211_multicast_groups { | |
54 | NL80211_MCGRP_CONFIG, | |
55 | NL80211_MCGRP_SCAN, | |
56 | NL80211_MCGRP_REGULATORY, | |
57 | NL80211_MCGRP_MLME, | |
567ffc35 | 58 | NL80211_MCGRP_VENDOR, |
2a94fe48 JB |
59 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
60 | }; | |
61 | ||
62 | static const struct genl_multicast_group nl80211_mcgrps[] = { | |
71b836ec JB |
63 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
64 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, | |
65 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, | |
66 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, | |
67 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, | |
2a94fe48 | 68 | #ifdef CONFIG_NL80211_TESTMODE |
71b836ec | 69 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
2a94fe48 JB |
70 | #endif |
71 | }; | |
72 | ||
89a54e48 JB |
73 | /* returns ERR_PTR values */ |
74 | static struct wireless_dev * | |
75 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 76 | { |
89a54e48 JB |
77 | struct cfg80211_registered_device *rdev; |
78 | struct wireless_dev *result = NULL; | |
79 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
80 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
81 | u64 wdev_id; | |
82 | int wiphy_idx = -1; | |
83 | int ifidx = -1; | |
55682965 | 84 | |
5fe231e8 | 85 | ASSERT_RTNL(); |
55682965 | 86 | |
89a54e48 JB |
87 | if (!have_ifidx && !have_wdev_id) |
88 | return ERR_PTR(-EINVAL); | |
55682965 | 89 | |
89a54e48 JB |
90 | if (have_ifidx) |
91 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
92 | if (have_wdev_id) { | |
93 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
94 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
95 | } |
96 | ||
89a54e48 JB |
97 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
98 | struct wireless_dev *wdev; | |
99 | ||
100 | if (wiphy_net(&rdev->wiphy) != netns) | |
101 | continue; | |
102 | ||
103 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
104 | continue; | |
105 | ||
53873f13 | 106 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
89a54e48 JB |
107 | if (have_ifidx && wdev->netdev && |
108 | wdev->netdev->ifindex == ifidx) { | |
109 | result = wdev; | |
110 | break; | |
111 | } | |
112 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
113 | result = wdev; | |
114 | break; | |
115 | } | |
116 | } | |
89a54e48 JB |
117 | |
118 | if (result) | |
119 | break; | |
120 | } | |
121 | ||
122 | if (result) | |
123 | return result; | |
124 | return ERR_PTR(-ENODEV); | |
55682965 JB |
125 | } |
126 | ||
a9455408 | 127 | static struct cfg80211_registered_device * |
878d9ec7 | 128 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 129 | { |
7fee4778 JB |
130 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
131 | struct net_device *netdev; | |
a9455408 | 132 | |
5fe231e8 | 133 | ASSERT_RTNL(); |
a9455408 | 134 | |
878d9ec7 | 135 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
136 | !attrs[NL80211_ATTR_IFINDEX] && |
137 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
138 | return ERR_PTR(-EINVAL); |
139 | ||
878d9ec7 | 140 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 141 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 142 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 143 | |
89a54e48 JB |
144 | if (attrs[NL80211_ATTR_WDEV]) { |
145 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
146 | struct wireless_dev *wdev; | |
147 | bool found = false; | |
148 | ||
149 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
150 | if (tmp) { | |
151 | /* make sure wdev exists */ | |
53873f13 | 152 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { |
89a54e48 JB |
153 | if (wdev->identifier != (u32)wdev_id) |
154 | continue; | |
155 | found = true; | |
156 | break; | |
157 | } | |
89a54e48 JB |
158 | |
159 | if (!found) | |
160 | tmp = NULL; | |
161 | ||
162 | if (rdev && tmp != rdev) | |
163 | return ERR_PTR(-EINVAL); | |
164 | rdev = tmp; | |
165 | } | |
166 | } | |
167 | ||
878d9ec7 JB |
168 | if (attrs[NL80211_ATTR_IFINDEX]) { |
169 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
7a087e74 | 170 | |
7f2b8562 | 171 | netdev = __dev_get_by_index(netns, ifindex); |
7fee4778 JB |
172 | if (netdev) { |
173 | if (netdev->ieee80211_ptr) | |
f26cbf40 ZG |
174 | tmp = wiphy_to_rdev( |
175 | netdev->ieee80211_ptr->wiphy); | |
7fee4778 JB |
176 | else |
177 | tmp = NULL; | |
178 | ||
7fee4778 JB |
179 | /* not wireless device -- return error */ |
180 | if (!tmp) | |
181 | return ERR_PTR(-EINVAL); | |
182 | ||
183 | /* mismatch -- return error */ | |
184 | if (rdev && tmp != rdev) | |
185 | return ERR_PTR(-EINVAL); | |
186 | ||
187 | rdev = tmp; | |
a9455408 | 188 | } |
a9455408 | 189 | } |
a9455408 | 190 | |
4f7eff10 JB |
191 | if (!rdev) |
192 | return ERR_PTR(-ENODEV); | |
a9455408 | 193 | |
4f7eff10 JB |
194 | if (netns != wiphy_net(&rdev->wiphy)) |
195 | return ERR_PTR(-ENODEV); | |
196 | ||
197 | return rdev; | |
a9455408 JB |
198 | } |
199 | ||
200 | /* | |
201 | * This function returns a pointer to the driver | |
202 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
203 | * |
204 | * The result of this can be a PTR_ERR and hence must | |
205 | * be checked with IS_ERR() for errors. | |
206 | */ | |
207 | static struct cfg80211_registered_device * | |
4f7eff10 | 208 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 209 | { |
5fe231e8 | 210 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
211 | } |
212 | ||
55682965 | 213 | /* policy for the attributes */ |
8cd4d456 | 214 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
55682965 JB |
215 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
216 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 217 | .len = 20-1 }, |
31888487 | 218 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 219 | |
72bdcf34 | 220 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 221 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
222 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
223 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
224 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
225 | ||
b9a5f8ca JM |
226 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
227 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
228 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
229 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 230 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
3057dbfd | 231 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
55682965 JB |
232 | |
233 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
234 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
235 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 236 | |
e007b857 EP |
237 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
238 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 239 | |
b9454e83 | 240 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
241 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
242 | .len = WLAN_MAX_KEY_LEN }, | |
243 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
244 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
245 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 246 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 247 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
248 | |
249 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
250 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
251 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
252 | .len = IEEE80211_MAX_DATA_LEN }, | |
253 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
254 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
255 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
256 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
257 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
258 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
259 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 260 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 261 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 262 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 263 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 264 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 265 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 266 | |
b2e1b302 LR |
267 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
268 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
269 | ||
9f1ba906 JM |
270 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
271 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
272 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
273 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
274 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 275 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 276 | |
24bdd9f4 | 277 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 278 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 279 | |
6c739419 | 280 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
281 | |
282 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
283 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
284 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
285 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
286 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
287 | |
288 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
289 | .len = IEEE80211_MAX_SSID_LEN }, | |
290 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
291 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 292 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 293 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 294 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
295 | [NL80211_ATTR_STA_FLAGS2] = { |
296 | .len = sizeof(struct nl80211_sta_flag_update), | |
297 | }, | |
3f77316c | 298 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
299 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
300 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
301 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
302 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
303 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 304 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 305 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
306 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
307 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
308 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
309 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 310 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
311 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
312 | .len = IEEE80211_MAX_DATA_LEN }, | |
313 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 314 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 315 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 316 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 317 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
318 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
319 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 320 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
321 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
322 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 323 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 324 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 325 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 326 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 327 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 328 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 329 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 330 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 331 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
332 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
333 | .len = IEEE80211_MAX_DATA_LEN }, | |
334 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
335 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 336 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 337 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 338 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
339 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
340 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
341 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
342 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
343 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
31fa97c5 | 344 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
e247bd90 | 345 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
346 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
347 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 348 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
349 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
350 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
351 | .len = NL80211_HT_CAPABILITY_LEN | |
352 | }, | |
1d9d9213 | 353 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 354 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 355 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 356 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 357 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
e39e5b5e | 358 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
f461be3e | 359 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
ed473771 | 360 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
53cabad7 JB |
361 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
362 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | |
77765eaf VT |
363 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
364 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
365 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
366 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 367 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
368 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
369 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
370 | .len = NL80211_VHT_CAPABILITY_LEN, | |
371 | }, | |
355199e0 JM |
372 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
373 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
374 | .len = IEEE80211_MAX_DATA_LEN }, | |
5e4b6f56 | 375 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
16ef1fe2 SW |
376 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
377 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | |
378 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | |
9a774c78 AO |
379 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
380 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, | |
c01fc9ad SD |
381 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
382 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, | |
5336fa88 | 383 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
60f4a7b1 | 384 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
ad7e718c JB |
385 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
386 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, | |
387 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, | |
fa9ffc74 KP |
388 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
389 | .len = IEEE80211_QOS_MAP_LEN_MAX }, | |
1df4a510 JM |
390 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
391 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, | |
df942e7b | 392 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
18e5ca65 | 393 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
34d22ce2 | 394 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
bab5ab7d | 395 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
960d01ac JB |
396 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
397 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, | |
398 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, | |
18998c38 | 399 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
ad2b26ab | 400 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
1bdd716c | 401 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
4b681c82 | 402 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
9c748934 | 403 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
05050753 | 404 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
34d50519 | 405 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
38de03d2 | 406 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
17b94247 | 407 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 }, |
c6e6a0c8 AE |
408 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
409 | .len = VHT_MUMIMO_GROUPS_DATA_LEN | |
410 | }, | |
411 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN }, | |
cb3b7d87 AB |
412 | [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 }, |
413 | [NL80211_ATTR_NAN_DUAL] = { .type = NLA_U8 }, | |
55682965 JB |
414 | }; |
415 | ||
e31b8213 | 416 | /* policy for the key attributes */ |
b54452b0 | 417 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 418 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
419 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
420 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 421 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
422 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
423 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 424 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
425 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
426 | }; | |
427 | ||
428 | /* policy for the key default flags */ | |
429 | static const struct nla_policy | |
430 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
431 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
432 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
433 | }; |
434 | ||
ff1b6e69 JB |
435 | /* policy for WoWLAN attributes */ |
436 | static const struct nla_policy | |
437 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
438 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
439 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
440 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
441 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
442 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
443 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
444 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
445 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e | 446 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
8cd4d456 | 447 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
2a0e047e JB |
448 | }; |
449 | ||
450 | static const struct nla_policy | |
451 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
452 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
453 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
454 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
455 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
456 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
457 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
458 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
459 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
460 | }, | |
461 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
462 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
463 | }, | |
464 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
465 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
466 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
467 | }; |
468 | ||
be29b99a AK |
469 | /* policy for coalesce rule attributes */ |
470 | static const struct nla_policy | |
471 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
472 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
473 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
474 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
475 | }; | |
476 | ||
e5497d76 JB |
477 | /* policy for GTK rekey offload attributes */ |
478 | static const struct nla_policy | |
479 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
480 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
481 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
482 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
483 | }; | |
484 | ||
a1f1c21c LC |
485 | static const struct nla_policy |
486 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 487 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 488 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 489 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
490 | }; |
491 | ||
3b06d277 AS |
492 | static const struct nla_policy |
493 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { | |
494 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, | |
495 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, | |
496 | }; | |
497 | ||
38de03d2 AS |
498 | static const struct nla_policy |
499 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { | |
500 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, | |
501 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, | |
502 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { | |
503 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) | |
504 | }, | |
505 | }; | |
506 | ||
97990a06 JB |
507 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
508 | struct netlink_callback *cb, | |
509 | struct cfg80211_registered_device **rdev, | |
510 | struct wireless_dev **wdev) | |
a043897a | 511 | { |
97990a06 | 512 | int err; |
a043897a | 513 | |
97990a06 | 514 | rtnl_lock(); |
a043897a | 515 | |
97990a06 JB |
516 | if (!cb->args[0]) { |
517 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
518 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
519 | nl80211_policy); | |
520 | if (err) | |
521 | goto out_unlock; | |
67748893 | 522 | |
97990a06 JB |
523 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
524 | nl80211_fam.attrbuf); | |
525 | if (IS_ERR(*wdev)) { | |
526 | err = PTR_ERR(*wdev); | |
527 | goto out_unlock; | |
528 | } | |
f26cbf40 | 529 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
530 | /* 0 is the first index - add 1 to parse only once */ |
531 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
532 | cb->args[1] = (*wdev)->identifier; |
533 | } else { | |
c319d50b JB |
534 | /* subtract the 1 again here */ |
535 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 536 | struct wireless_dev *tmp; |
67748893 | 537 | |
97990a06 JB |
538 | if (!wiphy) { |
539 | err = -ENODEV; | |
540 | goto out_unlock; | |
541 | } | |
f26cbf40 | 542 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 543 | *wdev = NULL; |
67748893 | 544 | |
53873f13 | 545 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
97990a06 JB |
546 | if (tmp->identifier == cb->args[1]) { |
547 | *wdev = tmp; | |
548 | break; | |
549 | } | |
550 | } | |
67748893 | 551 | |
97990a06 JB |
552 | if (!*wdev) { |
553 | err = -ENODEV; | |
554 | goto out_unlock; | |
555 | } | |
67748893 JB |
556 | } |
557 | ||
67748893 | 558 | return 0; |
97990a06 | 559 | out_unlock: |
67748893 JB |
560 | rtnl_unlock(); |
561 | return err; | |
562 | } | |
563 | ||
97990a06 | 564 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 565 | { |
67748893 JB |
566 | rtnl_unlock(); |
567 | } | |
568 | ||
f4a11bb0 JB |
569 | /* IE validation */ |
570 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
571 | { | |
572 | const u8 *pos; | |
573 | int len; | |
574 | ||
575 | if (!attr) | |
576 | return true; | |
577 | ||
578 | pos = nla_data(attr); | |
579 | len = nla_len(attr); | |
580 | ||
581 | while (len) { | |
582 | u8 elemlen; | |
583 | ||
584 | if (len < 2) | |
585 | return false; | |
586 | len -= 2; | |
587 | ||
588 | elemlen = pos[1]; | |
589 | if (elemlen > len) | |
590 | return false; | |
591 | ||
592 | len -= elemlen; | |
593 | pos += 2 + elemlen; | |
594 | } | |
595 | ||
596 | return true; | |
597 | } | |
598 | ||
55682965 | 599 | /* message building helper */ |
15e47304 | 600 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
601 | int flags, u8 cmd) |
602 | { | |
603 | /* since there is no private header just add the generic one */ | |
15e47304 | 604 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
605 | } |
606 | ||
5dab3b8a | 607 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
608 | struct ieee80211_channel *chan, |
609 | bool large) | |
5dab3b8a | 610 | { |
ea077c1c RL |
611 | /* Some channels must be completely excluded from the |
612 | * list to protect old user-space tools from breaking | |
613 | */ | |
614 | if (!large && chan->flags & | |
615 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
616 | return 0; | |
617 | ||
9360ffd1 DM |
618 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
619 | chan->center_freq)) | |
620 | goto nla_put_failure; | |
5dab3b8a | 621 | |
9360ffd1 DM |
622 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
623 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
624 | goto nla_put_failure; | |
8fe02e16 LR |
625 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
626 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
627 | goto nla_put_failure; | |
628 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
629 | goto nla_put_failure; | |
630 | } | |
cdc89b97 JB |
631 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
632 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
633 | goto nla_put_failure; | |
634 | if (large) { | |
635 | u32 time; | |
636 | ||
637 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
638 | ||
639 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
640 | chan->dfs_state)) | |
641 | goto nla_put_failure; | |
642 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
643 | time)) | |
644 | goto nla_put_failure; | |
089027e5 JD |
645 | if (nla_put_u32(msg, |
646 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
647 | chan->dfs_cac_ms)) | |
648 | goto nla_put_failure; | |
cdc89b97 JB |
649 | } |
650 | } | |
5dab3b8a | 651 | |
fe1abafd JB |
652 | if (large) { |
653 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
654 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
655 | goto nla_put_failure; | |
656 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
657 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
658 | goto nla_put_failure; | |
659 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
660 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
661 | goto nla_put_failure; | |
662 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
663 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
664 | goto nla_put_failure; | |
570dbde1 DS |
665 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
666 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
667 | goto nla_put_failure; | |
06f207fc AN |
668 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
669 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) | |
570dbde1 | 670 | goto nla_put_failure; |
ea077c1c RL |
671 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
672 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
673 | goto nla_put_failure; | |
674 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
675 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
676 | goto nla_put_failure; | |
fe1abafd JB |
677 | } |
678 | ||
9360ffd1 DM |
679 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
680 | DBM_TO_MBM(chan->max_power))) | |
681 | goto nla_put_failure; | |
5dab3b8a LR |
682 | |
683 | return 0; | |
684 | ||
685 | nla_put_failure: | |
686 | return -ENOBUFS; | |
687 | } | |
688 | ||
55682965 JB |
689 | /* netlink command implementations */ |
690 | ||
b9454e83 JB |
691 | struct key_parse { |
692 | struct key_params p; | |
693 | int idx; | |
e31b8213 | 694 | int type; |
b9454e83 | 695 | bool def, defmgmt; |
dbd2fd65 | 696 | bool def_uni, def_multi; |
b9454e83 JB |
697 | }; |
698 | ||
699 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
700 | { | |
701 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
702 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
703 | nl80211_key_policy); | |
704 | if (err) | |
705 | return err; | |
706 | ||
707 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
708 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
709 | ||
dbd2fd65 JB |
710 | if (k->def) { |
711 | k->def_uni = true; | |
712 | k->def_multi = true; | |
713 | } | |
714 | if (k->defmgmt) | |
715 | k->def_multi = true; | |
716 | ||
b9454e83 JB |
717 | if (tb[NL80211_KEY_IDX]) |
718 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
719 | ||
720 | if (tb[NL80211_KEY_DATA]) { | |
721 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
722 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
723 | } | |
724 | ||
725 | if (tb[NL80211_KEY_SEQ]) { | |
726 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
727 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
728 | } | |
729 | ||
730 | if (tb[NL80211_KEY_CIPHER]) | |
731 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
732 | ||
e31b8213 JB |
733 | if (tb[NL80211_KEY_TYPE]) { |
734 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
735 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
736 | return -EINVAL; | |
737 | } | |
738 | ||
dbd2fd65 JB |
739 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
740 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
7a087e74 | 741 | |
2da8f419 JB |
742 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
743 | tb[NL80211_KEY_DEFAULT_TYPES], | |
744 | nl80211_key_default_policy); | |
dbd2fd65 JB |
745 | if (err) |
746 | return err; | |
747 | ||
748 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
749 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
750 | } | |
751 | ||
b9454e83 JB |
752 | return 0; |
753 | } | |
754 | ||
755 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
756 | { | |
757 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
758 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
759 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
760 | } | |
761 | ||
762 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
763 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
764 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
765 | } | |
766 | ||
767 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
768 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
769 | ||
770 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
771 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
772 | ||
773 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
774 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
775 | ||
dbd2fd65 JB |
776 | if (k->def) { |
777 | k->def_uni = true; | |
778 | k->def_multi = true; | |
779 | } | |
780 | if (k->defmgmt) | |
781 | k->def_multi = true; | |
782 | ||
e31b8213 JB |
783 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
784 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
785 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
786 | return -EINVAL; | |
787 | } | |
788 | ||
dbd2fd65 JB |
789 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
790 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
791 | int err = nla_parse_nested( | |
792 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
793 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
794 | nl80211_key_default_policy); | |
795 | if (err) | |
796 | return err; | |
797 | ||
798 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
799 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
800 | } | |
801 | ||
b9454e83 JB |
802 | return 0; |
803 | } | |
804 | ||
805 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
806 | { | |
807 | int err; | |
808 | ||
809 | memset(k, 0, sizeof(*k)); | |
810 | k->idx = -1; | |
e31b8213 | 811 | k->type = -1; |
b9454e83 JB |
812 | |
813 | if (info->attrs[NL80211_ATTR_KEY]) | |
814 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
815 | else | |
816 | err = nl80211_parse_key_old(info, k); | |
817 | ||
818 | if (err) | |
819 | return err; | |
820 | ||
821 | if (k->def && k->defmgmt) | |
822 | return -EINVAL; | |
823 | ||
dbd2fd65 JB |
824 | if (k->defmgmt) { |
825 | if (k->def_uni || !k->def_multi) | |
826 | return -EINVAL; | |
827 | } | |
828 | ||
b9454e83 JB |
829 | if (k->idx != -1) { |
830 | if (k->defmgmt) { | |
831 | if (k->idx < 4 || k->idx > 5) | |
832 | return -EINVAL; | |
833 | } else if (k->def) { | |
834 | if (k->idx < 0 || k->idx > 3) | |
835 | return -EINVAL; | |
836 | } else { | |
837 | if (k->idx < 0 || k->idx > 5) | |
838 | return -EINVAL; | |
839 | } | |
840 | } | |
841 | ||
842 | return 0; | |
843 | } | |
844 | ||
fffd0934 JB |
845 | static struct cfg80211_cached_keys * |
846 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 847 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
848 | { |
849 | struct key_parse parse; | |
850 | struct nlattr *key; | |
851 | struct cfg80211_cached_keys *result; | |
852 | int rem, err, def = 0; | |
f1c1f17a JB |
853 | bool have_key = false; |
854 | ||
855 | nla_for_each_nested(key, keys, rem) { | |
856 | have_key = true; | |
857 | break; | |
858 | } | |
859 | ||
860 | if (!have_key) | |
861 | return NULL; | |
fffd0934 JB |
862 | |
863 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
864 | if (!result) | |
865 | return ERR_PTR(-ENOMEM); | |
866 | ||
867 | result->def = -1; | |
fffd0934 JB |
868 | |
869 | nla_for_each_nested(key, keys, rem) { | |
870 | memset(&parse, 0, sizeof(parse)); | |
871 | parse.idx = -1; | |
872 | ||
873 | err = nl80211_parse_key_new(key, &parse); | |
874 | if (err) | |
875 | goto error; | |
876 | err = -EINVAL; | |
877 | if (!parse.p.key) | |
878 | goto error; | |
42ee231c | 879 | if (parse.idx < 0 || parse.idx > 3) |
fffd0934 JB |
880 | goto error; |
881 | if (parse.def) { | |
882 | if (def) | |
883 | goto error; | |
884 | def = 1; | |
885 | result->def = parse.idx; | |
dbd2fd65 JB |
886 | if (!parse.def_uni || !parse.def_multi) |
887 | goto error; | |
fffd0934 JB |
888 | } else if (parse.defmgmt) |
889 | goto error; | |
890 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 891 | parse.idx, false, NULL); |
fffd0934 JB |
892 | if (err) |
893 | goto error; | |
386b1f27 JB |
894 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
895 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { | |
896 | err = -EINVAL; | |
897 | goto error; | |
898 | } | |
fffd0934 JB |
899 | result->params[parse.idx].cipher = parse.p.cipher; |
900 | result->params[parse.idx].key_len = parse.p.key_len; | |
901 | result->params[parse.idx].key = result->data[parse.idx]; | |
902 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee | 903 | |
386b1f27 JB |
904 | /* must be WEP key if we got here */ |
905 | if (no_ht) | |
906 | *no_ht = true; | |
fffd0934 JB |
907 | } |
908 | ||
f1c1f17a JB |
909 | if (result->def < 0) { |
910 | err = -EINVAL; | |
911 | goto error; | |
912 | } | |
913 | ||
fffd0934 JB |
914 | return result; |
915 | error: | |
916 | kfree(result); | |
917 | return ERR_PTR(err); | |
918 | } | |
919 | ||
920 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
921 | { | |
922 | ASSERT_WDEV_LOCK(wdev); | |
923 | ||
fffd0934 JB |
924 | switch (wdev->iftype) { |
925 | case NL80211_IFTYPE_AP: | |
926 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 927 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 928 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
929 | break; |
930 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 931 | case NL80211_IFTYPE_STATION: |
074ac8df | 932 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 933 | if (!wdev->current_bss) |
fffd0934 JB |
934 | return -ENOLINK; |
935 | break; | |
de4fcbad | 936 | case NL80211_IFTYPE_UNSPECIFIED: |
6e0bd6c3 | 937 | case NL80211_IFTYPE_OCB: |
de4fcbad | 938 | case NL80211_IFTYPE_MONITOR: |
cb3b7d87 | 939 | case NL80211_IFTYPE_NAN: |
de4fcbad JB |
940 | case NL80211_IFTYPE_P2P_DEVICE: |
941 | case NL80211_IFTYPE_WDS: | |
942 | case NUM_NL80211_IFTYPES: | |
fffd0934 JB |
943 | return -EINVAL; |
944 | } | |
945 | ||
946 | return 0; | |
947 | } | |
948 | ||
664834de JM |
949 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
950 | struct nlattr *tb) | |
951 | { | |
952 | struct ieee80211_channel *chan; | |
953 | ||
954 | if (tb == NULL) | |
955 | return NULL; | |
956 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
957 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
958 | return NULL; | |
959 | return chan; | |
960 | } | |
961 | ||
7527a782 JB |
962 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
963 | { | |
964 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
965 | int i; | |
966 | ||
967 | if (!nl_modes) | |
968 | goto nla_put_failure; | |
969 | ||
970 | i = 0; | |
971 | while (ifmodes) { | |
9360ffd1 DM |
972 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
973 | goto nla_put_failure; | |
7527a782 JB |
974 | ifmodes >>= 1; |
975 | i++; | |
976 | } | |
977 | ||
978 | nla_nest_end(msg, nl_modes); | |
979 | return 0; | |
980 | ||
981 | nla_put_failure: | |
982 | return -ENOBUFS; | |
983 | } | |
984 | ||
985 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
986 | struct sk_buff *msg, |
987 | bool large) | |
7527a782 JB |
988 | { |
989 | struct nlattr *nl_combis; | |
990 | int i, j; | |
991 | ||
992 | nl_combis = nla_nest_start(msg, | |
993 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
994 | if (!nl_combis) | |
995 | goto nla_put_failure; | |
996 | ||
997 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
998 | const struct ieee80211_iface_combination *c; | |
999 | struct nlattr *nl_combi, *nl_limits; | |
1000 | ||
1001 | c = &wiphy->iface_combinations[i]; | |
1002 | ||
1003 | nl_combi = nla_nest_start(msg, i + 1); | |
1004 | if (!nl_combi) | |
1005 | goto nla_put_failure; | |
1006 | ||
1007 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
1008 | if (!nl_limits) | |
1009 | goto nla_put_failure; | |
1010 | ||
1011 | for (j = 0; j < c->n_limits; j++) { | |
1012 | struct nlattr *nl_limit; | |
1013 | ||
1014 | nl_limit = nla_nest_start(msg, j + 1); | |
1015 | if (!nl_limit) | |
1016 | goto nla_put_failure; | |
9360ffd1 DM |
1017 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
1018 | c->limits[j].max)) | |
1019 | goto nla_put_failure; | |
7527a782 JB |
1020 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
1021 | c->limits[j].types)) | |
1022 | goto nla_put_failure; | |
1023 | nla_nest_end(msg, nl_limit); | |
1024 | } | |
1025 | ||
1026 | nla_nest_end(msg, nl_limits); | |
1027 | ||
9360ffd1 DM |
1028 | if (c->beacon_int_infra_match && |
1029 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
1030 | goto nla_put_failure; | |
1031 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
1032 | c->num_different_channels) || | |
1033 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
1034 | c->max_interfaces)) | |
1035 | goto nla_put_failure; | |
cdc89b97 | 1036 | if (large && |
8c48b50a FF |
1037 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
1038 | c->radar_detect_widths) || | |
1039 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
1040 | c->radar_detect_regions))) | |
cdc89b97 | 1041 | goto nla_put_failure; |
7527a782 JB |
1042 | |
1043 | nla_nest_end(msg, nl_combi); | |
1044 | } | |
1045 | ||
1046 | nla_nest_end(msg, nl_combis); | |
1047 | ||
1048 | return 0; | |
1049 | nla_put_failure: | |
1050 | return -ENOBUFS; | |
1051 | } | |
1052 | ||
3713b4e3 | 1053 | #ifdef CONFIG_PM |
b56cf720 JB |
1054 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
1055 | struct sk_buff *msg) | |
1056 | { | |
964dc9e2 | 1057 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
1058 | struct nlattr *nl_tcp; |
1059 | ||
1060 | if (!tcp) | |
1061 | return 0; | |
1062 | ||
1063 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
1064 | if (!nl_tcp) | |
1065 | return -ENOBUFS; | |
1066 | ||
1067 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1068 | tcp->data_payload_max)) | |
1069 | return -ENOBUFS; | |
1070 | ||
1071 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1072 | tcp->data_payload_max)) | |
1073 | return -ENOBUFS; | |
1074 | ||
1075 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1076 | return -ENOBUFS; | |
1077 | ||
1078 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1079 | sizeof(*tcp->tok), tcp->tok)) | |
1080 | return -ENOBUFS; | |
1081 | ||
1082 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1083 | tcp->data_interval_max)) | |
1084 | return -ENOBUFS; | |
1085 | ||
1086 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1087 | tcp->wake_payload_max)) | |
1088 | return -ENOBUFS; | |
1089 | ||
1090 | nla_nest_end(msg, nl_tcp); | |
1091 | return 0; | |
1092 | } | |
1093 | ||
3713b4e3 | 1094 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1095 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1096 | bool large) |
55682965 | 1097 | { |
3713b4e3 | 1098 | struct nlattr *nl_wowlan; |
55682965 | 1099 | |
1b8ec87a | 1100 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1101 | return 0; |
55682965 | 1102 | |
3713b4e3 JB |
1103 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1104 | if (!nl_wowlan) | |
1105 | return -ENOBUFS; | |
9360ffd1 | 1106 | |
1b8ec87a | 1107 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1108 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1109 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1110 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1111 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1112 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1113 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1114 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1115 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1116 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1117 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1118 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1119 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1120 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1121 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1122 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1123 | return -ENOBUFS; | |
9360ffd1 | 1124 | |
1b8ec87a | 1125 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1126 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1127 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1128 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1129 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1130 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1131 | }; |
9360ffd1 | 1132 | |
3713b4e3 JB |
1133 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1134 | sizeof(pat), &pat)) | |
1135 | return -ENOBUFS; | |
1136 | } | |
9360ffd1 | 1137 | |
75453ccb LC |
1138 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
1139 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, | |
1140 | rdev->wiphy.wowlan->max_nd_match_sets)) | |
1141 | return -ENOBUFS; | |
1142 | ||
1b8ec87a | 1143 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1144 | return -ENOBUFS; |
1145 | ||
3713b4e3 | 1146 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1147 | |
3713b4e3 JB |
1148 | return 0; |
1149 | } | |
1150 | #endif | |
9360ffd1 | 1151 | |
be29b99a | 1152 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1153 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1154 | { |
1155 | struct nl80211_coalesce_rule_support rule; | |
1156 | ||
1b8ec87a | 1157 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1158 | return 0; |
1159 | ||
1b8ec87a ZG |
1160 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1161 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1162 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1163 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1164 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1165 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1166 | |
1167 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1168 | return -ENOBUFS; | |
1169 | ||
1170 | return 0; | |
1171 | } | |
1172 | ||
3713b4e3 JB |
1173 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1174 | struct ieee80211_supported_band *sband) | |
1175 | { | |
1176 | struct nlattr *nl_rates, *nl_rate; | |
1177 | struct ieee80211_rate *rate; | |
1178 | int i; | |
87bbbe22 | 1179 | |
3713b4e3 JB |
1180 | /* add HT info */ |
1181 | if (sband->ht_cap.ht_supported && | |
1182 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1183 | sizeof(sband->ht_cap.mcs), | |
1184 | &sband->ht_cap.mcs) || | |
1185 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1186 | sband->ht_cap.cap) || | |
1187 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1188 | sband->ht_cap.ampdu_factor) || | |
1189 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1190 | sband->ht_cap.ampdu_density))) | |
1191 | return -ENOBUFS; | |
afe0cbf8 | 1192 | |
3713b4e3 JB |
1193 | /* add VHT info */ |
1194 | if (sband->vht_cap.vht_supported && | |
1195 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1196 | sizeof(sband->vht_cap.vht_mcs), | |
1197 | &sband->vht_cap.vht_mcs) || | |
1198 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1199 | sband->vht_cap.cap))) | |
1200 | return -ENOBUFS; | |
f59ac048 | 1201 | |
3713b4e3 JB |
1202 | /* add bitrates */ |
1203 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1204 | if (!nl_rates) | |
1205 | return -ENOBUFS; | |
ee688b00 | 1206 | |
3713b4e3 JB |
1207 | for (i = 0; i < sband->n_bitrates; i++) { |
1208 | nl_rate = nla_nest_start(msg, i); | |
1209 | if (!nl_rate) | |
1210 | return -ENOBUFS; | |
ee688b00 | 1211 | |
3713b4e3 JB |
1212 | rate = &sband->bitrates[i]; |
1213 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1214 | rate->bitrate)) | |
1215 | return -ENOBUFS; | |
1216 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1217 | nla_put_flag(msg, | |
1218 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1219 | return -ENOBUFS; | |
ee688b00 | 1220 | |
3713b4e3 JB |
1221 | nla_nest_end(msg, nl_rate); |
1222 | } | |
d51626df | 1223 | |
3713b4e3 | 1224 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1225 | |
3713b4e3 JB |
1226 | return 0; |
1227 | } | |
ee688b00 | 1228 | |
3713b4e3 JB |
1229 | static int |
1230 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1231 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1232 | { | |
1233 | u16 stypes; | |
1234 | struct nlattr *nl_ftypes, *nl_ifs; | |
1235 | enum nl80211_iftype ift; | |
1236 | int i; | |
ee688b00 | 1237 | |
3713b4e3 JB |
1238 | if (!mgmt_stypes) |
1239 | return 0; | |
5dab3b8a | 1240 | |
3713b4e3 JB |
1241 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1242 | if (!nl_ifs) | |
1243 | return -ENOBUFS; | |
e2f367f2 | 1244 | |
3713b4e3 JB |
1245 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1246 | nl_ftypes = nla_nest_start(msg, ift); | |
1247 | if (!nl_ftypes) | |
1248 | return -ENOBUFS; | |
1249 | i = 0; | |
1250 | stypes = mgmt_stypes[ift].tx; | |
1251 | while (stypes) { | |
1252 | if ((stypes & 1) && | |
1253 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1254 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1255 | return -ENOBUFS; | |
1256 | stypes >>= 1; | |
1257 | i++; | |
ee688b00 | 1258 | } |
3713b4e3 JB |
1259 | nla_nest_end(msg, nl_ftypes); |
1260 | } | |
ee688b00 | 1261 | |
3713b4e3 | 1262 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1263 | |
3713b4e3 JB |
1264 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1265 | if (!nl_ifs) | |
1266 | return -ENOBUFS; | |
ee688b00 | 1267 | |
3713b4e3 JB |
1268 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1269 | nl_ftypes = nla_nest_start(msg, ift); | |
1270 | if (!nl_ftypes) | |
1271 | return -ENOBUFS; | |
1272 | i = 0; | |
1273 | stypes = mgmt_stypes[ift].rx; | |
1274 | while (stypes) { | |
1275 | if ((stypes & 1) && | |
1276 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1277 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1278 | return -ENOBUFS; | |
1279 | stypes >>= 1; | |
1280 | i++; | |
1281 | } | |
1282 | nla_nest_end(msg, nl_ftypes); | |
1283 | } | |
1284 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1285 | |
3713b4e3 JB |
1286 | return 0; |
1287 | } | |
ee688b00 | 1288 | |
86e8cf98 JB |
1289 | struct nl80211_dump_wiphy_state { |
1290 | s64 filter_wiphy; | |
1291 | long start; | |
019ae3a9 | 1292 | long split_start, band_start, chan_start, capa_start; |
86e8cf98 JB |
1293 | bool split; |
1294 | }; | |
1295 | ||
1b8ec87a | 1296 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 1297 | enum nl80211_commands cmd, |
3713b4e3 | 1298 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1299 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1300 | { |
1301 | void *hdr; | |
1302 | struct nlattr *nl_bands, *nl_band; | |
1303 | struct nlattr *nl_freqs, *nl_freq; | |
1304 | struct nlattr *nl_cmds; | |
57fbcce3 | 1305 | enum nl80211_band band; |
3713b4e3 JB |
1306 | struct ieee80211_channel *chan; |
1307 | int i; | |
1308 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1309 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1310 | u32 features; |
ee688b00 | 1311 | |
3bb20556 | 1312 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
1313 | if (!hdr) |
1314 | return -ENOBUFS; | |
ee688b00 | 1315 | |
86e8cf98 JB |
1316 | if (WARN_ON(!state)) |
1317 | return -EINVAL; | |
ee688b00 | 1318 | |
1b8ec87a | 1319 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1320 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1321 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1322 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1323 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1324 | goto nla_put_failure; |
1325 | ||
3bb20556 JB |
1326 | if (cmd != NL80211_CMD_NEW_WIPHY) |
1327 | goto finish; | |
1328 | ||
86e8cf98 | 1329 | switch (state->split_start) { |
3713b4e3 JB |
1330 | case 0: |
1331 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1332 | rdev->wiphy.retry_short) || |
3713b4e3 | 1333 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1334 | rdev->wiphy.retry_long) || |
3713b4e3 | 1335 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1336 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1337 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1338 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1339 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1340 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1341 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1342 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1343 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1344 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1345 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1346 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1347 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1348 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1349 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
3b06d277 AS |
1350 | rdev->wiphy.max_match_sets) || |
1351 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, | |
1352 | rdev->wiphy.max_sched_scan_plans) || | |
1353 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, | |
1354 | rdev->wiphy.max_sched_scan_plan_interval) || | |
1355 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, | |
1356 | rdev->wiphy.max_sched_scan_plan_iterations)) | |
9360ffd1 | 1357 | goto nla_put_failure; |
3713b4e3 | 1358 | |
1b8ec87a | 1359 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1360 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1361 | goto nla_put_failure; |
1b8ec87a | 1362 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1363 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1364 | goto nla_put_failure; | |
1b8ec87a | 1365 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1366 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1367 | goto nla_put_failure; | |
1b8ec87a | 1368 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1369 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1370 | goto nla_put_failure; | |
1b8ec87a | 1371 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1372 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1373 | goto nla_put_failure; | |
1b8ec87a | 1374 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1375 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1376 | goto nla_put_failure; |
86e8cf98 JB |
1377 | state->split_start++; |
1378 | if (state->split) | |
3713b4e3 JB |
1379 | break; |
1380 | case 1: | |
1381 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1382 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1383 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1384 | goto nla_put_failure; |
4745fc09 | 1385 | |
3713b4e3 | 1386 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1387 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1388 | goto nla_put_failure; |
b23aa676 | 1389 | |
1b8ec87a | 1390 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1391 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1392 | goto nla_put_failure; |
b23aa676 | 1393 | |
3713b4e3 | 1394 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1395 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1396 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1397 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1398 | goto nla_put_failure; |
b23aa676 | 1399 | |
1b8ec87a | 1400 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1401 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1402 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1403 | goto nla_put_failure; |
8fdc621d | 1404 | |
1b8ec87a ZG |
1405 | if ((rdev->wiphy.available_antennas_tx || |
1406 | rdev->wiphy.available_antennas_rx) && | |
1407 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1408 | u32 tx_ant = 0, rx_ant = 0; |
1409 | int res; | |
7a087e74 | 1410 | |
1b8ec87a | 1411 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1412 | if (!res) { |
1413 | if (nla_put_u32(msg, | |
1414 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1415 | tx_ant) || | |
1416 | nla_put_u32(msg, | |
1417 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1418 | rx_ant)) | |
1419 | goto nla_put_failure; | |
1420 | } | |
1421 | } | |
a293911d | 1422 | |
86e8cf98 JB |
1423 | state->split_start++; |
1424 | if (state->split) | |
3713b4e3 JB |
1425 | break; |
1426 | case 2: | |
1427 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1428 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1429 | goto nla_put_failure; |
86e8cf98 JB |
1430 | state->split_start++; |
1431 | if (state->split) | |
3713b4e3 JB |
1432 | break; |
1433 | case 3: | |
1434 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1435 | if (!nl_bands) | |
1436 | goto nla_put_failure; | |
f7ca38df | 1437 | |
86e8cf98 | 1438 | for (band = state->band_start; |
57fbcce3 | 1439 | band < NUM_NL80211_BANDS; band++) { |
3713b4e3 | 1440 | struct ieee80211_supported_band *sband; |
2e161f78 | 1441 | |
1b8ec87a | 1442 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1443 | |
3713b4e3 JB |
1444 | if (!sband) |
1445 | continue; | |
1446 | ||
1447 | nl_band = nla_nest_start(msg, band); | |
1448 | if (!nl_band) | |
2e161f78 | 1449 | goto nla_put_failure; |
3713b4e3 | 1450 | |
86e8cf98 | 1451 | switch (state->chan_start) { |
3713b4e3 JB |
1452 | case 0: |
1453 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1454 | goto nla_put_failure; |
86e8cf98 JB |
1455 | state->chan_start++; |
1456 | if (state->split) | |
3713b4e3 JB |
1457 | break; |
1458 | default: | |
1459 | /* add frequencies */ | |
1460 | nl_freqs = nla_nest_start( | |
1461 | msg, NL80211_BAND_ATTR_FREQS); | |
1462 | if (!nl_freqs) | |
1463 | goto nla_put_failure; | |
1464 | ||
86e8cf98 | 1465 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1466 | i < sband->n_channels; |
1467 | i++) { | |
1468 | nl_freq = nla_nest_start(msg, i); | |
1469 | if (!nl_freq) | |
1470 | goto nla_put_failure; | |
1471 | ||
1472 | chan = &sband->channels[i]; | |
1473 | ||
86e8cf98 JB |
1474 | if (nl80211_msg_put_channel( |
1475 | msg, chan, | |
1476 | state->split)) | |
3713b4e3 JB |
1477 | goto nla_put_failure; |
1478 | ||
1479 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1480 | if (state->split) |
3713b4e3 JB |
1481 | break; |
1482 | } | |
1483 | if (i < sband->n_channels) | |
86e8cf98 | 1484 | state->chan_start = i + 2; |
3713b4e3 | 1485 | else |
86e8cf98 | 1486 | state->chan_start = 0; |
3713b4e3 JB |
1487 | nla_nest_end(msg, nl_freqs); |
1488 | } | |
1489 | ||
1490 | nla_nest_end(msg, nl_band); | |
1491 | ||
86e8cf98 | 1492 | if (state->split) { |
3713b4e3 | 1493 | /* start again here */ |
86e8cf98 | 1494 | if (state->chan_start) |
3713b4e3 JB |
1495 | band--; |
1496 | break; | |
2e161f78 | 1497 | } |
2e161f78 | 1498 | } |
3713b4e3 | 1499 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1500 | |
57fbcce3 | 1501 | if (band < NUM_NL80211_BANDS) |
86e8cf98 | 1502 | state->band_start = band + 1; |
3713b4e3 | 1503 | else |
86e8cf98 | 1504 | state->band_start = 0; |
74b70a4e | 1505 | |
3713b4e3 | 1506 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1507 | if (state->band_start == 0 && state->chan_start == 0) |
1508 | state->split_start++; | |
1509 | if (state->split) | |
3713b4e3 JB |
1510 | break; |
1511 | case 4: | |
1512 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1513 | if (!nl_cmds) | |
2e161f78 JB |
1514 | goto nla_put_failure; |
1515 | ||
3713b4e3 JB |
1516 | i = 0; |
1517 | #define CMD(op, n) \ | |
1518 | do { \ | |
1b8ec87a | 1519 | if (rdev->ops->op) { \ |
3713b4e3 JB |
1520 | i++; \ |
1521 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1522 | goto nla_put_failure; \ | |
1523 | } \ | |
1524 | } while (0) | |
1525 | ||
1526 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1527 | CMD(change_virtual_intf, SET_INTERFACE); | |
1528 | CMD(add_key, NEW_KEY); | |
1529 | CMD(start_ap, START_AP); | |
1530 | CMD(add_station, NEW_STATION); | |
1531 | CMD(add_mpath, NEW_MPATH); | |
1532 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1533 | CMD(change_bss, SET_BSS); | |
1534 | CMD(auth, AUTHENTICATE); | |
1535 | CMD(assoc, ASSOCIATE); | |
1536 | CMD(deauth, DEAUTHENTICATE); | |
1537 | CMD(disassoc, DISASSOCIATE); | |
1538 | CMD(join_ibss, JOIN_IBSS); | |
1539 | CMD(join_mesh, JOIN_MESH); | |
1540 | CMD(set_pmksa, SET_PMKSA); | |
1541 | CMD(del_pmksa, DEL_PMKSA); | |
1542 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1b8ec87a | 1543 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
3713b4e3 JB |
1544 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
1545 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1546 | CMD(mgmt_tx, FRAME); | |
1547 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1b8ec87a | 1548 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
3713b4e3 JB |
1549 | i++; |
1550 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1551 | goto nla_put_failure; |
2e161f78 | 1552 | } |
1b8ec87a ZG |
1553 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
1554 | rdev->ops->join_mesh) { | |
3713b4e3 JB |
1555 | i++; |
1556 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1557 | goto nla_put_failure; | |
1558 | } | |
1559 | CMD(set_wds_peer, SET_WDS_PEER); | |
1b8ec87a | 1560 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
3713b4e3 JB |
1561 | CMD(tdls_mgmt, TDLS_MGMT); |
1562 | CMD(tdls_oper, TDLS_OPER); | |
1563 | } | |
1b8ec87a | 1564 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
3713b4e3 JB |
1565 | CMD(sched_scan_start, START_SCHED_SCAN); |
1566 | CMD(probe_client, PROBE_CLIENT); | |
1567 | CMD(set_noack_map, SET_NOACK_MAP); | |
1b8ec87a | 1568 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
3713b4e3 JB |
1569 | i++; |
1570 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1571 | goto nla_put_failure; | |
1572 | } | |
1573 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1574 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
02df00eb JB |
1575 | #ifdef CONFIG_NL80211_TESTMODE |
1576 | CMD(testmode_cmd, TESTMODE); | |
1577 | #endif | |
86e8cf98 | 1578 | if (state->split) { |
5de17984 AS |
1579 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1580 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 1581 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 1582 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 1583 | CMD(set_qos_map, SET_QOS_MAP); |
723e73ac JB |
1584 | if (rdev->wiphy.features & |
1585 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | |
960d01ac | 1586 | CMD(add_tx_ts, ADD_TX_TS); |
5de17984 | 1587 | } |
02df00eb | 1588 | /* add into the if now */ |
3713b4e3 | 1589 | #undef CMD |
ff1b6e69 | 1590 | |
1b8ec87a | 1591 | if (rdev->ops->connect || rdev->ops->auth) { |
3713b4e3 JB |
1592 | i++; |
1593 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1594 | goto nla_put_failure; |
ff1b6e69 JB |
1595 | } |
1596 | ||
1b8ec87a | 1597 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
3713b4e3 JB |
1598 | i++; |
1599 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1600 | goto nla_put_failure; | |
1601 | } | |
1602 | ||
1603 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1604 | state->split_start++; |
1605 | if (state->split) | |
3713b4e3 JB |
1606 | break; |
1607 | case 5: | |
1b8ec87a ZG |
1608 | if (rdev->ops->remain_on_channel && |
1609 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
1610 | nla_put_u32(msg, |
1611 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 1612 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
1613 | goto nla_put_failure; |
1614 | ||
1b8ec87a | 1615 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
1616 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
1617 | goto nla_put_failure; | |
1618 | ||
1619 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1620 | goto nla_put_failure; | |
86e8cf98 JB |
1621 | state->split_start++; |
1622 | if (state->split) | |
3713b4e3 JB |
1623 | break; |
1624 | case 6: | |
1625 | #ifdef CONFIG_PM | |
1b8ec87a | 1626 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 1627 | goto nla_put_failure; |
86e8cf98 JB |
1628 | state->split_start++; |
1629 | if (state->split) | |
3713b4e3 JB |
1630 | break; |
1631 | #else | |
86e8cf98 | 1632 | state->split_start++; |
dfb89c56 | 1633 | #endif |
3713b4e3 JB |
1634 | case 7: |
1635 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 1636 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 1637 | goto nla_put_failure; |
ff1b6e69 | 1638 | |
1b8ec87a | 1639 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 1640 | state->split)) |
3713b4e3 | 1641 | goto nla_put_failure; |
7527a782 | 1642 | |
86e8cf98 JB |
1643 | state->split_start++; |
1644 | if (state->split) | |
3713b4e3 JB |
1645 | break; |
1646 | case 8: | |
1b8ec87a | 1647 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 1648 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 1649 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 1650 | goto nla_put_failure; |
7527a782 | 1651 | |
1b8ec87a | 1652 | features = rdev->wiphy.features; |
fe1abafd JB |
1653 | /* |
1654 | * We can only add the per-channel limit information if the | |
1655 | * dump is split, otherwise it makes it too big. Therefore | |
1656 | * only advertise it in that case. | |
1657 | */ | |
86e8cf98 | 1658 | if (state->split) |
fe1abafd JB |
1659 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1660 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1661 | goto nla_put_failure; |
562a7480 | 1662 | |
1b8ec87a | 1663 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 1664 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
1665 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
1666 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 1667 | goto nla_put_failure; |
1f074bd8 | 1668 | |
1b8ec87a ZG |
1669 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1670 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 1671 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 1672 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 1673 | goto nla_put_failure; |
7e7c8926 | 1674 | |
3713b4e3 JB |
1675 | /* |
1676 | * Any information below this point is only available to | |
1677 | * applications that can deal with it being split. This | |
1678 | * helps ensure that newly added capabilities don't break | |
1679 | * older tools by overrunning their buffers. | |
1680 | * | |
1681 | * We still increment split_start so that in the split | |
1682 | * case we'll continue with more data in the next round, | |
1683 | * but break unconditionally so unsplit data stops here. | |
1684 | */ | |
86e8cf98 | 1685 | state->split_start++; |
3713b4e3 JB |
1686 | break; |
1687 | case 9: | |
1b8ec87a | 1688 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 1689 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
1690 | rdev->wiphy.extended_capabilities_len, |
1691 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 1692 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
1693 | rdev->wiphy.extended_capabilities_len, |
1694 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 1695 | goto nla_put_failure; |
a50df0c4 | 1696 | |
1b8ec87a | 1697 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 1698 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
1699 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
1700 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
1701 | goto nla_put_failure; |
1702 | ||
be29b99a AK |
1703 | state->split_start++; |
1704 | break; | |
1705 | case 10: | |
1b8ec87a | 1706 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
1707 | goto nla_put_failure; |
1708 | ||
1b8ec87a | 1709 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
1710 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
1711 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1712 | goto nla_put_failure; | |
b43504cf | 1713 | |
1b8ec87a | 1714 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 1715 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 1716 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
1717 | goto nla_put_failure; |
1718 | ||
ad7e718c JB |
1719 | state->split_start++; |
1720 | break; | |
1721 | case 11: | |
1b8ec87a | 1722 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
1723 | const struct nl80211_vendor_cmd_info *info; |
1724 | struct nlattr *nested; | |
1725 | ||
1726 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1727 | if (!nested) | |
1728 | goto nla_put_failure; | |
1729 | ||
1b8ec87a ZG |
1730 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
1731 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
1732 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1733 | goto nla_put_failure; | |
1734 | } | |
1735 | nla_nest_end(msg, nested); | |
1736 | } | |
1737 | ||
1b8ec87a | 1738 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
1739 | const struct nl80211_vendor_cmd_info *info; |
1740 | struct nlattr *nested; | |
ad7e718c | 1741 | |
567ffc35 JB |
1742 | nested = nla_nest_start(msg, |
1743 | NL80211_ATTR_VENDOR_EVENTS); | |
1744 | if (!nested) | |
ad7e718c | 1745 | goto nla_put_failure; |
567ffc35 | 1746 | |
1b8ec87a ZG |
1747 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
1748 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
1749 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1750 | goto nla_put_failure; | |
1751 | } | |
1752 | nla_nest_end(msg, nested); | |
1753 | } | |
9a774c78 AO |
1754 | state->split_start++; |
1755 | break; | |
1756 | case 12: | |
1757 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
1758 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
1759 | rdev->wiphy.max_num_csa_counters)) | |
1760 | goto nla_put_failure; | |
01e0daa4 | 1761 | |
1bdd716c AN |
1762 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
1763 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
1764 | goto nla_put_failure; | |
1765 | ||
d75bb06b GKS |
1766 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
1767 | sizeof(rdev->wiphy.ext_features), | |
1768 | rdev->wiphy.ext_features)) | |
1769 | goto nla_put_failure; | |
1770 | ||
38de03d2 AS |
1771 | if (rdev->wiphy.bss_select_support) { |
1772 | struct nlattr *nested; | |
1773 | u32 bss_select_support = rdev->wiphy.bss_select_support; | |
1774 | ||
1775 | nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); | |
1776 | if (!nested) | |
1777 | goto nla_put_failure; | |
1778 | ||
1779 | i = 0; | |
1780 | while (bss_select_support) { | |
1781 | if ((bss_select_support & 1) && | |
1782 | nla_put_flag(msg, i)) | |
1783 | goto nla_put_failure; | |
1784 | i++; | |
1785 | bss_select_support >>= 1; | |
1786 | } | |
1787 | nla_nest_end(msg, nested); | |
1788 | } | |
1789 | ||
019ae3a9 KV |
1790 | state->split_start++; |
1791 | break; | |
1792 | case 13: | |
1793 | if (rdev->wiphy.num_iftype_ext_capab && | |
1794 | rdev->wiphy.iftype_ext_capab) { | |
1795 | struct nlattr *nested_ext_capab, *nested; | |
1796 | ||
1797 | nested = nla_nest_start(msg, | |
1798 | NL80211_ATTR_IFTYPE_EXT_CAPA); | |
1799 | if (!nested) | |
1800 | goto nla_put_failure; | |
1801 | ||
1802 | for (i = state->capa_start; | |
1803 | i < rdev->wiphy.num_iftype_ext_capab; i++) { | |
1804 | const struct wiphy_iftype_ext_capab *capab; | |
1805 | ||
1806 | capab = &rdev->wiphy.iftype_ext_capab[i]; | |
1807 | ||
1808 | nested_ext_capab = nla_nest_start(msg, i); | |
1809 | if (!nested_ext_capab || | |
1810 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, | |
1811 | capab->iftype) || | |
1812 | nla_put(msg, NL80211_ATTR_EXT_CAPA, | |
1813 | capab->extended_capabilities_len, | |
1814 | capab->extended_capabilities) || | |
1815 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | |
1816 | capab->extended_capabilities_len, | |
1817 | capab->extended_capabilities_mask)) | |
1818 | goto nla_put_failure; | |
1819 | ||
1820 | nla_nest_end(msg, nested_ext_capab); | |
1821 | if (state->split) | |
1822 | break; | |
1823 | } | |
1824 | nla_nest_end(msg, nested); | |
1825 | if (i < rdev->wiphy.num_iftype_ext_capab) { | |
1826 | state->capa_start = i + 1; | |
1827 | break; | |
1828 | } | |
1829 | } | |
1830 | ||
3713b4e3 | 1831 | /* done */ |
86e8cf98 | 1832 | state->split_start = 0; |
3713b4e3 JB |
1833 | break; |
1834 | } | |
3bb20556 | 1835 | finish: |
053c095a JB |
1836 | genlmsg_end(msg, hdr); |
1837 | return 0; | |
55682965 JB |
1838 | |
1839 | nla_put_failure: | |
bc3ed28c TG |
1840 | genlmsg_cancel(msg, hdr); |
1841 | return -EMSGSIZE; | |
55682965 JB |
1842 | } |
1843 | ||
86e8cf98 JB |
1844 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1845 | struct netlink_callback *cb, | |
1846 | struct nl80211_dump_wiphy_state *state) | |
1847 | { | |
1848 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1849 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1850 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1851 | /* ignore parse errors for backward compatibility */ | |
1852 | if (ret) | |
1853 | return 0; | |
1854 | ||
1855 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1856 | if (tb[NL80211_ATTR_WIPHY]) | |
1857 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1858 | if (tb[NL80211_ATTR_WDEV]) | |
1859 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1860 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1861 | struct net_device *netdev; | |
1862 | struct cfg80211_registered_device *rdev; | |
1863 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1864 | ||
7f2b8562 | 1865 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1866 | if (!netdev) |
1867 | return -ENODEV; | |
1868 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1869 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1870 | netdev->ieee80211_ptr->wiphy); |
1871 | state->filter_wiphy = rdev->wiphy_idx; | |
1872 | } | |
86e8cf98 JB |
1873 | } |
1874 | ||
1875 | return 0; | |
1876 | } | |
1877 | ||
55682965 JB |
1878 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1879 | { | |
645e77de | 1880 | int idx = 0, ret; |
86e8cf98 | 1881 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1882 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1883 | |
5fe231e8 | 1884 | rtnl_lock(); |
86e8cf98 JB |
1885 | if (!state) { |
1886 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1887 | if (!state) { |
1888 | rtnl_unlock(); | |
86e8cf98 | 1889 | return -ENOMEM; |
3713b4e3 | 1890 | } |
86e8cf98 JB |
1891 | state->filter_wiphy = -1; |
1892 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1893 | if (ret) { | |
1894 | kfree(state); | |
1895 | rtnl_unlock(); | |
1896 | return ret; | |
3713b4e3 | 1897 | } |
86e8cf98 | 1898 | cb->args[0] = (long)state; |
3713b4e3 JB |
1899 | } |
1900 | ||
1b8ec87a ZG |
1901 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1902 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1903 | continue; |
86e8cf98 | 1904 | if (++idx <= state->start) |
55682965 | 1905 | continue; |
86e8cf98 | 1906 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1907 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1908 | continue; |
1909 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1910 | do { | |
3bb20556 JB |
1911 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
1912 | skb, | |
3713b4e3 JB |
1913 | NETLINK_CB(cb->skb).portid, |
1914 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1915 | NLM_F_MULTI, state); |
3713b4e3 JB |
1916 | if (ret < 0) { |
1917 | /* | |
1918 | * If sending the wiphy data didn't fit (ENOBUFS | |
1919 | * or EMSGSIZE returned), this SKB is still | |
1920 | * empty (so it's not too big because another | |
1921 | * wiphy dataset is already in the skb) and | |
1922 | * we've not tried to adjust the dump allocation | |
1923 | * yet ... then adjust the alloc size to be | |
1924 | * bigger, and return 1 but with the empty skb. | |
1925 | * This results in an empty message being RX'ed | |
1926 | * in userspace, but that is ignored. | |
1927 | * | |
1928 | * We can then retry with the larger buffer. | |
1929 | */ | |
1930 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1931 | !skb->len && !state->split && |
3713b4e3 JB |
1932 | cb->min_dump_alloc < 4096) { |
1933 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1934 | state->split_start = 0; |
d98cae64 | 1935 | rtnl_unlock(); |
3713b4e3 JB |
1936 | return 1; |
1937 | } | |
1938 | idx--; | |
1939 | break; | |
645e77de | 1940 | } |
86e8cf98 | 1941 | } while (state->split_start > 0); |
3713b4e3 | 1942 | break; |
55682965 | 1943 | } |
5fe231e8 | 1944 | rtnl_unlock(); |
55682965 | 1945 | |
86e8cf98 | 1946 | state->start = idx; |
55682965 JB |
1947 | |
1948 | return skb->len; | |
1949 | } | |
1950 | ||
86e8cf98 JB |
1951 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1952 | { | |
1953 | kfree((void *)cb->args[0]); | |
1954 | return 0; | |
1955 | } | |
1956 | ||
55682965 JB |
1957 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1958 | { | |
1959 | struct sk_buff *msg; | |
1b8ec87a | 1960 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 1961 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1962 | |
645e77de | 1963 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1964 | if (!msg) |
4c476991 | 1965 | return -ENOMEM; |
55682965 | 1966 | |
3bb20556 JB |
1967 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
1968 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 1969 | &state) < 0) { |
4c476991 JB |
1970 | nlmsg_free(msg); |
1971 | return -ENOBUFS; | |
1972 | } | |
55682965 | 1973 | |
134e6375 | 1974 | return genlmsg_reply(msg, info); |
55682965 JB |
1975 | } |
1976 | ||
31888487 JM |
1977 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1978 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1979 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1980 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1981 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1982 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1983 | }; | |
1984 | ||
1985 | static int parse_txq_params(struct nlattr *tb[], | |
1986 | struct ieee80211_txq_params *txq_params) | |
1987 | { | |
a3304b0a | 1988 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1989 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1990 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1991 | return -EINVAL; | |
1992 | ||
a3304b0a | 1993 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1994 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1995 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1996 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1997 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1998 | ||
a3304b0a JB |
1999 | if (txq_params->ac >= NL80211_NUM_ACS) |
2000 | return -EINVAL; | |
2001 | ||
31888487 JM |
2002 | return 0; |
2003 | } | |
2004 | ||
f444de05 JB |
2005 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
2006 | { | |
2007 | /* | |
cc1d2806 JB |
2008 | * You can only set the channel explicitly for WDS interfaces, |
2009 | * all others have their channel managed via their respective | |
2010 | * "establish a connection" command (connect, join, ...) | |
2011 | * | |
2012 | * For AP/GO and mesh mode, the channel can be set with the | |
2013 | * channel userspace API, but is only stored and passed to the | |
2014 | * low-level driver when the AP starts or the mesh is joined. | |
2015 | * This is for backward compatibility, userspace can also give | |
2016 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
2017 | * |
2018 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
2019 | * whatever else is going on, so they have their own special |
2020 | * operation to set the monitor channel if possible. | |
f444de05 JB |
2021 | */ |
2022 | return !wdev || | |
2023 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 2024 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
2025 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
2026 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
2027 | } |
2028 | ||
683b6d3b JB |
2029 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
2030 | struct genl_info *info, | |
2031 | struct cfg80211_chan_def *chandef) | |
2032 | { | |
dbeca2ea | 2033 | u32 control_freq; |
683b6d3b JB |
2034 | |
2035 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
2036 | return -EINVAL; | |
2037 | ||
2038 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
2039 | ||
2040 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
2041 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
2042 | chandef->center_freq1 = control_freq; | |
2043 | chandef->center_freq2 = 0; | |
683b6d3b JB |
2044 | |
2045 | /* Primary channel not allowed */ | |
2046 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
2047 | return -EINVAL; | |
2048 | ||
3d9d1d66 JB |
2049 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
2050 | enum nl80211_channel_type chantype; | |
2051 | ||
2052 | chantype = nla_get_u32( | |
2053 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
2054 | ||
2055 | switch (chantype) { | |
2056 | case NL80211_CHAN_NO_HT: | |
2057 | case NL80211_CHAN_HT20: | |
2058 | case NL80211_CHAN_HT40PLUS: | |
2059 | case NL80211_CHAN_HT40MINUS: | |
2060 | cfg80211_chandef_create(chandef, chandef->chan, | |
2061 | chantype); | |
2062 | break; | |
2063 | default: | |
2064 | return -EINVAL; | |
2065 | } | |
2066 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
2067 | chandef->width = | |
2068 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
2069 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
2070 | chandef->center_freq1 = | |
2071 | nla_get_u32( | |
2072 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
2073 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
2074 | chandef->center_freq2 = | |
2075 | nla_get_u32( | |
2076 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
2077 | } | |
2078 | ||
9f5e8f6e | 2079 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
2080 | return -EINVAL; |
2081 | ||
9f5e8f6e JB |
2082 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
2083 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
2084 | return -EINVAL; |
2085 | ||
2f301ab2 SW |
2086 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
2087 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
2088 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
2089 | return -EINVAL; | |
2090 | ||
683b6d3b JB |
2091 | return 0; |
2092 | } | |
2093 | ||
f444de05 | 2094 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 2095 | struct net_device *dev, |
f444de05 JB |
2096 | struct genl_info *info) |
2097 | { | |
683b6d3b | 2098 | struct cfg80211_chan_def chandef; |
f444de05 | 2099 | int result; |
e8c9bd5b | 2100 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 2101 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 2102 | |
e16821bc JM |
2103 | if (dev) |
2104 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
2105 | if (!nl80211_can_set_dev_channel(wdev)) |
2106 | return -EOPNOTSUPP; | |
e16821bc JM |
2107 | if (wdev) |
2108 | iftype = wdev->iftype; | |
f444de05 | 2109 | |
683b6d3b JB |
2110 | result = nl80211_parse_chandef(rdev, info, &chandef); |
2111 | if (result) | |
2112 | return result; | |
f444de05 | 2113 | |
e8c9bd5b | 2114 | switch (iftype) { |
aa430da4 JB |
2115 | case NL80211_IFTYPE_AP: |
2116 | case NL80211_IFTYPE_P2P_GO: | |
923b352f AN |
2117 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
2118 | iftype)) { | |
aa430da4 JB |
2119 | result = -EINVAL; |
2120 | break; | |
2121 | } | |
e16821bc JM |
2122 | if (wdev->beacon_interval) { |
2123 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
2124 | !(rdev->wiphy.features & | |
2125 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
2126 | result = -EBUSY; | |
2127 | break; | |
2128 | } | |
2129 | ||
2130 | /* Only allow dynamic channel width changes */ | |
2131 | if (chandef.chan != wdev->preset_chandef.chan) { | |
2132 | result = -EBUSY; | |
2133 | break; | |
2134 | } | |
2135 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
2136 | if (result) | |
2137 | break; | |
2138 | } | |
683b6d3b | 2139 | wdev->preset_chandef = chandef; |
aa430da4 JB |
2140 | result = 0; |
2141 | break; | |
cc1d2806 | 2142 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 2143 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 2144 | break; |
e8c9bd5b | 2145 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 2146 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 2147 | break; |
aa430da4 | 2148 | default: |
e8c9bd5b | 2149 | result = -EINVAL; |
f444de05 | 2150 | } |
f444de05 JB |
2151 | |
2152 | return result; | |
2153 | } | |
2154 | ||
2155 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2156 | { | |
4c476991 JB |
2157 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2158 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2159 | |
e16821bc | 2160 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2161 | } |
2162 | ||
e8347eba BJ |
2163 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2164 | { | |
43b19952 JB |
2165 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2166 | struct net_device *dev = info->user_ptr[1]; | |
2167 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2168 | const u8 *bssid; |
e8347eba BJ |
2169 | |
2170 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2171 | return -EINVAL; | |
2172 | ||
43b19952 JB |
2173 | if (netif_running(dev)) |
2174 | return -EBUSY; | |
e8347eba | 2175 | |
43b19952 JB |
2176 | if (!rdev->ops->set_wds_peer) |
2177 | return -EOPNOTSUPP; | |
e8347eba | 2178 | |
43b19952 JB |
2179 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2180 | return -EOPNOTSUPP; | |
e8347eba BJ |
2181 | |
2182 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2183 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2184 | } |
2185 | ||
55682965 JB |
2186 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2187 | { | |
2188 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2189 | struct net_device *netdev = NULL; |
2190 | struct wireless_dev *wdev; | |
a1e567c8 | 2191 | int result = 0, rem_txq_params = 0; |
31888487 | 2192 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2193 | u32 changed; |
2194 | u8 retry_short = 0, retry_long = 0; | |
2195 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2196 | u8 coverage_class = 0; |
55682965 | 2197 | |
5fe231e8 JB |
2198 | ASSERT_RTNL(); |
2199 | ||
f444de05 JB |
2200 | /* |
2201 | * Try to find the wiphy and netdev. Normally this | |
2202 | * function shouldn't need the netdev, but this is | |
2203 | * done for backward compatibility -- previously | |
2204 | * setting the channel was done per wiphy, but now | |
2205 | * it is per netdev. Previous userland like hostapd | |
2206 | * also passed a netdev to set_wiphy, so that it is | |
2207 | * possible to let that go to the right netdev! | |
2208 | */ | |
4bbf4d56 | 2209 | |
f444de05 JB |
2210 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2211 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2212 | ||
7f2b8562 | 2213 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2214 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2215 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2216 | else |
f444de05 | 2217 | netdev = NULL; |
4bbf4d56 JB |
2218 | } |
2219 | ||
f444de05 | 2220 | if (!netdev) { |
878d9ec7 JB |
2221 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2222 | info->attrs); | |
5fe231e8 | 2223 | if (IS_ERR(rdev)) |
4c476991 | 2224 | return PTR_ERR(rdev); |
f444de05 JB |
2225 | wdev = NULL; |
2226 | netdev = NULL; | |
2227 | result = 0; | |
71fe96bf | 2228 | } else |
f444de05 | 2229 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2230 | |
2231 | /* | |
2232 | * end workaround code, by now the rdev is available | |
2233 | * and locked, and wdev may or may not be NULL. | |
2234 | */ | |
4bbf4d56 JB |
2235 | |
2236 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2237 | result = cfg80211_dev_rename( |
2238 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2239 | |
4bbf4d56 | 2240 | if (result) |
7f2b8562 | 2241 | return result; |
31888487 JM |
2242 | |
2243 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2244 | struct ieee80211_txq_params txq_params; | |
2245 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2246 | ||
7f2b8562 YX |
2247 | if (!rdev->ops->set_txq_params) |
2248 | return -EOPNOTSUPP; | |
31888487 | 2249 | |
7f2b8562 YX |
2250 | if (!netdev) |
2251 | return -EINVAL; | |
f70f01c2 | 2252 | |
133a3ff2 | 2253 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2254 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2255 | return -EINVAL; | |
133a3ff2 | 2256 | |
7f2b8562 YX |
2257 | if (!netif_running(netdev)) |
2258 | return -ENETDOWN; | |
2b5f8b0b | 2259 | |
31888487 JM |
2260 | nla_for_each_nested(nl_txq_params, |
2261 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2262 | rem_txq_params) { | |
ae811e21 JB |
2263 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2264 | nla_data(nl_txq_params), | |
2265 | nla_len(nl_txq_params), | |
2266 | txq_params_policy); | |
2267 | if (result) | |
2268 | return result; | |
31888487 JM |
2269 | result = parse_txq_params(tb, &txq_params); |
2270 | if (result) | |
7f2b8562 | 2271 | return result; |
31888487 | 2272 | |
e35e4d28 HG |
2273 | result = rdev_set_txq_params(rdev, netdev, |
2274 | &txq_params); | |
31888487 | 2275 | if (result) |
7f2b8562 | 2276 | return result; |
31888487 JM |
2277 | } |
2278 | } | |
55682965 | 2279 | |
72bdcf34 | 2280 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2281 | result = __nl80211_set_channel( |
2282 | rdev, | |
2283 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2284 | info); | |
72bdcf34 | 2285 | if (result) |
7f2b8562 | 2286 | return result; |
72bdcf34 JM |
2287 | } |
2288 | ||
98d2ff8b | 2289 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2290 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2291 | enum nl80211_tx_power_setting type; |
2292 | int idx, mbm = 0; | |
2293 | ||
c8442118 JB |
2294 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2295 | txp_wdev = NULL; | |
2296 | ||
7f2b8562 YX |
2297 | if (!rdev->ops->set_tx_power) |
2298 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2299 | |
2300 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2301 | type = nla_get_u32(info->attrs[idx]); | |
2302 | ||
2303 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2304 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2305 | return -EINVAL; | |
98d2ff8b JO |
2306 | |
2307 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2308 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2309 | mbm = nla_get_u32(info->attrs[idx]); | |
2310 | } | |
2311 | ||
c8442118 | 2312 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2313 | if (result) |
7f2b8562 | 2314 | return result; |
98d2ff8b JO |
2315 | } |
2316 | ||
afe0cbf8 BR |
2317 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2318 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2319 | u32 tx_ant, rx_ant; | |
7a087e74 | 2320 | |
7f531e03 BR |
2321 | if ((!rdev->wiphy.available_antennas_tx && |
2322 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2323 | !rdev->ops->set_antenna) |
2324 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2325 | |
2326 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2327 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2328 | ||
a7ffac95 | 2329 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2330 | * available antenna masks, except for the "all" mask */ |
2331 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2332 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2333 | return -EINVAL; | |
a7ffac95 | 2334 | |
7f531e03 BR |
2335 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2336 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2337 | |
e35e4d28 | 2338 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2339 | if (result) |
7f2b8562 | 2340 | return result; |
afe0cbf8 BR |
2341 | } |
2342 | ||
b9a5f8ca JM |
2343 | changed = 0; |
2344 | ||
2345 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2346 | retry_short = nla_get_u8( | |
2347 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2348 | if (retry_short == 0) |
2349 | return -EINVAL; | |
2350 | ||
b9a5f8ca JM |
2351 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2352 | } | |
2353 | ||
2354 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2355 | retry_long = nla_get_u8( | |
2356 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2357 | if (retry_long == 0) |
2358 | return -EINVAL; | |
2359 | ||
b9a5f8ca JM |
2360 | changed |= WIPHY_PARAM_RETRY_LONG; |
2361 | } | |
2362 | ||
2363 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2364 | frag_threshold = nla_get_u32( | |
2365 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2366 | if (frag_threshold < 256) |
2367 | return -EINVAL; | |
2368 | ||
b9a5f8ca JM |
2369 | if (frag_threshold != (u32) -1) { |
2370 | /* | |
2371 | * Fragments (apart from the last one) are required to | |
2372 | * have even length. Make the fragmentation code | |
2373 | * simpler by stripping LSB should someone try to use | |
2374 | * odd threshold value. | |
2375 | */ | |
2376 | frag_threshold &= ~0x1; | |
2377 | } | |
2378 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2379 | } | |
2380 | ||
2381 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2382 | rts_threshold = nla_get_u32( | |
2383 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2384 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2385 | } | |
2386 | ||
81077e82 | 2387 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
3057dbfd LB |
2388 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
2389 | return -EINVAL; | |
2390 | ||
81077e82 LT |
2391 | coverage_class = nla_get_u8( |
2392 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2393 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2394 | } | |
2395 | ||
3057dbfd LB |
2396 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
2397 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | |
2398 | return -EOPNOTSUPP; | |
2399 | ||
2400 | changed |= WIPHY_PARAM_DYN_ACK; | |
81077e82 LT |
2401 | } |
2402 | ||
b9a5f8ca JM |
2403 | if (changed) { |
2404 | u8 old_retry_short, old_retry_long; | |
2405 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2406 | u8 old_coverage_class; |
b9a5f8ca | 2407 | |
7f2b8562 YX |
2408 | if (!rdev->ops->set_wiphy_params) |
2409 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2410 | |
2411 | old_retry_short = rdev->wiphy.retry_short; | |
2412 | old_retry_long = rdev->wiphy.retry_long; | |
2413 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2414 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2415 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2416 | |
2417 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2418 | rdev->wiphy.retry_short = retry_short; | |
2419 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2420 | rdev->wiphy.retry_long = retry_long; | |
2421 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2422 | rdev->wiphy.frag_threshold = frag_threshold; | |
2423 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2424 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2425 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2426 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2427 | |
e35e4d28 | 2428 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2429 | if (result) { |
2430 | rdev->wiphy.retry_short = old_retry_short; | |
2431 | rdev->wiphy.retry_long = old_retry_long; | |
2432 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2433 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2434 | rdev->wiphy.coverage_class = old_coverage_class; |
9189ee31 | 2435 | return result; |
b9a5f8ca JM |
2436 | } |
2437 | } | |
7f2b8562 | 2438 | return 0; |
55682965 JB |
2439 | } |
2440 | ||
71bbc994 JB |
2441 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2442 | { | |
2443 | return (u64)wdev->identifier | | |
f26cbf40 | 2444 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2445 | } |
55682965 | 2446 | |
683b6d3b | 2447 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2448 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2449 | { |
601555cd JB |
2450 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
2451 | return -EINVAL; | |
3d9d1d66 | 2452 | |
683b6d3b JB |
2453 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2454 | chandef->chan->center_freq)) | |
2455 | return -ENOBUFS; | |
3d9d1d66 JB |
2456 | switch (chandef->width) { |
2457 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2458 | case NL80211_CHAN_WIDTH_20: | |
2459 | case NL80211_CHAN_WIDTH_40: | |
2460 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2461 | cfg80211_get_chandef_type(chandef))) | |
2462 | return -ENOBUFS; | |
2463 | break; | |
2464 | default: | |
2465 | break; | |
2466 | } | |
2467 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2468 | return -ENOBUFS; | |
2469 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2470 | return -ENOBUFS; | |
2471 | if (chandef->center_freq2 && | |
2472 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2473 | return -ENOBUFS; |
2474 | return 0; | |
2475 | } | |
2476 | ||
15e47304 | 2477 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2478 | struct cfg80211_registered_device *rdev, |
8f894be2 | 2479 | struct wireless_dev *wdev, bool removal) |
55682965 | 2480 | { |
72fb2abc | 2481 | struct net_device *dev = wdev->netdev; |
8f894be2 | 2482 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
55682965 JB |
2483 | void *hdr; |
2484 | ||
8f894be2 TB |
2485 | if (removal) |
2486 | cmd = NL80211_CMD_DEL_INTERFACE; | |
2487 | ||
2488 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | |
55682965 JB |
2489 | if (!hdr) |
2490 | return -1; | |
2491 | ||
72fb2abc JB |
2492 | if (dev && |
2493 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2494 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2495 | goto nla_put_failure; |
2496 | ||
2497 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2498 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
2dad624e ND |
2499 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
2500 | NL80211_ATTR_PAD) || | |
98104fde | 2501 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2502 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2503 | rdev->devlist_generation ^ | |
2504 | (cfg80211_rdev_list_generation << 2))) | |
2505 | goto nla_put_failure; | |
f5ea9120 | 2506 | |
5b7ccaf3 | 2507 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2508 | int ret; |
2509 | struct cfg80211_chan_def chandef; | |
2510 | ||
2511 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2512 | if (ret == 0) { | |
2513 | if (nl80211_send_chandef(msg, &chandef)) | |
2514 | goto nla_put_failure; | |
2515 | } | |
d91df0e3 PF |
2516 | } |
2517 | ||
d55d0d59 RM |
2518 | if (rdev->ops->get_tx_power) { |
2519 | int dbm, ret; | |
2520 | ||
2521 | ret = rdev_get_tx_power(rdev, wdev, &dbm); | |
2522 | if (ret == 0 && | |
2523 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, | |
2524 | DBM_TO_MBM(dbm))) | |
2525 | goto nla_put_failure; | |
2526 | } | |
2527 | ||
b84e7a05 AQ |
2528 | if (wdev->ssid_len) { |
2529 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2530 | goto nla_put_failure; | |
2531 | } | |
2532 | ||
053c095a JB |
2533 | genlmsg_end(msg, hdr); |
2534 | return 0; | |
55682965 JB |
2535 | |
2536 | nla_put_failure: | |
bc3ed28c TG |
2537 | genlmsg_cancel(msg, hdr); |
2538 | return -EMSGSIZE; | |
55682965 JB |
2539 | } |
2540 | ||
2541 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2542 | { | |
2543 | int wp_idx = 0; | |
2544 | int if_idx = 0; | |
2545 | int wp_start = cb->args[0]; | |
2546 | int if_start = cb->args[1]; | |
b7fb44da | 2547 | int filter_wiphy = -1; |
f5ea9120 | 2548 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2549 | struct wireless_dev *wdev; |
2550 | ||
5fe231e8 | 2551 | rtnl_lock(); |
b7fb44da DK |
2552 | if (!cb->args[2]) { |
2553 | struct nl80211_dump_wiphy_state state = { | |
2554 | .filter_wiphy = -1, | |
2555 | }; | |
2556 | int ret; | |
2557 | ||
2558 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); | |
2559 | if (ret) | |
2560 | return ret; | |
2561 | ||
2562 | filter_wiphy = state.filter_wiphy; | |
2563 | ||
2564 | /* | |
2565 | * if filtering, set cb->args[2] to +1 since 0 is the default | |
2566 | * value needed to determine that parsing is necessary. | |
2567 | */ | |
2568 | if (filter_wiphy >= 0) | |
2569 | cb->args[2] = filter_wiphy + 1; | |
2570 | else | |
2571 | cb->args[2] = -1; | |
2572 | } else if (cb->args[2] > 0) { | |
2573 | filter_wiphy = cb->args[2] - 1; | |
2574 | } | |
2575 | ||
f5ea9120 JB |
2576 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2577 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2578 | continue; |
bba95fef JB |
2579 | if (wp_idx < wp_start) { |
2580 | wp_idx++; | |
55682965 | 2581 | continue; |
bba95fef | 2582 | } |
b7fb44da DK |
2583 | |
2584 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) | |
2585 | continue; | |
2586 | ||
55682965 JB |
2587 | if_idx = 0; |
2588 | ||
53873f13 | 2589 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
bba95fef JB |
2590 | if (if_idx < if_start) { |
2591 | if_idx++; | |
55682965 | 2592 | continue; |
bba95fef | 2593 | } |
15e47304 | 2594 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2595 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
8f894be2 | 2596 | rdev, wdev, false) < 0) { |
bba95fef JB |
2597 | goto out; |
2598 | } | |
2599 | if_idx++; | |
55682965 | 2600 | } |
bba95fef JB |
2601 | |
2602 | wp_idx++; | |
55682965 | 2603 | } |
bba95fef | 2604 | out: |
5fe231e8 | 2605 | rtnl_unlock(); |
55682965 JB |
2606 | |
2607 | cb->args[0] = wp_idx; | |
2608 | cb->args[1] = if_idx; | |
2609 | ||
2610 | return skb->len; | |
2611 | } | |
2612 | ||
2613 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2614 | { | |
2615 | struct sk_buff *msg; | |
1b8ec87a | 2616 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2617 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2618 | |
fd2120ca | 2619 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2620 | if (!msg) |
4c476991 | 2621 | return -ENOMEM; |
55682965 | 2622 | |
15e47304 | 2623 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2624 | rdev, wdev, false) < 0) { |
4c476991 JB |
2625 | nlmsg_free(msg); |
2626 | return -ENOBUFS; | |
2627 | } | |
55682965 | 2628 | |
134e6375 | 2629 | return genlmsg_reply(msg, info); |
55682965 JB |
2630 | } |
2631 | ||
66f7ac50 MW |
2632 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2633 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2634 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2635 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2636 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2637 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2638 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2639 | }; |
2640 | ||
2641 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2642 | { | |
2643 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2644 | int flag; | |
2645 | ||
2646 | *mntrflags = 0; | |
2647 | ||
2648 | if (!nla) | |
2649 | return -EINVAL; | |
2650 | ||
2651 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2652 | nla, mntr_flags_policy)) | |
2653 | return -EINVAL; | |
2654 | ||
2655 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2656 | if (flags[flag]) | |
2657 | *mntrflags |= (1<<flag); | |
2658 | ||
2659 | return 0; | |
2660 | } | |
2661 | ||
9bc383de | 2662 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2663 | struct net_device *netdev, u8 use_4addr, |
2664 | enum nl80211_iftype iftype) | |
9bc383de | 2665 | { |
ad4bb6f8 | 2666 | if (!use_4addr) { |
f350a0a8 | 2667 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2668 | return -EBUSY; |
9bc383de | 2669 | return 0; |
ad4bb6f8 | 2670 | } |
9bc383de JB |
2671 | |
2672 | switch (iftype) { | |
2673 | case NL80211_IFTYPE_AP_VLAN: | |
2674 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2675 | return 0; | |
2676 | break; | |
2677 | case NL80211_IFTYPE_STATION: | |
2678 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2679 | return 0; | |
2680 | break; | |
2681 | default: | |
2682 | break; | |
2683 | } | |
2684 | ||
2685 | return -EOPNOTSUPP; | |
2686 | } | |
2687 | ||
55682965 JB |
2688 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2689 | { | |
4c476991 | 2690 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2691 | struct vif_params params; |
e36d56b6 | 2692 | int err; |
04a773ad | 2693 | enum nl80211_iftype otype, ntype; |
4c476991 | 2694 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2695 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2696 | bool change = false; |
55682965 | 2697 | |
2ec600d6 LCC |
2698 | memset(¶ms, 0, sizeof(params)); |
2699 | ||
04a773ad | 2700 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2701 | |
723b038d | 2702 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2703 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2704 | if (otype != ntype) |
ac7f9cfa | 2705 | change = true; |
4c476991 JB |
2706 | if (ntype > NL80211_IFTYPE_MAX) |
2707 | return -EINVAL; | |
723b038d JB |
2708 | } |
2709 | ||
92ffe055 | 2710 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2711 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2712 | ||
4c476991 JB |
2713 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2714 | return -EINVAL; | |
29cbe68c JB |
2715 | if (netif_running(dev)) |
2716 | return -EBUSY; | |
2717 | ||
2718 | wdev_lock(wdev); | |
2719 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2720 | IEEE80211_MAX_MESH_ID_LEN); | |
2721 | wdev->mesh_id_up_len = | |
2722 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2723 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2724 | wdev->mesh_id_up_len); | |
2725 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2726 | } |
2727 | ||
8b787643 FF |
2728 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2729 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2730 | change = true; | |
ad4bb6f8 | 2731 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2732 | if (err) |
4c476991 | 2733 | return err; |
8b787643 FF |
2734 | } else { |
2735 | params.use_4addr = -1; | |
2736 | } | |
2737 | ||
92ffe055 | 2738 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2739 | if (ntype != NL80211_IFTYPE_MONITOR) |
2740 | return -EINVAL; | |
92ffe055 JB |
2741 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2742 | &_flags); | |
ac7f9cfa | 2743 | if (err) |
4c476991 | 2744 | return err; |
ac7f9cfa JB |
2745 | |
2746 | flags = &_flags; | |
2747 | change = true; | |
92ffe055 | 2748 | } |
3b85875a | 2749 | |
c6e6a0c8 AE |
2750 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
2751 | const u8 *mumimo_groups; | |
2752 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; | |
2753 | ||
2754 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) | |
2755 | return -EOPNOTSUPP; | |
2756 | ||
2757 | mumimo_groups = | |
2758 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); | |
2759 | ||
2760 | /* bits 0 and 63 are reserved and must be zero */ | |
2761 | if ((mumimo_groups[0] & BIT(7)) || | |
2762 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0))) | |
2763 | return -EINVAL; | |
2764 | ||
2765 | memcpy(params.vht_mumimo_groups, mumimo_groups, | |
2766 | VHT_MUMIMO_GROUPS_DATA_LEN); | |
2767 | change = true; | |
2768 | } | |
2769 | ||
2770 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { | |
2771 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; | |
2772 | ||
2773 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) | |
2774 | return -EOPNOTSUPP; | |
2775 | ||
2776 | nla_memcpy(params.macaddr, | |
2777 | info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR], | |
2778 | ETH_ALEN); | |
2779 | change = true; | |
2780 | } | |
2781 | ||
18003297 | 2782 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2783 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2784 | return -EOPNOTSUPP; | |
2785 | ||
ac7f9cfa | 2786 | if (change) |
3d54d255 | 2787 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2788 | else |
2789 | err = 0; | |
60719ffd | 2790 | |
9bc383de JB |
2791 | if (!err && params.use_4addr != -1) |
2792 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2793 | ||
55682965 JB |
2794 | return err; |
2795 | } | |
2796 | ||
2797 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2798 | { | |
4c476991 | 2799 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2800 | struct vif_params params; |
84efbb84 | 2801 | struct wireless_dev *wdev; |
896ff063 | 2802 | struct sk_buff *msg; |
55682965 JB |
2803 | int err; |
2804 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2805 | u32 flags; |
55682965 | 2806 | |
78f22b6a JB |
2807 | /* to avoid failing a new interface creation due to pending removal */ |
2808 | cfg80211_destroy_ifaces(rdev); | |
2809 | ||
2ec600d6 LCC |
2810 | memset(¶ms, 0, sizeof(params)); |
2811 | ||
55682965 JB |
2812 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2813 | return -EINVAL; | |
2814 | ||
2815 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2816 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2817 | if (type > NL80211_IFTYPE_MAX) | |
2818 | return -EINVAL; | |
2819 | } | |
2820 | ||
79c97e97 | 2821 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2822 | !(rdev->wiphy.interface_modes & (1 << type))) |
2823 | return -EOPNOTSUPP; | |
55682965 | 2824 | |
cb3b7d87 | 2825 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
e8f479b1 BG |
2826 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
2827 | info->attrs[NL80211_ATTR_MAC]) { | |
1c18f145 AS |
2828 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
2829 | ETH_ALEN); | |
2830 | if (!is_valid_ether_addr(params.macaddr)) | |
2831 | return -EADDRNOTAVAIL; | |
2832 | } | |
2833 | ||
9bc383de | 2834 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2835 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2836 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2837 | if (err) |
4c476991 | 2838 | return err; |
9bc383de | 2839 | } |
8b787643 | 2840 | |
66f7ac50 MW |
2841 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2842 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2843 | &flags); | |
e057d3c3 | 2844 | |
18003297 | 2845 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2846 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2847 | return -EOPNOTSUPP; | |
2848 | ||
a18c7192 JB |
2849 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2850 | if (!msg) | |
2851 | return -ENOMEM; | |
2852 | ||
e35e4d28 HG |
2853 | wdev = rdev_add_virtual_intf(rdev, |
2854 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
6bab2e19 TG |
2855 | NET_NAME_USER, type, err ? NULL : &flags, |
2856 | ¶ms); | |
d687cbb7 RM |
2857 | if (WARN_ON(!wdev)) { |
2858 | nlmsg_free(msg); | |
2859 | return -EPROTO; | |
2860 | } else if (IS_ERR(wdev)) { | |
1c90f9d4 | 2861 | nlmsg_free(msg); |
84efbb84 | 2862 | return PTR_ERR(wdev); |
1c90f9d4 | 2863 | } |
2ec600d6 | 2864 | |
18e5ca65 | 2865 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
78f22b6a JB |
2866 | wdev->owner_nlportid = info->snd_portid; |
2867 | ||
98104fde JB |
2868 | switch (type) { |
2869 | case NL80211_IFTYPE_MESH_POINT: | |
2870 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2871 | break; | |
29cbe68c JB |
2872 | wdev_lock(wdev); |
2873 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2874 | IEEE80211_MAX_MESH_ID_LEN); | |
2875 | wdev->mesh_id_up_len = | |
2876 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2877 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2878 | wdev->mesh_id_up_len); | |
2879 | wdev_unlock(wdev); | |
98104fde | 2880 | break; |
cb3b7d87 | 2881 | case NL80211_IFTYPE_NAN: |
98104fde JB |
2882 | case NL80211_IFTYPE_P2P_DEVICE: |
2883 | /* | |
cb3b7d87 | 2884 | * P2P Device and NAN do not have a netdev, so don't go |
98104fde JB |
2885 | * through the netdev notifier and must be added here |
2886 | */ | |
2887 | mutex_init(&wdev->mtx); | |
2888 | INIT_LIST_HEAD(&wdev->event_list); | |
2889 | spin_lock_init(&wdev->event_lock); | |
2890 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2891 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2892 | ||
98104fde | 2893 | wdev->identifier = ++rdev->wdev_id; |
53873f13 | 2894 | list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list); |
98104fde | 2895 | rdev->devlist_generation++; |
98104fde JB |
2896 | break; |
2897 | default: | |
2898 | break; | |
29cbe68c JB |
2899 | } |
2900 | ||
15e47304 | 2901 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2902 | rdev, wdev, false) < 0) { |
1c90f9d4 JB |
2903 | nlmsg_free(msg); |
2904 | return -ENOBUFS; | |
2905 | } | |
2906 | ||
896ff063 DK |
2907 | /* |
2908 | * For wdevs which have no associated netdev object (e.g. of type | |
2909 | * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here. | |
2910 | * For all other types, the event will be generated from the | |
2911 | * netdev notifier | |
2912 | */ | |
2913 | if (!wdev->netdev) | |
2914 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); | |
8f894be2 | 2915 | |
1c90f9d4 | 2916 | return genlmsg_reply(msg, info); |
55682965 JB |
2917 | } |
2918 | ||
2919 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2920 | { | |
4c476991 | 2921 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2922 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2923 | |
4c476991 JB |
2924 | if (!rdev->ops->del_virtual_intf) |
2925 | return -EOPNOTSUPP; | |
55682965 | 2926 | |
84efbb84 JB |
2927 | /* |
2928 | * If we remove a wireless device without a netdev then clear | |
2929 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2930 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2931 | * since the wdev has been freed, unlike with a netdev where | |
2932 | * we need the dev_put() for the netdev to really be freed. | |
2933 | */ | |
2934 | if (!wdev->netdev) | |
2935 | info->user_ptr[1] = NULL; | |
2936 | ||
7f8ed01e | 2937 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2938 | } |
2939 | ||
1d9d9213 SW |
2940 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2941 | { | |
2942 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2943 | struct net_device *dev = info->user_ptr[1]; | |
2944 | u16 noack_map; | |
2945 | ||
2946 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2947 | return -EINVAL; | |
2948 | ||
2949 | if (!rdev->ops->set_noack_map) | |
2950 | return -EOPNOTSUPP; | |
2951 | ||
2952 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2953 | ||
e35e4d28 | 2954 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2955 | } |
2956 | ||
41ade00f JB |
2957 | struct get_key_cookie { |
2958 | struct sk_buff *msg; | |
2959 | int error; | |
b9454e83 | 2960 | int idx; |
41ade00f JB |
2961 | }; |
2962 | ||
2963 | static void get_key_callback(void *c, struct key_params *params) | |
2964 | { | |
b9454e83 | 2965 | struct nlattr *key; |
41ade00f JB |
2966 | struct get_key_cookie *cookie = c; |
2967 | ||
9360ffd1 DM |
2968 | if ((params->key && |
2969 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2970 | params->key_len, params->key)) || | |
2971 | (params->seq && | |
2972 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2973 | params->seq_len, params->seq)) || | |
2974 | (params->cipher && | |
2975 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2976 | params->cipher))) | |
2977 | goto nla_put_failure; | |
41ade00f | 2978 | |
b9454e83 JB |
2979 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2980 | if (!key) | |
2981 | goto nla_put_failure; | |
2982 | ||
9360ffd1 DM |
2983 | if ((params->key && |
2984 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2985 | params->key_len, params->key)) || | |
2986 | (params->seq && | |
2987 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2988 | params->seq_len, params->seq)) || | |
2989 | (params->cipher && | |
2990 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2991 | params->cipher))) | |
2992 | goto nla_put_failure; | |
b9454e83 | 2993 | |
9360ffd1 DM |
2994 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2995 | goto nla_put_failure; | |
b9454e83 JB |
2996 | |
2997 | nla_nest_end(cookie->msg, key); | |
2998 | ||
41ade00f JB |
2999 | return; |
3000 | nla_put_failure: | |
3001 | cookie->error = 1; | |
3002 | } | |
3003 | ||
3004 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
3005 | { | |
4c476991 | 3006 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3007 | int err; |
4c476991 | 3008 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3009 | u8 key_idx = 0; |
e31b8213 JB |
3010 | const u8 *mac_addr = NULL; |
3011 | bool pairwise; | |
41ade00f JB |
3012 | struct get_key_cookie cookie = { |
3013 | .error = 0, | |
3014 | }; | |
3015 | void *hdr; | |
3016 | struct sk_buff *msg; | |
3017 | ||
3018 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
3019 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
3020 | ||
3cfcf6ac | 3021 | if (key_idx > 5) |
41ade00f JB |
3022 | return -EINVAL; |
3023 | ||
3024 | if (info->attrs[NL80211_ATTR_MAC]) | |
3025 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3026 | ||
e31b8213 JB |
3027 | pairwise = !!mac_addr; |
3028 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
3029 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
7a087e74 | 3030 | |
e31b8213 JB |
3031 | if (kt >= NUM_NL80211_KEYTYPES) |
3032 | return -EINVAL; | |
3033 | if (kt != NL80211_KEYTYPE_GROUP && | |
3034 | kt != NL80211_KEYTYPE_PAIRWISE) | |
3035 | return -EINVAL; | |
3036 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
3037 | } | |
3038 | ||
4c476991 JB |
3039 | if (!rdev->ops->get_key) |
3040 | return -EOPNOTSUPP; | |
41ade00f | 3041 | |
0fa7b391 JB |
3042 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
3043 | return -ENOENT; | |
3044 | ||
fd2120ca | 3045 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
3046 | if (!msg) |
3047 | return -ENOMEM; | |
41ade00f | 3048 | |
15e47304 | 3049 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 3050 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 3051 | if (!hdr) |
9fe271af | 3052 | goto nla_put_failure; |
41ade00f JB |
3053 | |
3054 | cookie.msg = msg; | |
b9454e83 | 3055 | cookie.idx = key_idx; |
41ade00f | 3056 | |
9360ffd1 DM |
3057 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3058 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
3059 | goto nla_put_failure; | |
3060 | if (mac_addr && | |
3061 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
3062 | goto nla_put_failure; | |
41ade00f | 3063 | |
e35e4d28 HG |
3064 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
3065 | get_key_callback); | |
41ade00f JB |
3066 | |
3067 | if (err) | |
6c95e2a2 | 3068 | goto free_msg; |
41ade00f JB |
3069 | |
3070 | if (cookie.error) | |
3071 | goto nla_put_failure; | |
3072 | ||
3073 | genlmsg_end(msg, hdr); | |
4c476991 | 3074 | return genlmsg_reply(msg, info); |
41ade00f JB |
3075 | |
3076 | nla_put_failure: | |
3077 | err = -ENOBUFS; | |
6c95e2a2 | 3078 | free_msg: |
41ade00f | 3079 | nlmsg_free(msg); |
41ade00f JB |
3080 | return err; |
3081 | } | |
3082 | ||
3083 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
3084 | { | |
4c476991 | 3085 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 3086 | struct key_parse key; |
41ade00f | 3087 | int err; |
4c476991 | 3088 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3089 | |
b9454e83 JB |
3090 | err = nl80211_parse_key(info, &key); |
3091 | if (err) | |
3092 | return err; | |
41ade00f | 3093 | |
b9454e83 | 3094 | if (key.idx < 0) |
41ade00f JB |
3095 | return -EINVAL; |
3096 | ||
b9454e83 JB |
3097 | /* only support setting default key */ |
3098 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
3099 | return -EINVAL; |
3100 | ||
dbd2fd65 | 3101 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 3102 | |
dbd2fd65 JB |
3103 | if (key.def) { |
3104 | if (!rdev->ops->set_default_key) { | |
3105 | err = -EOPNOTSUPP; | |
3106 | goto out; | |
3107 | } | |
41ade00f | 3108 | |
dbd2fd65 JB |
3109 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
3110 | if (err) | |
3111 | goto out; | |
3112 | ||
e35e4d28 | 3113 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
3114 | key.def_uni, key.def_multi); |
3115 | ||
3116 | if (err) | |
3117 | goto out; | |
fffd0934 | 3118 | |
3d23e349 | 3119 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
3120 | dev->ieee80211_ptr->wext.default_key = key.idx; |
3121 | #endif | |
3122 | } else { | |
3123 | if (key.def_uni || !key.def_multi) { | |
3124 | err = -EINVAL; | |
3125 | goto out; | |
3126 | } | |
3127 | ||
3128 | if (!rdev->ops->set_default_mgmt_key) { | |
3129 | err = -EOPNOTSUPP; | |
3130 | goto out; | |
3131 | } | |
3132 | ||
3133 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3134 | if (err) | |
3135 | goto out; | |
3136 | ||
e35e4d28 | 3137 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
3138 | if (err) |
3139 | goto out; | |
3140 | ||
3141 | #ifdef CONFIG_CFG80211_WEXT | |
3142 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 3143 | #endif |
dbd2fd65 JB |
3144 | } |
3145 | ||
3146 | out: | |
fffd0934 | 3147 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3148 | |
41ade00f JB |
3149 | return err; |
3150 | } | |
3151 | ||
3152 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
3153 | { | |
4c476991 | 3154 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 3155 | int err; |
4c476991 | 3156 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 3157 | struct key_parse key; |
e31b8213 | 3158 | const u8 *mac_addr = NULL; |
41ade00f | 3159 | |
b9454e83 JB |
3160 | err = nl80211_parse_key(info, &key); |
3161 | if (err) | |
3162 | return err; | |
41ade00f | 3163 | |
b9454e83 | 3164 | if (!key.p.key) |
41ade00f JB |
3165 | return -EINVAL; |
3166 | ||
41ade00f JB |
3167 | if (info->attrs[NL80211_ATTR_MAC]) |
3168 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3169 | ||
e31b8213 JB |
3170 | if (key.type == -1) { |
3171 | if (mac_addr) | |
3172 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3173 | else | |
3174 | key.type = NL80211_KEYTYPE_GROUP; | |
3175 | } | |
3176 | ||
3177 | /* for now */ | |
3178 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3179 | key.type != NL80211_KEYTYPE_GROUP) | |
3180 | return -EINVAL; | |
3181 | ||
4c476991 JB |
3182 | if (!rdev->ops->add_key) |
3183 | return -EOPNOTSUPP; | |
25e47c18 | 3184 | |
e31b8213 JB |
3185 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
3186 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3187 | mac_addr)) | |
4c476991 | 3188 | return -EINVAL; |
41ade00f | 3189 | |
fffd0934 JB |
3190 | wdev_lock(dev->ieee80211_ptr); |
3191 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3192 | if (!err) | |
e35e4d28 HG |
3193 | err = rdev_add_key(rdev, dev, key.idx, |
3194 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3195 | mac_addr, &key.p); | |
fffd0934 | 3196 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3197 | |
41ade00f JB |
3198 | return err; |
3199 | } | |
3200 | ||
3201 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
3202 | { | |
4c476991 | 3203 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3204 | int err; |
4c476991 | 3205 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3206 | u8 *mac_addr = NULL; |
b9454e83 | 3207 | struct key_parse key; |
41ade00f | 3208 | |
b9454e83 JB |
3209 | err = nl80211_parse_key(info, &key); |
3210 | if (err) | |
3211 | return err; | |
41ade00f JB |
3212 | |
3213 | if (info->attrs[NL80211_ATTR_MAC]) | |
3214 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3215 | ||
e31b8213 JB |
3216 | if (key.type == -1) { |
3217 | if (mac_addr) | |
3218 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3219 | else | |
3220 | key.type = NL80211_KEYTYPE_GROUP; | |
3221 | } | |
3222 | ||
3223 | /* for now */ | |
3224 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3225 | key.type != NL80211_KEYTYPE_GROUP) | |
3226 | return -EINVAL; | |
3227 | ||
4c476991 JB |
3228 | if (!rdev->ops->del_key) |
3229 | return -EOPNOTSUPP; | |
41ade00f | 3230 | |
fffd0934 JB |
3231 | wdev_lock(dev->ieee80211_ptr); |
3232 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 | 3233 | |
0fa7b391 | 3234 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
e31b8213 JB |
3235 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
3236 | err = -ENOENT; | |
3237 | ||
fffd0934 | 3238 | if (!err) |
e35e4d28 HG |
3239 | err = rdev_del_key(rdev, dev, key.idx, |
3240 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3241 | mac_addr); | |
41ade00f | 3242 | |
3d23e349 | 3243 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 3244 | if (!err) { |
b9454e83 | 3245 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 3246 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 3247 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
3248 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
3249 | } | |
3250 | #endif | |
fffd0934 | 3251 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 3252 | |
41ade00f JB |
3253 | return err; |
3254 | } | |
3255 | ||
77765eaf VT |
3256 | /* This function returns an error or the number of nested attributes */ |
3257 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
3258 | { | |
3259 | struct nlattr *attr; | |
3260 | int n_entries = 0, tmp; | |
3261 | ||
3262 | nla_for_each_nested(attr, nl_attr, tmp) { | |
3263 | if (nla_len(attr) != ETH_ALEN) | |
3264 | return -EINVAL; | |
3265 | ||
3266 | n_entries++; | |
3267 | } | |
3268 | ||
3269 | return n_entries; | |
3270 | } | |
3271 | ||
3272 | /* | |
3273 | * This function parses ACL information and allocates memory for ACL data. | |
3274 | * On successful return, the calling function is responsible to free the | |
3275 | * ACL buffer returned by this function. | |
3276 | */ | |
3277 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3278 | struct genl_info *info) | |
3279 | { | |
3280 | enum nl80211_acl_policy acl_policy; | |
3281 | struct nlattr *attr; | |
3282 | struct cfg80211_acl_data *acl; | |
3283 | int i = 0, n_entries, tmp; | |
3284 | ||
3285 | if (!wiphy->max_acl_mac_addrs) | |
3286 | return ERR_PTR(-EOPNOTSUPP); | |
3287 | ||
3288 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3289 | return ERR_PTR(-EINVAL); | |
3290 | ||
3291 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3292 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3293 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3294 | return ERR_PTR(-EINVAL); | |
3295 | ||
3296 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3297 | return ERR_PTR(-EINVAL); | |
3298 | ||
3299 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3300 | if (n_entries < 0) | |
3301 | return ERR_PTR(n_entries); | |
3302 | ||
3303 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3304 | return ERR_PTR(-ENOTSUPP); | |
3305 | ||
3306 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
3307 | GFP_KERNEL); | |
3308 | if (!acl) | |
3309 | return ERR_PTR(-ENOMEM); | |
3310 | ||
3311 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3312 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3313 | i++; | |
3314 | } | |
3315 | ||
3316 | acl->n_acl_entries = n_entries; | |
3317 | acl->acl_policy = acl_policy; | |
3318 | ||
3319 | return acl; | |
3320 | } | |
3321 | ||
3322 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3323 | { | |
3324 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3325 | struct net_device *dev = info->user_ptr[1]; | |
3326 | struct cfg80211_acl_data *acl; | |
3327 | int err; | |
3328 | ||
3329 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3330 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3331 | return -EOPNOTSUPP; | |
3332 | ||
3333 | if (!dev->ieee80211_ptr->beacon_interval) | |
3334 | return -EINVAL; | |
3335 | ||
3336 | acl = parse_acl_data(&rdev->wiphy, info); | |
3337 | if (IS_ERR(acl)) | |
3338 | return PTR_ERR(acl); | |
3339 | ||
3340 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3341 | ||
3342 | kfree(acl); | |
3343 | ||
3344 | return err; | |
3345 | } | |
3346 | ||
a7c7fbff PK |
3347 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
3348 | u8 *rates, u8 rates_len) | |
3349 | { | |
3350 | u8 i; | |
3351 | u32 mask = 0; | |
3352 | ||
3353 | for (i = 0; i < rates_len; i++) { | |
3354 | int rate = (rates[i] & 0x7f) * 5; | |
3355 | int ridx; | |
3356 | ||
3357 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
3358 | struct ieee80211_rate *srate = | |
3359 | &sband->bitrates[ridx]; | |
3360 | if (rate == srate->bitrate) { | |
3361 | mask |= 1 << ridx; | |
3362 | break; | |
3363 | } | |
3364 | } | |
3365 | if (ridx == sband->n_bitrates) | |
3366 | return 0; /* rate not found */ | |
3367 | } | |
3368 | ||
3369 | return mask; | |
3370 | } | |
3371 | ||
3372 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, | |
3373 | u8 *rates, u8 rates_len, | |
3374 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
3375 | { | |
3376 | u8 i; | |
3377 | ||
3378 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
3379 | ||
3380 | for (i = 0; i < rates_len; i++) { | |
3381 | int ridx, rbit; | |
3382 | ||
3383 | ridx = rates[i] / 8; | |
3384 | rbit = BIT(rates[i] % 8); | |
3385 | ||
3386 | /* check validity */ | |
3387 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) | |
3388 | return false; | |
3389 | ||
3390 | /* check availability */ | |
3391 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
3392 | mcs[ridx] |= rbit; | |
3393 | else | |
3394 | return false; | |
3395 | } | |
3396 | ||
3397 | return true; | |
3398 | } | |
3399 | ||
3400 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) | |
3401 | { | |
3402 | u16 mcs_mask = 0; | |
3403 | ||
3404 | switch (vht_mcs_map) { | |
3405 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
3406 | break; | |
3407 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
3408 | mcs_mask = 0x00FF; | |
3409 | break; | |
3410 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
3411 | mcs_mask = 0x01FF; | |
3412 | break; | |
3413 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
3414 | mcs_mask = 0x03FF; | |
3415 | break; | |
3416 | default: | |
3417 | break; | |
3418 | } | |
3419 | ||
3420 | return mcs_mask; | |
3421 | } | |
3422 | ||
3423 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
3424 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
3425 | { | |
3426 | u8 nss; | |
3427 | ||
3428 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
3429 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
3430 | vht_mcs_map >>= 2; | |
3431 | } | |
3432 | } | |
3433 | ||
3434 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
3435 | struct nl80211_txrate_vht *txrate, | |
3436 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
3437 | { | |
3438 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
3439 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
3440 | u8 i; | |
3441 | ||
3442 | if (!sband->vht_cap.vht_supported) | |
3443 | return false; | |
3444 | ||
3445 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
3446 | ||
3447 | /* Build vht_mcs_mask from VHT capabilities */ | |
3448 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
3449 | ||
3450 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
3451 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
3452 | mcs[i] = txrate->mcs[i]; | |
3453 | else | |
3454 | return false; | |
3455 | } | |
3456 | ||
3457 | return true; | |
3458 | } | |
3459 | ||
3460 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { | |
3461 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, | |
3462 | .len = NL80211_MAX_SUPP_RATES }, | |
3463 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, | |
3464 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
3465 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, | |
3466 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, | |
3467 | }; | |
3468 | ||
3469 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, | |
3470 | struct cfg80211_bitrate_mask *mask) | |
3471 | { | |
3472 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
3473 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3474 | int rem, i; | |
3475 | struct nlattr *tx_rates; | |
3476 | struct ieee80211_supported_band *sband; | |
3477 | u16 vht_tx_mcs_map; | |
3478 | ||
3479 | memset(mask, 0, sizeof(*mask)); | |
3480 | /* Default to all rates enabled */ | |
3481 | for (i = 0; i < NUM_NL80211_BANDS; i++) { | |
3482 | sband = rdev->wiphy.bands[i]; | |
3483 | ||
3484 | if (!sband) | |
3485 | continue; | |
3486 | ||
3487 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; | |
3488 | memcpy(mask->control[i].ht_mcs, | |
3489 | sband->ht_cap.mcs.rx_mask, | |
3490 | sizeof(mask->control[i].ht_mcs)); | |
3491 | ||
3492 | if (!sband->vht_cap.vht_supported) | |
3493 | continue; | |
3494 | ||
3495 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
3496 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); | |
3497 | } | |
3498 | ||
3499 | /* if no rates are given set it back to the defaults */ | |
3500 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
3501 | goto out; | |
3502 | ||
3503 | /* The nested attribute uses enum nl80211_band as the index. This maps | |
3504 | * directly to the enum nl80211_band values used in cfg80211. | |
3505 | */ | |
3506 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); | |
3507 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { | |
3508 | enum nl80211_band band = nla_type(tx_rates); | |
3509 | int err; | |
3510 | ||
3511 | if (band < 0 || band >= NUM_NL80211_BANDS) | |
3512 | return -EINVAL; | |
3513 | sband = rdev->wiphy.bands[band]; | |
3514 | if (sband == NULL) | |
3515 | return -EINVAL; | |
3516 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), | |
3517 | nla_len(tx_rates), nl80211_txattr_policy); | |
3518 | if (err) | |
3519 | return err; | |
3520 | if (tb[NL80211_TXRATE_LEGACY]) { | |
3521 | mask->control[band].legacy = rateset_to_mask( | |
3522 | sband, | |
3523 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
3524 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
3525 | if ((mask->control[band].legacy == 0) && | |
3526 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
3527 | return -EINVAL; | |
3528 | } | |
3529 | if (tb[NL80211_TXRATE_HT]) { | |
3530 | if (!ht_rateset_to_mask( | |
3531 | sband, | |
3532 | nla_data(tb[NL80211_TXRATE_HT]), | |
3533 | nla_len(tb[NL80211_TXRATE_HT]), | |
3534 | mask->control[band].ht_mcs)) | |
3535 | return -EINVAL; | |
3536 | } | |
3537 | if (tb[NL80211_TXRATE_VHT]) { | |
3538 | if (!vht_set_mcs_mask( | |
3539 | sband, | |
3540 | nla_data(tb[NL80211_TXRATE_VHT]), | |
3541 | mask->control[band].vht_mcs)) | |
3542 | return -EINVAL; | |
3543 | } | |
3544 | if (tb[NL80211_TXRATE_GI]) { | |
3545 | mask->control[band].gi = | |
3546 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
3547 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
3548 | return -EINVAL; | |
3549 | } | |
3550 | ||
3551 | if (mask->control[band].legacy == 0) { | |
3552 | /* don't allow empty legacy rates if HT or VHT | |
3553 | * are not even supported. | |
3554 | */ | |
3555 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
3556 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
3557 | return -EINVAL; | |
3558 | ||
3559 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
3560 | if (mask->control[band].ht_mcs[i]) | |
3561 | goto out; | |
3562 | ||
3563 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
3564 | if (mask->control[band].vht_mcs[i]) | |
3565 | goto out; | |
3566 | ||
3567 | /* legacy and mcs rates may not be both empty */ | |
3568 | return -EINVAL; | |
3569 | } | |
3570 | } | |
3571 | ||
3572 | out: | |
3573 | return 0; | |
3574 | } | |
3575 | ||
8564e382 JB |
3576 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
3577 | enum nl80211_band band, | |
3578 | struct cfg80211_bitrate_mask *beacon_rate) | |
a7c7fbff | 3579 | { |
8564e382 JB |
3580 | u32 count_ht, count_vht, i; |
3581 | u32 rate = beacon_rate->control[band].legacy; | |
a7c7fbff PK |
3582 | |
3583 | /* Allow only one rate */ | |
3584 | if (hweight32(rate) > 1) | |
3585 | return -EINVAL; | |
3586 | ||
3587 | count_ht = 0; | |
3588 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { | |
8564e382 | 3589 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
a7c7fbff | 3590 | return -EINVAL; |
8564e382 | 3591 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
a7c7fbff PK |
3592 | count_ht++; |
3593 | if (count_ht > 1) | |
3594 | return -EINVAL; | |
3595 | } | |
3596 | if (count_ht && rate) | |
3597 | return -EINVAL; | |
3598 | } | |
3599 | ||
3600 | count_vht = 0; | |
3601 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
8564e382 | 3602 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
a7c7fbff | 3603 | return -EINVAL; |
8564e382 | 3604 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
a7c7fbff PK |
3605 | count_vht++; |
3606 | if (count_vht > 1) | |
3607 | return -EINVAL; | |
3608 | } | |
3609 | if (count_vht && rate) | |
3610 | return -EINVAL; | |
3611 | } | |
3612 | ||
3613 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) | |
3614 | return -EINVAL; | |
3615 | ||
8564e382 JB |
3616 | if (rate && |
3617 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
3618 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) | |
3619 | return -EINVAL; | |
3620 | if (count_ht && | |
3621 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
3622 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) | |
3623 | return -EINVAL; | |
3624 | if (count_vht && | |
3625 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
3626 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) | |
3627 | return -EINVAL; | |
3628 | ||
a7c7fbff PK |
3629 | return 0; |
3630 | } | |
3631 | ||
a1193be8 | 3632 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3633 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3634 | { |
8860020e | 3635 | bool haveinfo = false; |
ed1b6cc7 | 3636 | |
a1193be8 SW |
3637 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3638 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3639 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3640 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3641 | return -EINVAL; |
3642 | ||
8860020e | 3643 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3644 | |
a1193be8 SW |
3645 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3646 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3647 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3648 | if (!bcn->head_len) |
3649 | return -EINVAL; | |
3650 | haveinfo = true; | |
ed1b6cc7 JB |
3651 | } |
3652 | ||
a1193be8 SW |
3653 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3654 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3655 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3656 | haveinfo = true; |
ed1b6cc7 JB |
3657 | } |
3658 | ||
4c476991 JB |
3659 | if (!haveinfo) |
3660 | return -EINVAL; | |
3b85875a | 3661 | |
a1193be8 SW |
3662 | if (attrs[NL80211_ATTR_IE]) { |
3663 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3664 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3665 | } |
3666 | ||
a1193be8 | 3667 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3668 | bcn->proberesp_ies = |
a1193be8 | 3669 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3670 | bcn->proberesp_ies_len = |
a1193be8 | 3671 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3672 | } |
3673 | ||
a1193be8 | 3674 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3675 | bcn->assocresp_ies = |
a1193be8 | 3676 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3677 | bcn->assocresp_ies_len = |
a1193be8 | 3678 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3679 | } |
3680 | ||
a1193be8 SW |
3681 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3682 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3683 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3684 | } |
3685 | ||
8860020e JB |
3686 | return 0; |
3687 | } | |
3688 | ||
46c1dd0c FF |
3689 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3690 | struct cfg80211_ap_settings *params) | |
3691 | { | |
3692 | struct wireless_dev *wdev; | |
3693 | bool ret = false; | |
3694 | ||
53873f13 | 3695 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
46c1dd0c FF |
3696 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3697 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3698 | continue; | |
3699 | ||
683b6d3b | 3700 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3701 | continue; |
3702 | ||
683b6d3b | 3703 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3704 | ret = true; |
3705 | break; | |
3706 | } | |
3707 | ||
46c1dd0c FF |
3708 | return ret; |
3709 | } | |
3710 | ||
e39e5b5e JM |
3711 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3712 | enum nl80211_auth_type auth_type, | |
3713 | enum nl80211_commands cmd) | |
3714 | { | |
3715 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3716 | return false; | |
3717 | ||
3718 | switch (cmd) { | |
3719 | case NL80211_CMD_AUTHENTICATE: | |
3720 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3721 | auth_type == NL80211_AUTHTYPE_SAE) | |
3722 | return false; | |
3723 | return true; | |
3724 | case NL80211_CMD_CONNECT: | |
3725 | case NL80211_CMD_START_AP: | |
3726 | /* SAE not supported yet */ | |
3727 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3728 | return false; | |
3729 | return true; | |
3730 | default: | |
3731 | return false; | |
3732 | } | |
3733 | } | |
3734 | ||
8860020e JB |
3735 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3736 | { | |
3737 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3738 | struct net_device *dev = info->user_ptr[1]; | |
3739 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3740 | struct cfg80211_ap_settings params; | |
3741 | int err; | |
3742 | ||
3743 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3744 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3745 | return -EOPNOTSUPP; | |
3746 | ||
3747 | if (!rdev->ops->start_ap) | |
3748 | return -EOPNOTSUPP; | |
3749 | ||
3750 | if (wdev->beacon_interval) | |
3751 | return -EALREADY; | |
3752 | ||
3753 | memset(¶ms, 0, sizeof(params)); | |
3754 | ||
3755 | /* these are required for START_AP */ | |
3756 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3757 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3758 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3759 | return -EINVAL; | |
3760 | ||
a1193be8 | 3761 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3762 | if (err) |
3763 | return err; | |
3764 | ||
3765 | params.beacon_interval = | |
3766 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3767 | params.dtim_period = | |
3768 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3769 | ||
3770 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3771 | if (err) | |
3772 | return err; | |
3773 | ||
3774 | /* | |
3775 | * In theory, some of these attributes should be required here | |
3776 | * but since they were not used when the command was originally | |
3777 | * added, keep them optional for old user space programs to let | |
3778 | * them continue to work with drivers that do not need the | |
3779 | * additional information -- drivers must check! | |
3780 | */ | |
3781 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3782 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3783 | params.ssid_len = | |
3784 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3785 | if (params.ssid_len == 0 || | |
3786 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3787 | return -EINVAL; | |
3788 | } | |
3789 | ||
3790 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3791 | params.hidden_ssid = nla_get_u32( | |
3792 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3793 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3794 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3795 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3796 | return -EINVAL; | |
3797 | } | |
3798 | ||
3799 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3800 | ||
3801 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3802 | params.auth_type = nla_get_u32( | |
3803 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3804 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3805 | NL80211_CMD_START_AP)) | |
8860020e JB |
3806 | return -EINVAL; |
3807 | } else | |
3808 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3809 | ||
3810 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3811 | NL80211_MAX_NR_CIPHER_SUITES); | |
3812 | if (err) | |
3813 | return err; | |
3814 | ||
1b658f11 VT |
3815 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3816 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3817 | return -EOPNOTSUPP; | |
3818 | params.inactivity_timeout = nla_get_u16( | |
3819 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3820 | } | |
3821 | ||
53cabad7 JB |
3822 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3823 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3824 | return -EINVAL; | |
3825 | params.p2p_ctwindow = | |
3826 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3827 | if (params.p2p_ctwindow > 127) | |
3828 | return -EINVAL; | |
3829 | if (params.p2p_ctwindow != 0 && | |
3830 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3831 | return -EINVAL; | |
3832 | } | |
3833 | ||
3834 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3835 | u8 tmp; | |
3836 | ||
3837 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3838 | return -EINVAL; | |
3839 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3840 | if (tmp > 1) | |
3841 | return -EINVAL; | |
3842 | params.p2p_opp_ps = tmp; | |
3843 | if (params.p2p_opp_ps != 0 && | |
3844 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3845 | return -EINVAL; | |
3846 | } | |
3847 | ||
aa430da4 | 3848 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3849 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3850 | if (err) | |
3851 | return err; | |
3852 | } else if (wdev->preset_chandef.chan) { | |
3853 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3854 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3855 | return -EINVAL; |
3856 | ||
923b352f AN |
3857 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
3858 | wdev->iftype)) | |
aa430da4 JB |
3859 | return -EINVAL; |
3860 | ||
a7c7fbff PK |
3861 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
3862 | err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate); | |
3863 | if (err) | |
3864 | return err; | |
3865 | ||
8564e382 JB |
3866 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
3867 | ¶ms.beacon_rate); | |
a7c7fbff PK |
3868 | if (err) |
3869 | return err; | |
3870 | } | |
3871 | ||
18998c38 EP |
3872 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
3873 | params.smps_mode = | |
3874 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); | |
3875 | switch (params.smps_mode) { | |
3876 | case NL80211_SMPS_OFF: | |
3877 | break; | |
3878 | case NL80211_SMPS_STATIC: | |
3879 | if (!(rdev->wiphy.features & | |
3880 | NL80211_FEATURE_STATIC_SMPS)) | |
3881 | return -EINVAL; | |
3882 | break; | |
3883 | case NL80211_SMPS_DYNAMIC: | |
3884 | if (!(rdev->wiphy.features & | |
3885 | NL80211_FEATURE_DYNAMIC_SMPS)) | |
3886 | return -EINVAL; | |
3887 | break; | |
3888 | default: | |
3889 | return -EINVAL; | |
3890 | } | |
3891 | } else { | |
3892 | params.smps_mode = NL80211_SMPS_OFF; | |
3893 | } | |
3894 | ||
6e8ef842 PK |
3895 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
3896 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) | |
3897 | return -EOPNOTSUPP; | |
3898 | ||
4baf6bea OO |
3899 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3900 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3901 | if (IS_ERR(params.acl)) | |
3902 | return PTR_ERR(params.acl); | |
3903 | } | |
3904 | ||
c56589ed | 3905 | wdev_lock(wdev); |
e35e4d28 | 3906 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3907 | if (!err) { |
683b6d3b | 3908 | wdev->preset_chandef = params.chandef; |
8860020e | 3909 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 3910 | wdev->chandef = params.chandef; |
06e191e2 AQ |
3911 | wdev->ssid_len = params.ssid_len; |
3912 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3913 | } |
c56589ed | 3914 | wdev_unlock(wdev); |
77765eaf VT |
3915 | |
3916 | kfree(params.acl); | |
3917 | ||
56d1893d | 3918 | return err; |
ed1b6cc7 JB |
3919 | } |
3920 | ||
8860020e JB |
3921 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3922 | { | |
3923 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3924 | struct net_device *dev = info->user_ptr[1]; | |
3925 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3926 | struct cfg80211_beacon_data params; | |
3927 | int err; | |
3928 | ||
3929 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3930 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3931 | return -EOPNOTSUPP; | |
3932 | ||
3933 | if (!rdev->ops->change_beacon) | |
3934 | return -EOPNOTSUPP; | |
3935 | ||
3936 | if (!wdev->beacon_interval) | |
3937 | return -EINVAL; | |
3938 | ||
a1193be8 | 3939 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3940 | if (err) |
3941 | return err; | |
3942 | ||
c56589ed SW |
3943 | wdev_lock(wdev); |
3944 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3945 | wdev_unlock(wdev); | |
3946 | ||
3947 | return err; | |
8860020e JB |
3948 | } |
3949 | ||
3950 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3951 | { |
4c476991 JB |
3952 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3953 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3954 | |
7c8d5e03 | 3955 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
3956 | } |
3957 | ||
5727ef1b JB |
3958 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3959 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3960 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3961 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3962 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3963 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3964 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3965 | }; |
3966 | ||
eccb8e8f | 3967 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3968 | enum nl80211_iftype iftype, |
eccb8e8f | 3969 | struct station_parameters *params) |
5727ef1b JB |
3970 | { |
3971 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3972 | struct nlattr *nla; |
5727ef1b JB |
3973 | int flag; |
3974 | ||
eccb8e8f JB |
3975 | /* |
3976 | * Try parsing the new attribute first so userspace | |
3977 | * can specify both for older kernels. | |
3978 | */ | |
3979 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3980 | if (nla) { | |
3981 | struct nl80211_sta_flag_update *sta_flags; | |
3982 | ||
3983 | sta_flags = nla_data(nla); | |
3984 | params->sta_flags_mask = sta_flags->mask; | |
3985 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3986 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3987 | if ((params->sta_flags_mask | |
3988 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3989 | return -EINVAL; | |
3990 | return 0; | |
3991 | } | |
3992 | ||
3993 | /* if present, parse the old attribute */ | |
5727ef1b | 3994 | |
eccb8e8f | 3995 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3996 | if (!nla) |
3997 | return 0; | |
3998 | ||
3999 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
4000 | nla, sta_flags_policy)) | |
4001 | return -EINVAL; | |
4002 | ||
bdd3ae3d JB |
4003 | /* |
4004 | * Only allow certain flags for interface types so that | |
4005 | * other attributes are silently ignored. Remember that | |
4006 | * this is backward compatibility code with old userspace | |
4007 | * and shouldn't be hit in other cases anyway. | |
4008 | */ | |
4009 | switch (iftype) { | |
4010 | case NL80211_IFTYPE_AP: | |
4011 | case NL80211_IFTYPE_AP_VLAN: | |
4012 | case NL80211_IFTYPE_P2P_GO: | |
4013 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4014 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
4015 | BIT(NL80211_STA_FLAG_WME) | | |
4016 | BIT(NL80211_STA_FLAG_MFP); | |
4017 | break; | |
4018 | case NL80211_IFTYPE_P2P_CLIENT: | |
4019 | case NL80211_IFTYPE_STATION: | |
4020 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4021 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
4022 | break; | |
4023 | case NL80211_IFTYPE_MESH_POINT: | |
4024 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4025 | BIT(NL80211_STA_FLAG_MFP) | | |
4026 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
4027 | default: | |
4028 | return -EINVAL; | |
4029 | } | |
5727ef1b | 4030 | |
3383b5a6 JB |
4031 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
4032 | if (flags[flag]) { | |
eccb8e8f | 4033 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 4034 | |
3383b5a6 JB |
4035 | /* no longer support new API additions in old API */ |
4036 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
4037 | return -EINVAL; | |
4038 | } | |
4039 | } | |
4040 | ||
5727ef1b JB |
4041 | return 0; |
4042 | } | |
4043 | ||
c8dcfd8a FF |
4044 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
4045 | int attr) | |
4046 | { | |
4047 | struct nlattr *rate; | |
8eb41c8d VK |
4048 | u32 bitrate; |
4049 | u16 bitrate_compat; | |
b51f3bee | 4050 | enum nl80211_attrs rate_flg; |
c8dcfd8a FF |
4051 | |
4052 | rate = nla_nest_start(msg, attr); | |
4053 | if (!rate) | |
db9c64cf | 4054 | return false; |
c8dcfd8a FF |
4055 | |
4056 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
4057 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
4058 | /* report 16-bit bitrate only if we can */ |
4059 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
4060 | if (bitrate > 0 && |
4061 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
4062 | return false; | |
4063 | if (bitrate_compat > 0 && | |
4064 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
4065 | return false; | |
4066 | ||
b51f3bee JB |
4067 | switch (info->bw) { |
4068 | case RATE_INFO_BW_5: | |
4069 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; | |
4070 | break; | |
4071 | case RATE_INFO_BW_10: | |
4072 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; | |
4073 | break; | |
4074 | default: | |
4075 | WARN_ON(1); | |
4076 | /* fall through */ | |
4077 | case RATE_INFO_BW_20: | |
4078 | rate_flg = 0; | |
4079 | break; | |
4080 | case RATE_INFO_BW_40: | |
4081 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; | |
4082 | break; | |
4083 | case RATE_INFO_BW_80: | |
4084 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; | |
4085 | break; | |
4086 | case RATE_INFO_BW_160: | |
4087 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; | |
4088 | break; | |
4089 | } | |
4090 | ||
4091 | if (rate_flg && nla_put_flag(msg, rate_flg)) | |
4092 | return false; | |
4093 | ||
db9c64cf JB |
4094 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
4095 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
4096 | return false; | |
db9c64cf JB |
4097 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
4098 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
4099 | return false; | |
4100 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
4101 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
4102 | return false; | |
4103 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
4104 | return false; | |
db9c64cf JB |
4105 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
4106 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
4107 | return false; | |
4108 | } | |
c8dcfd8a FF |
4109 | |
4110 | nla_nest_end(msg, rate); | |
4111 | return true; | |
c8dcfd8a FF |
4112 | } |
4113 | ||
119363c7 FF |
4114 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
4115 | int id) | |
4116 | { | |
4117 | void *attr; | |
4118 | int i = 0; | |
4119 | ||
4120 | if (!mask) | |
4121 | return true; | |
4122 | ||
4123 | attr = nla_nest_start(msg, id); | |
4124 | if (!attr) | |
4125 | return false; | |
4126 | ||
4127 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
4128 | if (!(mask & BIT(i))) | |
4129 | continue; | |
4130 | ||
4131 | if (nla_put_u8(msg, i, signal[i])) | |
4132 | return false; | |
4133 | } | |
4134 | ||
4135 | nla_nest_end(msg, attr); | |
4136 | ||
4137 | return true; | |
4138 | } | |
4139 | ||
cf5ead82 JB |
4140 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
4141 | u32 seq, int flags, | |
66266b3a JL |
4142 | struct cfg80211_registered_device *rdev, |
4143 | struct net_device *dev, | |
98b62183 | 4144 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
4145 | { |
4146 | void *hdr; | |
f4263c98 | 4147 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 4148 | |
cf5ead82 | 4149 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
fd5b74dc JB |
4150 | if (!hdr) |
4151 | return -1; | |
4152 | ||
9360ffd1 DM |
4153 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4154 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
4155 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
4156 | goto nla_put_failure; | |
f5ea9120 | 4157 | |
2ec600d6 LCC |
4158 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
4159 | if (!sinfoattr) | |
fd5b74dc | 4160 | goto nla_put_failure; |
319090bf JB |
4161 | |
4162 | #define PUT_SINFO(attr, memb, type) do { \ | |
d686b920 | 4163 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
739960f1 | 4164 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
319090bf JB |
4165 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
4166 | sinfo->memb)) \ | |
4167 | goto nla_put_failure; \ | |
4168 | } while (0) | |
d686b920 JB |
4169 | #define PUT_SINFO_U64(attr, memb) do { \ |
4170 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ | |
4171 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ | |
4172 | sinfo->memb, NL80211_STA_INFO_PAD)) \ | |
4173 | goto nla_put_failure; \ | |
4174 | } while (0) | |
319090bf JB |
4175 | |
4176 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); | |
4177 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); | |
4178 | ||
4179 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | | |
4180 | BIT(NL80211_STA_INFO_RX_BYTES64)) && | |
9360ffd1 | 4181 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 4182 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 4183 | goto nla_put_failure; |
319090bf JB |
4184 | |
4185 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | | |
4186 | BIT(NL80211_STA_INFO_TX_BYTES64)) && | |
9360ffd1 | 4187 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
4188 | (u32)sinfo->tx_bytes)) |
4189 | goto nla_put_failure; | |
319090bf | 4190 | |
d686b920 JB |
4191 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
4192 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); | |
319090bf JB |
4193 | PUT_SINFO(LLID, llid, u16); |
4194 | PUT_SINFO(PLID, plid, u16); | |
4195 | PUT_SINFO(PLINK_STATE, plink_state, u8); | |
d686b920 | 4196 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
319090bf | 4197 | |
66266b3a JL |
4198 | switch (rdev->wiphy.signal_type) { |
4199 | case CFG80211_SIGNAL_TYPE_MBM: | |
319090bf JB |
4200 | PUT_SINFO(SIGNAL, signal, u8); |
4201 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); | |
66266b3a JL |
4202 | break; |
4203 | default: | |
4204 | break; | |
4205 | } | |
319090bf | 4206 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
119363c7 FF |
4207 | if (!nl80211_put_signal(msg, sinfo->chains, |
4208 | sinfo->chain_signal, | |
4209 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
4210 | goto nla_put_failure; | |
4211 | } | |
319090bf | 4212 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
119363c7 FF |
4213 | if (!nl80211_put_signal(msg, sinfo->chains, |
4214 | sinfo->chain_signal_avg, | |
4215 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
4216 | goto nla_put_failure; | |
4217 | } | |
319090bf | 4218 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
c8dcfd8a FF |
4219 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
4220 | NL80211_STA_INFO_TX_BITRATE)) | |
4221 | goto nla_put_failure; | |
4222 | } | |
319090bf | 4223 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
c8dcfd8a FF |
4224 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
4225 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 4226 | goto nla_put_failure; |
420e7fab | 4227 | } |
319090bf JB |
4228 | |
4229 | PUT_SINFO(RX_PACKETS, rx_packets, u32); | |
4230 | PUT_SINFO(TX_PACKETS, tx_packets, u32); | |
4231 | PUT_SINFO(TX_RETRIES, tx_retries, u32); | |
4232 | PUT_SINFO(TX_FAILED, tx_failed, u32); | |
4233 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); | |
4234 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); | |
4235 | PUT_SINFO(LOCAL_PM, local_pm, u32); | |
4236 | PUT_SINFO(PEER_PM, peer_pm, u32); | |
4237 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); | |
4238 | ||
4239 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { | |
f4263c98 PS |
4240 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
4241 | if (!bss_param) | |
4242 | goto nla_put_failure; | |
4243 | ||
9360ffd1 DM |
4244 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
4245 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
4246 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
4247 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
4248 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
4249 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
4250 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
4251 | sinfo->bss_param.dtim_period) || | |
4252 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
4253 | sinfo->bss_param.beacon_interval)) | |
4254 | goto nla_put_failure; | |
f4263c98 PS |
4255 | |
4256 | nla_nest_end(msg, bss_param); | |
4257 | } | |
319090bf | 4258 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
9360ffd1 DM |
4259 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
4260 | sizeof(struct nl80211_sta_flag_update), | |
4261 | &sinfo->sta_flags)) | |
4262 | goto nla_put_failure; | |
319090bf | 4263 | |
d686b920 JB |
4264 | PUT_SINFO_U64(T_OFFSET, t_offset); |
4265 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); | |
4266 | PUT_SINFO_U64(BEACON_RX, rx_beacon); | |
a76b1942 | 4267 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
319090bf JB |
4268 | |
4269 | #undef PUT_SINFO | |
d686b920 | 4270 | #undef PUT_SINFO_U64 |
6de39808 JB |
4271 | |
4272 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { | |
4273 | struct nlattr *tidsattr; | |
4274 | int tid; | |
4275 | ||
4276 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); | |
4277 | if (!tidsattr) | |
4278 | goto nla_put_failure; | |
4279 | ||
4280 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { | |
4281 | struct cfg80211_tid_stats *tidstats; | |
4282 | struct nlattr *tidattr; | |
4283 | ||
4284 | tidstats = &sinfo->pertid[tid]; | |
4285 | ||
4286 | if (!tidstats->filled) | |
4287 | continue; | |
4288 | ||
4289 | tidattr = nla_nest_start(msg, tid + 1); | |
4290 | if (!tidattr) | |
4291 | goto nla_put_failure; | |
4292 | ||
d686b920 | 4293 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
6de39808 | 4294 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
d686b920 JB |
4295 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
4296 | tidstats->memb, NL80211_TID_STATS_PAD)) \ | |
6de39808 JB |
4297 | goto nla_put_failure; \ |
4298 | } while (0) | |
4299 | ||
d686b920 JB |
4300 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
4301 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); | |
4302 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); | |
4303 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); | |
6de39808 | 4304 | |
d686b920 | 4305 | #undef PUT_TIDVAL_U64 |
6de39808 JB |
4306 | nla_nest_end(msg, tidattr); |
4307 | } | |
4308 | ||
4309 | nla_nest_end(msg, tidsattr); | |
4310 | } | |
4311 | ||
2ec600d6 | 4312 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 4313 | |
319090bf | 4314 | if (sinfo->assoc_req_ies_len && |
9360ffd1 DM |
4315 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
4316 | sinfo->assoc_req_ies)) | |
4317 | goto nla_put_failure; | |
50d3dfb7 | 4318 | |
053c095a JB |
4319 | genlmsg_end(msg, hdr); |
4320 | return 0; | |
fd5b74dc JB |
4321 | |
4322 | nla_put_failure: | |
bc3ed28c TG |
4323 | genlmsg_cancel(msg, hdr); |
4324 | return -EMSGSIZE; | |
fd5b74dc JB |
4325 | } |
4326 | ||
2ec600d6 | 4327 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 4328 | struct netlink_callback *cb) |
2ec600d6 | 4329 | { |
2ec600d6 | 4330 | struct station_info sinfo; |
1b8ec87a | 4331 | struct cfg80211_registered_device *rdev; |
97990a06 | 4332 | struct wireless_dev *wdev; |
2ec600d6 | 4333 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 4334 | int sta_idx = cb->args[2]; |
2ec600d6 | 4335 | int err; |
2ec600d6 | 4336 | |
1b8ec87a | 4337 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
4338 | if (err) |
4339 | return err; | |
bba95fef | 4340 | |
97990a06 JB |
4341 | if (!wdev->netdev) { |
4342 | err = -EINVAL; | |
4343 | goto out_err; | |
4344 | } | |
4345 | ||
1b8ec87a | 4346 | if (!rdev->ops->dump_station) { |
eec60b03 | 4347 | err = -EOPNOTSUPP; |
bba95fef JB |
4348 | goto out_err; |
4349 | } | |
4350 | ||
bba95fef | 4351 | while (1) { |
f612cedf | 4352 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 4353 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
e35e4d28 | 4354 | mac_addr, &sinfo); |
bba95fef JB |
4355 | if (err == -ENOENT) |
4356 | break; | |
4357 | if (err) | |
3b85875a | 4358 | goto out_err; |
bba95fef | 4359 | |
cf5ead82 | 4360 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
15e47304 | 4361 | NETLINK_CB(cb->skb).portid, |
bba95fef | 4362 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 4363 | rdev, wdev->netdev, mac_addr, |
bba95fef JB |
4364 | &sinfo) < 0) |
4365 | goto out; | |
4366 | ||
4367 | sta_idx++; | |
4368 | } | |
4369 | ||
bba95fef | 4370 | out: |
97990a06 | 4371 | cb->args[2] = sta_idx; |
bba95fef | 4372 | err = skb->len; |
bba95fef | 4373 | out_err: |
1b8ec87a | 4374 | nl80211_finish_wdev_dump(rdev); |
bba95fef JB |
4375 | |
4376 | return err; | |
2ec600d6 | 4377 | } |
fd5b74dc | 4378 | |
5727ef1b JB |
4379 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
4380 | { | |
4c476991 JB |
4381 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4382 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 4383 | struct station_info sinfo; |
fd5b74dc JB |
4384 | struct sk_buff *msg; |
4385 | u8 *mac_addr = NULL; | |
4c476991 | 4386 | int err; |
fd5b74dc | 4387 | |
2ec600d6 | 4388 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
4389 | |
4390 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4391 | return -EINVAL; | |
4392 | ||
4393 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4394 | ||
4c476991 JB |
4395 | if (!rdev->ops->get_station) |
4396 | return -EOPNOTSUPP; | |
3b85875a | 4397 | |
e35e4d28 | 4398 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 4399 | if (err) |
4c476991 | 4400 | return err; |
2ec600d6 | 4401 | |
fd2120ca | 4402 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 4403 | if (!msg) |
4c476991 | 4404 | return -ENOMEM; |
fd5b74dc | 4405 | |
cf5ead82 JB |
4406 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
4407 | info->snd_portid, info->snd_seq, 0, | |
66266b3a | 4408 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
4409 | nlmsg_free(msg); |
4410 | return -ENOBUFS; | |
4411 | } | |
3b85875a | 4412 | |
4c476991 | 4413 | return genlmsg_reply(msg, info); |
5727ef1b JB |
4414 | } |
4415 | ||
77ee7c89 JB |
4416 | int cfg80211_check_station_change(struct wiphy *wiphy, |
4417 | struct station_parameters *params, | |
4418 | enum cfg80211_station_type statype) | |
4419 | { | |
e4208427 AB |
4420 | if (params->listen_interval != -1 && |
4421 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
77ee7c89 | 4422 | return -EINVAL; |
e4208427 | 4423 | |
17b94247 AB |
4424 | if (params->support_p2p_ps != -1 && |
4425 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
4426 | return -EINVAL; | |
4427 | ||
c72e1140 | 4428 | if (params->aid && |
e4208427 AB |
4429 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
4430 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
77ee7c89 JB |
4431 | return -EINVAL; |
4432 | ||
4433 | /* When you run into this, adjust the code below for the new flag */ | |
4434 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4435 | ||
4436 | switch (statype) { | |
eef941e6 TP |
4437 | case CFG80211_STA_MESH_PEER_KERNEL: |
4438 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
4439 | /* |
4440 | * No ignoring the TDLS flag here -- the userspace mesh | |
4441 | * code doesn't have the bug of including TDLS in the | |
4442 | * mask everywhere. | |
4443 | */ | |
4444 | if (params->sta_flags_mask & | |
4445 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4446 | BIT(NL80211_STA_FLAG_MFP) | | |
4447 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
4448 | return -EINVAL; | |
4449 | break; | |
4450 | case CFG80211_STA_TDLS_PEER_SETUP: | |
4451 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
4452 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4453 | return -EINVAL; | |
4454 | /* ignore since it can't change */ | |
4455 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
4456 | break; | |
4457 | default: | |
4458 | /* disallow mesh-specific things */ | |
4459 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
4460 | return -EINVAL; | |
4461 | if (params->local_pm) | |
4462 | return -EINVAL; | |
4463 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
4464 | return -EINVAL; | |
4465 | } | |
4466 | ||
4467 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
4468 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
4469 | /* TDLS can't be set, ... */ | |
4470 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4471 | return -EINVAL; | |
4472 | /* | |
4473 | * ... but don't bother the driver with it. This works around | |
4474 | * a hostapd/wpa_supplicant issue -- it always includes the | |
4475 | * TLDS_PEER flag in the mask even for AP mode. | |
4476 | */ | |
4477 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
4478 | } | |
4479 | ||
47edb11b AB |
4480 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
4481 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { | |
77ee7c89 JB |
4482 | /* reject other things that can't change */ |
4483 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
4484 | return -EINVAL; | |
4485 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
4486 | return -EINVAL; | |
4487 | if (params->supported_rates) | |
4488 | return -EINVAL; | |
4489 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
4490 | return -EINVAL; | |
4491 | } | |
4492 | ||
47edb11b AB |
4493 | if (statype != CFG80211_STA_AP_CLIENT && |
4494 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { | |
77ee7c89 JB |
4495 | if (params->vlan) |
4496 | return -EINVAL; | |
4497 | } | |
4498 | ||
4499 | switch (statype) { | |
4500 | case CFG80211_STA_AP_MLME_CLIENT: | |
4501 | /* Use this only for authorizing/unauthorizing a station */ | |
4502 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
4503 | return -EOPNOTSUPP; | |
4504 | break; | |
4505 | case CFG80211_STA_AP_CLIENT: | |
47edb11b | 4506 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
77ee7c89 JB |
4507 | /* accept only the listed bits */ |
4508 | if (params->sta_flags_mask & | |
4509 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4510 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4511 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4512 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
4513 | BIT(NL80211_STA_FLAG_WME) | | |
4514 | BIT(NL80211_STA_FLAG_MFP))) | |
4515 | return -EINVAL; | |
4516 | ||
4517 | /* but authenticated/associated only if driver handles it */ | |
4518 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4519 | params->sta_flags_mask & | |
4520 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4521 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4522 | return -EINVAL; | |
4523 | break; | |
4524 | case CFG80211_STA_IBSS: | |
4525 | case CFG80211_STA_AP_STA: | |
4526 | /* reject any changes other than AUTHORIZED */ | |
4527 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
4528 | return -EINVAL; | |
4529 | break; | |
4530 | case CFG80211_STA_TDLS_PEER_SETUP: | |
4531 | /* reject any changes other than AUTHORIZED or WME */ | |
4532 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4533 | BIT(NL80211_STA_FLAG_WME))) | |
4534 | return -EINVAL; | |
4535 | /* force (at least) rates when authorizing */ | |
4536 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
4537 | !params->supported_rates) | |
4538 | return -EINVAL; | |
4539 | break; | |
4540 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
4541 | /* reject any changes */ | |
4542 | return -EINVAL; | |
eef941e6 | 4543 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
4544 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
4545 | return -EINVAL; | |
4546 | break; | |
eef941e6 | 4547 | case CFG80211_STA_MESH_PEER_USER: |
42925040 CYY |
4548 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
4549 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) | |
77ee7c89 JB |
4550 | return -EINVAL; |
4551 | break; | |
4552 | } | |
4553 | ||
4554 | return 0; | |
4555 | } | |
4556 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
4557 | ||
5727ef1b | 4558 | /* |
c258d2de | 4559 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 4560 | */ |
80b99899 JB |
4561 | static struct net_device *get_vlan(struct genl_info *info, |
4562 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 4563 | { |
463d0183 | 4564 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
4565 | struct net_device *v; |
4566 | int ret; | |
4567 | ||
4568 | if (!vlanattr) | |
4569 | return NULL; | |
4570 | ||
4571 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
4572 | if (!v) | |
4573 | return ERR_PTR(-ENODEV); | |
4574 | ||
4575 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
4576 | ret = -EINVAL; | |
4577 | goto error; | |
5727ef1b | 4578 | } |
80b99899 | 4579 | |
77ee7c89 JB |
4580 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
4581 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4582 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
4583 | ret = -EINVAL; | |
4584 | goto error; | |
4585 | } | |
4586 | ||
80b99899 JB |
4587 | if (!netif_running(v)) { |
4588 | ret = -ENETDOWN; | |
4589 | goto error; | |
4590 | } | |
4591 | ||
4592 | return v; | |
4593 | error: | |
4594 | dev_put(v); | |
4595 | return ERR_PTR(ret); | |
5727ef1b JB |
4596 | } |
4597 | ||
94e860f1 JB |
4598 | static const struct nla_policy |
4599 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
4600 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
4601 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
4602 | }; | |
4603 | ||
ff276691 JB |
4604 | static int nl80211_parse_sta_wme(struct genl_info *info, |
4605 | struct station_parameters *params) | |
df881293 | 4606 | { |
df881293 JM |
4607 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
4608 | struct nlattr *nla; | |
4609 | int err; | |
4610 | ||
df881293 JM |
4611 | /* parse WME attributes if present */ |
4612 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
4613 | return 0; | |
4614 | ||
4615 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
4616 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
4617 | nl80211_sta_wme_policy); | |
4618 | if (err) | |
4619 | return err; | |
4620 | ||
4621 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
4622 | params->uapsd_queues = nla_get_u8( | |
4623 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4624 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
4625 | return -EINVAL; | |
4626 | ||
4627 | if (tb[NL80211_STA_WME_MAX_SP]) | |
4628 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4629 | ||
4630 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
4631 | return -EINVAL; | |
4632 | ||
4633 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
4634 | ||
4635 | return 0; | |
4636 | } | |
4637 | ||
c01fc9ad SD |
4638 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4639 | struct station_parameters *params) | |
4640 | { | |
4641 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4642 | params->supported_channels = | |
4643 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4644 | params->supported_channels_len = | |
4645 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4646 | /* | |
4647 | * Need to include at least one (first channel, number of | |
4648 | * channels) tuple for each subband, and must have proper | |
4649 | * tuples for the rest of the data as well. | |
4650 | */ | |
4651 | if (params->supported_channels_len < 2) | |
4652 | return -EINVAL; | |
4653 | if (params->supported_channels_len % 2) | |
4654 | return -EINVAL; | |
4655 | } | |
4656 | ||
4657 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4658 | params->supported_oper_classes = | |
4659 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4660 | params->supported_oper_classes_len = | |
4661 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4662 | /* | |
4663 | * The value of the Length field of the Supported Operating | |
4664 | * Classes element is between 2 and 253. | |
4665 | */ | |
4666 | if (params->supported_oper_classes_len < 2 || | |
4667 | params->supported_oper_classes_len > 253) | |
4668 | return -EINVAL; | |
4669 | } | |
4670 | return 0; | |
4671 | } | |
4672 | ||
ff276691 JB |
4673 | static int nl80211_set_station_tdls(struct genl_info *info, |
4674 | struct station_parameters *params) | |
4675 | { | |
c01fc9ad | 4676 | int err; |
ff276691 | 4677 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4678 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4679 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4680 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4681 | params->ht_capa = | |
4682 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4683 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4684 | params->vht_capa = | |
4685 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4686 | ||
c01fc9ad SD |
4687 | err = nl80211_parse_sta_channel_info(info, params); |
4688 | if (err) | |
4689 | return err; | |
4690 | ||
ff276691 JB |
4691 | return nl80211_parse_sta_wme(info, params); |
4692 | } | |
4693 | ||
5727ef1b JB |
4694 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4695 | { | |
4c476991 | 4696 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4697 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4698 | struct station_parameters params; |
77ee7c89 JB |
4699 | u8 *mac_addr; |
4700 | int err; | |
5727ef1b JB |
4701 | |
4702 | memset(¶ms, 0, sizeof(params)); | |
4703 | ||
77ee7c89 JB |
4704 | if (!rdev->ops->change_station) |
4705 | return -EOPNOTSUPP; | |
4706 | ||
e4208427 AB |
4707 | /* |
4708 | * AID and listen_interval properties can be set only for unassociated | |
4709 | * station. Include these parameters here and will check them in | |
4710 | * cfg80211_check_station_change(). | |
4711 | */ | |
a9bc31e4 AB |
4712 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4713 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
e4208427 AB |
4714 | |
4715 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | |
4716 | params.listen_interval = | |
4717 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
4718 | else | |
4719 | params.listen_interval = -1; | |
5727ef1b | 4720 | |
17b94247 AB |
4721 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
4722 | u8 tmp; | |
4723 | ||
4724 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); | |
4725 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) | |
4726 | return -EINVAL; | |
4727 | ||
4728 | params.support_p2p_ps = tmp; | |
4729 | } else { | |
4730 | params.support_p2p_ps = -1; | |
4731 | } | |
4732 | ||
5727ef1b JB |
4733 | if (!info->attrs[NL80211_ATTR_MAC]) |
4734 | return -EINVAL; | |
4735 | ||
4736 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4737 | ||
4738 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4739 | params.supported_rates = | |
4740 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4741 | params.supported_rates_len = | |
4742 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4743 | } | |
4744 | ||
9d62a986 JM |
4745 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4746 | params.capability = | |
4747 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4748 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4749 | } | |
4750 | ||
4751 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4752 | params.ext_capab = | |
4753 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4754 | params.ext_capab_len = | |
4755 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4756 | } | |
4757 | ||
bdd3ae3d | 4758 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4759 | return -EINVAL; |
4760 | ||
f8bacc21 | 4761 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4762 | params.plink_action = |
f8bacc21 JB |
4763 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4764 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4765 | return -EINVAL; | |
4766 | } | |
2ec600d6 | 4767 | |
f8bacc21 | 4768 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4769 | params.plink_state = |
f8bacc21 JB |
4770 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4771 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4772 | return -EINVAL; | |
7d27a0ba MH |
4773 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) { |
4774 | params.peer_aid = nla_get_u16( | |
4775 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); | |
4776 | if (params.peer_aid > IEEE80211_MAX_AID) | |
4777 | return -EINVAL; | |
4778 | } | |
f8bacc21 JB |
4779 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
4780 | } | |
9c3990aa | 4781 | |
3b1c5a53 MP |
4782 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4783 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4784 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4785 | ||
4786 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4787 | pm > NL80211_MESH_POWER_MAX) | |
4788 | return -EINVAL; | |
4789 | ||
4790 | params.local_pm = pm; | |
4791 | } | |
4792 | ||
77ee7c89 JB |
4793 | /* Include parameters for TDLS peer (will check later) */ |
4794 | err = nl80211_set_station_tdls(info, ¶ms); | |
4795 | if (err) | |
4796 | return err; | |
4797 | ||
4798 | params.vlan = get_vlan(info, rdev); | |
4799 | if (IS_ERR(params.vlan)) | |
4800 | return PTR_ERR(params.vlan); | |
4801 | ||
a97f4424 JB |
4802 | switch (dev->ieee80211_ptr->iftype) { |
4803 | case NL80211_IFTYPE_AP: | |
4804 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4805 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4806 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4807 | case NL80211_IFTYPE_STATION: |
267335d6 | 4808 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4809 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4810 | break; |
4811 | default: | |
77ee7c89 JB |
4812 | err = -EOPNOTSUPP; |
4813 | goto out_put_vlan; | |
034d655e JB |
4814 | } |
4815 | ||
77ee7c89 | 4816 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4817 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4818 | |
77ee7c89 | 4819 | out_put_vlan: |
5727ef1b JB |
4820 | if (params.vlan) |
4821 | dev_put(params.vlan); | |
3b85875a | 4822 | |
5727ef1b JB |
4823 | return err; |
4824 | } | |
4825 | ||
4826 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4827 | { | |
4c476991 | 4828 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4829 | int err; |
4c476991 | 4830 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4831 | struct station_parameters params; |
4832 | u8 *mac_addr = NULL; | |
bda95eb1 JB |
4833 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
4834 | BIT(NL80211_STA_FLAG_ASSOCIATED); | |
5727ef1b JB |
4835 | |
4836 | memset(¶ms, 0, sizeof(params)); | |
4837 | ||
984c311b JB |
4838 | if (!rdev->ops->add_station) |
4839 | return -EOPNOTSUPP; | |
4840 | ||
5727ef1b JB |
4841 | if (!info->attrs[NL80211_ATTR_MAC]) |
4842 | return -EINVAL; | |
4843 | ||
5727ef1b JB |
4844 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4845 | return -EINVAL; | |
4846 | ||
4847 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4848 | return -EINVAL; | |
4849 | ||
5e4b6f56 JM |
4850 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4851 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4852 | return -EINVAL; |
4853 | ||
5727ef1b JB |
4854 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4855 | params.supported_rates = | |
4856 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4857 | params.supported_rates_len = | |
4858 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4859 | params.listen_interval = | |
4860 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4861 | |
17b94247 AB |
4862 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
4863 | u8 tmp; | |
4864 | ||
4865 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); | |
4866 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) | |
4867 | return -EINVAL; | |
4868 | ||
4869 | params.support_p2p_ps = tmp; | |
4870 | } else { | |
4871 | /* | |
4872 | * if not specified, assume it's supported for P2P GO interface, | |
4873 | * and is NOT supported for AP interface | |
4874 | */ | |
4875 | params.support_p2p_ps = | |
4876 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; | |
4877 | } | |
4878 | ||
3d124ea2 | 4879 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4880 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4881 | else |
4882 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4883 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4884 | return -EINVAL; | |
51b50fbe | 4885 | |
9d62a986 JM |
4886 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4887 | params.capability = | |
4888 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4889 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4890 | } | |
4891 | ||
4892 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4893 | params.ext_capab = | |
4894 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4895 | params.ext_capab_len = | |
4896 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4897 | } | |
4898 | ||
36aedc90 JM |
4899 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4900 | params.ht_capa = | |
4901 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4902 | |
f461be3e MP |
4903 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4904 | params.vht_capa = | |
4905 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4906 | ||
60f4a7b1 MK |
4907 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4908 | params.opmode_notif_used = true; | |
4909 | params.opmode_notif = | |
4910 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4911 | } | |
4912 | ||
f8bacc21 | 4913 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4914 | params.plink_action = |
f8bacc21 JB |
4915 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4916 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4917 | return -EINVAL; | |
4918 | } | |
96b78dff | 4919 | |
c01fc9ad SD |
4920 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4921 | if (err) | |
4922 | return err; | |
4923 | ||
ff276691 JB |
4924 | err = nl80211_parse_sta_wme(info, ¶ms); |
4925 | if (err) | |
4926 | return err; | |
bdd90d5e | 4927 | |
bdd3ae3d | 4928 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4929 | return -EINVAL; |
4930 | ||
496fcc29 JB |
4931 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
4932 | * as userspace might just pass through the capabilities from the IEs | |
4933 | * directly, rather than enforcing this restriction and returning an | |
4934 | * error in this case. | |
4935 | */ | |
4936 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { | |
4937 | params.ht_capa = NULL; | |
4938 | params.vht_capa = NULL; | |
4939 | } | |
4940 | ||
77ee7c89 JB |
4941 | /* When you run into this, adjust the code below for the new flag */ |
4942 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4943 | ||
bdd90d5e JB |
4944 | switch (dev->ieee80211_ptr->iftype) { |
4945 | case NL80211_IFTYPE_AP: | |
4946 | case NL80211_IFTYPE_AP_VLAN: | |
4947 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4948 | /* ignore WME attributes if iface/sta is not capable */ |
4949 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4950 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4951 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4952 | |
bdd90d5e | 4953 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4954 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4955 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4956 | return -EINVAL; |
bdd90d5e JB |
4957 | /* but don't bother the driver with it */ |
4958 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4959 | |
d582cffb JB |
4960 | /* allow authenticated/associated only if driver handles it */ |
4961 | if (!(rdev->wiphy.features & | |
4962 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
bda95eb1 | 4963 | params.sta_flags_mask & auth_assoc) |
d582cffb JB |
4964 | return -EINVAL; |
4965 | ||
bda95eb1 JB |
4966 | /* Older userspace, or userspace wanting to be compatible with |
4967 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth | |
4968 | * and assoc flags in the mask, but assumes the station will be | |
4969 | * added as associated anyway since this was the required driver | |
4970 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was | |
4971 | * introduced. | |
4972 | * In order to not bother drivers with this quirk in the API | |
4973 | * set the flags in both the mask and set for new stations in | |
4974 | * this case. | |
4975 | */ | |
4976 | if (!(params.sta_flags_mask & auth_assoc)) { | |
4977 | params.sta_flags_mask |= auth_assoc; | |
4978 | params.sta_flags_set |= auth_assoc; | |
4979 | } | |
4980 | ||
bdd90d5e JB |
4981 | /* must be last in here for error handling */ |
4982 | params.vlan = get_vlan(info, rdev); | |
4983 | if (IS_ERR(params.vlan)) | |
4984 | return PTR_ERR(params.vlan); | |
4985 | break; | |
4986 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4987 | /* ignore uAPSD data */ |
4988 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4989 | ||
d582cffb JB |
4990 | /* associated is disallowed */ |
4991 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4992 | return -EINVAL; | |
bdd90d5e | 4993 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4994 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4995 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4996 | return -EINVAL; |
4997 | break; | |
4998 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4999 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
5000 | /* ignore uAPSD data */ |
5001 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
5002 | ||
77ee7c89 JB |
5003 | /* these are disallowed */ |
5004 | if (params.sta_flags_mask & | |
5005 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
5006 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 5007 | return -EINVAL; |
bdd90d5e JB |
5008 | /* Only TDLS peers can be added */ |
5009 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
5010 | return -EINVAL; | |
5011 | /* Can only add if TDLS ... */ | |
5012 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
5013 | return -EOPNOTSUPP; | |
5014 | /* ... with external setup is supported */ | |
5015 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
5016 | return -EOPNOTSUPP; | |
77ee7c89 JB |
5017 | /* |
5018 | * Older wpa_supplicant versions always mark the TDLS peer | |
5019 | * as authorized, but it shouldn't yet be. | |
5020 | */ | |
5021 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
5022 | break; |
5023 | default: | |
5024 | return -EOPNOTSUPP; | |
c75786c9 EP |
5025 | } |
5026 | ||
bdd90d5e | 5027 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 5028 | |
e35e4d28 | 5029 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 5030 | |
5727ef1b JB |
5031 | if (params.vlan) |
5032 | dev_put(params.vlan); | |
5727ef1b JB |
5033 | return err; |
5034 | } | |
5035 | ||
5036 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
5037 | { | |
4c476991 JB |
5038 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5039 | struct net_device *dev = info->user_ptr[1]; | |
89c771e5 JM |
5040 | struct station_del_parameters params; |
5041 | ||
5042 | memset(¶ms, 0, sizeof(params)); | |
5727ef1b JB |
5043 | |
5044 | if (info->attrs[NL80211_ATTR_MAC]) | |
89c771e5 | 5045 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5727ef1b | 5046 | |
e80cf853 | 5047 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 5048 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 5049 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
5050 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
5051 | return -EINVAL; | |
5727ef1b | 5052 | |
4c476991 JB |
5053 | if (!rdev->ops->del_station) |
5054 | return -EOPNOTSUPP; | |
3b85875a | 5055 | |
98856866 JM |
5056 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
5057 | params.subtype = | |
5058 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | |
5059 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | |
5060 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | |
5061 | return -EINVAL; | |
5062 | } else { | |
5063 | /* Default to Deauthentication frame */ | |
5064 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | |
5065 | } | |
5066 | ||
5067 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | |
5068 | params.reason_code = | |
5069 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
5070 | if (params.reason_code == 0) | |
5071 | return -EINVAL; /* 0 is reserved */ | |
5072 | } else { | |
5073 | /* Default to reason code 2 */ | |
5074 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | |
5075 | } | |
5076 | ||
89c771e5 | 5077 | return rdev_del_station(rdev, dev, ¶ms); |
5727ef1b JB |
5078 | } |
5079 | ||
15e47304 | 5080 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
5081 | int flags, struct net_device *dev, |
5082 | u8 *dst, u8 *next_hop, | |
5083 | struct mpath_info *pinfo) | |
5084 | { | |
5085 | void *hdr; | |
5086 | struct nlattr *pinfoattr; | |
5087 | ||
1ef4c850 | 5088 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
2ec600d6 LCC |
5089 | if (!hdr) |
5090 | return -1; | |
5091 | ||
9360ffd1 DM |
5092 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5093 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
5094 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
5095 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
5096 | goto nla_put_failure; | |
f5ea9120 | 5097 | |
2ec600d6 LCC |
5098 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
5099 | if (!pinfoattr) | |
5100 | goto nla_put_failure; | |
9360ffd1 DM |
5101 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
5102 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
5103 | pinfo->frame_qlen)) | |
5104 | goto nla_put_failure; | |
5105 | if (((pinfo->filled & MPATH_INFO_SN) && | |
5106 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
5107 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
5108 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
5109 | pinfo->metric)) || | |
5110 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
5111 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
5112 | pinfo->exptime)) || | |
5113 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
5114 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
5115 | pinfo->flags)) || | |
5116 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
5117 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
5118 | pinfo->discovery_timeout)) || | |
5119 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
5120 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
5121 | pinfo->discovery_retries))) | |
5122 | goto nla_put_failure; | |
2ec600d6 LCC |
5123 | |
5124 | nla_nest_end(msg, pinfoattr); | |
5125 | ||
053c095a JB |
5126 | genlmsg_end(msg, hdr); |
5127 | return 0; | |
2ec600d6 LCC |
5128 | |
5129 | nla_put_failure: | |
bc3ed28c TG |
5130 | genlmsg_cancel(msg, hdr); |
5131 | return -EMSGSIZE; | |
2ec600d6 LCC |
5132 | } |
5133 | ||
5134 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 5135 | struct netlink_callback *cb) |
2ec600d6 | 5136 | { |
2ec600d6 | 5137 | struct mpath_info pinfo; |
1b8ec87a | 5138 | struct cfg80211_registered_device *rdev; |
97990a06 | 5139 | struct wireless_dev *wdev; |
2ec600d6 LCC |
5140 | u8 dst[ETH_ALEN]; |
5141 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 5142 | int path_idx = cb->args[2]; |
2ec600d6 | 5143 | int err; |
2ec600d6 | 5144 | |
1b8ec87a | 5145 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
5146 | if (err) |
5147 | return err; | |
bba95fef | 5148 | |
1b8ec87a | 5149 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 5150 | err = -EOPNOTSUPP; |
bba95fef JB |
5151 | goto out_err; |
5152 | } | |
5153 | ||
97990a06 | 5154 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 5155 | err = -EOPNOTSUPP; |
0448b5fc | 5156 | goto out_err; |
eec60b03 JM |
5157 | } |
5158 | ||
bba95fef | 5159 | while (1) { |
1b8ec87a | 5160 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 5161 | next_hop, &pinfo); |
bba95fef | 5162 | if (err == -ENOENT) |
2ec600d6 | 5163 | break; |
bba95fef | 5164 | if (err) |
3b85875a | 5165 | goto out_err; |
2ec600d6 | 5166 | |
15e47304 | 5167 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 5168 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 5169 | wdev->netdev, dst, next_hop, |
bba95fef JB |
5170 | &pinfo) < 0) |
5171 | goto out; | |
2ec600d6 | 5172 | |
bba95fef | 5173 | path_idx++; |
2ec600d6 | 5174 | } |
2ec600d6 | 5175 | |
bba95fef | 5176 | out: |
97990a06 | 5177 | cb->args[2] = path_idx; |
bba95fef | 5178 | err = skb->len; |
bba95fef | 5179 | out_err: |
1b8ec87a | 5180 | nl80211_finish_wdev_dump(rdev); |
bba95fef | 5181 | return err; |
2ec600d6 LCC |
5182 | } |
5183 | ||
5184 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
5185 | { | |
4c476991 | 5186 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 5187 | int err; |
4c476991 | 5188 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
5189 | struct mpath_info pinfo; |
5190 | struct sk_buff *msg; | |
5191 | u8 *dst = NULL; | |
5192 | u8 next_hop[ETH_ALEN]; | |
5193 | ||
5194 | memset(&pinfo, 0, sizeof(pinfo)); | |
5195 | ||
5196 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5197 | return -EINVAL; | |
5198 | ||
5199 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5200 | ||
4c476991 JB |
5201 | if (!rdev->ops->get_mpath) |
5202 | return -EOPNOTSUPP; | |
2ec600d6 | 5203 | |
4c476991 JB |
5204 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
5205 | return -EOPNOTSUPP; | |
eec60b03 | 5206 | |
e35e4d28 | 5207 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 5208 | if (err) |
4c476991 | 5209 | return err; |
2ec600d6 | 5210 | |
fd2120ca | 5211 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 5212 | if (!msg) |
4c476991 | 5213 | return -ENOMEM; |
2ec600d6 | 5214 | |
15e47304 | 5215 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
5216 | dev, dst, next_hop, &pinfo) < 0) { |
5217 | nlmsg_free(msg); | |
5218 | return -ENOBUFS; | |
5219 | } | |
3b85875a | 5220 | |
4c476991 | 5221 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
5222 | } |
5223 | ||
5224 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
5225 | { | |
4c476991 JB |
5226 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5227 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
5228 | u8 *dst = NULL; |
5229 | u8 *next_hop = NULL; | |
5230 | ||
5231 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5232 | return -EINVAL; | |
5233 | ||
5234 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
5235 | return -EINVAL; | |
5236 | ||
5237 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5238 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
5239 | ||
4c476991 JB |
5240 | if (!rdev->ops->change_mpath) |
5241 | return -EOPNOTSUPP; | |
35a8efe1 | 5242 | |
4c476991 JB |
5243 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
5244 | return -EOPNOTSUPP; | |
2ec600d6 | 5245 | |
e35e4d28 | 5246 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 5247 | } |
4c476991 | 5248 | |
2ec600d6 LCC |
5249 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
5250 | { | |
4c476991 JB |
5251 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5252 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
5253 | u8 *dst = NULL; |
5254 | u8 *next_hop = NULL; | |
5255 | ||
5256 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5257 | return -EINVAL; | |
5258 | ||
5259 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
5260 | return -EINVAL; | |
5261 | ||
5262 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5263 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
5264 | ||
4c476991 JB |
5265 | if (!rdev->ops->add_mpath) |
5266 | return -EOPNOTSUPP; | |
35a8efe1 | 5267 | |
4c476991 JB |
5268 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
5269 | return -EOPNOTSUPP; | |
2ec600d6 | 5270 | |
e35e4d28 | 5271 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
5272 | } |
5273 | ||
5274 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
5275 | { | |
4c476991 JB |
5276 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5277 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
5278 | u8 *dst = NULL; |
5279 | ||
5280 | if (info->attrs[NL80211_ATTR_MAC]) | |
5281 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5282 | ||
4c476991 JB |
5283 | if (!rdev->ops->del_mpath) |
5284 | return -EOPNOTSUPP; | |
3b85875a | 5285 | |
e35e4d28 | 5286 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
5287 | } |
5288 | ||
66be7d2b HR |
5289 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
5290 | { | |
5291 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5292 | int err; | |
5293 | struct net_device *dev = info->user_ptr[1]; | |
5294 | struct mpath_info pinfo; | |
5295 | struct sk_buff *msg; | |
5296 | u8 *dst = NULL; | |
5297 | u8 mpp[ETH_ALEN]; | |
5298 | ||
5299 | memset(&pinfo, 0, sizeof(pinfo)); | |
5300 | ||
5301 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5302 | return -EINVAL; | |
5303 | ||
5304 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5305 | ||
5306 | if (!rdev->ops->get_mpp) | |
5307 | return -EOPNOTSUPP; | |
5308 | ||
5309 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
5310 | return -EOPNOTSUPP; | |
5311 | ||
5312 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | |
5313 | if (err) | |
5314 | return err; | |
5315 | ||
5316 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5317 | if (!msg) | |
5318 | return -ENOMEM; | |
5319 | ||
5320 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | |
5321 | dev, dst, mpp, &pinfo) < 0) { | |
5322 | nlmsg_free(msg); | |
5323 | return -ENOBUFS; | |
5324 | } | |
5325 | ||
5326 | return genlmsg_reply(msg, info); | |
5327 | } | |
5328 | ||
5329 | static int nl80211_dump_mpp(struct sk_buff *skb, | |
5330 | struct netlink_callback *cb) | |
5331 | { | |
5332 | struct mpath_info pinfo; | |
5333 | struct cfg80211_registered_device *rdev; | |
5334 | struct wireless_dev *wdev; | |
5335 | u8 dst[ETH_ALEN]; | |
5336 | u8 mpp[ETH_ALEN]; | |
5337 | int path_idx = cb->args[2]; | |
5338 | int err; | |
5339 | ||
5340 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | |
5341 | if (err) | |
5342 | return err; | |
5343 | ||
5344 | if (!rdev->ops->dump_mpp) { | |
5345 | err = -EOPNOTSUPP; | |
5346 | goto out_err; | |
5347 | } | |
5348 | ||
5349 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | |
5350 | err = -EOPNOTSUPP; | |
5351 | goto out_err; | |
5352 | } | |
5353 | ||
5354 | while (1) { | |
5355 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | |
5356 | mpp, &pinfo); | |
5357 | if (err == -ENOENT) | |
5358 | break; | |
5359 | if (err) | |
5360 | goto out_err; | |
5361 | ||
5362 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | |
5363 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
5364 | wdev->netdev, dst, mpp, | |
5365 | &pinfo) < 0) | |
5366 | goto out; | |
5367 | ||
5368 | path_idx++; | |
5369 | } | |
5370 | ||
5371 | out: | |
5372 | cb->args[2] = path_idx; | |
5373 | err = skb->len; | |
5374 | out_err: | |
5375 | nl80211_finish_wdev_dump(rdev); | |
5376 | return err; | |
5377 | } | |
5378 | ||
9f1ba906 JM |
5379 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
5380 | { | |
4c476991 JB |
5381 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5382 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 5383 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 5384 | struct bss_parameters params; |
c56589ed | 5385 | int err; |
9f1ba906 JM |
5386 | |
5387 | memset(¶ms, 0, sizeof(params)); | |
5388 | /* default to not changing parameters */ | |
5389 | params.use_cts_prot = -1; | |
5390 | params.use_short_preamble = -1; | |
5391 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 5392 | params.ap_isolate = -1; |
50b12f59 | 5393 | params.ht_opmode = -1; |
53cabad7 JB |
5394 | params.p2p_ctwindow = -1; |
5395 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
5396 | |
5397 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
5398 | params.use_cts_prot = | |
5399 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
5400 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
5401 | params.use_short_preamble = | |
5402 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
5403 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
5404 | params.use_short_slot_time = | |
5405 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
5406 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
5407 | params.basic_rates = | |
5408 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
5409 | params.basic_rates_len = | |
5410 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
5411 | } | |
fd8aaaf3 FF |
5412 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
5413 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
5414 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
5415 | params.ht_opmode = | |
5416 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 5417 | |
53cabad7 JB |
5418 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
5419 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
5420 | return -EINVAL; | |
5421 | params.p2p_ctwindow = | |
5422 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
5423 | if (params.p2p_ctwindow < 0) | |
5424 | return -EINVAL; | |
5425 | if (params.p2p_ctwindow != 0 && | |
5426 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
5427 | return -EINVAL; | |
5428 | } | |
5429 | ||
5430 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
5431 | u8 tmp; | |
5432 | ||
5433 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
5434 | return -EINVAL; | |
5435 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
5436 | if (tmp > 1) | |
5437 | return -EINVAL; | |
5438 | params.p2p_opp_ps = tmp; | |
5439 | if (params.p2p_opp_ps && | |
5440 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
5441 | return -EINVAL; | |
5442 | } | |
5443 | ||
4c476991 JB |
5444 | if (!rdev->ops->change_bss) |
5445 | return -EOPNOTSUPP; | |
9f1ba906 | 5446 | |
074ac8df | 5447 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
5448 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
5449 | return -EOPNOTSUPP; | |
3b85875a | 5450 | |
c56589ed SW |
5451 | wdev_lock(wdev); |
5452 | err = rdev_change_bss(rdev, dev, ¶ms); | |
5453 | wdev_unlock(wdev); | |
5454 | ||
5455 | return err; | |
9f1ba906 JM |
5456 | } |
5457 | ||
b2e1b302 LR |
5458 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
5459 | { | |
b2e1b302 | 5460 | char *data = NULL; |
05050753 | 5461 | bool is_indoor; |
57b5ce07 | 5462 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
05050753 I |
5463 | u32 owner_nlportid; |
5464 | ||
80778f18 LR |
5465 | /* |
5466 | * You should only get this when cfg80211 hasn't yet initialized | |
5467 | * completely when built-in to the kernel right between the time | |
5468 | * window between nl80211_init() and regulatory_init(), if that is | |
5469 | * even possible. | |
5470 | */ | |
458f4f9e | 5471 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 5472 | return -EINPROGRESS; |
80778f18 | 5473 | |
57b5ce07 LR |
5474 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
5475 | user_reg_hint_type = | |
5476 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
5477 | else | |
5478 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
5479 | ||
5480 | switch (user_reg_hint_type) { | |
5481 | case NL80211_USER_REG_HINT_USER: | |
5482 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
5483 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
5484 | return -EINVAL; | |
5485 | ||
5486 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5487 | return regulatory_hint_user(data, user_reg_hint_type); | |
5488 | case NL80211_USER_REG_HINT_INDOOR: | |
05050753 I |
5489 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
5490 | owner_nlportid = info->snd_portid; | |
5491 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; | |
5492 | } else { | |
5493 | owner_nlportid = 0; | |
5494 | is_indoor = true; | |
5495 | } | |
5496 | ||
5497 | return regulatory_hint_indoor(is_indoor, owner_nlportid); | |
57b5ce07 LR |
5498 | default: |
5499 | return -EINVAL; | |
5500 | } | |
b2e1b302 LR |
5501 | } |
5502 | ||
24bdd9f4 | 5503 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 5504 | struct genl_info *info) |
93da9cc1 | 5505 | { |
4c476991 | 5506 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 5507 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
5508 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5509 | struct mesh_config cur_params; | |
5510 | int err = 0; | |
93da9cc1 | 5511 | void *hdr; |
5512 | struct nlattr *pinfoattr; | |
5513 | struct sk_buff *msg; | |
5514 | ||
29cbe68c JB |
5515 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5516 | return -EOPNOTSUPP; | |
5517 | ||
24bdd9f4 | 5518 | if (!rdev->ops->get_mesh_config) |
4c476991 | 5519 | return -EOPNOTSUPP; |
f3f92586 | 5520 | |
29cbe68c JB |
5521 | wdev_lock(wdev); |
5522 | /* If not connected, get default parameters */ | |
5523 | if (!wdev->mesh_id_len) | |
5524 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
5525 | else | |
e35e4d28 | 5526 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
5527 | wdev_unlock(wdev); |
5528 | ||
93da9cc1 | 5529 | if (err) |
4c476991 | 5530 | return err; |
93da9cc1 | 5531 | |
5532 | /* Draw up a netlink message to send back */ | |
fd2120ca | 5533 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
5534 | if (!msg) |
5535 | return -ENOMEM; | |
15e47304 | 5536 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 5537 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 5538 | if (!hdr) |
efe1cf0c | 5539 | goto out; |
24bdd9f4 | 5540 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 5541 | if (!pinfoattr) |
5542 | goto nla_put_failure; | |
9360ffd1 DM |
5543 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5544 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
5545 | cur_params.dot11MeshRetryTimeout) || | |
5546 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
5547 | cur_params.dot11MeshConfirmTimeout) || | |
5548 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
5549 | cur_params.dot11MeshHoldingTimeout) || | |
5550 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
5551 | cur_params.dot11MeshMaxPeerLinks) || | |
5552 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
5553 | cur_params.dot11MeshMaxRetries) || | |
5554 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
5555 | cur_params.dot11MeshTTL) || | |
5556 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
5557 | cur_params.element_ttl) || | |
5558 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
5559 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
5560 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5561 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
5562 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5563 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
5564 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
5565 | cur_params.path_refresh_time) || | |
5566 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
5567 | cur_params.min_discovery_timeout) || | |
5568 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
5569 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
5570 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
5571 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
5572 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
5573 | cur_params.dot11MeshHWMPperrMinInterval) || | |
5574 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
5575 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
5576 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5577 | cur_params.dot11MeshHWMPRootMode) || | |
5578 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
5579 | cur_params.dot11MeshHWMPRannInterval) || | |
5580 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
5581 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
5582 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
5583 | cur_params.dot11MeshForwarding) || | |
5584 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
5585 | cur_params.rssi_threshold) || |
5586 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
5587 | cur_params.ht_opmode) || |
5588 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
5589 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
5590 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
5591 | cur_params.dot11MeshHWMProotInterval) || |
5592 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
5593 | cur_params.dot11MeshHWMPconfirmationInterval) || |
5594 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
5595 | cur_params.power_mode) || | |
5596 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
5597 | cur_params.dot11MeshAwakeWindowDuration) || |
5598 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5599 | cur_params.plink_timeout)) | |
9360ffd1 | 5600 | goto nla_put_failure; |
93da9cc1 | 5601 | nla_nest_end(msg, pinfoattr); |
5602 | genlmsg_end(msg, hdr); | |
4c476991 | 5603 | return genlmsg_reply(msg, info); |
93da9cc1 | 5604 | |
3b85875a | 5605 | nla_put_failure: |
93da9cc1 | 5606 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 5607 | out: |
d080e275 | 5608 | nlmsg_free(msg); |
4c476991 | 5609 | return -ENOBUFS; |
93da9cc1 | 5610 | } |
5611 | ||
b54452b0 | 5612 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 5613 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
5614 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
5615 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
5616 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
5617 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
5618 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 5619 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 5620 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 5621 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 5622 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
5623 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
5624 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
5625 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
5626 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 5627 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 5628 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 5629 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 5630 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 5631 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 5632 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
5633 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
5634 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
5635 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
5636 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 5637 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
5638 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
5639 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 5640 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 5641 | }; |
5642 | ||
c80d545d JC |
5643 | static const struct nla_policy |
5644 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 5645 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
5646 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
5647 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 5648 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 5649 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 5650 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 5651 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 5652 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 5653 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
5654 | }; |
5655 | ||
f151d9db AB |
5656 | static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out) |
5657 | { | |
5658 | u8 val = nla_get_u8(nla); | |
5659 | if (val < min || val > max) | |
5660 | return -EINVAL; | |
5661 | *out = val; | |
5662 | return 0; | |
5663 | } | |
5664 | ||
5665 | static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out) | |
5666 | { | |
5667 | u8 val = nla_get_u8(nla); | |
5668 | if (val < min || val > max) | |
5669 | return -EINVAL; | |
5670 | *out = val; | |
5671 | return 0; | |
5672 | } | |
5673 | ||
5674 | static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out) | |
5675 | { | |
5676 | u16 val = nla_get_u16(nla); | |
5677 | if (val < min || val > max) | |
5678 | return -EINVAL; | |
5679 | *out = val; | |
5680 | return 0; | |
5681 | } | |
5682 | ||
5683 | static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out) | |
5684 | { | |
5685 | u32 val = nla_get_u32(nla); | |
5686 | if (val < min || val > max) | |
5687 | return -EINVAL; | |
5688 | *out = val; | |
5689 | return 0; | |
5690 | } | |
5691 | ||
5692 | static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out) | |
5693 | { | |
5694 | s32 val = nla_get_s32(nla); | |
5695 | if (val < min || val > max) | |
5696 | return -EINVAL; | |
5697 | *out = val; | |
5698 | return 0; | |
5699 | } | |
5700 | ||
ff9a71af JB |
5701 | static int nl80211_check_power_mode(const struct nlattr *nla, |
5702 | enum nl80211_mesh_power_mode min, | |
5703 | enum nl80211_mesh_power_mode max, | |
5704 | enum nl80211_mesh_power_mode *out) | |
5705 | { | |
5706 | u32 val = nla_get_u32(nla); | |
5707 | if (val < min || val > max) | |
5708 | return -EINVAL; | |
5709 | *out = val; | |
5710 | return 0; | |
5711 | } | |
5712 | ||
24bdd9f4 | 5713 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
5714 | struct mesh_config *cfg, |
5715 | u32 *mask_out) | |
93da9cc1 | 5716 | { |
93da9cc1 | 5717 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 5718 | u32 mask = 0; |
9757235f | 5719 | u16 ht_opmode; |
93da9cc1 | 5720 | |
ea54fba2 MP |
5721 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
5722 | do { \ | |
5723 | if (tb[attr]) { \ | |
f151d9db | 5724 | if (fn(tb[attr], min, max, &cfg->param)) \ |
ea54fba2 | 5725 | return -EINVAL; \ |
ea54fba2 MP |
5726 | mask |= (1 << (attr - 1)); \ |
5727 | } \ | |
5728 | } while (0) | |
bd90fdcc | 5729 | |
24bdd9f4 | 5730 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 5731 | return -EINVAL; |
5732 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 5733 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 5734 | nl80211_meshconf_params_policy)) |
93da9cc1 | 5735 | return -EINVAL; |
5736 | ||
93da9cc1 | 5737 | /* This makes sure that there aren't more than 32 mesh config |
5738 | * parameters (otherwise our bitfield scheme would not work.) */ | |
5739 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
5740 | ||
5741 | /* Fill in the params struct */ | |
ea54fba2 | 5742 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea | 5743 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
f151d9db | 5744 | nl80211_check_u16); |
ea54fba2 | 5745 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea | 5746 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
f151d9db | 5747 | nl80211_check_u16); |
ea54fba2 | 5748 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea | 5749 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
f151d9db | 5750 | nl80211_check_u16); |
ea54fba2 | 5751 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea | 5752 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
f151d9db | 5753 | nl80211_check_u16); |
ea54fba2 | 5754 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea | 5755 | mask, NL80211_MESHCONF_MAX_RETRIES, |
f151d9db | 5756 | nl80211_check_u8); |
ea54fba2 | 5757 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
f151d9db | 5758 | mask, NL80211_MESHCONF_TTL, nl80211_check_u8); |
ea54fba2 | 5759 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea | 5760 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
f151d9db | 5761 | nl80211_check_u8); |
ea54fba2 | 5762 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea | 5763 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
f151d9db | 5764 | nl80211_check_bool); |
ea54fba2 MP |
5765 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
5766 | 1, 255, mask, | |
a4f606ea | 5767 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
f151d9db | 5768 | nl80211_check_u32); |
ea54fba2 | 5769 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea | 5770 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
f151d9db | 5771 | nl80211_check_u8); |
ea54fba2 | 5772 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea | 5773 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
f151d9db | 5774 | nl80211_check_u32); |
ea54fba2 | 5775 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea | 5776 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
f151d9db | 5777 | nl80211_check_u16); |
ea54fba2 MP |
5778 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
5779 | 1, 65535, mask, | |
a4f606ea | 5780 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
f151d9db | 5781 | nl80211_check_u32); |
93da9cc1 | 5782 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
5783 | 1, 65535, mask, |
5784 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
f151d9db | 5785 | nl80211_check_u16); |
dca7e943 | 5786 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
5787 | 1, 65535, mask, |
5788 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
f151d9db | 5789 | nl80211_check_u16); |
93da9cc1 | 5790 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5791 | dot11MeshHWMPnetDiameterTraversalTime, |
5792 | 1, 65535, mask, | |
a4f606ea | 5793 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
f151d9db | 5794 | nl80211_check_u16); |
ea54fba2 MP |
5795 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
5796 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
f151d9db | 5797 | nl80211_check_u8); |
ea54fba2 MP |
5798 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
5799 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
f151d9db | 5800 | nl80211_check_u16); |
63c5723b | 5801 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5802 | dot11MeshGateAnnouncementProtocol, 0, 1, |
5803 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
f151d9db | 5804 | nl80211_check_bool); |
ea54fba2 | 5805 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea | 5806 | mask, NL80211_MESHCONF_FORWARDING, |
f151d9db | 5807 | nl80211_check_bool); |
83374fe9 | 5808 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 5809 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
f151d9db | 5810 | nl80211_check_s32); |
9757235f MH |
5811 | /* |
5812 | * Check HT operation mode based on | |
5813 | * IEEE 802.11 2012 8.4.2.59 HT Operation element. | |
5814 | */ | |
5815 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { | |
5816 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); | |
5817 | ||
5818 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | | |
5819 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | | |
5820 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) | |
5821 | return -EINVAL; | |
5822 | ||
5823 | if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) && | |
5824 | (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) | |
5825 | return -EINVAL; | |
5826 | ||
5827 | switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) { | |
5828 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: | |
5829 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: | |
5830 | if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) | |
5831 | return -EINVAL; | |
5832 | break; | |
5833 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: | |
5834 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: | |
5835 | if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) | |
5836 | return -EINVAL; | |
5837 | break; | |
5838 | } | |
5839 | cfg->ht_opmode = ht_opmode; | |
5840 | } | |
ac1073a6 | 5841 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
ea54fba2 | 5842 | 1, 65535, mask, |
ac1073a6 | 5843 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
f151d9db | 5844 | nl80211_check_u32); |
ea54fba2 | 5845 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 5846 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
f151d9db | 5847 | nl80211_check_u16); |
728b19e5 | 5848 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5849 | dot11MeshHWMPconfirmationInterval, |
5850 | 1, 65535, mask, | |
728b19e5 | 5851 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
f151d9db | 5852 | nl80211_check_u16); |
3b1c5a53 MP |
5853 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
5854 | NL80211_MESH_POWER_ACTIVE, | |
5855 | NL80211_MESH_POWER_MAX, | |
5856 | mask, NL80211_MESHCONF_POWER_MODE, | |
ff9a71af | 5857 | nl80211_check_power_mode); |
3b1c5a53 MP |
5858 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
5859 | 0, 65535, mask, | |
f151d9db | 5860 | NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16); |
31f909a2 | 5861 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
8e7c0538 | 5862 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
f151d9db | 5863 | nl80211_check_u32); |
bd90fdcc JB |
5864 | if (mask_out) |
5865 | *mask_out = mask; | |
c80d545d | 5866 | |
bd90fdcc JB |
5867 | return 0; |
5868 | ||
5869 | #undef FILL_IN_MESH_PARAM_IF_SET | |
5870 | } | |
5871 | ||
c80d545d JC |
5872 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
5873 | struct mesh_setup *setup) | |
5874 | { | |
bb2798d4 | 5875 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
5876 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
5877 | ||
5878 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
5879 | return -EINVAL; | |
5880 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
5881 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
5882 | nl80211_mesh_setup_params_policy)) | |
5883 | return -EINVAL; | |
5884 | ||
d299a1f2 JC |
5885 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
5886 | setup->sync_method = | |
5887 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
5888 | IEEE80211_SYNC_METHOD_VENDOR : | |
5889 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
5890 | ||
c80d545d JC |
5891 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
5892 | setup->path_sel_proto = | |
5893 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5894 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5895 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5896 | ||
5897 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5898 | setup->path_metric = | |
5899 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5900 | IEEE80211_PATH_METRIC_VENDOR : | |
5901 | IEEE80211_PATH_METRIC_AIRTIME; | |
5902 | ||
581a8b0f | 5903 | if (tb[NL80211_MESH_SETUP_IE]) { |
c80d545d | 5904 | struct nlattr *ieattr = |
581a8b0f | 5905 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5906 | if (!is_valid_ie_attr(ieattr)) |
5907 | return -EINVAL; | |
581a8b0f JC |
5908 | setup->ie = nla_data(ieattr); |
5909 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5910 | } |
bb2798d4 TP |
5911 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5912 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5913 | return -EINVAL; | |
5914 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5915 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5916 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5917 | if (setup->is_secure) |
5918 | setup->user_mpm = true; | |
c80d545d | 5919 | |
6e16d90b CT |
5920 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5921 | if (!setup->user_mpm) | |
5922 | return -EINVAL; | |
5923 | setup->auth_id = | |
5924 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5925 | } | |
5926 | ||
c80d545d JC |
5927 | return 0; |
5928 | } | |
5929 | ||
24bdd9f4 | 5930 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5931 | struct genl_info *info) |
bd90fdcc JB |
5932 | { |
5933 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5934 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5935 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5936 | struct mesh_config cfg; |
5937 | u32 mask; | |
5938 | int err; | |
5939 | ||
29cbe68c JB |
5940 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5941 | return -EOPNOTSUPP; | |
5942 | ||
24bdd9f4 | 5943 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5944 | return -EOPNOTSUPP; |
5945 | ||
24bdd9f4 | 5946 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5947 | if (err) |
5948 | return err; | |
5949 | ||
29cbe68c JB |
5950 | wdev_lock(wdev); |
5951 | if (!wdev->mesh_id_len) | |
5952 | err = -ENOLINK; | |
5953 | ||
5954 | if (!err) | |
e35e4d28 | 5955 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5956 | |
5957 | wdev_unlock(wdev); | |
5958 | ||
5959 | return err; | |
93da9cc1 | 5960 | } |
5961 | ||
ad30ca2c AN |
5962 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
5963 | struct sk_buff *msg) | |
f130347c | 5964 | { |
f130347c LR |
5965 | struct nlattr *nl_reg_rules; |
5966 | unsigned int i; | |
f130347c | 5967 | |
458f4f9e JB |
5968 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
5969 | (regdom->dfs_region && | |
5970 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
ad30ca2c | 5971 | goto nla_put_failure; |
458f4f9e | 5972 | |
f130347c LR |
5973 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5974 | if (!nl_reg_rules) | |
ad30ca2c | 5975 | goto nla_put_failure; |
f130347c | 5976 | |
458f4f9e | 5977 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5978 | struct nlattr *nl_reg_rule; |
5979 | const struct ieee80211_reg_rule *reg_rule; | |
5980 | const struct ieee80211_freq_range *freq_range; | |
5981 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 5982 | unsigned int max_bandwidth_khz; |
f130347c | 5983 | |
458f4f9e | 5984 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5985 | freq_range = ®_rule->freq_range; |
5986 | power_rule = ®_rule->power_rule; | |
5987 | ||
5988 | nl_reg_rule = nla_nest_start(msg, i); | |
5989 | if (!nl_reg_rule) | |
ad30ca2c | 5990 | goto nla_put_failure; |
f130347c | 5991 | |
97524820 JD |
5992 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
5993 | if (!max_bandwidth_khz) | |
5994 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
5995 | reg_rule); | |
5996 | ||
9360ffd1 DM |
5997 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5998 | reg_rule->flags) || | |
5999 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
6000 | freq_range->start_freq_khz) || | |
6001 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
6002 | freq_range->end_freq_khz) || | |
6003 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 6004 | max_bandwidth_khz) || |
9360ffd1 DM |
6005 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
6006 | power_rule->max_antenna_gain) || | |
6007 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
6008 | power_rule->max_eirp) || |
6009 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
6010 | reg_rule->dfs_cac_ms)) | |
ad30ca2c | 6011 | goto nla_put_failure; |
f130347c LR |
6012 | |
6013 | nla_nest_end(msg, nl_reg_rule); | |
6014 | } | |
6015 | ||
6016 | nla_nest_end(msg, nl_reg_rules); | |
ad30ca2c AN |
6017 | return 0; |
6018 | ||
6019 | nla_put_failure: | |
6020 | return -EMSGSIZE; | |
6021 | } | |
6022 | ||
6023 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) | |
6024 | { | |
6025 | const struct ieee80211_regdomain *regdom = NULL; | |
6026 | struct cfg80211_registered_device *rdev; | |
6027 | struct wiphy *wiphy = NULL; | |
6028 | struct sk_buff *msg; | |
6029 | void *hdr; | |
6030 | ||
6031 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
6032 | if (!msg) | |
6033 | return -ENOBUFS; | |
6034 | ||
6035 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
6036 | NL80211_CMD_GET_REG); | |
6037 | if (!hdr) | |
6038 | goto put_failure; | |
6039 | ||
6040 | if (info->attrs[NL80211_ATTR_WIPHY]) { | |
1bdd716c AN |
6041 | bool self_managed; |
6042 | ||
ad30ca2c AN |
6043 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
6044 | if (IS_ERR(rdev)) { | |
6045 | nlmsg_free(msg); | |
6046 | return PTR_ERR(rdev); | |
6047 | } | |
6048 | ||
6049 | wiphy = &rdev->wiphy; | |
1bdd716c AN |
6050 | self_managed = wiphy->regulatory_flags & |
6051 | REGULATORY_WIPHY_SELF_MANAGED; | |
ad30ca2c AN |
6052 | regdom = get_wiphy_regdom(wiphy); |
6053 | ||
1bdd716c AN |
6054 | /* a self-managed-reg device must have a private regdom */ |
6055 | if (WARN_ON(!regdom && self_managed)) { | |
6056 | nlmsg_free(msg); | |
6057 | return -EINVAL; | |
6058 | } | |
6059 | ||
ad30ca2c AN |
6060 | if (regdom && |
6061 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
6062 | goto nla_put_failure; | |
6063 | } | |
6064 | ||
6065 | if (!wiphy && reg_last_request_cell_base() && | |
6066 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
6067 | NL80211_USER_REG_HINT_CELL_BASE)) | |
6068 | goto nla_put_failure; | |
6069 | ||
6070 | rcu_read_lock(); | |
6071 | ||
6072 | if (!regdom) | |
6073 | regdom = rcu_dereference(cfg80211_regdomain); | |
6074 | ||
6075 | if (nl80211_put_regdom(regdom, msg)) | |
6076 | goto nla_put_failure_rcu; | |
6077 | ||
6078 | rcu_read_unlock(); | |
f130347c LR |
6079 | |
6080 | genlmsg_end(msg, hdr); | |
5fe231e8 | 6081 | return genlmsg_reply(msg, info); |
f130347c | 6082 | |
458f4f9e JB |
6083 | nla_put_failure_rcu: |
6084 | rcu_read_unlock(); | |
f130347c LR |
6085 | nla_put_failure: |
6086 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 6087 | put_failure: |
d080e275 | 6088 | nlmsg_free(msg); |
5fe231e8 | 6089 | return -EMSGSIZE; |
f130347c LR |
6090 | } |
6091 | ||
ad30ca2c AN |
6092 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
6093 | u32 seq, int flags, struct wiphy *wiphy, | |
6094 | const struct ieee80211_regdomain *regdom) | |
6095 | { | |
6096 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | |
6097 | NL80211_CMD_GET_REG); | |
6098 | ||
6099 | if (!hdr) | |
6100 | return -1; | |
6101 | ||
6102 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); | |
6103 | ||
6104 | if (nl80211_put_regdom(regdom, msg)) | |
6105 | goto nla_put_failure; | |
6106 | ||
6107 | if (!wiphy && reg_last_request_cell_base() && | |
6108 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
6109 | NL80211_USER_REG_HINT_CELL_BASE)) | |
6110 | goto nla_put_failure; | |
6111 | ||
6112 | if (wiphy && | |
6113 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
6114 | goto nla_put_failure; | |
6115 | ||
1bdd716c AN |
6116 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
6117 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
6118 | goto nla_put_failure; | |
6119 | ||
053c095a JB |
6120 | genlmsg_end(msg, hdr); |
6121 | return 0; | |
ad30ca2c AN |
6122 | |
6123 | nla_put_failure: | |
6124 | genlmsg_cancel(msg, hdr); | |
6125 | return -EMSGSIZE; | |
6126 | } | |
6127 | ||
6128 | static int nl80211_get_reg_dump(struct sk_buff *skb, | |
6129 | struct netlink_callback *cb) | |
6130 | { | |
6131 | const struct ieee80211_regdomain *regdom = NULL; | |
6132 | struct cfg80211_registered_device *rdev; | |
6133 | int err, reg_idx, start = cb->args[2]; | |
6134 | ||
6135 | rtnl_lock(); | |
6136 | ||
6137 | if (cfg80211_regdomain && start == 0) { | |
6138 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
6139 | NLM_F_MULTI, NULL, | |
6140 | rtnl_dereference(cfg80211_regdomain)); | |
6141 | if (err < 0) | |
6142 | goto out_err; | |
6143 | } | |
6144 | ||
6145 | /* the global regdom is idx 0 */ | |
6146 | reg_idx = 1; | |
6147 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | |
6148 | regdom = get_wiphy_regdom(&rdev->wiphy); | |
6149 | if (!regdom) | |
6150 | continue; | |
6151 | ||
6152 | if (++reg_idx <= start) | |
6153 | continue; | |
6154 | ||
6155 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
6156 | NLM_F_MULTI, &rdev->wiphy, regdom); | |
6157 | if (err < 0) { | |
6158 | reg_idx--; | |
6159 | break; | |
6160 | } | |
6161 | } | |
6162 | ||
6163 | cb->args[2] = reg_idx; | |
6164 | err = skb->len; | |
6165 | out_err: | |
6166 | rtnl_unlock(); | |
6167 | return err; | |
6168 | } | |
6169 | ||
b6863036 JB |
6170 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
6171 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { | |
6172 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, | |
6173 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
6174 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
6175 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
6176 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
6177 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
6178 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, | |
6179 | }; | |
6180 | ||
6181 | static int parse_reg_rule(struct nlattr *tb[], | |
6182 | struct ieee80211_reg_rule *reg_rule) | |
6183 | { | |
6184 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
6185 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
6186 | ||
6187 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
6188 | return -EINVAL; | |
6189 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
6190 | return -EINVAL; | |
6191 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
6192 | return -EINVAL; | |
6193 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
6194 | return -EINVAL; | |
6195 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
6196 | return -EINVAL; | |
6197 | ||
6198 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
6199 | ||
6200 | freq_range->start_freq_khz = | |
6201 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
6202 | freq_range->end_freq_khz = | |
6203 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
6204 | freq_range->max_bandwidth_khz = | |
6205 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
6206 | ||
6207 | power_rule->max_eirp = | |
6208 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
6209 | ||
6210 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
6211 | power_rule->max_antenna_gain = | |
6212 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
6213 | ||
6214 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) | |
6215 | reg_rule->dfs_cac_ms = | |
6216 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
6217 | ||
6218 | return 0; | |
6219 | } | |
6220 | ||
b2e1b302 LR |
6221 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
6222 | { | |
6223 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
6224 | struct nlattr *nl_reg_rule; | |
ea372c54 JB |
6225 | char *alpha2; |
6226 | int rem_reg_rules, r; | |
b2e1b302 | 6227 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
4c7d3982 | 6228 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
ea372c54 | 6229 | struct ieee80211_regdomain *rd; |
b2e1b302 LR |
6230 | |
6231 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
6232 | return -EINVAL; | |
6233 | ||
6234 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
6235 | return -EINVAL; | |
6236 | ||
6237 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
6238 | ||
8b60b078 LR |
6239 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
6240 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
6241 | ||
b2e1b302 | 6242 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 6243 | rem_reg_rules) { |
b2e1b302 LR |
6244 | num_rules++; |
6245 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 6246 | return -EINVAL; |
b2e1b302 LR |
6247 | } |
6248 | ||
e438768f LR |
6249 | if (!reg_is_valid_request(alpha2)) |
6250 | return -EINVAL; | |
6251 | ||
b2e1b302 | 6252 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 6253 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
6254 | |
6255 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
6256 | if (!rd) |
6257 | return -ENOMEM; | |
b2e1b302 LR |
6258 | |
6259 | rd->n_reg_rules = num_rules; | |
6260 | rd->alpha2[0] = alpha2[0]; | |
6261 | rd->alpha2[1] = alpha2[1]; | |
6262 | ||
8b60b078 LR |
6263 | /* |
6264 | * Disable DFS master mode if the DFS region was | |
6265 | * not supported or known on this kernel. | |
6266 | */ | |
6267 | if (reg_supported_dfs_region(dfs_region)) | |
6268 | rd->dfs_region = dfs_region; | |
6269 | ||
b2e1b302 | 6270 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 6271 | rem_reg_rules) { |
ae811e21 JB |
6272 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
6273 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
6274 | reg_rule_policy); | |
6275 | if (r) | |
6276 | goto bad_reg; | |
b2e1b302 LR |
6277 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
6278 | if (r) | |
6279 | goto bad_reg; | |
6280 | ||
6281 | rule_idx++; | |
6282 | ||
d0e18f83 LR |
6283 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
6284 | r = -EINVAL; | |
b2e1b302 | 6285 | goto bad_reg; |
d0e18f83 | 6286 | } |
b2e1b302 LR |
6287 | } |
6288 | ||
06627990 JB |
6289 | /* set_regdom takes ownership of rd */ |
6290 | return set_regdom(rd, REGD_SOURCE_CRDA); | |
d2372b31 | 6291 | bad_reg: |
b2e1b302 | 6292 | kfree(rd); |
d0e18f83 | 6293 | return r; |
b2e1b302 | 6294 | } |
b6863036 | 6295 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
b2e1b302 | 6296 | |
83f5e2cf JB |
6297 | static int validate_scan_freqs(struct nlattr *freqs) |
6298 | { | |
6299 | struct nlattr *attr1, *attr2; | |
6300 | int n_channels = 0, tmp1, tmp2; | |
6301 | ||
6302 | nla_for_each_nested(attr1, freqs, tmp1) { | |
6303 | n_channels++; | |
6304 | /* | |
6305 | * Some hardware has a limited channel list for | |
6306 | * scanning, and it is pretty much nonsensical | |
6307 | * to scan for a channel twice, so disallow that | |
6308 | * and don't require drivers to check that the | |
6309 | * channel list they get isn't longer than what | |
6310 | * they can scan, as long as they can scan all | |
6311 | * the channels they registered at once. | |
6312 | */ | |
6313 | nla_for_each_nested(attr2, freqs, tmp2) | |
6314 | if (attr1 != attr2 && | |
6315 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
6316 | return 0; | |
6317 | } | |
6318 | ||
6319 | return n_channels; | |
6320 | } | |
6321 | ||
57fbcce3 | 6322 | static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) |
38de03d2 | 6323 | { |
57fbcce3 | 6324 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
38de03d2 AS |
6325 | } |
6326 | ||
6327 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, | |
6328 | struct cfg80211_bss_selection *bss_select) | |
6329 | { | |
6330 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; | |
6331 | struct nlattr *nest; | |
6332 | int err; | |
6333 | bool found = false; | |
6334 | int i; | |
6335 | ||
6336 | /* only process one nested attribute */ | |
6337 | nest = nla_data(nla); | |
6338 | if (!nla_ok(nest, nla_len(nest))) | |
6339 | return -EINVAL; | |
6340 | ||
6341 | err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest), | |
6342 | nla_len(nest), nl80211_bss_select_policy); | |
6343 | if (err) | |
6344 | return err; | |
6345 | ||
6346 | /* only one attribute may be given */ | |
6347 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { | |
6348 | if (attr[i]) { | |
6349 | if (found) | |
6350 | return -EINVAL; | |
6351 | found = true; | |
6352 | } | |
6353 | } | |
6354 | ||
6355 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; | |
6356 | ||
6357 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) | |
6358 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; | |
6359 | ||
6360 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { | |
6361 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; | |
6362 | bss_select->param.band_pref = | |
6363 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); | |
6364 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) | |
6365 | return -EINVAL; | |
6366 | } | |
6367 | ||
6368 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { | |
6369 | struct nl80211_bss_select_rssi_adjust *adj_param; | |
6370 | ||
6371 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); | |
6372 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; | |
6373 | bss_select->param.adjust.band = adj_param->band; | |
6374 | bss_select->param.adjust.delta = adj_param->delta; | |
6375 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) | |
6376 | return -EINVAL; | |
6377 | } | |
6378 | ||
6379 | /* user-space did not provide behaviour attribute */ | |
6380 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) | |
6381 | return -EINVAL; | |
6382 | ||
6383 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) | |
6384 | return -EINVAL; | |
6385 | ||
6386 | return 0; | |
6387 | } | |
6388 | ||
ad2b26ab JB |
6389 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
6390 | u8 *mac_addr, u8 *mac_addr_mask) | |
6391 | { | |
6392 | int i; | |
6393 | ||
6394 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { | |
d2beae10 JP |
6395 | eth_zero_addr(mac_addr); |
6396 | eth_zero_addr(mac_addr_mask); | |
ad2b26ab JB |
6397 | mac_addr[0] = 0x2; |
6398 | mac_addr_mask[0] = 0x3; | |
6399 | ||
6400 | return 0; | |
6401 | } | |
6402 | ||
6403 | /* need both or none */ | |
6404 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) | |
6405 | return -EINVAL; | |
6406 | ||
6407 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); | |
6408 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); | |
6409 | ||
6410 | /* don't allow or configure an mcast address */ | |
6411 | if (!is_multicast_ether_addr(mac_addr_mask) || | |
6412 | is_multicast_ether_addr(mac_addr)) | |
6413 | return -EINVAL; | |
6414 | ||
6415 | /* | |
6416 | * allow users to pass a MAC address that has bits set outside | |
6417 | * of the mask, but don't bother drivers with having to deal | |
6418 | * with such bits | |
6419 | */ | |
6420 | for (i = 0; i < ETH_ALEN; i++) | |
6421 | mac_addr[i] &= mac_addr_mask[i]; | |
6422 | ||
6423 | return 0; | |
6424 | } | |
6425 | ||
2a519311 JB |
6426 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
6427 | { | |
4c476991 | 6428 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 6429 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 6430 | struct cfg80211_scan_request *request; |
2a519311 JB |
6431 | struct nlattr *attr; |
6432 | struct wiphy *wiphy; | |
83f5e2cf | 6433 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 6434 | size_t ie_len; |
2a519311 | 6435 | |
f4a11bb0 JB |
6436 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6437 | return -EINVAL; | |
6438 | ||
79c97e97 | 6439 | wiphy = &rdev->wiphy; |
2a519311 | 6440 | |
cb3b7d87 AB |
6441 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
6442 | return -EOPNOTSUPP; | |
6443 | ||
4c476991 JB |
6444 | if (!rdev->ops->scan) |
6445 | return -EOPNOTSUPP; | |
2a519311 | 6446 | |
f9d15d16 | 6447 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
6448 | err = -EBUSY; |
6449 | goto unlock; | |
6450 | } | |
2a519311 JB |
6451 | |
6452 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
6453 | n_channels = validate_scan_freqs( |
6454 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
6455 | if (!n_channels) { |
6456 | err = -EINVAL; | |
6457 | goto unlock; | |
6458 | } | |
2a519311 | 6459 | } else { |
bdfbec2d | 6460 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
6461 | } |
6462 | ||
6463 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
6464 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
6465 | n_ssids++; | |
6466 | ||
f9f47529 JB |
6467 | if (n_ssids > wiphy->max_scan_ssids) { |
6468 | err = -EINVAL; | |
6469 | goto unlock; | |
6470 | } | |
2a519311 | 6471 | |
70692ad2 JM |
6472 | if (info->attrs[NL80211_ATTR_IE]) |
6473 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6474 | else | |
6475 | ie_len = 0; | |
6476 | ||
f9f47529 JB |
6477 | if (ie_len > wiphy->max_scan_ie_len) { |
6478 | err = -EINVAL; | |
6479 | goto unlock; | |
6480 | } | |
18a83659 | 6481 | |
2a519311 | 6482 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
6483 | + sizeof(*request->ssids) * n_ssids |
6484 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 6485 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
6486 | if (!request) { |
6487 | err = -ENOMEM; | |
6488 | goto unlock; | |
6489 | } | |
2a519311 | 6490 | |
2a519311 | 6491 | if (n_ssids) |
5ba63533 | 6492 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 6493 | request->n_ssids = n_ssids; |
70692ad2 | 6494 | if (ie_len) { |
13874e4b | 6495 | if (n_ssids) |
70692ad2 JM |
6496 | request->ie = (void *)(request->ssids + n_ssids); |
6497 | else | |
6498 | request->ie = (void *)(request->channels + n_channels); | |
6499 | } | |
2a519311 | 6500 | |
584991dc | 6501 | i = 0; |
2a519311 JB |
6502 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
6503 | /* user specified, bail out if channel not found */ | |
2a519311 | 6504 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
6505 | struct ieee80211_channel *chan; |
6506 | ||
6507 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
6508 | ||
6509 | if (!chan) { | |
2a519311 JB |
6510 | err = -EINVAL; |
6511 | goto out_free; | |
6512 | } | |
584991dc JB |
6513 | |
6514 | /* ignore disabled channels */ | |
6515 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6516 | continue; | |
6517 | ||
6518 | request->channels[i] = chan; | |
2a519311 JB |
6519 | i++; |
6520 | } | |
6521 | } else { | |
57fbcce3 | 6522 | enum nl80211_band band; |
34850ab2 | 6523 | |
2a519311 | 6524 | /* all channels */ |
57fbcce3 | 6525 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
2a519311 | 6526 | int j; |
7a087e74 | 6527 | |
2a519311 JB |
6528 | if (!wiphy->bands[band]) |
6529 | continue; | |
6530 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
6531 | struct ieee80211_channel *chan; |
6532 | ||
6533 | chan = &wiphy->bands[band]->channels[j]; | |
6534 | ||
6535 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6536 | continue; | |
6537 | ||
6538 | request->channels[i] = chan; | |
2a519311 JB |
6539 | i++; |
6540 | } | |
6541 | } | |
6542 | } | |
6543 | ||
584991dc JB |
6544 | if (!i) { |
6545 | err = -EINVAL; | |
6546 | goto out_free; | |
6547 | } | |
6548 | ||
6549 | request->n_channels = i; | |
6550 | ||
2a519311 | 6551 | i = 0; |
13874e4b | 6552 | if (n_ssids) { |
2a519311 | 6553 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
57a27e1d | 6554 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
6555 | err = -EINVAL; |
6556 | goto out_free; | |
6557 | } | |
57a27e1d | 6558 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 6559 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
6560 | i++; |
6561 | } | |
6562 | } | |
6563 | ||
70692ad2 JM |
6564 | if (info->attrs[NL80211_ATTR_IE]) { |
6565 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
6566 | memcpy((void *)request->ie, |
6567 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
6568 | request->ie_len); |
6569 | } | |
6570 | ||
57fbcce3 | 6571 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
a401d2bb JB |
6572 | if (wiphy->bands[i]) |
6573 | request->rates[i] = | |
6574 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
6575 | |
6576 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
6577 | nla_for_each_nested(attr, | |
6578 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
6579 | tmp) { | |
57fbcce3 | 6580 | enum nl80211_band band = nla_type(attr); |
34850ab2 | 6581 | |
57fbcce3 | 6582 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
34850ab2 JB |
6583 | err = -EINVAL; |
6584 | goto out_free; | |
6585 | } | |
1b09cd82 FF |
6586 | |
6587 | if (!wiphy->bands[band]) | |
6588 | continue; | |
6589 | ||
34850ab2 JB |
6590 | err = ieee80211_get_ratemask(wiphy->bands[band], |
6591 | nla_data(attr), | |
6592 | nla_len(attr), | |
6593 | &request->rates[band]); | |
6594 | if (err) | |
6595 | goto out_free; | |
6596 | } | |
6597 | } | |
6598 | ||
1d76250b AS |
6599 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
6600 | if (!wiphy_ext_feature_isset(wiphy, | |
6601 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { | |
6602 | err = -EOPNOTSUPP; | |
6603 | goto out_free; | |
6604 | } | |
6605 | ||
6606 | request->duration = | |
6607 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); | |
6608 | request->duration_mandatory = | |
6609 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); | |
6610 | } | |
6611 | ||
46856bbf | 6612 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
6613 | request->flags = nla_get_u32( |
6614 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
6615 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
6616 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
6617 | err = -EOPNOTSUPP; |
6618 | goto out_free; | |
6619 | } | |
ad2b26ab JB |
6620 | |
6621 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
6622 | if (!(wiphy->features & | |
6623 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { | |
6624 | err = -EOPNOTSUPP; | |
6625 | goto out_free; | |
6626 | } | |
6627 | ||
6628 | if (wdev->current_bss) { | |
6629 | err = -EOPNOTSUPP; | |
6630 | goto out_free; | |
6631 | } | |
6632 | ||
6633 | err = nl80211_parse_random_mac(info->attrs, | |
6634 | request->mac_addr, | |
6635 | request->mac_addr_mask); | |
6636 | if (err) | |
6637 | goto out_free; | |
6638 | } | |
46856bbf | 6639 | } |
ed473771 | 6640 | |
e9f935e3 RM |
6641 | request->no_cck = |
6642 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
6643 | ||
818965d3 JM |
6644 | if (info->attrs[NL80211_ATTR_MAC]) |
6645 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), | |
6646 | ETH_ALEN); | |
6647 | else | |
6648 | eth_broadcast_addr(request->bssid); | |
6649 | ||
fd014284 | 6650 | request->wdev = wdev; |
79c97e97 | 6651 | request->wiphy = &rdev->wiphy; |
15d6030b | 6652 | request->scan_start = jiffies; |
2a519311 | 6653 | |
79c97e97 | 6654 | rdev->scan_req = request; |
e35e4d28 | 6655 | err = rdev_scan(rdev, request); |
2a519311 | 6656 | |
463d0183 | 6657 | if (!err) { |
fd014284 JB |
6658 | nl80211_send_scan_start(rdev, wdev); |
6659 | if (wdev->netdev) | |
6660 | dev_hold(wdev->netdev); | |
4c476991 | 6661 | } else { |
2a519311 | 6662 | out_free: |
79c97e97 | 6663 | rdev->scan_req = NULL; |
2a519311 JB |
6664 | kfree(request); |
6665 | } | |
3b85875a | 6666 | |
f9f47529 | 6667 | unlock: |
2a519311 JB |
6668 | return err; |
6669 | } | |
6670 | ||
91d3ab46 VK |
6671 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
6672 | { | |
6673 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6674 | struct wireless_dev *wdev = info->user_ptr[1]; | |
6675 | ||
6676 | if (!rdev->ops->abort_scan) | |
6677 | return -EOPNOTSUPP; | |
6678 | ||
6679 | if (rdev->scan_msg) | |
6680 | return 0; | |
6681 | ||
6682 | if (!rdev->scan_req) | |
6683 | return -ENOENT; | |
6684 | ||
6685 | rdev_abort_scan(rdev, wdev); | |
6686 | return 0; | |
6687 | } | |
6688 | ||
3b06d277 AS |
6689 | static int |
6690 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, | |
6691 | struct cfg80211_sched_scan_request *request, | |
6692 | struct nlattr **attrs) | |
6693 | { | |
6694 | int tmp, err, i = 0; | |
6695 | struct nlattr *attr; | |
6696 | ||
6697 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { | |
6698 | u32 interval; | |
6699 | ||
6700 | /* | |
6701 | * If scan plans are not specified, | |
6702 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this | |
6703 | * case one scan plan will be set with the specified scan | |
6704 | * interval and infinite number of iterations. | |
6705 | */ | |
6706 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
6707 | return -EINVAL; | |
6708 | ||
6709 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
6710 | if (!interval) | |
6711 | return -EINVAL; | |
6712 | ||
6713 | request->scan_plans[0].interval = | |
6714 | DIV_ROUND_UP(interval, MSEC_PER_SEC); | |
6715 | if (!request->scan_plans[0].interval) | |
6716 | return -EINVAL; | |
6717 | ||
6718 | if (request->scan_plans[0].interval > | |
6719 | wiphy->max_sched_scan_plan_interval) | |
6720 | request->scan_plans[0].interval = | |
6721 | wiphy->max_sched_scan_plan_interval; | |
6722 | ||
6723 | return 0; | |
6724 | } | |
6725 | ||
6726 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { | |
6727 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; | |
6728 | ||
6729 | if (WARN_ON(i >= n_plans)) | |
6730 | return -EINVAL; | |
6731 | ||
6732 | err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX, | |
6733 | nla_data(attr), nla_len(attr), | |
6734 | nl80211_plan_policy); | |
6735 | if (err) | |
6736 | return err; | |
6737 | ||
6738 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) | |
6739 | return -EINVAL; | |
6740 | ||
6741 | request->scan_plans[i].interval = | |
6742 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); | |
6743 | if (!request->scan_plans[i].interval || | |
6744 | request->scan_plans[i].interval > | |
6745 | wiphy->max_sched_scan_plan_interval) | |
6746 | return -EINVAL; | |
6747 | ||
6748 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { | |
6749 | request->scan_plans[i].iterations = | |
6750 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); | |
6751 | if (!request->scan_plans[i].iterations || | |
6752 | (request->scan_plans[i].iterations > | |
6753 | wiphy->max_sched_scan_plan_iterations)) | |
6754 | return -EINVAL; | |
6755 | } else if (i < n_plans - 1) { | |
6756 | /* | |
6757 | * All scan plans but the last one must specify | |
6758 | * a finite number of iterations | |
6759 | */ | |
6760 | return -EINVAL; | |
6761 | } | |
6762 | ||
6763 | i++; | |
6764 | } | |
6765 | ||
6766 | /* | |
6767 | * The last scan plan must not specify the number of | |
6768 | * iterations, it is supposed to run infinitely | |
6769 | */ | |
6770 | if (request->scan_plans[n_plans - 1].iterations) | |
6771 | return -EINVAL; | |
6772 | ||
6773 | return 0; | |
6774 | } | |
6775 | ||
256da02d | 6776 | static struct cfg80211_sched_scan_request * |
ad2b26ab | 6777 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
256da02d | 6778 | struct nlattr **attrs) |
807f8a8c LC |
6779 | { |
6780 | struct cfg80211_sched_scan_request *request; | |
807f8a8c | 6781 | struct nlattr *attr; |
3b06d277 | 6782 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; |
57fbcce3 | 6783 | enum nl80211_band band; |
807f8a8c | 6784 | size_t ie_len; |
a1f1c21c | 6785 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 6786 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c | 6787 | |
256da02d LC |
6788 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
6789 | return ERR_PTR(-EINVAL); | |
807f8a8c | 6790 | |
256da02d | 6791 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c | 6792 | n_channels = validate_scan_freqs( |
256da02d | 6793 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
807f8a8c | 6794 | if (!n_channels) |
256da02d | 6795 | return ERR_PTR(-EINVAL); |
807f8a8c | 6796 | } else { |
bdfbec2d | 6797 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
6798 | } |
6799 | ||
256da02d LC |
6800 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
6801 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c LC |
6802 | tmp) |
6803 | n_ssids++; | |
6804 | ||
93b6aa69 | 6805 | if (n_ssids > wiphy->max_sched_scan_ssids) |
256da02d | 6806 | return ERR_PTR(-EINVAL); |
807f8a8c | 6807 | |
ea73cbce JB |
6808 | /* |
6809 | * First, count the number of 'real' matchsets. Due to an issue with | |
6810 | * the old implementation, matchsets containing only the RSSI attribute | |
6811 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
6812 | * RSSI for all matchsets, rather than their own matchset for reporting | |
6813 | * all APs with a strong RSSI. This is needed to be compatible with | |
6814 | * older userspace that treated a matchset with only the RSSI as the | |
6815 | * global RSSI for all other matchsets - if there are other matchsets. | |
6816 | */ | |
256da02d | 6817 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 6818 | nla_for_each_nested(attr, |
256da02d | 6819 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
ea73cbce JB |
6820 | tmp) { |
6821 | struct nlattr *rssi; | |
6822 | ||
6823 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
6824 | nla_data(attr), nla_len(attr), | |
6825 | nl80211_match_policy); | |
6826 | if (err) | |
256da02d | 6827 | return ERR_PTR(err); |
ea73cbce JB |
6828 | /* add other standalone attributes here */ |
6829 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | |
6830 | n_match_sets++; | |
6831 | continue; | |
6832 | } | |
6833 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6834 | if (rssi) | |
6835 | default_match_rssi = nla_get_s32(rssi); | |
6836 | } | |
6837 | } | |
6838 | ||
6839 | /* However, if there's no other matchset, add the RSSI one */ | |
6840 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
6841 | n_match_sets = 1; | |
a1f1c21c LC |
6842 | |
6843 | if (n_match_sets > wiphy->max_match_sets) | |
256da02d | 6844 | return ERR_PTR(-EINVAL); |
a1f1c21c | 6845 | |
256da02d LC |
6846 | if (attrs[NL80211_ATTR_IE]) |
6847 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); | |
807f8a8c LC |
6848 | else |
6849 | ie_len = 0; | |
6850 | ||
5a865bad | 6851 | if (ie_len > wiphy->max_sched_scan_ie_len) |
256da02d | 6852 | return ERR_PTR(-EINVAL); |
c10841ca | 6853 | |
3b06d277 AS |
6854 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
6855 | /* | |
6856 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since | |
6857 | * each scan plan already specifies its own interval | |
6858 | */ | |
6859 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
6860 | return ERR_PTR(-EINVAL); | |
6861 | ||
6862 | nla_for_each_nested(attr, | |
6863 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) | |
6864 | n_plans++; | |
6865 | } else { | |
6866 | /* | |
6867 | * The scan interval attribute is kept for backward | |
6868 | * compatibility. If no scan plans are specified and sched scan | |
6869 | * interval is specified, one scan plan will be set with this | |
6870 | * scan interval and infinite number of iterations. | |
6871 | */ | |
6872 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
6873 | return ERR_PTR(-EINVAL); | |
6874 | ||
6875 | n_plans = 1; | |
6876 | } | |
6877 | ||
6878 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) | |
6879 | return ERR_PTR(-EINVAL); | |
6880 | ||
807f8a8c | 6881 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 6882 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 6883 | + sizeof(*request->match_sets) * n_match_sets |
3b06d277 | 6884 | + sizeof(*request->scan_plans) * n_plans |
a2cd43c5 | 6885 | + sizeof(*request->channels) * n_channels |
807f8a8c | 6886 | + ie_len, GFP_KERNEL); |
256da02d LC |
6887 | if (!request) |
6888 | return ERR_PTR(-ENOMEM); | |
807f8a8c LC |
6889 | |
6890 | if (n_ssids) | |
6891 | request->ssids = (void *)&request->channels[n_channels]; | |
6892 | request->n_ssids = n_ssids; | |
6893 | if (ie_len) { | |
13874e4b | 6894 | if (n_ssids) |
807f8a8c LC |
6895 | request->ie = (void *)(request->ssids + n_ssids); |
6896 | else | |
6897 | request->ie = (void *)(request->channels + n_channels); | |
6898 | } | |
6899 | ||
a1f1c21c LC |
6900 | if (n_match_sets) { |
6901 | if (request->ie) | |
6902 | request->match_sets = (void *)(request->ie + ie_len); | |
13874e4b | 6903 | else if (n_ssids) |
a1f1c21c LC |
6904 | request->match_sets = |
6905 | (void *)(request->ssids + n_ssids); | |
6906 | else | |
6907 | request->match_sets = | |
6908 | (void *)(request->channels + n_channels); | |
6909 | } | |
6910 | request->n_match_sets = n_match_sets; | |
6911 | ||
3b06d277 AS |
6912 | if (n_match_sets) |
6913 | request->scan_plans = (void *)(request->match_sets + | |
6914 | n_match_sets); | |
6915 | else if (request->ie) | |
6916 | request->scan_plans = (void *)(request->ie + ie_len); | |
6917 | else if (n_ssids) | |
6918 | request->scan_plans = (void *)(request->ssids + n_ssids); | |
6919 | else | |
6920 | request->scan_plans = (void *)(request->channels + n_channels); | |
6921 | ||
6922 | request->n_scan_plans = n_plans; | |
6923 | ||
807f8a8c | 6924 | i = 0; |
256da02d | 6925 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c LC |
6926 | /* user specified, bail out if channel not found */ |
6927 | nla_for_each_nested(attr, | |
256da02d | 6928 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
807f8a8c LC |
6929 | tmp) { |
6930 | struct ieee80211_channel *chan; | |
6931 | ||
6932 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
6933 | ||
6934 | if (!chan) { | |
6935 | err = -EINVAL; | |
6936 | goto out_free; | |
6937 | } | |
6938 | ||
6939 | /* ignore disabled channels */ | |
6940 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6941 | continue; | |
6942 | ||
6943 | request->channels[i] = chan; | |
6944 | i++; | |
6945 | } | |
6946 | } else { | |
6947 | /* all channels */ | |
57fbcce3 | 6948 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
807f8a8c | 6949 | int j; |
7a087e74 | 6950 | |
807f8a8c LC |
6951 | if (!wiphy->bands[band]) |
6952 | continue; | |
6953 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
6954 | struct ieee80211_channel *chan; | |
6955 | ||
6956 | chan = &wiphy->bands[band]->channels[j]; | |
6957 | ||
6958 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6959 | continue; | |
6960 | ||
6961 | request->channels[i] = chan; | |
6962 | i++; | |
6963 | } | |
6964 | } | |
6965 | } | |
6966 | ||
6967 | if (!i) { | |
6968 | err = -EINVAL; | |
6969 | goto out_free; | |
6970 | } | |
6971 | ||
6972 | request->n_channels = i; | |
6973 | ||
6974 | i = 0; | |
13874e4b | 6975 | if (n_ssids) { |
256da02d | 6976 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
807f8a8c | 6977 | tmp) { |
57a27e1d | 6978 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
6979 | err = -EINVAL; |
6980 | goto out_free; | |
6981 | } | |
57a27e1d | 6982 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
6983 | memcpy(request->ssids[i].ssid, nla_data(attr), |
6984 | nla_len(attr)); | |
807f8a8c LC |
6985 | i++; |
6986 | } | |
6987 | } | |
6988 | ||
a1f1c21c | 6989 | i = 0; |
256da02d | 6990 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 6991 | nla_for_each_nested(attr, |
256da02d | 6992 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
a1f1c21c | 6993 | tmp) { |
88e920b4 | 6994 | struct nlattr *ssid, *rssi; |
a1f1c21c | 6995 | |
ae811e21 JB |
6996 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
6997 | nla_data(attr), nla_len(attr), | |
6998 | nl80211_match_policy); | |
6999 | if (err) | |
7000 | goto out_free; | |
4a4ab0d7 | 7001 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 7002 | if (ssid) { |
ea73cbce JB |
7003 | if (WARN_ON(i >= n_match_sets)) { |
7004 | /* this indicates a programming error, | |
7005 | * the loop above should have verified | |
7006 | * things properly | |
7007 | */ | |
7008 | err = -EINVAL; | |
7009 | goto out_free; | |
7010 | } | |
7011 | ||
a1f1c21c LC |
7012 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
7013 | err = -EINVAL; | |
7014 | goto out_free; | |
7015 | } | |
7016 | memcpy(request->match_sets[i].ssid.ssid, | |
7017 | nla_data(ssid), nla_len(ssid)); | |
7018 | request->match_sets[i].ssid.ssid_len = | |
7019 | nla_len(ssid); | |
56ab364f | 7020 | /* special attribute - old implementation w/a */ |
ea73cbce JB |
7021 | request->match_sets[i].rssi_thold = |
7022 | default_match_rssi; | |
7023 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
7024 | if (rssi) | |
7025 | request->match_sets[i].rssi_thold = | |
7026 | nla_get_s32(rssi); | |
a1f1c21c LC |
7027 | } |
7028 | i++; | |
7029 | } | |
ea73cbce JB |
7030 | |
7031 | /* there was no other matchset, so the RSSI one is alone */ | |
f89f46cf | 7032 | if (i == 0 && n_match_sets) |
ea73cbce JB |
7033 | request->match_sets[0].rssi_thold = default_match_rssi; |
7034 | ||
7035 | request->min_rssi_thold = INT_MAX; | |
7036 | for (i = 0; i < n_match_sets; i++) | |
7037 | request->min_rssi_thold = | |
7038 | min(request->match_sets[i].rssi_thold, | |
7039 | request->min_rssi_thold); | |
7040 | } else { | |
7041 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
7042 | } |
7043 | ||
9900e484 JB |
7044 | if (ie_len) { |
7045 | request->ie_len = ie_len; | |
807f8a8c | 7046 | memcpy((void *)request->ie, |
256da02d | 7047 | nla_data(attrs[NL80211_ATTR_IE]), |
807f8a8c LC |
7048 | request->ie_len); |
7049 | } | |
7050 | ||
256da02d | 7051 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 | 7052 | request->flags = nla_get_u32( |
256da02d | 7053 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
00c3a6ed JB |
7054 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
7055 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
7056 | err = -EOPNOTSUPP; |
7057 | goto out_free; | |
7058 | } | |
ad2b26ab JB |
7059 | |
7060 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
7061 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; | |
7062 | ||
7063 | if (!wdev) /* must be net-detect */ | |
7064 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
7065 | ||
7066 | if (!(wiphy->features & flg)) { | |
7067 | err = -EOPNOTSUPP; | |
7068 | goto out_free; | |
7069 | } | |
7070 | ||
7071 | if (wdev && wdev->current_bss) { | |
7072 | err = -EOPNOTSUPP; | |
7073 | goto out_free; | |
7074 | } | |
7075 | ||
7076 | err = nl80211_parse_random_mac(attrs, request->mac_addr, | |
7077 | request->mac_addr_mask); | |
7078 | if (err) | |
7079 | goto out_free; | |
7080 | } | |
46856bbf | 7081 | } |
ed473771 | 7082 | |
9c748934 LC |
7083 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
7084 | request->delay = | |
7085 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); | |
7086 | ||
3b06d277 AS |
7087 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
7088 | if (err) | |
7089 | goto out_free; | |
7090 | ||
15d6030b | 7091 | request->scan_start = jiffies; |
807f8a8c | 7092 | |
256da02d | 7093 | return request; |
807f8a8c LC |
7094 | |
7095 | out_free: | |
7096 | kfree(request); | |
256da02d LC |
7097 | return ERR_PTR(err); |
7098 | } | |
7099 | ||
7100 | static int nl80211_start_sched_scan(struct sk_buff *skb, | |
7101 | struct genl_info *info) | |
7102 | { | |
7103 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7104 | struct net_device *dev = info->user_ptr[1]; | |
ad2b26ab | 7105 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
31a60ed1 | 7106 | struct cfg80211_sched_scan_request *sched_scan_req; |
256da02d LC |
7107 | int err; |
7108 | ||
7109 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
7110 | !rdev->ops->sched_scan_start) | |
7111 | return -EOPNOTSUPP; | |
7112 | ||
7113 | if (rdev->sched_scan_req) | |
7114 | return -EINPROGRESS; | |
7115 | ||
31a60ed1 JR |
7116 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
7117 | info->attrs); | |
7118 | ||
7119 | err = PTR_ERR_OR_ZERO(sched_scan_req); | |
256da02d LC |
7120 | if (err) |
7121 | goto out_err; | |
7122 | ||
31a60ed1 | 7123 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
256da02d LC |
7124 | if (err) |
7125 | goto out_free; | |
7126 | ||
31a60ed1 JR |
7127 | sched_scan_req->dev = dev; |
7128 | sched_scan_req->wiphy = &rdev->wiphy; | |
7129 | ||
93a1e86c JR |
7130 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
7131 | sched_scan_req->owner_nlportid = info->snd_portid; | |
7132 | ||
31a60ed1 | 7133 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
256da02d LC |
7134 | |
7135 | nl80211_send_sched_scan(rdev, dev, | |
7136 | NL80211_CMD_START_SCHED_SCAN); | |
7137 | return 0; | |
7138 | ||
7139 | out_free: | |
31a60ed1 | 7140 | kfree(sched_scan_req); |
256da02d | 7141 | out_err: |
807f8a8c LC |
7142 | return err; |
7143 | } | |
7144 | ||
7145 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
7146 | struct genl_info *info) | |
7147 | { | |
7148 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7149 | ||
7150 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
7151 | !rdev->ops->sched_scan_stop) | |
7152 | return -EOPNOTSUPP; | |
7153 | ||
5fe231e8 | 7154 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
7155 | } |
7156 | ||
04f39047 SW |
7157 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
7158 | struct genl_info *info) | |
7159 | { | |
7160 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7161 | struct net_device *dev = info->user_ptr[1]; | |
7162 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7163 | struct cfg80211_chan_def chandef; | |
55f7435c | 7164 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 7165 | unsigned int cac_time_ms; |
04f39047 SW |
7166 | int err; |
7167 | ||
55f7435c LR |
7168 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
7169 | if (dfs_region == NL80211_DFS_UNSET) | |
7170 | return -EINVAL; | |
7171 | ||
04f39047 SW |
7172 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7173 | if (err) | |
7174 | return err; | |
7175 | ||
ff311bc1 SW |
7176 | if (netif_carrier_ok(dev)) |
7177 | return -EBUSY; | |
7178 | ||
04f39047 SW |
7179 | if (wdev->cac_started) |
7180 | return -EBUSY; | |
7181 | ||
2beb6dab | 7182 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
00ec75fc | 7183 | wdev->iftype); |
04f39047 SW |
7184 | if (err < 0) |
7185 | return err; | |
7186 | ||
7187 | if (err == 0) | |
7188 | return -EINVAL; | |
7189 | ||
fe7c3a1f | 7190 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
7191 | return -EINVAL; |
7192 | ||
7193 | if (!rdev->ops->start_radar_detection) | |
7194 | return -EOPNOTSUPP; | |
7195 | ||
31559f35 JD |
7196 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
7197 | if (WARN_ON(!cac_time_ms)) | |
7198 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
7199 | ||
a1056b1b | 7200 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
04f39047 | 7201 | if (!err) { |
9e0e2961 | 7202 | wdev->chandef = chandef; |
04f39047 SW |
7203 | wdev->cac_started = true; |
7204 | wdev->cac_start_time = jiffies; | |
31559f35 | 7205 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 7206 | } |
04f39047 SW |
7207 | return err; |
7208 | } | |
7209 | ||
16ef1fe2 SW |
7210 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
7211 | { | |
7212 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7213 | struct net_device *dev = info->user_ptr[1]; | |
7214 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7215 | struct cfg80211_csa_settings params; | |
7216 | /* csa_attrs is defined static to avoid waste of stack size - this | |
7217 | * function is called under RTNL lock, so this should not be a problem. | |
7218 | */ | |
7219 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
16ef1fe2 | 7220 | int err; |
ee4bc9e7 | 7221 | bool need_new_beacon = false; |
9a774c78 | 7222 | int len, i; |
252e07ca | 7223 | u32 cs_count; |
16ef1fe2 SW |
7224 | |
7225 | if (!rdev->ops->channel_switch || | |
7226 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
7227 | return -EOPNOTSUPP; | |
7228 | ||
ee4bc9e7 SW |
7229 | switch (dev->ieee80211_ptr->iftype) { |
7230 | case NL80211_IFTYPE_AP: | |
7231 | case NL80211_IFTYPE_P2P_GO: | |
7232 | need_new_beacon = true; | |
7233 | ||
7234 | /* useless if AP is not running */ | |
7235 | if (!wdev->beacon_interval) | |
1ff79dfa | 7236 | return -ENOTCONN; |
ee4bc9e7 SW |
7237 | break; |
7238 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
7239 | if (!wdev->ssid_len) |
7240 | return -ENOTCONN; | |
7241 | break; | |
c6da674a | 7242 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
7243 | if (!wdev->mesh_id_len) |
7244 | return -ENOTCONN; | |
ee4bc9e7 SW |
7245 | break; |
7246 | default: | |
16ef1fe2 | 7247 | return -EOPNOTSUPP; |
ee4bc9e7 | 7248 | } |
16ef1fe2 SW |
7249 | |
7250 | memset(¶ms, 0, sizeof(params)); | |
7251 | ||
7252 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7253 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
7254 | return -EINVAL; | |
7255 | ||
7256 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 7257 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
7258 | return -EINVAL; |
7259 | ||
252e07ca LC |
7260 | /* Even though the attribute is u32, the specification says |
7261 | * u8, so let's make sure we don't overflow. | |
7262 | */ | |
7263 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
7264 | if (cs_count > 255) | |
7265 | return -EINVAL; | |
7266 | ||
7267 | params.count = cs_count; | |
16ef1fe2 | 7268 | |
ee4bc9e7 SW |
7269 | if (!need_new_beacon) |
7270 | goto skip_beacons; | |
7271 | ||
16ef1fe2 SW |
7272 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
7273 | if (err) | |
7274 | return err; | |
7275 | ||
7276 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
7277 | info->attrs[NL80211_ATTR_CSA_IES], | |
7278 | nl80211_policy); | |
7279 | if (err) | |
7280 | return err; | |
7281 | ||
7282 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
7283 | if (err) | |
7284 | return err; | |
7285 | ||
7286 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
7287 | return -EINVAL; | |
7288 | ||
9a774c78 AO |
7289 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
7290 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
7291 | return -EINVAL; |
7292 | ||
9a774c78 AO |
7293 | params.n_counter_offsets_beacon = len / sizeof(u16); |
7294 | if (rdev->wiphy.max_num_csa_counters && | |
7295 | (params.n_counter_offsets_beacon > | |
7296 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
7297 | return -EINVAL; |
7298 | ||
9a774c78 AO |
7299 | params.counter_offsets_beacon = |
7300 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
7301 | ||
7302 | /* sanity checks - counters should fit and be the same */ | |
7303 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
7304 | u16 offset = params.counter_offsets_beacon[i]; | |
7305 | ||
7306 | if (offset >= params.beacon_csa.tail_len) | |
7307 | return -EINVAL; | |
7308 | ||
7309 | if (params.beacon_csa.tail[offset] != params.count) | |
7310 | return -EINVAL; | |
7311 | } | |
7312 | ||
16ef1fe2 | 7313 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
7314 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
7315 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
7316 | return -EINVAL; |
7317 | ||
9a774c78 AO |
7318 | params.n_counter_offsets_presp = len / sizeof(u16); |
7319 | if (rdev->wiphy.max_num_csa_counters && | |
7320 | (params.n_counter_offsets_beacon > | |
7321 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 | 7322 | return -EINVAL; |
9a774c78 AO |
7323 | |
7324 | params.counter_offsets_presp = | |
7325 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
7326 | ||
7327 | /* sanity checks - counters should fit and be the same */ | |
7328 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
7329 | u16 offset = params.counter_offsets_presp[i]; | |
7330 | ||
7331 | if (offset >= params.beacon_csa.probe_resp_len) | |
7332 | return -EINVAL; | |
7333 | ||
7334 | if (params.beacon_csa.probe_resp[offset] != | |
7335 | params.count) | |
7336 | return -EINVAL; | |
7337 | } | |
16ef1fe2 SW |
7338 | } |
7339 | ||
ee4bc9e7 | 7340 | skip_beacons: |
16ef1fe2 SW |
7341 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
7342 | if (err) | |
7343 | return err; | |
7344 | ||
923b352f AN |
7345 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
7346 | wdev->iftype)) | |
16ef1fe2 SW |
7347 | return -EINVAL; |
7348 | ||
2beb6dab LC |
7349 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
7350 | ¶ms.chandef, | |
7351 | wdev->iftype); | |
7352 | if (err < 0) | |
7353 | return err; | |
7354 | ||
dcc6c2f5 | 7355 | if (err > 0) |
2beb6dab | 7356 | params.radar_required = true; |
16ef1fe2 | 7357 | |
16ef1fe2 SW |
7358 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
7359 | params.block_tx = true; | |
7360 | ||
c56589ed SW |
7361 | wdev_lock(wdev); |
7362 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
7363 | wdev_unlock(wdev); | |
7364 | ||
7365 | return err; | |
16ef1fe2 SW |
7366 | } |
7367 | ||
9720bb3a JB |
7368 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
7369 | u32 seq, int flags, | |
2a519311 | 7370 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
7371 | struct wireless_dev *wdev, |
7372 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 7373 | { |
48ab905d | 7374 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 7375 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
7376 | void *hdr; |
7377 | struct nlattr *bss; | |
48ab905d JB |
7378 | |
7379 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 7380 | |
15e47304 | 7381 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
7382 | NL80211_CMD_NEW_SCAN_RESULTS); |
7383 | if (!hdr) | |
7384 | return -1; | |
7385 | ||
9720bb3a JB |
7386 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
7387 | ||
97990a06 JB |
7388 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
7389 | goto nla_put_failure; | |
7390 | if (wdev->netdev && | |
9360ffd1 DM |
7391 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
7392 | goto nla_put_failure; | |
2dad624e ND |
7393 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
7394 | NL80211_ATTR_PAD)) | |
97990a06 | 7395 | goto nla_put_failure; |
2a519311 JB |
7396 | |
7397 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
7398 | if (!bss) | |
7399 | goto nla_put_failure; | |
9360ffd1 | 7400 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 7401 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 7402 | goto nla_put_failure; |
9caf0364 JB |
7403 | |
7404 | rcu_read_lock(); | |
0e227084 JB |
7405 | /* indicate whether we have probe response data or not */ |
7406 | if (rcu_access_pointer(res->proberesp_ies) && | |
7407 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
7408 | goto fail_unlock_rcu; | |
7409 | ||
7410 | /* this pointer prefers to be pointed to probe response data | |
7411 | * but is always valid | |
7412 | */ | |
9caf0364 | 7413 | ies = rcu_dereference(res->ies); |
8cef2c9d | 7414 | if (ies) { |
2dad624e ND |
7415 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
7416 | NL80211_BSS_PAD)) | |
8cef2c9d | 7417 | goto fail_unlock_rcu; |
8cef2c9d JB |
7418 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
7419 | ies->len, ies->data)) | |
7420 | goto fail_unlock_rcu; | |
9caf0364 | 7421 | } |
0e227084 JB |
7422 | |
7423 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 7424 | ies = rcu_dereference(res->beacon_ies); |
0e227084 | 7425 | if (ies && ies->from_beacon) { |
2dad624e ND |
7426 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
7427 | NL80211_BSS_PAD)) | |
8cef2c9d JB |
7428 | goto fail_unlock_rcu; |
7429 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
7430 | ies->len, ies->data)) | |
7431 | goto fail_unlock_rcu; | |
9caf0364 JB |
7432 | } |
7433 | rcu_read_unlock(); | |
7434 | ||
9360ffd1 DM |
7435 | if (res->beacon_interval && |
7436 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
7437 | goto nla_put_failure; | |
7438 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
7439 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 7440 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
7441 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
7442 | jiffies_to_msecs(jiffies - intbss->ts))) | |
7443 | goto nla_put_failure; | |
2a519311 | 7444 | |
1d76250b AS |
7445 | if (intbss->parent_tsf && |
7446 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, | |
7447 | intbss->parent_tsf, NL80211_BSS_PAD) || | |
7448 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, | |
7449 | intbss->parent_bssid))) | |
7450 | goto nla_put_failure; | |
7451 | ||
6e19bc4b | 7452 | if (intbss->ts_boottime && |
2dad624e ND |
7453 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
7454 | intbss->ts_boottime, NL80211_BSS_PAD)) | |
6e19bc4b DS |
7455 | goto nla_put_failure; |
7456 | ||
77965c97 | 7457 | switch (rdev->wiphy.signal_type) { |
2a519311 | 7458 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
7459 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
7460 | goto nla_put_failure; | |
2a519311 JB |
7461 | break; |
7462 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
7463 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
7464 | goto nla_put_failure; | |
2a519311 JB |
7465 | break; |
7466 | default: | |
7467 | break; | |
7468 | } | |
7469 | ||
48ab905d | 7470 | switch (wdev->iftype) { |
074ac8df | 7471 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 7472 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
7473 | if (intbss == wdev->current_bss && |
7474 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
7475 | NL80211_BSS_STATUS_ASSOCIATED)) | |
7476 | goto nla_put_failure; | |
48ab905d JB |
7477 | break; |
7478 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
7479 | if (intbss == wdev->current_bss && |
7480 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
7481 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
7482 | goto nla_put_failure; | |
48ab905d JB |
7483 | break; |
7484 | default: | |
7485 | break; | |
7486 | } | |
7487 | ||
2a519311 JB |
7488 | nla_nest_end(msg, bss); |
7489 | ||
053c095a JB |
7490 | genlmsg_end(msg, hdr); |
7491 | return 0; | |
2a519311 | 7492 | |
8cef2c9d JB |
7493 | fail_unlock_rcu: |
7494 | rcu_read_unlock(); | |
2a519311 JB |
7495 | nla_put_failure: |
7496 | genlmsg_cancel(msg, hdr); | |
7497 | return -EMSGSIZE; | |
7498 | } | |
7499 | ||
97990a06 | 7500 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 7501 | { |
48ab905d | 7502 | struct cfg80211_registered_device *rdev; |
2a519311 | 7503 | struct cfg80211_internal_bss *scan; |
48ab905d | 7504 | struct wireless_dev *wdev; |
97990a06 | 7505 | int start = cb->args[2], idx = 0; |
2a519311 JB |
7506 | int err; |
7507 | ||
97990a06 | 7508 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
7509 | if (err) |
7510 | return err; | |
2a519311 | 7511 | |
48ab905d JB |
7512 | wdev_lock(wdev); |
7513 | spin_lock_bh(&rdev->bss_lock); | |
7514 | cfg80211_bss_expire(rdev); | |
7515 | ||
9720bb3a JB |
7516 | cb->seq = rdev->bss_generation; |
7517 | ||
48ab905d | 7518 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
7519 | if (++idx <= start) |
7520 | continue; | |
9720bb3a | 7521 | if (nl80211_send_bss(skb, cb, |
2a519311 | 7522 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 7523 | rdev, wdev, scan) < 0) { |
2a519311 | 7524 | idx--; |
67748893 | 7525 | break; |
2a519311 JB |
7526 | } |
7527 | } | |
7528 | ||
48ab905d JB |
7529 | spin_unlock_bh(&rdev->bss_lock); |
7530 | wdev_unlock(wdev); | |
2a519311 | 7531 | |
97990a06 JB |
7532 | cb->args[2] = idx; |
7533 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 7534 | |
67748893 | 7535 | return skb->len; |
2a519311 JB |
7536 | } |
7537 | ||
15e47304 | 7538 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
11f78ac3 JB |
7539 | int flags, struct net_device *dev, |
7540 | bool allow_radio_stats, | |
7541 | struct survey_info *survey) | |
61fa713c HS |
7542 | { |
7543 | void *hdr; | |
7544 | struct nlattr *infoattr; | |
7545 | ||
11f78ac3 JB |
7546 | /* skip radio stats if userspace didn't request them */ |
7547 | if (!survey->channel && !allow_radio_stats) | |
7548 | return 0; | |
7549 | ||
15e47304 | 7550 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
7551 | NL80211_CMD_NEW_SURVEY_RESULTS); |
7552 | if (!hdr) | |
7553 | return -ENOMEM; | |
7554 | ||
9360ffd1 DM |
7555 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
7556 | goto nla_put_failure; | |
61fa713c HS |
7557 | |
7558 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
7559 | if (!infoattr) | |
7560 | goto nla_put_failure; | |
7561 | ||
11f78ac3 JB |
7562 | if (survey->channel && |
7563 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
9360ffd1 DM |
7564 | survey->channel->center_freq)) |
7565 | goto nla_put_failure; | |
7566 | ||
7567 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
7568 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
7569 | goto nla_put_failure; | |
7570 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
7571 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
7572 | goto nla_put_failure; | |
4ed20beb | 7573 | if ((survey->filled & SURVEY_INFO_TIME) && |
2dad624e ND |
7574 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
7575 | survey->time, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7576 | goto nla_put_failure; |
4ed20beb | 7577 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
2dad624e ND |
7578 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
7579 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7580 | goto nla_put_failure; |
4ed20beb | 7581 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
2dad624e ND |
7582 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
7583 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7584 | goto nla_put_failure; |
4ed20beb | 7585 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
2dad624e ND |
7586 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
7587 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7588 | goto nla_put_failure; |
4ed20beb | 7589 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
2dad624e ND |
7590 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
7591 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7592 | goto nla_put_failure; |
052536ab | 7593 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
2dad624e ND |
7594 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
7595 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) | |
052536ab | 7596 | goto nla_put_failure; |
61fa713c HS |
7597 | |
7598 | nla_nest_end(msg, infoattr); | |
7599 | ||
053c095a JB |
7600 | genlmsg_end(msg, hdr); |
7601 | return 0; | |
61fa713c HS |
7602 | |
7603 | nla_put_failure: | |
7604 | genlmsg_cancel(msg, hdr); | |
7605 | return -EMSGSIZE; | |
7606 | } | |
7607 | ||
11f78ac3 | 7608 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
61fa713c HS |
7609 | { |
7610 | struct survey_info survey; | |
1b8ec87a | 7611 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
7612 | struct wireless_dev *wdev; |
7613 | int survey_idx = cb->args[2]; | |
61fa713c | 7614 | int res; |
11f78ac3 | 7615 | bool radio_stats; |
61fa713c | 7616 | |
1b8ec87a | 7617 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
7618 | if (res) |
7619 | return res; | |
61fa713c | 7620 | |
11f78ac3 JB |
7621 | /* prepare_wdev_dump parsed the attributes */ |
7622 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; | |
7623 | ||
97990a06 JB |
7624 | if (!wdev->netdev) { |
7625 | res = -EINVAL; | |
7626 | goto out_err; | |
7627 | } | |
7628 | ||
1b8ec87a | 7629 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
7630 | res = -EOPNOTSUPP; |
7631 | goto out_err; | |
7632 | } | |
7633 | ||
7634 | while (1) { | |
1b8ec87a | 7635 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
7636 | if (res == -ENOENT) |
7637 | break; | |
7638 | if (res) | |
7639 | goto out_err; | |
7640 | ||
11f78ac3 JB |
7641 | /* don't send disabled channels, but do send non-channel data */ |
7642 | if (survey.channel && | |
7643 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { | |
180cdc79 LR |
7644 | survey_idx++; |
7645 | continue; | |
7646 | } | |
7647 | ||
61fa713c | 7648 | if (nl80211_send_survey(skb, |
15e47304 | 7649 | NETLINK_CB(cb->skb).portid, |
61fa713c | 7650 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
11f78ac3 | 7651 | wdev->netdev, radio_stats, &survey) < 0) |
61fa713c HS |
7652 | goto out; |
7653 | survey_idx++; | |
7654 | } | |
7655 | ||
7656 | out: | |
97990a06 | 7657 | cb->args[2] = survey_idx; |
61fa713c HS |
7658 | res = skb->len; |
7659 | out_err: | |
1b8ec87a | 7660 | nl80211_finish_wdev_dump(rdev); |
61fa713c HS |
7661 | return res; |
7662 | } | |
7663 | ||
b23aa676 SO |
7664 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
7665 | { | |
7666 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
7667 | NL80211_WPA_VERSION_2)); | |
7668 | } | |
7669 | ||
636a5d36 JM |
7670 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
7671 | { | |
4c476991 JB |
7672 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7673 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7674 | struct ieee80211_channel *chan; |
e39e5b5e JM |
7675 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
7676 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 7677 | enum nl80211_auth_type auth_type; |
fffd0934 | 7678 | struct key_parse key; |
d5cdfacb | 7679 | bool local_state_change; |
636a5d36 | 7680 | |
f4a11bb0 JB |
7681 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7682 | return -EINVAL; | |
7683 | ||
7684 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7685 | return -EINVAL; | |
7686 | ||
1778092e JM |
7687 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
7688 | return -EINVAL; | |
7689 | ||
19957bb3 JB |
7690 | if (!info->attrs[NL80211_ATTR_SSID]) |
7691 | return -EINVAL; | |
7692 | ||
7693 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
7694 | return -EINVAL; | |
7695 | ||
fffd0934 JB |
7696 | err = nl80211_parse_key(info, &key); |
7697 | if (err) | |
7698 | return err; | |
7699 | ||
7700 | if (key.idx >= 0) { | |
e31b8213 JB |
7701 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
7702 | return -EINVAL; | |
fffd0934 JB |
7703 | if (!key.p.key || !key.p.key_len) |
7704 | return -EINVAL; | |
7705 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
7706 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
7707 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
7708 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
7709 | return -EINVAL; | |
b6b5555b | 7710 | if (key.idx > 3) |
fffd0934 JB |
7711 | return -EINVAL; |
7712 | } else { | |
7713 | key.p.key_len = 0; | |
7714 | key.p.key = NULL; | |
7715 | } | |
7716 | ||
afea0b7a JB |
7717 | if (key.idx >= 0) { |
7718 | int i; | |
7719 | bool ok = false; | |
7a087e74 | 7720 | |
afea0b7a JB |
7721 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
7722 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
7723 | ok = true; | |
7724 | break; | |
7725 | } | |
7726 | } | |
4c476991 JB |
7727 | if (!ok) |
7728 | return -EINVAL; | |
afea0b7a JB |
7729 | } |
7730 | ||
4c476991 JB |
7731 | if (!rdev->ops->auth) |
7732 | return -EOPNOTSUPP; | |
636a5d36 | 7733 | |
074ac8df | 7734 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7735 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7736 | return -EOPNOTSUPP; | |
eec60b03 | 7737 | |
19957bb3 | 7738 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
7739 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
7740 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7741 | if (!chan) | |
4c476991 | 7742 | return -EINVAL; |
636a5d36 | 7743 | |
19957bb3 JB |
7744 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7745 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
7746 | |
7747 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7748 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7749 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7750 | } |
7751 | ||
19957bb3 | 7752 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 7753 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 7754 | return -EINVAL; |
636a5d36 | 7755 | |
e39e5b5e JM |
7756 | if (auth_type == NL80211_AUTHTYPE_SAE && |
7757 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
7758 | return -EINVAL; | |
7759 | ||
7760 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
7761 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
7762 | return -EINVAL; | |
7763 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
7764 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
7765 | /* need to include at least Auth Transaction and Status Code */ | |
7766 | if (sae_data_len < 4) | |
7767 | return -EINVAL; | |
7768 | } | |
7769 | ||
d5cdfacb JM |
7770 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7771 | ||
95de817b JB |
7772 | /* |
7773 | * Since we no longer track auth state, ignore | |
7774 | * requests to only change local state. | |
7775 | */ | |
7776 | if (local_state_change) | |
7777 | return 0; | |
7778 | ||
91bf9b26 JB |
7779 | wdev_lock(dev->ieee80211_ptr); |
7780 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
7781 | ssid, ssid_len, ie, ie_len, | |
7782 | key.p.key, key.p.key_len, key.idx, | |
7783 | sae_data, sae_data_len); | |
7784 | wdev_unlock(dev->ieee80211_ptr); | |
7785 | return err; | |
636a5d36 JM |
7786 | } |
7787 | ||
c0692b8f JB |
7788 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
7789 | struct genl_info *info, | |
3dc27d25 JB |
7790 | struct cfg80211_crypto_settings *settings, |
7791 | int cipher_limit) | |
b23aa676 | 7792 | { |
c0b2bbd8 JB |
7793 | memset(settings, 0, sizeof(*settings)); |
7794 | ||
b23aa676 SO |
7795 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
7796 | ||
c0692b8f JB |
7797 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
7798 | u16 proto; | |
7a087e74 | 7799 | |
c0692b8f JB |
7800 | proto = nla_get_u16( |
7801 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
7802 | settings->control_port_ethertype = cpu_to_be16(proto); | |
7803 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
7804 | proto != ETH_P_PAE) | |
7805 | return -EINVAL; | |
7806 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
7807 | settings->control_port_no_encrypt = true; | |
7808 | } else | |
7809 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
7810 | ||
b23aa676 SO |
7811 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
7812 | void *data; | |
7813 | int len, i; | |
7814 | ||
7815 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
7816 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
7817 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
7818 | ||
7819 | if (len % sizeof(u32)) | |
7820 | return -EINVAL; | |
7821 | ||
3dc27d25 | 7822 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
7823 | return -EINVAL; |
7824 | ||
7825 | memcpy(settings->ciphers_pairwise, data, len); | |
7826 | ||
7827 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
7828 | if (!cfg80211_supported_cipher_suite( |
7829 | &rdev->wiphy, | |
b23aa676 SO |
7830 | settings->ciphers_pairwise[i])) |
7831 | return -EINVAL; | |
7832 | } | |
7833 | ||
7834 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
7835 | settings->cipher_group = | |
7836 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
7837 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
7838 | settings->cipher_group)) | |
b23aa676 SO |
7839 | return -EINVAL; |
7840 | } | |
7841 | ||
7842 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
7843 | settings->wpa_versions = | |
7844 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
7845 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
7846 | return -EINVAL; | |
7847 | } | |
7848 | ||
7849 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
7850 | void *data; | |
6d30240e | 7851 | int len; |
b23aa676 SO |
7852 | |
7853 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
7854 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
7855 | settings->n_akm_suites = len / sizeof(u32); | |
7856 | ||
7857 | if (len % sizeof(u32)) | |
7858 | return -EINVAL; | |
7859 | ||
1b9ca027 JM |
7860 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
7861 | return -EINVAL; | |
7862 | ||
b23aa676 | 7863 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
7864 | } |
7865 | ||
7866 | return 0; | |
7867 | } | |
7868 | ||
636a5d36 JM |
7869 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
7870 | { | |
4c476991 JB |
7871 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7872 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 7873 | struct ieee80211_channel *chan; |
f62fab73 JB |
7874 | struct cfg80211_assoc_request req = {}; |
7875 | const u8 *bssid, *ssid; | |
7876 | int err, ssid_len = 0; | |
636a5d36 | 7877 | |
f4a11bb0 JB |
7878 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7879 | return -EINVAL; | |
7880 | ||
7881 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
7882 | !info->attrs[NL80211_ATTR_SSID] || |
7883 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
7884 | return -EINVAL; |
7885 | ||
4c476991 JB |
7886 | if (!rdev->ops->assoc) |
7887 | return -EOPNOTSUPP; | |
636a5d36 | 7888 | |
074ac8df | 7889 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7890 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7891 | return -EOPNOTSUPP; | |
eec60b03 | 7892 | |
19957bb3 | 7893 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7894 | |
664834de JM |
7895 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
7896 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7897 | if (!chan) | |
4c476991 | 7898 | return -EINVAL; |
636a5d36 | 7899 | |
19957bb3 JB |
7900 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7901 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
7902 | |
7903 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
7904 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7905 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7906 | } |
7907 | ||
dc6382ce | 7908 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 7909 | enum nl80211_mfp mfp = |
dc6382ce | 7910 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 7911 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 7912 | req.use_mfp = true; |
4c476991 JB |
7913 | else if (mfp != NL80211_MFP_NO) |
7914 | return -EINVAL; | |
dc6382ce JM |
7915 | } |
7916 | ||
3e5d7649 | 7917 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 7918 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 7919 | |
7e7c8926 | 7920 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 7921 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
7922 | |
7923 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
7924 | memcpy(&req.ht_capa_mask, |
7925 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7926 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
7927 | |
7928 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 7929 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 7930 | return -EINVAL; |
f62fab73 JB |
7931 | memcpy(&req.ht_capa, |
7932 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7933 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
7934 | } |
7935 | ||
ee2aca34 | 7936 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 7937 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
7938 | |
7939 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
7940 | memcpy(&req.vht_capa_mask, |
7941 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7942 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
7943 | |
7944 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 7945 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 7946 | return -EINVAL; |
f62fab73 JB |
7947 | memcpy(&req.vht_capa, |
7948 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7949 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
7950 | } |
7951 | ||
bab5ab7d | 7952 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
0c9ca11b BL |
7953 | if (!((rdev->wiphy.features & |
7954 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && | |
7955 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && | |
7956 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
7957 | NL80211_EXT_FEATURE_RRM)) | |
bab5ab7d AK |
7958 | return -EINVAL; |
7959 | req.flags |= ASSOC_REQ_USE_RRM; | |
7960 | } | |
7961 | ||
f62fab73 | 7962 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
7963 | if (!err) { |
7964 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
7965 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
7966 | ssid, ssid_len, &req); | |
91bf9b26 JB |
7967 | wdev_unlock(dev->ieee80211_ptr); |
7968 | } | |
636a5d36 | 7969 | |
636a5d36 JM |
7970 | return err; |
7971 | } | |
7972 | ||
7973 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
7974 | { | |
4c476991 JB |
7975 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7976 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7977 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7978 | int ie_len = 0, err; |
19957bb3 | 7979 | u16 reason_code; |
d5cdfacb | 7980 | bool local_state_change; |
636a5d36 | 7981 | |
f4a11bb0 JB |
7982 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7983 | return -EINVAL; | |
7984 | ||
7985 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7986 | return -EINVAL; | |
7987 | ||
7988 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7989 | return -EINVAL; | |
7990 | ||
4c476991 JB |
7991 | if (!rdev->ops->deauth) |
7992 | return -EOPNOTSUPP; | |
636a5d36 | 7993 | |
074ac8df | 7994 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7995 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7996 | return -EOPNOTSUPP; | |
eec60b03 | 7997 | |
19957bb3 | 7998 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7999 | |
19957bb3 JB |
8000 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
8001 | if (reason_code == 0) { | |
f4a11bb0 | 8002 | /* Reason Code 0 is reserved */ |
4c476991 | 8003 | return -EINVAL; |
255e737e | 8004 | } |
636a5d36 JM |
8005 | |
8006 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
8007 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
8008 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
8009 | } |
8010 | ||
d5cdfacb JM |
8011 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
8012 | ||
91bf9b26 JB |
8013 | wdev_lock(dev->ieee80211_ptr); |
8014 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
8015 | local_state_change); | |
8016 | wdev_unlock(dev->ieee80211_ptr); | |
8017 | return err; | |
636a5d36 JM |
8018 | } |
8019 | ||
8020 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
8021 | { | |
4c476991 JB |
8022 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8023 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 8024 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 8025 | int ie_len = 0, err; |
19957bb3 | 8026 | u16 reason_code; |
d5cdfacb | 8027 | bool local_state_change; |
636a5d36 | 8028 | |
f4a11bb0 JB |
8029 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
8030 | return -EINVAL; | |
8031 | ||
8032 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8033 | return -EINVAL; | |
8034 | ||
8035 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
8036 | return -EINVAL; | |
8037 | ||
4c476991 JB |
8038 | if (!rdev->ops->disassoc) |
8039 | return -EOPNOTSUPP; | |
636a5d36 | 8040 | |
074ac8df | 8041 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8042 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8043 | return -EOPNOTSUPP; | |
eec60b03 | 8044 | |
19957bb3 | 8045 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 8046 | |
19957bb3 JB |
8047 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
8048 | if (reason_code == 0) { | |
f4a11bb0 | 8049 | /* Reason Code 0 is reserved */ |
4c476991 | 8050 | return -EINVAL; |
255e737e | 8051 | } |
636a5d36 JM |
8052 | |
8053 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
8054 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
8055 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
8056 | } |
8057 | ||
d5cdfacb JM |
8058 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
8059 | ||
91bf9b26 JB |
8060 | wdev_lock(dev->ieee80211_ptr); |
8061 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
8062 | local_state_change); | |
8063 | wdev_unlock(dev->ieee80211_ptr); | |
8064 | return err; | |
636a5d36 JM |
8065 | } |
8066 | ||
dd5b4cc7 FF |
8067 | static bool |
8068 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
57fbcce3 | 8069 | int mcast_rate[NUM_NL80211_BANDS], |
dd5b4cc7 FF |
8070 | int rateval) |
8071 | { | |
8072 | struct wiphy *wiphy = &rdev->wiphy; | |
8073 | bool found = false; | |
8074 | int band, i; | |
8075 | ||
57fbcce3 | 8076 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
dd5b4cc7 FF |
8077 | struct ieee80211_supported_band *sband; |
8078 | ||
8079 | sband = wiphy->bands[band]; | |
8080 | if (!sband) | |
8081 | continue; | |
8082 | ||
8083 | for (i = 0; i < sband->n_bitrates; i++) { | |
8084 | if (sband->bitrates[i].bitrate == rateval) { | |
8085 | mcast_rate[band] = i + 1; | |
8086 | found = true; | |
8087 | break; | |
8088 | } | |
8089 | } | |
8090 | } | |
8091 | ||
8092 | return found; | |
8093 | } | |
8094 | ||
04a773ad JB |
8095 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
8096 | { | |
4c476991 JB |
8097 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8098 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
8099 | struct cfg80211_ibss_params ibss; |
8100 | struct wiphy *wiphy; | |
fffd0934 | 8101 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
8102 | int err; |
8103 | ||
8e30bc55 JB |
8104 | memset(&ibss, 0, sizeof(ibss)); |
8105 | ||
04a773ad JB |
8106 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
8107 | return -EINVAL; | |
8108 | ||
683b6d3b | 8109 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
8110 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
8111 | return -EINVAL; | |
8112 | ||
8e30bc55 JB |
8113 | ibss.beacon_interval = 100; |
8114 | ||
12d20fc9 | 8115 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
8e30bc55 JB |
8116 | ibss.beacon_interval = |
8117 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
12d20fc9 PK |
8118 | |
8119 | err = cfg80211_validate_beacon_int(rdev, ibss.beacon_interval); | |
8120 | if (err) | |
8121 | return err; | |
8e30bc55 | 8122 | |
4c476991 JB |
8123 | if (!rdev->ops->join_ibss) |
8124 | return -EOPNOTSUPP; | |
04a773ad | 8125 | |
4c476991 JB |
8126 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
8127 | return -EOPNOTSUPP; | |
04a773ad | 8128 | |
79c97e97 | 8129 | wiphy = &rdev->wiphy; |
04a773ad | 8130 | |
39193498 | 8131 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 8132 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
8133 | |
8134 | if (!is_valid_ether_addr(ibss.bssid)) | |
8135 | return -EINVAL; | |
8136 | } | |
04a773ad JB |
8137 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
8138 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
8139 | ||
8140 | if (info->attrs[NL80211_ATTR_IE]) { | |
8141 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8142 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8143 | } | |
8144 | ||
683b6d3b JB |
8145 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
8146 | if (err) | |
8147 | return err; | |
04a773ad | 8148 | |
174e0cd2 IP |
8149 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
8150 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
8151 | return -EINVAL; |
8152 | ||
2f301ab2 | 8153 | switch (ibss.chandef.width) { |
bf372645 SW |
8154 | case NL80211_CHAN_WIDTH_5: |
8155 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
8156 | case NL80211_CHAN_WIDTH_20_NOHT: |
8157 | break; | |
8158 | case NL80211_CHAN_WIDTH_20: | |
8159 | case NL80211_CHAN_WIDTH_40: | |
ffc11991 JD |
8160 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
8161 | return -EINVAL; | |
8162 | break; | |
8163 | case NL80211_CHAN_WIDTH_80: | |
8164 | case NL80211_CHAN_WIDTH_80P80: | |
8165 | case NL80211_CHAN_WIDTH_160: | |
8166 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | |
8167 | return -EINVAL; | |
8168 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
8169 | NL80211_EXT_FEATURE_VHT_IBSS)) | |
8170 | return -EINVAL; | |
8171 | break; | |
2f301ab2 | 8172 | default: |
c04d6150 | 8173 | return -EINVAL; |
2f301ab2 | 8174 | } |
db9c64cf | 8175 | |
04a773ad | 8176 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
8177 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
8178 | ||
fbd2c8dc TP |
8179 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8180 | u8 *rates = | |
8181 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8182 | int n_rates = | |
8183 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8184 | struct ieee80211_supported_band *sband = | |
683b6d3b | 8185 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 8186 | |
34850ab2 JB |
8187 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
8188 | &ibss.basic_rates); | |
8189 | if (err) | |
8190 | return err; | |
fbd2c8dc | 8191 | } |
dd5b4cc7 | 8192 | |
803768f5 SW |
8193 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
8194 | memcpy(&ibss.ht_capa_mask, | |
8195 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
8196 | sizeof(ibss.ht_capa_mask)); | |
8197 | ||
8198 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
8199 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
8200 | return -EINVAL; | |
8201 | memcpy(&ibss.ht_capa, | |
8202 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
8203 | sizeof(ibss.ht_capa)); | |
8204 | } | |
8205 | ||
dd5b4cc7 FF |
8206 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8207 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
8208 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8209 | return -EINVAL; | |
fbd2c8dc | 8210 | |
4c476991 | 8211 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
8212 | bool no_ht = false; |
8213 | ||
4c476991 | 8214 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
8215 | info->attrs[NL80211_ATTR_KEYS], |
8216 | &no_ht); | |
4c476991 JB |
8217 | if (IS_ERR(connkeys)) |
8218 | return PTR_ERR(connkeys); | |
de7044ee | 8219 | |
3d9d1d66 JB |
8220 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
8221 | no_ht) { | |
5e950a78 | 8222 | kzfree(connkeys); |
de7044ee SM |
8223 | return -EINVAL; |
8224 | } | |
4c476991 | 8225 | } |
04a773ad | 8226 | |
267335d6 AQ |
8227 | ibss.control_port = |
8228 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
8229 | ||
5336fa88 SW |
8230 | ibss.userspace_handles_dfs = |
8231 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
8232 | ||
4c476991 | 8233 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 | 8234 | if (err) |
b47f610b | 8235 | kzfree(connkeys); |
04a773ad JB |
8236 | return err; |
8237 | } | |
8238 | ||
8239 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
8240 | { | |
4c476991 JB |
8241 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8242 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 8243 | |
4c476991 JB |
8244 | if (!rdev->ops->leave_ibss) |
8245 | return -EOPNOTSUPP; | |
04a773ad | 8246 | |
4c476991 JB |
8247 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
8248 | return -EOPNOTSUPP; | |
04a773ad | 8249 | |
4c476991 | 8250 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
8251 | } |
8252 | ||
f4e583c8 AQ |
8253 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
8254 | { | |
8255 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8256 | struct net_device *dev = info->user_ptr[1]; | |
57fbcce3 | 8257 | int mcast_rate[NUM_NL80211_BANDS]; |
f4e583c8 AQ |
8258 | u32 nla_rate; |
8259 | int err; | |
8260 | ||
8261 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
876dc930 BVB |
8262 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
8263 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) | |
f4e583c8 AQ |
8264 | return -EOPNOTSUPP; |
8265 | ||
8266 | if (!rdev->ops->set_mcast_rate) | |
8267 | return -EOPNOTSUPP; | |
8268 | ||
8269 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
8270 | ||
8271 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
8272 | return -EINVAL; | |
8273 | ||
8274 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
8275 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
8276 | return -EINVAL; | |
8277 | ||
a1056b1b | 8278 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
f4e583c8 AQ |
8279 | |
8280 | return err; | |
8281 | } | |
8282 | ||
ad7e718c JB |
8283 | static struct sk_buff * |
8284 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
6c09e791 AK |
8285 | struct wireless_dev *wdev, int approxlen, |
8286 | u32 portid, u32 seq, enum nl80211_commands cmd, | |
567ffc35 JB |
8287 | enum nl80211_attrs attr, |
8288 | const struct nl80211_vendor_cmd_info *info, | |
8289 | gfp_t gfp) | |
ad7e718c JB |
8290 | { |
8291 | struct sk_buff *skb; | |
8292 | void *hdr; | |
8293 | struct nlattr *data; | |
8294 | ||
8295 | skb = nlmsg_new(approxlen + 100, gfp); | |
8296 | if (!skb) | |
8297 | return NULL; | |
8298 | ||
8299 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
8300 | if (!hdr) { | |
8301 | kfree_skb(skb); | |
8302 | return NULL; | |
8303 | } | |
8304 | ||
8305 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
8306 | goto nla_put_failure; | |
567ffc35 JB |
8307 | |
8308 | if (info) { | |
8309 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
8310 | info->vendor_id)) | |
8311 | goto nla_put_failure; | |
8312 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
8313 | info->subcmd)) | |
8314 | goto nla_put_failure; | |
8315 | } | |
8316 | ||
6c09e791 | 8317 | if (wdev) { |
2dad624e ND |
8318 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
8319 | wdev_id(wdev), NL80211_ATTR_PAD)) | |
6c09e791 AK |
8320 | goto nla_put_failure; |
8321 | if (wdev->netdev && | |
8322 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, | |
8323 | wdev->netdev->ifindex)) | |
8324 | goto nla_put_failure; | |
8325 | } | |
8326 | ||
ad7e718c | 8327 | data = nla_nest_start(skb, attr); |
76e1fb4b JB |
8328 | if (!data) |
8329 | goto nla_put_failure; | |
ad7e718c JB |
8330 | |
8331 | ((void **)skb->cb)[0] = rdev; | |
8332 | ((void **)skb->cb)[1] = hdr; | |
8333 | ((void **)skb->cb)[2] = data; | |
8334 | ||
8335 | return skb; | |
8336 | ||
8337 | nla_put_failure: | |
8338 | kfree_skb(skb); | |
8339 | return NULL; | |
8340 | } | |
f4e583c8 | 8341 | |
e03ad6ea | 8342 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
6c09e791 | 8343 | struct wireless_dev *wdev, |
e03ad6ea JB |
8344 | enum nl80211_commands cmd, |
8345 | enum nl80211_attrs attr, | |
8346 | int vendor_event_idx, | |
8347 | int approxlen, gfp_t gfp) | |
8348 | { | |
f26cbf40 | 8349 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
8350 | const struct nl80211_vendor_cmd_info *info; |
8351 | ||
8352 | switch (cmd) { | |
8353 | case NL80211_CMD_TESTMODE: | |
8354 | if (WARN_ON(vendor_event_idx != -1)) | |
8355 | return NULL; | |
8356 | info = NULL; | |
8357 | break; | |
8358 | case NL80211_CMD_VENDOR: | |
8359 | if (WARN_ON(vendor_event_idx < 0 || | |
8360 | vendor_event_idx >= wiphy->n_vendor_events)) | |
8361 | return NULL; | |
8362 | info = &wiphy->vendor_events[vendor_event_idx]; | |
8363 | break; | |
8364 | default: | |
8365 | WARN_ON(1); | |
8366 | return NULL; | |
8367 | } | |
8368 | ||
6c09e791 | 8369 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
e03ad6ea JB |
8370 | cmd, attr, info, gfp); |
8371 | } | |
8372 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
8373 | ||
8374 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
8375 | { | |
8376 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
8377 | void *hdr = ((void **)skb->cb)[1]; | |
8378 | struct nlattr *data = ((void **)skb->cb)[2]; | |
8379 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
8380 | ||
bd8c78e7 JB |
8381 | /* clear CB data for netlink core to own from now on */ |
8382 | memset(skb->cb, 0, sizeof(skb->cb)); | |
8383 | ||
e03ad6ea JB |
8384 | nla_nest_end(skb, data); |
8385 | genlmsg_end(skb, hdr); | |
8386 | ||
8387 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
8388 | mcgrp = NL80211_MCGRP_VENDOR; | |
8389 | ||
8390 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
8391 | mcgrp, gfp); | |
8392 | } | |
8393 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
8394 | ||
aff89a9b | 8395 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
8396 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
8397 | { | |
4c476991 | 8398 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
8399 | struct wireless_dev *wdev = |
8400 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
8401 | int err; |
8402 | ||
fc73f11f DS |
8403 | if (!rdev->ops->testmode_cmd) |
8404 | return -EOPNOTSUPP; | |
8405 | ||
8406 | if (IS_ERR(wdev)) { | |
8407 | err = PTR_ERR(wdev); | |
8408 | if (err != -EINVAL) | |
8409 | return err; | |
8410 | wdev = NULL; | |
8411 | } else if (wdev->wiphy != &rdev->wiphy) { | |
8412 | return -EINVAL; | |
8413 | } | |
8414 | ||
aff89a9b JB |
8415 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
8416 | return -EINVAL; | |
8417 | ||
ad7e718c | 8418 | rdev->cur_cmd_info = info; |
fc73f11f | 8419 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
8420 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
8421 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 8422 | rdev->cur_cmd_info = NULL; |
aff89a9b | 8423 | |
aff89a9b JB |
8424 | return err; |
8425 | } | |
8426 | ||
71063f0e WYG |
8427 | static int nl80211_testmode_dump(struct sk_buff *skb, |
8428 | struct netlink_callback *cb) | |
8429 | { | |
00918d33 | 8430 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
8431 | int err; |
8432 | long phy_idx; | |
8433 | void *data = NULL; | |
8434 | int data_len = 0; | |
8435 | ||
5fe231e8 JB |
8436 | rtnl_lock(); |
8437 | ||
71063f0e WYG |
8438 | if (cb->args[0]) { |
8439 | /* | |
8440 | * 0 is a valid index, but not valid for args[0], | |
8441 | * so we need to offset by 1. | |
8442 | */ | |
8443 | phy_idx = cb->args[0] - 1; | |
8444 | } else { | |
8445 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
8446 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
8447 | nl80211_policy); | |
8448 | if (err) | |
5fe231e8 | 8449 | goto out_err; |
00918d33 | 8450 | |
2bd7e35d JB |
8451 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
8452 | nl80211_fam.attrbuf); | |
8453 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
8454 | err = PTR_ERR(rdev); |
8455 | goto out_err; | |
00918d33 | 8456 | } |
2bd7e35d JB |
8457 | phy_idx = rdev->wiphy_idx; |
8458 | rdev = NULL; | |
2bd7e35d | 8459 | |
71063f0e WYG |
8460 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
8461 | cb->args[1] = | |
8462 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
8463 | } | |
8464 | ||
8465 | if (cb->args[1]) { | |
8466 | data = nla_data((void *)cb->args[1]); | |
8467 | data_len = nla_len((void *)cb->args[1]); | |
8468 | } | |
8469 | ||
00918d33 JB |
8470 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
8471 | if (!rdev) { | |
5fe231e8 JB |
8472 | err = -ENOENT; |
8473 | goto out_err; | |
71063f0e | 8474 | } |
71063f0e | 8475 | |
00918d33 | 8476 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
8477 | err = -EOPNOTSUPP; |
8478 | goto out_err; | |
8479 | } | |
8480 | ||
8481 | while (1) { | |
15e47304 | 8482 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
8483 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
8484 | NL80211_CMD_TESTMODE); | |
8485 | struct nlattr *tmdata; | |
8486 | ||
cb35fba3 DC |
8487 | if (!hdr) |
8488 | break; | |
8489 | ||
9360ffd1 | 8490 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
8491 | genlmsg_cancel(skb, hdr); |
8492 | break; | |
8493 | } | |
8494 | ||
8495 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
8496 | if (!tmdata) { | |
8497 | genlmsg_cancel(skb, hdr); | |
8498 | break; | |
8499 | } | |
e35e4d28 | 8500 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
8501 | nla_nest_end(skb, tmdata); |
8502 | ||
8503 | if (err == -ENOBUFS || err == -ENOENT) { | |
8504 | genlmsg_cancel(skb, hdr); | |
8505 | break; | |
8506 | } else if (err) { | |
8507 | genlmsg_cancel(skb, hdr); | |
8508 | goto out_err; | |
8509 | } | |
8510 | ||
8511 | genlmsg_end(skb, hdr); | |
8512 | } | |
8513 | ||
8514 | err = skb->len; | |
8515 | /* see above */ | |
8516 | cb->args[0] = phy_idx + 1; | |
8517 | out_err: | |
5fe231e8 | 8518 | rtnl_unlock(); |
71063f0e WYG |
8519 | return err; |
8520 | } | |
aff89a9b JB |
8521 | #endif |
8522 | ||
b23aa676 SO |
8523 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
8524 | { | |
4c476991 JB |
8525 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8526 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
8527 | struct cfg80211_connect_params connect; |
8528 | struct wiphy *wiphy; | |
fffd0934 | 8529 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
8530 | int err; |
8531 | ||
8532 | memset(&connect, 0, sizeof(connect)); | |
8533 | ||
8534 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
8535 | return -EINVAL; | |
8536 | ||
8537 | if (!info->attrs[NL80211_ATTR_SSID] || | |
8538 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
8539 | return -EINVAL; | |
8540 | ||
8541 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
8542 | connect.auth_type = | |
8543 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
8544 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
8545 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
8546 | return -EINVAL; |
8547 | } else | |
8548 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
8549 | ||
8550 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
8551 | ||
c0692b8f | 8552 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 8553 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
8554 | if (err) |
8555 | return err; | |
b23aa676 | 8556 | |
074ac8df | 8557 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8558 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8559 | return -EOPNOTSUPP; | |
b23aa676 | 8560 | |
79c97e97 | 8561 | wiphy = &rdev->wiphy; |
b23aa676 | 8562 | |
4486ea98 BS |
8563 | connect.bg_scan_period = -1; |
8564 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
8565 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
8566 | connect.bg_scan_period = | |
8567 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
8568 | } | |
8569 | ||
b23aa676 SO |
8570 | if (info->attrs[NL80211_ATTR_MAC]) |
8571 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
8572 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
8573 | connect.bssid_hint = | |
8574 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
8575 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
8576 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
8577 | ||
8578 | if (info->attrs[NL80211_ATTR_IE]) { | |
8579 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8580 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8581 | } | |
8582 | ||
cee00a95 JM |
8583 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
8584 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
8585 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
8586 | connect.mfp != NL80211_MFP_NO) | |
8587 | return -EINVAL; | |
8588 | } else { | |
8589 | connect.mfp = NL80211_MFP_NO; | |
8590 | } | |
8591 | ||
ba6fbacf JM |
8592 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
8593 | connect.prev_bssid = | |
8594 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | |
8595 | ||
b23aa676 | 8596 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
8597 | connect.channel = nl80211_get_valid_chan( |
8598 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
8599 | if (!connect.channel) | |
1df4a510 JM |
8600 | return -EINVAL; |
8601 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
8602 | connect.channel_hint = nl80211_get_valid_chan( |
8603 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
8604 | if (!connect.channel_hint) | |
4c476991 | 8605 | return -EINVAL; |
b23aa676 SO |
8606 | } |
8607 | ||
fffd0934 JB |
8608 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
8609 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 8610 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
8611 | if (IS_ERR(connkeys)) |
8612 | return PTR_ERR(connkeys); | |
fffd0934 JB |
8613 | } |
8614 | ||
7e7c8926 BG |
8615 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
8616 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
8617 | ||
8618 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
8619 | memcpy(&connect.ht_capa_mask, | |
8620 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
8621 | sizeof(connect.ht_capa_mask)); | |
8622 | ||
8623 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e | 8624 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
b47f610b | 8625 | kzfree(connkeys); |
7e7c8926 | 8626 | return -EINVAL; |
b4e4f47e | 8627 | } |
7e7c8926 BG |
8628 | memcpy(&connect.ht_capa, |
8629 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
8630 | sizeof(connect.ht_capa)); | |
8631 | } | |
8632 | ||
ee2aca34 JB |
8633 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
8634 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
8635 | ||
8636 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
8637 | memcpy(&connect.vht_capa_mask, | |
8638 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
8639 | sizeof(connect.vht_capa_mask)); | |
8640 | ||
8641 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
8642 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
b47f610b | 8643 | kzfree(connkeys); |
ee2aca34 JB |
8644 | return -EINVAL; |
8645 | } | |
8646 | memcpy(&connect.vht_capa, | |
8647 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
8648 | sizeof(connect.vht_capa)); | |
8649 | } | |
8650 | ||
bab5ab7d | 8651 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
0c9ca11b BL |
8652 | if (!((rdev->wiphy.features & |
8653 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && | |
8654 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && | |
8655 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
8656 | NL80211_EXT_FEATURE_RRM)) { | |
707554b4 | 8657 | kzfree(connkeys); |
bab5ab7d | 8658 | return -EINVAL; |
707554b4 | 8659 | } |
bab5ab7d AK |
8660 | connect.flags |= ASSOC_REQ_USE_RRM; |
8661 | } | |
8662 | ||
34d50519 | 8663 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
57fbcce3 | 8664 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
34d50519 LD |
8665 | kzfree(connkeys); |
8666 | return -EOPNOTSUPP; | |
8667 | } | |
8668 | ||
38de03d2 AS |
8669 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
8670 | /* bss selection makes no sense if bssid is set */ | |
8671 | if (connect.bssid) { | |
8672 | kzfree(connkeys); | |
8673 | return -EINVAL; | |
8674 | } | |
8675 | ||
8676 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], | |
8677 | wiphy, &connect.bss_select); | |
8678 | if (err) { | |
8679 | kzfree(connkeys); | |
8680 | return err; | |
8681 | } | |
8682 | } | |
8683 | ||
83739b03 | 8684 | wdev_lock(dev->ieee80211_ptr); |
4ce2bd9c JM |
8685 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
8686 | connect.prev_bssid); | |
83739b03 | 8687 | wdev_unlock(dev->ieee80211_ptr); |
fffd0934 | 8688 | if (err) |
b47f610b | 8689 | kzfree(connkeys); |
b23aa676 SO |
8690 | return err; |
8691 | } | |
8692 | ||
8693 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
8694 | { | |
4c476991 JB |
8695 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8696 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 8697 | u16 reason; |
83739b03 | 8698 | int ret; |
b23aa676 SO |
8699 | |
8700 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
8701 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
8702 | else | |
8703 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
8704 | ||
8705 | if (reason == 0) | |
8706 | return -EINVAL; | |
8707 | ||
074ac8df | 8708 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8709 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8710 | return -EOPNOTSUPP; | |
b23aa676 | 8711 | |
83739b03 JB |
8712 | wdev_lock(dev->ieee80211_ptr); |
8713 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
8714 | wdev_unlock(dev->ieee80211_ptr); | |
8715 | return ret; | |
b23aa676 SO |
8716 | } |
8717 | ||
463d0183 JB |
8718 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
8719 | { | |
4c476991 | 8720 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
8721 | struct net *net; |
8722 | int err; | |
463d0183 | 8723 | |
4b681c82 VK |
8724 | if (info->attrs[NL80211_ATTR_PID]) { |
8725 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
8726 | ||
8727 | net = get_net_ns_by_pid(pid); | |
8728 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { | |
8729 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); | |
463d0183 | 8730 | |
4b681c82 VK |
8731 | net = get_net_ns_by_fd(fd); |
8732 | } else { | |
8733 | return -EINVAL; | |
8734 | } | |
463d0183 | 8735 | |
4c476991 JB |
8736 | if (IS_ERR(net)) |
8737 | return PTR_ERR(net); | |
463d0183 JB |
8738 | |
8739 | err = 0; | |
8740 | ||
8741 | /* check if anything to do */ | |
4c476991 JB |
8742 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
8743 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 8744 | |
463d0183 | 8745 | put_net(net); |
463d0183 JB |
8746 | return err; |
8747 | } | |
8748 | ||
67fbb16b SO |
8749 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
8750 | { | |
4c476991 | 8751 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
8752 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
8753 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 8754 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
8755 | struct cfg80211_pmksa pmksa; |
8756 | ||
8757 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
8758 | ||
8759 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8760 | return -EINVAL; | |
8761 | ||
8762 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
8763 | return -EINVAL; | |
8764 | ||
67fbb16b SO |
8765 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
8766 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8767 | ||
074ac8df | 8768 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8769 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8770 | return -EOPNOTSUPP; | |
67fbb16b SO |
8771 | |
8772 | switch (info->genlhdr->cmd) { | |
8773 | case NL80211_CMD_SET_PMKSA: | |
8774 | rdev_ops = rdev->ops->set_pmksa; | |
8775 | break; | |
8776 | case NL80211_CMD_DEL_PMKSA: | |
8777 | rdev_ops = rdev->ops->del_pmksa; | |
8778 | break; | |
8779 | default: | |
8780 | WARN_ON(1); | |
8781 | break; | |
8782 | } | |
8783 | ||
4c476991 JB |
8784 | if (!rdev_ops) |
8785 | return -EOPNOTSUPP; | |
67fbb16b | 8786 | |
4c476991 | 8787 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
8788 | } |
8789 | ||
8790 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
8791 | { | |
4c476991 JB |
8792 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8793 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 8794 | |
074ac8df | 8795 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8796 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8797 | return -EOPNOTSUPP; | |
67fbb16b | 8798 | |
4c476991 JB |
8799 | if (!rdev->ops->flush_pmksa) |
8800 | return -EOPNOTSUPP; | |
67fbb16b | 8801 | |
e35e4d28 | 8802 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
8803 | } |
8804 | ||
109086ce AN |
8805 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
8806 | { | |
8807 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8808 | struct net_device *dev = info->user_ptr[1]; | |
8809 | u8 action_code, dialog_token; | |
df942e7b | 8810 | u32 peer_capability = 0; |
109086ce AN |
8811 | u16 status_code; |
8812 | u8 *peer; | |
31fa97c5 | 8813 | bool initiator; |
109086ce AN |
8814 | |
8815 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
8816 | !rdev->ops->tdls_mgmt) | |
8817 | return -EOPNOTSUPP; | |
8818 | ||
8819 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
8820 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
8821 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
8822 | !info->attrs[NL80211_ATTR_IE] || | |
8823 | !info->attrs[NL80211_ATTR_MAC]) | |
8824 | return -EINVAL; | |
8825 | ||
8826 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8827 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
8828 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
8829 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 8830 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
8831 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
8832 | peer_capability = | |
8833 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 8834 | |
e35e4d28 | 8835 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 8836 | dialog_token, status_code, peer_capability, |
31fa97c5 | 8837 | initiator, |
e35e4d28 HG |
8838 | nla_data(info->attrs[NL80211_ATTR_IE]), |
8839 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
8840 | } |
8841 | ||
8842 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
8843 | { | |
8844 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8845 | struct net_device *dev = info->user_ptr[1]; | |
8846 | enum nl80211_tdls_operation operation; | |
8847 | u8 *peer; | |
8848 | ||
8849 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
8850 | !rdev->ops->tdls_oper) | |
8851 | return -EOPNOTSUPP; | |
8852 | ||
8853 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
8854 | !info->attrs[NL80211_ATTR_MAC]) | |
8855 | return -EINVAL; | |
8856 | ||
8857 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
8858 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8859 | ||
e35e4d28 | 8860 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
8861 | } |
8862 | ||
9588bbd5 JM |
8863 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
8864 | struct genl_info *info) | |
8865 | { | |
4c476991 | 8866 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8867 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 8868 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
8869 | struct sk_buff *msg; |
8870 | void *hdr; | |
8871 | u64 cookie; | |
683b6d3b | 8872 | u32 duration; |
9588bbd5 JM |
8873 | int err; |
8874 | ||
8875 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
8876 | !info->attrs[NL80211_ATTR_DURATION]) | |
8877 | return -EINVAL; | |
8878 | ||
8879 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
8880 | ||
ebf348fc JB |
8881 | if (!rdev->ops->remain_on_channel || |
8882 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
8883 | return -EOPNOTSUPP; | |
8884 | ||
9588bbd5 | 8885 | /* |
ebf348fc JB |
8886 | * We should be on that channel for at least a minimum amount of |
8887 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 8888 | */ |
ebf348fc | 8889 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 8890 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
8891 | return -EINVAL; |
8892 | ||
683b6d3b JB |
8893 | err = nl80211_parse_chandef(rdev, info, &chandef); |
8894 | if (err) | |
8895 | return err; | |
9588bbd5 JM |
8896 | |
8897 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
8898 | if (!msg) |
8899 | return -ENOMEM; | |
9588bbd5 | 8900 | |
15e47304 | 8901 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 8902 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
8903 | if (!hdr) { |
8904 | err = -ENOBUFS; | |
9588bbd5 JM |
8905 | goto free_msg; |
8906 | } | |
8907 | ||
683b6d3b JB |
8908 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
8909 | duration, &cookie); | |
9588bbd5 JM |
8910 | |
8911 | if (err) | |
8912 | goto free_msg; | |
8913 | ||
2dad624e ND |
8914 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
8915 | NL80211_ATTR_PAD)) | |
9360ffd1 | 8916 | goto nla_put_failure; |
9588bbd5 JM |
8917 | |
8918 | genlmsg_end(msg, hdr); | |
4c476991 JB |
8919 | |
8920 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
8921 | |
8922 | nla_put_failure: | |
8923 | err = -ENOBUFS; | |
8924 | free_msg: | |
8925 | nlmsg_free(msg); | |
9588bbd5 JM |
8926 | return err; |
8927 | } | |
8928 | ||
8929 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
8930 | struct genl_info *info) | |
8931 | { | |
4c476991 | 8932 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8933 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 8934 | u64 cookie; |
9588bbd5 JM |
8935 | |
8936 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8937 | return -EINVAL; | |
8938 | ||
4c476991 JB |
8939 | if (!rdev->ops->cancel_remain_on_channel) |
8940 | return -EOPNOTSUPP; | |
9588bbd5 | 8941 | |
9588bbd5 JM |
8942 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
8943 | ||
e35e4d28 | 8944 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
8945 | } |
8946 | ||
13ae75b1 JM |
8947 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
8948 | struct genl_info *info) | |
8949 | { | |
13ae75b1 | 8950 | struct cfg80211_bitrate_mask mask; |
a7c7fbff | 8951 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 8952 | struct net_device *dev = info->user_ptr[1]; |
a7c7fbff | 8953 | int err; |
13ae75b1 | 8954 | |
4c476991 JB |
8955 | if (!rdev->ops->set_bitrate_mask) |
8956 | return -EOPNOTSUPP; | |
13ae75b1 | 8957 | |
a7c7fbff PK |
8958 | err = nl80211_parse_tx_bitrate_mask(info, &mask); |
8959 | if (err) | |
8960 | return err; | |
13ae75b1 | 8961 | |
e35e4d28 | 8962 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
8963 | } |
8964 | ||
2e161f78 | 8965 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8966 | { |
4c476991 | 8967 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8968 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 8969 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
8970 | |
8971 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
8972 | return -EINVAL; | |
8973 | ||
2e161f78 JB |
8974 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
8975 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 8976 | |
71bbc994 JB |
8977 | switch (wdev->iftype) { |
8978 | case NL80211_IFTYPE_STATION: | |
8979 | case NL80211_IFTYPE_ADHOC: | |
8980 | case NL80211_IFTYPE_P2P_CLIENT: | |
8981 | case NL80211_IFTYPE_AP: | |
8982 | case NL80211_IFTYPE_AP_VLAN: | |
8983 | case NL80211_IFTYPE_MESH_POINT: | |
8984 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8985 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 | 8986 | break; |
cb3b7d87 | 8987 | case NL80211_IFTYPE_NAN: |
71bbc994 | 8988 | default: |
4c476991 | 8989 | return -EOPNOTSUPP; |
71bbc994 | 8990 | } |
026331c4 JM |
8991 | |
8992 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
8993 | if (!rdev->ops->mgmt_tx) |
8994 | return -EOPNOTSUPP; | |
026331c4 | 8995 | |
15e47304 | 8996 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
8997 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
8998 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
8999 | } |
9000 | ||
2e161f78 | 9001 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 9002 | { |
4c476991 | 9003 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 9004 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 9005 | struct cfg80211_chan_def chandef; |
026331c4 | 9006 | int err; |
d64d373f | 9007 | void *hdr = NULL; |
026331c4 | 9008 | u64 cookie; |
e247bd90 | 9009 | struct sk_buff *msg = NULL; |
b176e629 AO |
9010 | struct cfg80211_mgmt_tx_params params = { |
9011 | .dont_wait_for_ack = | |
9012 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
9013 | }; | |
026331c4 | 9014 | |
683b6d3b | 9015 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
9016 | return -EINVAL; |
9017 | ||
4c476991 JB |
9018 | if (!rdev->ops->mgmt_tx) |
9019 | return -EOPNOTSUPP; | |
026331c4 | 9020 | |
71bbc994 | 9021 | switch (wdev->iftype) { |
ea141b75 AQ |
9022 | case NL80211_IFTYPE_P2P_DEVICE: |
9023 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
9024 | return -EINVAL; | |
71bbc994 JB |
9025 | case NL80211_IFTYPE_STATION: |
9026 | case NL80211_IFTYPE_ADHOC: | |
9027 | case NL80211_IFTYPE_P2P_CLIENT: | |
9028 | case NL80211_IFTYPE_AP: | |
9029 | case NL80211_IFTYPE_AP_VLAN: | |
9030 | case NL80211_IFTYPE_MESH_POINT: | |
9031 | case NL80211_IFTYPE_P2P_GO: | |
9032 | break; | |
cb3b7d87 | 9033 | case NL80211_IFTYPE_NAN: |
71bbc994 | 9034 | default: |
4c476991 | 9035 | return -EOPNOTSUPP; |
71bbc994 | 9036 | } |
026331c4 | 9037 | |
f7ca38df | 9038 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 9039 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 9040 | return -EINVAL; |
b176e629 | 9041 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
9042 | |
9043 | /* | |
9044 | * We should wait on the channel for at least a minimum amount | |
9045 | * of time (10ms) but no longer than the driver supports. | |
9046 | */ | |
b176e629 AO |
9047 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
9048 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc | 9049 | return -EINVAL; |
f7ca38df JB |
9050 | } |
9051 | ||
b176e629 | 9052 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 9053 | |
b176e629 | 9054 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
9055 | return -EINVAL; |
9056 | ||
b176e629 | 9057 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 9058 | |
ea141b75 AQ |
9059 | /* get the channel if any has been specified, otherwise pass NULL to |
9060 | * the driver. The latter will use the current one | |
9061 | */ | |
9062 | chandef.chan = NULL; | |
9063 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
9064 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
9065 | if (err) | |
9066 | return err; | |
9067 | } | |
9068 | ||
b176e629 | 9069 | if (!chandef.chan && params.offchan) |
ea141b75 | 9070 | return -EINVAL; |
026331c4 | 9071 | |
34d22ce2 AO |
9072 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
9073 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
9074 | ||
9075 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
9076 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
9077 | int i; | |
9078 | ||
9079 | if (len % sizeof(u16)) | |
9080 | return -EINVAL; | |
9081 | ||
9082 | params.n_csa_offsets = len / sizeof(u16); | |
9083 | params.csa_offsets = | |
9084 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
9085 | ||
9086 | /* check that all the offsets fit the frame */ | |
9087 | for (i = 0; i < params.n_csa_offsets; i++) { | |
9088 | if (params.csa_offsets[i] >= params.len) | |
9089 | return -EINVAL; | |
9090 | } | |
9091 | } | |
9092 | ||
b176e629 | 9093 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
9094 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
9095 | if (!msg) | |
9096 | return -ENOMEM; | |
026331c4 | 9097 | |
15e47304 | 9098 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 9099 | NL80211_CMD_FRAME); |
cb35fba3 DC |
9100 | if (!hdr) { |
9101 | err = -ENOBUFS; | |
e247bd90 JB |
9102 | goto free_msg; |
9103 | } | |
026331c4 | 9104 | } |
e247bd90 | 9105 | |
b176e629 AO |
9106 | params.chan = chandef.chan; |
9107 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
9108 | if (err) |
9109 | goto free_msg; | |
9110 | ||
e247bd90 | 9111 | if (msg) { |
2dad624e ND |
9112 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
9113 | NL80211_ATTR_PAD)) | |
9360ffd1 | 9114 | goto nla_put_failure; |
026331c4 | 9115 | |
e247bd90 JB |
9116 | genlmsg_end(msg, hdr); |
9117 | return genlmsg_reply(msg, info); | |
9118 | } | |
9119 | ||
9120 | return 0; | |
026331c4 JM |
9121 | |
9122 | nla_put_failure: | |
9123 | err = -ENOBUFS; | |
9124 | free_msg: | |
9125 | nlmsg_free(msg); | |
026331c4 JM |
9126 | return err; |
9127 | } | |
9128 | ||
f7ca38df JB |
9129 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
9130 | { | |
9131 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 9132 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
9133 | u64 cookie; |
9134 | ||
9135 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
9136 | return -EINVAL; | |
9137 | ||
9138 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
9139 | return -EOPNOTSUPP; | |
9140 | ||
71bbc994 JB |
9141 | switch (wdev->iftype) { |
9142 | case NL80211_IFTYPE_STATION: | |
9143 | case NL80211_IFTYPE_ADHOC: | |
9144 | case NL80211_IFTYPE_P2P_CLIENT: | |
9145 | case NL80211_IFTYPE_AP: | |
9146 | case NL80211_IFTYPE_AP_VLAN: | |
9147 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 9148 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 | 9149 | break; |
cb3b7d87 | 9150 | case NL80211_IFTYPE_NAN: |
71bbc994 | 9151 | default: |
f7ca38df | 9152 | return -EOPNOTSUPP; |
71bbc994 | 9153 | } |
f7ca38df JB |
9154 | |
9155 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
9156 | ||
e35e4d28 | 9157 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
9158 | } |
9159 | ||
ffb9eb3d KV |
9160 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
9161 | { | |
4c476991 | 9162 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 9163 | struct wireless_dev *wdev; |
4c476991 | 9164 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
9165 | u8 ps_state; |
9166 | bool state; | |
9167 | int err; | |
9168 | ||
4c476991 JB |
9169 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
9170 | return -EINVAL; | |
ffb9eb3d KV |
9171 | |
9172 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
9173 | ||
4c476991 JB |
9174 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
9175 | return -EINVAL; | |
ffb9eb3d KV |
9176 | |
9177 | wdev = dev->ieee80211_ptr; | |
9178 | ||
4c476991 JB |
9179 | if (!rdev->ops->set_power_mgmt) |
9180 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
9181 | |
9182 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
9183 | ||
9184 | if (state == wdev->ps) | |
4c476991 | 9185 | return 0; |
ffb9eb3d | 9186 | |
e35e4d28 | 9187 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
9188 | if (!err) |
9189 | wdev->ps = state; | |
ffb9eb3d KV |
9190 | return err; |
9191 | } | |
9192 | ||
9193 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
9194 | { | |
4c476991 | 9195 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
9196 | enum nl80211_ps_state ps_state; |
9197 | struct wireless_dev *wdev; | |
4c476991 | 9198 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
9199 | struct sk_buff *msg; |
9200 | void *hdr; | |
9201 | int err; | |
9202 | ||
ffb9eb3d KV |
9203 | wdev = dev->ieee80211_ptr; |
9204 | ||
4c476991 JB |
9205 | if (!rdev->ops->set_power_mgmt) |
9206 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
9207 | |
9208 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
9209 | if (!msg) |
9210 | return -ENOMEM; | |
ffb9eb3d | 9211 | |
15e47304 | 9212 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
9213 | NL80211_CMD_GET_POWER_SAVE); |
9214 | if (!hdr) { | |
4c476991 | 9215 | err = -ENOBUFS; |
ffb9eb3d KV |
9216 | goto free_msg; |
9217 | } | |
9218 | ||
9219 | if (wdev->ps) | |
9220 | ps_state = NL80211_PS_ENABLED; | |
9221 | else | |
9222 | ps_state = NL80211_PS_DISABLED; | |
9223 | ||
9360ffd1 DM |
9224 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
9225 | goto nla_put_failure; | |
ffb9eb3d KV |
9226 | |
9227 | genlmsg_end(msg, hdr); | |
4c476991 | 9228 | return genlmsg_reply(msg, info); |
ffb9eb3d | 9229 | |
4c476991 | 9230 | nla_put_failure: |
ffb9eb3d | 9231 | err = -ENOBUFS; |
4c476991 | 9232 | free_msg: |
ffb9eb3d | 9233 | nlmsg_free(msg); |
ffb9eb3d KV |
9234 | return err; |
9235 | } | |
9236 | ||
94e860f1 JB |
9237 | static const struct nla_policy |
9238 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
9239 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
9240 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
9241 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
9242 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
9243 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
9244 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
9245 | }; |
9246 | ||
84f10708 | 9247 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 9248 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
9249 | { |
9250 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 9251 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 9252 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 9253 | |
d9d8b019 | 9254 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
9255 | return -EINVAL; |
9256 | ||
84f10708 TP |
9257 | if (!rdev->ops->set_cqm_txe_config) |
9258 | return -EOPNOTSUPP; | |
9259 | ||
9260 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
9261 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
9262 | return -EOPNOTSUPP; | |
9263 | ||
e35e4d28 | 9264 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
9265 | } |
9266 | ||
d6dc1a38 JO |
9267 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
9268 | s32 threshold, u32 hysteresis) | |
9269 | { | |
4c476991 | 9270 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 9271 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 9272 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
9273 | |
9274 | if (threshold > 0) | |
9275 | return -EINVAL; | |
9276 | ||
1da5fcc8 JB |
9277 | /* disabling - hysteresis should also be zero then */ |
9278 | if (threshold == 0) | |
9279 | hysteresis = 0; | |
d6dc1a38 | 9280 | |
4c476991 JB |
9281 | if (!rdev->ops->set_cqm_rssi_config) |
9282 | return -EOPNOTSUPP; | |
d6dc1a38 | 9283 | |
074ac8df | 9284 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
9285 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
9286 | return -EOPNOTSUPP; | |
d6dc1a38 | 9287 | |
e35e4d28 | 9288 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
9289 | } |
9290 | ||
9291 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
9292 | { | |
9293 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
9294 | struct nlattr *cqm; | |
9295 | int err; | |
9296 | ||
9297 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
9298 | if (!cqm) |
9299 | return -EINVAL; | |
d6dc1a38 JO |
9300 | |
9301 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
9302 | nl80211_attr_cqm_policy); | |
9303 | if (err) | |
1da5fcc8 | 9304 | return err; |
d6dc1a38 JO |
9305 | |
9306 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
9307 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
9308 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
9309 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 9310 | |
1da5fcc8 JB |
9311 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
9312 | } | |
9313 | ||
9314 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
9315 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
9316 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
9317 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
9318 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
9319 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
9320 | ||
9321 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
9322 | } | |
9323 | ||
9324 | return -EINVAL; | |
d6dc1a38 JO |
9325 | } |
9326 | ||
6e0bd6c3 RL |
9327 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
9328 | { | |
9329 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9330 | struct net_device *dev = info->user_ptr[1]; | |
9331 | struct ocb_setup setup = {}; | |
9332 | int err; | |
9333 | ||
9334 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | |
9335 | if (err) | |
9336 | return err; | |
9337 | ||
9338 | return cfg80211_join_ocb(rdev, dev, &setup); | |
9339 | } | |
9340 | ||
9341 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | |
9342 | { | |
9343 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9344 | struct net_device *dev = info->user_ptr[1]; | |
9345 | ||
9346 | return cfg80211_leave_ocb(rdev, dev); | |
9347 | } | |
9348 | ||
29cbe68c JB |
9349 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
9350 | { | |
9351 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9352 | struct net_device *dev = info->user_ptr[1]; | |
9353 | struct mesh_config cfg; | |
c80d545d | 9354 | struct mesh_setup setup; |
29cbe68c JB |
9355 | int err; |
9356 | ||
9357 | /* start with default */ | |
9358 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 9359 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 9360 | |
24bdd9f4 | 9361 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 9362 | /* and parse parameters if given */ |
24bdd9f4 | 9363 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
9364 | if (err) |
9365 | return err; | |
9366 | } | |
9367 | ||
9368 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
9369 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
9370 | return -EINVAL; | |
9371 | ||
c80d545d JC |
9372 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
9373 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
9374 | ||
4bb62344 CYY |
9375 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
9376 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
9377 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
9378 | return -EINVAL; | |
9379 | ||
9bdbf04d MP |
9380 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
9381 | setup.beacon_interval = | |
9382 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
12d20fc9 PK |
9383 | |
9384 | err = cfg80211_validate_beacon_int(rdev, setup.beacon_interval); | |
9385 | if (err) | |
9386 | return err; | |
9bdbf04d MP |
9387 | } |
9388 | ||
9389 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
9390 | setup.dtim_period = | |
9391 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
9392 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
9393 | return -EINVAL; | |
9394 | } | |
9395 | ||
c80d545d JC |
9396 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
9397 | /* parse additional setup parameters if given */ | |
9398 | err = nl80211_parse_mesh_setup(info, &setup); | |
9399 | if (err) | |
9400 | return err; | |
9401 | } | |
9402 | ||
d37bb18a TP |
9403 | if (setup.user_mpm) |
9404 | cfg.auto_open_plinks = false; | |
9405 | ||
cc1d2806 | 9406 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
9407 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
9408 | if (err) | |
9409 | return err; | |
cc1d2806 JB |
9410 | } else { |
9411 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 9412 | setup.chandef.chan = NULL; |
cc1d2806 JB |
9413 | } |
9414 | ||
ffb3cf30 AN |
9415 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
9416 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
9417 | int n_rates = | |
9418 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
9419 | struct ieee80211_supported_band *sband; | |
9420 | ||
9421 | if (!setup.chandef.chan) | |
9422 | return -EINVAL; | |
9423 | ||
9424 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
9425 | ||
9426 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
9427 | &setup.basic_rates); | |
9428 | if (err) | |
9429 | return err; | |
9430 | } | |
9431 | ||
8564e382 JB |
9432 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
9433 | err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate); | |
9434 | if (err) | |
9435 | return err; | |
9436 | ||
9437 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, | |
9438 | &setup.beacon_rate); | |
9439 | if (err) | |
9440 | return err; | |
9441 | } | |
9442 | ||
c80d545d | 9443 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
9444 | } |
9445 | ||
9446 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
9447 | { | |
9448 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9449 | struct net_device *dev = info->user_ptr[1]; | |
9450 | ||
9451 | return cfg80211_leave_mesh(rdev, dev); | |
9452 | } | |
9453 | ||
dfb89c56 | 9454 | #ifdef CONFIG_PM |
bb92d199 AK |
9455 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
9456 | struct cfg80211_registered_device *rdev) | |
9457 | { | |
6abb9cb9 | 9458 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
9459 | struct nlattr *nl_pats, *nl_pat; |
9460 | int i, pat_len; | |
9461 | ||
6abb9cb9 | 9462 | if (!wowlan->n_patterns) |
bb92d199 AK |
9463 | return 0; |
9464 | ||
9465 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
9466 | if (!nl_pats) | |
9467 | return -ENOBUFS; | |
9468 | ||
6abb9cb9 | 9469 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
9470 | nl_pat = nla_nest_start(msg, i + 1); |
9471 | if (!nl_pat) | |
9472 | return -ENOBUFS; | |
6abb9cb9 | 9473 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 9474 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 9475 | wowlan->patterns[i].mask) || |
50ac6607 AK |
9476 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
9477 | wowlan->patterns[i].pattern) || | |
9478 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 9479 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
9480 | return -ENOBUFS; |
9481 | nla_nest_end(msg, nl_pat); | |
9482 | } | |
9483 | nla_nest_end(msg, nl_pats); | |
9484 | ||
9485 | return 0; | |
9486 | } | |
9487 | ||
2a0e047e JB |
9488 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
9489 | struct cfg80211_wowlan_tcp *tcp) | |
9490 | { | |
9491 | struct nlattr *nl_tcp; | |
9492 | ||
9493 | if (!tcp) | |
9494 | return 0; | |
9495 | ||
9496 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
9497 | if (!nl_tcp) | |
9498 | return -ENOBUFS; | |
9499 | ||
930345ea JB |
9500 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
9501 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
2a0e047e JB |
9502 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
9503 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
9504 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
9505 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
9506 | tcp->payload_len, tcp->payload) || | |
9507 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
9508 | tcp->data_interval) || | |
9509 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
9510 | tcp->wake_len, tcp->wake_data) || | |
9511 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
9512 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
9513 | return -ENOBUFS; | |
9514 | ||
9515 | if (tcp->payload_seq.len && | |
9516 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
9517 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
9518 | return -ENOBUFS; | |
9519 | ||
9520 | if (tcp->payload_tok.len && | |
9521 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
9522 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
9523 | &tcp->payload_tok)) | |
9524 | return -ENOBUFS; | |
9525 | ||
e248ad30 JB |
9526 | nla_nest_end(msg, nl_tcp); |
9527 | ||
2a0e047e JB |
9528 | return 0; |
9529 | } | |
9530 | ||
75453ccb LC |
9531 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
9532 | struct cfg80211_sched_scan_request *req) | |
9533 | { | |
3b06d277 | 9534 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
75453ccb LC |
9535 | int i; |
9536 | ||
9537 | if (!req) | |
9538 | return 0; | |
9539 | ||
9540 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); | |
9541 | if (!nd) | |
9542 | return -ENOBUFS; | |
9543 | ||
3b06d277 AS |
9544 | if (req->n_scan_plans == 1 && |
9545 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, | |
9546 | req->scan_plans[0].interval * 1000)) | |
75453ccb LC |
9547 | return -ENOBUFS; |
9548 | ||
21fea567 LC |
9549 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
9550 | return -ENOBUFS; | |
9551 | ||
75453ccb LC |
9552 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
9553 | if (!freqs) | |
9554 | return -ENOBUFS; | |
9555 | ||
53b18980 JB |
9556 | for (i = 0; i < req->n_channels; i++) { |
9557 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
9558 | return -ENOBUFS; | |
9559 | } | |
75453ccb LC |
9560 | |
9561 | nla_nest_end(msg, freqs); | |
9562 | ||
9563 | if (req->n_match_sets) { | |
9564 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); | |
76e1fb4b JB |
9565 | if (!matches) |
9566 | return -ENOBUFS; | |
9567 | ||
75453ccb LC |
9568 | for (i = 0; i < req->n_match_sets; i++) { |
9569 | match = nla_nest_start(msg, i); | |
76e1fb4b JB |
9570 | if (!match) |
9571 | return -ENOBUFS; | |
9572 | ||
53b18980 JB |
9573 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
9574 | req->match_sets[i].ssid.ssid_len, | |
9575 | req->match_sets[i].ssid.ssid)) | |
9576 | return -ENOBUFS; | |
75453ccb LC |
9577 | nla_nest_end(msg, match); |
9578 | } | |
9579 | nla_nest_end(msg, matches); | |
9580 | } | |
9581 | ||
3b06d277 AS |
9582 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
9583 | if (!scan_plans) | |
9584 | return -ENOBUFS; | |
9585 | ||
9586 | for (i = 0; i < req->n_scan_plans; i++) { | |
9587 | scan_plan = nla_nest_start(msg, i + 1); | |
76e1fb4b JB |
9588 | if (!scan_plan) |
9589 | return -ENOBUFS; | |
9590 | ||
3b06d277 AS |
9591 | if (!scan_plan || |
9592 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, | |
9593 | req->scan_plans[i].interval) || | |
9594 | (req->scan_plans[i].iterations && | |
9595 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, | |
9596 | req->scan_plans[i].iterations))) | |
9597 | return -ENOBUFS; | |
9598 | nla_nest_end(msg, scan_plan); | |
9599 | } | |
9600 | nla_nest_end(msg, scan_plans); | |
9601 | ||
75453ccb LC |
9602 | nla_nest_end(msg, nd); |
9603 | ||
9604 | return 0; | |
9605 | } | |
9606 | ||
ff1b6e69 JB |
9607 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
9608 | { | |
9609 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9610 | struct sk_buff *msg; | |
9611 | void *hdr; | |
2a0e047e | 9612 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 9613 | |
964dc9e2 | 9614 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
9615 | return -EOPNOTSUPP; |
9616 | ||
6abb9cb9 | 9617 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 9618 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
9619 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
9620 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
9621 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
9622 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
9623 | } |
9624 | ||
9625 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
9626 | if (!msg) |
9627 | return -ENOMEM; | |
9628 | ||
15e47304 | 9629 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
9630 | NL80211_CMD_GET_WOWLAN); |
9631 | if (!hdr) | |
9632 | goto nla_put_failure; | |
9633 | ||
6abb9cb9 | 9634 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
9635 | struct nlattr *nl_wowlan; |
9636 | ||
9637 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
9638 | if (!nl_wowlan) | |
9639 | goto nla_put_failure; | |
9640 | ||
6abb9cb9 | 9641 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 9642 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 9643 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 9644 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 9645 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 9646 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 9647 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 9648 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 9649 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 9650 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 9651 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 9652 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 9653 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
9654 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
9655 | goto nla_put_failure; | |
2a0e047e | 9656 | |
bb92d199 AK |
9657 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
9658 | goto nla_put_failure; | |
2a0e047e | 9659 | |
6abb9cb9 JB |
9660 | if (nl80211_send_wowlan_tcp(msg, |
9661 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e | 9662 | goto nla_put_failure; |
75453ccb LC |
9663 | |
9664 | if (nl80211_send_wowlan_nd( | |
9665 | msg, | |
9666 | rdev->wiphy.wowlan_config->nd_config)) | |
9667 | goto nla_put_failure; | |
2a0e047e | 9668 | |
ff1b6e69 JB |
9669 | nla_nest_end(msg, nl_wowlan); |
9670 | } | |
9671 | ||
9672 | genlmsg_end(msg, hdr); | |
9673 | return genlmsg_reply(msg, info); | |
9674 | ||
9675 | nla_put_failure: | |
9676 | nlmsg_free(msg); | |
9677 | return -ENOBUFS; | |
9678 | } | |
9679 | ||
2a0e047e JB |
9680 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
9681 | struct nlattr *attr, | |
9682 | struct cfg80211_wowlan *trig) | |
9683 | { | |
9684 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
9685 | struct cfg80211_wowlan_tcp *cfg; | |
9686 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
9687 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
9688 | u32 size; | |
9689 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
9690 | int err, port; | |
9691 | ||
964dc9e2 | 9692 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
9693 | return -EINVAL; |
9694 | ||
9695 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
9696 | nla_data(attr), nla_len(attr), | |
9697 | nl80211_wowlan_tcp_policy); | |
9698 | if (err) | |
9699 | return err; | |
9700 | ||
9701 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
9702 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
9703 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
9704 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
9705 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
9706 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
9707 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
9708 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
9709 | return -EINVAL; | |
9710 | ||
9711 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 9712 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
9713 | return -EINVAL; |
9714 | ||
9715 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 9716 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 9717 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
9718 | return -EINVAL; |
9719 | ||
9720 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 9721 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
9722 | return -EINVAL; |
9723 | ||
9724 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
9725 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
9726 | return -EINVAL; | |
9727 | ||
9728 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
9729 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
9730 | ||
9731 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
9732 | tokens_size = tokln - sizeof(*tok); | |
9733 | ||
9734 | if (!tok->len || tokens_size % tok->len) | |
9735 | return -EINVAL; | |
964dc9e2 | 9736 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 9737 | return -EINVAL; |
964dc9e2 | 9738 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 9739 | return -EINVAL; |
964dc9e2 | 9740 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 9741 | return -EINVAL; |
964dc9e2 | 9742 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
9743 | return -EINVAL; |
9744 | if (tok->offset + tok->len > data_size) | |
9745 | return -EINVAL; | |
9746 | } | |
9747 | ||
9748 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
9749 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 9750 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
9751 | return -EINVAL; |
9752 | if (seq->len == 0 || seq->len > 4) | |
9753 | return -EINVAL; | |
9754 | if (seq->len + seq->offset > data_size) | |
9755 | return -EINVAL; | |
9756 | } | |
9757 | ||
9758 | size = sizeof(*cfg); | |
9759 | size += data_size; | |
9760 | size += wake_size + wake_mask_size; | |
9761 | size += tokens_size; | |
9762 | ||
9763 | cfg = kzalloc(size, GFP_KERNEL); | |
9764 | if (!cfg) | |
9765 | return -ENOMEM; | |
67b61f6c JB |
9766 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
9767 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
2a0e047e JB |
9768 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
9769 | ETH_ALEN); | |
9770 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
9771 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
9772 | else | |
9773 | port = 0; | |
9774 | #ifdef CONFIG_INET | |
9775 | /* allocate a socket and port for it and use it */ | |
9776 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
9777 | IPPROTO_TCP, &cfg->sock, 1); | |
9778 | if (err) { | |
9779 | kfree(cfg); | |
9780 | return err; | |
9781 | } | |
9782 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
9783 | sock_release(cfg->sock); | |
9784 | kfree(cfg); | |
9785 | return -EADDRINUSE; | |
9786 | } | |
9787 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
9788 | #else | |
9789 | if (!port) { | |
9790 | kfree(cfg); | |
9791 | return -EINVAL; | |
9792 | } | |
9793 | cfg->src_port = port; | |
9794 | #endif | |
9795 | ||
9796 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
9797 | cfg->payload_len = data_size; | |
9798 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
9799 | memcpy((void *)cfg->payload, | |
9800 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
9801 | data_size); | |
9802 | if (seq) | |
9803 | cfg->payload_seq = *seq; | |
9804 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
9805 | cfg->wake_len = wake_size; | |
9806 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
9807 | memcpy((void *)cfg->wake_data, | |
9808 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
9809 | wake_size); | |
9810 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
9811 | data_size + wake_size; | |
9812 | memcpy((void *)cfg->wake_mask, | |
9813 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
9814 | wake_mask_size); | |
9815 | if (tok) { | |
9816 | cfg->tokens_size = tokens_size; | |
9817 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
9818 | } | |
9819 | ||
9820 | trig->tcp = cfg; | |
9821 | ||
9822 | return 0; | |
9823 | } | |
9824 | ||
8cd4d456 LC |
9825 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
9826 | const struct wiphy_wowlan_support *wowlan, | |
9827 | struct nlattr *attr, | |
9828 | struct cfg80211_wowlan *trig) | |
9829 | { | |
9830 | struct nlattr **tb; | |
9831 | int err; | |
9832 | ||
9833 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); | |
9834 | if (!tb) | |
9835 | return -ENOMEM; | |
9836 | ||
9837 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | |
9838 | err = -EOPNOTSUPP; | |
9839 | goto out; | |
9840 | } | |
9841 | ||
9842 | err = nla_parse(tb, NL80211_ATTR_MAX, | |
9843 | nla_data(attr), nla_len(attr), | |
9844 | nl80211_policy); | |
9845 | if (err) | |
9846 | goto out; | |
9847 | ||
ad2b26ab | 9848 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
8cd4d456 LC |
9849 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
9850 | if (err) | |
9851 | trig->nd_config = NULL; | |
9852 | ||
9853 | out: | |
9854 | kfree(tb); | |
9855 | return err; | |
9856 | } | |
9857 | ||
ff1b6e69 JB |
9858 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
9859 | { | |
9860 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9861 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 9862 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 9863 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 9864 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 9865 | int err, i; |
6abb9cb9 | 9866 | bool prev_enabled = rdev->wiphy.wowlan_config; |
98fc4386 | 9867 | bool regular = false; |
ff1b6e69 | 9868 | |
964dc9e2 | 9869 | if (!wowlan) |
ff1b6e69 JB |
9870 | return -EOPNOTSUPP; |
9871 | ||
ae33bd81 JB |
9872 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
9873 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 9874 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
9875 | goto set_wakeup; |
9876 | } | |
ff1b6e69 JB |
9877 | |
9878 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
9879 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9880 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9881 | nl80211_wowlan_policy); | |
9882 | if (err) | |
9883 | return err; | |
9884 | ||
9885 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
9886 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
9887 | return -EINVAL; | |
9888 | new_triggers.any = true; | |
9889 | } | |
9890 | ||
9891 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
9892 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
9893 | return -EINVAL; | |
9894 | new_triggers.disconnect = true; | |
98fc4386 | 9895 | regular = true; |
ff1b6e69 JB |
9896 | } |
9897 | ||
9898 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
9899 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
9900 | return -EINVAL; | |
9901 | new_triggers.magic_pkt = true; | |
98fc4386 | 9902 | regular = true; |
ff1b6e69 JB |
9903 | } |
9904 | ||
77dbbb13 JB |
9905 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
9906 | return -EINVAL; | |
9907 | ||
9908 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
9909 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
9910 | return -EINVAL; | |
9911 | new_triggers.gtk_rekey_failure = true; | |
98fc4386 | 9912 | regular = true; |
77dbbb13 JB |
9913 | } |
9914 | ||
9915 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
9916 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
9917 | return -EINVAL; | |
9918 | new_triggers.eap_identity_req = true; | |
98fc4386 | 9919 | regular = true; |
77dbbb13 JB |
9920 | } |
9921 | ||
9922 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
9923 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
9924 | return -EINVAL; | |
9925 | new_triggers.four_way_handshake = true; | |
98fc4386 | 9926 | regular = true; |
77dbbb13 JB |
9927 | } |
9928 | ||
9929 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
9930 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
9931 | return -EINVAL; | |
9932 | new_triggers.rfkill_release = true; | |
98fc4386 | 9933 | regular = true; |
77dbbb13 JB |
9934 | } |
9935 | ||
ff1b6e69 JB |
9936 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
9937 | struct nlattr *pat; | |
9938 | int n_patterns = 0; | |
bb92d199 | 9939 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 9940 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 | 9941 | |
98fc4386 JB |
9942 | regular = true; |
9943 | ||
ff1b6e69 JB |
9944 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
9945 | rem) | |
9946 | n_patterns++; | |
9947 | if (n_patterns > wowlan->n_patterns) | |
9948 | return -EINVAL; | |
9949 | ||
9950 | new_triggers.patterns = kcalloc(n_patterns, | |
9951 | sizeof(new_triggers.patterns[0]), | |
9952 | GFP_KERNEL); | |
9953 | if (!new_triggers.patterns) | |
9954 | return -ENOMEM; | |
9955 | ||
9956 | new_triggers.n_patterns = n_patterns; | |
9957 | i = 0; | |
9958 | ||
9959 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9960 | rem) { | |
922bd80f JB |
9961 | u8 *mask_pat; |
9962 | ||
50ac6607 AK |
9963 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9964 | nla_len(pat), NULL); | |
ff1b6e69 | 9965 | err = -EINVAL; |
50ac6607 AK |
9966 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
9967 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 9968 | goto error; |
50ac6607 | 9969 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 9970 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 9971 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
9972 | goto error; |
9973 | if (pat_len > wowlan->pattern_max_len || | |
9974 | pat_len < wowlan->pattern_min_len) | |
9975 | goto error; | |
9976 | ||
50ac6607 | 9977 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
9978 | pkt_offset = 0; |
9979 | else | |
9980 | pkt_offset = nla_get_u32( | |
50ac6607 | 9981 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
9982 | if (pkt_offset > wowlan->max_pkt_offset) |
9983 | goto error; | |
9984 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
9985 | ||
922bd80f JB |
9986 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9987 | if (!mask_pat) { | |
ff1b6e69 JB |
9988 | err = -ENOMEM; |
9989 | goto error; | |
9990 | } | |
922bd80f JB |
9991 | new_triggers.patterns[i].mask = mask_pat; |
9992 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 9993 | mask_len); |
922bd80f JB |
9994 | mask_pat += mask_len; |
9995 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 9996 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 9997 | memcpy(mask_pat, |
50ac6607 | 9998 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
9999 | pat_len); |
10000 | i++; | |
10001 | } | |
10002 | } | |
10003 | ||
2a0e047e | 10004 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
98fc4386 | 10005 | regular = true; |
2a0e047e JB |
10006 | err = nl80211_parse_wowlan_tcp( |
10007 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
10008 | &new_triggers); | |
10009 | if (err) | |
10010 | goto error; | |
10011 | } | |
10012 | ||
8cd4d456 | 10013 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
98fc4386 | 10014 | regular = true; |
8cd4d456 LC |
10015 | err = nl80211_parse_wowlan_nd( |
10016 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | |
10017 | &new_triggers); | |
10018 | if (err) | |
10019 | goto error; | |
10020 | } | |
10021 | ||
98fc4386 JB |
10022 | /* The 'any' trigger means the device continues operating more or less |
10023 | * as in its normal operation mode and wakes up the host on most of the | |
10024 | * normal interrupts (like packet RX, ...) | |
10025 | * It therefore makes little sense to combine with the more constrained | |
10026 | * wakeup trigger modes. | |
10027 | */ | |
10028 | if (new_triggers.any && regular) { | |
10029 | err = -EINVAL; | |
10030 | goto error; | |
10031 | } | |
10032 | ||
ae33bd81 JB |
10033 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
10034 | if (!ntrig) { | |
10035 | err = -ENOMEM; | |
10036 | goto error; | |
ff1b6e69 | 10037 | } |
ae33bd81 | 10038 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 10039 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 10040 | |
ae33bd81 | 10041 | set_wakeup: |
6abb9cb9 JB |
10042 | if (rdev->ops->set_wakeup && |
10043 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
10044 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 10045 | |
ff1b6e69 JB |
10046 | return 0; |
10047 | error: | |
10048 | for (i = 0; i < new_triggers.n_patterns; i++) | |
10049 | kfree(new_triggers.patterns[i].mask); | |
10050 | kfree(new_triggers.patterns); | |
2a0e047e JB |
10051 | if (new_triggers.tcp && new_triggers.tcp->sock) |
10052 | sock_release(new_triggers.tcp->sock); | |
10053 | kfree(new_triggers.tcp); | |
e5dbe070 | 10054 | kfree(new_triggers.nd_config); |
ff1b6e69 JB |
10055 | return err; |
10056 | } | |
dfb89c56 | 10057 | #endif |
ff1b6e69 | 10058 | |
be29b99a AK |
10059 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
10060 | struct cfg80211_registered_device *rdev) | |
10061 | { | |
10062 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
10063 | int i, j, pat_len; | |
10064 | struct cfg80211_coalesce_rules *rule; | |
10065 | ||
10066 | if (!rdev->coalesce->n_rules) | |
10067 | return 0; | |
10068 | ||
10069 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
10070 | if (!nl_rules) | |
10071 | return -ENOBUFS; | |
10072 | ||
10073 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
10074 | nl_rule = nla_nest_start(msg, i + 1); | |
10075 | if (!nl_rule) | |
10076 | return -ENOBUFS; | |
10077 | ||
10078 | rule = &rdev->coalesce->rules[i]; | |
10079 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
10080 | rule->delay)) | |
10081 | return -ENOBUFS; | |
10082 | ||
10083 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
10084 | rule->condition)) | |
10085 | return -ENOBUFS; | |
10086 | ||
10087 | nl_pats = nla_nest_start(msg, | |
10088 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
10089 | if (!nl_pats) | |
10090 | return -ENOBUFS; | |
10091 | ||
10092 | for (j = 0; j < rule->n_patterns; j++) { | |
10093 | nl_pat = nla_nest_start(msg, j + 1); | |
10094 | if (!nl_pat) | |
10095 | return -ENOBUFS; | |
10096 | pat_len = rule->patterns[j].pattern_len; | |
10097 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
10098 | DIV_ROUND_UP(pat_len, 8), | |
10099 | rule->patterns[j].mask) || | |
10100 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
10101 | rule->patterns[j].pattern) || | |
10102 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
10103 | rule->patterns[j].pkt_offset)) | |
10104 | return -ENOBUFS; | |
10105 | nla_nest_end(msg, nl_pat); | |
10106 | } | |
10107 | nla_nest_end(msg, nl_pats); | |
10108 | nla_nest_end(msg, nl_rule); | |
10109 | } | |
10110 | nla_nest_end(msg, nl_rules); | |
10111 | ||
10112 | return 0; | |
10113 | } | |
10114 | ||
10115 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
10116 | { | |
10117 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10118 | struct sk_buff *msg; | |
10119 | void *hdr; | |
10120 | ||
10121 | if (!rdev->wiphy.coalesce) | |
10122 | return -EOPNOTSUPP; | |
10123 | ||
10124 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10125 | if (!msg) | |
10126 | return -ENOMEM; | |
10127 | ||
10128 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
10129 | NL80211_CMD_GET_COALESCE); | |
10130 | if (!hdr) | |
10131 | goto nla_put_failure; | |
10132 | ||
10133 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
10134 | goto nla_put_failure; | |
10135 | ||
10136 | genlmsg_end(msg, hdr); | |
10137 | return genlmsg_reply(msg, info); | |
10138 | ||
10139 | nla_put_failure: | |
10140 | nlmsg_free(msg); | |
10141 | return -ENOBUFS; | |
10142 | } | |
10143 | ||
10144 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
10145 | { | |
10146 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
10147 | int i, j; | |
10148 | struct cfg80211_coalesce_rules *rule; | |
10149 | ||
10150 | if (!coalesce) | |
10151 | return; | |
10152 | ||
10153 | for (i = 0; i < coalesce->n_rules; i++) { | |
10154 | rule = &coalesce->rules[i]; | |
10155 | for (j = 0; j < rule->n_patterns; j++) | |
10156 | kfree(rule->patterns[j].mask); | |
10157 | kfree(rule->patterns); | |
10158 | } | |
10159 | kfree(coalesce->rules); | |
10160 | kfree(coalesce); | |
10161 | rdev->coalesce = NULL; | |
10162 | } | |
10163 | ||
10164 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
10165 | struct nlattr *rule, | |
10166 | struct cfg80211_coalesce_rules *new_rule) | |
10167 | { | |
10168 | int err, i; | |
10169 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
10170 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
10171 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
10172 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
10173 | ||
10174 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
10175 | nla_len(rule), nl80211_coalesce_policy); | |
10176 | if (err) | |
10177 | return err; | |
10178 | ||
10179 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
10180 | new_rule->delay = | |
10181 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
10182 | if (new_rule->delay > coalesce->max_delay) | |
10183 | return -EINVAL; | |
10184 | ||
10185 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
10186 | new_rule->condition = | |
10187 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
10188 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
10189 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
10190 | return -EINVAL; | |
10191 | ||
10192 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
10193 | return -EINVAL; | |
10194 | ||
10195 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
10196 | rem) | |
10197 | n_patterns++; | |
10198 | if (n_patterns > coalesce->n_patterns) | |
10199 | return -EINVAL; | |
10200 | ||
10201 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
10202 | GFP_KERNEL); | |
10203 | if (!new_rule->patterns) | |
10204 | return -ENOMEM; | |
10205 | ||
10206 | new_rule->n_patterns = n_patterns; | |
10207 | i = 0; | |
10208 | ||
10209 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
10210 | rem) { | |
922bd80f JB |
10211 | u8 *mask_pat; |
10212 | ||
be29b99a AK |
10213 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
10214 | nla_len(pat), NULL); | |
10215 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
10216 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
10217 | return -EINVAL; | |
10218 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
10219 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
10220 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
10221 | return -EINVAL; | |
10222 | if (pat_len > coalesce->pattern_max_len || | |
10223 | pat_len < coalesce->pattern_min_len) | |
10224 | return -EINVAL; | |
10225 | ||
10226 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
10227 | pkt_offset = 0; | |
10228 | else | |
10229 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
10230 | if (pkt_offset > coalesce->max_pkt_offset) | |
10231 | return -EINVAL; | |
10232 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
10233 | ||
922bd80f JB |
10234 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
10235 | if (!mask_pat) | |
be29b99a | 10236 | return -ENOMEM; |
922bd80f JB |
10237 | |
10238 | new_rule->patterns[i].mask = mask_pat; | |
10239 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
10240 | mask_len); | |
10241 | ||
10242 | mask_pat += mask_len; | |
10243 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 10244 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
10245 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
10246 | pat_len); | |
be29b99a AK |
10247 | i++; |
10248 | } | |
10249 | ||
10250 | return 0; | |
10251 | } | |
10252 | ||
10253 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
10254 | { | |
10255 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10256 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
10257 | struct cfg80211_coalesce new_coalesce = {}; | |
10258 | struct cfg80211_coalesce *n_coalesce; | |
10259 | int err, rem_rule, n_rules = 0, i, j; | |
10260 | struct nlattr *rule; | |
10261 | struct cfg80211_coalesce_rules *tmp_rule; | |
10262 | ||
10263 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
10264 | return -EOPNOTSUPP; | |
10265 | ||
10266 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
10267 | cfg80211_rdev_free_coalesce(rdev); | |
a1056b1b | 10268 | rdev_set_coalesce(rdev, NULL); |
be29b99a AK |
10269 | return 0; |
10270 | } | |
10271 | ||
10272 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
10273 | rem_rule) | |
10274 | n_rules++; | |
10275 | if (n_rules > coalesce->n_rules) | |
10276 | return -EINVAL; | |
10277 | ||
10278 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
10279 | GFP_KERNEL); | |
10280 | if (!new_coalesce.rules) | |
10281 | return -ENOMEM; | |
10282 | ||
10283 | new_coalesce.n_rules = n_rules; | |
10284 | i = 0; | |
10285 | ||
10286 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
10287 | rem_rule) { | |
10288 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
10289 | &new_coalesce.rules[i]); | |
10290 | if (err) | |
10291 | goto error; | |
10292 | ||
10293 | i++; | |
10294 | } | |
10295 | ||
a1056b1b | 10296 | err = rdev_set_coalesce(rdev, &new_coalesce); |
be29b99a AK |
10297 | if (err) |
10298 | goto error; | |
10299 | ||
10300 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
10301 | if (!n_coalesce) { | |
10302 | err = -ENOMEM; | |
10303 | goto error; | |
10304 | } | |
10305 | cfg80211_rdev_free_coalesce(rdev); | |
10306 | rdev->coalesce = n_coalesce; | |
10307 | ||
10308 | return 0; | |
10309 | error: | |
10310 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
10311 | tmp_rule = &new_coalesce.rules[i]; | |
10312 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
10313 | kfree(tmp_rule->patterns[j].mask); | |
10314 | kfree(tmp_rule->patterns); | |
10315 | } | |
10316 | kfree(new_coalesce.rules); | |
10317 | ||
10318 | return err; | |
10319 | } | |
10320 | ||
e5497d76 JB |
10321 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
10322 | { | |
10323 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10324 | struct net_device *dev = info->user_ptr[1]; | |
10325 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10326 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
10327 | struct cfg80211_gtk_rekey_data rekey_data; | |
10328 | int err; | |
10329 | ||
10330 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
10331 | return -EINVAL; | |
10332 | ||
10333 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
10334 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
10335 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
10336 | nl80211_rekey_policy); | |
10337 | if (err) | |
10338 | return err; | |
10339 | ||
10340 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
10341 | return -ERANGE; | |
10342 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
10343 | return -ERANGE; | |
10344 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
10345 | return -ERANGE; | |
10346 | ||
78f686ca JB |
10347 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
10348 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | |
10349 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | |
e5497d76 JB |
10350 | |
10351 | wdev_lock(wdev); | |
10352 | if (!wdev->current_bss) { | |
10353 | err = -ENOTCONN; | |
10354 | goto out; | |
10355 | } | |
10356 | ||
10357 | if (!rdev->ops->set_rekey_data) { | |
10358 | err = -EOPNOTSUPP; | |
10359 | goto out; | |
10360 | } | |
10361 | ||
e35e4d28 | 10362 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
10363 | out: |
10364 | wdev_unlock(wdev); | |
10365 | return err; | |
10366 | } | |
10367 | ||
28946da7 JB |
10368 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
10369 | struct genl_info *info) | |
10370 | { | |
10371 | struct net_device *dev = info->user_ptr[1]; | |
10372 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10373 | ||
10374 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
10375 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
10376 | return -EINVAL; | |
10377 | ||
15e47304 | 10378 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
10379 | return -EBUSY; |
10380 | ||
15e47304 | 10381 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
10382 | return 0; |
10383 | } | |
10384 | ||
7f6cf311 JB |
10385 | static int nl80211_probe_client(struct sk_buff *skb, |
10386 | struct genl_info *info) | |
10387 | { | |
10388 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10389 | struct net_device *dev = info->user_ptr[1]; | |
10390 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10391 | struct sk_buff *msg; | |
10392 | void *hdr; | |
10393 | const u8 *addr; | |
10394 | u64 cookie; | |
10395 | int err; | |
10396 | ||
10397 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
10398 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
10399 | return -EOPNOTSUPP; | |
10400 | ||
10401 | if (!info->attrs[NL80211_ATTR_MAC]) | |
10402 | return -EINVAL; | |
10403 | ||
10404 | if (!rdev->ops->probe_client) | |
10405 | return -EOPNOTSUPP; | |
10406 | ||
10407 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10408 | if (!msg) | |
10409 | return -ENOMEM; | |
10410 | ||
15e47304 | 10411 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 10412 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
10413 | if (!hdr) { |
10414 | err = -ENOBUFS; | |
7f6cf311 JB |
10415 | goto free_msg; |
10416 | } | |
10417 | ||
10418 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10419 | ||
e35e4d28 | 10420 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
10421 | if (err) |
10422 | goto free_msg; | |
10423 | ||
2dad624e ND |
10424 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
10425 | NL80211_ATTR_PAD)) | |
9360ffd1 | 10426 | goto nla_put_failure; |
7f6cf311 JB |
10427 | |
10428 | genlmsg_end(msg, hdr); | |
10429 | ||
10430 | return genlmsg_reply(msg, info); | |
10431 | ||
10432 | nla_put_failure: | |
10433 | err = -ENOBUFS; | |
10434 | free_msg: | |
10435 | nlmsg_free(msg); | |
10436 | return err; | |
10437 | } | |
10438 | ||
5e760230 JB |
10439 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
10440 | { | |
10441 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
10442 | struct cfg80211_beacon_registration *reg, *nreg; |
10443 | int rv; | |
5e760230 JB |
10444 | |
10445 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
10446 | return -EOPNOTSUPP; | |
10447 | ||
37c73b5f BG |
10448 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
10449 | if (!nreg) | |
10450 | return -ENOMEM; | |
10451 | ||
10452 | /* First, check if already registered. */ | |
10453 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
10454 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
10455 | if (reg->nlportid == info->snd_portid) { | |
10456 | rv = -EALREADY; | |
10457 | goto out_err; | |
10458 | } | |
10459 | } | |
10460 | /* Add it to the list */ | |
10461 | nreg->nlportid = info->snd_portid; | |
10462 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 10463 | |
37c73b5f | 10464 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
10465 | |
10466 | return 0; | |
37c73b5f BG |
10467 | out_err: |
10468 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
10469 | kfree(nreg); | |
10470 | return rv; | |
5e760230 JB |
10471 | } |
10472 | ||
98104fde JB |
10473 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
10474 | { | |
10475 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10476 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10477 | int err; | |
10478 | ||
10479 | if (!rdev->ops->start_p2p_device) | |
10480 | return -EOPNOTSUPP; | |
10481 | ||
10482 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
10483 | return -EOPNOTSUPP; | |
10484 | ||
10485 | if (wdev->p2p_started) | |
10486 | return 0; | |
10487 | ||
b6a55015 LC |
10488 | if (rfkill_blocked(rdev->rfkill)) |
10489 | return -ERFKILL; | |
98104fde | 10490 | |
eeb126e9 | 10491 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
10492 | if (err) |
10493 | return err; | |
10494 | ||
10495 | wdev->p2p_started = true; | |
98104fde | 10496 | rdev->opencount++; |
98104fde JB |
10497 | |
10498 | return 0; | |
10499 | } | |
10500 | ||
10501 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
10502 | { | |
10503 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10504 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10505 | ||
10506 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
10507 | return -EOPNOTSUPP; | |
10508 | ||
10509 | if (!rdev->ops->stop_p2p_device) | |
10510 | return -EOPNOTSUPP; | |
10511 | ||
f9f47529 | 10512 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
10513 | |
10514 | return 0; | |
10515 | } | |
10516 | ||
cb3b7d87 AB |
10517 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
10518 | { | |
10519 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10520 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10521 | struct cfg80211_nan_conf conf = {}; | |
10522 | int err; | |
10523 | ||
10524 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
10525 | return -EOPNOTSUPP; | |
10526 | ||
10527 | if (wdev->nan_started) | |
10528 | return -EEXIST; | |
10529 | ||
10530 | if (rfkill_blocked(rdev->rfkill)) | |
10531 | return -ERFKILL; | |
10532 | ||
10533 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) | |
10534 | return -EINVAL; | |
10535 | ||
10536 | if (!info->attrs[NL80211_ATTR_NAN_DUAL]) | |
10537 | return -EINVAL; | |
10538 | ||
10539 | conf.master_pref = | |
10540 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); | |
10541 | if (!conf.master_pref) | |
10542 | return -EINVAL; | |
10543 | ||
10544 | conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]); | |
10545 | ||
10546 | err = rdev_start_nan(rdev, wdev, &conf); | |
10547 | if (err) | |
10548 | return err; | |
10549 | ||
10550 | wdev->nan_started = true; | |
10551 | rdev->opencount++; | |
10552 | ||
10553 | return 0; | |
10554 | } | |
10555 | ||
10556 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) | |
10557 | { | |
10558 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10559 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10560 | ||
10561 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
10562 | return -EOPNOTSUPP; | |
10563 | ||
10564 | cfg80211_stop_nan(rdev, wdev); | |
10565 | ||
10566 | return 0; | |
10567 | } | |
10568 | ||
3713b4e3 JB |
10569 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
10570 | struct genl_info *info) | |
10571 | { | |
10572 | void *hdr; | |
10573 | struct sk_buff *msg; | |
10574 | ||
10575 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10576 | if (!msg) | |
10577 | return -ENOMEM; | |
10578 | ||
10579 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
10580 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
10581 | if (!hdr) | |
10582 | goto nla_put_failure; | |
10583 | ||
10584 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
10585 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
10586 | goto nla_put_failure; | |
10587 | ||
10588 | genlmsg_end(msg, hdr); | |
10589 | return genlmsg_reply(msg, info); | |
10590 | ||
10591 | nla_put_failure: | |
10592 | kfree_skb(msg); | |
10593 | return -ENOBUFS; | |
10594 | } | |
10595 | ||
355199e0 JM |
10596 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
10597 | { | |
10598 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10599 | struct cfg80211_update_ft_ies_params ft_params; | |
10600 | struct net_device *dev = info->user_ptr[1]; | |
10601 | ||
10602 | if (!rdev->ops->update_ft_ies) | |
10603 | return -EOPNOTSUPP; | |
10604 | ||
10605 | if (!info->attrs[NL80211_ATTR_MDID] || | |
10606 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
10607 | return -EINVAL; | |
10608 | ||
10609 | memset(&ft_params, 0, sizeof(ft_params)); | |
10610 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
10611 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
10612 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
10613 | ||
10614 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
10615 | } | |
10616 | ||
5de17984 AS |
10617 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
10618 | struct genl_info *info) | |
10619 | { | |
10620 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10621 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10622 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
10623 | u16 duration; | |
10624 | int ret; | |
10625 | ||
10626 | if (!rdev->ops->crit_proto_start) | |
10627 | return -EOPNOTSUPP; | |
10628 | ||
10629 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
10630 | return -EINVAL; | |
10631 | ||
10632 | if (rdev->crit_proto_nlportid) | |
10633 | return -EBUSY; | |
10634 | ||
10635 | /* determine protocol if provided */ | |
10636 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
10637 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
10638 | ||
10639 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
10640 | return -EINVAL; | |
10641 | ||
10642 | /* timeout must be provided */ | |
10643 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
10644 | return -EINVAL; | |
10645 | ||
10646 | duration = | |
10647 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
10648 | ||
10649 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
10650 | return -ERANGE; | |
10651 | ||
10652 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
10653 | if (!ret) | |
10654 | rdev->crit_proto_nlportid = info->snd_portid; | |
10655 | ||
10656 | return ret; | |
10657 | } | |
10658 | ||
10659 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
10660 | struct genl_info *info) | |
10661 | { | |
10662 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10663 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10664 | ||
10665 | if (!rdev->ops->crit_proto_stop) | |
10666 | return -EOPNOTSUPP; | |
10667 | ||
10668 | if (rdev->crit_proto_nlportid) { | |
10669 | rdev->crit_proto_nlportid = 0; | |
10670 | rdev_crit_proto_stop(rdev, wdev); | |
10671 | } | |
10672 | return 0; | |
10673 | } | |
10674 | ||
ad7e718c JB |
10675 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
10676 | { | |
10677 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10678 | struct wireless_dev *wdev = | |
10679 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
10680 | int i, err; | |
10681 | u32 vid, subcmd; | |
10682 | ||
10683 | if (!rdev->wiphy.vendor_commands) | |
10684 | return -EOPNOTSUPP; | |
10685 | ||
10686 | if (IS_ERR(wdev)) { | |
10687 | err = PTR_ERR(wdev); | |
10688 | if (err != -EINVAL) | |
10689 | return err; | |
10690 | wdev = NULL; | |
10691 | } else if (wdev->wiphy != &rdev->wiphy) { | |
10692 | return -EINVAL; | |
10693 | } | |
10694 | ||
10695 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
10696 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
10697 | return -EINVAL; | |
10698 | ||
10699 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
10700 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
10701 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
10702 | const struct wiphy_vendor_command *vcmd; | |
10703 | void *data = NULL; | |
10704 | int len = 0; | |
10705 | ||
10706 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
10707 | ||
10708 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
10709 | continue; | |
10710 | ||
10711 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
10712 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
10713 | if (!wdev) | |
10714 | return -EINVAL; | |
10715 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
10716 | !wdev->netdev) | |
10717 | return -EINVAL; | |
10718 | ||
10719 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
10720 | if (wdev->netdev && | |
10721 | !netif_running(wdev->netdev)) | |
10722 | return -ENETDOWN; | |
10723 | if (!wdev->netdev && !wdev->p2p_started) | |
10724 | return -ENETDOWN; | |
10725 | } | |
7bdbe400 JB |
10726 | |
10727 | if (!vcmd->doit) | |
10728 | return -EOPNOTSUPP; | |
ad7e718c JB |
10729 | } else { |
10730 | wdev = NULL; | |
10731 | } | |
10732 | ||
10733 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
10734 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
10735 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
10736 | } | |
10737 | ||
10738 | rdev->cur_cmd_info = info; | |
10739 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
10740 | data, len); | |
10741 | rdev->cur_cmd_info = NULL; | |
10742 | return err; | |
10743 | } | |
10744 | ||
10745 | return -EOPNOTSUPP; | |
10746 | } | |
10747 | ||
7bdbe400 JB |
10748 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
10749 | struct netlink_callback *cb, | |
10750 | struct cfg80211_registered_device **rdev, | |
10751 | struct wireless_dev **wdev) | |
10752 | { | |
10753 | u32 vid, subcmd; | |
10754 | unsigned int i; | |
10755 | int vcmd_idx = -1; | |
10756 | int err; | |
10757 | void *data = NULL; | |
10758 | unsigned int data_len = 0; | |
10759 | ||
10760 | rtnl_lock(); | |
10761 | ||
10762 | if (cb->args[0]) { | |
10763 | /* subtract the 1 again here */ | |
10764 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
10765 | struct wireless_dev *tmp; | |
10766 | ||
10767 | if (!wiphy) { | |
10768 | err = -ENODEV; | |
10769 | goto out_unlock; | |
10770 | } | |
10771 | *rdev = wiphy_to_rdev(wiphy); | |
10772 | *wdev = NULL; | |
10773 | ||
10774 | if (cb->args[1]) { | |
53873f13 | 10775 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
7bdbe400 JB |
10776 | if (tmp->identifier == cb->args[1] - 1) { |
10777 | *wdev = tmp; | |
10778 | break; | |
10779 | } | |
10780 | } | |
10781 | } | |
10782 | ||
10783 | /* keep rtnl locked in successful case */ | |
10784 | return 0; | |
10785 | } | |
10786 | ||
10787 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
10788 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
10789 | nl80211_policy); | |
10790 | if (err) | |
10791 | goto out_unlock; | |
10792 | ||
10793 | if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] || | |
10794 | !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { | |
10795 | err = -EINVAL; | |
10796 | goto out_unlock; | |
10797 | } | |
10798 | ||
10799 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), | |
10800 | nl80211_fam.attrbuf); | |
10801 | if (IS_ERR(*wdev)) | |
10802 | *wdev = NULL; | |
10803 | ||
10804 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), | |
10805 | nl80211_fam.attrbuf); | |
10806 | if (IS_ERR(*rdev)) { | |
10807 | err = PTR_ERR(*rdev); | |
10808 | goto out_unlock; | |
10809 | } | |
10810 | ||
10811 | vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]); | |
10812 | subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); | |
10813 | ||
10814 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { | |
10815 | const struct wiphy_vendor_command *vcmd; | |
10816 | ||
10817 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; | |
10818 | ||
10819 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
10820 | continue; | |
10821 | ||
10822 | if (!vcmd->dumpit) { | |
10823 | err = -EOPNOTSUPP; | |
10824 | goto out_unlock; | |
10825 | } | |
10826 | ||
10827 | vcmd_idx = i; | |
10828 | break; | |
10829 | } | |
10830 | ||
10831 | if (vcmd_idx < 0) { | |
10832 | err = -EOPNOTSUPP; | |
10833 | goto out_unlock; | |
10834 | } | |
10835 | ||
10836 | if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) { | |
10837 | data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); | |
10838 | data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); | |
10839 | } | |
10840 | ||
10841 | /* 0 is the first index - add 1 to parse only once */ | |
10842 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
10843 | /* add 1 to know if it was NULL */ | |
10844 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; | |
10845 | cb->args[2] = vcmd_idx; | |
10846 | cb->args[3] = (unsigned long)data; | |
10847 | cb->args[4] = data_len; | |
10848 | ||
10849 | /* keep rtnl locked in successful case */ | |
10850 | return 0; | |
10851 | out_unlock: | |
10852 | rtnl_unlock(); | |
10853 | return err; | |
10854 | } | |
10855 | ||
10856 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, | |
10857 | struct netlink_callback *cb) | |
10858 | { | |
10859 | struct cfg80211_registered_device *rdev; | |
10860 | struct wireless_dev *wdev; | |
10861 | unsigned int vcmd_idx; | |
10862 | const struct wiphy_vendor_command *vcmd; | |
10863 | void *data; | |
10864 | int data_len; | |
10865 | int err; | |
10866 | struct nlattr *vendor_data; | |
10867 | ||
10868 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); | |
10869 | if (err) | |
10870 | return err; | |
10871 | ||
10872 | vcmd_idx = cb->args[2]; | |
10873 | data = (void *)cb->args[3]; | |
10874 | data_len = cb->args[4]; | |
10875 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; | |
10876 | ||
10877 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
10878 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
10879 | if (!wdev) | |
10880 | return -EINVAL; | |
10881 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
10882 | !wdev->netdev) | |
10883 | return -EINVAL; | |
10884 | ||
10885 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
10886 | if (wdev->netdev && | |
10887 | !netif_running(wdev->netdev)) | |
10888 | return -ENETDOWN; | |
10889 | if (!wdev->netdev && !wdev->p2p_started) | |
10890 | return -ENETDOWN; | |
10891 | } | |
10892 | } | |
10893 | ||
10894 | while (1) { | |
10895 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, | |
10896 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
10897 | NL80211_CMD_VENDOR); | |
10898 | if (!hdr) | |
10899 | break; | |
10900 | ||
10901 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
10902 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
10903 | wdev_id(wdev), | |
10904 | NL80211_ATTR_PAD))) { | |
7bdbe400 JB |
10905 | genlmsg_cancel(skb, hdr); |
10906 | break; | |
10907 | } | |
10908 | ||
10909 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); | |
10910 | if (!vendor_data) { | |
10911 | genlmsg_cancel(skb, hdr); | |
10912 | break; | |
10913 | } | |
10914 | ||
10915 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, | |
10916 | (unsigned long *)&cb->args[5]); | |
10917 | nla_nest_end(skb, vendor_data); | |
10918 | ||
10919 | if (err == -ENOBUFS || err == -ENOENT) { | |
10920 | genlmsg_cancel(skb, hdr); | |
10921 | break; | |
10922 | } else if (err) { | |
10923 | genlmsg_cancel(skb, hdr); | |
10924 | goto out; | |
10925 | } | |
10926 | ||
10927 | genlmsg_end(skb, hdr); | |
10928 | } | |
10929 | ||
10930 | err = skb->len; | |
10931 | out: | |
10932 | rtnl_unlock(); | |
10933 | return err; | |
10934 | } | |
10935 | ||
ad7e718c JB |
10936 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
10937 | enum nl80211_commands cmd, | |
10938 | enum nl80211_attrs attr, | |
10939 | int approxlen) | |
10940 | { | |
f26cbf40 | 10941 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
10942 | |
10943 | if (WARN_ON(!rdev->cur_cmd_info)) | |
10944 | return NULL; | |
10945 | ||
6c09e791 | 10946 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
ad7e718c JB |
10947 | rdev->cur_cmd_info->snd_portid, |
10948 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 10949 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
10950 | } |
10951 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
10952 | ||
10953 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
10954 | { | |
10955 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
10956 | void *hdr = ((void **)skb->cb)[1]; | |
10957 | struct nlattr *data = ((void **)skb->cb)[2]; | |
10958 | ||
bd8c78e7 JB |
10959 | /* clear CB data for netlink core to own from now on */ |
10960 | memset(skb->cb, 0, sizeof(skb->cb)); | |
10961 | ||
ad7e718c JB |
10962 | if (WARN_ON(!rdev->cur_cmd_info)) { |
10963 | kfree_skb(skb); | |
10964 | return -EINVAL; | |
10965 | } | |
10966 | ||
10967 | nla_nest_end(skb, data); | |
10968 | genlmsg_end(skb, hdr); | |
10969 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
10970 | } | |
10971 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
10972 | ||
fa9ffc74 KP |
10973 | static int nl80211_set_qos_map(struct sk_buff *skb, |
10974 | struct genl_info *info) | |
10975 | { | |
10976 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10977 | struct cfg80211_qos_map *qos_map = NULL; | |
10978 | struct net_device *dev = info->user_ptr[1]; | |
10979 | u8 *pos, len, num_des, des_len, des; | |
10980 | int ret; | |
10981 | ||
10982 | if (!rdev->ops->set_qos_map) | |
10983 | return -EOPNOTSUPP; | |
10984 | ||
10985 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
10986 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
10987 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
10988 | ||
10989 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
10990 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
10991 | return -EINVAL; | |
10992 | ||
10993 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
10994 | if (!qos_map) | |
10995 | return -ENOMEM; | |
10996 | ||
10997 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
10998 | if (num_des) { | |
10999 | des_len = num_des * | |
11000 | sizeof(struct cfg80211_dscp_exception); | |
11001 | memcpy(qos_map->dscp_exception, pos, des_len); | |
11002 | qos_map->num_des = num_des; | |
11003 | for (des = 0; des < num_des; des++) { | |
11004 | if (qos_map->dscp_exception[des].up > 7) { | |
11005 | kfree(qos_map); | |
11006 | return -EINVAL; | |
11007 | } | |
11008 | } | |
11009 | pos += des_len; | |
11010 | } | |
11011 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
11012 | } | |
11013 | ||
11014 | wdev_lock(dev->ieee80211_ptr); | |
11015 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
11016 | if (!ret) | |
11017 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
11018 | wdev_unlock(dev->ieee80211_ptr); | |
11019 | ||
11020 | kfree(qos_map); | |
11021 | return ret; | |
11022 | } | |
11023 | ||
960d01ac JB |
11024 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
11025 | { | |
11026 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11027 | struct net_device *dev = info->user_ptr[1]; | |
11028 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11029 | const u8 *peer; | |
11030 | u8 tsid, up; | |
11031 | u16 admitted_time = 0; | |
11032 | int err; | |
11033 | ||
723e73ac | 11034 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
960d01ac JB |
11035 | return -EOPNOTSUPP; |
11036 | ||
11037 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | |
11038 | !info->attrs[NL80211_ATTR_USER_PRIO]) | |
11039 | return -EINVAL; | |
11040 | ||
11041 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
11042 | if (tsid >= IEEE80211_NUM_TIDS) | |
11043 | return -EINVAL; | |
11044 | ||
11045 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); | |
11046 | if (up >= IEEE80211_NUM_UPS) | |
11047 | return -EINVAL; | |
11048 | ||
11049 | /* WMM uses TIDs 0-7 even for TSPEC */ | |
723e73ac | 11050 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
960d01ac | 11051 | /* TODO: handle 802.11 TSPEC/admission control |
723e73ac JB |
11052 | * need more attributes for that (e.g. BA session requirement); |
11053 | * change the WMM adminssion test above to allow both then | |
960d01ac JB |
11054 | */ |
11055 | return -EINVAL; | |
11056 | } | |
11057 | ||
11058 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
11059 | ||
11060 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | |
11061 | admitted_time = | |
11062 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | |
11063 | if (!admitted_time) | |
11064 | return -EINVAL; | |
11065 | } | |
11066 | ||
11067 | wdev_lock(wdev); | |
11068 | switch (wdev->iftype) { | |
11069 | case NL80211_IFTYPE_STATION: | |
11070 | case NL80211_IFTYPE_P2P_CLIENT: | |
11071 | if (wdev->current_bss) | |
11072 | break; | |
11073 | err = -ENOTCONN; | |
11074 | goto out; | |
11075 | default: | |
11076 | err = -EOPNOTSUPP; | |
11077 | goto out; | |
11078 | } | |
11079 | ||
11080 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | |
11081 | ||
11082 | out: | |
11083 | wdev_unlock(wdev); | |
11084 | return err; | |
11085 | } | |
11086 | ||
11087 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | |
11088 | { | |
11089 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11090 | struct net_device *dev = info->user_ptr[1]; | |
11091 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11092 | const u8 *peer; | |
11093 | u8 tsid; | |
11094 | int err; | |
11095 | ||
11096 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | |
11097 | return -EINVAL; | |
11098 | ||
11099 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
11100 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
11101 | ||
11102 | wdev_lock(wdev); | |
11103 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | |
11104 | wdev_unlock(wdev); | |
11105 | ||
11106 | return err; | |
11107 | } | |
11108 | ||
1057d35e AN |
11109 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
11110 | struct genl_info *info) | |
11111 | { | |
11112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11113 | struct net_device *dev = info->user_ptr[1]; | |
11114 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11115 | struct cfg80211_chan_def chandef = {}; | |
11116 | const u8 *addr; | |
11117 | u8 oper_class; | |
11118 | int err; | |
11119 | ||
11120 | if (!rdev->ops->tdls_channel_switch || | |
11121 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
11122 | return -EOPNOTSUPP; | |
11123 | ||
11124 | switch (dev->ieee80211_ptr->iftype) { | |
11125 | case NL80211_IFTYPE_STATION: | |
11126 | case NL80211_IFTYPE_P2P_CLIENT: | |
11127 | break; | |
11128 | default: | |
11129 | return -EOPNOTSUPP; | |
11130 | } | |
11131 | ||
11132 | if (!info->attrs[NL80211_ATTR_MAC] || | |
11133 | !info->attrs[NL80211_ATTR_OPER_CLASS]) | |
11134 | return -EINVAL; | |
11135 | ||
11136 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
11137 | if (err) | |
11138 | return err; | |
11139 | ||
11140 | /* | |
11141 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | |
11142 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | |
11143 | * specification is not defined for them. | |
11144 | */ | |
57fbcce3 | 11145 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
1057d35e AN |
11146 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
11147 | chandef.width != NL80211_CHAN_WIDTH_20) | |
11148 | return -EINVAL; | |
11149 | ||
11150 | /* we will be active on the TDLS link */ | |
923b352f AN |
11151 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
11152 | wdev->iftype)) | |
1057d35e AN |
11153 | return -EINVAL; |
11154 | ||
11155 | /* don't allow switching to DFS channels */ | |
11156 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | |
11157 | return -EINVAL; | |
11158 | ||
11159 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
11160 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | |
11161 | ||
11162 | wdev_lock(wdev); | |
11163 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | |
11164 | wdev_unlock(wdev); | |
11165 | ||
11166 | return err; | |
11167 | } | |
11168 | ||
11169 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | |
11170 | struct genl_info *info) | |
11171 | { | |
11172 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11173 | struct net_device *dev = info->user_ptr[1]; | |
11174 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11175 | const u8 *addr; | |
11176 | ||
11177 | if (!rdev->ops->tdls_channel_switch || | |
11178 | !rdev->ops->tdls_cancel_channel_switch || | |
11179 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
11180 | return -EOPNOTSUPP; | |
11181 | ||
11182 | switch (dev->ieee80211_ptr->iftype) { | |
11183 | case NL80211_IFTYPE_STATION: | |
11184 | case NL80211_IFTYPE_P2P_CLIENT: | |
11185 | break; | |
11186 | default: | |
11187 | return -EOPNOTSUPP; | |
11188 | } | |
11189 | ||
11190 | if (!info->attrs[NL80211_ATTR_MAC]) | |
11191 | return -EINVAL; | |
11192 | ||
11193 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
11194 | ||
11195 | wdev_lock(wdev); | |
11196 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); | |
11197 | wdev_unlock(wdev); | |
11198 | ||
11199 | return 0; | |
11200 | } | |
11201 | ||
4c476991 JB |
11202 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
11203 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
11204 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
11205 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
11206 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
11207 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 11208 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 11209 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
11210 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
11211 | NL80211_FLAG_CHECK_NETDEV_UP) | |
5393b917 | 11212 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
4c476991 | 11213 | |
f84f771d | 11214 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
11215 | struct genl_info *info) |
11216 | { | |
11217 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 11218 | struct wireless_dev *wdev; |
4c476991 | 11219 | struct net_device *dev; |
4c476991 JB |
11220 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
11221 | ||
11222 | if (rtnl) | |
11223 | rtnl_lock(); | |
11224 | ||
11225 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 11226 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
11227 | if (IS_ERR(rdev)) { |
11228 | if (rtnl) | |
11229 | rtnl_unlock(); | |
11230 | return PTR_ERR(rdev); | |
11231 | } | |
11232 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
11233 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
11234 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
11235 | ASSERT_RTNL(); |
11236 | ||
89a54e48 JB |
11237 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
11238 | info->attrs); | |
11239 | if (IS_ERR(wdev)) { | |
4c476991 JB |
11240 | if (rtnl) |
11241 | rtnl_unlock(); | |
89a54e48 | 11242 | return PTR_ERR(wdev); |
4c476991 | 11243 | } |
89a54e48 | 11244 | |
89a54e48 | 11245 | dev = wdev->netdev; |
f26cbf40 | 11246 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 11247 | |
1bf614ef JB |
11248 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
11249 | if (!dev) { | |
1bf614ef JB |
11250 | if (rtnl) |
11251 | rtnl_unlock(); | |
11252 | return -EINVAL; | |
11253 | } | |
11254 | ||
11255 | info->user_ptr[1] = dev; | |
11256 | } else { | |
11257 | info->user_ptr[1] = wdev; | |
41265714 | 11258 | } |
1bf614ef JB |
11259 | |
11260 | if (dev) { | |
11261 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
11262 | !netif_running(dev)) { | |
1bf614ef JB |
11263 | if (rtnl) |
11264 | rtnl_unlock(); | |
11265 | return -ENETDOWN; | |
11266 | } | |
11267 | ||
11268 | dev_hold(dev); | |
98104fde | 11269 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
cb3b7d87 AB |
11270 | if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE && |
11271 | !wdev->p2p_started) { | |
11272 | if (rtnl) | |
11273 | rtnl_unlock(); | |
11274 | return -ENETDOWN; | |
11275 | } | |
11276 | if (wdev->iftype == NL80211_IFTYPE_NAN && | |
11277 | !wdev->nan_started) { | |
98104fde JB |
11278 | if (rtnl) |
11279 | rtnl_unlock(); | |
11280 | return -ENETDOWN; | |
11281 | } | |
41265714 | 11282 | } |
89a54e48 | 11283 | |
4c476991 | 11284 | info->user_ptr[0] = rdev; |
4c476991 JB |
11285 | } |
11286 | ||
11287 | return 0; | |
11288 | } | |
11289 | ||
f84f771d | 11290 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
11291 | struct genl_info *info) |
11292 | { | |
1bf614ef JB |
11293 | if (info->user_ptr[1]) { |
11294 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
11295 | struct wireless_dev *wdev = info->user_ptr[1]; | |
11296 | ||
11297 | if (wdev->netdev) | |
11298 | dev_put(wdev->netdev); | |
11299 | } else { | |
11300 | dev_put(info->user_ptr[1]); | |
11301 | } | |
11302 | } | |
5393b917 | 11303 | |
4c476991 JB |
11304 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
11305 | rtnl_unlock(); | |
5393b917 JB |
11306 | |
11307 | /* If needed, clear the netlink message payload from the SKB | |
11308 | * as it might contain key data that shouldn't stick around on | |
11309 | * the heap after the SKB is freed. The netlink message header | |
11310 | * is still needed for further processing, so leave it intact. | |
11311 | */ | |
11312 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | |
11313 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | |
11314 | ||
11315 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | |
11316 | } | |
4c476991 JB |
11317 | } |
11318 | ||
4534de83 | 11319 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
11320 | { |
11321 | .cmd = NL80211_CMD_GET_WIPHY, | |
11322 | .doit = nl80211_get_wiphy, | |
11323 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 11324 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
11325 | .policy = nl80211_policy, |
11326 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
11327 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11328 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
11329 | }, |
11330 | { | |
11331 | .cmd = NL80211_CMD_SET_WIPHY, | |
11332 | .doit = nl80211_set_wiphy, | |
11333 | .policy = nl80211_policy, | |
5617c6cd | 11334 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 | 11335 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
11336 | }, |
11337 | { | |
11338 | .cmd = NL80211_CMD_GET_INTERFACE, | |
11339 | .doit = nl80211_get_interface, | |
11340 | .dumpit = nl80211_dump_interface, | |
11341 | .policy = nl80211_policy, | |
11342 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
11343 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
11344 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
11345 | }, |
11346 | { | |
11347 | .cmd = NL80211_CMD_SET_INTERFACE, | |
11348 | .doit = nl80211_set_interface, | |
11349 | .policy = nl80211_policy, | |
5617c6cd | 11350 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11351 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11352 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
11353 | }, |
11354 | { | |
11355 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
11356 | .doit = nl80211_new_interface, | |
11357 | .policy = nl80211_policy, | |
5617c6cd | 11358 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11359 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11360 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
11361 | }, |
11362 | { | |
11363 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
11364 | .doit = nl80211_del_interface, | |
11365 | .policy = nl80211_policy, | |
5617c6cd | 11366 | .flags = GENL_UNS_ADMIN_PERM, |
84efbb84 | 11367 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 11368 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
11369 | }, |
11370 | { | |
11371 | .cmd = NL80211_CMD_GET_KEY, | |
11372 | .doit = nl80211_get_key, | |
11373 | .policy = nl80211_policy, | |
5617c6cd | 11374 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11375 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11376 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
11377 | }, |
11378 | { | |
11379 | .cmd = NL80211_CMD_SET_KEY, | |
11380 | .doit = nl80211_set_key, | |
11381 | .policy = nl80211_policy, | |
5617c6cd | 11382 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11383 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
11384 | NL80211_FLAG_NEED_RTNL | |
11385 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
11386 | }, |
11387 | { | |
11388 | .cmd = NL80211_CMD_NEW_KEY, | |
11389 | .doit = nl80211_new_key, | |
11390 | .policy = nl80211_policy, | |
5617c6cd | 11391 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11392 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
11393 | NL80211_FLAG_NEED_RTNL | |
11394 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
11395 | }, |
11396 | { | |
11397 | .cmd = NL80211_CMD_DEL_KEY, | |
11398 | .doit = nl80211_del_key, | |
11399 | .policy = nl80211_policy, | |
5617c6cd | 11400 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11401 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11402 | NL80211_FLAG_NEED_RTNL, |
55682965 | 11403 | }, |
ed1b6cc7 JB |
11404 | { |
11405 | .cmd = NL80211_CMD_SET_BEACON, | |
11406 | .policy = nl80211_policy, | |
5617c6cd | 11407 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 11408 | .doit = nl80211_set_beacon, |
2b5f8b0b | 11409 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11410 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
11411 | }, |
11412 | { | |
8860020e | 11413 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 | 11414 | .policy = nl80211_policy, |
5617c6cd | 11415 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 11416 | .doit = nl80211_start_ap, |
2b5f8b0b | 11417 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11418 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
11419 | }, |
11420 | { | |
8860020e | 11421 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 | 11422 | .policy = nl80211_policy, |
5617c6cd | 11423 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 11424 | .doit = nl80211_stop_ap, |
2b5f8b0b | 11425 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11426 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 11427 | }, |
5727ef1b JB |
11428 | { |
11429 | .cmd = NL80211_CMD_GET_STATION, | |
11430 | .doit = nl80211_get_station, | |
2ec600d6 | 11431 | .dumpit = nl80211_dump_station, |
5727ef1b | 11432 | .policy = nl80211_policy, |
4c476991 JB |
11433 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11434 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
11435 | }, |
11436 | { | |
11437 | .cmd = NL80211_CMD_SET_STATION, | |
11438 | .doit = nl80211_set_station, | |
11439 | .policy = nl80211_policy, | |
5617c6cd | 11440 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11441 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11442 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
11443 | }, |
11444 | { | |
11445 | .cmd = NL80211_CMD_NEW_STATION, | |
11446 | .doit = nl80211_new_station, | |
11447 | .policy = nl80211_policy, | |
5617c6cd | 11448 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11449 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11450 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
11451 | }, |
11452 | { | |
11453 | .cmd = NL80211_CMD_DEL_STATION, | |
11454 | .doit = nl80211_del_station, | |
11455 | .policy = nl80211_policy, | |
5617c6cd | 11456 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11457 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11458 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
11459 | }, |
11460 | { | |
11461 | .cmd = NL80211_CMD_GET_MPATH, | |
11462 | .doit = nl80211_get_mpath, | |
11463 | .dumpit = nl80211_dump_mpath, | |
11464 | .policy = nl80211_policy, | |
5617c6cd | 11465 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11466 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11467 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 | 11468 | }, |
66be7d2b HR |
11469 | { |
11470 | .cmd = NL80211_CMD_GET_MPP, | |
11471 | .doit = nl80211_get_mpp, | |
11472 | .dumpit = nl80211_dump_mpp, | |
11473 | .policy = nl80211_policy, | |
5617c6cd | 11474 | .flags = GENL_UNS_ADMIN_PERM, |
66be7d2b HR |
11475 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11476 | NL80211_FLAG_NEED_RTNL, | |
11477 | }, | |
2ec600d6 LCC |
11478 | { |
11479 | .cmd = NL80211_CMD_SET_MPATH, | |
11480 | .doit = nl80211_set_mpath, | |
11481 | .policy = nl80211_policy, | |
5617c6cd | 11482 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11483 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11484 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
11485 | }, |
11486 | { | |
11487 | .cmd = NL80211_CMD_NEW_MPATH, | |
11488 | .doit = nl80211_new_mpath, | |
11489 | .policy = nl80211_policy, | |
5617c6cd | 11490 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11491 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11492 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
11493 | }, |
11494 | { | |
11495 | .cmd = NL80211_CMD_DEL_MPATH, | |
11496 | .doit = nl80211_del_mpath, | |
11497 | .policy = nl80211_policy, | |
5617c6cd | 11498 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11499 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11500 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
11501 | }, |
11502 | { | |
11503 | .cmd = NL80211_CMD_SET_BSS, | |
11504 | .doit = nl80211_set_bss, | |
11505 | .policy = nl80211_policy, | |
5617c6cd | 11506 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11507 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11508 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 11509 | }, |
f130347c LR |
11510 | { |
11511 | .cmd = NL80211_CMD_GET_REG, | |
ad30ca2c AN |
11512 | .doit = nl80211_get_reg_do, |
11513 | .dumpit = nl80211_get_reg_dump, | |
f130347c | 11514 | .policy = nl80211_policy, |
5fe231e8 | 11515 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
11516 | /* can be retrieved by unprivileged users */ |
11517 | }, | |
b6863036 | 11518 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
b2e1b302 LR |
11519 | { |
11520 | .cmd = NL80211_CMD_SET_REG, | |
11521 | .doit = nl80211_set_reg, | |
11522 | .policy = nl80211_policy, | |
11523 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 11524 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 11525 | }, |
b6863036 | 11526 | #endif |
b2e1b302 LR |
11527 | { |
11528 | .cmd = NL80211_CMD_REQ_SET_REG, | |
11529 | .doit = nl80211_req_set_reg, | |
11530 | .policy = nl80211_policy, | |
93da9cc1 | 11531 | .flags = GENL_ADMIN_PERM, |
11532 | }, | |
11533 | { | |
24bdd9f4 JC |
11534 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
11535 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 11536 | .policy = nl80211_policy, |
11537 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 11538 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11539 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 11540 | }, |
11541 | { | |
24bdd9f4 JC |
11542 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
11543 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 11544 | .policy = nl80211_policy, |
5617c6cd | 11545 | .flags = GENL_UNS_ADMIN_PERM, |
29cbe68c | 11546 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11547 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 11548 | }, |
2a519311 JB |
11549 | { |
11550 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
11551 | .doit = nl80211_trigger_scan, | |
11552 | .policy = nl80211_policy, | |
5617c6cd | 11553 | .flags = GENL_UNS_ADMIN_PERM, |
fd014284 | 11554 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 11555 | NL80211_FLAG_NEED_RTNL, |
2a519311 | 11556 | }, |
91d3ab46 VK |
11557 | { |
11558 | .cmd = NL80211_CMD_ABORT_SCAN, | |
11559 | .doit = nl80211_abort_scan, | |
11560 | .policy = nl80211_policy, | |
5617c6cd | 11561 | .flags = GENL_UNS_ADMIN_PERM, |
91d3ab46 VK |
11562 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
11563 | NL80211_FLAG_NEED_RTNL, | |
11564 | }, | |
2a519311 JB |
11565 | { |
11566 | .cmd = NL80211_CMD_GET_SCAN, | |
11567 | .policy = nl80211_policy, | |
11568 | .dumpit = nl80211_dump_scan, | |
11569 | }, | |
807f8a8c LC |
11570 | { |
11571 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
11572 | .doit = nl80211_start_sched_scan, | |
11573 | .policy = nl80211_policy, | |
5617c6cd | 11574 | .flags = GENL_UNS_ADMIN_PERM, |
807f8a8c LC |
11575 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11576 | NL80211_FLAG_NEED_RTNL, | |
11577 | }, | |
11578 | { | |
11579 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
11580 | .doit = nl80211_stop_sched_scan, | |
11581 | .policy = nl80211_policy, | |
5617c6cd | 11582 | .flags = GENL_UNS_ADMIN_PERM, |
807f8a8c LC |
11583 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11584 | NL80211_FLAG_NEED_RTNL, | |
11585 | }, | |
636a5d36 JM |
11586 | { |
11587 | .cmd = NL80211_CMD_AUTHENTICATE, | |
11588 | .doit = nl80211_authenticate, | |
11589 | .policy = nl80211_policy, | |
5617c6cd | 11590 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11591 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
11592 | NL80211_FLAG_NEED_RTNL | |
11593 | NL80211_FLAG_CLEAR_SKB, | |
636a5d36 JM |
11594 | }, |
11595 | { | |
11596 | .cmd = NL80211_CMD_ASSOCIATE, | |
11597 | .doit = nl80211_associate, | |
11598 | .policy = nl80211_policy, | |
5617c6cd | 11599 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11600 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11601 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
11602 | }, |
11603 | { | |
11604 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
11605 | .doit = nl80211_deauthenticate, | |
11606 | .policy = nl80211_policy, | |
5617c6cd | 11607 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11608 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11609 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
11610 | }, |
11611 | { | |
11612 | .cmd = NL80211_CMD_DISASSOCIATE, | |
11613 | .doit = nl80211_disassociate, | |
11614 | .policy = nl80211_policy, | |
5617c6cd | 11615 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11616 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11617 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 11618 | }, |
04a773ad JB |
11619 | { |
11620 | .cmd = NL80211_CMD_JOIN_IBSS, | |
11621 | .doit = nl80211_join_ibss, | |
11622 | .policy = nl80211_policy, | |
5617c6cd | 11623 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11624 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11625 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
11626 | }, |
11627 | { | |
11628 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
11629 | .doit = nl80211_leave_ibss, | |
11630 | .policy = nl80211_policy, | |
5617c6cd | 11631 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11632 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11633 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 11634 | }, |
aff89a9b JB |
11635 | #ifdef CONFIG_NL80211_TESTMODE |
11636 | { | |
11637 | .cmd = NL80211_CMD_TESTMODE, | |
11638 | .doit = nl80211_testmode_do, | |
71063f0e | 11639 | .dumpit = nl80211_testmode_dump, |
aff89a9b | 11640 | .policy = nl80211_policy, |
5617c6cd | 11641 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11642 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11643 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
11644 | }, |
11645 | #endif | |
b23aa676 SO |
11646 | { |
11647 | .cmd = NL80211_CMD_CONNECT, | |
11648 | .doit = nl80211_connect, | |
11649 | .policy = nl80211_policy, | |
5617c6cd | 11650 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11651 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11652 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
11653 | }, |
11654 | { | |
11655 | .cmd = NL80211_CMD_DISCONNECT, | |
11656 | .doit = nl80211_disconnect, | |
11657 | .policy = nl80211_policy, | |
5617c6cd | 11658 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11659 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11660 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 11661 | }, |
463d0183 JB |
11662 | { |
11663 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
11664 | .doit = nl80211_wiphy_netns, | |
11665 | .policy = nl80211_policy, | |
5617c6cd | 11666 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11667 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11668 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 11669 | }, |
61fa713c HS |
11670 | { |
11671 | .cmd = NL80211_CMD_GET_SURVEY, | |
11672 | .policy = nl80211_policy, | |
11673 | .dumpit = nl80211_dump_survey, | |
11674 | }, | |
67fbb16b SO |
11675 | { |
11676 | .cmd = NL80211_CMD_SET_PMKSA, | |
11677 | .doit = nl80211_setdel_pmksa, | |
11678 | .policy = nl80211_policy, | |
5617c6cd | 11679 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11680 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11681 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
11682 | }, |
11683 | { | |
11684 | .cmd = NL80211_CMD_DEL_PMKSA, | |
11685 | .doit = nl80211_setdel_pmksa, | |
11686 | .policy = nl80211_policy, | |
5617c6cd | 11687 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11688 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11689 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
11690 | }, |
11691 | { | |
11692 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
11693 | .doit = nl80211_flush_pmksa, | |
11694 | .policy = nl80211_policy, | |
5617c6cd | 11695 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11696 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11697 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 11698 | }, |
9588bbd5 JM |
11699 | { |
11700 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
11701 | .doit = nl80211_remain_on_channel, | |
11702 | .policy = nl80211_policy, | |
5617c6cd | 11703 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 11704 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 11705 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
11706 | }, |
11707 | { | |
11708 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
11709 | .doit = nl80211_cancel_remain_on_channel, | |
11710 | .policy = nl80211_policy, | |
5617c6cd | 11711 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 11712 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 11713 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 11714 | }, |
13ae75b1 JM |
11715 | { |
11716 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
11717 | .doit = nl80211_set_tx_bitrate_mask, | |
11718 | .policy = nl80211_policy, | |
5617c6cd | 11719 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11720 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11721 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 11722 | }, |
026331c4 | 11723 | { |
2e161f78 JB |
11724 | .cmd = NL80211_CMD_REGISTER_FRAME, |
11725 | .doit = nl80211_register_mgmt, | |
026331c4 | 11726 | .policy = nl80211_policy, |
5617c6cd | 11727 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 11728 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 11729 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
11730 | }, |
11731 | { | |
2e161f78 JB |
11732 | .cmd = NL80211_CMD_FRAME, |
11733 | .doit = nl80211_tx_mgmt, | |
026331c4 | 11734 | .policy = nl80211_policy, |
5617c6cd | 11735 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 11736 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
11737 | NL80211_FLAG_NEED_RTNL, |
11738 | }, | |
11739 | { | |
11740 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
11741 | .doit = nl80211_tx_mgmt_cancel_wait, | |
11742 | .policy = nl80211_policy, | |
5617c6cd | 11743 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 11744 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 11745 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 11746 | }, |
ffb9eb3d KV |
11747 | { |
11748 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
11749 | .doit = nl80211_set_power_save, | |
11750 | .policy = nl80211_policy, | |
5617c6cd | 11751 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11752 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11753 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
11754 | }, |
11755 | { | |
11756 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
11757 | .doit = nl80211_get_power_save, | |
11758 | .policy = nl80211_policy, | |
11759 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
11760 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11761 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 11762 | }, |
d6dc1a38 JO |
11763 | { |
11764 | .cmd = NL80211_CMD_SET_CQM, | |
11765 | .doit = nl80211_set_cqm, | |
11766 | .policy = nl80211_policy, | |
5617c6cd | 11767 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11768 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11769 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 11770 | }, |
f444de05 JB |
11771 | { |
11772 | .cmd = NL80211_CMD_SET_CHANNEL, | |
11773 | .doit = nl80211_set_channel, | |
11774 | .policy = nl80211_policy, | |
5617c6cd | 11775 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11776 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11777 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 11778 | }, |
e8347eba BJ |
11779 | { |
11780 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
11781 | .doit = nl80211_set_wds_peer, | |
11782 | .policy = nl80211_policy, | |
5617c6cd | 11783 | .flags = GENL_UNS_ADMIN_PERM, |
43b19952 JB |
11784 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11785 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 11786 | }, |
29cbe68c JB |
11787 | { |
11788 | .cmd = NL80211_CMD_JOIN_MESH, | |
11789 | .doit = nl80211_join_mesh, | |
11790 | .policy = nl80211_policy, | |
5617c6cd | 11791 | .flags = GENL_UNS_ADMIN_PERM, |
29cbe68c JB |
11792 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11793 | NL80211_FLAG_NEED_RTNL, | |
11794 | }, | |
11795 | { | |
11796 | .cmd = NL80211_CMD_LEAVE_MESH, | |
11797 | .doit = nl80211_leave_mesh, | |
11798 | .policy = nl80211_policy, | |
5617c6cd | 11799 | .flags = GENL_UNS_ADMIN_PERM, |
29cbe68c JB |
11800 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11801 | NL80211_FLAG_NEED_RTNL, | |
11802 | }, | |
6e0bd6c3 RL |
11803 | { |
11804 | .cmd = NL80211_CMD_JOIN_OCB, | |
11805 | .doit = nl80211_join_ocb, | |
11806 | .policy = nl80211_policy, | |
5617c6cd | 11807 | .flags = GENL_UNS_ADMIN_PERM, |
6e0bd6c3 RL |
11808 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11809 | NL80211_FLAG_NEED_RTNL, | |
11810 | }, | |
11811 | { | |
11812 | .cmd = NL80211_CMD_LEAVE_OCB, | |
11813 | .doit = nl80211_leave_ocb, | |
11814 | .policy = nl80211_policy, | |
5617c6cd | 11815 | .flags = GENL_UNS_ADMIN_PERM, |
6e0bd6c3 RL |
11816 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11817 | NL80211_FLAG_NEED_RTNL, | |
11818 | }, | |
dfb89c56 | 11819 | #ifdef CONFIG_PM |
ff1b6e69 JB |
11820 | { |
11821 | .cmd = NL80211_CMD_GET_WOWLAN, | |
11822 | .doit = nl80211_get_wowlan, | |
11823 | .policy = nl80211_policy, | |
11824 | /* can be retrieved by unprivileged users */ | |
11825 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
11826 | NL80211_FLAG_NEED_RTNL, | |
11827 | }, | |
11828 | { | |
11829 | .cmd = NL80211_CMD_SET_WOWLAN, | |
11830 | .doit = nl80211_set_wowlan, | |
11831 | .policy = nl80211_policy, | |
5617c6cd | 11832 | .flags = GENL_UNS_ADMIN_PERM, |
ff1b6e69 JB |
11833 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11834 | NL80211_FLAG_NEED_RTNL, | |
11835 | }, | |
dfb89c56 | 11836 | #endif |
e5497d76 JB |
11837 | { |
11838 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
11839 | .doit = nl80211_set_rekey_data, | |
11840 | .policy = nl80211_policy, | |
5617c6cd | 11841 | .flags = GENL_UNS_ADMIN_PERM, |
e5497d76 | 11842 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
11843 | NL80211_FLAG_NEED_RTNL | |
11844 | NL80211_FLAG_CLEAR_SKB, | |
e5497d76 | 11845 | }, |
109086ce AN |
11846 | { |
11847 | .cmd = NL80211_CMD_TDLS_MGMT, | |
11848 | .doit = nl80211_tdls_mgmt, | |
11849 | .policy = nl80211_policy, | |
5617c6cd | 11850 | .flags = GENL_UNS_ADMIN_PERM, |
109086ce AN |
11851 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11852 | NL80211_FLAG_NEED_RTNL, | |
11853 | }, | |
11854 | { | |
11855 | .cmd = NL80211_CMD_TDLS_OPER, | |
11856 | .doit = nl80211_tdls_oper, | |
11857 | .policy = nl80211_policy, | |
5617c6cd | 11858 | .flags = GENL_UNS_ADMIN_PERM, |
109086ce AN |
11859 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11860 | NL80211_FLAG_NEED_RTNL, | |
11861 | }, | |
28946da7 JB |
11862 | { |
11863 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
11864 | .doit = nl80211_register_unexpected_frame, | |
11865 | .policy = nl80211_policy, | |
5617c6cd | 11866 | .flags = GENL_UNS_ADMIN_PERM, |
28946da7 JB |
11867 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11868 | NL80211_FLAG_NEED_RTNL, | |
11869 | }, | |
7f6cf311 JB |
11870 | { |
11871 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
11872 | .doit = nl80211_probe_client, | |
11873 | .policy = nl80211_policy, | |
5617c6cd | 11874 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11875 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
11876 | NL80211_FLAG_NEED_RTNL, |
11877 | }, | |
5e760230 JB |
11878 | { |
11879 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
11880 | .doit = nl80211_register_beacons, | |
11881 | .policy = nl80211_policy, | |
5617c6cd | 11882 | .flags = GENL_UNS_ADMIN_PERM, |
5e760230 JB |
11883 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11884 | NL80211_FLAG_NEED_RTNL, | |
11885 | }, | |
1d9d9213 SW |
11886 | { |
11887 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
11888 | .doit = nl80211_set_noack_map, | |
11889 | .policy = nl80211_policy, | |
5617c6cd | 11890 | .flags = GENL_UNS_ADMIN_PERM, |
1d9d9213 SW |
11891 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11892 | NL80211_FLAG_NEED_RTNL, | |
11893 | }, | |
98104fde JB |
11894 | { |
11895 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
11896 | .doit = nl80211_start_p2p_device, | |
11897 | .policy = nl80211_policy, | |
5617c6cd | 11898 | .flags = GENL_UNS_ADMIN_PERM, |
98104fde JB |
11899 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
11900 | NL80211_FLAG_NEED_RTNL, | |
11901 | }, | |
11902 | { | |
11903 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
11904 | .doit = nl80211_stop_p2p_device, | |
11905 | .policy = nl80211_policy, | |
5617c6cd | 11906 | .flags = GENL_UNS_ADMIN_PERM, |
98104fde JB |
11907 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
11908 | NL80211_FLAG_NEED_RTNL, | |
cb3b7d87 AB |
11909 | }, |
11910 | { | |
11911 | .cmd = NL80211_CMD_START_NAN, | |
11912 | .doit = nl80211_start_nan, | |
11913 | .policy = nl80211_policy, | |
11914 | .flags = GENL_ADMIN_PERM, | |
11915 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
11916 | NL80211_FLAG_NEED_RTNL, | |
11917 | }, | |
11918 | { | |
11919 | .cmd = NL80211_CMD_STOP_NAN, | |
11920 | .doit = nl80211_stop_nan, | |
11921 | .policy = nl80211_policy, | |
11922 | .flags = GENL_ADMIN_PERM, | |
11923 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
11924 | NL80211_FLAG_NEED_RTNL, | |
98104fde | 11925 | }, |
f4e583c8 AQ |
11926 | { |
11927 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
11928 | .doit = nl80211_set_mcast_rate, | |
77765eaf | 11929 | .policy = nl80211_policy, |
5617c6cd | 11930 | .flags = GENL_UNS_ADMIN_PERM, |
77765eaf VT |
11931 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11932 | NL80211_FLAG_NEED_RTNL, | |
11933 | }, | |
11934 | { | |
11935 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
11936 | .doit = nl80211_set_mac_acl, | |
f4e583c8 | 11937 | .policy = nl80211_policy, |
5617c6cd | 11938 | .flags = GENL_UNS_ADMIN_PERM, |
f4e583c8 AQ |
11939 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11940 | NL80211_FLAG_NEED_RTNL, | |
11941 | }, | |
04f39047 SW |
11942 | { |
11943 | .cmd = NL80211_CMD_RADAR_DETECT, | |
11944 | .doit = nl80211_start_radar_detection, | |
11945 | .policy = nl80211_policy, | |
5617c6cd | 11946 | .flags = GENL_UNS_ADMIN_PERM, |
04f39047 SW |
11947 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11948 | NL80211_FLAG_NEED_RTNL, | |
11949 | }, | |
3713b4e3 JB |
11950 | { |
11951 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
11952 | .doit = nl80211_get_protocol_features, | |
11953 | .policy = nl80211_policy, | |
11954 | }, | |
355199e0 JM |
11955 | { |
11956 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
11957 | .doit = nl80211_update_ft_ies, | |
11958 | .policy = nl80211_policy, | |
5617c6cd | 11959 | .flags = GENL_UNS_ADMIN_PERM, |
355199e0 JM |
11960 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11961 | NL80211_FLAG_NEED_RTNL, | |
11962 | }, | |
5de17984 AS |
11963 | { |
11964 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
11965 | .doit = nl80211_crit_protocol_start, | |
11966 | .policy = nl80211_policy, | |
5617c6cd | 11967 | .flags = GENL_UNS_ADMIN_PERM, |
5de17984 AS |
11968 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
11969 | NL80211_FLAG_NEED_RTNL, | |
11970 | }, | |
11971 | { | |
11972 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
11973 | .doit = nl80211_crit_protocol_stop, | |
11974 | .policy = nl80211_policy, | |
5617c6cd | 11975 | .flags = GENL_UNS_ADMIN_PERM, |
5de17984 AS |
11976 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
11977 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
11978 | }, |
11979 | { | |
11980 | .cmd = NL80211_CMD_GET_COALESCE, | |
11981 | .doit = nl80211_get_coalesce, | |
11982 | .policy = nl80211_policy, | |
11983 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
11984 | NL80211_FLAG_NEED_RTNL, | |
11985 | }, | |
11986 | { | |
11987 | .cmd = NL80211_CMD_SET_COALESCE, | |
11988 | .doit = nl80211_set_coalesce, | |
11989 | .policy = nl80211_policy, | |
5617c6cd | 11990 | .flags = GENL_UNS_ADMIN_PERM, |
be29b99a AK |
11991 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11992 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
11993 | }, |
11994 | { | |
11995 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
11996 | .doit = nl80211_channel_switch, | |
11997 | .policy = nl80211_policy, | |
5617c6cd | 11998 | .flags = GENL_UNS_ADMIN_PERM, |
16ef1fe2 SW |
11999 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12000 | NL80211_FLAG_NEED_RTNL, | |
12001 | }, | |
ad7e718c JB |
12002 | { |
12003 | .cmd = NL80211_CMD_VENDOR, | |
12004 | .doit = nl80211_vendor_cmd, | |
7bdbe400 | 12005 | .dumpit = nl80211_vendor_cmd_dump, |
ad7e718c | 12006 | .policy = nl80211_policy, |
5617c6cd | 12007 | .flags = GENL_UNS_ADMIN_PERM, |
ad7e718c JB |
12008 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
12009 | NL80211_FLAG_NEED_RTNL, | |
12010 | }, | |
fa9ffc74 KP |
12011 | { |
12012 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
12013 | .doit = nl80211_set_qos_map, | |
12014 | .policy = nl80211_policy, | |
5617c6cd | 12015 | .flags = GENL_UNS_ADMIN_PERM, |
fa9ffc74 KP |
12016 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12017 | NL80211_FLAG_NEED_RTNL, | |
12018 | }, | |
960d01ac JB |
12019 | { |
12020 | .cmd = NL80211_CMD_ADD_TX_TS, | |
12021 | .doit = nl80211_add_tx_ts, | |
12022 | .policy = nl80211_policy, | |
5617c6cd | 12023 | .flags = GENL_UNS_ADMIN_PERM, |
960d01ac JB |
12024 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12025 | NL80211_FLAG_NEED_RTNL, | |
12026 | }, | |
12027 | { | |
12028 | .cmd = NL80211_CMD_DEL_TX_TS, | |
12029 | .doit = nl80211_del_tx_ts, | |
12030 | .policy = nl80211_policy, | |
5617c6cd | 12031 | .flags = GENL_UNS_ADMIN_PERM, |
960d01ac JB |
12032 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12033 | NL80211_FLAG_NEED_RTNL, | |
12034 | }, | |
1057d35e AN |
12035 | { |
12036 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | |
12037 | .doit = nl80211_tdls_channel_switch, | |
12038 | .policy = nl80211_policy, | |
5617c6cd | 12039 | .flags = GENL_UNS_ADMIN_PERM, |
1057d35e AN |
12040 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12041 | NL80211_FLAG_NEED_RTNL, | |
12042 | }, | |
12043 | { | |
12044 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | |
12045 | .doit = nl80211_tdls_cancel_channel_switch, | |
12046 | .policy = nl80211_policy, | |
5617c6cd | 12047 | .flags = GENL_UNS_ADMIN_PERM, |
1057d35e AN |
12048 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12049 | NL80211_FLAG_NEED_RTNL, | |
12050 | }, | |
55682965 | 12051 | }; |
9588bbd5 | 12052 | |
55682965 JB |
12053 | /* notification functions */ |
12054 | ||
3bb20556 JB |
12055 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
12056 | enum nl80211_commands cmd) | |
55682965 JB |
12057 | { |
12058 | struct sk_buff *msg; | |
86e8cf98 | 12059 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 12060 | |
3bb20556 JB |
12061 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
12062 | cmd != NL80211_CMD_DEL_WIPHY); | |
12063 | ||
fd2120ca | 12064 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
12065 | if (!msg) |
12066 | return; | |
12067 | ||
3bb20556 | 12068 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
12069 | nlmsg_free(msg); |
12070 | return; | |
12071 | } | |
12072 | ||
68eb5503 | 12073 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12074 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
12075 | } |
12076 | ||
896ff063 DK |
12077 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
12078 | struct wireless_dev *wdev, | |
12079 | enum nl80211_commands cmd) | |
12080 | { | |
12081 | struct sk_buff *msg; | |
12082 | ||
12083 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && | |
12084 | cmd != NL80211_CMD_DEL_INTERFACE); | |
12085 | ||
12086 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12087 | if (!msg) | |
12088 | return; | |
12089 | ||
12090 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, | |
12091 | cmd == NL80211_CMD_DEL_INTERFACE) < 0) { | |
12092 | nlmsg_free(msg); | |
12093 | return; | |
12094 | } | |
12095 | ||
12096 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | |
12097 | NL80211_MCGRP_CONFIG, GFP_KERNEL); | |
12098 | } | |
12099 | ||
362a415d JB |
12100 | static int nl80211_add_scan_req(struct sk_buff *msg, |
12101 | struct cfg80211_registered_device *rdev) | |
12102 | { | |
12103 | struct cfg80211_scan_request *req = rdev->scan_req; | |
12104 | struct nlattr *nest; | |
12105 | int i; | |
12106 | ||
12107 | if (WARN_ON(!req)) | |
12108 | return 0; | |
12109 | ||
12110 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
12111 | if (!nest) | |
12112 | goto nla_put_failure; | |
9360ffd1 DM |
12113 | for (i = 0; i < req->n_ssids; i++) { |
12114 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
12115 | goto nla_put_failure; | |
12116 | } | |
362a415d JB |
12117 | nla_nest_end(msg, nest); |
12118 | ||
12119 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
12120 | if (!nest) | |
12121 | goto nla_put_failure; | |
9360ffd1 DM |
12122 | for (i = 0; i < req->n_channels; i++) { |
12123 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
12124 | goto nla_put_failure; | |
12125 | } | |
362a415d JB |
12126 | nla_nest_end(msg, nest); |
12127 | ||
9360ffd1 DM |
12128 | if (req->ie && |
12129 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
12130 | goto nla_put_failure; | |
362a415d | 12131 | |
ae917c9f JB |
12132 | if (req->flags && |
12133 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
12134 | goto nla_put_failure; | |
ed473771 | 12135 | |
1d76250b AS |
12136 | if (req->info.scan_start_tsf && |
12137 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, | |
12138 | req->info.scan_start_tsf, NL80211_BSS_PAD) || | |
12139 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, | |
12140 | req->info.tsf_bssid))) | |
12141 | goto nla_put_failure; | |
12142 | ||
362a415d JB |
12143 | return 0; |
12144 | nla_put_failure: | |
12145 | return -ENOBUFS; | |
12146 | } | |
12147 | ||
a538e2d5 JB |
12148 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
12149 | struct cfg80211_registered_device *rdev, | |
fd014284 | 12150 | struct wireless_dev *wdev, |
15e47304 | 12151 | u32 portid, u32 seq, int flags, |
a538e2d5 | 12152 | u32 cmd) |
2a519311 JB |
12153 | { |
12154 | void *hdr; | |
12155 | ||
15e47304 | 12156 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
12157 | if (!hdr) |
12158 | return -1; | |
12159 | ||
9360ffd1 | 12160 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
12161 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
12162 | wdev->netdev->ifindex)) || | |
2dad624e ND |
12163 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
12164 | NL80211_ATTR_PAD)) | |
9360ffd1 | 12165 | goto nla_put_failure; |
2a519311 | 12166 | |
362a415d JB |
12167 | /* ignore errors and send incomplete event anyway */ |
12168 | nl80211_add_scan_req(msg, rdev); | |
2a519311 | 12169 | |
053c095a JB |
12170 | genlmsg_end(msg, hdr); |
12171 | return 0; | |
2a519311 JB |
12172 | |
12173 | nla_put_failure: | |
12174 | genlmsg_cancel(msg, hdr); | |
12175 | return -EMSGSIZE; | |
12176 | } | |
12177 | ||
807f8a8c LC |
12178 | static int |
12179 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
12180 | struct cfg80211_registered_device *rdev, | |
12181 | struct net_device *netdev, | |
15e47304 | 12182 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
12183 | { |
12184 | void *hdr; | |
12185 | ||
15e47304 | 12186 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
12187 | if (!hdr) |
12188 | return -1; | |
12189 | ||
9360ffd1 DM |
12190 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12191 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
12192 | goto nla_put_failure; | |
807f8a8c | 12193 | |
053c095a JB |
12194 | genlmsg_end(msg, hdr); |
12195 | return 0; | |
807f8a8c LC |
12196 | |
12197 | nla_put_failure: | |
12198 | genlmsg_cancel(msg, hdr); | |
12199 | return -EMSGSIZE; | |
12200 | } | |
12201 | ||
a538e2d5 | 12202 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 12203 | struct wireless_dev *wdev) |
a538e2d5 JB |
12204 | { |
12205 | struct sk_buff *msg; | |
12206 | ||
58050fce | 12207 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
12208 | if (!msg) |
12209 | return; | |
12210 | ||
fd014284 | 12211 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
12212 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
12213 | nlmsg_free(msg); | |
12214 | return; | |
12215 | } | |
12216 | ||
68eb5503 | 12217 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12218 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
12219 | } |
12220 | ||
f9d15d16 JB |
12221 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
12222 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
12223 | { |
12224 | struct sk_buff *msg; | |
12225 | ||
fd2120ca | 12226 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 12227 | if (!msg) |
f9d15d16 | 12228 | return NULL; |
2a519311 | 12229 | |
fd014284 | 12230 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
12231 | aborted ? NL80211_CMD_SCAN_ABORTED : |
12232 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 12233 | nlmsg_free(msg); |
f9d15d16 | 12234 | return NULL; |
2a519311 JB |
12235 | } |
12236 | ||
f9d15d16 | 12237 | return msg; |
2a519311 JB |
12238 | } |
12239 | ||
f9d15d16 JB |
12240 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
12241 | struct sk_buff *msg) | |
2a519311 | 12242 | { |
2a519311 JB |
12243 | if (!msg) |
12244 | return; | |
12245 | ||
68eb5503 | 12246 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12247 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
12248 | } |
12249 | ||
807f8a8c LC |
12250 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
12251 | struct net_device *netdev) | |
12252 | { | |
12253 | struct sk_buff *msg; | |
12254 | ||
12255 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12256 | if (!msg) | |
12257 | return; | |
12258 | ||
12259 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
12260 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
12261 | nlmsg_free(msg); | |
12262 | return; | |
12263 | } | |
12264 | ||
68eb5503 | 12265 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12266 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
12267 | } |
12268 | ||
12269 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
12270 | struct net_device *netdev, u32 cmd) | |
12271 | { | |
12272 | struct sk_buff *msg; | |
12273 | ||
58050fce | 12274 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
12275 | if (!msg) |
12276 | return; | |
12277 | ||
12278 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
12279 | nlmsg_free(msg); | |
12280 | return; | |
12281 | } | |
12282 | ||
68eb5503 | 12283 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12284 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
12285 | } |
12286 | ||
b0d7aa59 JD |
12287 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
12288 | struct regulatory_request *request) | |
73d54c9e | 12289 | { |
73d54c9e | 12290 | /* Userspace can always count this one always being set */ |
9360ffd1 DM |
12291 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
12292 | goto nla_put_failure; | |
12293 | ||
12294 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
12295 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
12296 | NL80211_REGDOM_TYPE_WORLD)) | |
12297 | goto nla_put_failure; | |
12298 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
12299 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
12300 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
12301 | goto nla_put_failure; | |
12302 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
12303 | request->intersect) { | |
12304 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
12305 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
12306 | goto nla_put_failure; | |
12307 | } else { | |
12308 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
12309 | NL80211_REGDOM_TYPE_COUNTRY) || | |
12310 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
12311 | request->alpha2)) | |
12312 | goto nla_put_failure; | |
12313 | } | |
12314 | ||
ad30ca2c AN |
12315 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
12316 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); | |
12317 | ||
12318 | if (wiphy && | |
12319 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | |
12320 | goto nla_put_failure; | |
1bdd716c AN |
12321 | |
12322 | if (wiphy && | |
12323 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | |
12324 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
12325 | goto nla_put_failure; | |
ad30ca2c | 12326 | } |
73d54c9e | 12327 | |
b0d7aa59 JD |
12328 | return true; |
12329 | ||
12330 | nla_put_failure: | |
12331 | return false; | |
12332 | } | |
12333 | ||
12334 | /* | |
12335 | * This can happen on global regulatory changes or device specific settings | |
12336 | * based on custom regulatory domains. | |
12337 | */ | |
12338 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, | |
12339 | struct regulatory_request *request) | |
12340 | { | |
12341 | struct sk_buff *msg; | |
12342 | void *hdr; | |
12343 | ||
12344 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12345 | if (!msg) | |
12346 | return; | |
12347 | ||
12348 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); | |
12349 | if (!hdr) { | |
12350 | nlmsg_free(msg); | |
12351 | return; | |
12352 | } | |
12353 | ||
12354 | if (nl80211_reg_change_event_fill(msg, request) == false) | |
12355 | goto nla_put_failure; | |
12356 | ||
3b7b72ee | 12357 | genlmsg_end(msg, hdr); |
73d54c9e | 12358 | |
bc43b28c | 12359 | rcu_read_lock(); |
68eb5503 | 12360 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 12361 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 12362 | rcu_read_unlock(); |
73d54c9e LR |
12363 | |
12364 | return; | |
12365 | ||
12366 | nla_put_failure: | |
12367 | genlmsg_cancel(msg, hdr); | |
12368 | nlmsg_free(msg); | |
12369 | } | |
12370 | ||
6039f6d2 JM |
12371 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
12372 | struct net_device *netdev, | |
12373 | const u8 *buf, size_t len, | |
b0b6aa2c EP |
12374 | enum nl80211_commands cmd, gfp_t gfp, |
12375 | int uapsd_queues) | |
6039f6d2 JM |
12376 | { |
12377 | struct sk_buff *msg; | |
12378 | void *hdr; | |
12379 | ||
e6d6e342 | 12380 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
12381 | if (!msg) |
12382 | return; | |
12383 | ||
12384 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
12385 | if (!hdr) { | |
12386 | nlmsg_free(msg); | |
12387 | return; | |
12388 | } | |
12389 | ||
9360ffd1 DM |
12390 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12391 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12392 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
12393 | goto nla_put_failure; | |
6039f6d2 | 12394 | |
b0b6aa2c EP |
12395 | if (uapsd_queues >= 0) { |
12396 | struct nlattr *nla_wmm = | |
12397 | nla_nest_start(msg, NL80211_ATTR_STA_WME); | |
12398 | if (!nla_wmm) | |
12399 | goto nla_put_failure; | |
12400 | ||
12401 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
12402 | uapsd_queues)) | |
12403 | goto nla_put_failure; | |
12404 | ||
12405 | nla_nest_end(msg, nla_wmm); | |
12406 | } | |
12407 | ||
3b7b72ee | 12408 | genlmsg_end(msg, hdr); |
6039f6d2 | 12409 | |
68eb5503 | 12410 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12411 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
12412 | return; |
12413 | ||
12414 | nla_put_failure: | |
12415 | genlmsg_cancel(msg, hdr); | |
12416 | nlmsg_free(msg); | |
12417 | } | |
12418 | ||
12419 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
12420 | struct net_device *netdev, const u8 *buf, |
12421 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
12422 | { |
12423 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 12424 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
6039f6d2 JM |
12425 | } |
12426 | ||
12427 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
12428 | struct net_device *netdev, const u8 *buf, | |
b0b6aa2c | 12429 | size_t len, gfp_t gfp, int uapsd_queues) |
6039f6d2 | 12430 | { |
e6d6e342 | 12431 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
b0b6aa2c | 12432 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
6039f6d2 JM |
12433 | } |
12434 | ||
53b46b84 | 12435 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
12436 | struct net_device *netdev, const u8 *buf, |
12437 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
12438 | { |
12439 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 12440 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
6039f6d2 JM |
12441 | } |
12442 | ||
53b46b84 JM |
12443 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
12444 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 12445 | size_t len, gfp_t gfp) |
6039f6d2 JM |
12446 | { |
12447 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 12448 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
6039f6d2 JM |
12449 | } |
12450 | ||
6ff57cf8 JB |
12451 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
12452 | size_t len) | |
cf4e594e | 12453 | { |
947add36 JB |
12454 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
12455 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12456 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
12457 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
12458 | u32 cmd; | |
947add36 | 12459 | |
6ff57cf8 JB |
12460 | if (WARN_ON(len < 2)) |
12461 | return; | |
cf4e594e | 12462 | |
6ff57cf8 JB |
12463 | if (ieee80211_is_deauth(mgmt->frame_control)) |
12464 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
12465 | else | |
12466 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 12467 | |
6ff57cf8 | 12468 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
b0b6aa2c | 12469 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
cf4e594e | 12470 | } |
6ff57cf8 | 12471 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 12472 | |
1b06bb40 LR |
12473 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
12474 | struct net_device *netdev, int cmd, | |
e6d6e342 | 12475 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
12476 | { |
12477 | struct sk_buff *msg; | |
12478 | void *hdr; | |
12479 | ||
e6d6e342 | 12480 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
12481 | if (!msg) |
12482 | return; | |
12483 | ||
12484 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
12485 | if (!hdr) { | |
12486 | nlmsg_free(msg); | |
12487 | return; | |
12488 | } | |
12489 | ||
9360ffd1 DM |
12490 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12491 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12492 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
12493 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
12494 | goto nla_put_failure; | |
1965c853 | 12495 | |
3b7b72ee | 12496 | genlmsg_end(msg, hdr); |
1965c853 | 12497 | |
68eb5503 | 12498 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12499 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
12500 | return; |
12501 | ||
12502 | nla_put_failure: | |
12503 | genlmsg_cancel(msg, hdr); | |
12504 | nlmsg_free(msg); | |
12505 | } | |
12506 | ||
12507 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
12508 | struct net_device *netdev, const u8 *addr, |
12509 | gfp_t gfp) | |
1965c853 JM |
12510 | { |
12511 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 12512 | addr, gfp); |
1965c853 JM |
12513 | } |
12514 | ||
12515 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
12516 | struct net_device *netdev, const u8 *addr, |
12517 | gfp_t gfp) | |
1965c853 | 12518 | { |
e6d6e342 JB |
12519 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
12520 | addr, gfp); | |
1965c853 JM |
12521 | } |
12522 | ||
b23aa676 SO |
12523 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
12524 | struct net_device *netdev, const u8 *bssid, | |
12525 | const u8 *req_ie, size_t req_ie_len, | |
12526 | const u8 *resp_ie, size_t resp_ie_len, | |
bf1ecd21 | 12527 | int status, gfp_t gfp) |
b23aa676 SO |
12528 | { |
12529 | struct sk_buff *msg; | |
12530 | void *hdr; | |
12531 | ||
58050fce | 12532 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
12533 | if (!msg) |
12534 | return; | |
12535 | ||
12536 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
12537 | if (!hdr) { | |
12538 | nlmsg_free(msg); | |
12539 | return; | |
12540 | } | |
12541 | ||
9360ffd1 DM |
12542 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12543 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12544 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
bf1ecd21 JM |
12545 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
12546 | status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : | |
12547 | status) || | |
12548 | (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) || | |
9360ffd1 DM |
12549 | (req_ie && |
12550 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
12551 | (resp_ie && | |
12552 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
12553 | goto nla_put_failure; | |
b23aa676 | 12554 | |
3b7b72ee | 12555 | genlmsg_end(msg, hdr); |
b23aa676 | 12556 | |
68eb5503 | 12557 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12558 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
12559 | return; |
12560 | ||
12561 | nla_put_failure: | |
12562 | genlmsg_cancel(msg, hdr); | |
12563 | nlmsg_free(msg); | |
b23aa676 SO |
12564 | } |
12565 | ||
12566 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
12567 | struct net_device *netdev, const u8 *bssid, | |
12568 | const u8 *req_ie, size_t req_ie_len, | |
12569 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
12570 | { | |
12571 | struct sk_buff *msg; | |
12572 | void *hdr; | |
12573 | ||
58050fce | 12574 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
12575 | if (!msg) |
12576 | return; | |
12577 | ||
12578 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
12579 | if (!hdr) { | |
12580 | nlmsg_free(msg); | |
12581 | return; | |
12582 | } | |
12583 | ||
9360ffd1 DM |
12584 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12585 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12586 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
12587 | (req_ie && | |
12588 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
12589 | (resp_ie && | |
12590 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
12591 | goto nla_put_failure; | |
b23aa676 | 12592 | |
3b7b72ee | 12593 | genlmsg_end(msg, hdr); |
b23aa676 | 12594 | |
68eb5503 | 12595 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12596 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
12597 | return; |
12598 | ||
12599 | nla_put_failure: | |
12600 | genlmsg_cancel(msg, hdr); | |
12601 | nlmsg_free(msg); | |
b23aa676 SO |
12602 | } |
12603 | ||
12604 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
12605 | struct net_device *netdev, u16 reason, | |
667503dd | 12606 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
12607 | { |
12608 | struct sk_buff *msg; | |
12609 | void *hdr; | |
12610 | ||
58050fce | 12611 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
12612 | if (!msg) |
12613 | return; | |
12614 | ||
12615 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
12616 | if (!hdr) { | |
12617 | nlmsg_free(msg); | |
12618 | return; | |
12619 | } | |
12620 | ||
9360ffd1 DM |
12621 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12622 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12623 | (from_ap && reason && | |
12624 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
12625 | (from_ap && | |
12626 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
12627 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
12628 | goto nla_put_failure; | |
b23aa676 | 12629 | |
3b7b72ee | 12630 | genlmsg_end(msg, hdr); |
b23aa676 | 12631 | |
68eb5503 | 12632 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12633 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
12634 | return; |
12635 | ||
12636 | nla_put_failure: | |
12637 | genlmsg_cancel(msg, hdr); | |
12638 | nlmsg_free(msg); | |
b23aa676 SO |
12639 | } |
12640 | ||
04a773ad JB |
12641 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
12642 | struct net_device *netdev, const u8 *bssid, | |
12643 | gfp_t gfp) | |
12644 | { | |
12645 | struct sk_buff *msg; | |
12646 | void *hdr; | |
12647 | ||
fd2120ca | 12648 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
12649 | if (!msg) |
12650 | return; | |
12651 | ||
12652 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
12653 | if (!hdr) { | |
12654 | nlmsg_free(msg); | |
12655 | return; | |
12656 | } | |
12657 | ||
9360ffd1 DM |
12658 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12659 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12660 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
12661 | goto nla_put_failure; | |
04a773ad | 12662 | |
3b7b72ee | 12663 | genlmsg_end(msg, hdr); |
04a773ad | 12664 | |
68eb5503 | 12665 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12666 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
12667 | return; |
12668 | ||
12669 | nla_put_failure: | |
12670 | genlmsg_cancel(msg, hdr); | |
12671 | nlmsg_free(msg); | |
12672 | } | |
12673 | ||
947add36 JB |
12674 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
12675 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 12676 | { |
947add36 | 12677 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 12678 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
12679 | struct sk_buff *msg; |
12680 | void *hdr; | |
12681 | ||
947add36 JB |
12682 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
12683 | return; | |
12684 | ||
12685 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
12686 | ||
c93b5e71 JC |
12687 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
12688 | if (!msg) | |
12689 | return; | |
12690 | ||
12691 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
12692 | if (!hdr) { | |
12693 | nlmsg_free(msg); | |
12694 | return; | |
12695 | } | |
12696 | ||
9360ffd1 | 12697 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
12698 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
12699 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
12700 | (ie_len && ie && |
12701 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
12702 | goto nla_put_failure; | |
c93b5e71 | 12703 | |
3b7b72ee | 12704 | genlmsg_end(msg, hdr); |
c93b5e71 | 12705 | |
68eb5503 | 12706 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12707 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
12708 | return; |
12709 | ||
12710 | nla_put_failure: | |
12711 | genlmsg_cancel(msg, hdr); | |
12712 | nlmsg_free(msg); | |
12713 | } | |
947add36 | 12714 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 12715 | |
a3b8b056 JM |
12716 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
12717 | struct net_device *netdev, const u8 *addr, | |
12718 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 12719 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
12720 | { |
12721 | struct sk_buff *msg; | |
12722 | void *hdr; | |
12723 | ||
e6d6e342 | 12724 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
12725 | if (!msg) |
12726 | return; | |
12727 | ||
12728 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
12729 | if (!hdr) { | |
12730 | nlmsg_free(msg); | |
12731 | return; | |
12732 | } | |
12733 | ||
9360ffd1 DM |
12734 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12735 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12736 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
12737 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
12738 | (key_id != -1 && | |
12739 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
12740 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
12741 | goto nla_put_failure; | |
a3b8b056 | 12742 | |
3b7b72ee | 12743 | genlmsg_end(msg, hdr); |
a3b8b056 | 12744 | |
68eb5503 | 12745 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12746 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
12747 | return; |
12748 | ||
12749 | nla_put_failure: | |
12750 | genlmsg_cancel(msg, hdr); | |
12751 | nlmsg_free(msg); | |
12752 | } | |
12753 | ||
6bad8766 LR |
12754 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
12755 | struct ieee80211_channel *channel_before, | |
12756 | struct ieee80211_channel *channel_after) | |
12757 | { | |
12758 | struct sk_buff *msg; | |
12759 | void *hdr; | |
12760 | struct nlattr *nl_freq; | |
12761 | ||
fd2120ca | 12762 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
12763 | if (!msg) |
12764 | return; | |
12765 | ||
12766 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
12767 | if (!hdr) { | |
12768 | nlmsg_free(msg); | |
12769 | return; | |
12770 | } | |
12771 | ||
12772 | /* | |
12773 | * Since we are applying the beacon hint to a wiphy we know its | |
12774 | * wiphy_idx is valid | |
12775 | */ | |
9360ffd1 DM |
12776 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
12777 | goto nla_put_failure; | |
6bad8766 LR |
12778 | |
12779 | /* Before */ | |
12780 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
12781 | if (!nl_freq) | |
12782 | goto nla_put_failure; | |
cdc89b97 | 12783 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
12784 | goto nla_put_failure; |
12785 | nla_nest_end(msg, nl_freq); | |
12786 | ||
12787 | /* After */ | |
12788 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
12789 | if (!nl_freq) | |
12790 | goto nla_put_failure; | |
cdc89b97 | 12791 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
12792 | goto nla_put_failure; |
12793 | nla_nest_end(msg, nl_freq); | |
12794 | ||
3b7b72ee | 12795 | genlmsg_end(msg, hdr); |
6bad8766 | 12796 | |
463d0183 | 12797 | rcu_read_lock(); |
68eb5503 | 12798 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 12799 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 12800 | rcu_read_unlock(); |
6bad8766 LR |
12801 | |
12802 | return; | |
12803 | ||
12804 | nla_put_failure: | |
12805 | genlmsg_cancel(msg, hdr); | |
12806 | nlmsg_free(msg); | |
12807 | } | |
12808 | ||
9588bbd5 JM |
12809 | static void nl80211_send_remain_on_chan_event( |
12810 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 12811 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 12812 | struct ieee80211_channel *chan, |
9588bbd5 JM |
12813 | unsigned int duration, gfp_t gfp) |
12814 | { | |
12815 | struct sk_buff *msg; | |
12816 | void *hdr; | |
12817 | ||
12818 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12819 | if (!msg) | |
12820 | return; | |
12821 | ||
12822 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
12823 | if (!hdr) { | |
12824 | nlmsg_free(msg); | |
12825 | return; | |
12826 | } | |
12827 | ||
9360ffd1 | 12828 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
12829 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
12830 | wdev->netdev->ifindex)) || | |
2dad624e ND |
12831 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
12832 | NL80211_ATTR_PAD) || | |
9360ffd1 | 12833 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
12834 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
12835 | NL80211_CHAN_NO_HT) || | |
2dad624e ND |
12836 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
12837 | NL80211_ATTR_PAD)) | |
9360ffd1 | 12838 | goto nla_put_failure; |
9588bbd5 | 12839 | |
9360ffd1 DM |
12840 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
12841 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
12842 | goto nla_put_failure; | |
9588bbd5 | 12843 | |
3b7b72ee | 12844 | genlmsg_end(msg, hdr); |
9588bbd5 | 12845 | |
68eb5503 | 12846 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12847 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
12848 | return; |
12849 | ||
12850 | nla_put_failure: | |
12851 | genlmsg_cancel(msg, hdr); | |
12852 | nlmsg_free(msg); | |
12853 | } | |
12854 | ||
947add36 JB |
12855 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
12856 | struct ieee80211_channel *chan, | |
12857 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 12858 | { |
947add36 | 12859 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 12860 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12861 | |
12862 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 12863 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 12864 | rdev, wdev, cookie, chan, |
42d97a59 | 12865 | duration, gfp); |
9588bbd5 | 12866 | } |
947add36 | 12867 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 12868 | |
947add36 JB |
12869 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
12870 | struct ieee80211_channel *chan, | |
12871 | gfp_t gfp) | |
9588bbd5 | 12872 | { |
947add36 | 12873 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 12874 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12875 | |
12876 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 12877 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 12878 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 12879 | } |
947add36 | 12880 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 12881 | |
947add36 JB |
12882 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
12883 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 12884 | { |
947add36 | 12885 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 12886 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
12887 | struct sk_buff *msg; |
12888 | ||
947add36 JB |
12889 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
12890 | ||
58050fce | 12891 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
12892 | if (!msg) |
12893 | return; | |
12894 | ||
cf5ead82 | 12895 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
66266b3a | 12896 | rdev, dev, mac_addr, sinfo) < 0) { |
98b62183 JB |
12897 | nlmsg_free(msg); |
12898 | return; | |
12899 | } | |
12900 | ||
68eb5503 | 12901 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12902 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 12903 | } |
947add36 | 12904 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 12905 | |
cf5ead82 JB |
12906 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
12907 | struct station_info *sinfo, gfp_t gfp) | |
ec15e68b | 12908 | { |
947add36 | 12909 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 12910 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b | 12911 | struct sk_buff *msg; |
cf5ead82 JB |
12912 | struct station_info empty_sinfo = {}; |
12913 | ||
12914 | if (!sinfo) | |
12915 | sinfo = &empty_sinfo; | |
ec15e68b | 12916 | |
947add36 JB |
12917 | trace_cfg80211_del_sta(dev, mac_addr); |
12918 | ||
58050fce | 12919 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
12920 | if (!msg) |
12921 | return; | |
12922 | ||
cf5ead82 | 12923 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
57007121 | 12924 | rdev, dev, mac_addr, sinfo) < 0) { |
ec15e68b JM |
12925 | nlmsg_free(msg); |
12926 | return; | |
12927 | } | |
12928 | ||
68eb5503 | 12929 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12930 | NL80211_MCGRP_MLME, gfp); |
ec15e68b | 12931 | } |
cf5ead82 | 12932 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
ec15e68b | 12933 | |
947add36 JB |
12934 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
12935 | enum nl80211_connect_failed_reason reason, | |
12936 | gfp_t gfp) | |
ed44a951 | 12937 | { |
947add36 | 12938 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 12939 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
12940 | struct sk_buff *msg; |
12941 | void *hdr; | |
12942 | ||
12943 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
12944 | if (!msg) | |
12945 | return; | |
12946 | ||
12947 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
12948 | if (!hdr) { | |
12949 | nlmsg_free(msg); | |
12950 | return; | |
12951 | } | |
12952 | ||
12953 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12954 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
12955 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
12956 | goto nla_put_failure; | |
12957 | ||
12958 | genlmsg_end(msg, hdr); | |
12959 | ||
68eb5503 | 12960 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12961 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
12962 | return; |
12963 | ||
12964 | nla_put_failure: | |
12965 | genlmsg_cancel(msg, hdr); | |
12966 | nlmsg_free(msg); | |
12967 | } | |
947add36 | 12968 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 12969 | |
b92ab5d8 JB |
12970 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
12971 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
12972 | { |
12973 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12974 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
12975 | struct sk_buff *msg; |
12976 | void *hdr; | |
15e47304 | 12977 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 12978 | |
15e47304 | 12979 | if (!nlportid) |
28946da7 JB |
12980 | return false; |
12981 | ||
12982 | msg = nlmsg_new(100, gfp); | |
12983 | if (!msg) | |
12984 | return true; | |
12985 | ||
b92ab5d8 | 12986 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
12987 | if (!hdr) { |
12988 | nlmsg_free(msg); | |
12989 | return true; | |
12990 | } | |
12991 | ||
9360ffd1 DM |
12992 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12993 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12994 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
12995 | goto nla_put_failure; | |
28946da7 | 12996 | |
9c90a9f6 | 12997 | genlmsg_end(msg, hdr); |
15e47304 | 12998 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
12999 | return true; |
13000 | ||
13001 | nla_put_failure: | |
13002 | genlmsg_cancel(msg, hdr); | |
13003 | nlmsg_free(msg); | |
13004 | return true; | |
13005 | } | |
13006 | ||
947add36 JB |
13007 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
13008 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 13009 | { |
947add36 JB |
13010 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
13011 | bool ret; | |
13012 | ||
13013 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
13014 | ||
13015 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
13016 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
13017 | trace_cfg80211_return_bool(false); | |
13018 | return false; | |
13019 | } | |
13020 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
13021 | addr, gfp); | |
13022 | trace_cfg80211_return_bool(ret); | |
13023 | return ret; | |
b92ab5d8 | 13024 | } |
947add36 | 13025 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 13026 | |
947add36 JB |
13027 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
13028 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 13029 | { |
947add36 JB |
13030 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
13031 | bool ret; | |
13032 | ||
13033 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
13034 | ||
13035 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
13036 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
13037 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
13038 | trace_cfg80211_return_bool(false); | |
13039 | return false; | |
13040 | } | |
13041 | ret = __nl80211_unexpected_frame(dev, | |
13042 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
13043 | addr, gfp); | |
13044 | trace_cfg80211_return_bool(ret); | |
13045 | return ret; | |
b92ab5d8 | 13046 | } |
947add36 | 13047 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 13048 | |
2e161f78 | 13049 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 13050 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 13051 | int freq, int sig_dbm, |
19504cf5 | 13052 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 13053 | { |
71bbc994 | 13054 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
13055 | struct sk_buff *msg; |
13056 | void *hdr; | |
026331c4 JM |
13057 | |
13058 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
13059 | if (!msg) | |
13060 | return -ENOMEM; | |
13061 | ||
2e161f78 | 13062 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
13063 | if (!hdr) { |
13064 | nlmsg_free(msg); | |
13065 | return -ENOMEM; | |
13066 | } | |
13067 | ||
9360ffd1 | 13068 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
13069 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
13070 | netdev->ifindex)) || | |
2dad624e ND |
13071 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
13072 | NL80211_ATTR_PAD) || | |
9360ffd1 DM |
13073 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
13074 | (sig_dbm && | |
13075 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
13076 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
13077 | (flags && | |
13078 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 13079 | goto nla_put_failure; |
026331c4 | 13080 | |
3b7b72ee | 13081 | genlmsg_end(msg, hdr); |
026331c4 | 13082 | |
15e47304 | 13083 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
13084 | |
13085 | nla_put_failure: | |
13086 | genlmsg_cancel(msg, hdr); | |
13087 | nlmsg_free(msg); | |
13088 | return -ENOBUFS; | |
13089 | } | |
13090 | ||
947add36 JB |
13091 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
13092 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 13093 | { |
947add36 | 13094 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 13095 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 13096 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
13097 | struct sk_buff *msg; |
13098 | void *hdr; | |
13099 | ||
947add36 JB |
13100 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
13101 | ||
026331c4 JM |
13102 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
13103 | if (!msg) | |
13104 | return; | |
13105 | ||
2e161f78 | 13106 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
13107 | if (!hdr) { |
13108 | nlmsg_free(msg); | |
13109 | return; | |
13110 | } | |
13111 | ||
9360ffd1 | 13112 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
13113 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
13114 | netdev->ifindex)) || | |
2dad624e ND |
13115 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
13116 | NL80211_ATTR_PAD) || | |
9360ffd1 | 13117 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
2dad624e ND |
13118 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
13119 | NL80211_ATTR_PAD) || | |
9360ffd1 DM |
13120 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
13121 | goto nla_put_failure; | |
026331c4 | 13122 | |
3b7b72ee | 13123 | genlmsg_end(msg, hdr); |
026331c4 | 13124 | |
68eb5503 | 13125 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13126 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
13127 | return; |
13128 | ||
13129 | nla_put_failure: | |
13130 | genlmsg_cancel(msg, hdr); | |
13131 | nlmsg_free(msg); | |
13132 | } | |
947add36 | 13133 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 13134 | |
5b97f49d JB |
13135 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
13136 | const char *mac, gfp_t gfp) | |
d6dc1a38 | 13137 | { |
947add36 | 13138 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5b97f49d JB |
13139 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
13140 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
13141 | void **cb; | |
947add36 | 13142 | |
d6dc1a38 | 13143 | if (!msg) |
5b97f49d | 13144 | return NULL; |
d6dc1a38 | 13145 | |
5b97f49d JB |
13146 | cb = (void **)msg->cb; |
13147 | ||
13148 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
13149 | if (!cb[0]) { | |
d6dc1a38 | 13150 | nlmsg_free(msg); |
5b97f49d | 13151 | return NULL; |
d6dc1a38 JO |
13152 | } |
13153 | ||
9360ffd1 | 13154 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 13155 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 13156 | goto nla_put_failure; |
d6dc1a38 | 13157 | |
5b97f49d | 13158 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
d6dc1a38 JO |
13159 | goto nla_put_failure; |
13160 | ||
5b97f49d JB |
13161 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
13162 | if (!cb[1]) | |
9360ffd1 | 13163 | goto nla_put_failure; |
d6dc1a38 | 13164 | |
5b97f49d | 13165 | cb[2] = rdev; |
d6dc1a38 | 13166 | |
5b97f49d JB |
13167 | return msg; |
13168 | nla_put_failure: | |
13169 | nlmsg_free(msg); | |
13170 | return NULL; | |
13171 | } | |
13172 | ||
13173 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) | |
13174 | { | |
13175 | void **cb = (void **)msg->cb; | |
13176 | struct cfg80211_registered_device *rdev = cb[2]; | |
13177 | ||
13178 | nla_nest_end(msg, cb[1]); | |
13179 | genlmsg_end(msg, cb[0]); | |
13180 | ||
13181 | memset(msg->cb, 0, sizeof(msg->cb)); | |
d6dc1a38 | 13182 | |
68eb5503 | 13183 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13184 | NL80211_MCGRP_MLME, gfp); |
5b97f49d JB |
13185 | } |
13186 | ||
13187 | void cfg80211_cqm_rssi_notify(struct net_device *dev, | |
13188 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
13189 | gfp_t gfp) | |
13190 | { | |
13191 | struct sk_buff *msg; | |
13192 | ||
13193 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); | |
13194 | ||
98f03342 JB |
13195 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
13196 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) | |
13197 | return; | |
13198 | ||
5b97f49d JB |
13199 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
13200 | if (!msg) | |
13201 | return; | |
13202 | ||
13203 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
13204 | rssi_event)) | |
13205 | goto nla_put_failure; | |
13206 | ||
13207 | cfg80211_send_cqm(msg, gfp); | |
13208 | ||
d6dc1a38 JO |
13209 | return; |
13210 | ||
13211 | nla_put_failure: | |
d6dc1a38 JO |
13212 | nlmsg_free(msg); |
13213 | } | |
947add36 | 13214 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 13215 | |
5b97f49d JB |
13216 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
13217 | const u8 *peer, u32 num_packets, | |
13218 | u32 rate, u32 intvl, gfp_t gfp) | |
13219 | { | |
13220 | struct sk_buff *msg; | |
13221 | ||
13222 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
13223 | if (!msg) | |
13224 | return; | |
13225 | ||
13226 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
13227 | goto nla_put_failure; | |
13228 | ||
13229 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
13230 | goto nla_put_failure; | |
13231 | ||
13232 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
13233 | goto nla_put_failure; | |
13234 | ||
13235 | cfg80211_send_cqm(msg, gfp); | |
13236 | return; | |
13237 | ||
13238 | nla_put_failure: | |
13239 | nlmsg_free(msg); | |
13240 | } | |
13241 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); | |
13242 | ||
13243 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, | |
13244 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
13245 | { | |
13246 | struct sk_buff *msg; | |
13247 | ||
13248 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); | |
13249 | ||
13250 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
13251 | if (!msg) | |
13252 | return; | |
13253 | ||
13254 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) | |
13255 | goto nla_put_failure; | |
13256 | ||
13257 | cfg80211_send_cqm(msg, gfp); | |
13258 | return; | |
13259 | ||
13260 | nla_put_failure: | |
13261 | nlmsg_free(msg); | |
13262 | } | |
13263 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); | |
13264 | ||
98f03342 JB |
13265 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
13266 | { | |
13267 | struct sk_buff *msg; | |
13268 | ||
13269 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); | |
13270 | if (!msg) | |
13271 | return; | |
13272 | ||
13273 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) | |
13274 | goto nla_put_failure; | |
13275 | ||
13276 | cfg80211_send_cqm(msg, gfp); | |
13277 | return; | |
13278 | ||
13279 | nla_put_failure: | |
13280 | nlmsg_free(msg); | |
13281 | } | |
13282 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); | |
13283 | ||
947add36 JB |
13284 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
13285 | struct net_device *netdev, const u8 *bssid, | |
13286 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
13287 | { |
13288 | struct sk_buff *msg; | |
13289 | struct nlattr *rekey_attr; | |
13290 | void *hdr; | |
13291 | ||
58050fce | 13292 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
13293 | if (!msg) |
13294 | return; | |
13295 | ||
13296 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
13297 | if (!hdr) { | |
13298 | nlmsg_free(msg); | |
13299 | return; | |
13300 | } | |
13301 | ||
9360ffd1 DM |
13302 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13303 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13304 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
13305 | goto nla_put_failure; | |
e5497d76 JB |
13306 | |
13307 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
13308 | if (!rekey_attr) | |
13309 | goto nla_put_failure; | |
13310 | ||
9360ffd1 DM |
13311 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
13312 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
13313 | goto nla_put_failure; | |
e5497d76 JB |
13314 | |
13315 | nla_nest_end(msg, rekey_attr); | |
13316 | ||
3b7b72ee | 13317 | genlmsg_end(msg, hdr); |
e5497d76 | 13318 | |
68eb5503 | 13319 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13320 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
13321 | return; |
13322 | ||
13323 | nla_put_failure: | |
13324 | genlmsg_cancel(msg, hdr); | |
13325 | nlmsg_free(msg); | |
13326 | } | |
13327 | ||
947add36 JB |
13328 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
13329 | const u8 *replay_ctr, gfp_t gfp) | |
13330 | { | |
13331 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13332 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 13333 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
13334 | |
13335 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
13336 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
13337 | } | |
13338 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
13339 | ||
13340 | static void | |
13341 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
13342 | struct net_device *netdev, int index, | |
13343 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
13344 | { |
13345 | struct sk_buff *msg; | |
13346 | struct nlattr *attr; | |
13347 | void *hdr; | |
13348 | ||
58050fce | 13349 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
13350 | if (!msg) |
13351 | return; | |
13352 | ||
13353 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
13354 | if (!hdr) { | |
13355 | nlmsg_free(msg); | |
13356 | return; | |
13357 | } | |
13358 | ||
9360ffd1 DM |
13359 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13360 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
13361 | goto nla_put_failure; | |
c9df56b4 JM |
13362 | |
13363 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
13364 | if (!attr) | |
13365 | goto nla_put_failure; | |
13366 | ||
9360ffd1 DM |
13367 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
13368 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
13369 | (preauth && | |
13370 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
13371 | goto nla_put_failure; | |
c9df56b4 JM |
13372 | |
13373 | nla_nest_end(msg, attr); | |
13374 | ||
3b7b72ee | 13375 | genlmsg_end(msg, hdr); |
c9df56b4 | 13376 | |
68eb5503 | 13377 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13378 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
13379 | return; |
13380 | ||
13381 | nla_put_failure: | |
13382 | genlmsg_cancel(msg, hdr); | |
13383 | nlmsg_free(msg); | |
13384 | } | |
13385 | ||
947add36 JB |
13386 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
13387 | const u8 *bssid, bool preauth, gfp_t gfp) | |
13388 | { | |
13389 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13390 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 13391 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
13392 | |
13393 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
13394 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
13395 | } | |
13396 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
13397 | ||
13398 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
13399 | struct net_device *netdev, | |
13400 | struct cfg80211_chan_def *chandef, | |
f8d7552e LC |
13401 | gfp_t gfp, |
13402 | enum nl80211_commands notif, | |
13403 | u8 count) | |
5314526b TP |
13404 | { |
13405 | struct sk_buff *msg; | |
13406 | void *hdr; | |
13407 | ||
58050fce | 13408 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
13409 | if (!msg) |
13410 | return; | |
13411 | ||
f8d7552e | 13412 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
5314526b TP |
13413 | if (!hdr) { |
13414 | nlmsg_free(msg); | |
13415 | return; | |
13416 | } | |
13417 | ||
683b6d3b JB |
13418 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
13419 | goto nla_put_failure; | |
13420 | ||
13421 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 13422 | goto nla_put_failure; |
5314526b | 13423 | |
f8d7552e LC |
13424 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
13425 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) | |
13426 | goto nla_put_failure; | |
13427 | ||
5314526b TP |
13428 | genlmsg_end(msg, hdr); |
13429 | ||
68eb5503 | 13430 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13431 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
13432 | return; |
13433 | ||
13434 | nla_put_failure: | |
13435 | genlmsg_cancel(msg, hdr); | |
13436 | nlmsg_free(msg); | |
13437 | } | |
13438 | ||
947add36 JB |
13439 | void cfg80211_ch_switch_notify(struct net_device *dev, |
13440 | struct cfg80211_chan_def *chandef) | |
84f10708 | 13441 | { |
947add36 JB |
13442 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
13443 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 13444 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 13445 | |
e487eaeb | 13446 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 13447 | |
e487eaeb | 13448 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 | 13449 | |
9e0e2961 | 13450 | wdev->chandef = *chandef; |
96f55f12 | 13451 | wdev->preset_chandef = *chandef; |
f8d7552e LC |
13452 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
13453 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); | |
947add36 JB |
13454 | } |
13455 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
13456 | ||
f8d7552e LC |
13457 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
13458 | struct cfg80211_chan_def *chandef, | |
13459 | u8 count) | |
13460 | { | |
13461 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13462 | struct wiphy *wiphy = wdev->wiphy; | |
13463 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
13464 | ||
13465 | trace_cfg80211_ch_switch_started_notify(dev, chandef); | |
13466 | ||
13467 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | |
13468 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); | |
13469 | } | |
13470 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | |
13471 | ||
04f39047 SW |
13472 | void |
13473 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 13474 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
13475 | enum nl80211_radar_event event, |
13476 | struct net_device *netdev, gfp_t gfp) | |
13477 | { | |
13478 | struct sk_buff *msg; | |
13479 | void *hdr; | |
13480 | ||
13481 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
13482 | if (!msg) | |
13483 | return; | |
13484 | ||
13485 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
13486 | if (!hdr) { | |
13487 | nlmsg_free(msg); | |
13488 | return; | |
13489 | } | |
13490 | ||
13491 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
13492 | goto nla_put_failure; | |
13493 | ||
13494 | /* NOP and radar events don't need a netdev parameter */ | |
13495 | if (netdev) { | |
13496 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
13497 | ||
13498 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
2dad624e ND |
13499 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
13500 | NL80211_ATTR_PAD)) | |
04f39047 SW |
13501 | goto nla_put_failure; |
13502 | } | |
13503 | ||
13504 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
13505 | goto nla_put_failure; | |
13506 | ||
13507 | if (nl80211_send_chandef(msg, chandef)) | |
13508 | goto nla_put_failure; | |
13509 | ||
9c90a9f6 | 13510 | genlmsg_end(msg, hdr); |
04f39047 | 13511 | |
68eb5503 | 13512 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13513 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
13514 | return; |
13515 | ||
13516 | nla_put_failure: | |
13517 | genlmsg_cancel(msg, hdr); | |
13518 | nlmsg_free(msg); | |
13519 | } | |
13520 | ||
7f6cf311 JB |
13521 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
13522 | u64 cookie, bool acked, gfp_t gfp) | |
13523 | { | |
13524 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 13525 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
13526 | struct sk_buff *msg; |
13527 | void *hdr; | |
7f6cf311 | 13528 | |
4ee3e063 BL |
13529 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
13530 | ||
58050fce | 13531 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 13532 | |
7f6cf311 JB |
13533 | if (!msg) |
13534 | return; | |
13535 | ||
13536 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
13537 | if (!hdr) { | |
13538 | nlmsg_free(msg); | |
13539 | return; | |
13540 | } | |
13541 | ||
9360ffd1 DM |
13542 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13543 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
13544 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
2dad624e ND |
13545 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
13546 | NL80211_ATTR_PAD) || | |
9360ffd1 DM |
13547 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
13548 | goto nla_put_failure; | |
7f6cf311 | 13549 | |
9c90a9f6 | 13550 | genlmsg_end(msg, hdr); |
7f6cf311 | 13551 | |
68eb5503 | 13552 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13553 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
13554 | return; |
13555 | ||
13556 | nla_put_failure: | |
13557 | genlmsg_cancel(msg, hdr); | |
13558 | nlmsg_free(msg); | |
13559 | } | |
13560 | EXPORT_SYMBOL(cfg80211_probe_status); | |
13561 | ||
5e760230 JB |
13562 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
13563 | const u8 *frame, size_t len, | |
37c73b5f | 13564 | int freq, int sig_dbm) |
5e760230 | 13565 | { |
f26cbf40 | 13566 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
13567 | struct sk_buff *msg; |
13568 | void *hdr; | |
37c73b5f | 13569 | struct cfg80211_beacon_registration *reg; |
5e760230 | 13570 | |
4ee3e063 BL |
13571 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
13572 | ||
37c73b5f BG |
13573 | spin_lock_bh(&rdev->beacon_registrations_lock); |
13574 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
13575 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
13576 | if (!msg) { | |
13577 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
13578 | return; | |
13579 | } | |
5e760230 | 13580 | |
37c73b5f BG |
13581 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
13582 | if (!hdr) | |
13583 | goto nla_put_failure; | |
5e760230 | 13584 | |
37c73b5f BG |
13585 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13586 | (freq && | |
13587 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
13588 | (sig_dbm && | |
13589 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
13590 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
13591 | goto nla_put_failure; | |
5e760230 | 13592 | |
37c73b5f | 13593 | genlmsg_end(msg, hdr); |
5e760230 | 13594 | |
37c73b5f BG |
13595 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
13596 | } | |
13597 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
13598 | return; |
13599 | ||
13600 | nla_put_failure: | |
37c73b5f BG |
13601 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
13602 | if (hdr) | |
13603 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
13604 | nlmsg_free(msg); |
13605 | } | |
13606 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
13607 | ||
cd8f7cb4 | 13608 | #ifdef CONFIG_PM |
8cd4d456 LC |
13609 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
13610 | struct cfg80211_wowlan_wakeup *wakeup) | |
13611 | { | |
13612 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | |
13613 | struct nlattr *nl_results, *nl_match, *nl_freqs; | |
13614 | int i, j; | |
13615 | ||
13616 | nl_results = nla_nest_start( | |
13617 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | |
13618 | if (!nl_results) | |
13619 | return -EMSGSIZE; | |
13620 | ||
13621 | for (i = 0; i < nd->n_matches; i++) { | |
13622 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | |
13623 | ||
13624 | nl_match = nla_nest_start(msg, i); | |
13625 | if (!nl_match) | |
13626 | break; | |
13627 | ||
13628 | /* The SSID attribute is optional in nl80211, but for | |
13629 | * simplicity reasons it's always present in the | |
13630 | * cfg80211 structure. If a driver can't pass the | |
13631 | * SSID, that needs to be changed. A zero length SSID | |
13632 | * is still a valid SSID (wildcard), so it cannot be | |
13633 | * used for this purpose. | |
13634 | */ | |
13635 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | |
13636 | match->ssid.ssid)) { | |
13637 | nla_nest_cancel(msg, nl_match); | |
13638 | goto out; | |
13639 | } | |
13640 | ||
13641 | if (match->n_channels) { | |
13642 | nl_freqs = nla_nest_start( | |
13643 | msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
13644 | if (!nl_freqs) { | |
13645 | nla_nest_cancel(msg, nl_match); | |
13646 | goto out; | |
13647 | } | |
13648 | ||
13649 | for (j = 0; j < match->n_channels; j++) { | |
5528fae8 | 13650 | if (nla_put_u32(msg, j, match->channels[j])) { |
8cd4d456 LC |
13651 | nla_nest_cancel(msg, nl_freqs); |
13652 | nla_nest_cancel(msg, nl_match); | |
13653 | goto out; | |
13654 | } | |
13655 | } | |
13656 | ||
13657 | nla_nest_end(msg, nl_freqs); | |
13658 | } | |
13659 | ||
13660 | nla_nest_end(msg, nl_match); | |
13661 | } | |
13662 | ||
13663 | out: | |
13664 | nla_nest_end(msg, nl_results); | |
13665 | return 0; | |
13666 | } | |
13667 | ||
cd8f7cb4 JB |
13668 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
13669 | struct cfg80211_wowlan_wakeup *wakeup, | |
13670 | gfp_t gfp) | |
13671 | { | |
f26cbf40 | 13672 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
13673 | struct sk_buff *msg; |
13674 | void *hdr; | |
9c90a9f6 | 13675 | int size = 200; |
cd8f7cb4 JB |
13676 | |
13677 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
13678 | ||
13679 | if (wakeup) | |
13680 | size += wakeup->packet_present_len; | |
13681 | ||
13682 | msg = nlmsg_new(size, gfp); | |
13683 | if (!msg) | |
13684 | return; | |
13685 | ||
13686 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
13687 | if (!hdr) | |
13688 | goto free_msg; | |
13689 | ||
13690 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
13691 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
13692 | NL80211_ATTR_PAD)) | |
cd8f7cb4 JB |
13693 | goto free_msg; |
13694 | ||
13695 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
13696 | wdev->netdev->ifindex)) | |
13697 | goto free_msg; | |
13698 | ||
13699 | if (wakeup) { | |
13700 | struct nlattr *reasons; | |
13701 | ||
13702 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
13703 | if (!reasons) |
13704 | goto free_msg; | |
cd8f7cb4 JB |
13705 | |
13706 | if (wakeup->disconnect && | |
13707 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
13708 | goto free_msg; | |
13709 | if (wakeup->magic_pkt && | |
13710 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
13711 | goto free_msg; | |
13712 | if (wakeup->gtk_rekey_failure && | |
13713 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
13714 | goto free_msg; | |
13715 | if (wakeup->eap_identity_req && | |
13716 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
13717 | goto free_msg; | |
13718 | if (wakeup->four_way_handshake && | |
13719 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
13720 | goto free_msg; | |
13721 | if (wakeup->rfkill_release && | |
13722 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
13723 | goto free_msg; | |
13724 | ||
13725 | if (wakeup->pattern_idx >= 0 && | |
13726 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
13727 | wakeup->pattern_idx)) | |
13728 | goto free_msg; | |
13729 | ||
ae917c9f JB |
13730 | if (wakeup->tcp_match && |
13731 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
13732 | goto free_msg; | |
2a0e047e | 13733 | |
ae917c9f JB |
13734 | if (wakeup->tcp_connlost && |
13735 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
13736 | goto free_msg; | |
2a0e047e | 13737 | |
ae917c9f JB |
13738 | if (wakeup->tcp_nomoretokens && |
13739 | nla_put_flag(msg, | |
13740 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
13741 | goto free_msg; | |
2a0e047e | 13742 | |
cd8f7cb4 JB |
13743 | if (wakeup->packet) { |
13744 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
13745 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
13746 | ||
13747 | if (!wakeup->packet_80211) { | |
13748 | pkt_attr = | |
13749 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
13750 | len_attr = | |
13751 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
13752 | } | |
13753 | ||
13754 | if (wakeup->packet_len && | |
13755 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
13756 | goto free_msg; | |
13757 | ||
13758 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
13759 | wakeup->packet)) | |
13760 | goto free_msg; | |
13761 | } | |
13762 | ||
8cd4d456 LC |
13763 | if (wakeup->net_detect && |
13764 | cfg80211_net_detect_results(msg, wakeup)) | |
13765 | goto free_msg; | |
13766 | ||
cd8f7cb4 JB |
13767 | nla_nest_end(msg, reasons); |
13768 | } | |
13769 | ||
9c90a9f6 | 13770 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 13771 | |
68eb5503 | 13772 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13773 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
13774 | return; |
13775 | ||
13776 | free_msg: | |
13777 | nlmsg_free(msg); | |
13778 | } | |
13779 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
13780 | #endif | |
13781 | ||
3475b094 JM |
13782 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
13783 | enum nl80211_tdls_operation oper, | |
13784 | u16 reason_code, gfp_t gfp) | |
13785 | { | |
13786 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 13787 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
13788 | struct sk_buff *msg; |
13789 | void *hdr; | |
3475b094 JM |
13790 | |
13791 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
13792 | reason_code); | |
13793 | ||
13794 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
13795 | if (!msg) | |
13796 | return; | |
13797 | ||
13798 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
13799 | if (!hdr) { | |
13800 | nlmsg_free(msg); | |
13801 | return; | |
13802 | } | |
13803 | ||
13804 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
13805 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
13806 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
13807 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
13808 | (reason_code > 0 && | |
13809 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
13810 | goto nla_put_failure; | |
13811 | ||
9c90a9f6 | 13812 | genlmsg_end(msg, hdr); |
3475b094 | 13813 | |
68eb5503 | 13814 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13815 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
13816 | return; |
13817 | ||
13818 | nla_put_failure: | |
13819 | genlmsg_cancel(msg, hdr); | |
13820 | nlmsg_free(msg); | |
13821 | } | |
13822 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
13823 | ||
026331c4 JM |
13824 | static int nl80211_netlink_notify(struct notifier_block * nb, |
13825 | unsigned long state, | |
13826 | void *_notify) | |
13827 | { | |
13828 | struct netlink_notify *notify = _notify; | |
13829 | struct cfg80211_registered_device *rdev; | |
13830 | struct wireless_dev *wdev; | |
37c73b5f | 13831 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 | 13832 | |
8f815cdd | 13833 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
026331c4 JM |
13834 | return NOTIFY_DONE; |
13835 | ||
13836 | rcu_read_lock(); | |
13837 | ||
5e760230 | 13838 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
78f22b6a | 13839 | bool schedule_destroy_work = false; |
93a1e86c JR |
13840 | bool schedule_scan_stop = false; |
13841 | struct cfg80211_sched_scan_request *sched_scan_req = | |
13842 | rcu_dereference(rdev->sched_scan_req); | |
13843 | ||
13844 | if (sched_scan_req && notify->portid && | |
13845 | sched_scan_req->owner_nlportid == notify->portid) | |
13846 | schedule_scan_stop = true; | |
78f22b6a | 13847 | |
53873f13 | 13848 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
15e47304 | 13849 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 13850 | |
78f22b6a JB |
13851 | if (wdev->owner_nlportid == notify->portid) |
13852 | schedule_destroy_work = true; | |
13853 | } | |
13854 | ||
37c73b5f BG |
13855 | spin_lock_bh(&rdev->beacon_registrations_lock); |
13856 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
13857 | list) { | |
13858 | if (reg->nlportid == notify->portid) { | |
13859 | list_del(®->list); | |
13860 | kfree(reg); | |
13861 | break; | |
13862 | } | |
13863 | } | |
13864 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
78f22b6a JB |
13865 | |
13866 | if (schedule_destroy_work) { | |
13867 | struct cfg80211_iface_destroy *destroy; | |
13868 | ||
13869 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | |
13870 | if (destroy) { | |
13871 | destroy->nlportid = notify->portid; | |
13872 | spin_lock(&rdev->destroy_list_lock); | |
13873 | list_add(&destroy->list, &rdev->destroy_list); | |
13874 | spin_unlock(&rdev->destroy_list_lock); | |
13875 | schedule_work(&rdev->destroy_work); | |
13876 | } | |
93a1e86c JR |
13877 | } else if (schedule_scan_stop) { |
13878 | sched_scan_req->owner_nlportid = 0; | |
13879 | ||
13880 | if (rdev->ops->sched_scan_stop && | |
13881 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
13882 | schedule_work(&rdev->sched_scan_stop_wk); | |
78f22b6a | 13883 | } |
5e760230 | 13884 | } |
026331c4 JM |
13885 | |
13886 | rcu_read_unlock(); | |
13887 | ||
05050753 I |
13888 | /* |
13889 | * It is possible that the user space process that is controlling the | |
13890 | * indoor setting disappeared, so notify the regulatory core. | |
13891 | */ | |
13892 | regulatory_netlink_notify(notify->portid); | |
6784c7db | 13893 | return NOTIFY_OK; |
026331c4 JM |
13894 | } |
13895 | ||
13896 | static struct notifier_block nl80211_netlink_notifier = { | |
13897 | .notifier_call = nl80211_netlink_notify, | |
13898 | }; | |
13899 | ||
355199e0 JM |
13900 | void cfg80211_ft_event(struct net_device *netdev, |
13901 | struct cfg80211_ft_event_params *ft_event) | |
13902 | { | |
13903 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 13904 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
13905 | struct sk_buff *msg; |
13906 | void *hdr; | |
355199e0 JM |
13907 | |
13908 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
13909 | ||
13910 | if (!ft_event->target_ap) | |
13911 | return; | |
13912 | ||
13913 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
13914 | if (!msg) | |
13915 | return; | |
13916 | ||
13917 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
13918 | if (!hdr) |
13919 | goto out; | |
355199e0 | 13920 | |
ae917c9f JB |
13921 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13922 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13923 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
13924 | goto out; | |
355199e0 | 13925 | |
ae917c9f JB |
13926 | if (ft_event->ies && |
13927 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
13928 | goto out; | |
13929 | if (ft_event->ric_ies && | |
13930 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
13931 | ft_event->ric_ies)) | |
13932 | goto out; | |
355199e0 | 13933 | |
9c90a9f6 | 13934 | genlmsg_end(msg, hdr); |
355199e0 | 13935 | |
68eb5503 | 13936 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13937 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
13938 | return; |
13939 | out: | |
13940 | nlmsg_free(msg); | |
355199e0 JM |
13941 | } |
13942 | EXPORT_SYMBOL(cfg80211_ft_event); | |
13943 | ||
5de17984 AS |
13944 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
13945 | { | |
13946 | struct cfg80211_registered_device *rdev; | |
13947 | struct sk_buff *msg; | |
13948 | void *hdr; | |
13949 | u32 nlportid; | |
13950 | ||
f26cbf40 | 13951 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
13952 | if (!rdev->crit_proto_nlportid) |
13953 | return; | |
13954 | ||
13955 | nlportid = rdev->crit_proto_nlportid; | |
13956 | rdev->crit_proto_nlportid = 0; | |
13957 | ||
13958 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
13959 | if (!msg) | |
13960 | return; | |
13961 | ||
13962 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
13963 | if (!hdr) | |
13964 | goto nla_put_failure; | |
13965 | ||
13966 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
13967 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
13968 | NL80211_ATTR_PAD)) | |
5de17984 AS |
13969 | goto nla_put_failure; |
13970 | ||
13971 | genlmsg_end(msg, hdr); | |
13972 | ||
13973 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
13974 | return; | |
13975 | ||
13976 | nla_put_failure: | |
13977 | if (hdr) | |
13978 | genlmsg_cancel(msg, hdr); | |
13979 | nlmsg_free(msg); | |
5de17984 AS |
13980 | } |
13981 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
13982 | ||
348baf0e JB |
13983 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
13984 | { | |
13985 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 13986 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
13987 | struct sk_buff *msg; |
13988 | void *hdr; | |
13989 | ||
13990 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
13991 | if (!msg) | |
13992 | return; | |
13993 | ||
13994 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
13995 | if (!hdr) | |
13996 | goto out; | |
13997 | ||
13998 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
13999 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
2dad624e ND |
14000 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
14001 | NL80211_ATTR_PAD)) | |
348baf0e JB |
14002 | goto out; |
14003 | ||
14004 | genlmsg_end(msg, hdr); | |
14005 | ||
14006 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
14007 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
14008 | return; | |
14009 | out: | |
14010 | nlmsg_free(msg); | |
14011 | } | |
14012 | ||
55682965 JB |
14013 | /* initialisation/exit functions */ |
14014 | ||
14015 | int nl80211_init(void) | |
14016 | { | |
0d63cbb5 | 14017 | int err; |
55682965 | 14018 | |
2a94fe48 JB |
14019 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
14020 | nl80211_mcgrps); | |
55682965 JB |
14021 | if (err) |
14022 | return err; | |
14023 | ||
026331c4 JM |
14024 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
14025 | if (err) | |
14026 | goto err_out; | |
14027 | ||
55682965 JB |
14028 | return 0; |
14029 | err_out: | |
14030 | genl_unregister_family(&nl80211_fam); | |
14031 | return err; | |
14032 | } | |
14033 | ||
14034 | void nl80211_exit(void) | |
14035 | { | |
026331c4 | 14036 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
14037 | genl_unregister_family(&nl80211_fam); |
14038 | } |