]>
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 }, | |
55682965 JB |
412 | }; |
413 | ||
e31b8213 | 414 | /* policy for the key attributes */ |
b54452b0 | 415 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 416 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
417 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
418 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 419 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
420 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
421 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 422 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
423 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
424 | }; | |
425 | ||
426 | /* policy for the key default flags */ | |
427 | static const struct nla_policy | |
428 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
429 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
430 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
431 | }; |
432 | ||
ff1b6e69 JB |
433 | /* policy for WoWLAN attributes */ |
434 | static const struct nla_policy | |
435 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
436 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
437 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
438 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
439 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
440 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
441 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
442 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
443 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e | 444 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
8cd4d456 | 445 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
2a0e047e JB |
446 | }; |
447 | ||
448 | static const struct nla_policy | |
449 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
450 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
451 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
452 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
453 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
454 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
455 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
456 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
457 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
458 | }, | |
459 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
460 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
461 | }, | |
462 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
463 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
464 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
465 | }; |
466 | ||
be29b99a AK |
467 | /* policy for coalesce rule attributes */ |
468 | static const struct nla_policy | |
469 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
470 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
471 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
472 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
473 | }; | |
474 | ||
e5497d76 JB |
475 | /* policy for GTK rekey offload attributes */ |
476 | static const struct nla_policy | |
477 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
478 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
479 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
480 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
481 | }; | |
482 | ||
a1f1c21c LC |
483 | static const struct nla_policy |
484 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 485 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 486 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 487 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
488 | }; |
489 | ||
3b06d277 AS |
490 | static const struct nla_policy |
491 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { | |
492 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, | |
493 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, | |
494 | }; | |
495 | ||
38de03d2 AS |
496 | static const struct nla_policy |
497 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { | |
498 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, | |
499 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, | |
500 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { | |
501 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) | |
502 | }, | |
503 | }; | |
504 | ||
97990a06 JB |
505 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
506 | struct netlink_callback *cb, | |
507 | struct cfg80211_registered_device **rdev, | |
508 | struct wireless_dev **wdev) | |
a043897a | 509 | { |
97990a06 | 510 | int err; |
a043897a | 511 | |
97990a06 | 512 | rtnl_lock(); |
a043897a | 513 | |
97990a06 JB |
514 | if (!cb->args[0]) { |
515 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
516 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
517 | nl80211_policy); | |
518 | if (err) | |
519 | goto out_unlock; | |
67748893 | 520 | |
97990a06 JB |
521 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
522 | nl80211_fam.attrbuf); | |
523 | if (IS_ERR(*wdev)) { | |
524 | err = PTR_ERR(*wdev); | |
525 | goto out_unlock; | |
526 | } | |
f26cbf40 | 527 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
528 | /* 0 is the first index - add 1 to parse only once */ |
529 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
530 | cb->args[1] = (*wdev)->identifier; |
531 | } else { | |
c319d50b JB |
532 | /* subtract the 1 again here */ |
533 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 534 | struct wireless_dev *tmp; |
67748893 | 535 | |
97990a06 JB |
536 | if (!wiphy) { |
537 | err = -ENODEV; | |
538 | goto out_unlock; | |
539 | } | |
f26cbf40 | 540 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 541 | *wdev = NULL; |
67748893 | 542 | |
53873f13 | 543 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
97990a06 JB |
544 | if (tmp->identifier == cb->args[1]) { |
545 | *wdev = tmp; | |
546 | break; | |
547 | } | |
548 | } | |
67748893 | 549 | |
97990a06 JB |
550 | if (!*wdev) { |
551 | err = -ENODEV; | |
552 | goto out_unlock; | |
553 | } | |
67748893 JB |
554 | } |
555 | ||
67748893 | 556 | return 0; |
97990a06 | 557 | out_unlock: |
67748893 JB |
558 | rtnl_unlock(); |
559 | return err; | |
560 | } | |
561 | ||
97990a06 | 562 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 563 | { |
67748893 JB |
564 | rtnl_unlock(); |
565 | } | |
566 | ||
f4a11bb0 JB |
567 | /* IE validation */ |
568 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
569 | { | |
570 | const u8 *pos; | |
571 | int len; | |
572 | ||
573 | if (!attr) | |
574 | return true; | |
575 | ||
576 | pos = nla_data(attr); | |
577 | len = nla_len(attr); | |
578 | ||
579 | while (len) { | |
580 | u8 elemlen; | |
581 | ||
582 | if (len < 2) | |
583 | return false; | |
584 | len -= 2; | |
585 | ||
586 | elemlen = pos[1]; | |
587 | if (elemlen > len) | |
588 | return false; | |
589 | ||
590 | len -= elemlen; | |
591 | pos += 2 + elemlen; | |
592 | } | |
593 | ||
594 | return true; | |
595 | } | |
596 | ||
55682965 | 597 | /* message building helper */ |
15e47304 | 598 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
599 | int flags, u8 cmd) |
600 | { | |
601 | /* since there is no private header just add the generic one */ | |
15e47304 | 602 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
603 | } |
604 | ||
5dab3b8a | 605 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
606 | struct ieee80211_channel *chan, |
607 | bool large) | |
5dab3b8a | 608 | { |
ea077c1c RL |
609 | /* Some channels must be completely excluded from the |
610 | * list to protect old user-space tools from breaking | |
611 | */ | |
612 | if (!large && chan->flags & | |
613 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
614 | return 0; | |
615 | ||
9360ffd1 DM |
616 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
617 | chan->center_freq)) | |
618 | goto nla_put_failure; | |
5dab3b8a | 619 | |
9360ffd1 DM |
620 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
621 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
622 | goto nla_put_failure; | |
8fe02e16 LR |
623 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
624 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
625 | goto nla_put_failure; | |
626 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
627 | goto nla_put_failure; | |
628 | } | |
cdc89b97 JB |
629 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
630 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
631 | goto nla_put_failure; | |
632 | if (large) { | |
633 | u32 time; | |
634 | ||
635 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
636 | ||
637 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
638 | chan->dfs_state)) | |
639 | goto nla_put_failure; | |
640 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
641 | time)) | |
642 | goto nla_put_failure; | |
089027e5 JD |
643 | if (nla_put_u32(msg, |
644 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
645 | chan->dfs_cac_ms)) | |
646 | goto nla_put_failure; | |
cdc89b97 JB |
647 | } |
648 | } | |
5dab3b8a | 649 | |
fe1abafd JB |
650 | if (large) { |
651 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
652 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
653 | goto nla_put_failure; | |
654 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
655 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
656 | goto nla_put_failure; | |
657 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
658 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
659 | goto nla_put_failure; | |
660 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
661 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
662 | goto nla_put_failure; | |
570dbde1 DS |
663 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
664 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
665 | goto nla_put_failure; | |
06f207fc AN |
666 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
667 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) | |
570dbde1 | 668 | goto nla_put_failure; |
ea077c1c RL |
669 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
670 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
671 | goto nla_put_failure; | |
672 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
673 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
674 | goto nla_put_failure; | |
fe1abafd JB |
675 | } |
676 | ||
9360ffd1 DM |
677 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
678 | DBM_TO_MBM(chan->max_power))) | |
679 | goto nla_put_failure; | |
5dab3b8a LR |
680 | |
681 | return 0; | |
682 | ||
683 | nla_put_failure: | |
684 | return -ENOBUFS; | |
685 | } | |
686 | ||
55682965 JB |
687 | /* netlink command implementations */ |
688 | ||
b9454e83 JB |
689 | struct key_parse { |
690 | struct key_params p; | |
691 | int idx; | |
e31b8213 | 692 | int type; |
b9454e83 | 693 | bool def, defmgmt; |
dbd2fd65 | 694 | bool def_uni, def_multi; |
b9454e83 JB |
695 | }; |
696 | ||
697 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
698 | { | |
699 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
700 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
701 | nl80211_key_policy); | |
702 | if (err) | |
703 | return err; | |
704 | ||
705 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
706 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
707 | ||
dbd2fd65 JB |
708 | if (k->def) { |
709 | k->def_uni = true; | |
710 | k->def_multi = true; | |
711 | } | |
712 | if (k->defmgmt) | |
713 | k->def_multi = true; | |
714 | ||
b9454e83 JB |
715 | if (tb[NL80211_KEY_IDX]) |
716 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
717 | ||
718 | if (tb[NL80211_KEY_DATA]) { | |
719 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
720 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
721 | } | |
722 | ||
723 | if (tb[NL80211_KEY_SEQ]) { | |
724 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
725 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
726 | } | |
727 | ||
728 | if (tb[NL80211_KEY_CIPHER]) | |
729 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
730 | ||
e31b8213 JB |
731 | if (tb[NL80211_KEY_TYPE]) { |
732 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
733 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
734 | return -EINVAL; | |
735 | } | |
736 | ||
dbd2fd65 JB |
737 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
738 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
7a087e74 | 739 | |
2da8f419 JB |
740 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
741 | tb[NL80211_KEY_DEFAULT_TYPES], | |
742 | nl80211_key_default_policy); | |
dbd2fd65 JB |
743 | if (err) |
744 | return err; | |
745 | ||
746 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
747 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
748 | } | |
749 | ||
b9454e83 JB |
750 | return 0; |
751 | } | |
752 | ||
753 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
754 | { | |
755 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
756 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
757 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
758 | } | |
759 | ||
760 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
761 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
762 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
763 | } | |
764 | ||
765 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
766 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
767 | ||
768 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
769 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
770 | ||
771 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
772 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
773 | ||
dbd2fd65 JB |
774 | if (k->def) { |
775 | k->def_uni = true; | |
776 | k->def_multi = true; | |
777 | } | |
778 | if (k->defmgmt) | |
779 | k->def_multi = true; | |
780 | ||
e31b8213 JB |
781 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
782 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
783 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
784 | return -EINVAL; | |
785 | } | |
786 | ||
dbd2fd65 JB |
787 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
788 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
789 | int err = nla_parse_nested( | |
790 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
791 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
792 | nl80211_key_default_policy); | |
793 | if (err) | |
794 | return err; | |
795 | ||
796 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
797 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
798 | } | |
799 | ||
b9454e83 JB |
800 | return 0; |
801 | } | |
802 | ||
803 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
804 | { | |
805 | int err; | |
806 | ||
807 | memset(k, 0, sizeof(*k)); | |
808 | k->idx = -1; | |
e31b8213 | 809 | k->type = -1; |
b9454e83 JB |
810 | |
811 | if (info->attrs[NL80211_ATTR_KEY]) | |
812 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
813 | else | |
814 | err = nl80211_parse_key_old(info, k); | |
815 | ||
816 | if (err) | |
817 | return err; | |
818 | ||
819 | if (k->def && k->defmgmt) | |
820 | return -EINVAL; | |
821 | ||
dbd2fd65 JB |
822 | if (k->defmgmt) { |
823 | if (k->def_uni || !k->def_multi) | |
824 | return -EINVAL; | |
825 | } | |
826 | ||
b9454e83 JB |
827 | if (k->idx != -1) { |
828 | if (k->defmgmt) { | |
829 | if (k->idx < 4 || k->idx > 5) | |
830 | return -EINVAL; | |
831 | } else if (k->def) { | |
832 | if (k->idx < 0 || k->idx > 3) | |
833 | return -EINVAL; | |
834 | } else { | |
835 | if (k->idx < 0 || k->idx > 5) | |
836 | return -EINVAL; | |
837 | } | |
838 | } | |
839 | ||
840 | return 0; | |
841 | } | |
842 | ||
fffd0934 JB |
843 | static struct cfg80211_cached_keys * |
844 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 845 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
846 | { |
847 | struct key_parse parse; | |
848 | struct nlattr *key; | |
849 | struct cfg80211_cached_keys *result; | |
850 | int rem, err, def = 0; | |
f1c1f17a JB |
851 | bool have_key = false; |
852 | ||
853 | nla_for_each_nested(key, keys, rem) { | |
854 | have_key = true; | |
855 | break; | |
856 | } | |
857 | ||
858 | if (!have_key) | |
859 | return NULL; | |
fffd0934 JB |
860 | |
861 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
862 | if (!result) | |
863 | return ERR_PTR(-ENOMEM); | |
864 | ||
865 | result->def = -1; | |
fffd0934 JB |
866 | |
867 | nla_for_each_nested(key, keys, rem) { | |
868 | memset(&parse, 0, sizeof(parse)); | |
869 | parse.idx = -1; | |
870 | ||
871 | err = nl80211_parse_key_new(key, &parse); | |
872 | if (err) | |
873 | goto error; | |
874 | err = -EINVAL; | |
875 | if (!parse.p.key) | |
876 | goto error; | |
42ee231c | 877 | if (parse.idx < 0 || parse.idx > 3) |
fffd0934 JB |
878 | goto error; |
879 | if (parse.def) { | |
880 | if (def) | |
881 | goto error; | |
882 | def = 1; | |
883 | result->def = parse.idx; | |
dbd2fd65 JB |
884 | if (!parse.def_uni || !parse.def_multi) |
885 | goto error; | |
fffd0934 JB |
886 | } else if (parse.defmgmt) |
887 | goto error; | |
888 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 889 | parse.idx, false, NULL); |
fffd0934 JB |
890 | if (err) |
891 | goto error; | |
386b1f27 JB |
892 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
893 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { | |
894 | err = -EINVAL; | |
895 | goto error; | |
896 | } | |
fffd0934 JB |
897 | result->params[parse.idx].cipher = parse.p.cipher; |
898 | result->params[parse.idx].key_len = parse.p.key_len; | |
899 | result->params[parse.idx].key = result->data[parse.idx]; | |
900 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee | 901 | |
386b1f27 JB |
902 | /* must be WEP key if we got here */ |
903 | if (no_ht) | |
904 | *no_ht = true; | |
fffd0934 JB |
905 | } |
906 | ||
f1c1f17a JB |
907 | if (result->def < 0) { |
908 | err = -EINVAL; | |
909 | goto error; | |
910 | } | |
911 | ||
fffd0934 JB |
912 | return result; |
913 | error: | |
914 | kfree(result); | |
915 | return ERR_PTR(err); | |
916 | } | |
917 | ||
918 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
919 | { | |
920 | ASSERT_WDEV_LOCK(wdev); | |
921 | ||
fffd0934 JB |
922 | switch (wdev->iftype) { |
923 | case NL80211_IFTYPE_AP: | |
924 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 925 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 926 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
927 | break; |
928 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 929 | case NL80211_IFTYPE_STATION: |
074ac8df | 930 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 931 | if (!wdev->current_bss) |
fffd0934 JB |
932 | return -ENOLINK; |
933 | break; | |
de4fcbad | 934 | case NL80211_IFTYPE_UNSPECIFIED: |
6e0bd6c3 | 935 | case NL80211_IFTYPE_OCB: |
de4fcbad JB |
936 | case NL80211_IFTYPE_MONITOR: |
937 | case NL80211_IFTYPE_P2P_DEVICE: | |
938 | case NL80211_IFTYPE_WDS: | |
939 | case NUM_NL80211_IFTYPES: | |
fffd0934 JB |
940 | return -EINVAL; |
941 | } | |
942 | ||
943 | return 0; | |
944 | } | |
945 | ||
664834de JM |
946 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
947 | struct nlattr *tb) | |
948 | { | |
949 | struct ieee80211_channel *chan; | |
950 | ||
951 | if (tb == NULL) | |
952 | return NULL; | |
953 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
954 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
955 | return NULL; | |
956 | return chan; | |
957 | } | |
958 | ||
7527a782 JB |
959 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
960 | { | |
961 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
962 | int i; | |
963 | ||
964 | if (!nl_modes) | |
965 | goto nla_put_failure; | |
966 | ||
967 | i = 0; | |
968 | while (ifmodes) { | |
9360ffd1 DM |
969 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
970 | goto nla_put_failure; | |
7527a782 JB |
971 | ifmodes >>= 1; |
972 | i++; | |
973 | } | |
974 | ||
975 | nla_nest_end(msg, nl_modes); | |
976 | return 0; | |
977 | ||
978 | nla_put_failure: | |
979 | return -ENOBUFS; | |
980 | } | |
981 | ||
982 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
983 | struct sk_buff *msg, |
984 | bool large) | |
7527a782 JB |
985 | { |
986 | struct nlattr *nl_combis; | |
987 | int i, j; | |
988 | ||
989 | nl_combis = nla_nest_start(msg, | |
990 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
991 | if (!nl_combis) | |
992 | goto nla_put_failure; | |
993 | ||
994 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
995 | const struct ieee80211_iface_combination *c; | |
996 | struct nlattr *nl_combi, *nl_limits; | |
997 | ||
998 | c = &wiphy->iface_combinations[i]; | |
999 | ||
1000 | nl_combi = nla_nest_start(msg, i + 1); | |
1001 | if (!nl_combi) | |
1002 | goto nla_put_failure; | |
1003 | ||
1004 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
1005 | if (!nl_limits) | |
1006 | goto nla_put_failure; | |
1007 | ||
1008 | for (j = 0; j < c->n_limits; j++) { | |
1009 | struct nlattr *nl_limit; | |
1010 | ||
1011 | nl_limit = nla_nest_start(msg, j + 1); | |
1012 | if (!nl_limit) | |
1013 | goto nla_put_failure; | |
9360ffd1 DM |
1014 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
1015 | c->limits[j].max)) | |
1016 | goto nla_put_failure; | |
7527a782 JB |
1017 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
1018 | c->limits[j].types)) | |
1019 | goto nla_put_failure; | |
1020 | nla_nest_end(msg, nl_limit); | |
1021 | } | |
1022 | ||
1023 | nla_nest_end(msg, nl_limits); | |
1024 | ||
9360ffd1 DM |
1025 | if (c->beacon_int_infra_match && |
1026 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
1027 | goto nla_put_failure; | |
1028 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
1029 | c->num_different_channels) || | |
1030 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
1031 | c->max_interfaces)) | |
1032 | goto nla_put_failure; | |
cdc89b97 | 1033 | if (large && |
8c48b50a FF |
1034 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
1035 | c->radar_detect_widths) || | |
1036 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
1037 | c->radar_detect_regions))) | |
cdc89b97 | 1038 | goto nla_put_failure; |
7527a782 JB |
1039 | |
1040 | nla_nest_end(msg, nl_combi); | |
1041 | } | |
1042 | ||
1043 | nla_nest_end(msg, nl_combis); | |
1044 | ||
1045 | return 0; | |
1046 | nla_put_failure: | |
1047 | return -ENOBUFS; | |
1048 | } | |
1049 | ||
3713b4e3 | 1050 | #ifdef CONFIG_PM |
b56cf720 JB |
1051 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
1052 | struct sk_buff *msg) | |
1053 | { | |
964dc9e2 | 1054 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
1055 | struct nlattr *nl_tcp; |
1056 | ||
1057 | if (!tcp) | |
1058 | return 0; | |
1059 | ||
1060 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
1061 | if (!nl_tcp) | |
1062 | return -ENOBUFS; | |
1063 | ||
1064 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1065 | tcp->data_payload_max)) | |
1066 | return -ENOBUFS; | |
1067 | ||
1068 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1069 | tcp->data_payload_max)) | |
1070 | return -ENOBUFS; | |
1071 | ||
1072 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1073 | return -ENOBUFS; | |
1074 | ||
1075 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1076 | sizeof(*tcp->tok), tcp->tok)) | |
1077 | return -ENOBUFS; | |
1078 | ||
1079 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1080 | tcp->data_interval_max)) | |
1081 | return -ENOBUFS; | |
1082 | ||
1083 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1084 | tcp->wake_payload_max)) | |
1085 | return -ENOBUFS; | |
1086 | ||
1087 | nla_nest_end(msg, nl_tcp); | |
1088 | return 0; | |
1089 | } | |
1090 | ||
3713b4e3 | 1091 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1092 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1093 | bool large) |
55682965 | 1094 | { |
3713b4e3 | 1095 | struct nlattr *nl_wowlan; |
55682965 | 1096 | |
1b8ec87a | 1097 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1098 | return 0; |
55682965 | 1099 | |
3713b4e3 JB |
1100 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1101 | if (!nl_wowlan) | |
1102 | return -ENOBUFS; | |
9360ffd1 | 1103 | |
1b8ec87a | 1104 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1105 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1106 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1107 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1108 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1109 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1110 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1111 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1112 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1113 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1114 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1115 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1116 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1117 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1118 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1119 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1120 | return -ENOBUFS; | |
9360ffd1 | 1121 | |
1b8ec87a | 1122 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1123 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1124 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1125 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1126 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1127 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1128 | }; |
9360ffd1 | 1129 | |
3713b4e3 JB |
1130 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1131 | sizeof(pat), &pat)) | |
1132 | return -ENOBUFS; | |
1133 | } | |
9360ffd1 | 1134 | |
75453ccb LC |
1135 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
1136 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, | |
1137 | rdev->wiphy.wowlan->max_nd_match_sets)) | |
1138 | return -ENOBUFS; | |
1139 | ||
1b8ec87a | 1140 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1141 | return -ENOBUFS; |
1142 | ||
3713b4e3 | 1143 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1144 | |
3713b4e3 JB |
1145 | return 0; |
1146 | } | |
1147 | #endif | |
9360ffd1 | 1148 | |
be29b99a | 1149 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1150 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1151 | { |
1152 | struct nl80211_coalesce_rule_support rule; | |
1153 | ||
1b8ec87a | 1154 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1155 | return 0; |
1156 | ||
1b8ec87a ZG |
1157 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1158 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1159 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1160 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1161 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1162 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1163 | |
1164 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1165 | return -ENOBUFS; | |
1166 | ||
1167 | return 0; | |
1168 | } | |
1169 | ||
3713b4e3 JB |
1170 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1171 | struct ieee80211_supported_band *sband) | |
1172 | { | |
1173 | struct nlattr *nl_rates, *nl_rate; | |
1174 | struct ieee80211_rate *rate; | |
1175 | int i; | |
87bbbe22 | 1176 | |
3713b4e3 JB |
1177 | /* add HT info */ |
1178 | if (sband->ht_cap.ht_supported && | |
1179 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1180 | sizeof(sband->ht_cap.mcs), | |
1181 | &sband->ht_cap.mcs) || | |
1182 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1183 | sband->ht_cap.cap) || | |
1184 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1185 | sband->ht_cap.ampdu_factor) || | |
1186 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1187 | sband->ht_cap.ampdu_density))) | |
1188 | return -ENOBUFS; | |
afe0cbf8 | 1189 | |
3713b4e3 JB |
1190 | /* add VHT info */ |
1191 | if (sband->vht_cap.vht_supported && | |
1192 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1193 | sizeof(sband->vht_cap.vht_mcs), | |
1194 | &sband->vht_cap.vht_mcs) || | |
1195 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1196 | sband->vht_cap.cap))) | |
1197 | return -ENOBUFS; | |
f59ac048 | 1198 | |
3713b4e3 JB |
1199 | /* add bitrates */ |
1200 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1201 | if (!nl_rates) | |
1202 | return -ENOBUFS; | |
ee688b00 | 1203 | |
3713b4e3 JB |
1204 | for (i = 0; i < sband->n_bitrates; i++) { |
1205 | nl_rate = nla_nest_start(msg, i); | |
1206 | if (!nl_rate) | |
1207 | return -ENOBUFS; | |
ee688b00 | 1208 | |
3713b4e3 JB |
1209 | rate = &sband->bitrates[i]; |
1210 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1211 | rate->bitrate)) | |
1212 | return -ENOBUFS; | |
1213 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1214 | nla_put_flag(msg, | |
1215 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1216 | return -ENOBUFS; | |
ee688b00 | 1217 | |
3713b4e3 JB |
1218 | nla_nest_end(msg, nl_rate); |
1219 | } | |
d51626df | 1220 | |
3713b4e3 | 1221 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1222 | |
3713b4e3 JB |
1223 | return 0; |
1224 | } | |
ee688b00 | 1225 | |
3713b4e3 JB |
1226 | static int |
1227 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1228 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1229 | { | |
1230 | u16 stypes; | |
1231 | struct nlattr *nl_ftypes, *nl_ifs; | |
1232 | enum nl80211_iftype ift; | |
1233 | int i; | |
ee688b00 | 1234 | |
3713b4e3 JB |
1235 | if (!mgmt_stypes) |
1236 | return 0; | |
5dab3b8a | 1237 | |
3713b4e3 JB |
1238 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1239 | if (!nl_ifs) | |
1240 | return -ENOBUFS; | |
e2f367f2 | 1241 | |
3713b4e3 JB |
1242 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1243 | nl_ftypes = nla_nest_start(msg, ift); | |
1244 | if (!nl_ftypes) | |
1245 | return -ENOBUFS; | |
1246 | i = 0; | |
1247 | stypes = mgmt_stypes[ift].tx; | |
1248 | while (stypes) { | |
1249 | if ((stypes & 1) && | |
1250 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1251 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1252 | return -ENOBUFS; | |
1253 | stypes >>= 1; | |
1254 | i++; | |
ee688b00 | 1255 | } |
3713b4e3 JB |
1256 | nla_nest_end(msg, nl_ftypes); |
1257 | } | |
ee688b00 | 1258 | |
3713b4e3 | 1259 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1260 | |
3713b4e3 JB |
1261 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1262 | if (!nl_ifs) | |
1263 | return -ENOBUFS; | |
ee688b00 | 1264 | |
3713b4e3 JB |
1265 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1266 | nl_ftypes = nla_nest_start(msg, ift); | |
1267 | if (!nl_ftypes) | |
1268 | return -ENOBUFS; | |
1269 | i = 0; | |
1270 | stypes = mgmt_stypes[ift].rx; | |
1271 | while (stypes) { | |
1272 | if ((stypes & 1) && | |
1273 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1274 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1275 | return -ENOBUFS; | |
1276 | stypes >>= 1; | |
1277 | i++; | |
1278 | } | |
1279 | nla_nest_end(msg, nl_ftypes); | |
1280 | } | |
1281 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1282 | |
3713b4e3 JB |
1283 | return 0; |
1284 | } | |
ee688b00 | 1285 | |
86e8cf98 JB |
1286 | struct nl80211_dump_wiphy_state { |
1287 | s64 filter_wiphy; | |
1288 | long start; | |
019ae3a9 | 1289 | long split_start, band_start, chan_start, capa_start; |
86e8cf98 JB |
1290 | bool split; |
1291 | }; | |
1292 | ||
1b8ec87a | 1293 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 1294 | enum nl80211_commands cmd, |
3713b4e3 | 1295 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1296 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1297 | { |
1298 | void *hdr; | |
1299 | struct nlattr *nl_bands, *nl_band; | |
1300 | struct nlattr *nl_freqs, *nl_freq; | |
1301 | struct nlattr *nl_cmds; | |
57fbcce3 | 1302 | enum nl80211_band band; |
3713b4e3 JB |
1303 | struct ieee80211_channel *chan; |
1304 | int i; | |
1305 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1306 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1307 | u32 features; |
ee688b00 | 1308 | |
3bb20556 | 1309 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
1310 | if (!hdr) |
1311 | return -ENOBUFS; | |
ee688b00 | 1312 | |
86e8cf98 JB |
1313 | if (WARN_ON(!state)) |
1314 | return -EINVAL; | |
ee688b00 | 1315 | |
1b8ec87a | 1316 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1317 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1318 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1319 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1320 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1321 | goto nla_put_failure; |
1322 | ||
3bb20556 JB |
1323 | if (cmd != NL80211_CMD_NEW_WIPHY) |
1324 | goto finish; | |
1325 | ||
86e8cf98 | 1326 | switch (state->split_start) { |
3713b4e3 JB |
1327 | case 0: |
1328 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1329 | rdev->wiphy.retry_short) || |
3713b4e3 | 1330 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1331 | rdev->wiphy.retry_long) || |
3713b4e3 | 1332 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1333 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1334 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1335 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1336 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1337 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1338 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1339 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1340 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1341 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1342 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1343 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1344 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1345 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1346 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
3b06d277 AS |
1347 | rdev->wiphy.max_match_sets) || |
1348 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, | |
1349 | rdev->wiphy.max_sched_scan_plans) || | |
1350 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, | |
1351 | rdev->wiphy.max_sched_scan_plan_interval) || | |
1352 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, | |
1353 | rdev->wiphy.max_sched_scan_plan_iterations)) | |
9360ffd1 | 1354 | goto nla_put_failure; |
3713b4e3 | 1355 | |
1b8ec87a | 1356 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1357 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1358 | goto nla_put_failure; |
1b8ec87a | 1359 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1360 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1361 | goto nla_put_failure; | |
1b8ec87a | 1362 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1363 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1364 | goto nla_put_failure; | |
1b8ec87a | 1365 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1366 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1367 | goto nla_put_failure; | |
1b8ec87a | 1368 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1369 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1370 | goto nla_put_failure; | |
1b8ec87a | 1371 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1372 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1373 | goto nla_put_failure; |
86e8cf98 JB |
1374 | state->split_start++; |
1375 | if (state->split) | |
3713b4e3 JB |
1376 | break; |
1377 | case 1: | |
1378 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1379 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1380 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1381 | goto nla_put_failure; |
4745fc09 | 1382 | |
3713b4e3 | 1383 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1384 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1385 | goto nla_put_failure; |
b23aa676 | 1386 | |
1b8ec87a | 1387 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1388 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1389 | goto nla_put_failure; |
b23aa676 | 1390 | |
3713b4e3 | 1391 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1392 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1393 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1394 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1395 | goto nla_put_failure; |
b23aa676 | 1396 | |
1b8ec87a | 1397 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1398 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1399 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1400 | goto nla_put_failure; |
8fdc621d | 1401 | |
1b8ec87a ZG |
1402 | if ((rdev->wiphy.available_antennas_tx || |
1403 | rdev->wiphy.available_antennas_rx) && | |
1404 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1405 | u32 tx_ant = 0, rx_ant = 0; |
1406 | int res; | |
7a087e74 | 1407 | |
1b8ec87a | 1408 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1409 | if (!res) { |
1410 | if (nla_put_u32(msg, | |
1411 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1412 | tx_ant) || | |
1413 | nla_put_u32(msg, | |
1414 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1415 | rx_ant)) | |
1416 | goto nla_put_failure; | |
1417 | } | |
1418 | } | |
a293911d | 1419 | |
86e8cf98 JB |
1420 | state->split_start++; |
1421 | if (state->split) | |
3713b4e3 JB |
1422 | break; |
1423 | case 2: | |
1424 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1425 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1426 | goto nla_put_failure; |
86e8cf98 JB |
1427 | state->split_start++; |
1428 | if (state->split) | |
3713b4e3 JB |
1429 | break; |
1430 | case 3: | |
1431 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1432 | if (!nl_bands) | |
1433 | goto nla_put_failure; | |
f7ca38df | 1434 | |
86e8cf98 | 1435 | for (band = state->band_start; |
57fbcce3 | 1436 | band < NUM_NL80211_BANDS; band++) { |
3713b4e3 | 1437 | struct ieee80211_supported_band *sband; |
2e161f78 | 1438 | |
1b8ec87a | 1439 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1440 | |
3713b4e3 JB |
1441 | if (!sband) |
1442 | continue; | |
1443 | ||
1444 | nl_band = nla_nest_start(msg, band); | |
1445 | if (!nl_band) | |
2e161f78 | 1446 | goto nla_put_failure; |
3713b4e3 | 1447 | |
86e8cf98 | 1448 | switch (state->chan_start) { |
3713b4e3 JB |
1449 | case 0: |
1450 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1451 | goto nla_put_failure; |
86e8cf98 JB |
1452 | state->chan_start++; |
1453 | if (state->split) | |
3713b4e3 JB |
1454 | break; |
1455 | default: | |
1456 | /* add frequencies */ | |
1457 | nl_freqs = nla_nest_start( | |
1458 | msg, NL80211_BAND_ATTR_FREQS); | |
1459 | if (!nl_freqs) | |
1460 | goto nla_put_failure; | |
1461 | ||
86e8cf98 | 1462 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1463 | i < sband->n_channels; |
1464 | i++) { | |
1465 | nl_freq = nla_nest_start(msg, i); | |
1466 | if (!nl_freq) | |
1467 | goto nla_put_failure; | |
1468 | ||
1469 | chan = &sband->channels[i]; | |
1470 | ||
86e8cf98 JB |
1471 | if (nl80211_msg_put_channel( |
1472 | msg, chan, | |
1473 | state->split)) | |
3713b4e3 JB |
1474 | goto nla_put_failure; |
1475 | ||
1476 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1477 | if (state->split) |
3713b4e3 JB |
1478 | break; |
1479 | } | |
1480 | if (i < sband->n_channels) | |
86e8cf98 | 1481 | state->chan_start = i + 2; |
3713b4e3 | 1482 | else |
86e8cf98 | 1483 | state->chan_start = 0; |
3713b4e3 JB |
1484 | nla_nest_end(msg, nl_freqs); |
1485 | } | |
1486 | ||
1487 | nla_nest_end(msg, nl_band); | |
1488 | ||
86e8cf98 | 1489 | if (state->split) { |
3713b4e3 | 1490 | /* start again here */ |
86e8cf98 | 1491 | if (state->chan_start) |
3713b4e3 JB |
1492 | band--; |
1493 | break; | |
2e161f78 | 1494 | } |
2e161f78 | 1495 | } |
3713b4e3 | 1496 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1497 | |
57fbcce3 | 1498 | if (band < NUM_NL80211_BANDS) |
86e8cf98 | 1499 | state->band_start = band + 1; |
3713b4e3 | 1500 | else |
86e8cf98 | 1501 | state->band_start = 0; |
74b70a4e | 1502 | |
3713b4e3 | 1503 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1504 | if (state->band_start == 0 && state->chan_start == 0) |
1505 | state->split_start++; | |
1506 | if (state->split) | |
3713b4e3 JB |
1507 | break; |
1508 | case 4: | |
1509 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1510 | if (!nl_cmds) | |
2e161f78 JB |
1511 | goto nla_put_failure; |
1512 | ||
3713b4e3 JB |
1513 | i = 0; |
1514 | #define CMD(op, n) \ | |
1515 | do { \ | |
1b8ec87a | 1516 | if (rdev->ops->op) { \ |
3713b4e3 JB |
1517 | i++; \ |
1518 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1519 | goto nla_put_failure; \ | |
1520 | } \ | |
1521 | } while (0) | |
1522 | ||
1523 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1524 | CMD(change_virtual_intf, SET_INTERFACE); | |
1525 | CMD(add_key, NEW_KEY); | |
1526 | CMD(start_ap, START_AP); | |
1527 | CMD(add_station, NEW_STATION); | |
1528 | CMD(add_mpath, NEW_MPATH); | |
1529 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1530 | CMD(change_bss, SET_BSS); | |
1531 | CMD(auth, AUTHENTICATE); | |
1532 | CMD(assoc, ASSOCIATE); | |
1533 | CMD(deauth, DEAUTHENTICATE); | |
1534 | CMD(disassoc, DISASSOCIATE); | |
1535 | CMD(join_ibss, JOIN_IBSS); | |
1536 | CMD(join_mesh, JOIN_MESH); | |
1537 | CMD(set_pmksa, SET_PMKSA); | |
1538 | CMD(del_pmksa, DEL_PMKSA); | |
1539 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1b8ec87a | 1540 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
3713b4e3 JB |
1541 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
1542 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1543 | CMD(mgmt_tx, FRAME); | |
1544 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1b8ec87a | 1545 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
3713b4e3 JB |
1546 | i++; |
1547 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1548 | goto nla_put_failure; |
2e161f78 | 1549 | } |
1b8ec87a ZG |
1550 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
1551 | rdev->ops->join_mesh) { | |
3713b4e3 JB |
1552 | i++; |
1553 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1554 | goto nla_put_failure; | |
1555 | } | |
1556 | CMD(set_wds_peer, SET_WDS_PEER); | |
1b8ec87a | 1557 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
3713b4e3 JB |
1558 | CMD(tdls_mgmt, TDLS_MGMT); |
1559 | CMD(tdls_oper, TDLS_OPER); | |
1560 | } | |
1b8ec87a | 1561 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
3713b4e3 JB |
1562 | CMD(sched_scan_start, START_SCHED_SCAN); |
1563 | CMD(probe_client, PROBE_CLIENT); | |
1564 | CMD(set_noack_map, SET_NOACK_MAP); | |
1b8ec87a | 1565 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
3713b4e3 JB |
1566 | i++; |
1567 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1568 | goto nla_put_failure; | |
1569 | } | |
1570 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1571 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
02df00eb JB |
1572 | #ifdef CONFIG_NL80211_TESTMODE |
1573 | CMD(testmode_cmd, TESTMODE); | |
1574 | #endif | |
86e8cf98 | 1575 | if (state->split) { |
5de17984 AS |
1576 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1577 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 1578 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 1579 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 1580 | CMD(set_qos_map, SET_QOS_MAP); |
723e73ac JB |
1581 | if (rdev->wiphy.features & |
1582 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | |
960d01ac | 1583 | CMD(add_tx_ts, ADD_TX_TS); |
5de17984 | 1584 | } |
02df00eb | 1585 | /* add into the if now */ |
3713b4e3 | 1586 | #undef CMD |
ff1b6e69 | 1587 | |
1b8ec87a | 1588 | if (rdev->ops->connect || rdev->ops->auth) { |
3713b4e3 JB |
1589 | i++; |
1590 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1591 | goto nla_put_failure; |
ff1b6e69 JB |
1592 | } |
1593 | ||
1b8ec87a | 1594 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
3713b4e3 JB |
1595 | i++; |
1596 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1597 | goto nla_put_failure; | |
1598 | } | |
1599 | ||
1600 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1601 | state->split_start++; |
1602 | if (state->split) | |
3713b4e3 JB |
1603 | break; |
1604 | case 5: | |
1b8ec87a ZG |
1605 | if (rdev->ops->remain_on_channel && |
1606 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
1607 | nla_put_u32(msg, |
1608 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 1609 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
1610 | goto nla_put_failure; |
1611 | ||
1b8ec87a | 1612 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
1613 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
1614 | goto nla_put_failure; | |
1615 | ||
1616 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1617 | goto nla_put_failure; | |
86e8cf98 JB |
1618 | state->split_start++; |
1619 | if (state->split) | |
3713b4e3 JB |
1620 | break; |
1621 | case 6: | |
1622 | #ifdef CONFIG_PM | |
1b8ec87a | 1623 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 1624 | goto nla_put_failure; |
86e8cf98 JB |
1625 | state->split_start++; |
1626 | if (state->split) | |
3713b4e3 JB |
1627 | break; |
1628 | #else | |
86e8cf98 | 1629 | state->split_start++; |
dfb89c56 | 1630 | #endif |
3713b4e3 JB |
1631 | case 7: |
1632 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 1633 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 1634 | goto nla_put_failure; |
ff1b6e69 | 1635 | |
1b8ec87a | 1636 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 1637 | state->split)) |
3713b4e3 | 1638 | goto nla_put_failure; |
7527a782 | 1639 | |
86e8cf98 JB |
1640 | state->split_start++; |
1641 | if (state->split) | |
3713b4e3 JB |
1642 | break; |
1643 | case 8: | |
1b8ec87a | 1644 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 1645 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 1646 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 1647 | goto nla_put_failure; |
7527a782 | 1648 | |
1b8ec87a | 1649 | features = rdev->wiphy.features; |
fe1abafd JB |
1650 | /* |
1651 | * We can only add the per-channel limit information if the | |
1652 | * dump is split, otherwise it makes it too big. Therefore | |
1653 | * only advertise it in that case. | |
1654 | */ | |
86e8cf98 | 1655 | if (state->split) |
fe1abafd JB |
1656 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1657 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1658 | goto nla_put_failure; |
562a7480 | 1659 | |
1b8ec87a | 1660 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 1661 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
1662 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
1663 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 1664 | goto nla_put_failure; |
1f074bd8 | 1665 | |
1b8ec87a ZG |
1666 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1667 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 1668 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 1669 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 1670 | goto nla_put_failure; |
7e7c8926 | 1671 | |
3713b4e3 JB |
1672 | /* |
1673 | * Any information below this point is only available to | |
1674 | * applications that can deal with it being split. This | |
1675 | * helps ensure that newly added capabilities don't break | |
1676 | * older tools by overrunning their buffers. | |
1677 | * | |
1678 | * We still increment split_start so that in the split | |
1679 | * case we'll continue with more data in the next round, | |
1680 | * but break unconditionally so unsplit data stops here. | |
1681 | */ | |
86e8cf98 | 1682 | state->split_start++; |
3713b4e3 JB |
1683 | break; |
1684 | case 9: | |
1b8ec87a | 1685 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 1686 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
1687 | rdev->wiphy.extended_capabilities_len, |
1688 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 1689 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
1690 | rdev->wiphy.extended_capabilities_len, |
1691 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 1692 | goto nla_put_failure; |
a50df0c4 | 1693 | |
1b8ec87a | 1694 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 1695 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
1696 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
1697 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
1698 | goto nla_put_failure; |
1699 | ||
be29b99a AK |
1700 | state->split_start++; |
1701 | break; | |
1702 | case 10: | |
1b8ec87a | 1703 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
1704 | goto nla_put_failure; |
1705 | ||
1b8ec87a | 1706 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
1707 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
1708 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1709 | goto nla_put_failure; | |
b43504cf | 1710 | |
1b8ec87a | 1711 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 1712 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 1713 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
1714 | goto nla_put_failure; |
1715 | ||
ad7e718c JB |
1716 | state->split_start++; |
1717 | break; | |
1718 | case 11: | |
1b8ec87a | 1719 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
1720 | const struct nl80211_vendor_cmd_info *info; |
1721 | struct nlattr *nested; | |
1722 | ||
1723 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1724 | if (!nested) | |
1725 | goto nla_put_failure; | |
1726 | ||
1b8ec87a ZG |
1727 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
1728 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
1729 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1730 | goto nla_put_failure; | |
1731 | } | |
1732 | nla_nest_end(msg, nested); | |
1733 | } | |
1734 | ||
1b8ec87a | 1735 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
1736 | const struct nl80211_vendor_cmd_info *info; |
1737 | struct nlattr *nested; | |
ad7e718c | 1738 | |
567ffc35 JB |
1739 | nested = nla_nest_start(msg, |
1740 | NL80211_ATTR_VENDOR_EVENTS); | |
1741 | if (!nested) | |
ad7e718c | 1742 | goto nla_put_failure; |
567ffc35 | 1743 | |
1b8ec87a ZG |
1744 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
1745 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
1746 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1747 | goto nla_put_failure; | |
1748 | } | |
1749 | nla_nest_end(msg, nested); | |
1750 | } | |
9a774c78 AO |
1751 | state->split_start++; |
1752 | break; | |
1753 | case 12: | |
1754 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
1755 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
1756 | rdev->wiphy.max_num_csa_counters)) | |
1757 | goto nla_put_failure; | |
01e0daa4 | 1758 | |
1bdd716c AN |
1759 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
1760 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
1761 | goto nla_put_failure; | |
1762 | ||
d75bb06b GKS |
1763 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
1764 | sizeof(rdev->wiphy.ext_features), | |
1765 | rdev->wiphy.ext_features)) | |
1766 | goto nla_put_failure; | |
1767 | ||
38de03d2 AS |
1768 | if (rdev->wiphy.bss_select_support) { |
1769 | struct nlattr *nested; | |
1770 | u32 bss_select_support = rdev->wiphy.bss_select_support; | |
1771 | ||
1772 | nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); | |
1773 | if (!nested) | |
1774 | goto nla_put_failure; | |
1775 | ||
1776 | i = 0; | |
1777 | while (bss_select_support) { | |
1778 | if ((bss_select_support & 1) && | |
1779 | nla_put_flag(msg, i)) | |
1780 | goto nla_put_failure; | |
1781 | i++; | |
1782 | bss_select_support >>= 1; | |
1783 | } | |
1784 | nla_nest_end(msg, nested); | |
1785 | } | |
1786 | ||
019ae3a9 KV |
1787 | state->split_start++; |
1788 | break; | |
1789 | case 13: | |
1790 | if (rdev->wiphy.num_iftype_ext_capab && | |
1791 | rdev->wiphy.iftype_ext_capab) { | |
1792 | struct nlattr *nested_ext_capab, *nested; | |
1793 | ||
1794 | nested = nla_nest_start(msg, | |
1795 | NL80211_ATTR_IFTYPE_EXT_CAPA); | |
1796 | if (!nested) | |
1797 | goto nla_put_failure; | |
1798 | ||
1799 | for (i = state->capa_start; | |
1800 | i < rdev->wiphy.num_iftype_ext_capab; i++) { | |
1801 | const struct wiphy_iftype_ext_capab *capab; | |
1802 | ||
1803 | capab = &rdev->wiphy.iftype_ext_capab[i]; | |
1804 | ||
1805 | nested_ext_capab = nla_nest_start(msg, i); | |
1806 | if (!nested_ext_capab || | |
1807 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, | |
1808 | capab->iftype) || | |
1809 | nla_put(msg, NL80211_ATTR_EXT_CAPA, | |
1810 | capab->extended_capabilities_len, | |
1811 | capab->extended_capabilities) || | |
1812 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | |
1813 | capab->extended_capabilities_len, | |
1814 | capab->extended_capabilities_mask)) | |
1815 | goto nla_put_failure; | |
1816 | ||
1817 | nla_nest_end(msg, nested_ext_capab); | |
1818 | if (state->split) | |
1819 | break; | |
1820 | } | |
1821 | nla_nest_end(msg, nested); | |
1822 | if (i < rdev->wiphy.num_iftype_ext_capab) { | |
1823 | state->capa_start = i + 1; | |
1824 | break; | |
1825 | } | |
1826 | } | |
1827 | ||
3713b4e3 | 1828 | /* done */ |
86e8cf98 | 1829 | state->split_start = 0; |
3713b4e3 JB |
1830 | break; |
1831 | } | |
3bb20556 | 1832 | finish: |
053c095a JB |
1833 | genlmsg_end(msg, hdr); |
1834 | return 0; | |
55682965 JB |
1835 | |
1836 | nla_put_failure: | |
bc3ed28c TG |
1837 | genlmsg_cancel(msg, hdr); |
1838 | return -EMSGSIZE; | |
55682965 JB |
1839 | } |
1840 | ||
86e8cf98 JB |
1841 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1842 | struct netlink_callback *cb, | |
1843 | struct nl80211_dump_wiphy_state *state) | |
1844 | { | |
1845 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1846 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1847 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1848 | /* ignore parse errors for backward compatibility */ | |
1849 | if (ret) | |
1850 | return 0; | |
1851 | ||
1852 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1853 | if (tb[NL80211_ATTR_WIPHY]) | |
1854 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1855 | if (tb[NL80211_ATTR_WDEV]) | |
1856 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1857 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1858 | struct net_device *netdev; | |
1859 | struct cfg80211_registered_device *rdev; | |
1860 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1861 | ||
7f2b8562 | 1862 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1863 | if (!netdev) |
1864 | return -ENODEV; | |
1865 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1866 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1867 | netdev->ieee80211_ptr->wiphy); |
1868 | state->filter_wiphy = rdev->wiphy_idx; | |
1869 | } | |
86e8cf98 JB |
1870 | } |
1871 | ||
1872 | return 0; | |
1873 | } | |
1874 | ||
55682965 JB |
1875 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1876 | { | |
645e77de | 1877 | int idx = 0, ret; |
86e8cf98 | 1878 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1879 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1880 | |
5fe231e8 | 1881 | rtnl_lock(); |
86e8cf98 JB |
1882 | if (!state) { |
1883 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1884 | if (!state) { |
1885 | rtnl_unlock(); | |
86e8cf98 | 1886 | return -ENOMEM; |
3713b4e3 | 1887 | } |
86e8cf98 JB |
1888 | state->filter_wiphy = -1; |
1889 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1890 | if (ret) { | |
1891 | kfree(state); | |
1892 | rtnl_unlock(); | |
1893 | return ret; | |
3713b4e3 | 1894 | } |
86e8cf98 | 1895 | cb->args[0] = (long)state; |
3713b4e3 JB |
1896 | } |
1897 | ||
1b8ec87a ZG |
1898 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1899 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1900 | continue; |
86e8cf98 | 1901 | if (++idx <= state->start) |
55682965 | 1902 | continue; |
86e8cf98 | 1903 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1904 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1905 | continue; |
1906 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1907 | do { | |
3bb20556 JB |
1908 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
1909 | skb, | |
3713b4e3 JB |
1910 | NETLINK_CB(cb->skb).portid, |
1911 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1912 | NLM_F_MULTI, state); |
3713b4e3 JB |
1913 | if (ret < 0) { |
1914 | /* | |
1915 | * If sending the wiphy data didn't fit (ENOBUFS | |
1916 | * or EMSGSIZE returned), this SKB is still | |
1917 | * empty (so it's not too big because another | |
1918 | * wiphy dataset is already in the skb) and | |
1919 | * we've not tried to adjust the dump allocation | |
1920 | * yet ... then adjust the alloc size to be | |
1921 | * bigger, and return 1 but with the empty skb. | |
1922 | * This results in an empty message being RX'ed | |
1923 | * in userspace, but that is ignored. | |
1924 | * | |
1925 | * We can then retry with the larger buffer. | |
1926 | */ | |
1927 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1928 | !skb->len && !state->split && |
3713b4e3 JB |
1929 | cb->min_dump_alloc < 4096) { |
1930 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1931 | state->split_start = 0; |
d98cae64 | 1932 | rtnl_unlock(); |
3713b4e3 JB |
1933 | return 1; |
1934 | } | |
1935 | idx--; | |
1936 | break; | |
645e77de | 1937 | } |
86e8cf98 | 1938 | } while (state->split_start > 0); |
3713b4e3 | 1939 | break; |
55682965 | 1940 | } |
5fe231e8 | 1941 | rtnl_unlock(); |
55682965 | 1942 | |
86e8cf98 | 1943 | state->start = idx; |
55682965 JB |
1944 | |
1945 | return skb->len; | |
1946 | } | |
1947 | ||
86e8cf98 JB |
1948 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1949 | { | |
1950 | kfree((void *)cb->args[0]); | |
1951 | return 0; | |
1952 | } | |
1953 | ||
55682965 JB |
1954 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1955 | { | |
1956 | struct sk_buff *msg; | |
1b8ec87a | 1957 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 1958 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1959 | |
645e77de | 1960 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1961 | if (!msg) |
4c476991 | 1962 | return -ENOMEM; |
55682965 | 1963 | |
3bb20556 JB |
1964 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
1965 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 1966 | &state) < 0) { |
4c476991 JB |
1967 | nlmsg_free(msg); |
1968 | return -ENOBUFS; | |
1969 | } | |
55682965 | 1970 | |
134e6375 | 1971 | return genlmsg_reply(msg, info); |
55682965 JB |
1972 | } |
1973 | ||
31888487 JM |
1974 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1975 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1976 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1977 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1978 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1979 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1980 | }; | |
1981 | ||
1982 | static int parse_txq_params(struct nlattr *tb[], | |
1983 | struct ieee80211_txq_params *txq_params) | |
1984 | { | |
a3304b0a | 1985 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1986 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1987 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1988 | return -EINVAL; | |
1989 | ||
a3304b0a | 1990 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1991 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1992 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1993 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1994 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1995 | ||
a3304b0a JB |
1996 | if (txq_params->ac >= NL80211_NUM_ACS) |
1997 | return -EINVAL; | |
1998 | ||
31888487 JM |
1999 | return 0; |
2000 | } | |
2001 | ||
f444de05 JB |
2002 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
2003 | { | |
2004 | /* | |
cc1d2806 JB |
2005 | * You can only set the channel explicitly for WDS interfaces, |
2006 | * all others have their channel managed via their respective | |
2007 | * "establish a connection" command (connect, join, ...) | |
2008 | * | |
2009 | * For AP/GO and mesh mode, the channel can be set with the | |
2010 | * channel userspace API, but is only stored and passed to the | |
2011 | * low-level driver when the AP starts or the mesh is joined. | |
2012 | * This is for backward compatibility, userspace can also give | |
2013 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
2014 | * |
2015 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
2016 | * whatever else is going on, so they have their own special |
2017 | * operation to set the monitor channel if possible. | |
f444de05 JB |
2018 | */ |
2019 | return !wdev || | |
2020 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 2021 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
2022 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
2023 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
2024 | } |
2025 | ||
683b6d3b JB |
2026 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
2027 | struct genl_info *info, | |
2028 | struct cfg80211_chan_def *chandef) | |
2029 | { | |
dbeca2ea | 2030 | u32 control_freq; |
683b6d3b JB |
2031 | |
2032 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
2033 | return -EINVAL; | |
2034 | ||
2035 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
2036 | ||
2037 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
2038 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
2039 | chandef->center_freq1 = control_freq; | |
2040 | chandef->center_freq2 = 0; | |
683b6d3b JB |
2041 | |
2042 | /* Primary channel not allowed */ | |
2043 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
2044 | return -EINVAL; | |
2045 | ||
3d9d1d66 JB |
2046 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
2047 | enum nl80211_channel_type chantype; | |
2048 | ||
2049 | chantype = nla_get_u32( | |
2050 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
2051 | ||
2052 | switch (chantype) { | |
2053 | case NL80211_CHAN_NO_HT: | |
2054 | case NL80211_CHAN_HT20: | |
2055 | case NL80211_CHAN_HT40PLUS: | |
2056 | case NL80211_CHAN_HT40MINUS: | |
2057 | cfg80211_chandef_create(chandef, chandef->chan, | |
2058 | chantype); | |
2059 | break; | |
2060 | default: | |
2061 | return -EINVAL; | |
2062 | } | |
2063 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
2064 | chandef->width = | |
2065 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
2066 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
2067 | chandef->center_freq1 = | |
2068 | nla_get_u32( | |
2069 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
2070 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
2071 | chandef->center_freq2 = | |
2072 | nla_get_u32( | |
2073 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
2074 | } | |
2075 | ||
9f5e8f6e | 2076 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
2077 | return -EINVAL; |
2078 | ||
9f5e8f6e JB |
2079 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
2080 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
2081 | return -EINVAL; |
2082 | ||
2f301ab2 SW |
2083 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
2084 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
2085 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
2086 | return -EINVAL; | |
2087 | ||
683b6d3b JB |
2088 | return 0; |
2089 | } | |
2090 | ||
f444de05 | 2091 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 2092 | struct net_device *dev, |
f444de05 JB |
2093 | struct genl_info *info) |
2094 | { | |
683b6d3b | 2095 | struct cfg80211_chan_def chandef; |
f444de05 | 2096 | int result; |
e8c9bd5b | 2097 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 2098 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 2099 | |
e16821bc JM |
2100 | if (dev) |
2101 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
2102 | if (!nl80211_can_set_dev_channel(wdev)) |
2103 | return -EOPNOTSUPP; | |
e16821bc JM |
2104 | if (wdev) |
2105 | iftype = wdev->iftype; | |
f444de05 | 2106 | |
683b6d3b JB |
2107 | result = nl80211_parse_chandef(rdev, info, &chandef); |
2108 | if (result) | |
2109 | return result; | |
f444de05 | 2110 | |
e8c9bd5b | 2111 | switch (iftype) { |
aa430da4 JB |
2112 | case NL80211_IFTYPE_AP: |
2113 | case NL80211_IFTYPE_P2P_GO: | |
923b352f AN |
2114 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
2115 | iftype)) { | |
aa430da4 JB |
2116 | result = -EINVAL; |
2117 | break; | |
2118 | } | |
e16821bc JM |
2119 | if (wdev->beacon_interval) { |
2120 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
2121 | !(rdev->wiphy.features & | |
2122 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
2123 | result = -EBUSY; | |
2124 | break; | |
2125 | } | |
2126 | ||
2127 | /* Only allow dynamic channel width changes */ | |
2128 | if (chandef.chan != wdev->preset_chandef.chan) { | |
2129 | result = -EBUSY; | |
2130 | break; | |
2131 | } | |
2132 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
2133 | if (result) | |
2134 | break; | |
2135 | } | |
683b6d3b | 2136 | wdev->preset_chandef = chandef; |
aa430da4 JB |
2137 | result = 0; |
2138 | break; | |
cc1d2806 | 2139 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 2140 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 2141 | break; |
e8c9bd5b | 2142 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 2143 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 2144 | break; |
aa430da4 | 2145 | default: |
e8c9bd5b | 2146 | result = -EINVAL; |
f444de05 | 2147 | } |
f444de05 JB |
2148 | |
2149 | return result; | |
2150 | } | |
2151 | ||
2152 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2153 | { | |
4c476991 JB |
2154 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2155 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2156 | |
e16821bc | 2157 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2158 | } |
2159 | ||
e8347eba BJ |
2160 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2161 | { | |
43b19952 JB |
2162 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2163 | struct net_device *dev = info->user_ptr[1]; | |
2164 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2165 | const u8 *bssid; |
e8347eba BJ |
2166 | |
2167 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2168 | return -EINVAL; | |
2169 | ||
43b19952 JB |
2170 | if (netif_running(dev)) |
2171 | return -EBUSY; | |
e8347eba | 2172 | |
43b19952 JB |
2173 | if (!rdev->ops->set_wds_peer) |
2174 | return -EOPNOTSUPP; | |
e8347eba | 2175 | |
43b19952 JB |
2176 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2177 | return -EOPNOTSUPP; | |
e8347eba BJ |
2178 | |
2179 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2180 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2181 | } |
2182 | ||
55682965 JB |
2183 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2184 | { | |
2185 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2186 | struct net_device *netdev = NULL; |
2187 | struct wireless_dev *wdev; | |
a1e567c8 | 2188 | int result = 0, rem_txq_params = 0; |
31888487 | 2189 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2190 | u32 changed; |
2191 | u8 retry_short = 0, retry_long = 0; | |
2192 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2193 | u8 coverage_class = 0; |
55682965 | 2194 | |
5fe231e8 JB |
2195 | ASSERT_RTNL(); |
2196 | ||
f444de05 JB |
2197 | /* |
2198 | * Try to find the wiphy and netdev. Normally this | |
2199 | * function shouldn't need the netdev, but this is | |
2200 | * done for backward compatibility -- previously | |
2201 | * setting the channel was done per wiphy, but now | |
2202 | * it is per netdev. Previous userland like hostapd | |
2203 | * also passed a netdev to set_wiphy, so that it is | |
2204 | * possible to let that go to the right netdev! | |
2205 | */ | |
4bbf4d56 | 2206 | |
f444de05 JB |
2207 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2208 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2209 | ||
7f2b8562 | 2210 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2211 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2212 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2213 | else |
f444de05 | 2214 | netdev = NULL; |
4bbf4d56 JB |
2215 | } |
2216 | ||
f444de05 | 2217 | if (!netdev) { |
878d9ec7 JB |
2218 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2219 | info->attrs); | |
5fe231e8 | 2220 | if (IS_ERR(rdev)) |
4c476991 | 2221 | return PTR_ERR(rdev); |
f444de05 JB |
2222 | wdev = NULL; |
2223 | netdev = NULL; | |
2224 | result = 0; | |
71fe96bf | 2225 | } else |
f444de05 | 2226 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2227 | |
2228 | /* | |
2229 | * end workaround code, by now the rdev is available | |
2230 | * and locked, and wdev may or may not be NULL. | |
2231 | */ | |
4bbf4d56 JB |
2232 | |
2233 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2234 | result = cfg80211_dev_rename( |
2235 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2236 | |
4bbf4d56 | 2237 | if (result) |
7f2b8562 | 2238 | return result; |
31888487 JM |
2239 | |
2240 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2241 | struct ieee80211_txq_params txq_params; | |
2242 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2243 | ||
7f2b8562 YX |
2244 | if (!rdev->ops->set_txq_params) |
2245 | return -EOPNOTSUPP; | |
31888487 | 2246 | |
7f2b8562 YX |
2247 | if (!netdev) |
2248 | return -EINVAL; | |
f70f01c2 | 2249 | |
133a3ff2 | 2250 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2251 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2252 | return -EINVAL; | |
133a3ff2 | 2253 | |
7f2b8562 YX |
2254 | if (!netif_running(netdev)) |
2255 | return -ENETDOWN; | |
2b5f8b0b | 2256 | |
31888487 JM |
2257 | nla_for_each_nested(nl_txq_params, |
2258 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2259 | rem_txq_params) { | |
ae811e21 JB |
2260 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2261 | nla_data(nl_txq_params), | |
2262 | nla_len(nl_txq_params), | |
2263 | txq_params_policy); | |
2264 | if (result) | |
2265 | return result; | |
31888487 JM |
2266 | result = parse_txq_params(tb, &txq_params); |
2267 | if (result) | |
7f2b8562 | 2268 | return result; |
31888487 | 2269 | |
e35e4d28 HG |
2270 | result = rdev_set_txq_params(rdev, netdev, |
2271 | &txq_params); | |
31888487 | 2272 | if (result) |
7f2b8562 | 2273 | return result; |
31888487 JM |
2274 | } |
2275 | } | |
55682965 | 2276 | |
72bdcf34 | 2277 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2278 | result = __nl80211_set_channel( |
2279 | rdev, | |
2280 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2281 | info); | |
72bdcf34 | 2282 | if (result) |
7f2b8562 | 2283 | return result; |
72bdcf34 JM |
2284 | } |
2285 | ||
98d2ff8b | 2286 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2287 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2288 | enum nl80211_tx_power_setting type; |
2289 | int idx, mbm = 0; | |
2290 | ||
c8442118 JB |
2291 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2292 | txp_wdev = NULL; | |
2293 | ||
7f2b8562 YX |
2294 | if (!rdev->ops->set_tx_power) |
2295 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2296 | |
2297 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2298 | type = nla_get_u32(info->attrs[idx]); | |
2299 | ||
2300 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2301 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2302 | return -EINVAL; | |
98d2ff8b JO |
2303 | |
2304 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2305 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2306 | mbm = nla_get_u32(info->attrs[idx]); | |
2307 | } | |
2308 | ||
c8442118 | 2309 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2310 | if (result) |
7f2b8562 | 2311 | return result; |
98d2ff8b JO |
2312 | } |
2313 | ||
afe0cbf8 BR |
2314 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2315 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2316 | u32 tx_ant, rx_ant; | |
7a087e74 | 2317 | |
7f531e03 BR |
2318 | if ((!rdev->wiphy.available_antennas_tx && |
2319 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2320 | !rdev->ops->set_antenna) |
2321 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2322 | |
2323 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2324 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2325 | ||
a7ffac95 | 2326 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2327 | * available antenna masks, except for the "all" mask */ |
2328 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2329 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2330 | return -EINVAL; | |
a7ffac95 | 2331 | |
7f531e03 BR |
2332 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2333 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2334 | |
e35e4d28 | 2335 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2336 | if (result) |
7f2b8562 | 2337 | return result; |
afe0cbf8 BR |
2338 | } |
2339 | ||
b9a5f8ca JM |
2340 | changed = 0; |
2341 | ||
2342 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2343 | retry_short = nla_get_u8( | |
2344 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2345 | if (retry_short == 0) |
2346 | return -EINVAL; | |
2347 | ||
b9a5f8ca JM |
2348 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2349 | } | |
2350 | ||
2351 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2352 | retry_long = nla_get_u8( | |
2353 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2354 | if (retry_long == 0) |
2355 | return -EINVAL; | |
2356 | ||
b9a5f8ca JM |
2357 | changed |= WIPHY_PARAM_RETRY_LONG; |
2358 | } | |
2359 | ||
2360 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2361 | frag_threshold = nla_get_u32( | |
2362 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2363 | if (frag_threshold < 256) |
2364 | return -EINVAL; | |
2365 | ||
b9a5f8ca JM |
2366 | if (frag_threshold != (u32) -1) { |
2367 | /* | |
2368 | * Fragments (apart from the last one) are required to | |
2369 | * have even length. Make the fragmentation code | |
2370 | * simpler by stripping LSB should someone try to use | |
2371 | * odd threshold value. | |
2372 | */ | |
2373 | frag_threshold &= ~0x1; | |
2374 | } | |
2375 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2376 | } | |
2377 | ||
2378 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2379 | rts_threshold = nla_get_u32( | |
2380 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2381 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2382 | } | |
2383 | ||
81077e82 | 2384 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
3057dbfd LB |
2385 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
2386 | return -EINVAL; | |
2387 | ||
81077e82 LT |
2388 | coverage_class = nla_get_u8( |
2389 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2390 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2391 | } | |
2392 | ||
3057dbfd LB |
2393 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
2394 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | |
2395 | return -EOPNOTSUPP; | |
2396 | ||
2397 | changed |= WIPHY_PARAM_DYN_ACK; | |
81077e82 LT |
2398 | } |
2399 | ||
b9a5f8ca JM |
2400 | if (changed) { |
2401 | u8 old_retry_short, old_retry_long; | |
2402 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2403 | u8 old_coverage_class; |
b9a5f8ca | 2404 | |
7f2b8562 YX |
2405 | if (!rdev->ops->set_wiphy_params) |
2406 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2407 | |
2408 | old_retry_short = rdev->wiphy.retry_short; | |
2409 | old_retry_long = rdev->wiphy.retry_long; | |
2410 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2411 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2412 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2413 | |
2414 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2415 | rdev->wiphy.retry_short = retry_short; | |
2416 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2417 | rdev->wiphy.retry_long = retry_long; | |
2418 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2419 | rdev->wiphy.frag_threshold = frag_threshold; | |
2420 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2421 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2422 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2423 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2424 | |
e35e4d28 | 2425 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2426 | if (result) { |
2427 | rdev->wiphy.retry_short = old_retry_short; | |
2428 | rdev->wiphy.retry_long = old_retry_long; | |
2429 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2430 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2431 | rdev->wiphy.coverage_class = old_coverage_class; |
9189ee31 | 2432 | return result; |
b9a5f8ca JM |
2433 | } |
2434 | } | |
7f2b8562 | 2435 | return 0; |
55682965 JB |
2436 | } |
2437 | ||
71bbc994 JB |
2438 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2439 | { | |
2440 | return (u64)wdev->identifier | | |
f26cbf40 | 2441 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2442 | } |
55682965 | 2443 | |
683b6d3b | 2444 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2445 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2446 | { |
601555cd JB |
2447 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
2448 | return -EINVAL; | |
3d9d1d66 | 2449 | |
683b6d3b JB |
2450 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2451 | chandef->chan->center_freq)) | |
2452 | return -ENOBUFS; | |
3d9d1d66 JB |
2453 | switch (chandef->width) { |
2454 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2455 | case NL80211_CHAN_WIDTH_20: | |
2456 | case NL80211_CHAN_WIDTH_40: | |
2457 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2458 | cfg80211_get_chandef_type(chandef))) | |
2459 | return -ENOBUFS; | |
2460 | break; | |
2461 | default: | |
2462 | break; | |
2463 | } | |
2464 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2465 | return -ENOBUFS; | |
2466 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2467 | return -ENOBUFS; | |
2468 | if (chandef->center_freq2 && | |
2469 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2470 | return -ENOBUFS; |
2471 | return 0; | |
2472 | } | |
2473 | ||
15e47304 | 2474 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2475 | struct cfg80211_registered_device *rdev, |
8f894be2 | 2476 | struct wireless_dev *wdev, bool removal) |
55682965 | 2477 | { |
72fb2abc | 2478 | struct net_device *dev = wdev->netdev; |
8f894be2 | 2479 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
55682965 JB |
2480 | void *hdr; |
2481 | ||
8f894be2 TB |
2482 | if (removal) |
2483 | cmd = NL80211_CMD_DEL_INTERFACE; | |
2484 | ||
2485 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | |
55682965 JB |
2486 | if (!hdr) |
2487 | return -1; | |
2488 | ||
72fb2abc JB |
2489 | if (dev && |
2490 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2491 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2492 | goto nla_put_failure; |
2493 | ||
2494 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2495 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
2dad624e ND |
2496 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
2497 | NL80211_ATTR_PAD) || | |
98104fde | 2498 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2499 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2500 | rdev->devlist_generation ^ | |
2501 | (cfg80211_rdev_list_generation << 2))) | |
2502 | goto nla_put_failure; | |
f5ea9120 | 2503 | |
5b7ccaf3 | 2504 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2505 | int ret; |
2506 | struct cfg80211_chan_def chandef; | |
2507 | ||
2508 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2509 | if (ret == 0) { | |
2510 | if (nl80211_send_chandef(msg, &chandef)) | |
2511 | goto nla_put_failure; | |
2512 | } | |
d91df0e3 PF |
2513 | } |
2514 | ||
d55d0d59 RM |
2515 | if (rdev->ops->get_tx_power) { |
2516 | int dbm, ret; | |
2517 | ||
2518 | ret = rdev_get_tx_power(rdev, wdev, &dbm); | |
2519 | if (ret == 0 && | |
2520 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, | |
2521 | DBM_TO_MBM(dbm))) | |
2522 | goto nla_put_failure; | |
2523 | } | |
2524 | ||
b84e7a05 AQ |
2525 | if (wdev->ssid_len) { |
2526 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2527 | goto nla_put_failure; | |
2528 | } | |
2529 | ||
053c095a JB |
2530 | genlmsg_end(msg, hdr); |
2531 | return 0; | |
55682965 JB |
2532 | |
2533 | nla_put_failure: | |
bc3ed28c TG |
2534 | genlmsg_cancel(msg, hdr); |
2535 | return -EMSGSIZE; | |
55682965 JB |
2536 | } |
2537 | ||
2538 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2539 | { | |
2540 | int wp_idx = 0; | |
2541 | int if_idx = 0; | |
2542 | int wp_start = cb->args[0]; | |
2543 | int if_start = cb->args[1]; | |
b7fb44da | 2544 | int filter_wiphy = -1; |
f5ea9120 | 2545 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2546 | struct wireless_dev *wdev; |
2547 | ||
5fe231e8 | 2548 | rtnl_lock(); |
b7fb44da DK |
2549 | if (!cb->args[2]) { |
2550 | struct nl80211_dump_wiphy_state state = { | |
2551 | .filter_wiphy = -1, | |
2552 | }; | |
2553 | int ret; | |
2554 | ||
2555 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); | |
2556 | if (ret) | |
2557 | return ret; | |
2558 | ||
2559 | filter_wiphy = state.filter_wiphy; | |
2560 | ||
2561 | /* | |
2562 | * if filtering, set cb->args[2] to +1 since 0 is the default | |
2563 | * value needed to determine that parsing is necessary. | |
2564 | */ | |
2565 | if (filter_wiphy >= 0) | |
2566 | cb->args[2] = filter_wiphy + 1; | |
2567 | else | |
2568 | cb->args[2] = -1; | |
2569 | } else if (cb->args[2] > 0) { | |
2570 | filter_wiphy = cb->args[2] - 1; | |
2571 | } | |
2572 | ||
f5ea9120 JB |
2573 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2574 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2575 | continue; |
bba95fef JB |
2576 | if (wp_idx < wp_start) { |
2577 | wp_idx++; | |
55682965 | 2578 | continue; |
bba95fef | 2579 | } |
b7fb44da DK |
2580 | |
2581 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) | |
2582 | continue; | |
2583 | ||
55682965 JB |
2584 | if_idx = 0; |
2585 | ||
53873f13 | 2586 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
bba95fef JB |
2587 | if (if_idx < if_start) { |
2588 | if_idx++; | |
55682965 | 2589 | continue; |
bba95fef | 2590 | } |
15e47304 | 2591 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2592 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
8f894be2 | 2593 | rdev, wdev, false) < 0) { |
bba95fef JB |
2594 | goto out; |
2595 | } | |
2596 | if_idx++; | |
55682965 | 2597 | } |
bba95fef JB |
2598 | |
2599 | wp_idx++; | |
55682965 | 2600 | } |
bba95fef | 2601 | out: |
5fe231e8 | 2602 | rtnl_unlock(); |
55682965 JB |
2603 | |
2604 | cb->args[0] = wp_idx; | |
2605 | cb->args[1] = if_idx; | |
2606 | ||
2607 | return skb->len; | |
2608 | } | |
2609 | ||
2610 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2611 | { | |
2612 | struct sk_buff *msg; | |
1b8ec87a | 2613 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2614 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2615 | |
fd2120ca | 2616 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2617 | if (!msg) |
4c476991 | 2618 | return -ENOMEM; |
55682965 | 2619 | |
15e47304 | 2620 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2621 | rdev, wdev, false) < 0) { |
4c476991 JB |
2622 | nlmsg_free(msg); |
2623 | return -ENOBUFS; | |
2624 | } | |
55682965 | 2625 | |
134e6375 | 2626 | return genlmsg_reply(msg, info); |
55682965 JB |
2627 | } |
2628 | ||
66f7ac50 MW |
2629 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2630 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2631 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2632 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2633 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2634 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2635 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2636 | }; |
2637 | ||
2638 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2639 | { | |
2640 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2641 | int flag; | |
2642 | ||
2643 | *mntrflags = 0; | |
2644 | ||
2645 | if (!nla) | |
2646 | return -EINVAL; | |
2647 | ||
2648 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2649 | nla, mntr_flags_policy)) | |
2650 | return -EINVAL; | |
2651 | ||
2652 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2653 | if (flags[flag]) | |
2654 | *mntrflags |= (1<<flag); | |
2655 | ||
2656 | return 0; | |
2657 | } | |
2658 | ||
9bc383de | 2659 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2660 | struct net_device *netdev, u8 use_4addr, |
2661 | enum nl80211_iftype iftype) | |
9bc383de | 2662 | { |
ad4bb6f8 | 2663 | if (!use_4addr) { |
f350a0a8 | 2664 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2665 | return -EBUSY; |
9bc383de | 2666 | return 0; |
ad4bb6f8 | 2667 | } |
9bc383de JB |
2668 | |
2669 | switch (iftype) { | |
2670 | case NL80211_IFTYPE_AP_VLAN: | |
2671 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2672 | return 0; | |
2673 | break; | |
2674 | case NL80211_IFTYPE_STATION: | |
2675 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2676 | return 0; | |
2677 | break; | |
2678 | default: | |
2679 | break; | |
2680 | } | |
2681 | ||
2682 | return -EOPNOTSUPP; | |
2683 | } | |
2684 | ||
55682965 JB |
2685 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2686 | { | |
4c476991 | 2687 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2688 | struct vif_params params; |
e36d56b6 | 2689 | int err; |
04a773ad | 2690 | enum nl80211_iftype otype, ntype; |
4c476991 | 2691 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2692 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2693 | bool change = false; |
55682965 | 2694 | |
2ec600d6 LCC |
2695 | memset(¶ms, 0, sizeof(params)); |
2696 | ||
04a773ad | 2697 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2698 | |
723b038d | 2699 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2700 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2701 | if (otype != ntype) |
ac7f9cfa | 2702 | change = true; |
4c476991 JB |
2703 | if (ntype > NL80211_IFTYPE_MAX) |
2704 | return -EINVAL; | |
723b038d JB |
2705 | } |
2706 | ||
92ffe055 | 2707 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2708 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2709 | ||
4c476991 JB |
2710 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2711 | return -EINVAL; | |
29cbe68c JB |
2712 | if (netif_running(dev)) |
2713 | return -EBUSY; | |
2714 | ||
2715 | wdev_lock(wdev); | |
2716 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2717 | IEEE80211_MAX_MESH_ID_LEN); | |
2718 | wdev->mesh_id_up_len = | |
2719 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2720 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2721 | wdev->mesh_id_up_len); | |
2722 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2723 | } |
2724 | ||
8b787643 FF |
2725 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2726 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2727 | change = true; | |
ad4bb6f8 | 2728 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2729 | if (err) |
4c476991 | 2730 | return err; |
8b787643 FF |
2731 | } else { |
2732 | params.use_4addr = -1; | |
2733 | } | |
2734 | ||
92ffe055 | 2735 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2736 | if (ntype != NL80211_IFTYPE_MONITOR) |
2737 | return -EINVAL; | |
92ffe055 JB |
2738 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2739 | &_flags); | |
ac7f9cfa | 2740 | if (err) |
4c476991 | 2741 | return err; |
ac7f9cfa JB |
2742 | |
2743 | flags = &_flags; | |
2744 | change = true; | |
92ffe055 | 2745 | } |
3b85875a | 2746 | |
c6e6a0c8 AE |
2747 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
2748 | const u8 *mumimo_groups; | |
2749 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; | |
2750 | ||
2751 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) | |
2752 | return -EOPNOTSUPP; | |
2753 | ||
2754 | mumimo_groups = | |
2755 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); | |
2756 | ||
2757 | /* bits 0 and 63 are reserved and must be zero */ | |
2758 | if ((mumimo_groups[0] & BIT(7)) || | |
2759 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0))) | |
2760 | return -EINVAL; | |
2761 | ||
2762 | memcpy(params.vht_mumimo_groups, mumimo_groups, | |
2763 | VHT_MUMIMO_GROUPS_DATA_LEN); | |
2764 | change = true; | |
2765 | } | |
2766 | ||
2767 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { | |
2768 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; | |
2769 | ||
2770 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) | |
2771 | return -EOPNOTSUPP; | |
2772 | ||
2773 | nla_memcpy(params.macaddr, | |
2774 | info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR], | |
2775 | ETH_ALEN); | |
2776 | change = true; | |
2777 | } | |
2778 | ||
18003297 | 2779 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2780 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2781 | return -EOPNOTSUPP; | |
2782 | ||
ac7f9cfa | 2783 | if (change) |
3d54d255 | 2784 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2785 | else |
2786 | err = 0; | |
60719ffd | 2787 | |
9bc383de JB |
2788 | if (!err && params.use_4addr != -1) |
2789 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2790 | ||
55682965 JB |
2791 | return err; |
2792 | } | |
2793 | ||
2794 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2795 | { | |
4c476991 | 2796 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2797 | struct vif_params params; |
84efbb84 | 2798 | struct wireless_dev *wdev; |
896ff063 | 2799 | struct sk_buff *msg; |
55682965 JB |
2800 | int err; |
2801 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2802 | u32 flags; |
55682965 | 2803 | |
78f22b6a JB |
2804 | /* to avoid failing a new interface creation due to pending removal */ |
2805 | cfg80211_destroy_ifaces(rdev); | |
2806 | ||
2ec600d6 LCC |
2807 | memset(¶ms, 0, sizeof(params)); |
2808 | ||
55682965 JB |
2809 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2810 | return -EINVAL; | |
2811 | ||
2812 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2813 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2814 | if (type > NL80211_IFTYPE_MAX) | |
2815 | return -EINVAL; | |
2816 | } | |
2817 | ||
79c97e97 | 2818 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2819 | !(rdev->wiphy.interface_modes & (1 << type))) |
2820 | return -EOPNOTSUPP; | |
55682965 | 2821 | |
e8f479b1 BG |
2822 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
2823 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && | |
2824 | info->attrs[NL80211_ATTR_MAC]) { | |
1c18f145 AS |
2825 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
2826 | ETH_ALEN); | |
2827 | if (!is_valid_ether_addr(params.macaddr)) | |
2828 | return -EADDRNOTAVAIL; | |
2829 | } | |
2830 | ||
9bc383de | 2831 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2832 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2833 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2834 | if (err) |
4c476991 | 2835 | return err; |
9bc383de | 2836 | } |
8b787643 | 2837 | |
66f7ac50 MW |
2838 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2839 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2840 | &flags); | |
e057d3c3 | 2841 | |
18003297 | 2842 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2843 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2844 | return -EOPNOTSUPP; | |
2845 | ||
a18c7192 JB |
2846 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2847 | if (!msg) | |
2848 | return -ENOMEM; | |
2849 | ||
e35e4d28 HG |
2850 | wdev = rdev_add_virtual_intf(rdev, |
2851 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
6bab2e19 TG |
2852 | NET_NAME_USER, type, err ? NULL : &flags, |
2853 | ¶ms); | |
d687cbb7 RM |
2854 | if (WARN_ON(!wdev)) { |
2855 | nlmsg_free(msg); | |
2856 | return -EPROTO; | |
2857 | } else if (IS_ERR(wdev)) { | |
1c90f9d4 | 2858 | nlmsg_free(msg); |
84efbb84 | 2859 | return PTR_ERR(wdev); |
1c90f9d4 | 2860 | } |
2ec600d6 | 2861 | |
18e5ca65 | 2862 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
78f22b6a JB |
2863 | wdev->owner_nlportid = info->snd_portid; |
2864 | ||
98104fde JB |
2865 | switch (type) { |
2866 | case NL80211_IFTYPE_MESH_POINT: | |
2867 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2868 | break; | |
29cbe68c JB |
2869 | wdev_lock(wdev); |
2870 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2871 | IEEE80211_MAX_MESH_ID_LEN); | |
2872 | wdev->mesh_id_up_len = | |
2873 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2874 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2875 | wdev->mesh_id_up_len); | |
2876 | wdev_unlock(wdev); | |
98104fde JB |
2877 | break; |
2878 | case NL80211_IFTYPE_P2P_DEVICE: | |
2879 | /* | |
2880 | * P2P Device doesn't have a netdev, so doesn't go | |
2881 | * through the netdev notifier and must be added here | |
2882 | */ | |
2883 | mutex_init(&wdev->mtx); | |
2884 | INIT_LIST_HEAD(&wdev->event_list); | |
2885 | spin_lock_init(&wdev->event_lock); | |
2886 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2887 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2888 | ||
98104fde | 2889 | wdev->identifier = ++rdev->wdev_id; |
53873f13 | 2890 | list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list); |
98104fde | 2891 | rdev->devlist_generation++; |
98104fde JB |
2892 | break; |
2893 | default: | |
2894 | break; | |
29cbe68c JB |
2895 | } |
2896 | ||
15e47304 | 2897 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2898 | rdev, wdev, false) < 0) { |
1c90f9d4 JB |
2899 | nlmsg_free(msg); |
2900 | return -ENOBUFS; | |
2901 | } | |
2902 | ||
896ff063 DK |
2903 | /* |
2904 | * For wdevs which have no associated netdev object (e.g. of type | |
2905 | * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here. | |
2906 | * For all other types, the event will be generated from the | |
2907 | * netdev notifier | |
2908 | */ | |
2909 | if (!wdev->netdev) | |
2910 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); | |
8f894be2 | 2911 | |
1c90f9d4 | 2912 | return genlmsg_reply(msg, info); |
55682965 JB |
2913 | } |
2914 | ||
2915 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2916 | { | |
4c476991 | 2917 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2918 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2919 | |
4c476991 JB |
2920 | if (!rdev->ops->del_virtual_intf) |
2921 | return -EOPNOTSUPP; | |
55682965 | 2922 | |
84efbb84 JB |
2923 | /* |
2924 | * If we remove a wireless device without a netdev then clear | |
2925 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2926 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2927 | * since the wdev has been freed, unlike with a netdev where | |
2928 | * we need the dev_put() for the netdev to really be freed. | |
2929 | */ | |
2930 | if (!wdev->netdev) | |
2931 | info->user_ptr[1] = NULL; | |
2932 | ||
7f8ed01e | 2933 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2934 | } |
2935 | ||
1d9d9213 SW |
2936 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2937 | { | |
2938 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2939 | struct net_device *dev = info->user_ptr[1]; | |
2940 | u16 noack_map; | |
2941 | ||
2942 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2943 | return -EINVAL; | |
2944 | ||
2945 | if (!rdev->ops->set_noack_map) | |
2946 | return -EOPNOTSUPP; | |
2947 | ||
2948 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2949 | ||
e35e4d28 | 2950 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2951 | } |
2952 | ||
41ade00f JB |
2953 | struct get_key_cookie { |
2954 | struct sk_buff *msg; | |
2955 | int error; | |
b9454e83 | 2956 | int idx; |
41ade00f JB |
2957 | }; |
2958 | ||
2959 | static void get_key_callback(void *c, struct key_params *params) | |
2960 | { | |
b9454e83 | 2961 | struct nlattr *key; |
41ade00f JB |
2962 | struct get_key_cookie *cookie = c; |
2963 | ||
9360ffd1 DM |
2964 | if ((params->key && |
2965 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2966 | params->key_len, params->key)) || | |
2967 | (params->seq && | |
2968 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2969 | params->seq_len, params->seq)) || | |
2970 | (params->cipher && | |
2971 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2972 | params->cipher))) | |
2973 | goto nla_put_failure; | |
41ade00f | 2974 | |
b9454e83 JB |
2975 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2976 | if (!key) | |
2977 | goto nla_put_failure; | |
2978 | ||
9360ffd1 DM |
2979 | if ((params->key && |
2980 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2981 | params->key_len, params->key)) || | |
2982 | (params->seq && | |
2983 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2984 | params->seq_len, params->seq)) || | |
2985 | (params->cipher && | |
2986 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2987 | params->cipher))) | |
2988 | goto nla_put_failure; | |
b9454e83 | 2989 | |
9360ffd1 DM |
2990 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2991 | goto nla_put_failure; | |
b9454e83 JB |
2992 | |
2993 | nla_nest_end(cookie->msg, key); | |
2994 | ||
41ade00f JB |
2995 | return; |
2996 | nla_put_failure: | |
2997 | cookie->error = 1; | |
2998 | } | |
2999 | ||
3000 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
3001 | { | |
4c476991 | 3002 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3003 | int err; |
4c476991 | 3004 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3005 | u8 key_idx = 0; |
e31b8213 JB |
3006 | const u8 *mac_addr = NULL; |
3007 | bool pairwise; | |
41ade00f JB |
3008 | struct get_key_cookie cookie = { |
3009 | .error = 0, | |
3010 | }; | |
3011 | void *hdr; | |
3012 | struct sk_buff *msg; | |
3013 | ||
3014 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
3015 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
3016 | ||
3cfcf6ac | 3017 | if (key_idx > 5) |
41ade00f JB |
3018 | return -EINVAL; |
3019 | ||
3020 | if (info->attrs[NL80211_ATTR_MAC]) | |
3021 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3022 | ||
e31b8213 JB |
3023 | pairwise = !!mac_addr; |
3024 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
3025 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
7a087e74 | 3026 | |
e31b8213 JB |
3027 | if (kt >= NUM_NL80211_KEYTYPES) |
3028 | return -EINVAL; | |
3029 | if (kt != NL80211_KEYTYPE_GROUP && | |
3030 | kt != NL80211_KEYTYPE_PAIRWISE) | |
3031 | return -EINVAL; | |
3032 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
3033 | } | |
3034 | ||
4c476991 JB |
3035 | if (!rdev->ops->get_key) |
3036 | return -EOPNOTSUPP; | |
41ade00f | 3037 | |
0fa7b391 JB |
3038 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
3039 | return -ENOENT; | |
3040 | ||
fd2120ca | 3041 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
3042 | if (!msg) |
3043 | return -ENOMEM; | |
41ade00f | 3044 | |
15e47304 | 3045 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 3046 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 3047 | if (!hdr) |
9fe271af | 3048 | goto nla_put_failure; |
41ade00f JB |
3049 | |
3050 | cookie.msg = msg; | |
b9454e83 | 3051 | cookie.idx = key_idx; |
41ade00f | 3052 | |
9360ffd1 DM |
3053 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3054 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
3055 | goto nla_put_failure; | |
3056 | if (mac_addr && | |
3057 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
3058 | goto nla_put_failure; | |
41ade00f | 3059 | |
e35e4d28 HG |
3060 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
3061 | get_key_callback); | |
41ade00f JB |
3062 | |
3063 | if (err) | |
6c95e2a2 | 3064 | goto free_msg; |
41ade00f JB |
3065 | |
3066 | if (cookie.error) | |
3067 | goto nla_put_failure; | |
3068 | ||
3069 | genlmsg_end(msg, hdr); | |
4c476991 | 3070 | return genlmsg_reply(msg, info); |
41ade00f JB |
3071 | |
3072 | nla_put_failure: | |
3073 | err = -ENOBUFS; | |
6c95e2a2 | 3074 | free_msg: |
41ade00f | 3075 | nlmsg_free(msg); |
41ade00f JB |
3076 | return err; |
3077 | } | |
3078 | ||
3079 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
3080 | { | |
4c476991 | 3081 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 3082 | struct key_parse key; |
41ade00f | 3083 | int err; |
4c476991 | 3084 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3085 | |
b9454e83 JB |
3086 | err = nl80211_parse_key(info, &key); |
3087 | if (err) | |
3088 | return err; | |
41ade00f | 3089 | |
b9454e83 | 3090 | if (key.idx < 0) |
41ade00f JB |
3091 | return -EINVAL; |
3092 | ||
b9454e83 JB |
3093 | /* only support setting default key */ |
3094 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
3095 | return -EINVAL; |
3096 | ||
dbd2fd65 | 3097 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 3098 | |
dbd2fd65 JB |
3099 | if (key.def) { |
3100 | if (!rdev->ops->set_default_key) { | |
3101 | err = -EOPNOTSUPP; | |
3102 | goto out; | |
3103 | } | |
41ade00f | 3104 | |
dbd2fd65 JB |
3105 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
3106 | if (err) | |
3107 | goto out; | |
3108 | ||
e35e4d28 | 3109 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
3110 | key.def_uni, key.def_multi); |
3111 | ||
3112 | if (err) | |
3113 | goto out; | |
fffd0934 | 3114 | |
3d23e349 | 3115 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
3116 | dev->ieee80211_ptr->wext.default_key = key.idx; |
3117 | #endif | |
3118 | } else { | |
3119 | if (key.def_uni || !key.def_multi) { | |
3120 | err = -EINVAL; | |
3121 | goto out; | |
3122 | } | |
3123 | ||
3124 | if (!rdev->ops->set_default_mgmt_key) { | |
3125 | err = -EOPNOTSUPP; | |
3126 | goto out; | |
3127 | } | |
3128 | ||
3129 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3130 | if (err) | |
3131 | goto out; | |
3132 | ||
e35e4d28 | 3133 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
3134 | if (err) |
3135 | goto out; | |
3136 | ||
3137 | #ifdef CONFIG_CFG80211_WEXT | |
3138 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 3139 | #endif |
dbd2fd65 JB |
3140 | } |
3141 | ||
3142 | out: | |
fffd0934 | 3143 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3144 | |
41ade00f JB |
3145 | return err; |
3146 | } | |
3147 | ||
3148 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
3149 | { | |
4c476991 | 3150 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 3151 | int err; |
4c476991 | 3152 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 3153 | struct key_parse key; |
e31b8213 | 3154 | const u8 *mac_addr = NULL; |
41ade00f | 3155 | |
b9454e83 JB |
3156 | err = nl80211_parse_key(info, &key); |
3157 | if (err) | |
3158 | return err; | |
41ade00f | 3159 | |
b9454e83 | 3160 | if (!key.p.key) |
41ade00f JB |
3161 | return -EINVAL; |
3162 | ||
41ade00f JB |
3163 | if (info->attrs[NL80211_ATTR_MAC]) |
3164 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3165 | ||
e31b8213 JB |
3166 | if (key.type == -1) { |
3167 | if (mac_addr) | |
3168 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3169 | else | |
3170 | key.type = NL80211_KEYTYPE_GROUP; | |
3171 | } | |
3172 | ||
3173 | /* for now */ | |
3174 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3175 | key.type != NL80211_KEYTYPE_GROUP) | |
3176 | return -EINVAL; | |
3177 | ||
4c476991 JB |
3178 | if (!rdev->ops->add_key) |
3179 | return -EOPNOTSUPP; | |
25e47c18 | 3180 | |
e31b8213 JB |
3181 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
3182 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3183 | mac_addr)) | |
4c476991 | 3184 | return -EINVAL; |
41ade00f | 3185 | |
fffd0934 JB |
3186 | wdev_lock(dev->ieee80211_ptr); |
3187 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3188 | if (!err) | |
e35e4d28 HG |
3189 | err = rdev_add_key(rdev, dev, key.idx, |
3190 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3191 | mac_addr, &key.p); | |
fffd0934 | 3192 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3193 | |
41ade00f JB |
3194 | return err; |
3195 | } | |
3196 | ||
3197 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
3198 | { | |
4c476991 | 3199 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3200 | int err; |
4c476991 | 3201 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3202 | u8 *mac_addr = NULL; |
b9454e83 | 3203 | struct key_parse key; |
41ade00f | 3204 | |
b9454e83 JB |
3205 | err = nl80211_parse_key(info, &key); |
3206 | if (err) | |
3207 | return err; | |
41ade00f JB |
3208 | |
3209 | if (info->attrs[NL80211_ATTR_MAC]) | |
3210 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3211 | ||
e31b8213 JB |
3212 | if (key.type == -1) { |
3213 | if (mac_addr) | |
3214 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3215 | else | |
3216 | key.type = NL80211_KEYTYPE_GROUP; | |
3217 | } | |
3218 | ||
3219 | /* for now */ | |
3220 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3221 | key.type != NL80211_KEYTYPE_GROUP) | |
3222 | return -EINVAL; | |
3223 | ||
4c476991 JB |
3224 | if (!rdev->ops->del_key) |
3225 | return -EOPNOTSUPP; | |
41ade00f | 3226 | |
fffd0934 JB |
3227 | wdev_lock(dev->ieee80211_ptr); |
3228 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 | 3229 | |
0fa7b391 | 3230 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
e31b8213 JB |
3231 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
3232 | err = -ENOENT; | |
3233 | ||
fffd0934 | 3234 | if (!err) |
e35e4d28 HG |
3235 | err = rdev_del_key(rdev, dev, key.idx, |
3236 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3237 | mac_addr); | |
41ade00f | 3238 | |
3d23e349 | 3239 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 3240 | if (!err) { |
b9454e83 | 3241 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 3242 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 3243 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
3244 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
3245 | } | |
3246 | #endif | |
fffd0934 | 3247 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 3248 | |
41ade00f JB |
3249 | return err; |
3250 | } | |
3251 | ||
77765eaf VT |
3252 | /* This function returns an error or the number of nested attributes */ |
3253 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
3254 | { | |
3255 | struct nlattr *attr; | |
3256 | int n_entries = 0, tmp; | |
3257 | ||
3258 | nla_for_each_nested(attr, nl_attr, tmp) { | |
3259 | if (nla_len(attr) != ETH_ALEN) | |
3260 | return -EINVAL; | |
3261 | ||
3262 | n_entries++; | |
3263 | } | |
3264 | ||
3265 | return n_entries; | |
3266 | } | |
3267 | ||
3268 | /* | |
3269 | * This function parses ACL information and allocates memory for ACL data. | |
3270 | * On successful return, the calling function is responsible to free the | |
3271 | * ACL buffer returned by this function. | |
3272 | */ | |
3273 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3274 | struct genl_info *info) | |
3275 | { | |
3276 | enum nl80211_acl_policy acl_policy; | |
3277 | struct nlattr *attr; | |
3278 | struct cfg80211_acl_data *acl; | |
3279 | int i = 0, n_entries, tmp; | |
3280 | ||
3281 | if (!wiphy->max_acl_mac_addrs) | |
3282 | return ERR_PTR(-EOPNOTSUPP); | |
3283 | ||
3284 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3285 | return ERR_PTR(-EINVAL); | |
3286 | ||
3287 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3288 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3289 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3290 | return ERR_PTR(-EINVAL); | |
3291 | ||
3292 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3293 | return ERR_PTR(-EINVAL); | |
3294 | ||
3295 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3296 | if (n_entries < 0) | |
3297 | return ERR_PTR(n_entries); | |
3298 | ||
3299 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3300 | return ERR_PTR(-ENOTSUPP); | |
3301 | ||
3302 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
3303 | GFP_KERNEL); | |
3304 | if (!acl) | |
3305 | return ERR_PTR(-ENOMEM); | |
3306 | ||
3307 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3308 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3309 | i++; | |
3310 | } | |
3311 | ||
3312 | acl->n_acl_entries = n_entries; | |
3313 | acl->acl_policy = acl_policy; | |
3314 | ||
3315 | return acl; | |
3316 | } | |
3317 | ||
3318 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3319 | { | |
3320 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3321 | struct net_device *dev = info->user_ptr[1]; | |
3322 | struct cfg80211_acl_data *acl; | |
3323 | int err; | |
3324 | ||
3325 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3326 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3327 | return -EOPNOTSUPP; | |
3328 | ||
3329 | if (!dev->ieee80211_ptr->beacon_interval) | |
3330 | return -EINVAL; | |
3331 | ||
3332 | acl = parse_acl_data(&rdev->wiphy, info); | |
3333 | if (IS_ERR(acl)) | |
3334 | return PTR_ERR(acl); | |
3335 | ||
3336 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3337 | ||
3338 | kfree(acl); | |
3339 | ||
3340 | return err; | |
3341 | } | |
3342 | ||
a7c7fbff PK |
3343 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
3344 | u8 *rates, u8 rates_len) | |
3345 | { | |
3346 | u8 i; | |
3347 | u32 mask = 0; | |
3348 | ||
3349 | for (i = 0; i < rates_len; i++) { | |
3350 | int rate = (rates[i] & 0x7f) * 5; | |
3351 | int ridx; | |
3352 | ||
3353 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
3354 | struct ieee80211_rate *srate = | |
3355 | &sband->bitrates[ridx]; | |
3356 | if (rate == srate->bitrate) { | |
3357 | mask |= 1 << ridx; | |
3358 | break; | |
3359 | } | |
3360 | } | |
3361 | if (ridx == sband->n_bitrates) | |
3362 | return 0; /* rate not found */ | |
3363 | } | |
3364 | ||
3365 | return mask; | |
3366 | } | |
3367 | ||
3368 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, | |
3369 | u8 *rates, u8 rates_len, | |
3370 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
3371 | { | |
3372 | u8 i; | |
3373 | ||
3374 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
3375 | ||
3376 | for (i = 0; i < rates_len; i++) { | |
3377 | int ridx, rbit; | |
3378 | ||
3379 | ridx = rates[i] / 8; | |
3380 | rbit = BIT(rates[i] % 8); | |
3381 | ||
3382 | /* check validity */ | |
3383 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) | |
3384 | return false; | |
3385 | ||
3386 | /* check availability */ | |
3387 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
3388 | mcs[ridx] |= rbit; | |
3389 | else | |
3390 | return false; | |
3391 | } | |
3392 | ||
3393 | return true; | |
3394 | } | |
3395 | ||
3396 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) | |
3397 | { | |
3398 | u16 mcs_mask = 0; | |
3399 | ||
3400 | switch (vht_mcs_map) { | |
3401 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
3402 | break; | |
3403 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
3404 | mcs_mask = 0x00FF; | |
3405 | break; | |
3406 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
3407 | mcs_mask = 0x01FF; | |
3408 | break; | |
3409 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
3410 | mcs_mask = 0x03FF; | |
3411 | break; | |
3412 | default: | |
3413 | break; | |
3414 | } | |
3415 | ||
3416 | return mcs_mask; | |
3417 | } | |
3418 | ||
3419 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
3420 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
3421 | { | |
3422 | u8 nss; | |
3423 | ||
3424 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
3425 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
3426 | vht_mcs_map >>= 2; | |
3427 | } | |
3428 | } | |
3429 | ||
3430 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
3431 | struct nl80211_txrate_vht *txrate, | |
3432 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
3433 | { | |
3434 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
3435 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
3436 | u8 i; | |
3437 | ||
3438 | if (!sband->vht_cap.vht_supported) | |
3439 | return false; | |
3440 | ||
3441 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
3442 | ||
3443 | /* Build vht_mcs_mask from VHT capabilities */ | |
3444 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
3445 | ||
3446 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
3447 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
3448 | mcs[i] = txrate->mcs[i]; | |
3449 | else | |
3450 | return false; | |
3451 | } | |
3452 | ||
3453 | return true; | |
3454 | } | |
3455 | ||
3456 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { | |
3457 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, | |
3458 | .len = NL80211_MAX_SUPP_RATES }, | |
3459 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, | |
3460 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
3461 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, | |
3462 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, | |
3463 | }; | |
3464 | ||
3465 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, | |
3466 | struct cfg80211_bitrate_mask *mask) | |
3467 | { | |
3468 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
3469 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3470 | int rem, i; | |
3471 | struct nlattr *tx_rates; | |
3472 | struct ieee80211_supported_band *sband; | |
3473 | u16 vht_tx_mcs_map; | |
3474 | ||
3475 | memset(mask, 0, sizeof(*mask)); | |
3476 | /* Default to all rates enabled */ | |
3477 | for (i = 0; i < NUM_NL80211_BANDS; i++) { | |
3478 | sband = rdev->wiphy.bands[i]; | |
3479 | ||
3480 | if (!sband) | |
3481 | continue; | |
3482 | ||
3483 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; | |
3484 | memcpy(mask->control[i].ht_mcs, | |
3485 | sband->ht_cap.mcs.rx_mask, | |
3486 | sizeof(mask->control[i].ht_mcs)); | |
3487 | ||
3488 | if (!sband->vht_cap.vht_supported) | |
3489 | continue; | |
3490 | ||
3491 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
3492 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); | |
3493 | } | |
3494 | ||
3495 | /* if no rates are given set it back to the defaults */ | |
3496 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
3497 | goto out; | |
3498 | ||
3499 | /* The nested attribute uses enum nl80211_band as the index. This maps | |
3500 | * directly to the enum nl80211_band values used in cfg80211. | |
3501 | */ | |
3502 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); | |
3503 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { | |
3504 | enum nl80211_band band = nla_type(tx_rates); | |
3505 | int err; | |
3506 | ||
3507 | if (band < 0 || band >= NUM_NL80211_BANDS) | |
3508 | return -EINVAL; | |
3509 | sband = rdev->wiphy.bands[band]; | |
3510 | if (sband == NULL) | |
3511 | return -EINVAL; | |
3512 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), | |
3513 | nla_len(tx_rates), nl80211_txattr_policy); | |
3514 | if (err) | |
3515 | return err; | |
3516 | if (tb[NL80211_TXRATE_LEGACY]) { | |
3517 | mask->control[band].legacy = rateset_to_mask( | |
3518 | sband, | |
3519 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
3520 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
3521 | if ((mask->control[band].legacy == 0) && | |
3522 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
3523 | return -EINVAL; | |
3524 | } | |
3525 | if (tb[NL80211_TXRATE_HT]) { | |
3526 | if (!ht_rateset_to_mask( | |
3527 | sband, | |
3528 | nla_data(tb[NL80211_TXRATE_HT]), | |
3529 | nla_len(tb[NL80211_TXRATE_HT]), | |
3530 | mask->control[band].ht_mcs)) | |
3531 | return -EINVAL; | |
3532 | } | |
3533 | if (tb[NL80211_TXRATE_VHT]) { | |
3534 | if (!vht_set_mcs_mask( | |
3535 | sband, | |
3536 | nla_data(tb[NL80211_TXRATE_VHT]), | |
3537 | mask->control[band].vht_mcs)) | |
3538 | return -EINVAL; | |
3539 | } | |
3540 | if (tb[NL80211_TXRATE_GI]) { | |
3541 | mask->control[band].gi = | |
3542 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
3543 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
3544 | return -EINVAL; | |
3545 | } | |
3546 | ||
3547 | if (mask->control[band].legacy == 0) { | |
3548 | /* don't allow empty legacy rates if HT or VHT | |
3549 | * are not even supported. | |
3550 | */ | |
3551 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
3552 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
3553 | return -EINVAL; | |
3554 | ||
3555 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
3556 | if (mask->control[band].ht_mcs[i]) | |
3557 | goto out; | |
3558 | ||
3559 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
3560 | if (mask->control[band].vht_mcs[i]) | |
3561 | goto out; | |
3562 | ||
3563 | /* legacy and mcs rates may not be both empty */ | |
3564 | return -EINVAL; | |
3565 | } | |
3566 | } | |
3567 | ||
3568 | out: | |
3569 | return 0; | |
3570 | } | |
3571 | ||
8564e382 JB |
3572 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
3573 | enum nl80211_band band, | |
3574 | struct cfg80211_bitrate_mask *beacon_rate) | |
a7c7fbff | 3575 | { |
8564e382 JB |
3576 | u32 count_ht, count_vht, i; |
3577 | u32 rate = beacon_rate->control[band].legacy; | |
a7c7fbff PK |
3578 | |
3579 | /* Allow only one rate */ | |
3580 | if (hweight32(rate) > 1) | |
3581 | return -EINVAL; | |
3582 | ||
3583 | count_ht = 0; | |
3584 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { | |
8564e382 | 3585 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
a7c7fbff | 3586 | return -EINVAL; |
8564e382 | 3587 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
a7c7fbff PK |
3588 | count_ht++; |
3589 | if (count_ht > 1) | |
3590 | return -EINVAL; | |
3591 | } | |
3592 | if (count_ht && rate) | |
3593 | return -EINVAL; | |
3594 | } | |
3595 | ||
3596 | count_vht = 0; | |
3597 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
8564e382 | 3598 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
a7c7fbff | 3599 | return -EINVAL; |
8564e382 | 3600 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
a7c7fbff PK |
3601 | count_vht++; |
3602 | if (count_vht > 1) | |
3603 | return -EINVAL; | |
3604 | } | |
3605 | if (count_vht && rate) | |
3606 | return -EINVAL; | |
3607 | } | |
3608 | ||
3609 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) | |
3610 | return -EINVAL; | |
3611 | ||
8564e382 JB |
3612 | if (rate && |
3613 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
3614 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) | |
3615 | return -EINVAL; | |
3616 | if (count_ht && | |
3617 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
3618 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) | |
3619 | return -EINVAL; | |
3620 | if (count_vht && | |
3621 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
3622 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) | |
3623 | return -EINVAL; | |
3624 | ||
a7c7fbff PK |
3625 | return 0; |
3626 | } | |
3627 | ||
a1193be8 | 3628 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3629 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3630 | { |
8860020e | 3631 | bool haveinfo = false; |
ed1b6cc7 | 3632 | |
a1193be8 SW |
3633 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3634 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3635 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3636 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3637 | return -EINVAL; |
3638 | ||
8860020e | 3639 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3640 | |
a1193be8 SW |
3641 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3642 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3643 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3644 | if (!bcn->head_len) |
3645 | return -EINVAL; | |
3646 | haveinfo = true; | |
ed1b6cc7 JB |
3647 | } |
3648 | ||
a1193be8 SW |
3649 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3650 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3651 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3652 | haveinfo = true; |
ed1b6cc7 JB |
3653 | } |
3654 | ||
4c476991 JB |
3655 | if (!haveinfo) |
3656 | return -EINVAL; | |
3b85875a | 3657 | |
a1193be8 SW |
3658 | if (attrs[NL80211_ATTR_IE]) { |
3659 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3660 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3661 | } |
3662 | ||
a1193be8 | 3663 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3664 | bcn->proberesp_ies = |
a1193be8 | 3665 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3666 | bcn->proberesp_ies_len = |
a1193be8 | 3667 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3668 | } |
3669 | ||
a1193be8 | 3670 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3671 | bcn->assocresp_ies = |
a1193be8 | 3672 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3673 | bcn->assocresp_ies_len = |
a1193be8 | 3674 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3675 | } |
3676 | ||
a1193be8 SW |
3677 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3678 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3679 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3680 | } |
3681 | ||
8860020e JB |
3682 | return 0; |
3683 | } | |
3684 | ||
46c1dd0c FF |
3685 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3686 | struct cfg80211_ap_settings *params) | |
3687 | { | |
3688 | struct wireless_dev *wdev; | |
3689 | bool ret = false; | |
3690 | ||
53873f13 | 3691 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
46c1dd0c FF |
3692 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3693 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3694 | continue; | |
3695 | ||
683b6d3b | 3696 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3697 | continue; |
3698 | ||
683b6d3b | 3699 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3700 | ret = true; |
3701 | break; | |
3702 | } | |
3703 | ||
46c1dd0c FF |
3704 | return ret; |
3705 | } | |
3706 | ||
e39e5b5e JM |
3707 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3708 | enum nl80211_auth_type auth_type, | |
3709 | enum nl80211_commands cmd) | |
3710 | { | |
3711 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3712 | return false; | |
3713 | ||
3714 | switch (cmd) { | |
3715 | case NL80211_CMD_AUTHENTICATE: | |
3716 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3717 | auth_type == NL80211_AUTHTYPE_SAE) | |
3718 | return false; | |
3719 | return true; | |
3720 | case NL80211_CMD_CONNECT: | |
3721 | case NL80211_CMD_START_AP: | |
3722 | /* SAE not supported yet */ | |
3723 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3724 | return false; | |
3725 | return true; | |
3726 | default: | |
3727 | return false; | |
3728 | } | |
3729 | } | |
3730 | ||
8860020e JB |
3731 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3732 | { | |
3733 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3734 | struct net_device *dev = info->user_ptr[1]; | |
3735 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3736 | struct cfg80211_ap_settings params; | |
3737 | int err; | |
3738 | ||
3739 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3740 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3741 | return -EOPNOTSUPP; | |
3742 | ||
3743 | if (!rdev->ops->start_ap) | |
3744 | return -EOPNOTSUPP; | |
3745 | ||
3746 | if (wdev->beacon_interval) | |
3747 | return -EALREADY; | |
3748 | ||
3749 | memset(¶ms, 0, sizeof(params)); | |
3750 | ||
3751 | /* these are required for START_AP */ | |
3752 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3753 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3754 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3755 | return -EINVAL; | |
3756 | ||
a1193be8 | 3757 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3758 | if (err) |
3759 | return err; | |
3760 | ||
3761 | params.beacon_interval = | |
3762 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3763 | params.dtim_period = | |
3764 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3765 | ||
3766 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3767 | if (err) | |
3768 | return err; | |
3769 | ||
3770 | /* | |
3771 | * In theory, some of these attributes should be required here | |
3772 | * but since they were not used when the command was originally | |
3773 | * added, keep them optional for old user space programs to let | |
3774 | * them continue to work with drivers that do not need the | |
3775 | * additional information -- drivers must check! | |
3776 | */ | |
3777 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3778 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3779 | params.ssid_len = | |
3780 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3781 | if (params.ssid_len == 0 || | |
3782 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3783 | return -EINVAL; | |
3784 | } | |
3785 | ||
3786 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3787 | params.hidden_ssid = nla_get_u32( | |
3788 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3789 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3790 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3791 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3792 | return -EINVAL; | |
3793 | } | |
3794 | ||
3795 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3796 | ||
3797 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3798 | params.auth_type = nla_get_u32( | |
3799 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3800 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3801 | NL80211_CMD_START_AP)) | |
8860020e JB |
3802 | return -EINVAL; |
3803 | } else | |
3804 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3805 | ||
3806 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3807 | NL80211_MAX_NR_CIPHER_SUITES); | |
3808 | if (err) | |
3809 | return err; | |
3810 | ||
1b658f11 VT |
3811 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3812 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3813 | return -EOPNOTSUPP; | |
3814 | params.inactivity_timeout = nla_get_u16( | |
3815 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3816 | } | |
3817 | ||
53cabad7 JB |
3818 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3819 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3820 | return -EINVAL; | |
3821 | params.p2p_ctwindow = | |
3822 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3823 | if (params.p2p_ctwindow > 127) | |
3824 | return -EINVAL; | |
3825 | if (params.p2p_ctwindow != 0 && | |
3826 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3827 | return -EINVAL; | |
3828 | } | |
3829 | ||
3830 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3831 | u8 tmp; | |
3832 | ||
3833 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3834 | return -EINVAL; | |
3835 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3836 | if (tmp > 1) | |
3837 | return -EINVAL; | |
3838 | params.p2p_opp_ps = tmp; | |
3839 | if (params.p2p_opp_ps != 0 && | |
3840 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3841 | return -EINVAL; | |
3842 | } | |
3843 | ||
aa430da4 | 3844 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3845 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3846 | if (err) | |
3847 | return err; | |
3848 | } else if (wdev->preset_chandef.chan) { | |
3849 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3850 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3851 | return -EINVAL; |
3852 | ||
923b352f AN |
3853 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
3854 | wdev->iftype)) | |
aa430da4 JB |
3855 | return -EINVAL; |
3856 | ||
a7c7fbff PK |
3857 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
3858 | err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate); | |
3859 | if (err) | |
3860 | return err; | |
3861 | ||
8564e382 JB |
3862 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
3863 | ¶ms.beacon_rate); | |
a7c7fbff PK |
3864 | if (err) |
3865 | return err; | |
3866 | } | |
3867 | ||
18998c38 EP |
3868 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
3869 | params.smps_mode = | |
3870 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); | |
3871 | switch (params.smps_mode) { | |
3872 | case NL80211_SMPS_OFF: | |
3873 | break; | |
3874 | case NL80211_SMPS_STATIC: | |
3875 | if (!(rdev->wiphy.features & | |
3876 | NL80211_FEATURE_STATIC_SMPS)) | |
3877 | return -EINVAL; | |
3878 | break; | |
3879 | case NL80211_SMPS_DYNAMIC: | |
3880 | if (!(rdev->wiphy.features & | |
3881 | NL80211_FEATURE_DYNAMIC_SMPS)) | |
3882 | return -EINVAL; | |
3883 | break; | |
3884 | default: | |
3885 | return -EINVAL; | |
3886 | } | |
3887 | } else { | |
3888 | params.smps_mode = NL80211_SMPS_OFF; | |
3889 | } | |
3890 | ||
6e8ef842 PK |
3891 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
3892 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) | |
3893 | return -EOPNOTSUPP; | |
3894 | ||
4baf6bea OO |
3895 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3896 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3897 | if (IS_ERR(params.acl)) | |
3898 | return PTR_ERR(params.acl); | |
3899 | } | |
3900 | ||
c56589ed | 3901 | wdev_lock(wdev); |
e35e4d28 | 3902 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3903 | if (!err) { |
683b6d3b | 3904 | wdev->preset_chandef = params.chandef; |
8860020e | 3905 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 3906 | wdev->chandef = params.chandef; |
06e191e2 AQ |
3907 | wdev->ssid_len = params.ssid_len; |
3908 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3909 | } |
c56589ed | 3910 | wdev_unlock(wdev); |
77765eaf VT |
3911 | |
3912 | kfree(params.acl); | |
3913 | ||
56d1893d | 3914 | return err; |
ed1b6cc7 JB |
3915 | } |
3916 | ||
8860020e JB |
3917 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3918 | { | |
3919 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3920 | struct net_device *dev = info->user_ptr[1]; | |
3921 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3922 | struct cfg80211_beacon_data params; | |
3923 | int err; | |
3924 | ||
3925 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3926 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3927 | return -EOPNOTSUPP; | |
3928 | ||
3929 | if (!rdev->ops->change_beacon) | |
3930 | return -EOPNOTSUPP; | |
3931 | ||
3932 | if (!wdev->beacon_interval) | |
3933 | return -EINVAL; | |
3934 | ||
a1193be8 | 3935 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3936 | if (err) |
3937 | return err; | |
3938 | ||
c56589ed SW |
3939 | wdev_lock(wdev); |
3940 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3941 | wdev_unlock(wdev); | |
3942 | ||
3943 | return err; | |
8860020e JB |
3944 | } |
3945 | ||
3946 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3947 | { |
4c476991 JB |
3948 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3949 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3950 | |
7c8d5e03 | 3951 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
3952 | } |
3953 | ||
5727ef1b JB |
3954 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3955 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3956 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3957 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3958 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3959 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3960 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3961 | }; |
3962 | ||
eccb8e8f | 3963 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3964 | enum nl80211_iftype iftype, |
eccb8e8f | 3965 | struct station_parameters *params) |
5727ef1b JB |
3966 | { |
3967 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3968 | struct nlattr *nla; |
5727ef1b JB |
3969 | int flag; |
3970 | ||
eccb8e8f JB |
3971 | /* |
3972 | * Try parsing the new attribute first so userspace | |
3973 | * can specify both for older kernels. | |
3974 | */ | |
3975 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3976 | if (nla) { | |
3977 | struct nl80211_sta_flag_update *sta_flags; | |
3978 | ||
3979 | sta_flags = nla_data(nla); | |
3980 | params->sta_flags_mask = sta_flags->mask; | |
3981 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3982 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3983 | if ((params->sta_flags_mask | |
3984 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3985 | return -EINVAL; | |
3986 | return 0; | |
3987 | } | |
3988 | ||
3989 | /* if present, parse the old attribute */ | |
5727ef1b | 3990 | |
eccb8e8f | 3991 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3992 | if (!nla) |
3993 | return 0; | |
3994 | ||
3995 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3996 | nla, sta_flags_policy)) | |
3997 | return -EINVAL; | |
3998 | ||
bdd3ae3d JB |
3999 | /* |
4000 | * Only allow certain flags for interface types so that | |
4001 | * other attributes are silently ignored. Remember that | |
4002 | * this is backward compatibility code with old userspace | |
4003 | * and shouldn't be hit in other cases anyway. | |
4004 | */ | |
4005 | switch (iftype) { | |
4006 | case NL80211_IFTYPE_AP: | |
4007 | case NL80211_IFTYPE_AP_VLAN: | |
4008 | case NL80211_IFTYPE_P2P_GO: | |
4009 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4010 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
4011 | BIT(NL80211_STA_FLAG_WME) | | |
4012 | BIT(NL80211_STA_FLAG_MFP); | |
4013 | break; | |
4014 | case NL80211_IFTYPE_P2P_CLIENT: | |
4015 | case NL80211_IFTYPE_STATION: | |
4016 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4017 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
4018 | break; | |
4019 | case NL80211_IFTYPE_MESH_POINT: | |
4020 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4021 | BIT(NL80211_STA_FLAG_MFP) | | |
4022 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
4023 | default: | |
4024 | return -EINVAL; | |
4025 | } | |
5727ef1b | 4026 | |
3383b5a6 JB |
4027 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
4028 | if (flags[flag]) { | |
eccb8e8f | 4029 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 4030 | |
3383b5a6 JB |
4031 | /* no longer support new API additions in old API */ |
4032 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
4033 | return -EINVAL; | |
4034 | } | |
4035 | } | |
4036 | ||
5727ef1b JB |
4037 | return 0; |
4038 | } | |
4039 | ||
c8dcfd8a FF |
4040 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
4041 | int attr) | |
4042 | { | |
4043 | struct nlattr *rate; | |
8eb41c8d VK |
4044 | u32 bitrate; |
4045 | u16 bitrate_compat; | |
b51f3bee | 4046 | enum nl80211_attrs rate_flg; |
c8dcfd8a FF |
4047 | |
4048 | rate = nla_nest_start(msg, attr); | |
4049 | if (!rate) | |
db9c64cf | 4050 | return false; |
c8dcfd8a FF |
4051 | |
4052 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
4053 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
4054 | /* report 16-bit bitrate only if we can */ |
4055 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
4056 | if (bitrate > 0 && |
4057 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
4058 | return false; | |
4059 | if (bitrate_compat > 0 && | |
4060 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
4061 | return false; | |
4062 | ||
b51f3bee JB |
4063 | switch (info->bw) { |
4064 | case RATE_INFO_BW_5: | |
4065 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; | |
4066 | break; | |
4067 | case RATE_INFO_BW_10: | |
4068 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; | |
4069 | break; | |
4070 | default: | |
4071 | WARN_ON(1); | |
4072 | /* fall through */ | |
4073 | case RATE_INFO_BW_20: | |
4074 | rate_flg = 0; | |
4075 | break; | |
4076 | case RATE_INFO_BW_40: | |
4077 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; | |
4078 | break; | |
4079 | case RATE_INFO_BW_80: | |
4080 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; | |
4081 | break; | |
4082 | case RATE_INFO_BW_160: | |
4083 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; | |
4084 | break; | |
4085 | } | |
4086 | ||
4087 | if (rate_flg && nla_put_flag(msg, rate_flg)) | |
4088 | return false; | |
4089 | ||
db9c64cf JB |
4090 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
4091 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
4092 | return false; | |
db9c64cf JB |
4093 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
4094 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
4095 | return false; | |
4096 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
4097 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
4098 | return false; | |
4099 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
4100 | return false; | |
db9c64cf JB |
4101 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
4102 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
4103 | return false; | |
4104 | } | |
c8dcfd8a FF |
4105 | |
4106 | nla_nest_end(msg, rate); | |
4107 | return true; | |
c8dcfd8a FF |
4108 | } |
4109 | ||
119363c7 FF |
4110 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
4111 | int id) | |
4112 | { | |
4113 | void *attr; | |
4114 | int i = 0; | |
4115 | ||
4116 | if (!mask) | |
4117 | return true; | |
4118 | ||
4119 | attr = nla_nest_start(msg, id); | |
4120 | if (!attr) | |
4121 | return false; | |
4122 | ||
4123 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
4124 | if (!(mask & BIT(i))) | |
4125 | continue; | |
4126 | ||
4127 | if (nla_put_u8(msg, i, signal[i])) | |
4128 | return false; | |
4129 | } | |
4130 | ||
4131 | nla_nest_end(msg, attr); | |
4132 | ||
4133 | return true; | |
4134 | } | |
4135 | ||
cf5ead82 JB |
4136 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
4137 | u32 seq, int flags, | |
66266b3a JL |
4138 | struct cfg80211_registered_device *rdev, |
4139 | struct net_device *dev, | |
98b62183 | 4140 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
4141 | { |
4142 | void *hdr; | |
f4263c98 | 4143 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 4144 | |
cf5ead82 | 4145 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
fd5b74dc JB |
4146 | if (!hdr) |
4147 | return -1; | |
4148 | ||
9360ffd1 DM |
4149 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4150 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
4151 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
4152 | goto nla_put_failure; | |
f5ea9120 | 4153 | |
2ec600d6 LCC |
4154 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
4155 | if (!sinfoattr) | |
fd5b74dc | 4156 | goto nla_put_failure; |
319090bf JB |
4157 | |
4158 | #define PUT_SINFO(attr, memb, type) do { \ | |
d686b920 | 4159 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
739960f1 | 4160 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
319090bf JB |
4161 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
4162 | sinfo->memb)) \ | |
4163 | goto nla_put_failure; \ | |
4164 | } while (0) | |
d686b920 JB |
4165 | #define PUT_SINFO_U64(attr, memb) do { \ |
4166 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ | |
4167 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ | |
4168 | sinfo->memb, NL80211_STA_INFO_PAD)) \ | |
4169 | goto nla_put_failure; \ | |
4170 | } while (0) | |
319090bf JB |
4171 | |
4172 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); | |
4173 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); | |
4174 | ||
4175 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | | |
4176 | BIT(NL80211_STA_INFO_RX_BYTES64)) && | |
9360ffd1 | 4177 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 4178 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 4179 | goto nla_put_failure; |
319090bf JB |
4180 | |
4181 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | | |
4182 | BIT(NL80211_STA_INFO_TX_BYTES64)) && | |
9360ffd1 | 4183 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
4184 | (u32)sinfo->tx_bytes)) |
4185 | goto nla_put_failure; | |
319090bf | 4186 | |
d686b920 JB |
4187 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
4188 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); | |
319090bf JB |
4189 | PUT_SINFO(LLID, llid, u16); |
4190 | PUT_SINFO(PLID, plid, u16); | |
4191 | PUT_SINFO(PLINK_STATE, plink_state, u8); | |
d686b920 | 4192 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
319090bf | 4193 | |
66266b3a JL |
4194 | switch (rdev->wiphy.signal_type) { |
4195 | case CFG80211_SIGNAL_TYPE_MBM: | |
319090bf JB |
4196 | PUT_SINFO(SIGNAL, signal, u8); |
4197 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); | |
66266b3a JL |
4198 | break; |
4199 | default: | |
4200 | break; | |
4201 | } | |
319090bf | 4202 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
119363c7 FF |
4203 | if (!nl80211_put_signal(msg, sinfo->chains, |
4204 | sinfo->chain_signal, | |
4205 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
4206 | goto nla_put_failure; | |
4207 | } | |
319090bf | 4208 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
119363c7 FF |
4209 | if (!nl80211_put_signal(msg, sinfo->chains, |
4210 | sinfo->chain_signal_avg, | |
4211 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
4212 | goto nla_put_failure; | |
4213 | } | |
319090bf | 4214 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
c8dcfd8a FF |
4215 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
4216 | NL80211_STA_INFO_TX_BITRATE)) | |
4217 | goto nla_put_failure; | |
4218 | } | |
319090bf | 4219 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
c8dcfd8a FF |
4220 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
4221 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 4222 | goto nla_put_failure; |
420e7fab | 4223 | } |
319090bf JB |
4224 | |
4225 | PUT_SINFO(RX_PACKETS, rx_packets, u32); | |
4226 | PUT_SINFO(TX_PACKETS, tx_packets, u32); | |
4227 | PUT_SINFO(TX_RETRIES, tx_retries, u32); | |
4228 | PUT_SINFO(TX_FAILED, tx_failed, u32); | |
4229 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); | |
4230 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); | |
4231 | PUT_SINFO(LOCAL_PM, local_pm, u32); | |
4232 | PUT_SINFO(PEER_PM, peer_pm, u32); | |
4233 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); | |
4234 | ||
4235 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { | |
f4263c98 PS |
4236 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
4237 | if (!bss_param) | |
4238 | goto nla_put_failure; | |
4239 | ||
9360ffd1 DM |
4240 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
4241 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
4242 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
4243 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
4244 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
4245 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
4246 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
4247 | sinfo->bss_param.dtim_period) || | |
4248 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
4249 | sinfo->bss_param.beacon_interval)) | |
4250 | goto nla_put_failure; | |
f4263c98 PS |
4251 | |
4252 | nla_nest_end(msg, bss_param); | |
4253 | } | |
319090bf | 4254 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
9360ffd1 DM |
4255 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
4256 | sizeof(struct nl80211_sta_flag_update), | |
4257 | &sinfo->sta_flags)) | |
4258 | goto nla_put_failure; | |
319090bf | 4259 | |
d686b920 JB |
4260 | PUT_SINFO_U64(T_OFFSET, t_offset); |
4261 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); | |
4262 | PUT_SINFO_U64(BEACON_RX, rx_beacon); | |
a76b1942 | 4263 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
319090bf JB |
4264 | |
4265 | #undef PUT_SINFO | |
d686b920 | 4266 | #undef PUT_SINFO_U64 |
6de39808 JB |
4267 | |
4268 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { | |
4269 | struct nlattr *tidsattr; | |
4270 | int tid; | |
4271 | ||
4272 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); | |
4273 | if (!tidsattr) | |
4274 | goto nla_put_failure; | |
4275 | ||
4276 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { | |
4277 | struct cfg80211_tid_stats *tidstats; | |
4278 | struct nlattr *tidattr; | |
4279 | ||
4280 | tidstats = &sinfo->pertid[tid]; | |
4281 | ||
4282 | if (!tidstats->filled) | |
4283 | continue; | |
4284 | ||
4285 | tidattr = nla_nest_start(msg, tid + 1); | |
4286 | if (!tidattr) | |
4287 | goto nla_put_failure; | |
4288 | ||
d686b920 | 4289 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
6de39808 | 4290 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
d686b920 JB |
4291 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
4292 | tidstats->memb, NL80211_TID_STATS_PAD)) \ | |
6de39808 JB |
4293 | goto nla_put_failure; \ |
4294 | } while (0) | |
4295 | ||
d686b920 JB |
4296 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
4297 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); | |
4298 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); | |
4299 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); | |
6de39808 | 4300 | |
d686b920 | 4301 | #undef PUT_TIDVAL_U64 |
6de39808 JB |
4302 | nla_nest_end(msg, tidattr); |
4303 | } | |
4304 | ||
4305 | nla_nest_end(msg, tidsattr); | |
4306 | } | |
4307 | ||
2ec600d6 | 4308 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 4309 | |
319090bf | 4310 | if (sinfo->assoc_req_ies_len && |
9360ffd1 DM |
4311 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
4312 | sinfo->assoc_req_ies)) | |
4313 | goto nla_put_failure; | |
50d3dfb7 | 4314 | |
053c095a JB |
4315 | genlmsg_end(msg, hdr); |
4316 | return 0; | |
fd5b74dc JB |
4317 | |
4318 | nla_put_failure: | |
bc3ed28c TG |
4319 | genlmsg_cancel(msg, hdr); |
4320 | return -EMSGSIZE; | |
fd5b74dc JB |
4321 | } |
4322 | ||
2ec600d6 | 4323 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 4324 | struct netlink_callback *cb) |
2ec600d6 | 4325 | { |
2ec600d6 | 4326 | struct station_info sinfo; |
1b8ec87a | 4327 | struct cfg80211_registered_device *rdev; |
97990a06 | 4328 | struct wireless_dev *wdev; |
2ec600d6 | 4329 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 4330 | int sta_idx = cb->args[2]; |
2ec600d6 | 4331 | int err; |
2ec600d6 | 4332 | |
1b8ec87a | 4333 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
4334 | if (err) |
4335 | return err; | |
bba95fef | 4336 | |
97990a06 JB |
4337 | if (!wdev->netdev) { |
4338 | err = -EINVAL; | |
4339 | goto out_err; | |
4340 | } | |
4341 | ||
1b8ec87a | 4342 | if (!rdev->ops->dump_station) { |
eec60b03 | 4343 | err = -EOPNOTSUPP; |
bba95fef JB |
4344 | goto out_err; |
4345 | } | |
4346 | ||
bba95fef | 4347 | while (1) { |
f612cedf | 4348 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 4349 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
e35e4d28 | 4350 | mac_addr, &sinfo); |
bba95fef JB |
4351 | if (err == -ENOENT) |
4352 | break; | |
4353 | if (err) | |
3b85875a | 4354 | goto out_err; |
bba95fef | 4355 | |
cf5ead82 | 4356 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
15e47304 | 4357 | NETLINK_CB(cb->skb).portid, |
bba95fef | 4358 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 4359 | rdev, wdev->netdev, mac_addr, |
bba95fef JB |
4360 | &sinfo) < 0) |
4361 | goto out; | |
4362 | ||
4363 | sta_idx++; | |
4364 | } | |
4365 | ||
bba95fef | 4366 | out: |
97990a06 | 4367 | cb->args[2] = sta_idx; |
bba95fef | 4368 | err = skb->len; |
bba95fef | 4369 | out_err: |
1b8ec87a | 4370 | nl80211_finish_wdev_dump(rdev); |
bba95fef JB |
4371 | |
4372 | return err; | |
2ec600d6 | 4373 | } |
fd5b74dc | 4374 | |
5727ef1b JB |
4375 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
4376 | { | |
4c476991 JB |
4377 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4378 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 4379 | struct station_info sinfo; |
fd5b74dc JB |
4380 | struct sk_buff *msg; |
4381 | u8 *mac_addr = NULL; | |
4c476991 | 4382 | int err; |
fd5b74dc | 4383 | |
2ec600d6 | 4384 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
4385 | |
4386 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4387 | return -EINVAL; | |
4388 | ||
4389 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4390 | ||
4c476991 JB |
4391 | if (!rdev->ops->get_station) |
4392 | return -EOPNOTSUPP; | |
3b85875a | 4393 | |
e35e4d28 | 4394 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 4395 | if (err) |
4c476991 | 4396 | return err; |
2ec600d6 | 4397 | |
fd2120ca | 4398 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 4399 | if (!msg) |
4c476991 | 4400 | return -ENOMEM; |
fd5b74dc | 4401 | |
cf5ead82 JB |
4402 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
4403 | info->snd_portid, info->snd_seq, 0, | |
66266b3a | 4404 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
4405 | nlmsg_free(msg); |
4406 | return -ENOBUFS; | |
4407 | } | |
3b85875a | 4408 | |
4c476991 | 4409 | return genlmsg_reply(msg, info); |
5727ef1b JB |
4410 | } |
4411 | ||
77ee7c89 JB |
4412 | int cfg80211_check_station_change(struct wiphy *wiphy, |
4413 | struct station_parameters *params, | |
4414 | enum cfg80211_station_type statype) | |
4415 | { | |
e4208427 AB |
4416 | if (params->listen_interval != -1 && |
4417 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
77ee7c89 | 4418 | return -EINVAL; |
e4208427 | 4419 | |
17b94247 AB |
4420 | if (params->support_p2p_ps != -1 && |
4421 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
4422 | return -EINVAL; | |
4423 | ||
c72e1140 | 4424 | if (params->aid && |
e4208427 AB |
4425 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
4426 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
77ee7c89 JB |
4427 | return -EINVAL; |
4428 | ||
4429 | /* When you run into this, adjust the code below for the new flag */ | |
4430 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4431 | ||
4432 | switch (statype) { | |
eef941e6 TP |
4433 | case CFG80211_STA_MESH_PEER_KERNEL: |
4434 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
4435 | /* |
4436 | * No ignoring the TDLS flag here -- the userspace mesh | |
4437 | * code doesn't have the bug of including TDLS in the | |
4438 | * mask everywhere. | |
4439 | */ | |
4440 | if (params->sta_flags_mask & | |
4441 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4442 | BIT(NL80211_STA_FLAG_MFP) | | |
4443 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
4444 | return -EINVAL; | |
4445 | break; | |
4446 | case CFG80211_STA_TDLS_PEER_SETUP: | |
4447 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
4448 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4449 | return -EINVAL; | |
4450 | /* ignore since it can't change */ | |
4451 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
4452 | break; | |
4453 | default: | |
4454 | /* disallow mesh-specific things */ | |
4455 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
4456 | return -EINVAL; | |
4457 | if (params->local_pm) | |
4458 | return -EINVAL; | |
4459 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
4460 | return -EINVAL; | |
4461 | } | |
4462 | ||
4463 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
4464 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
4465 | /* TDLS can't be set, ... */ | |
4466 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4467 | return -EINVAL; | |
4468 | /* | |
4469 | * ... but don't bother the driver with it. This works around | |
4470 | * a hostapd/wpa_supplicant issue -- it always includes the | |
4471 | * TLDS_PEER flag in the mask even for AP mode. | |
4472 | */ | |
4473 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
4474 | } | |
4475 | ||
47edb11b AB |
4476 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
4477 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { | |
77ee7c89 JB |
4478 | /* reject other things that can't change */ |
4479 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
4480 | return -EINVAL; | |
4481 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
4482 | return -EINVAL; | |
4483 | if (params->supported_rates) | |
4484 | return -EINVAL; | |
4485 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
4486 | return -EINVAL; | |
4487 | } | |
4488 | ||
47edb11b AB |
4489 | if (statype != CFG80211_STA_AP_CLIENT && |
4490 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { | |
77ee7c89 JB |
4491 | if (params->vlan) |
4492 | return -EINVAL; | |
4493 | } | |
4494 | ||
4495 | switch (statype) { | |
4496 | case CFG80211_STA_AP_MLME_CLIENT: | |
4497 | /* Use this only for authorizing/unauthorizing a station */ | |
4498 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
4499 | return -EOPNOTSUPP; | |
4500 | break; | |
4501 | case CFG80211_STA_AP_CLIENT: | |
47edb11b | 4502 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
77ee7c89 JB |
4503 | /* accept only the listed bits */ |
4504 | if (params->sta_flags_mask & | |
4505 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4506 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4507 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4508 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
4509 | BIT(NL80211_STA_FLAG_WME) | | |
4510 | BIT(NL80211_STA_FLAG_MFP))) | |
4511 | return -EINVAL; | |
4512 | ||
4513 | /* but authenticated/associated only if driver handles it */ | |
4514 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4515 | params->sta_flags_mask & | |
4516 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4517 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4518 | return -EINVAL; | |
4519 | break; | |
4520 | case CFG80211_STA_IBSS: | |
4521 | case CFG80211_STA_AP_STA: | |
4522 | /* reject any changes other than AUTHORIZED */ | |
4523 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
4524 | return -EINVAL; | |
4525 | break; | |
4526 | case CFG80211_STA_TDLS_PEER_SETUP: | |
4527 | /* reject any changes other than AUTHORIZED or WME */ | |
4528 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4529 | BIT(NL80211_STA_FLAG_WME))) | |
4530 | return -EINVAL; | |
4531 | /* force (at least) rates when authorizing */ | |
4532 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
4533 | !params->supported_rates) | |
4534 | return -EINVAL; | |
4535 | break; | |
4536 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
4537 | /* reject any changes */ | |
4538 | return -EINVAL; | |
eef941e6 | 4539 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
4540 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
4541 | return -EINVAL; | |
4542 | break; | |
eef941e6 | 4543 | case CFG80211_STA_MESH_PEER_USER: |
42925040 CYY |
4544 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
4545 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) | |
77ee7c89 JB |
4546 | return -EINVAL; |
4547 | break; | |
4548 | } | |
4549 | ||
4550 | return 0; | |
4551 | } | |
4552 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
4553 | ||
5727ef1b | 4554 | /* |
c258d2de | 4555 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 4556 | */ |
80b99899 JB |
4557 | static struct net_device *get_vlan(struct genl_info *info, |
4558 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 4559 | { |
463d0183 | 4560 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
4561 | struct net_device *v; |
4562 | int ret; | |
4563 | ||
4564 | if (!vlanattr) | |
4565 | return NULL; | |
4566 | ||
4567 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
4568 | if (!v) | |
4569 | return ERR_PTR(-ENODEV); | |
4570 | ||
4571 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
4572 | ret = -EINVAL; | |
4573 | goto error; | |
5727ef1b | 4574 | } |
80b99899 | 4575 | |
77ee7c89 JB |
4576 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
4577 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4578 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
4579 | ret = -EINVAL; | |
4580 | goto error; | |
4581 | } | |
4582 | ||
80b99899 JB |
4583 | if (!netif_running(v)) { |
4584 | ret = -ENETDOWN; | |
4585 | goto error; | |
4586 | } | |
4587 | ||
4588 | return v; | |
4589 | error: | |
4590 | dev_put(v); | |
4591 | return ERR_PTR(ret); | |
5727ef1b JB |
4592 | } |
4593 | ||
94e860f1 JB |
4594 | static const struct nla_policy |
4595 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
4596 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
4597 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
4598 | }; | |
4599 | ||
ff276691 JB |
4600 | static int nl80211_parse_sta_wme(struct genl_info *info, |
4601 | struct station_parameters *params) | |
df881293 | 4602 | { |
df881293 JM |
4603 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
4604 | struct nlattr *nla; | |
4605 | int err; | |
4606 | ||
df881293 JM |
4607 | /* parse WME attributes if present */ |
4608 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
4609 | return 0; | |
4610 | ||
4611 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
4612 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
4613 | nl80211_sta_wme_policy); | |
4614 | if (err) | |
4615 | return err; | |
4616 | ||
4617 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
4618 | params->uapsd_queues = nla_get_u8( | |
4619 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4620 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
4621 | return -EINVAL; | |
4622 | ||
4623 | if (tb[NL80211_STA_WME_MAX_SP]) | |
4624 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4625 | ||
4626 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
4627 | return -EINVAL; | |
4628 | ||
4629 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
4630 | ||
4631 | return 0; | |
4632 | } | |
4633 | ||
c01fc9ad SD |
4634 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4635 | struct station_parameters *params) | |
4636 | { | |
4637 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4638 | params->supported_channels = | |
4639 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4640 | params->supported_channels_len = | |
4641 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4642 | /* | |
4643 | * Need to include at least one (first channel, number of | |
4644 | * channels) tuple for each subband, and must have proper | |
4645 | * tuples for the rest of the data as well. | |
4646 | */ | |
4647 | if (params->supported_channels_len < 2) | |
4648 | return -EINVAL; | |
4649 | if (params->supported_channels_len % 2) | |
4650 | return -EINVAL; | |
4651 | } | |
4652 | ||
4653 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4654 | params->supported_oper_classes = | |
4655 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4656 | params->supported_oper_classes_len = | |
4657 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4658 | /* | |
4659 | * The value of the Length field of the Supported Operating | |
4660 | * Classes element is between 2 and 253. | |
4661 | */ | |
4662 | if (params->supported_oper_classes_len < 2 || | |
4663 | params->supported_oper_classes_len > 253) | |
4664 | return -EINVAL; | |
4665 | } | |
4666 | return 0; | |
4667 | } | |
4668 | ||
ff276691 JB |
4669 | static int nl80211_set_station_tdls(struct genl_info *info, |
4670 | struct station_parameters *params) | |
4671 | { | |
c01fc9ad | 4672 | int err; |
ff276691 | 4673 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4674 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4675 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4676 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4677 | params->ht_capa = | |
4678 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4679 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4680 | params->vht_capa = | |
4681 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4682 | ||
c01fc9ad SD |
4683 | err = nl80211_parse_sta_channel_info(info, params); |
4684 | if (err) | |
4685 | return err; | |
4686 | ||
ff276691 JB |
4687 | return nl80211_parse_sta_wme(info, params); |
4688 | } | |
4689 | ||
5727ef1b JB |
4690 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4691 | { | |
4c476991 | 4692 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4693 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4694 | struct station_parameters params; |
77ee7c89 JB |
4695 | u8 *mac_addr; |
4696 | int err; | |
5727ef1b JB |
4697 | |
4698 | memset(¶ms, 0, sizeof(params)); | |
4699 | ||
77ee7c89 JB |
4700 | if (!rdev->ops->change_station) |
4701 | return -EOPNOTSUPP; | |
4702 | ||
e4208427 AB |
4703 | /* |
4704 | * AID and listen_interval properties can be set only for unassociated | |
4705 | * station. Include these parameters here and will check them in | |
4706 | * cfg80211_check_station_change(). | |
4707 | */ | |
a9bc31e4 AB |
4708 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4709 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
e4208427 AB |
4710 | |
4711 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | |
4712 | params.listen_interval = | |
4713 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
4714 | else | |
4715 | params.listen_interval = -1; | |
5727ef1b | 4716 | |
17b94247 AB |
4717 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
4718 | u8 tmp; | |
4719 | ||
4720 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); | |
4721 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) | |
4722 | return -EINVAL; | |
4723 | ||
4724 | params.support_p2p_ps = tmp; | |
4725 | } else { | |
4726 | params.support_p2p_ps = -1; | |
4727 | } | |
4728 | ||
5727ef1b JB |
4729 | if (!info->attrs[NL80211_ATTR_MAC]) |
4730 | return -EINVAL; | |
4731 | ||
4732 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4733 | ||
4734 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4735 | params.supported_rates = | |
4736 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4737 | params.supported_rates_len = | |
4738 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4739 | } | |
4740 | ||
9d62a986 JM |
4741 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4742 | params.capability = | |
4743 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4744 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4745 | } | |
4746 | ||
4747 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4748 | params.ext_capab = | |
4749 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4750 | params.ext_capab_len = | |
4751 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4752 | } | |
4753 | ||
bdd3ae3d | 4754 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4755 | return -EINVAL; |
4756 | ||
f8bacc21 | 4757 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4758 | params.plink_action = |
f8bacc21 JB |
4759 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4760 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4761 | return -EINVAL; | |
4762 | } | |
2ec600d6 | 4763 | |
f8bacc21 | 4764 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4765 | params.plink_state = |
f8bacc21 JB |
4766 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4767 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4768 | return -EINVAL; | |
7d27a0ba MH |
4769 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) { |
4770 | params.peer_aid = nla_get_u16( | |
4771 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); | |
4772 | if (params.peer_aid > IEEE80211_MAX_AID) | |
4773 | return -EINVAL; | |
4774 | } | |
f8bacc21 JB |
4775 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
4776 | } | |
9c3990aa | 4777 | |
3b1c5a53 MP |
4778 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4779 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4780 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4781 | ||
4782 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4783 | pm > NL80211_MESH_POWER_MAX) | |
4784 | return -EINVAL; | |
4785 | ||
4786 | params.local_pm = pm; | |
4787 | } | |
4788 | ||
77ee7c89 JB |
4789 | /* Include parameters for TDLS peer (will check later) */ |
4790 | err = nl80211_set_station_tdls(info, ¶ms); | |
4791 | if (err) | |
4792 | return err; | |
4793 | ||
4794 | params.vlan = get_vlan(info, rdev); | |
4795 | if (IS_ERR(params.vlan)) | |
4796 | return PTR_ERR(params.vlan); | |
4797 | ||
a97f4424 JB |
4798 | switch (dev->ieee80211_ptr->iftype) { |
4799 | case NL80211_IFTYPE_AP: | |
4800 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4801 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4802 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4803 | case NL80211_IFTYPE_STATION: |
267335d6 | 4804 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4805 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4806 | break; |
4807 | default: | |
77ee7c89 JB |
4808 | err = -EOPNOTSUPP; |
4809 | goto out_put_vlan; | |
034d655e JB |
4810 | } |
4811 | ||
77ee7c89 | 4812 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4813 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4814 | |
77ee7c89 | 4815 | out_put_vlan: |
5727ef1b JB |
4816 | if (params.vlan) |
4817 | dev_put(params.vlan); | |
3b85875a | 4818 | |
5727ef1b JB |
4819 | return err; |
4820 | } | |
4821 | ||
4822 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4823 | { | |
4c476991 | 4824 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4825 | int err; |
4c476991 | 4826 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4827 | struct station_parameters params; |
4828 | u8 *mac_addr = NULL; | |
bda95eb1 JB |
4829 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
4830 | BIT(NL80211_STA_FLAG_ASSOCIATED); | |
5727ef1b JB |
4831 | |
4832 | memset(¶ms, 0, sizeof(params)); | |
4833 | ||
984c311b JB |
4834 | if (!rdev->ops->add_station) |
4835 | return -EOPNOTSUPP; | |
4836 | ||
5727ef1b JB |
4837 | if (!info->attrs[NL80211_ATTR_MAC]) |
4838 | return -EINVAL; | |
4839 | ||
5727ef1b JB |
4840 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4841 | return -EINVAL; | |
4842 | ||
4843 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4844 | return -EINVAL; | |
4845 | ||
5e4b6f56 JM |
4846 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4847 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4848 | return -EINVAL; |
4849 | ||
5727ef1b JB |
4850 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4851 | params.supported_rates = | |
4852 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4853 | params.supported_rates_len = | |
4854 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4855 | params.listen_interval = | |
4856 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4857 | |
17b94247 AB |
4858 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
4859 | u8 tmp; | |
4860 | ||
4861 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); | |
4862 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) | |
4863 | return -EINVAL; | |
4864 | ||
4865 | params.support_p2p_ps = tmp; | |
4866 | } else { | |
4867 | /* | |
4868 | * if not specified, assume it's supported for P2P GO interface, | |
4869 | * and is NOT supported for AP interface | |
4870 | */ | |
4871 | params.support_p2p_ps = | |
4872 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; | |
4873 | } | |
4874 | ||
3d124ea2 | 4875 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4876 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4877 | else |
4878 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4879 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4880 | return -EINVAL; | |
51b50fbe | 4881 | |
9d62a986 JM |
4882 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4883 | params.capability = | |
4884 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4885 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4886 | } | |
4887 | ||
4888 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4889 | params.ext_capab = | |
4890 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4891 | params.ext_capab_len = | |
4892 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4893 | } | |
4894 | ||
36aedc90 JM |
4895 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4896 | params.ht_capa = | |
4897 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4898 | |
f461be3e MP |
4899 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4900 | params.vht_capa = | |
4901 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4902 | ||
60f4a7b1 MK |
4903 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4904 | params.opmode_notif_used = true; | |
4905 | params.opmode_notif = | |
4906 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4907 | } | |
4908 | ||
f8bacc21 | 4909 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4910 | params.plink_action = |
f8bacc21 JB |
4911 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4912 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4913 | return -EINVAL; | |
4914 | } | |
96b78dff | 4915 | |
c01fc9ad SD |
4916 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4917 | if (err) | |
4918 | return err; | |
4919 | ||
ff276691 JB |
4920 | err = nl80211_parse_sta_wme(info, ¶ms); |
4921 | if (err) | |
4922 | return err; | |
bdd90d5e | 4923 | |
bdd3ae3d | 4924 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4925 | return -EINVAL; |
4926 | ||
496fcc29 JB |
4927 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
4928 | * as userspace might just pass through the capabilities from the IEs | |
4929 | * directly, rather than enforcing this restriction and returning an | |
4930 | * error in this case. | |
4931 | */ | |
4932 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { | |
4933 | params.ht_capa = NULL; | |
4934 | params.vht_capa = NULL; | |
4935 | } | |
4936 | ||
77ee7c89 JB |
4937 | /* When you run into this, adjust the code below for the new flag */ |
4938 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4939 | ||
bdd90d5e JB |
4940 | switch (dev->ieee80211_ptr->iftype) { |
4941 | case NL80211_IFTYPE_AP: | |
4942 | case NL80211_IFTYPE_AP_VLAN: | |
4943 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4944 | /* ignore WME attributes if iface/sta is not capable */ |
4945 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4946 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4947 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4948 | |
bdd90d5e | 4949 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4950 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4951 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4952 | return -EINVAL; |
bdd90d5e JB |
4953 | /* but don't bother the driver with it */ |
4954 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4955 | |
d582cffb JB |
4956 | /* allow authenticated/associated only if driver handles it */ |
4957 | if (!(rdev->wiphy.features & | |
4958 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
bda95eb1 | 4959 | params.sta_flags_mask & auth_assoc) |
d582cffb JB |
4960 | return -EINVAL; |
4961 | ||
bda95eb1 JB |
4962 | /* Older userspace, or userspace wanting to be compatible with |
4963 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth | |
4964 | * and assoc flags in the mask, but assumes the station will be | |
4965 | * added as associated anyway since this was the required driver | |
4966 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was | |
4967 | * introduced. | |
4968 | * In order to not bother drivers with this quirk in the API | |
4969 | * set the flags in both the mask and set for new stations in | |
4970 | * this case. | |
4971 | */ | |
4972 | if (!(params.sta_flags_mask & auth_assoc)) { | |
4973 | params.sta_flags_mask |= auth_assoc; | |
4974 | params.sta_flags_set |= auth_assoc; | |
4975 | } | |
4976 | ||
bdd90d5e JB |
4977 | /* must be last in here for error handling */ |
4978 | params.vlan = get_vlan(info, rdev); | |
4979 | if (IS_ERR(params.vlan)) | |
4980 | return PTR_ERR(params.vlan); | |
4981 | break; | |
4982 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4983 | /* ignore uAPSD data */ |
4984 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4985 | ||
d582cffb JB |
4986 | /* associated is disallowed */ |
4987 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4988 | return -EINVAL; | |
bdd90d5e | 4989 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4990 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4991 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4992 | return -EINVAL; |
4993 | break; | |
4994 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4995 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4996 | /* ignore uAPSD data */ |
4997 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4998 | ||
77ee7c89 JB |
4999 | /* these are disallowed */ |
5000 | if (params.sta_flags_mask & | |
5001 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
5002 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 5003 | return -EINVAL; |
bdd90d5e JB |
5004 | /* Only TDLS peers can be added */ |
5005 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
5006 | return -EINVAL; | |
5007 | /* Can only add if TDLS ... */ | |
5008 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
5009 | return -EOPNOTSUPP; | |
5010 | /* ... with external setup is supported */ | |
5011 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
5012 | return -EOPNOTSUPP; | |
77ee7c89 JB |
5013 | /* |
5014 | * Older wpa_supplicant versions always mark the TDLS peer | |
5015 | * as authorized, but it shouldn't yet be. | |
5016 | */ | |
5017 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
5018 | break; |
5019 | default: | |
5020 | return -EOPNOTSUPP; | |
c75786c9 EP |
5021 | } |
5022 | ||
bdd90d5e | 5023 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 5024 | |
e35e4d28 | 5025 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 5026 | |
5727ef1b JB |
5027 | if (params.vlan) |
5028 | dev_put(params.vlan); | |
5727ef1b JB |
5029 | return err; |
5030 | } | |
5031 | ||
5032 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
5033 | { | |
4c476991 JB |
5034 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5035 | struct net_device *dev = info->user_ptr[1]; | |
89c771e5 JM |
5036 | struct station_del_parameters params; |
5037 | ||
5038 | memset(¶ms, 0, sizeof(params)); | |
5727ef1b JB |
5039 | |
5040 | if (info->attrs[NL80211_ATTR_MAC]) | |
89c771e5 | 5041 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5727ef1b | 5042 | |
e80cf853 | 5043 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 5044 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 5045 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
5046 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
5047 | return -EINVAL; | |
5727ef1b | 5048 | |
4c476991 JB |
5049 | if (!rdev->ops->del_station) |
5050 | return -EOPNOTSUPP; | |
3b85875a | 5051 | |
98856866 JM |
5052 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
5053 | params.subtype = | |
5054 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | |
5055 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | |
5056 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | |
5057 | return -EINVAL; | |
5058 | } else { | |
5059 | /* Default to Deauthentication frame */ | |
5060 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | |
5061 | } | |
5062 | ||
5063 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | |
5064 | params.reason_code = | |
5065 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
5066 | if (params.reason_code == 0) | |
5067 | return -EINVAL; /* 0 is reserved */ | |
5068 | } else { | |
5069 | /* Default to reason code 2 */ | |
5070 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | |
5071 | } | |
5072 | ||
89c771e5 | 5073 | return rdev_del_station(rdev, dev, ¶ms); |
5727ef1b JB |
5074 | } |
5075 | ||
15e47304 | 5076 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
5077 | int flags, struct net_device *dev, |
5078 | u8 *dst, u8 *next_hop, | |
5079 | struct mpath_info *pinfo) | |
5080 | { | |
5081 | void *hdr; | |
5082 | struct nlattr *pinfoattr; | |
5083 | ||
1ef4c850 | 5084 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
2ec600d6 LCC |
5085 | if (!hdr) |
5086 | return -1; | |
5087 | ||
9360ffd1 DM |
5088 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5089 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
5090 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
5091 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
5092 | goto nla_put_failure; | |
f5ea9120 | 5093 | |
2ec600d6 LCC |
5094 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
5095 | if (!pinfoattr) | |
5096 | goto nla_put_failure; | |
9360ffd1 DM |
5097 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
5098 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
5099 | pinfo->frame_qlen)) | |
5100 | goto nla_put_failure; | |
5101 | if (((pinfo->filled & MPATH_INFO_SN) && | |
5102 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
5103 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
5104 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
5105 | pinfo->metric)) || | |
5106 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
5107 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
5108 | pinfo->exptime)) || | |
5109 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
5110 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
5111 | pinfo->flags)) || | |
5112 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
5113 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
5114 | pinfo->discovery_timeout)) || | |
5115 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
5116 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
5117 | pinfo->discovery_retries))) | |
5118 | goto nla_put_failure; | |
2ec600d6 LCC |
5119 | |
5120 | nla_nest_end(msg, pinfoattr); | |
5121 | ||
053c095a JB |
5122 | genlmsg_end(msg, hdr); |
5123 | return 0; | |
2ec600d6 LCC |
5124 | |
5125 | nla_put_failure: | |
bc3ed28c TG |
5126 | genlmsg_cancel(msg, hdr); |
5127 | return -EMSGSIZE; | |
2ec600d6 LCC |
5128 | } |
5129 | ||
5130 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 5131 | struct netlink_callback *cb) |
2ec600d6 | 5132 | { |
2ec600d6 | 5133 | struct mpath_info pinfo; |
1b8ec87a | 5134 | struct cfg80211_registered_device *rdev; |
97990a06 | 5135 | struct wireless_dev *wdev; |
2ec600d6 LCC |
5136 | u8 dst[ETH_ALEN]; |
5137 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 5138 | int path_idx = cb->args[2]; |
2ec600d6 | 5139 | int err; |
2ec600d6 | 5140 | |
1b8ec87a | 5141 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
5142 | if (err) |
5143 | return err; | |
bba95fef | 5144 | |
1b8ec87a | 5145 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 5146 | err = -EOPNOTSUPP; |
bba95fef JB |
5147 | goto out_err; |
5148 | } | |
5149 | ||
97990a06 | 5150 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 5151 | err = -EOPNOTSUPP; |
0448b5fc | 5152 | goto out_err; |
eec60b03 JM |
5153 | } |
5154 | ||
bba95fef | 5155 | while (1) { |
1b8ec87a | 5156 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 5157 | next_hop, &pinfo); |
bba95fef | 5158 | if (err == -ENOENT) |
2ec600d6 | 5159 | break; |
bba95fef | 5160 | if (err) |
3b85875a | 5161 | goto out_err; |
2ec600d6 | 5162 | |
15e47304 | 5163 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 5164 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 5165 | wdev->netdev, dst, next_hop, |
bba95fef JB |
5166 | &pinfo) < 0) |
5167 | goto out; | |
2ec600d6 | 5168 | |
bba95fef | 5169 | path_idx++; |
2ec600d6 | 5170 | } |
2ec600d6 | 5171 | |
bba95fef | 5172 | out: |
97990a06 | 5173 | cb->args[2] = path_idx; |
bba95fef | 5174 | err = skb->len; |
bba95fef | 5175 | out_err: |
1b8ec87a | 5176 | nl80211_finish_wdev_dump(rdev); |
bba95fef | 5177 | return err; |
2ec600d6 LCC |
5178 | } |
5179 | ||
5180 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
5181 | { | |
4c476991 | 5182 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 5183 | int err; |
4c476991 | 5184 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
5185 | struct mpath_info pinfo; |
5186 | struct sk_buff *msg; | |
5187 | u8 *dst = NULL; | |
5188 | u8 next_hop[ETH_ALEN]; | |
5189 | ||
5190 | memset(&pinfo, 0, sizeof(pinfo)); | |
5191 | ||
5192 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5193 | return -EINVAL; | |
5194 | ||
5195 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5196 | ||
4c476991 JB |
5197 | if (!rdev->ops->get_mpath) |
5198 | return -EOPNOTSUPP; | |
2ec600d6 | 5199 | |
4c476991 JB |
5200 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
5201 | return -EOPNOTSUPP; | |
eec60b03 | 5202 | |
e35e4d28 | 5203 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 5204 | if (err) |
4c476991 | 5205 | return err; |
2ec600d6 | 5206 | |
fd2120ca | 5207 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 5208 | if (!msg) |
4c476991 | 5209 | return -ENOMEM; |
2ec600d6 | 5210 | |
15e47304 | 5211 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
5212 | dev, dst, next_hop, &pinfo) < 0) { |
5213 | nlmsg_free(msg); | |
5214 | return -ENOBUFS; | |
5215 | } | |
3b85875a | 5216 | |
4c476991 | 5217 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
5218 | } |
5219 | ||
5220 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
5221 | { | |
4c476991 JB |
5222 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5223 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
5224 | u8 *dst = NULL; |
5225 | u8 *next_hop = NULL; | |
5226 | ||
5227 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5228 | return -EINVAL; | |
5229 | ||
5230 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
5231 | return -EINVAL; | |
5232 | ||
5233 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5234 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
5235 | ||
4c476991 JB |
5236 | if (!rdev->ops->change_mpath) |
5237 | return -EOPNOTSUPP; | |
35a8efe1 | 5238 | |
4c476991 JB |
5239 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
5240 | return -EOPNOTSUPP; | |
2ec600d6 | 5241 | |
e35e4d28 | 5242 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 5243 | } |
4c476991 | 5244 | |
2ec600d6 LCC |
5245 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
5246 | { | |
4c476991 JB |
5247 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5248 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
5249 | u8 *dst = NULL; |
5250 | u8 *next_hop = NULL; | |
5251 | ||
5252 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5253 | return -EINVAL; | |
5254 | ||
5255 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
5256 | return -EINVAL; | |
5257 | ||
5258 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5259 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
5260 | ||
4c476991 JB |
5261 | if (!rdev->ops->add_mpath) |
5262 | return -EOPNOTSUPP; | |
35a8efe1 | 5263 | |
4c476991 JB |
5264 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
5265 | return -EOPNOTSUPP; | |
2ec600d6 | 5266 | |
e35e4d28 | 5267 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
5268 | } |
5269 | ||
5270 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
5271 | { | |
4c476991 JB |
5272 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5273 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
5274 | u8 *dst = NULL; |
5275 | ||
5276 | if (info->attrs[NL80211_ATTR_MAC]) | |
5277 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5278 | ||
4c476991 JB |
5279 | if (!rdev->ops->del_mpath) |
5280 | return -EOPNOTSUPP; | |
3b85875a | 5281 | |
e35e4d28 | 5282 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
5283 | } |
5284 | ||
66be7d2b HR |
5285 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
5286 | { | |
5287 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5288 | int err; | |
5289 | struct net_device *dev = info->user_ptr[1]; | |
5290 | struct mpath_info pinfo; | |
5291 | struct sk_buff *msg; | |
5292 | u8 *dst = NULL; | |
5293 | u8 mpp[ETH_ALEN]; | |
5294 | ||
5295 | memset(&pinfo, 0, sizeof(pinfo)); | |
5296 | ||
5297 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5298 | return -EINVAL; | |
5299 | ||
5300 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5301 | ||
5302 | if (!rdev->ops->get_mpp) | |
5303 | return -EOPNOTSUPP; | |
5304 | ||
5305 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
5306 | return -EOPNOTSUPP; | |
5307 | ||
5308 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | |
5309 | if (err) | |
5310 | return err; | |
5311 | ||
5312 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5313 | if (!msg) | |
5314 | return -ENOMEM; | |
5315 | ||
5316 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | |
5317 | dev, dst, mpp, &pinfo) < 0) { | |
5318 | nlmsg_free(msg); | |
5319 | return -ENOBUFS; | |
5320 | } | |
5321 | ||
5322 | return genlmsg_reply(msg, info); | |
5323 | } | |
5324 | ||
5325 | static int nl80211_dump_mpp(struct sk_buff *skb, | |
5326 | struct netlink_callback *cb) | |
5327 | { | |
5328 | struct mpath_info pinfo; | |
5329 | struct cfg80211_registered_device *rdev; | |
5330 | struct wireless_dev *wdev; | |
5331 | u8 dst[ETH_ALEN]; | |
5332 | u8 mpp[ETH_ALEN]; | |
5333 | int path_idx = cb->args[2]; | |
5334 | int err; | |
5335 | ||
5336 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | |
5337 | if (err) | |
5338 | return err; | |
5339 | ||
5340 | if (!rdev->ops->dump_mpp) { | |
5341 | err = -EOPNOTSUPP; | |
5342 | goto out_err; | |
5343 | } | |
5344 | ||
5345 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | |
5346 | err = -EOPNOTSUPP; | |
5347 | goto out_err; | |
5348 | } | |
5349 | ||
5350 | while (1) { | |
5351 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | |
5352 | mpp, &pinfo); | |
5353 | if (err == -ENOENT) | |
5354 | break; | |
5355 | if (err) | |
5356 | goto out_err; | |
5357 | ||
5358 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | |
5359 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
5360 | wdev->netdev, dst, mpp, | |
5361 | &pinfo) < 0) | |
5362 | goto out; | |
5363 | ||
5364 | path_idx++; | |
5365 | } | |
5366 | ||
5367 | out: | |
5368 | cb->args[2] = path_idx; | |
5369 | err = skb->len; | |
5370 | out_err: | |
5371 | nl80211_finish_wdev_dump(rdev); | |
5372 | return err; | |
5373 | } | |
5374 | ||
9f1ba906 JM |
5375 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
5376 | { | |
4c476991 JB |
5377 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5378 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 5379 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 5380 | struct bss_parameters params; |
c56589ed | 5381 | int err; |
9f1ba906 JM |
5382 | |
5383 | memset(¶ms, 0, sizeof(params)); | |
5384 | /* default to not changing parameters */ | |
5385 | params.use_cts_prot = -1; | |
5386 | params.use_short_preamble = -1; | |
5387 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 5388 | params.ap_isolate = -1; |
50b12f59 | 5389 | params.ht_opmode = -1; |
53cabad7 JB |
5390 | params.p2p_ctwindow = -1; |
5391 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
5392 | |
5393 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
5394 | params.use_cts_prot = | |
5395 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
5396 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
5397 | params.use_short_preamble = | |
5398 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
5399 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
5400 | params.use_short_slot_time = | |
5401 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
5402 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
5403 | params.basic_rates = | |
5404 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
5405 | params.basic_rates_len = | |
5406 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
5407 | } | |
fd8aaaf3 FF |
5408 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
5409 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
5410 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
5411 | params.ht_opmode = | |
5412 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 5413 | |
53cabad7 JB |
5414 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
5415 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
5416 | return -EINVAL; | |
5417 | params.p2p_ctwindow = | |
5418 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
5419 | if (params.p2p_ctwindow < 0) | |
5420 | return -EINVAL; | |
5421 | if (params.p2p_ctwindow != 0 && | |
5422 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
5423 | return -EINVAL; | |
5424 | } | |
5425 | ||
5426 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
5427 | u8 tmp; | |
5428 | ||
5429 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
5430 | return -EINVAL; | |
5431 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
5432 | if (tmp > 1) | |
5433 | return -EINVAL; | |
5434 | params.p2p_opp_ps = tmp; | |
5435 | if (params.p2p_opp_ps && | |
5436 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
5437 | return -EINVAL; | |
5438 | } | |
5439 | ||
4c476991 JB |
5440 | if (!rdev->ops->change_bss) |
5441 | return -EOPNOTSUPP; | |
9f1ba906 | 5442 | |
074ac8df | 5443 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
5444 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
5445 | return -EOPNOTSUPP; | |
3b85875a | 5446 | |
c56589ed SW |
5447 | wdev_lock(wdev); |
5448 | err = rdev_change_bss(rdev, dev, ¶ms); | |
5449 | wdev_unlock(wdev); | |
5450 | ||
5451 | return err; | |
9f1ba906 JM |
5452 | } |
5453 | ||
b2e1b302 LR |
5454 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
5455 | { | |
b2e1b302 | 5456 | char *data = NULL; |
05050753 | 5457 | bool is_indoor; |
57b5ce07 | 5458 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
05050753 I |
5459 | u32 owner_nlportid; |
5460 | ||
80778f18 LR |
5461 | /* |
5462 | * You should only get this when cfg80211 hasn't yet initialized | |
5463 | * completely when built-in to the kernel right between the time | |
5464 | * window between nl80211_init() and regulatory_init(), if that is | |
5465 | * even possible. | |
5466 | */ | |
458f4f9e | 5467 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 5468 | return -EINPROGRESS; |
80778f18 | 5469 | |
57b5ce07 LR |
5470 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
5471 | user_reg_hint_type = | |
5472 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
5473 | else | |
5474 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
5475 | ||
5476 | switch (user_reg_hint_type) { | |
5477 | case NL80211_USER_REG_HINT_USER: | |
5478 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
5479 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
5480 | return -EINVAL; | |
5481 | ||
5482 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5483 | return regulatory_hint_user(data, user_reg_hint_type); | |
5484 | case NL80211_USER_REG_HINT_INDOOR: | |
05050753 I |
5485 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
5486 | owner_nlportid = info->snd_portid; | |
5487 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; | |
5488 | } else { | |
5489 | owner_nlportid = 0; | |
5490 | is_indoor = true; | |
5491 | } | |
5492 | ||
5493 | return regulatory_hint_indoor(is_indoor, owner_nlportid); | |
57b5ce07 LR |
5494 | default: |
5495 | return -EINVAL; | |
5496 | } | |
b2e1b302 LR |
5497 | } |
5498 | ||
24bdd9f4 | 5499 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 5500 | struct genl_info *info) |
93da9cc1 | 5501 | { |
4c476991 | 5502 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 5503 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
5504 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5505 | struct mesh_config cur_params; | |
5506 | int err = 0; | |
93da9cc1 | 5507 | void *hdr; |
5508 | struct nlattr *pinfoattr; | |
5509 | struct sk_buff *msg; | |
5510 | ||
29cbe68c JB |
5511 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5512 | return -EOPNOTSUPP; | |
5513 | ||
24bdd9f4 | 5514 | if (!rdev->ops->get_mesh_config) |
4c476991 | 5515 | return -EOPNOTSUPP; |
f3f92586 | 5516 | |
29cbe68c JB |
5517 | wdev_lock(wdev); |
5518 | /* If not connected, get default parameters */ | |
5519 | if (!wdev->mesh_id_len) | |
5520 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
5521 | else | |
e35e4d28 | 5522 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
5523 | wdev_unlock(wdev); |
5524 | ||
93da9cc1 | 5525 | if (err) |
4c476991 | 5526 | return err; |
93da9cc1 | 5527 | |
5528 | /* Draw up a netlink message to send back */ | |
fd2120ca | 5529 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
5530 | if (!msg) |
5531 | return -ENOMEM; | |
15e47304 | 5532 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 5533 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 5534 | if (!hdr) |
efe1cf0c | 5535 | goto out; |
24bdd9f4 | 5536 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 5537 | if (!pinfoattr) |
5538 | goto nla_put_failure; | |
9360ffd1 DM |
5539 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5540 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
5541 | cur_params.dot11MeshRetryTimeout) || | |
5542 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
5543 | cur_params.dot11MeshConfirmTimeout) || | |
5544 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
5545 | cur_params.dot11MeshHoldingTimeout) || | |
5546 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
5547 | cur_params.dot11MeshMaxPeerLinks) || | |
5548 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
5549 | cur_params.dot11MeshMaxRetries) || | |
5550 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
5551 | cur_params.dot11MeshTTL) || | |
5552 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
5553 | cur_params.element_ttl) || | |
5554 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
5555 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
5556 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5557 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
5558 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5559 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
5560 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
5561 | cur_params.path_refresh_time) || | |
5562 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
5563 | cur_params.min_discovery_timeout) || | |
5564 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
5565 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
5566 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
5567 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
5568 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
5569 | cur_params.dot11MeshHWMPperrMinInterval) || | |
5570 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
5571 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
5572 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5573 | cur_params.dot11MeshHWMPRootMode) || | |
5574 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
5575 | cur_params.dot11MeshHWMPRannInterval) || | |
5576 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
5577 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
5578 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
5579 | cur_params.dot11MeshForwarding) || | |
5580 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
5581 | cur_params.rssi_threshold) || |
5582 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
5583 | cur_params.ht_opmode) || |
5584 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
5585 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
5586 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
5587 | cur_params.dot11MeshHWMProotInterval) || |
5588 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
5589 | cur_params.dot11MeshHWMPconfirmationInterval) || |
5590 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
5591 | cur_params.power_mode) || | |
5592 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
5593 | cur_params.dot11MeshAwakeWindowDuration) || |
5594 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5595 | cur_params.plink_timeout)) | |
9360ffd1 | 5596 | goto nla_put_failure; |
93da9cc1 | 5597 | nla_nest_end(msg, pinfoattr); |
5598 | genlmsg_end(msg, hdr); | |
4c476991 | 5599 | return genlmsg_reply(msg, info); |
93da9cc1 | 5600 | |
3b85875a | 5601 | nla_put_failure: |
93da9cc1 | 5602 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 5603 | out: |
d080e275 | 5604 | nlmsg_free(msg); |
4c476991 | 5605 | return -ENOBUFS; |
93da9cc1 | 5606 | } |
5607 | ||
b54452b0 | 5608 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 5609 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
5610 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
5611 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
5612 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
5613 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
5614 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 5615 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 5616 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 5617 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 5618 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
5619 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
5620 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
5621 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
5622 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 5623 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 5624 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 5625 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 5626 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 5627 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 5628 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
5629 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
5630 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
5631 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
5632 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 5633 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
5634 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
5635 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 5636 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 5637 | }; |
5638 | ||
c80d545d JC |
5639 | static const struct nla_policy |
5640 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 5641 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
5642 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
5643 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 5644 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 5645 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 5646 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 5647 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 5648 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 5649 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
5650 | }; |
5651 | ||
f151d9db AB |
5652 | static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out) |
5653 | { | |
5654 | u8 val = nla_get_u8(nla); | |
5655 | if (val < min || val > max) | |
5656 | return -EINVAL; | |
5657 | *out = val; | |
5658 | return 0; | |
5659 | } | |
5660 | ||
5661 | static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out) | |
5662 | { | |
5663 | u8 val = nla_get_u8(nla); | |
5664 | if (val < min || val > max) | |
5665 | return -EINVAL; | |
5666 | *out = val; | |
5667 | return 0; | |
5668 | } | |
5669 | ||
5670 | static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out) | |
5671 | { | |
5672 | u16 val = nla_get_u16(nla); | |
5673 | if (val < min || val > max) | |
5674 | return -EINVAL; | |
5675 | *out = val; | |
5676 | return 0; | |
5677 | } | |
5678 | ||
5679 | static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out) | |
5680 | { | |
5681 | u32 val = nla_get_u32(nla); | |
5682 | if (val < min || val > max) | |
5683 | return -EINVAL; | |
5684 | *out = val; | |
5685 | return 0; | |
5686 | } | |
5687 | ||
5688 | static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out) | |
5689 | { | |
5690 | s32 val = nla_get_s32(nla); | |
5691 | if (val < min || val > max) | |
5692 | return -EINVAL; | |
5693 | *out = val; | |
5694 | return 0; | |
5695 | } | |
5696 | ||
ff9a71af JB |
5697 | static int nl80211_check_power_mode(const struct nlattr *nla, |
5698 | enum nl80211_mesh_power_mode min, | |
5699 | enum nl80211_mesh_power_mode max, | |
5700 | enum nl80211_mesh_power_mode *out) | |
5701 | { | |
5702 | u32 val = nla_get_u32(nla); | |
5703 | if (val < min || val > max) | |
5704 | return -EINVAL; | |
5705 | *out = val; | |
5706 | return 0; | |
5707 | } | |
5708 | ||
24bdd9f4 | 5709 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
5710 | struct mesh_config *cfg, |
5711 | u32 *mask_out) | |
93da9cc1 | 5712 | { |
93da9cc1 | 5713 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 5714 | u32 mask = 0; |
9757235f | 5715 | u16 ht_opmode; |
93da9cc1 | 5716 | |
ea54fba2 MP |
5717 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
5718 | do { \ | |
5719 | if (tb[attr]) { \ | |
f151d9db | 5720 | if (fn(tb[attr], min, max, &cfg->param)) \ |
ea54fba2 | 5721 | return -EINVAL; \ |
ea54fba2 MP |
5722 | mask |= (1 << (attr - 1)); \ |
5723 | } \ | |
5724 | } while (0) | |
bd90fdcc | 5725 | |
24bdd9f4 | 5726 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 5727 | return -EINVAL; |
5728 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 5729 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 5730 | nl80211_meshconf_params_policy)) |
93da9cc1 | 5731 | return -EINVAL; |
5732 | ||
93da9cc1 | 5733 | /* This makes sure that there aren't more than 32 mesh config |
5734 | * parameters (otherwise our bitfield scheme would not work.) */ | |
5735 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
5736 | ||
5737 | /* Fill in the params struct */ | |
ea54fba2 | 5738 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea | 5739 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
f151d9db | 5740 | nl80211_check_u16); |
ea54fba2 | 5741 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea | 5742 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
f151d9db | 5743 | nl80211_check_u16); |
ea54fba2 | 5744 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea | 5745 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
f151d9db | 5746 | nl80211_check_u16); |
ea54fba2 | 5747 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea | 5748 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
f151d9db | 5749 | nl80211_check_u16); |
ea54fba2 | 5750 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea | 5751 | mask, NL80211_MESHCONF_MAX_RETRIES, |
f151d9db | 5752 | nl80211_check_u8); |
ea54fba2 | 5753 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
f151d9db | 5754 | mask, NL80211_MESHCONF_TTL, nl80211_check_u8); |
ea54fba2 | 5755 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea | 5756 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
f151d9db | 5757 | nl80211_check_u8); |
ea54fba2 | 5758 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea | 5759 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
f151d9db | 5760 | nl80211_check_bool); |
ea54fba2 MP |
5761 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
5762 | 1, 255, mask, | |
a4f606ea | 5763 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
f151d9db | 5764 | nl80211_check_u32); |
ea54fba2 | 5765 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea | 5766 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
f151d9db | 5767 | nl80211_check_u8); |
ea54fba2 | 5768 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea | 5769 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
f151d9db | 5770 | nl80211_check_u32); |
ea54fba2 | 5771 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea | 5772 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
f151d9db | 5773 | nl80211_check_u16); |
ea54fba2 MP |
5774 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
5775 | 1, 65535, mask, | |
a4f606ea | 5776 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
f151d9db | 5777 | nl80211_check_u32); |
93da9cc1 | 5778 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
5779 | 1, 65535, mask, |
5780 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
f151d9db | 5781 | nl80211_check_u16); |
dca7e943 | 5782 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
5783 | 1, 65535, mask, |
5784 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
f151d9db | 5785 | nl80211_check_u16); |
93da9cc1 | 5786 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5787 | dot11MeshHWMPnetDiameterTraversalTime, |
5788 | 1, 65535, mask, | |
a4f606ea | 5789 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
f151d9db | 5790 | nl80211_check_u16); |
ea54fba2 MP |
5791 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
5792 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
f151d9db | 5793 | nl80211_check_u8); |
ea54fba2 MP |
5794 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
5795 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
f151d9db | 5796 | nl80211_check_u16); |
63c5723b | 5797 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5798 | dot11MeshGateAnnouncementProtocol, 0, 1, |
5799 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
f151d9db | 5800 | nl80211_check_bool); |
ea54fba2 | 5801 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea | 5802 | mask, NL80211_MESHCONF_FORWARDING, |
f151d9db | 5803 | nl80211_check_bool); |
83374fe9 | 5804 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 5805 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
f151d9db | 5806 | nl80211_check_s32); |
9757235f MH |
5807 | /* |
5808 | * Check HT operation mode based on | |
5809 | * IEEE 802.11 2012 8.4.2.59 HT Operation element. | |
5810 | */ | |
5811 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { | |
5812 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); | |
5813 | ||
5814 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | | |
5815 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | | |
5816 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) | |
5817 | return -EINVAL; | |
5818 | ||
5819 | if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) && | |
5820 | (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) | |
5821 | return -EINVAL; | |
5822 | ||
5823 | switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) { | |
5824 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: | |
5825 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: | |
5826 | if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) | |
5827 | return -EINVAL; | |
5828 | break; | |
5829 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: | |
5830 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: | |
5831 | if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) | |
5832 | return -EINVAL; | |
5833 | break; | |
5834 | } | |
5835 | cfg->ht_opmode = ht_opmode; | |
5836 | } | |
ac1073a6 | 5837 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
ea54fba2 | 5838 | 1, 65535, mask, |
ac1073a6 | 5839 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
f151d9db | 5840 | nl80211_check_u32); |
ea54fba2 | 5841 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 5842 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
f151d9db | 5843 | nl80211_check_u16); |
728b19e5 | 5844 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5845 | dot11MeshHWMPconfirmationInterval, |
5846 | 1, 65535, mask, | |
728b19e5 | 5847 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
f151d9db | 5848 | nl80211_check_u16); |
3b1c5a53 MP |
5849 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
5850 | NL80211_MESH_POWER_ACTIVE, | |
5851 | NL80211_MESH_POWER_MAX, | |
5852 | mask, NL80211_MESHCONF_POWER_MODE, | |
ff9a71af | 5853 | nl80211_check_power_mode); |
3b1c5a53 MP |
5854 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
5855 | 0, 65535, mask, | |
f151d9db | 5856 | NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16); |
31f909a2 | 5857 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
8e7c0538 | 5858 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
f151d9db | 5859 | nl80211_check_u32); |
bd90fdcc JB |
5860 | if (mask_out) |
5861 | *mask_out = mask; | |
c80d545d | 5862 | |
bd90fdcc JB |
5863 | return 0; |
5864 | ||
5865 | #undef FILL_IN_MESH_PARAM_IF_SET | |
5866 | } | |
5867 | ||
c80d545d JC |
5868 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
5869 | struct mesh_setup *setup) | |
5870 | { | |
bb2798d4 | 5871 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
5872 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
5873 | ||
5874 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
5875 | return -EINVAL; | |
5876 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
5877 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
5878 | nl80211_mesh_setup_params_policy)) | |
5879 | return -EINVAL; | |
5880 | ||
d299a1f2 JC |
5881 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
5882 | setup->sync_method = | |
5883 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
5884 | IEEE80211_SYNC_METHOD_VENDOR : | |
5885 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
5886 | ||
c80d545d JC |
5887 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
5888 | setup->path_sel_proto = | |
5889 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5890 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5891 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5892 | ||
5893 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5894 | setup->path_metric = | |
5895 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5896 | IEEE80211_PATH_METRIC_VENDOR : | |
5897 | IEEE80211_PATH_METRIC_AIRTIME; | |
5898 | ||
581a8b0f | 5899 | if (tb[NL80211_MESH_SETUP_IE]) { |
c80d545d | 5900 | struct nlattr *ieattr = |
581a8b0f | 5901 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5902 | if (!is_valid_ie_attr(ieattr)) |
5903 | return -EINVAL; | |
581a8b0f JC |
5904 | setup->ie = nla_data(ieattr); |
5905 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5906 | } |
bb2798d4 TP |
5907 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5908 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5909 | return -EINVAL; | |
5910 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5911 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5912 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5913 | if (setup->is_secure) |
5914 | setup->user_mpm = true; | |
c80d545d | 5915 | |
6e16d90b CT |
5916 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5917 | if (!setup->user_mpm) | |
5918 | return -EINVAL; | |
5919 | setup->auth_id = | |
5920 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5921 | } | |
5922 | ||
c80d545d JC |
5923 | return 0; |
5924 | } | |
5925 | ||
24bdd9f4 | 5926 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5927 | struct genl_info *info) |
bd90fdcc JB |
5928 | { |
5929 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5930 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5931 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5932 | struct mesh_config cfg; |
5933 | u32 mask; | |
5934 | int err; | |
5935 | ||
29cbe68c JB |
5936 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5937 | return -EOPNOTSUPP; | |
5938 | ||
24bdd9f4 | 5939 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5940 | return -EOPNOTSUPP; |
5941 | ||
24bdd9f4 | 5942 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5943 | if (err) |
5944 | return err; | |
5945 | ||
29cbe68c JB |
5946 | wdev_lock(wdev); |
5947 | if (!wdev->mesh_id_len) | |
5948 | err = -ENOLINK; | |
5949 | ||
5950 | if (!err) | |
e35e4d28 | 5951 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5952 | |
5953 | wdev_unlock(wdev); | |
5954 | ||
5955 | return err; | |
93da9cc1 | 5956 | } |
5957 | ||
ad30ca2c AN |
5958 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
5959 | struct sk_buff *msg) | |
f130347c | 5960 | { |
f130347c LR |
5961 | struct nlattr *nl_reg_rules; |
5962 | unsigned int i; | |
f130347c | 5963 | |
458f4f9e JB |
5964 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
5965 | (regdom->dfs_region && | |
5966 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
ad30ca2c | 5967 | goto nla_put_failure; |
458f4f9e | 5968 | |
f130347c LR |
5969 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5970 | if (!nl_reg_rules) | |
ad30ca2c | 5971 | goto nla_put_failure; |
f130347c | 5972 | |
458f4f9e | 5973 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5974 | struct nlattr *nl_reg_rule; |
5975 | const struct ieee80211_reg_rule *reg_rule; | |
5976 | const struct ieee80211_freq_range *freq_range; | |
5977 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 5978 | unsigned int max_bandwidth_khz; |
f130347c | 5979 | |
458f4f9e | 5980 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5981 | freq_range = ®_rule->freq_range; |
5982 | power_rule = ®_rule->power_rule; | |
5983 | ||
5984 | nl_reg_rule = nla_nest_start(msg, i); | |
5985 | if (!nl_reg_rule) | |
ad30ca2c | 5986 | goto nla_put_failure; |
f130347c | 5987 | |
97524820 JD |
5988 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
5989 | if (!max_bandwidth_khz) | |
5990 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
5991 | reg_rule); | |
5992 | ||
9360ffd1 DM |
5993 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5994 | reg_rule->flags) || | |
5995 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5996 | freq_range->start_freq_khz) || | |
5997 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5998 | freq_range->end_freq_khz) || | |
5999 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 6000 | max_bandwidth_khz) || |
9360ffd1 DM |
6001 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
6002 | power_rule->max_antenna_gain) || | |
6003 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
6004 | power_rule->max_eirp) || |
6005 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
6006 | reg_rule->dfs_cac_ms)) | |
ad30ca2c | 6007 | goto nla_put_failure; |
f130347c LR |
6008 | |
6009 | nla_nest_end(msg, nl_reg_rule); | |
6010 | } | |
6011 | ||
6012 | nla_nest_end(msg, nl_reg_rules); | |
ad30ca2c AN |
6013 | return 0; |
6014 | ||
6015 | nla_put_failure: | |
6016 | return -EMSGSIZE; | |
6017 | } | |
6018 | ||
6019 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) | |
6020 | { | |
6021 | const struct ieee80211_regdomain *regdom = NULL; | |
6022 | struct cfg80211_registered_device *rdev; | |
6023 | struct wiphy *wiphy = NULL; | |
6024 | struct sk_buff *msg; | |
6025 | void *hdr; | |
6026 | ||
6027 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
6028 | if (!msg) | |
6029 | return -ENOBUFS; | |
6030 | ||
6031 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
6032 | NL80211_CMD_GET_REG); | |
6033 | if (!hdr) | |
6034 | goto put_failure; | |
6035 | ||
6036 | if (info->attrs[NL80211_ATTR_WIPHY]) { | |
1bdd716c AN |
6037 | bool self_managed; |
6038 | ||
ad30ca2c AN |
6039 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
6040 | if (IS_ERR(rdev)) { | |
6041 | nlmsg_free(msg); | |
6042 | return PTR_ERR(rdev); | |
6043 | } | |
6044 | ||
6045 | wiphy = &rdev->wiphy; | |
1bdd716c AN |
6046 | self_managed = wiphy->regulatory_flags & |
6047 | REGULATORY_WIPHY_SELF_MANAGED; | |
ad30ca2c AN |
6048 | regdom = get_wiphy_regdom(wiphy); |
6049 | ||
1bdd716c AN |
6050 | /* a self-managed-reg device must have a private regdom */ |
6051 | if (WARN_ON(!regdom && self_managed)) { | |
6052 | nlmsg_free(msg); | |
6053 | return -EINVAL; | |
6054 | } | |
6055 | ||
ad30ca2c AN |
6056 | if (regdom && |
6057 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
6058 | goto nla_put_failure; | |
6059 | } | |
6060 | ||
6061 | if (!wiphy && reg_last_request_cell_base() && | |
6062 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
6063 | NL80211_USER_REG_HINT_CELL_BASE)) | |
6064 | goto nla_put_failure; | |
6065 | ||
6066 | rcu_read_lock(); | |
6067 | ||
6068 | if (!regdom) | |
6069 | regdom = rcu_dereference(cfg80211_regdomain); | |
6070 | ||
6071 | if (nl80211_put_regdom(regdom, msg)) | |
6072 | goto nla_put_failure_rcu; | |
6073 | ||
6074 | rcu_read_unlock(); | |
f130347c LR |
6075 | |
6076 | genlmsg_end(msg, hdr); | |
5fe231e8 | 6077 | return genlmsg_reply(msg, info); |
f130347c | 6078 | |
458f4f9e JB |
6079 | nla_put_failure_rcu: |
6080 | rcu_read_unlock(); | |
f130347c LR |
6081 | nla_put_failure: |
6082 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 6083 | put_failure: |
d080e275 | 6084 | nlmsg_free(msg); |
5fe231e8 | 6085 | return -EMSGSIZE; |
f130347c LR |
6086 | } |
6087 | ||
ad30ca2c AN |
6088 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
6089 | u32 seq, int flags, struct wiphy *wiphy, | |
6090 | const struct ieee80211_regdomain *regdom) | |
6091 | { | |
6092 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | |
6093 | NL80211_CMD_GET_REG); | |
6094 | ||
6095 | if (!hdr) | |
6096 | return -1; | |
6097 | ||
6098 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); | |
6099 | ||
6100 | if (nl80211_put_regdom(regdom, msg)) | |
6101 | goto nla_put_failure; | |
6102 | ||
6103 | if (!wiphy && reg_last_request_cell_base() && | |
6104 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
6105 | NL80211_USER_REG_HINT_CELL_BASE)) | |
6106 | goto nla_put_failure; | |
6107 | ||
6108 | if (wiphy && | |
6109 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
6110 | goto nla_put_failure; | |
6111 | ||
1bdd716c AN |
6112 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
6113 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
6114 | goto nla_put_failure; | |
6115 | ||
053c095a JB |
6116 | genlmsg_end(msg, hdr); |
6117 | return 0; | |
ad30ca2c AN |
6118 | |
6119 | nla_put_failure: | |
6120 | genlmsg_cancel(msg, hdr); | |
6121 | return -EMSGSIZE; | |
6122 | } | |
6123 | ||
6124 | static int nl80211_get_reg_dump(struct sk_buff *skb, | |
6125 | struct netlink_callback *cb) | |
6126 | { | |
6127 | const struct ieee80211_regdomain *regdom = NULL; | |
6128 | struct cfg80211_registered_device *rdev; | |
6129 | int err, reg_idx, start = cb->args[2]; | |
6130 | ||
6131 | rtnl_lock(); | |
6132 | ||
6133 | if (cfg80211_regdomain && start == 0) { | |
6134 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
6135 | NLM_F_MULTI, NULL, | |
6136 | rtnl_dereference(cfg80211_regdomain)); | |
6137 | if (err < 0) | |
6138 | goto out_err; | |
6139 | } | |
6140 | ||
6141 | /* the global regdom is idx 0 */ | |
6142 | reg_idx = 1; | |
6143 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | |
6144 | regdom = get_wiphy_regdom(&rdev->wiphy); | |
6145 | if (!regdom) | |
6146 | continue; | |
6147 | ||
6148 | if (++reg_idx <= start) | |
6149 | continue; | |
6150 | ||
6151 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
6152 | NLM_F_MULTI, &rdev->wiphy, regdom); | |
6153 | if (err < 0) { | |
6154 | reg_idx--; | |
6155 | break; | |
6156 | } | |
6157 | } | |
6158 | ||
6159 | cb->args[2] = reg_idx; | |
6160 | err = skb->len; | |
6161 | out_err: | |
6162 | rtnl_unlock(); | |
6163 | return err; | |
6164 | } | |
6165 | ||
b6863036 JB |
6166 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
6167 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { | |
6168 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, | |
6169 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
6170 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
6171 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
6172 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
6173 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
6174 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, | |
6175 | }; | |
6176 | ||
6177 | static int parse_reg_rule(struct nlattr *tb[], | |
6178 | struct ieee80211_reg_rule *reg_rule) | |
6179 | { | |
6180 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
6181 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
6182 | ||
6183 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
6184 | return -EINVAL; | |
6185 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
6186 | return -EINVAL; | |
6187 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
6188 | return -EINVAL; | |
6189 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
6190 | return -EINVAL; | |
6191 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
6192 | return -EINVAL; | |
6193 | ||
6194 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
6195 | ||
6196 | freq_range->start_freq_khz = | |
6197 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
6198 | freq_range->end_freq_khz = | |
6199 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
6200 | freq_range->max_bandwidth_khz = | |
6201 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
6202 | ||
6203 | power_rule->max_eirp = | |
6204 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
6205 | ||
6206 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
6207 | power_rule->max_antenna_gain = | |
6208 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
6209 | ||
6210 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) | |
6211 | reg_rule->dfs_cac_ms = | |
6212 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
6213 | ||
6214 | return 0; | |
6215 | } | |
6216 | ||
b2e1b302 LR |
6217 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
6218 | { | |
6219 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
6220 | struct nlattr *nl_reg_rule; | |
ea372c54 JB |
6221 | char *alpha2; |
6222 | int rem_reg_rules, r; | |
b2e1b302 | 6223 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
4c7d3982 | 6224 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
ea372c54 | 6225 | struct ieee80211_regdomain *rd; |
b2e1b302 LR |
6226 | |
6227 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
6228 | return -EINVAL; | |
6229 | ||
6230 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
6231 | return -EINVAL; | |
6232 | ||
6233 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
6234 | ||
8b60b078 LR |
6235 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
6236 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
6237 | ||
b2e1b302 | 6238 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 6239 | rem_reg_rules) { |
b2e1b302 LR |
6240 | num_rules++; |
6241 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 6242 | return -EINVAL; |
b2e1b302 LR |
6243 | } |
6244 | ||
e438768f LR |
6245 | if (!reg_is_valid_request(alpha2)) |
6246 | return -EINVAL; | |
6247 | ||
b2e1b302 | 6248 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 6249 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
6250 | |
6251 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
6252 | if (!rd) |
6253 | return -ENOMEM; | |
b2e1b302 LR |
6254 | |
6255 | rd->n_reg_rules = num_rules; | |
6256 | rd->alpha2[0] = alpha2[0]; | |
6257 | rd->alpha2[1] = alpha2[1]; | |
6258 | ||
8b60b078 LR |
6259 | /* |
6260 | * Disable DFS master mode if the DFS region was | |
6261 | * not supported or known on this kernel. | |
6262 | */ | |
6263 | if (reg_supported_dfs_region(dfs_region)) | |
6264 | rd->dfs_region = dfs_region; | |
6265 | ||
b2e1b302 | 6266 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 6267 | rem_reg_rules) { |
ae811e21 JB |
6268 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
6269 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
6270 | reg_rule_policy); | |
6271 | if (r) | |
6272 | goto bad_reg; | |
b2e1b302 LR |
6273 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
6274 | if (r) | |
6275 | goto bad_reg; | |
6276 | ||
6277 | rule_idx++; | |
6278 | ||
d0e18f83 LR |
6279 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
6280 | r = -EINVAL; | |
b2e1b302 | 6281 | goto bad_reg; |
d0e18f83 | 6282 | } |
b2e1b302 LR |
6283 | } |
6284 | ||
06627990 JB |
6285 | /* set_regdom takes ownership of rd */ |
6286 | return set_regdom(rd, REGD_SOURCE_CRDA); | |
d2372b31 | 6287 | bad_reg: |
b2e1b302 | 6288 | kfree(rd); |
d0e18f83 | 6289 | return r; |
b2e1b302 | 6290 | } |
b6863036 | 6291 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
b2e1b302 | 6292 | |
83f5e2cf JB |
6293 | static int validate_scan_freqs(struct nlattr *freqs) |
6294 | { | |
6295 | struct nlattr *attr1, *attr2; | |
6296 | int n_channels = 0, tmp1, tmp2; | |
6297 | ||
6298 | nla_for_each_nested(attr1, freqs, tmp1) { | |
6299 | n_channels++; | |
6300 | /* | |
6301 | * Some hardware has a limited channel list for | |
6302 | * scanning, and it is pretty much nonsensical | |
6303 | * to scan for a channel twice, so disallow that | |
6304 | * and don't require drivers to check that the | |
6305 | * channel list they get isn't longer than what | |
6306 | * they can scan, as long as they can scan all | |
6307 | * the channels they registered at once. | |
6308 | */ | |
6309 | nla_for_each_nested(attr2, freqs, tmp2) | |
6310 | if (attr1 != attr2 && | |
6311 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
6312 | return 0; | |
6313 | } | |
6314 | ||
6315 | return n_channels; | |
6316 | } | |
6317 | ||
57fbcce3 | 6318 | static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) |
38de03d2 | 6319 | { |
57fbcce3 | 6320 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
38de03d2 AS |
6321 | } |
6322 | ||
6323 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, | |
6324 | struct cfg80211_bss_selection *bss_select) | |
6325 | { | |
6326 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; | |
6327 | struct nlattr *nest; | |
6328 | int err; | |
6329 | bool found = false; | |
6330 | int i; | |
6331 | ||
6332 | /* only process one nested attribute */ | |
6333 | nest = nla_data(nla); | |
6334 | if (!nla_ok(nest, nla_len(nest))) | |
6335 | return -EINVAL; | |
6336 | ||
6337 | err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest), | |
6338 | nla_len(nest), nl80211_bss_select_policy); | |
6339 | if (err) | |
6340 | return err; | |
6341 | ||
6342 | /* only one attribute may be given */ | |
6343 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { | |
6344 | if (attr[i]) { | |
6345 | if (found) | |
6346 | return -EINVAL; | |
6347 | found = true; | |
6348 | } | |
6349 | } | |
6350 | ||
6351 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; | |
6352 | ||
6353 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) | |
6354 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; | |
6355 | ||
6356 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { | |
6357 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; | |
6358 | bss_select->param.band_pref = | |
6359 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); | |
6360 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) | |
6361 | return -EINVAL; | |
6362 | } | |
6363 | ||
6364 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { | |
6365 | struct nl80211_bss_select_rssi_adjust *adj_param; | |
6366 | ||
6367 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); | |
6368 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; | |
6369 | bss_select->param.adjust.band = adj_param->band; | |
6370 | bss_select->param.adjust.delta = adj_param->delta; | |
6371 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) | |
6372 | return -EINVAL; | |
6373 | } | |
6374 | ||
6375 | /* user-space did not provide behaviour attribute */ | |
6376 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) | |
6377 | return -EINVAL; | |
6378 | ||
6379 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) | |
6380 | return -EINVAL; | |
6381 | ||
6382 | return 0; | |
6383 | } | |
6384 | ||
ad2b26ab JB |
6385 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
6386 | u8 *mac_addr, u8 *mac_addr_mask) | |
6387 | { | |
6388 | int i; | |
6389 | ||
6390 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { | |
d2beae10 JP |
6391 | eth_zero_addr(mac_addr); |
6392 | eth_zero_addr(mac_addr_mask); | |
ad2b26ab JB |
6393 | mac_addr[0] = 0x2; |
6394 | mac_addr_mask[0] = 0x3; | |
6395 | ||
6396 | return 0; | |
6397 | } | |
6398 | ||
6399 | /* need both or none */ | |
6400 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) | |
6401 | return -EINVAL; | |
6402 | ||
6403 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); | |
6404 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); | |
6405 | ||
6406 | /* don't allow or configure an mcast address */ | |
6407 | if (!is_multicast_ether_addr(mac_addr_mask) || | |
6408 | is_multicast_ether_addr(mac_addr)) | |
6409 | return -EINVAL; | |
6410 | ||
6411 | /* | |
6412 | * allow users to pass a MAC address that has bits set outside | |
6413 | * of the mask, but don't bother drivers with having to deal | |
6414 | * with such bits | |
6415 | */ | |
6416 | for (i = 0; i < ETH_ALEN; i++) | |
6417 | mac_addr[i] &= mac_addr_mask[i]; | |
6418 | ||
6419 | return 0; | |
6420 | } | |
6421 | ||
2a519311 JB |
6422 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
6423 | { | |
4c476991 | 6424 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 6425 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 6426 | struct cfg80211_scan_request *request; |
2a519311 JB |
6427 | struct nlattr *attr; |
6428 | struct wiphy *wiphy; | |
83f5e2cf | 6429 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 6430 | size_t ie_len; |
2a519311 | 6431 | |
f4a11bb0 JB |
6432 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6433 | return -EINVAL; | |
6434 | ||
79c97e97 | 6435 | wiphy = &rdev->wiphy; |
2a519311 | 6436 | |
4c476991 JB |
6437 | if (!rdev->ops->scan) |
6438 | return -EOPNOTSUPP; | |
2a519311 | 6439 | |
f9d15d16 | 6440 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
6441 | err = -EBUSY; |
6442 | goto unlock; | |
6443 | } | |
2a519311 JB |
6444 | |
6445 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
6446 | n_channels = validate_scan_freqs( |
6447 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
6448 | if (!n_channels) { |
6449 | err = -EINVAL; | |
6450 | goto unlock; | |
6451 | } | |
2a519311 | 6452 | } else { |
bdfbec2d | 6453 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
6454 | } |
6455 | ||
6456 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
6457 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
6458 | n_ssids++; | |
6459 | ||
f9f47529 JB |
6460 | if (n_ssids > wiphy->max_scan_ssids) { |
6461 | err = -EINVAL; | |
6462 | goto unlock; | |
6463 | } | |
2a519311 | 6464 | |
70692ad2 JM |
6465 | if (info->attrs[NL80211_ATTR_IE]) |
6466 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6467 | else | |
6468 | ie_len = 0; | |
6469 | ||
f9f47529 JB |
6470 | if (ie_len > wiphy->max_scan_ie_len) { |
6471 | err = -EINVAL; | |
6472 | goto unlock; | |
6473 | } | |
18a83659 | 6474 | |
2a519311 | 6475 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
6476 | + sizeof(*request->ssids) * n_ssids |
6477 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 6478 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
6479 | if (!request) { |
6480 | err = -ENOMEM; | |
6481 | goto unlock; | |
6482 | } | |
2a519311 | 6483 | |
2a519311 | 6484 | if (n_ssids) |
5ba63533 | 6485 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 6486 | request->n_ssids = n_ssids; |
70692ad2 | 6487 | if (ie_len) { |
13874e4b | 6488 | if (n_ssids) |
70692ad2 JM |
6489 | request->ie = (void *)(request->ssids + n_ssids); |
6490 | else | |
6491 | request->ie = (void *)(request->channels + n_channels); | |
6492 | } | |
2a519311 | 6493 | |
584991dc | 6494 | i = 0; |
2a519311 JB |
6495 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
6496 | /* user specified, bail out if channel not found */ | |
2a519311 | 6497 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
6498 | struct ieee80211_channel *chan; |
6499 | ||
6500 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
6501 | ||
6502 | if (!chan) { | |
2a519311 JB |
6503 | err = -EINVAL; |
6504 | goto out_free; | |
6505 | } | |
584991dc JB |
6506 | |
6507 | /* ignore disabled channels */ | |
6508 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6509 | continue; | |
6510 | ||
6511 | request->channels[i] = chan; | |
2a519311 JB |
6512 | i++; |
6513 | } | |
6514 | } else { | |
57fbcce3 | 6515 | enum nl80211_band band; |
34850ab2 | 6516 | |
2a519311 | 6517 | /* all channels */ |
57fbcce3 | 6518 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
2a519311 | 6519 | int j; |
7a087e74 | 6520 | |
2a519311 JB |
6521 | if (!wiphy->bands[band]) |
6522 | continue; | |
6523 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
6524 | struct ieee80211_channel *chan; |
6525 | ||
6526 | chan = &wiphy->bands[band]->channels[j]; | |
6527 | ||
6528 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6529 | continue; | |
6530 | ||
6531 | request->channels[i] = chan; | |
2a519311 JB |
6532 | i++; |
6533 | } | |
6534 | } | |
6535 | } | |
6536 | ||
584991dc JB |
6537 | if (!i) { |
6538 | err = -EINVAL; | |
6539 | goto out_free; | |
6540 | } | |
6541 | ||
6542 | request->n_channels = i; | |
6543 | ||
2a519311 | 6544 | i = 0; |
13874e4b | 6545 | if (n_ssids) { |
2a519311 | 6546 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
57a27e1d | 6547 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
6548 | err = -EINVAL; |
6549 | goto out_free; | |
6550 | } | |
57a27e1d | 6551 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 6552 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
6553 | i++; |
6554 | } | |
6555 | } | |
6556 | ||
70692ad2 JM |
6557 | if (info->attrs[NL80211_ATTR_IE]) { |
6558 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
6559 | memcpy((void *)request->ie, |
6560 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
6561 | request->ie_len); |
6562 | } | |
6563 | ||
57fbcce3 | 6564 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
a401d2bb JB |
6565 | if (wiphy->bands[i]) |
6566 | request->rates[i] = | |
6567 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
6568 | |
6569 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
6570 | nla_for_each_nested(attr, | |
6571 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
6572 | tmp) { | |
57fbcce3 | 6573 | enum nl80211_band band = nla_type(attr); |
34850ab2 | 6574 | |
57fbcce3 | 6575 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
34850ab2 JB |
6576 | err = -EINVAL; |
6577 | goto out_free; | |
6578 | } | |
1b09cd82 FF |
6579 | |
6580 | if (!wiphy->bands[band]) | |
6581 | continue; | |
6582 | ||
34850ab2 JB |
6583 | err = ieee80211_get_ratemask(wiphy->bands[band], |
6584 | nla_data(attr), | |
6585 | nla_len(attr), | |
6586 | &request->rates[band]); | |
6587 | if (err) | |
6588 | goto out_free; | |
6589 | } | |
6590 | } | |
6591 | ||
1d76250b AS |
6592 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
6593 | if (!wiphy_ext_feature_isset(wiphy, | |
6594 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { | |
6595 | err = -EOPNOTSUPP; | |
6596 | goto out_free; | |
6597 | } | |
6598 | ||
6599 | request->duration = | |
6600 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); | |
6601 | request->duration_mandatory = | |
6602 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); | |
6603 | } | |
6604 | ||
46856bbf | 6605 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
6606 | request->flags = nla_get_u32( |
6607 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
6608 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
6609 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
6610 | err = -EOPNOTSUPP; |
6611 | goto out_free; | |
6612 | } | |
ad2b26ab JB |
6613 | |
6614 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
6615 | if (!(wiphy->features & | |
6616 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { | |
6617 | err = -EOPNOTSUPP; | |
6618 | goto out_free; | |
6619 | } | |
6620 | ||
6621 | if (wdev->current_bss) { | |
6622 | err = -EOPNOTSUPP; | |
6623 | goto out_free; | |
6624 | } | |
6625 | ||
6626 | err = nl80211_parse_random_mac(info->attrs, | |
6627 | request->mac_addr, | |
6628 | request->mac_addr_mask); | |
6629 | if (err) | |
6630 | goto out_free; | |
6631 | } | |
46856bbf | 6632 | } |
ed473771 | 6633 | |
e9f935e3 RM |
6634 | request->no_cck = |
6635 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
6636 | ||
818965d3 JM |
6637 | if (info->attrs[NL80211_ATTR_MAC]) |
6638 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), | |
6639 | ETH_ALEN); | |
6640 | else | |
6641 | eth_broadcast_addr(request->bssid); | |
6642 | ||
fd014284 | 6643 | request->wdev = wdev; |
79c97e97 | 6644 | request->wiphy = &rdev->wiphy; |
15d6030b | 6645 | request->scan_start = jiffies; |
2a519311 | 6646 | |
79c97e97 | 6647 | rdev->scan_req = request; |
e35e4d28 | 6648 | err = rdev_scan(rdev, request); |
2a519311 | 6649 | |
463d0183 | 6650 | if (!err) { |
fd014284 JB |
6651 | nl80211_send_scan_start(rdev, wdev); |
6652 | if (wdev->netdev) | |
6653 | dev_hold(wdev->netdev); | |
4c476991 | 6654 | } else { |
2a519311 | 6655 | out_free: |
79c97e97 | 6656 | rdev->scan_req = NULL; |
2a519311 JB |
6657 | kfree(request); |
6658 | } | |
3b85875a | 6659 | |
f9f47529 | 6660 | unlock: |
2a519311 JB |
6661 | return err; |
6662 | } | |
6663 | ||
91d3ab46 VK |
6664 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
6665 | { | |
6666 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6667 | struct wireless_dev *wdev = info->user_ptr[1]; | |
6668 | ||
6669 | if (!rdev->ops->abort_scan) | |
6670 | return -EOPNOTSUPP; | |
6671 | ||
6672 | if (rdev->scan_msg) | |
6673 | return 0; | |
6674 | ||
6675 | if (!rdev->scan_req) | |
6676 | return -ENOENT; | |
6677 | ||
6678 | rdev_abort_scan(rdev, wdev); | |
6679 | return 0; | |
6680 | } | |
6681 | ||
3b06d277 AS |
6682 | static int |
6683 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, | |
6684 | struct cfg80211_sched_scan_request *request, | |
6685 | struct nlattr **attrs) | |
6686 | { | |
6687 | int tmp, err, i = 0; | |
6688 | struct nlattr *attr; | |
6689 | ||
6690 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { | |
6691 | u32 interval; | |
6692 | ||
6693 | /* | |
6694 | * If scan plans are not specified, | |
6695 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this | |
6696 | * case one scan plan will be set with the specified scan | |
6697 | * interval and infinite number of iterations. | |
6698 | */ | |
6699 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
6700 | return -EINVAL; | |
6701 | ||
6702 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
6703 | if (!interval) | |
6704 | return -EINVAL; | |
6705 | ||
6706 | request->scan_plans[0].interval = | |
6707 | DIV_ROUND_UP(interval, MSEC_PER_SEC); | |
6708 | if (!request->scan_plans[0].interval) | |
6709 | return -EINVAL; | |
6710 | ||
6711 | if (request->scan_plans[0].interval > | |
6712 | wiphy->max_sched_scan_plan_interval) | |
6713 | request->scan_plans[0].interval = | |
6714 | wiphy->max_sched_scan_plan_interval; | |
6715 | ||
6716 | return 0; | |
6717 | } | |
6718 | ||
6719 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { | |
6720 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; | |
6721 | ||
6722 | if (WARN_ON(i >= n_plans)) | |
6723 | return -EINVAL; | |
6724 | ||
6725 | err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX, | |
6726 | nla_data(attr), nla_len(attr), | |
6727 | nl80211_plan_policy); | |
6728 | if (err) | |
6729 | return err; | |
6730 | ||
6731 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) | |
6732 | return -EINVAL; | |
6733 | ||
6734 | request->scan_plans[i].interval = | |
6735 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); | |
6736 | if (!request->scan_plans[i].interval || | |
6737 | request->scan_plans[i].interval > | |
6738 | wiphy->max_sched_scan_plan_interval) | |
6739 | return -EINVAL; | |
6740 | ||
6741 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { | |
6742 | request->scan_plans[i].iterations = | |
6743 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); | |
6744 | if (!request->scan_plans[i].iterations || | |
6745 | (request->scan_plans[i].iterations > | |
6746 | wiphy->max_sched_scan_plan_iterations)) | |
6747 | return -EINVAL; | |
6748 | } else if (i < n_plans - 1) { | |
6749 | /* | |
6750 | * All scan plans but the last one must specify | |
6751 | * a finite number of iterations | |
6752 | */ | |
6753 | return -EINVAL; | |
6754 | } | |
6755 | ||
6756 | i++; | |
6757 | } | |
6758 | ||
6759 | /* | |
6760 | * The last scan plan must not specify the number of | |
6761 | * iterations, it is supposed to run infinitely | |
6762 | */ | |
6763 | if (request->scan_plans[n_plans - 1].iterations) | |
6764 | return -EINVAL; | |
6765 | ||
6766 | return 0; | |
6767 | } | |
6768 | ||
256da02d | 6769 | static struct cfg80211_sched_scan_request * |
ad2b26ab | 6770 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
256da02d | 6771 | struct nlattr **attrs) |
807f8a8c LC |
6772 | { |
6773 | struct cfg80211_sched_scan_request *request; | |
807f8a8c | 6774 | struct nlattr *attr; |
3b06d277 | 6775 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; |
57fbcce3 | 6776 | enum nl80211_band band; |
807f8a8c | 6777 | size_t ie_len; |
a1f1c21c | 6778 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 6779 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c | 6780 | |
256da02d LC |
6781 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
6782 | return ERR_PTR(-EINVAL); | |
807f8a8c | 6783 | |
256da02d | 6784 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c | 6785 | n_channels = validate_scan_freqs( |
256da02d | 6786 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
807f8a8c | 6787 | if (!n_channels) |
256da02d | 6788 | return ERR_PTR(-EINVAL); |
807f8a8c | 6789 | } else { |
bdfbec2d | 6790 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
6791 | } |
6792 | ||
256da02d LC |
6793 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
6794 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c LC |
6795 | tmp) |
6796 | n_ssids++; | |
6797 | ||
93b6aa69 | 6798 | if (n_ssids > wiphy->max_sched_scan_ssids) |
256da02d | 6799 | return ERR_PTR(-EINVAL); |
807f8a8c | 6800 | |
ea73cbce JB |
6801 | /* |
6802 | * First, count the number of 'real' matchsets. Due to an issue with | |
6803 | * the old implementation, matchsets containing only the RSSI attribute | |
6804 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
6805 | * RSSI for all matchsets, rather than their own matchset for reporting | |
6806 | * all APs with a strong RSSI. This is needed to be compatible with | |
6807 | * older userspace that treated a matchset with only the RSSI as the | |
6808 | * global RSSI for all other matchsets - if there are other matchsets. | |
6809 | */ | |
256da02d | 6810 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 6811 | nla_for_each_nested(attr, |
256da02d | 6812 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
ea73cbce JB |
6813 | tmp) { |
6814 | struct nlattr *rssi; | |
6815 | ||
6816 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
6817 | nla_data(attr), nla_len(attr), | |
6818 | nl80211_match_policy); | |
6819 | if (err) | |
256da02d | 6820 | return ERR_PTR(err); |
ea73cbce JB |
6821 | /* add other standalone attributes here */ |
6822 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | |
6823 | n_match_sets++; | |
6824 | continue; | |
6825 | } | |
6826 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6827 | if (rssi) | |
6828 | default_match_rssi = nla_get_s32(rssi); | |
6829 | } | |
6830 | } | |
6831 | ||
6832 | /* However, if there's no other matchset, add the RSSI one */ | |
6833 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
6834 | n_match_sets = 1; | |
a1f1c21c LC |
6835 | |
6836 | if (n_match_sets > wiphy->max_match_sets) | |
256da02d | 6837 | return ERR_PTR(-EINVAL); |
a1f1c21c | 6838 | |
256da02d LC |
6839 | if (attrs[NL80211_ATTR_IE]) |
6840 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); | |
807f8a8c LC |
6841 | else |
6842 | ie_len = 0; | |
6843 | ||
5a865bad | 6844 | if (ie_len > wiphy->max_sched_scan_ie_len) |
256da02d | 6845 | return ERR_PTR(-EINVAL); |
c10841ca | 6846 | |
3b06d277 AS |
6847 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
6848 | /* | |
6849 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since | |
6850 | * each scan plan already specifies its own interval | |
6851 | */ | |
6852 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
6853 | return ERR_PTR(-EINVAL); | |
6854 | ||
6855 | nla_for_each_nested(attr, | |
6856 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) | |
6857 | n_plans++; | |
6858 | } else { | |
6859 | /* | |
6860 | * The scan interval attribute is kept for backward | |
6861 | * compatibility. If no scan plans are specified and sched scan | |
6862 | * interval is specified, one scan plan will be set with this | |
6863 | * scan interval and infinite number of iterations. | |
6864 | */ | |
6865 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
6866 | return ERR_PTR(-EINVAL); | |
6867 | ||
6868 | n_plans = 1; | |
6869 | } | |
6870 | ||
6871 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) | |
6872 | return ERR_PTR(-EINVAL); | |
6873 | ||
807f8a8c | 6874 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 6875 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 6876 | + sizeof(*request->match_sets) * n_match_sets |
3b06d277 | 6877 | + sizeof(*request->scan_plans) * n_plans |
a2cd43c5 | 6878 | + sizeof(*request->channels) * n_channels |
807f8a8c | 6879 | + ie_len, GFP_KERNEL); |
256da02d LC |
6880 | if (!request) |
6881 | return ERR_PTR(-ENOMEM); | |
807f8a8c LC |
6882 | |
6883 | if (n_ssids) | |
6884 | request->ssids = (void *)&request->channels[n_channels]; | |
6885 | request->n_ssids = n_ssids; | |
6886 | if (ie_len) { | |
13874e4b | 6887 | if (n_ssids) |
807f8a8c LC |
6888 | request->ie = (void *)(request->ssids + n_ssids); |
6889 | else | |
6890 | request->ie = (void *)(request->channels + n_channels); | |
6891 | } | |
6892 | ||
a1f1c21c LC |
6893 | if (n_match_sets) { |
6894 | if (request->ie) | |
6895 | request->match_sets = (void *)(request->ie + ie_len); | |
13874e4b | 6896 | else if (n_ssids) |
a1f1c21c LC |
6897 | request->match_sets = |
6898 | (void *)(request->ssids + n_ssids); | |
6899 | else | |
6900 | request->match_sets = | |
6901 | (void *)(request->channels + n_channels); | |
6902 | } | |
6903 | request->n_match_sets = n_match_sets; | |
6904 | ||
3b06d277 AS |
6905 | if (n_match_sets) |
6906 | request->scan_plans = (void *)(request->match_sets + | |
6907 | n_match_sets); | |
6908 | else if (request->ie) | |
6909 | request->scan_plans = (void *)(request->ie + ie_len); | |
6910 | else if (n_ssids) | |
6911 | request->scan_plans = (void *)(request->ssids + n_ssids); | |
6912 | else | |
6913 | request->scan_plans = (void *)(request->channels + n_channels); | |
6914 | ||
6915 | request->n_scan_plans = n_plans; | |
6916 | ||
807f8a8c | 6917 | i = 0; |
256da02d | 6918 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c LC |
6919 | /* user specified, bail out if channel not found */ |
6920 | nla_for_each_nested(attr, | |
256da02d | 6921 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
807f8a8c LC |
6922 | tmp) { |
6923 | struct ieee80211_channel *chan; | |
6924 | ||
6925 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
6926 | ||
6927 | if (!chan) { | |
6928 | err = -EINVAL; | |
6929 | goto out_free; | |
6930 | } | |
6931 | ||
6932 | /* ignore disabled channels */ | |
6933 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6934 | continue; | |
6935 | ||
6936 | request->channels[i] = chan; | |
6937 | i++; | |
6938 | } | |
6939 | } else { | |
6940 | /* all channels */ | |
57fbcce3 | 6941 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
807f8a8c | 6942 | int j; |
7a087e74 | 6943 | |
807f8a8c LC |
6944 | if (!wiphy->bands[band]) |
6945 | continue; | |
6946 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
6947 | struct ieee80211_channel *chan; | |
6948 | ||
6949 | chan = &wiphy->bands[band]->channels[j]; | |
6950 | ||
6951 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6952 | continue; | |
6953 | ||
6954 | request->channels[i] = chan; | |
6955 | i++; | |
6956 | } | |
6957 | } | |
6958 | } | |
6959 | ||
6960 | if (!i) { | |
6961 | err = -EINVAL; | |
6962 | goto out_free; | |
6963 | } | |
6964 | ||
6965 | request->n_channels = i; | |
6966 | ||
6967 | i = 0; | |
13874e4b | 6968 | if (n_ssids) { |
256da02d | 6969 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
807f8a8c | 6970 | tmp) { |
57a27e1d | 6971 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
6972 | err = -EINVAL; |
6973 | goto out_free; | |
6974 | } | |
57a27e1d | 6975 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
6976 | memcpy(request->ssids[i].ssid, nla_data(attr), |
6977 | nla_len(attr)); | |
807f8a8c LC |
6978 | i++; |
6979 | } | |
6980 | } | |
6981 | ||
a1f1c21c | 6982 | i = 0; |
256da02d | 6983 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 6984 | nla_for_each_nested(attr, |
256da02d | 6985 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
a1f1c21c | 6986 | tmp) { |
88e920b4 | 6987 | struct nlattr *ssid, *rssi; |
a1f1c21c | 6988 | |
ae811e21 JB |
6989 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
6990 | nla_data(attr), nla_len(attr), | |
6991 | nl80211_match_policy); | |
6992 | if (err) | |
6993 | goto out_free; | |
4a4ab0d7 | 6994 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 6995 | if (ssid) { |
ea73cbce JB |
6996 | if (WARN_ON(i >= n_match_sets)) { |
6997 | /* this indicates a programming error, | |
6998 | * the loop above should have verified | |
6999 | * things properly | |
7000 | */ | |
7001 | err = -EINVAL; | |
7002 | goto out_free; | |
7003 | } | |
7004 | ||
a1f1c21c LC |
7005 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
7006 | err = -EINVAL; | |
7007 | goto out_free; | |
7008 | } | |
7009 | memcpy(request->match_sets[i].ssid.ssid, | |
7010 | nla_data(ssid), nla_len(ssid)); | |
7011 | request->match_sets[i].ssid.ssid_len = | |
7012 | nla_len(ssid); | |
56ab364f | 7013 | /* special attribute - old implementation w/a */ |
ea73cbce JB |
7014 | request->match_sets[i].rssi_thold = |
7015 | default_match_rssi; | |
7016 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
7017 | if (rssi) | |
7018 | request->match_sets[i].rssi_thold = | |
7019 | nla_get_s32(rssi); | |
a1f1c21c LC |
7020 | } |
7021 | i++; | |
7022 | } | |
ea73cbce JB |
7023 | |
7024 | /* there was no other matchset, so the RSSI one is alone */ | |
f89f46cf | 7025 | if (i == 0 && n_match_sets) |
ea73cbce JB |
7026 | request->match_sets[0].rssi_thold = default_match_rssi; |
7027 | ||
7028 | request->min_rssi_thold = INT_MAX; | |
7029 | for (i = 0; i < n_match_sets; i++) | |
7030 | request->min_rssi_thold = | |
7031 | min(request->match_sets[i].rssi_thold, | |
7032 | request->min_rssi_thold); | |
7033 | } else { | |
7034 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
7035 | } |
7036 | ||
9900e484 JB |
7037 | if (ie_len) { |
7038 | request->ie_len = ie_len; | |
807f8a8c | 7039 | memcpy((void *)request->ie, |
256da02d | 7040 | nla_data(attrs[NL80211_ATTR_IE]), |
807f8a8c LC |
7041 | request->ie_len); |
7042 | } | |
7043 | ||
256da02d | 7044 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 | 7045 | request->flags = nla_get_u32( |
256da02d | 7046 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
00c3a6ed JB |
7047 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
7048 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
7049 | err = -EOPNOTSUPP; |
7050 | goto out_free; | |
7051 | } | |
ad2b26ab JB |
7052 | |
7053 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
7054 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; | |
7055 | ||
7056 | if (!wdev) /* must be net-detect */ | |
7057 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
7058 | ||
7059 | if (!(wiphy->features & flg)) { | |
7060 | err = -EOPNOTSUPP; | |
7061 | goto out_free; | |
7062 | } | |
7063 | ||
7064 | if (wdev && wdev->current_bss) { | |
7065 | err = -EOPNOTSUPP; | |
7066 | goto out_free; | |
7067 | } | |
7068 | ||
7069 | err = nl80211_parse_random_mac(attrs, request->mac_addr, | |
7070 | request->mac_addr_mask); | |
7071 | if (err) | |
7072 | goto out_free; | |
7073 | } | |
46856bbf | 7074 | } |
ed473771 | 7075 | |
9c748934 LC |
7076 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
7077 | request->delay = | |
7078 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); | |
7079 | ||
3b06d277 AS |
7080 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
7081 | if (err) | |
7082 | goto out_free; | |
7083 | ||
15d6030b | 7084 | request->scan_start = jiffies; |
807f8a8c | 7085 | |
256da02d | 7086 | return request; |
807f8a8c LC |
7087 | |
7088 | out_free: | |
7089 | kfree(request); | |
256da02d LC |
7090 | return ERR_PTR(err); |
7091 | } | |
7092 | ||
7093 | static int nl80211_start_sched_scan(struct sk_buff *skb, | |
7094 | struct genl_info *info) | |
7095 | { | |
7096 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7097 | struct net_device *dev = info->user_ptr[1]; | |
ad2b26ab | 7098 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
31a60ed1 | 7099 | struct cfg80211_sched_scan_request *sched_scan_req; |
256da02d LC |
7100 | int err; |
7101 | ||
7102 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
7103 | !rdev->ops->sched_scan_start) | |
7104 | return -EOPNOTSUPP; | |
7105 | ||
7106 | if (rdev->sched_scan_req) | |
7107 | return -EINPROGRESS; | |
7108 | ||
31a60ed1 JR |
7109 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
7110 | info->attrs); | |
7111 | ||
7112 | err = PTR_ERR_OR_ZERO(sched_scan_req); | |
256da02d LC |
7113 | if (err) |
7114 | goto out_err; | |
7115 | ||
31a60ed1 | 7116 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
256da02d LC |
7117 | if (err) |
7118 | goto out_free; | |
7119 | ||
31a60ed1 JR |
7120 | sched_scan_req->dev = dev; |
7121 | sched_scan_req->wiphy = &rdev->wiphy; | |
7122 | ||
93a1e86c JR |
7123 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
7124 | sched_scan_req->owner_nlportid = info->snd_portid; | |
7125 | ||
31a60ed1 | 7126 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
256da02d LC |
7127 | |
7128 | nl80211_send_sched_scan(rdev, dev, | |
7129 | NL80211_CMD_START_SCHED_SCAN); | |
7130 | return 0; | |
7131 | ||
7132 | out_free: | |
31a60ed1 | 7133 | kfree(sched_scan_req); |
256da02d | 7134 | out_err: |
807f8a8c LC |
7135 | return err; |
7136 | } | |
7137 | ||
7138 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
7139 | struct genl_info *info) | |
7140 | { | |
7141 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7142 | ||
7143 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
7144 | !rdev->ops->sched_scan_stop) | |
7145 | return -EOPNOTSUPP; | |
7146 | ||
5fe231e8 | 7147 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
7148 | } |
7149 | ||
04f39047 SW |
7150 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
7151 | struct genl_info *info) | |
7152 | { | |
7153 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7154 | struct net_device *dev = info->user_ptr[1]; | |
7155 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7156 | struct cfg80211_chan_def chandef; | |
55f7435c | 7157 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 7158 | unsigned int cac_time_ms; |
04f39047 SW |
7159 | int err; |
7160 | ||
55f7435c LR |
7161 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
7162 | if (dfs_region == NL80211_DFS_UNSET) | |
7163 | return -EINVAL; | |
7164 | ||
04f39047 SW |
7165 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7166 | if (err) | |
7167 | return err; | |
7168 | ||
ff311bc1 SW |
7169 | if (netif_carrier_ok(dev)) |
7170 | return -EBUSY; | |
7171 | ||
04f39047 SW |
7172 | if (wdev->cac_started) |
7173 | return -EBUSY; | |
7174 | ||
2beb6dab | 7175 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
00ec75fc | 7176 | wdev->iftype); |
04f39047 SW |
7177 | if (err < 0) |
7178 | return err; | |
7179 | ||
7180 | if (err == 0) | |
7181 | return -EINVAL; | |
7182 | ||
fe7c3a1f | 7183 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
7184 | return -EINVAL; |
7185 | ||
7186 | if (!rdev->ops->start_radar_detection) | |
7187 | return -EOPNOTSUPP; | |
7188 | ||
31559f35 JD |
7189 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
7190 | if (WARN_ON(!cac_time_ms)) | |
7191 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
7192 | ||
a1056b1b | 7193 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
04f39047 | 7194 | if (!err) { |
9e0e2961 | 7195 | wdev->chandef = chandef; |
04f39047 SW |
7196 | wdev->cac_started = true; |
7197 | wdev->cac_start_time = jiffies; | |
31559f35 | 7198 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 7199 | } |
04f39047 SW |
7200 | return err; |
7201 | } | |
7202 | ||
16ef1fe2 SW |
7203 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
7204 | { | |
7205 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7206 | struct net_device *dev = info->user_ptr[1]; | |
7207 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7208 | struct cfg80211_csa_settings params; | |
7209 | /* csa_attrs is defined static to avoid waste of stack size - this | |
7210 | * function is called under RTNL lock, so this should not be a problem. | |
7211 | */ | |
7212 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
16ef1fe2 | 7213 | int err; |
ee4bc9e7 | 7214 | bool need_new_beacon = false; |
9a774c78 | 7215 | int len, i; |
252e07ca | 7216 | u32 cs_count; |
16ef1fe2 SW |
7217 | |
7218 | if (!rdev->ops->channel_switch || | |
7219 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
7220 | return -EOPNOTSUPP; | |
7221 | ||
ee4bc9e7 SW |
7222 | switch (dev->ieee80211_ptr->iftype) { |
7223 | case NL80211_IFTYPE_AP: | |
7224 | case NL80211_IFTYPE_P2P_GO: | |
7225 | need_new_beacon = true; | |
7226 | ||
7227 | /* useless if AP is not running */ | |
7228 | if (!wdev->beacon_interval) | |
1ff79dfa | 7229 | return -ENOTCONN; |
ee4bc9e7 SW |
7230 | break; |
7231 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
7232 | if (!wdev->ssid_len) |
7233 | return -ENOTCONN; | |
7234 | break; | |
c6da674a | 7235 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
7236 | if (!wdev->mesh_id_len) |
7237 | return -ENOTCONN; | |
ee4bc9e7 SW |
7238 | break; |
7239 | default: | |
16ef1fe2 | 7240 | return -EOPNOTSUPP; |
ee4bc9e7 | 7241 | } |
16ef1fe2 SW |
7242 | |
7243 | memset(¶ms, 0, sizeof(params)); | |
7244 | ||
7245 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7246 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
7247 | return -EINVAL; | |
7248 | ||
7249 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 7250 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
7251 | return -EINVAL; |
7252 | ||
252e07ca LC |
7253 | /* Even though the attribute is u32, the specification says |
7254 | * u8, so let's make sure we don't overflow. | |
7255 | */ | |
7256 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
7257 | if (cs_count > 255) | |
7258 | return -EINVAL; | |
7259 | ||
7260 | params.count = cs_count; | |
16ef1fe2 | 7261 | |
ee4bc9e7 SW |
7262 | if (!need_new_beacon) |
7263 | goto skip_beacons; | |
7264 | ||
16ef1fe2 SW |
7265 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
7266 | if (err) | |
7267 | return err; | |
7268 | ||
7269 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
7270 | info->attrs[NL80211_ATTR_CSA_IES], | |
7271 | nl80211_policy); | |
7272 | if (err) | |
7273 | return err; | |
7274 | ||
7275 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
7276 | if (err) | |
7277 | return err; | |
7278 | ||
7279 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
7280 | return -EINVAL; | |
7281 | ||
9a774c78 AO |
7282 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
7283 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
7284 | return -EINVAL; |
7285 | ||
9a774c78 AO |
7286 | params.n_counter_offsets_beacon = len / sizeof(u16); |
7287 | if (rdev->wiphy.max_num_csa_counters && | |
7288 | (params.n_counter_offsets_beacon > | |
7289 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
7290 | return -EINVAL; |
7291 | ||
9a774c78 AO |
7292 | params.counter_offsets_beacon = |
7293 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
7294 | ||
7295 | /* sanity checks - counters should fit and be the same */ | |
7296 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
7297 | u16 offset = params.counter_offsets_beacon[i]; | |
7298 | ||
7299 | if (offset >= params.beacon_csa.tail_len) | |
7300 | return -EINVAL; | |
7301 | ||
7302 | if (params.beacon_csa.tail[offset] != params.count) | |
7303 | return -EINVAL; | |
7304 | } | |
7305 | ||
16ef1fe2 | 7306 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
7307 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
7308 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
7309 | return -EINVAL; |
7310 | ||
9a774c78 AO |
7311 | params.n_counter_offsets_presp = len / sizeof(u16); |
7312 | if (rdev->wiphy.max_num_csa_counters && | |
7313 | (params.n_counter_offsets_beacon > | |
7314 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 | 7315 | return -EINVAL; |
9a774c78 AO |
7316 | |
7317 | params.counter_offsets_presp = | |
7318 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
7319 | ||
7320 | /* sanity checks - counters should fit and be the same */ | |
7321 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
7322 | u16 offset = params.counter_offsets_presp[i]; | |
7323 | ||
7324 | if (offset >= params.beacon_csa.probe_resp_len) | |
7325 | return -EINVAL; | |
7326 | ||
7327 | if (params.beacon_csa.probe_resp[offset] != | |
7328 | params.count) | |
7329 | return -EINVAL; | |
7330 | } | |
16ef1fe2 SW |
7331 | } |
7332 | ||
ee4bc9e7 | 7333 | skip_beacons: |
16ef1fe2 SW |
7334 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
7335 | if (err) | |
7336 | return err; | |
7337 | ||
923b352f AN |
7338 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
7339 | wdev->iftype)) | |
16ef1fe2 SW |
7340 | return -EINVAL; |
7341 | ||
2beb6dab LC |
7342 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
7343 | ¶ms.chandef, | |
7344 | wdev->iftype); | |
7345 | if (err < 0) | |
7346 | return err; | |
7347 | ||
dcc6c2f5 | 7348 | if (err > 0) |
2beb6dab | 7349 | params.radar_required = true; |
16ef1fe2 | 7350 | |
16ef1fe2 SW |
7351 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
7352 | params.block_tx = true; | |
7353 | ||
c56589ed SW |
7354 | wdev_lock(wdev); |
7355 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
7356 | wdev_unlock(wdev); | |
7357 | ||
7358 | return err; | |
16ef1fe2 SW |
7359 | } |
7360 | ||
9720bb3a JB |
7361 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
7362 | u32 seq, int flags, | |
2a519311 | 7363 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
7364 | struct wireless_dev *wdev, |
7365 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 7366 | { |
48ab905d | 7367 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 7368 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
7369 | void *hdr; |
7370 | struct nlattr *bss; | |
48ab905d JB |
7371 | |
7372 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 7373 | |
15e47304 | 7374 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
7375 | NL80211_CMD_NEW_SCAN_RESULTS); |
7376 | if (!hdr) | |
7377 | return -1; | |
7378 | ||
9720bb3a JB |
7379 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
7380 | ||
97990a06 JB |
7381 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
7382 | goto nla_put_failure; | |
7383 | if (wdev->netdev && | |
9360ffd1 DM |
7384 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
7385 | goto nla_put_failure; | |
2dad624e ND |
7386 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
7387 | NL80211_ATTR_PAD)) | |
97990a06 | 7388 | goto nla_put_failure; |
2a519311 JB |
7389 | |
7390 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
7391 | if (!bss) | |
7392 | goto nla_put_failure; | |
9360ffd1 | 7393 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 7394 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 7395 | goto nla_put_failure; |
9caf0364 JB |
7396 | |
7397 | rcu_read_lock(); | |
0e227084 JB |
7398 | /* indicate whether we have probe response data or not */ |
7399 | if (rcu_access_pointer(res->proberesp_ies) && | |
7400 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
7401 | goto fail_unlock_rcu; | |
7402 | ||
7403 | /* this pointer prefers to be pointed to probe response data | |
7404 | * but is always valid | |
7405 | */ | |
9caf0364 | 7406 | ies = rcu_dereference(res->ies); |
8cef2c9d | 7407 | if (ies) { |
2dad624e ND |
7408 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
7409 | NL80211_BSS_PAD)) | |
8cef2c9d | 7410 | goto fail_unlock_rcu; |
8cef2c9d JB |
7411 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
7412 | ies->len, ies->data)) | |
7413 | goto fail_unlock_rcu; | |
9caf0364 | 7414 | } |
0e227084 JB |
7415 | |
7416 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 7417 | ies = rcu_dereference(res->beacon_ies); |
0e227084 | 7418 | if (ies && ies->from_beacon) { |
2dad624e ND |
7419 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
7420 | NL80211_BSS_PAD)) | |
8cef2c9d JB |
7421 | goto fail_unlock_rcu; |
7422 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
7423 | ies->len, ies->data)) | |
7424 | goto fail_unlock_rcu; | |
9caf0364 JB |
7425 | } |
7426 | rcu_read_unlock(); | |
7427 | ||
9360ffd1 DM |
7428 | if (res->beacon_interval && |
7429 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
7430 | goto nla_put_failure; | |
7431 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
7432 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 7433 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
7434 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
7435 | jiffies_to_msecs(jiffies - intbss->ts))) | |
7436 | goto nla_put_failure; | |
2a519311 | 7437 | |
1d76250b AS |
7438 | if (intbss->parent_tsf && |
7439 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, | |
7440 | intbss->parent_tsf, NL80211_BSS_PAD) || | |
7441 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, | |
7442 | intbss->parent_bssid))) | |
7443 | goto nla_put_failure; | |
7444 | ||
6e19bc4b | 7445 | if (intbss->ts_boottime && |
2dad624e ND |
7446 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
7447 | intbss->ts_boottime, NL80211_BSS_PAD)) | |
6e19bc4b DS |
7448 | goto nla_put_failure; |
7449 | ||
77965c97 | 7450 | switch (rdev->wiphy.signal_type) { |
2a519311 | 7451 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
7452 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
7453 | goto nla_put_failure; | |
2a519311 JB |
7454 | break; |
7455 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
7456 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
7457 | goto nla_put_failure; | |
2a519311 JB |
7458 | break; |
7459 | default: | |
7460 | break; | |
7461 | } | |
7462 | ||
48ab905d | 7463 | switch (wdev->iftype) { |
074ac8df | 7464 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 7465 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
7466 | if (intbss == wdev->current_bss && |
7467 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
7468 | NL80211_BSS_STATUS_ASSOCIATED)) | |
7469 | goto nla_put_failure; | |
48ab905d JB |
7470 | break; |
7471 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
7472 | if (intbss == wdev->current_bss && |
7473 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
7474 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
7475 | goto nla_put_failure; | |
48ab905d JB |
7476 | break; |
7477 | default: | |
7478 | break; | |
7479 | } | |
7480 | ||
2a519311 JB |
7481 | nla_nest_end(msg, bss); |
7482 | ||
053c095a JB |
7483 | genlmsg_end(msg, hdr); |
7484 | return 0; | |
2a519311 | 7485 | |
8cef2c9d JB |
7486 | fail_unlock_rcu: |
7487 | rcu_read_unlock(); | |
2a519311 JB |
7488 | nla_put_failure: |
7489 | genlmsg_cancel(msg, hdr); | |
7490 | return -EMSGSIZE; | |
7491 | } | |
7492 | ||
97990a06 | 7493 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 7494 | { |
48ab905d | 7495 | struct cfg80211_registered_device *rdev; |
2a519311 | 7496 | struct cfg80211_internal_bss *scan; |
48ab905d | 7497 | struct wireless_dev *wdev; |
97990a06 | 7498 | int start = cb->args[2], idx = 0; |
2a519311 JB |
7499 | int err; |
7500 | ||
97990a06 | 7501 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
7502 | if (err) |
7503 | return err; | |
2a519311 | 7504 | |
48ab905d JB |
7505 | wdev_lock(wdev); |
7506 | spin_lock_bh(&rdev->bss_lock); | |
7507 | cfg80211_bss_expire(rdev); | |
7508 | ||
9720bb3a JB |
7509 | cb->seq = rdev->bss_generation; |
7510 | ||
48ab905d | 7511 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
7512 | if (++idx <= start) |
7513 | continue; | |
9720bb3a | 7514 | if (nl80211_send_bss(skb, cb, |
2a519311 | 7515 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 7516 | rdev, wdev, scan) < 0) { |
2a519311 | 7517 | idx--; |
67748893 | 7518 | break; |
2a519311 JB |
7519 | } |
7520 | } | |
7521 | ||
48ab905d JB |
7522 | spin_unlock_bh(&rdev->bss_lock); |
7523 | wdev_unlock(wdev); | |
2a519311 | 7524 | |
97990a06 JB |
7525 | cb->args[2] = idx; |
7526 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 7527 | |
67748893 | 7528 | return skb->len; |
2a519311 JB |
7529 | } |
7530 | ||
15e47304 | 7531 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
11f78ac3 JB |
7532 | int flags, struct net_device *dev, |
7533 | bool allow_radio_stats, | |
7534 | struct survey_info *survey) | |
61fa713c HS |
7535 | { |
7536 | void *hdr; | |
7537 | struct nlattr *infoattr; | |
7538 | ||
11f78ac3 JB |
7539 | /* skip radio stats if userspace didn't request them */ |
7540 | if (!survey->channel && !allow_radio_stats) | |
7541 | return 0; | |
7542 | ||
15e47304 | 7543 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
7544 | NL80211_CMD_NEW_SURVEY_RESULTS); |
7545 | if (!hdr) | |
7546 | return -ENOMEM; | |
7547 | ||
9360ffd1 DM |
7548 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
7549 | goto nla_put_failure; | |
61fa713c HS |
7550 | |
7551 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
7552 | if (!infoattr) | |
7553 | goto nla_put_failure; | |
7554 | ||
11f78ac3 JB |
7555 | if (survey->channel && |
7556 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
9360ffd1 DM |
7557 | survey->channel->center_freq)) |
7558 | goto nla_put_failure; | |
7559 | ||
7560 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
7561 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
7562 | goto nla_put_failure; | |
7563 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
7564 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
7565 | goto nla_put_failure; | |
4ed20beb | 7566 | if ((survey->filled & SURVEY_INFO_TIME) && |
2dad624e ND |
7567 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
7568 | survey->time, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7569 | goto nla_put_failure; |
4ed20beb | 7570 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
2dad624e ND |
7571 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
7572 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7573 | goto nla_put_failure; |
4ed20beb | 7574 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
2dad624e ND |
7575 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
7576 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7577 | goto nla_put_failure; |
4ed20beb | 7578 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
2dad624e ND |
7579 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
7580 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7581 | goto nla_put_failure; |
4ed20beb | 7582 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
2dad624e ND |
7583 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
7584 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7585 | goto nla_put_failure; |
052536ab | 7586 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
2dad624e ND |
7587 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
7588 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) | |
052536ab | 7589 | goto nla_put_failure; |
61fa713c HS |
7590 | |
7591 | nla_nest_end(msg, infoattr); | |
7592 | ||
053c095a JB |
7593 | genlmsg_end(msg, hdr); |
7594 | return 0; | |
61fa713c HS |
7595 | |
7596 | nla_put_failure: | |
7597 | genlmsg_cancel(msg, hdr); | |
7598 | return -EMSGSIZE; | |
7599 | } | |
7600 | ||
11f78ac3 | 7601 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
61fa713c HS |
7602 | { |
7603 | struct survey_info survey; | |
1b8ec87a | 7604 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
7605 | struct wireless_dev *wdev; |
7606 | int survey_idx = cb->args[2]; | |
61fa713c | 7607 | int res; |
11f78ac3 | 7608 | bool radio_stats; |
61fa713c | 7609 | |
1b8ec87a | 7610 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
7611 | if (res) |
7612 | return res; | |
61fa713c | 7613 | |
11f78ac3 JB |
7614 | /* prepare_wdev_dump parsed the attributes */ |
7615 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; | |
7616 | ||
97990a06 JB |
7617 | if (!wdev->netdev) { |
7618 | res = -EINVAL; | |
7619 | goto out_err; | |
7620 | } | |
7621 | ||
1b8ec87a | 7622 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
7623 | res = -EOPNOTSUPP; |
7624 | goto out_err; | |
7625 | } | |
7626 | ||
7627 | while (1) { | |
1b8ec87a | 7628 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
7629 | if (res == -ENOENT) |
7630 | break; | |
7631 | if (res) | |
7632 | goto out_err; | |
7633 | ||
11f78ac3 JB |
7634 | /* don't send disabled channels, but do send non-channel data */ |
7635 | if (survey.channel && | |
7636 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { | |
180cdc79 LR |
7637 | survey_idx++; |
7638 | continue; | |
7639 | } | |
7640 | ||
61fa713c | 7641 | if (nl80211_send_survey(skb, |
15e47304 | 7642 | NETLINK_CB(cb->skb).portid, |
61fa713c | 7643 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
11f78ac3 | 7644 | wdev->netdev, radio_stats, &survey) < 0) |
61fa713c HS |
7645 | goto out; |
7646 | survey_idx++; | |
7647 | } | |
7648 | ||
7649 | out: | |
97990a06 | 7650 | cb->args[2] = survey_idx; |
61fa713c HS |
7651 | res = skb->len; |
7652 | out_err: | |
1b8ec87a | 7653 | nl80211_finish_wdev_dump(rdev); |
61fa713c HS |
7654 | return res; |
7655 | } | |
7656 | ||
b23aa676 SO |
7657 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
7658 | { | |
7659 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
7660 | NL80211_WPA_VERSION_2)); | |
7661 | } | |
7662 | ||
636a5d36 JM |
7663 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
7664 | { | |
4c476991 JB |
7665 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7666 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7667 | struct ieee80211_channel *chan; |
e39e5b5e JM |
7668 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
7669 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 7670 | enum nl80211_auth_type auth_type; |
fffd0934 | 7671 | struct key_parse key; |
d5cdfacb | 7672 | bool local_state_change; |
636a5d36 | 7673 | |
f4a11bb0 JB |
7674 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7675 | return -EINVAL; | |
7676 | ||
7677 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7678 | return -EINVAL; | |
7679 | ||
1778092e JM |
7680 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
7681 | return -EINVAL; | |
7682 | ||
19957bb3 JB |
7683 | if (!info->attrs[NL80211_ATTR_SSID]) |
7684 | return -EINVAL; | |
7685 | ||
7686 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
7687 | return -EINVAL; | |
7688 | ||
fffd0934 JB |
7689 | err = nl80211_parse_key(info, &key); |
7690 | if (err) | |
7691 | return err; | |
7692 | ||
7693 | if (key.idx >= 0) { | |
e31b8213 JB |
7694 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
7695 | return -EINVAL; | |
fffd0934 JB |
7696 | if (!key.p.key || !key.p.key_len) |
7697 | return -EINVAL; | |
7698 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
7699 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
7700 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
7701 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
7702 | return -EINVAL; | |
b6b5555b | 7703 | if (key.idx > 3) |
fffd0934 JB |
7704 | return -EINVAL; |
7705 | } else { | |
7706 | key.p.key_len = 0; | |
7707 | key.p.key = NULL; | |
7708 | } | |
7709 | ||
afea0b7a JB |
7710 | if (key.idx >= 0) { |
7711 | int i; | |
7712 | bool ok = false; | |
7a087e74 | 7713 | |
afea0b7a JB |
7714 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
7715 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
7716 | ok = true; | |
7717 | break; | |
7718 | } | |
7719 | } | |
4c476991 JB |
7720 | if (!ok) |
7721 | return -EINVAL; | |
afea0b7a JB |
7722 | } |
7723 | ||
4c476991 JB |
7724 | if (!rdev->ops->auth) |
7725 | return -EOPNOTSUPP; | |
636a5d36 | 7726 | |
074ac8df | 7727 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7728 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7729 | return -EOPNOTSUPP; | |
eec60b03 | 7730 | |
19957bb3 | 7731 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
7732 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
7733 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7734 | if (!chan) | |
4c476991 | 7735 | return -EINVAL; |
636a5d36 | 7736 | |
19957bb3 JB |
7737 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7738 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
7739 | |
7740 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7741 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7742 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7743 | } |
7744 | ||
19957bb3 | 7745 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 7746 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 7747 | return -EINVAL; |
636a5d36 | 7748 | |
e39e5b5e JM |
7749 | if (auth_type == NL80211_AUTHTYPE_SAE && |
7750 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
7751 | return -EINVAL; | |
7752 | ||
7753 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
7754 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
7755 | return -EINVAL; | |
7756 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
7757 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
7758 | /* need to include at least Auth Transaction and Status Code */ | |
7759 | if (sae_data_len < 4) | |
7760 | return -EINVAL; | |
7761 | } | |
7762 | ||
d5cdfacb JM |
7763 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7764 | ||
95de817b JB |
7765 | /* |
7766 | * Since we no longer track auth state, ignore | |
7767 | * requests to only change local state. | |
7768 | */ | |
7769 | if (local_state_change) | |
7770 | return 0; | |
7771 | ||
91bf9b26 JB |
7772 | wdev_lock(dev->ieee80211_ptr); |
7773 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
7774 | ssid, ssid_len, ie, ie_len, | |
7775 | key.p.key, key.p.key_len, key.idx, | |
7776 | sae_data, sae_data_len); | |
7777 | wdev_unlock(dev->ieee80211_ptr); | |
7778 | return err; | |
636a5d36 JM |
7779 | } |
7780 | ||
c0692b8f JB |
7781 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
7782 | struct genl_info *info, | |
3dc27d25 JB |
7783 | struct cfg80211_crypto_settings *settings, |
7784 | int cipher_limit) | |
b23aa676 | 7785 | { |
c0b2bbd8 JB |
7786 | memset(settings, 0, sizeof(*settings)); |
7787 | ||
b23aa676 SO |
7788 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
7789 | ||
c0692b8f JB |
7790 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
7791 | u16 proto; | |
7a087e74 | 7792 | |
c0692b8f JB |
7793 | proto = nla_get_u16( |
7794 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
7795 | settings->control_port_ethertype = cpu_to_be16(proto); | |
7796 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
7797 | proto != ETH_P_PAE) | |
7798 | return -EINVAL; | |
7799 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
7800 | settings->control_port_no_encrypt = true; | |
7801 | } else | |
7802 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
7803 | ||
b23aa676 SO |
7804 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
7805 | void *data; | |
7806 | int len, i; | |
7807 | ||
7808 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
7809 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
7810 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
7811 | ||
7812 | if (len % sizeof(u32)) | |
7813 | return -EINVAL; | |
7814 | ||
3dc27d25 | 7815 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
7816 | return -EINVAL; |
7817 | ||
7818 | memcpy(settings->ciphers_pairwise, data, len); | |
7819 | ||
7820 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
7821 | if (!cfg80211_supported_cipher_suite( |
7822 | &rdev->wiphy, | |
b23aa676 SO |
7823 | settings->ciphers_pairwise[i])) |
7824 | return -EINVAL; | |
7825 | } | |
7826 | ||
7827 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
7828 | settings->cipher_group = | |
7829 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
7830 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
7831 | settings->cipher_group)) | |
b23aa676 SO |
7832 | return -EINVAL; |
7833 | } | |
7834 | ||
7835 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
7836 | settings->wpa_versions = | |
7837 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
7838 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
7839 | return -EINVAL; | |
7840 | } | |
7841 | ||
7842 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
7843 | void *data; | |
6d30240e | 7844 | int len; |
b23aa676 SO |
7845 | |
7846 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
7847 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
7848 | settings->n_akm_suites = len / sizeof(u32); | |
7849 | ||
7850 | if (len % sizeof(u32)) | |
7851 | return -EINVAL; | |
7852 | ||
1b9ca027 JM |
7853 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
7854 | return -EINVAL; | |
7855 | ||
b23aa676 | 7856 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
7857 | } |
7858 | ||
7859 | return 0; | |
7860 | } | |
7861 | ||
636a5d36 JM |
7862 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
7863 | { | |
4c476991 JB |
7864 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7865 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 7866 | struct ieee80211_channel *chan; |
f62fab73 JB |
7867 | struct cfg80211_assoc_request req = {}; |
7868 | const u8 *bssid, *ssid; | |
7869 | int err, ssid_len = 0; | |
636a5d36 | 7870 | |
f4a11bb0 JB |
7871 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7872 | return -EINVAL; | |
7873 | ||
7874 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
7875 | !info->attrs[NL80211_ATTR_SSID] || |
7876 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
7877 | return -EINVAL; |
7878 | ||
4c476991 JB |
7879 | if (!rdev->ops->assoc) |
7880 | return -EOPNOTSUPP; | |
636a5d36 | 7881 | |
074ac8df | 7882 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7883 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7884 | return -EOPNOTSUPP; | |
eec60b03 | 7885 | |
19957bb3 | 7886 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7887 | |
664834de JM |
7888 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
7889 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7890 | if (!chan) | |
4c476991 | 7891 | return -EINVAL; |
636a5d36 | 7892 | |
19957bb3 JB |
7893 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7894 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
7895 | |
7896 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
7897 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7898 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7899 | } |
7900 | ||
dc6382ce | 7901 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 7902 | enum nl80211_mfp mfp = |
dc6382ce | 7903 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 7904 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 7905 | req.use_mfp = true; |
4c476991 JB |
7906 | else if (mfp != NL80211_MFP_NO) |
7907 | return -EINVAL; | |
dc6382ce JM |
7908 | } |
7909 | ||
3e5d7649 | 7910 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 7911 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 7912 | |
7e7c8926 | 7913 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 7914 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
7915 | |
7916 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
7917 | memcpy(&req.ht_capa_mask, |
7918 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7919 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
7920 | |
7921 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 7922 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 7923 | return -EINVAL; |
f62fab73 JB |
7924 | memcpy(&req.ht_capa, |
7925 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7926 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
7927 | } |
7928 | ||
ee2aca34 | 7929 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 7930 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
7931 | |
7932 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
7933 | memcpy(&req.vht_capa_mask, |
7934 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7935 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
7936 | |
7937 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 7938 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 7939 | return -EINVAL; |
f62fab73 JB |
7940 | memcpy(&req.vht_capa, |
7941 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7942 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
7943 | } |
7944 | ||
bab5ab7d | 7945 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
0c9ca11b BL |
7946 | if (!((rdev->wiphy.features & |
7947 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && | |
7948 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && | |
7949 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
7950 | NL80211_EXT_FEATURE_RRM)) | |
bab5ab7d AK |
7951 | return -EINVAL; |
7952 | req.flags |= ASSOC_REQ_USE_RRM; | |
7953 | } | |
7954 | ||
f62fab73 | 7955 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
7956 | if (!err) { |
7957 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
7958 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
7959 | ssid, ssid_len, &req); | |
91bf9b26 JB |
7960 | wdev_unlock(dev->ieee80211_ptr); |
7961 | } | |
636a5d36 | 7962 | |
636a5d36 JM |
7963 | return err; |
7964 | } | |
7965 | ||
7966 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
7967 | { | |
4c476991 JB |
7968 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7969 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7970 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7971 | int ie_len = 0, err; |
19957bb3 | 7972 | u16 reason_code; |
d5cdfacb | 7973 | bool local_state_change; |
636a5d36 | 7974 | |
f4a11bb0 JB |
7975 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7976 | return -EINVAL; | |
7977 | ||
7978 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7979 | return -EINVAL; | |
7980 | ||
7981 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7982 | return -EINVAL; | |
7983 | ||
4c476991 JB |
7984 | if (!rdev->ops->deauth) |
7985 | return -EOPNOTSUPP; | |
636a5d36 | 7986 | |
074ac8df | 7987 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7988 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7989 | return -EOPNOTSUPP; | |
eec60b03 | 7990 | |
19957bb3 | 7991 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7992 | |
19957bb3 JB |
7993 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7994 | if (reason_code == 0) { | |
f4a11bb0 | 7995 | /* Reason Code 0 is reserved */ |
4c476991 | 7996 | return -EINVAL; |
255e737e | 7997 | } |
636a5d36 JM |
7998 | |
7999 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
8000 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
8001 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
8002 | } |
8003 | ||
d5cdfacb JM |
8004 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
8005 | ||
91bf9b26 JB |
8006 | wdev_lock(dev->ieee80211_ptr); |
8007 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
8008 | local_state_change); | |
8009 | wdev_unlock(dev->ieee80211_ptr); | |
8010 | return err; | |
636a5d36 JM |
8011 | } |
8012 | ||
8013 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
8014 | { | |
4c476991 JB |
8015 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8016 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 8017 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 8018 | int ie_len = 0, err; |
19957bb3 | 8019 | u16 reason_code; |
d5cdfacb | 8020 | bool local_state_change; |
636a5d36 | 8021 | |
f4a11bb0 JB |
8022 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
8023 | return -EINVAL; | |
8024 | ||
8025 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8026 | return -EINVAL; | |
8027 | ||
8028 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
8029 | return -EINVAL; | |
8030 | ||
4c476991 JB |
8031 | if (!rdev->ops->disassoc) |
8032 | return -EOPNOTSUPP; | |
636a5d36 | 8033 | |
074ac8df | 8034 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8035 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8036 | return -EOPNOTSUPP; | |
eec60b03 | 8037 | |
19957bb3 | 8038 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 8039 | |
19957bb3 JB |
8040 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
8041 | if (reason_code == 0) { | |
f4a11bb0 | 8042 | /* Reason Code 0 is reserved */ |
4c476991 | 8043 | return -EINVAL; |
255e737e | 8044 | } |
636a5d36 JM |
8045 | |
8046 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
8047 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
8048 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
8049 | } |
8050 | ||
d5cdfacb JM |
8051 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
8052 | ||
91bf9b26 JB |
8053 | wdev_lock(dev->ieee80211_ptr); |
8054 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
8055 | local_state_change); | |
8056 | wdev_unlock(dev->ieee80211_ptr); | |
8057 | return err; | |
636a5d36 JM |
8058 | } |
8059 | ||
dd5b4cc7 FF |
8060 | static bool |
8061 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
57fbcce3 | 8062 | int mcast_rate[NUM_NL80211_BANDS], |
dd5b4cc7 FF |
8063 | int rateval) |
8064 | { | |
8065 | struct wiphy *wiphy = &rdev->wiphy; | |
8066 | bool found = false; | |
8067 | int band, i; | |
8068 | ||
57fbcce3 | 8069 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
dd5b4cc7 FF |
8070 | struct ieee80211_supported_band *sband; |
8071 | ||
8072 | sband = wiphy->bands[band]; | |
8073 | if (!sband) | |
8074 | continue; | |
8075 | ||
8076 | for (i = 0; i < sband->n_bitrates; i++) { | |
8077 | if (sband->bitrates[i].bitrate == rateval) { | |
8078 | mcast_rate[band] = i + 1; | |
8079 | found = true; | |
8080 | break; | |
8081 | } | |
8082 | } | |
8083 | } | |
8084 | ||
8085 | return found; | |
8086 | } | |
8087 | ||
04a773ad JB |
8088 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
8089 | { | |
4c476991 JB |
8090 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8091 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
8092 | struct cfg80211_ibss_params ibss; |
8093 | struct wiphy *wiphy; | |
fffd0934 | 8094 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
8095 | int err; |
8096 | ||
8e30bc55 JB |
8097 | memset(&ibss, 0, sizeof(ibss)); |
8098 | ||
04a773ad JB |
8099 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
8100 | return -EINVAL; | |
8101 | ||
683b6d3b | 8102 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
8103 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
8104 | return -EINVAL; | |
8105 | ||
8e30bc55 JB |
8106 | ibss.beacon_interval = 100; |
8107 | ||
12d20fc9 | 8108 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
8e30bc55 JB |
8109 | ibss.beacon_interval = |
8110 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
12d20fc9 PK |
8111 | |
8112 | err = cfg80211_validate_beacon_int(rdev, ibss.beacon_interval); | |
8113 | if (err) | |
8114 | return err; | |
8e30bc55 | 8115 | |
4c476991 JB |
8116 | if (!rdev->ops->join_ibss) |
8117 | return -EOPNOTSUPP; | |
04a773ad | 8118 | |
4c476991 JB |
8119 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
8120 | return -EOPNOTSUPP; | |
04a773ad | 8121 | |
79c97e97 | 8122 | wiphy = &rdev->wiphy; |
04a773ad | 8123 | |
39193498 | 8124 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 8125 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
8126 | |
8127 | if (!is_valid_ether_addr(ibss.bssid)) | |
8128 | return -EINVAL; | |
8129 | } | |
04a773ad JB |
8130 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
8131 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
8132 | ||
8133 | if (info->attrs[NL80211_ATTR_IE]) { | |
8134 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8135 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8136 | } | |
8137 | ||
683b6d3b JB |
8138 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
8139 | if (err) | |
8140 | return err; | |
04a773ad | 8141 | |
174e0cd2 IP |
8142 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
8143 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
8144 | return -EINVAL; |
8145 | ||
2f301ab2 | 8146 | switch (ibss.chandef.width) { |
bf372645 SW |
8147 | case NL80211_CHAN_WIDTH_5: |
8148 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
8149 | case NL80211_CHAN_WIDTH_20_NOHT: |
8150 | break; | |
8151 | case NL80211_CHAN_WIDTH_20: | |
8152 | case NL80211_CHAN_WIDTH_40: | |
ffc11991 JD |
8153 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
8154 | return -EINVAL; | |
8155 | break; | |
8156 | case NL80211_CHAN_WIDTH_80: | |
8157 | case NL80211_CHAN_WIDTH_80P80: | |
8158 | case NL80211_CHAN_WIDTH_160: | |
8159 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | |
8160 | return -EINVAL; | |
8161 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
8162 | NL80211_EXT_FEATURE_VHT_IBSS)) | |
8163 | return -EINVAL; | |
8164 | break; | |
2f301ab2 | 8165 | default: |
c04d6150 | 8166 | return -EINVAL; |
2f301ab2 | 8167 | } |
db9c64cf | 8168 | |
04a773ad | 8169 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
8170 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
8171 | ||
fbd2c8dc TP |
8172 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8173 | u8 *rates = | |
8174 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8175 | int n_rates = | |
8176 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8177 | struct ieee80211_supported_band *sband = | |
683b6d3b | 8178 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 8179 | |
34850ab2 JB |
8180 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
8181 | &ibss.basic_rates); | |
8182 | if (err) | |
8183 | return err; | |
fbd2c8dc | 8184 | } |
dd5b4cc7 | 8185 | |
803768f5 SW |
8186 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
8187 | memcpy(&ibss.ht_capa_mask, | |
8188 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
8189 | sizeof(ibss.ht_capa_mask)); | |
8190 | ||
8191 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
8192 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
8193 | return -EINVAL; | |
8194 | memcpy(&ibss.ht_capa, | |
8195 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
8196 | sizeof(ibss.ht_capa)); | |
8197 | } | |
8198 | ||
dd5b4cc7 FF |
8199 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8200 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
8201 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8202 | return -EINVAL; | |
fbd2c8dc | 8203 | |
4c476991 | 8204 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
8205 | bool no_ht = false; |
8206 | ||
4c476991 | 8207 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
8208 | info->attrs[NL80211_ATTR_KEYS], |
8209 | &no_ht); | |
4c476991 JB |
8210 | if (IS_ERR(connkeys)) |
8211 | return PTR_ERR(connkeys); | |
de7044ee | 8212 | |
3d9d1d66 JB |
8213 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
8214 | no_ht) { | |
5e950a78 | 8215 | kzfree(connkeys); |
de7044ee SM |
8216 | return -EINVAL; |
8217 | } | |
4c476991 | 8218 | } |
04a773ad | 8219 | |
267335d6 AQ |
8220 | ibss.control_port = |
8221 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
8222 | ||
5336fa88 SW |
8223 | ibss.userspace_handles_dfs = |
8224 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
8225 | ||
4c476991 | 8226 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 | 8227 | if (err) |
b47f610b | 8228 | kzfree(connkeys); |
04a773ad JB |
8229 | return err; |
8230 | } | |
8231 | ||
8232 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
8233 | { | |
4c476991 JB |
8234 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8235 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 8236 | |
4c476991 JB |
8237 | if (!rdev->ops->leave_ibss) |
8238 | return -EOPNOTSUPP; | |
04a773ad | 8239 | |
4c476991 JB |
8240 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
8241 | return -EOPNOTSUPP; | |
04a773ad | 8242 | |
4c476991 | 8243 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
8244 | } |
8245 | ||
f4e583c8 AQ |
8246 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
8247 | { | |
8248 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8249 | struct net_device *dev = info->user_ptr[1]; | |
57fbcce3 | 8250 | int mcast_rate[NUM_NL80211_BANDS]; |
f4e583c8 AQ |
8251 | u32 nla_rate; |
8252 | int err; | |
8253 | ||
8254 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
876dc930 BVB |
8255 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
8256 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) | |
f4e583c8 AQ |
8257 | return -EOPNOTSUPP; |
8258 | ||
8259 | if (!rdev->ops->set_mcast_rate) | |
8260 | return -EOPNOTSUPP; | |
8261 | ||
8262 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
8263 | ||
8264 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
8265 | return -EINVAL; | |
8266 | ||
8267 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
8268 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
8269 | return -EINVAL; | |
8270 | ||
a1056b1b | 8271 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
f4e583c8 AQ |
8272 | |
8273 | return err; | |
8274 | } | |
8275 | ||
ad7e718c JB |
8276 | static struct sk_buff * |
8277 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
6c09e791 AK |
8278 | struct wireless_dev *wdev, int approxlen, |
8279 | u32 portid, u32 seq, enum nl80211_commands cmd, | |
567ffc35 JB |
8280 | enum nl80211_attrs attr, |
8281 | const struct nl80211_vendor_cmd_info *info, | |
8282 | gfp_t gfp) | |
ad7e718c JB |
8283 | { |
8284 | struct sk_buff *skb; | |
8285 | void *hdr; | |
8286 | struct nlattr *data; | |
8287 | ||
8288 | skb = nlmsg_new(approxlen + 100, gfp); | |
8289 | if (!skb) | |
8290 | return NULL; | |
8291 | ||
8292 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
8293 | if (!hdr) { | |
8294 | kfree_skb(skb); | |
8295 | return NULL; | |
8296 | } | |
8297 | ||
8298 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
8299 | goto nla_put_failure; | |
567ffc35 JB |
8300 | |
8301 | if (info) { | |
8302 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
8303 | info->vendor_id)) | |
8304 | goto nla_put_failure; | |
8305 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
8306 | info->subcmd)) | |
8307 | goto nla_put_failure; | |
8308 | } | |
8309 | ||
6c09e791 | 8310 | if (wdev) { |
2dad624e ND |
8311 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
8312 | wdev_id(wdev), NL80211_ATTR_PAD)) | |
6c09e791 AK |
8313 | goto nla_put_failure; |
8314 | if (wdev->netdev && | |
8315 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, | |
8316 | wdev->netdev->ifindex)) | |
8317 | goto nla_put_failure; | |
8318 | } | |
8319 | ||
ad7e718c | 8320 | data = nla_nest_start(skb, attr); |
76e1fb4b JB |
8321 | if (!data) |
8322 | goto nla_put_failure; | |
ad7e718c JB |
8323 | |
8324 | ((void **)skb->cb)[0] = rdev; | |
8325 | ((void **)skb->cb)[1] = hdr; | |
8326 | ((void **)skb->cb)[2] = data; | |
8327 | ||
8328 | return skb; | |
8329 | ||
8330 | nla_put_failure: | |
8331 | kfree_skb(skb); | |
8332 | return NULL; | |
8333 | } | |
f4e583c8 | 8334 | |
e03ad6ea | 8335 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
6c09e791 | 8336 | struct wireless_dev *wdev, |
e03ad6ea JB |
8337 | enum nl80211_commands cmd, |
8338 | enum nl80211_attrs attr, | |
8339 | int vendor_event_idx, | |
8340 | int approxlen, gfp_t gfp) | |
8341 | { | |
f26cbf40 | 8342 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
8343 | const struct nl80211_vendor_cmd_info *info; |
8344 | ||
8345 | switch (cmd) { | |
8346 | case NL80211_CMD_TESTMODE: | |
8347 | if (WARN_ON(vendor_event_idx != -1)) | |
8348 | return NULL; | |
8349 | info = NULL; | |
8350 | break; | |
8351 | case NL80211_CMD_VENDOR: | |
8352 | if (WARN_ON(vendor_event_idx < 0 || | |
8353 | vendor_event_idx >= wiphy->n_vendor_events)) | |
8354 | return NULL; | |
8355 | info = &wiphy->vendor_events[vendor_event_idx]; | |
8356 | break; | |
8357 | default: | |
8358 | WARN_ON(1); | |
8359 | return NULL; | |
8360 | } | |
8361 | ||
6c09e791 | 8362 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
e03ad6ea JB |
8363 | cmd, attr, info, gfp); |
8364 | } | |
8365 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
8366 | ||
8367 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
8368 | { | |
8369 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
8370 | void *hdr = ((void **)skb->cb)[1]; | |
8371 | struct nlattr *data = ((void **)skb->cb)[2]; | |
8372 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
8373 | ||
bd8c78e7 JB |
8374 | /* clear CB data for netlink core to own from now on */ |
8375 | memset(skb->cb, 0, sizeof(skb->cb)); | |
8376 | ||
e03ad6ea JB |
8377 | nla_nest_end(skb, data); |
8378 | genlmsg_end(skb, hdr); | |
8379 | ||
8380 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
8381 | mcgrp = NL80211_MCGRP_VENDOR; | |
8382 | ||
8383 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
8384 | mcgrp, gfp); | |
8385 | } | |
8386 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
8387 | ||
aff89a9b | 8388 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
8389 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
8390 | { | |
4c476991 | 8391 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
8392 | struct wireless_dev *wdev = |
8393 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
8394 | int err; |
8395 | ||
fc73f11f DS |
8396 | if (!rdev->ops->testmode_cmd) |
8397 | return -EOPNOTSUPP; | |
8398 | ||
8399 | if (IS_ERR(wdev)) { | |
8400 | err = PTR_ERR(wdev); | |
8401 | if (err != -EINVAL) | |
8402 | return err; | |
8403 | wdev = NULL; | |
8404 | } else if (wdev->wiphy != &rdev->wiphy) { | |
8405 | return -EINVAL; | |
8406 | } | |
8407 | ||
aff89a9b JB |
8408 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
8409 | return -EINVAL; | |
8410 | ||
ad7e718c | 8411 | rdev->cur_cmd_info = info; |
fc73f11f | 8412 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
8413 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
8414 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 8415 | rdev->cur_cmd_info = NULL; |
aff89a9b | 8416 | |
aff89a9b JB |
8417 | return err; |
8418 | } | |
8419 | ||
71063f0e WYG |
8420 | static int nl80211_testmode_dump(struct sk_buff *skb, |
8421 | struct netlink_callback *cb) | |
8422 | { | |
00918d33 | 8423 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
8424 | int err; |
8425 | long phy_idx; | |
8426 | void *data = NULL; | |
8427 | int data_len = 0; | |
8428 | ||
5fe231e8 JB |
8429 | rtnl_lock(); |
8430 | ||
71063f0e WYG |
8431 | if (cb->args[0]) { |
8432 | /* | |
8433 | * 0 is a valid index, but not valid for args[0], | |
8434 | * so we need to offset by 1. | |
8435 | */ | |
8436 | phy_idx = cb->args[0] - 1; | |
8437 | } else { | |
8438 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
8439 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
8440 | nl80211_policy); | |
8441 | if (err) | |
5fe231e8 | 8442 | goto out_err; |
00918d33 | 8443 | |
2bd7e35d JB |
8444 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
8445 | nl80211_fam.attrbuf); | |
8446 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
8447 | err = PTR_ERR(rdev); |
8448 | goto out_err; | |
00918d33 | 8449 | } |
2bd7e35d JB |
8450 | phy_idx = rdev->wiphy_idx; |
8451 | rdev = NULL; | |
2bd7e35d | 8452 | |
71063f0e WYG |
8453 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
8454 | cb->args[1] = | |
8455 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
8456 | } | |
8457 | ||
8458 | if (cb->args[1]) { | |
8459 | data = nla_data((void *)cb->args[1]); | |
8460 | data_len = nla_len((void *)cb->args[1]); | |
8461 | } | |
8462 | ||
00918d33 JB |
8463 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
8464 | if (!rdev) { | |
5fe231e8 JB |
8465 | err = -ENOENT; |
8466 | goto out_err; | |
71063f0e | 8467 | } |
71063f0e | 8468 | |
00918d33 | 8469 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
8470 | err = -EOPNOTSUPP; |
8471 | goto out_err; | |
8472 | } | |
8473 | ||
8474 | while (1) { | |
15e47304 | 8475 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
8476 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
8477 | NL80211_CMD_TESTMODE); | |
8478 | struct nlattr *tmdata; | |
8479 | ||
cb35fba3 DC |
8480 | if (!hdr) |
8481 | break; | |
8482 | ||
9360ffd1 | 8483 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
8484 | genlmsg_cancel(skb, hdr); |
8485 | break; | |
8486 | } | |
8487 | ||
8488 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
8489 | if (!tmdata) { | |
8490 | genlmsg_cancel(skb, hdr); | |
8491 | break; | |
8492 | } | |
e35e4d28 | 8493 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
8494 | nla_nest_end(skb, tmdata); |
8495 | ||
8496 | if (err == -ENOBUFS || err == -ENOENT) { | |
8497 | genlmsg_cancel(skb, hdr); | |
8498 | break; | |
8499 | } else if (err) { | |
8500 | genlmsg_cancel(skb, hdr); | |
8501 | goto out_err; | |
8502 | } | |
8503 | ||
8504 | genlmsg_end(skb, hdr); | |
8505 | } | |
8506 | ||
8507 | err = skb->len; | |
8508 | /* see above */ | |
8509 | cb->args[0] = phy_idx + 1; | |
8510 | out_err: | |
5fe231e8 | 8511 | rtnl_unlock(); |
71063f0e WYG |
8512 | return err; |
8513 | } | |
aff89a9b JB |
8514 | #endif |
8515 | ||
b23aa676 SO |
8516 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
8517 | { | |
4c476991 JB |
8518 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8519 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
8520 | struct cfg80211_connect_params connect; |
8521 | struct wiphy *wiphy; | |
fffd0934 | 8522 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
8523 | int err; |
8524 | ||
8525 | memset(&connect, 0, sizeof(connect)); | |
8526 | ||
8527 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
8528 | return -EINVAL; | |
8529 | ||
8530 | if (!info->attrs[NL80211_ATTR_SSID] || | |
8531 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
8532 | return -EINVAL; | |
8533 | ||
8534 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
8535 | connect.auth_type = | |
8536 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
8537 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
8538 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
8539 | return -EINVAL; |
8540 | } else | |
8541 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
8542 | ||
8543 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
8544 | ||
c0692b8f | 8545 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 8546 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
8547 | if (err) |
8548 | return err; | |
b23aa676 | 8549 | |
074ac8df | 8550 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8551 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8552 | return -EOPNOTSUPP; | |
b23aa676 | 8553 | |
79c97e97 | 8554 | wiphy = &rdev->wiphy; |
b23aa676 | 8555 | |
4486ea98 BS |
8556 | connect.bg_scan_period = -1; |
8557 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
8558 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
8559 | connect.bg_scan_period = | |
8560 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
8561 | } | |
8562 | ||
b23aa676 SO |
8563 | if (info->attrs[NL80211_ATTR_MAC]) |
8564 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
8565 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
8566 | connect.bssid_hint = | |
8567 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
8568 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
8569 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
8570 | ||
8571 | if (info->attrs[NL80211_ATTR_IE]) { | |
8572 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8573 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8574 | } | |
8575 | ||
cee00a95 JM |
8576 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
8577 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
8578 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
8579 | connect.mfp != NL80211_MFP_NO) | |
8580 | return -EINVAL; | |
8581 | } else { | |
8582 | connect.mfp = NL80211_MFP_NO; | |
8583 | } | |
8584 | ||
ba6fbacf JM |
8585 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
8586 | connect.prev_bssid = | |
8587 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | |
8588 | ||
b23aa676 | 8589 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
8590 | connect.channel = nl80211_get_valid_chan( |
8591 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
8592 | if (!connect.channel) | |
1df4a510 JM |
8593 | return -EINVAL; |
8594 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
8595 | connect.channel_hint = nl80211_get_valid_chan( |
8596 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
8597 | if (!connect.channel_hint) | |
4c476991 | 8598 | return -EINVAL; |
b23aa676 SO |
8599 | } |
8600 | ||
fffd0934 JB |
8601 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
8602 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 8603 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
8604 | if (IS_ERR(connkeys)) |
8605 | return PTR_ERR(connkeys); | |
fffd0934 JB |
8606 | } |
8607 | ||
7e7c8926 BG |
8608 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
8609 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
8610 | ||
8611 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
8612 | memcpy(&connect.ht_capa_mask, | |
8613 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
8614 | sizeof(connect.ht_capa_mask)); | |
8615 | ||
8616 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e | 8617 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
b47f610b | 8618 | kzfree(connkeys); |
7e7c8926 | 8619 | return -EINVAL; |
b4e4f47e | 8620 | } |
7e7c8926 BG |
8621 | memcpy(&connect.ht_capa, |
8622 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
8623 | sizeof(connect.ht_capa)); | |
8624 | } | |
8625 | ||
ee2aca34 JB |
8626 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
8627 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
8628 | ||
8629 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
8630 | memcpy(&connect.vht_capa_mask, | |
8631 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
8632 | sizeof(connect.vht_capa_mask)); | |
8633 | ||
8634 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
8635 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
b47f610b | 8636 | kzfree(connkeys); |
ee2aca34 JB |
8637 | return -EINVAL; |
8638 | } | |
8639 | memcpy(&connect.vht_capa, | |
8640 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
8641 | sizeof(connect.vht_capa)); | |
8642 | } | |
8643 | ||
bab5ab7d | 8644 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
0c9ca11b BL |
8645 | if (!((rdev->wiphy.features & |
8646 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && | |
8647 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && | |
8648 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
8649 | NL80211_EXT_FEATURE_RRM)) { | |
707554b4 | 8650 | kzfree(connkeys); |
bab5ab7d | 8651 | return -EINVAL; |
707554b4 | 8652 | } |
bab5ab7d AK |
8653 | connect.flags |= ASSOC_REQ_USE_RRM; |
8654 | } | |
8655 | ||
34d50519 | 8656 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
57fbcce3 | 8657 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
34d50519 LD |
8658 | kzfree(connkeys); |
8659 | return -EOPNOTSUPP; | |
8660 | } | |
8661 | ||
38de03d2 AS |
8662 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
8663 | /* bss selection makes no sense if bssid is set */ | |
8664 | if (connect.bssid) { | |
8665 | kzfree(connkeys); | |
8666 | return -EINVAL; | |
8667 | } | |
8668 | ||
8669 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], | |
8670 | wiphy, &connect.bss_select); | |
8671 | if (err) { | |
8672 | kzfree(connkeys); | |
8673 | return err; | |
8674 | } | |
8675 | } | |
8676 | ||
83739b03 | 8677 | wdev_lock(dev->ieee80211_ptr); |
4ce2bd9c JM |
8678 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
8679 | connect.prev_bssid); | |
83739b03 | 8680 | wdev_unlock(dev->ieee80211_ptr); |
fffd0934 | 8681 | if (err) |
b47f610b | 8682 | kzfree(connkeys); |
b23aa676 SO |
8683 | return err; |
8684 | } | |
8685 | ||
8686 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
8687 | { | |
4c476991 JB |
8688 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8689 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 8690 | u16 reason; |
83739b03 | 8691 | int ret; |
b23aa676 SO |
8692 | |
8693 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
8694 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
8695 | else | |
8696 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
8697 | ||
8698 | if (reason == 0) | |
8699 | return -EINVAL; | |
8700 | ||
074ac8df | 8701 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8702 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8703 | return -EOPNOTSUPP; | |
b23aa676 | 8704 | |
83739b03 JB |
8705 | wdev_lock(dev->ieee80211_ptr); |
8706 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
8707 | wdev_unlock(dev->ieee80211_ptr); | |
8708 | return ret; | |
b23aa676 SO |
8709 | } |
8710 | ||
463d0183 JB |
8711 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
8712 | { | |
4c476991 | 8713 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
8714 | struct net *net; |
8715 | int err; | |
463d0183 | 8716 | |
4b681c82 VK |
8717 | if (info->attrs[NL80211_ATTR_PID]) { |
8718 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
8719 | ||
8720 | net = get_net_ns_by_pid(pid); | |
8721 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { | |
8722 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); | |
463d0183 | 8723 | |
4b681c82 VK |
8724 | net = get_net_ns_by_fd(fd); |
8725 | } else { | |
8726 | return -EINVAL; | |
8727 | } | |
463d0183 | 8728 | |
4c476991 JB |
8729 | if (IS_ERR(net)) |
8730 | return PTR_ERR(net); | |
463d0183 JB |
8731 | |
8732 | err = 0; | |
8733 | ||
8734 | /* check if anything to do */ | |
4c476991 JB |
8735 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
8736 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 8737 | |
463d0183 | 8738 | put_net(net); |
463d0183 JB |
8739 | return err; |
8740 | } | |
8741 | ||
67fbb16b SO |
8742 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
8743 | { | |
4c476991 | 8744 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
8745 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
8746 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 8747 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
8748 | struct cfg80211_pmksa pmksa; |
8749 | ||
8750 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
8751 | ||
8752 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8753 | return -EINVAL; | |
8754 | ||
8755 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
8756 | return -EINVAL; | |
8757 | ||
67fbb16b SO |
8758 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
8759 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8760 | ||
074ac8df | 8761 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8762 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8763 | return -EOPNOTSUPP; | |
67fbb16b SO |
8764 | |
8765 | switch (info->genlhdr->cmd) { | |
8766 | case NL80211_CMD_SET_PMKSA: | |
8767 | rdev_ops = rdev->ops->set_pmksa; | |
8768 | break; | |
8769 | case NL80211_CMD_DEL_PMKSA: | |
8770 | rdev_ops = rdev->ops->del_pmksa; | |
8771 | break; | |
8772 | default: | |
8773 | WARN_ON(1); | |
8774 | break; | |
8775 | } | |
8776 | ||
4c476991 JB |
8777 | if (!rdev_ops) |
8778 | return -EOPNOTSUPP; | |
67fbb16b | 8779 | |
4c476991 | 8780 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
8781 | } |
8782 | ||
8783 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
8784 | { | |
4c476991 JB |
8785 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8786 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 8787 | |
074ac8df | 8788 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8789 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8790 | return -EOPNOTSUPP; | |
67fbb16b | 8791 | |
4c476991 JB |
8792 | if (!rdev->ops->flush_pmksa) |
8793 | return -EOPNOTSUPP; | |
67fbb16b | 8794 | |
e35e4d28 | 8795 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
8796 | } |
8797 | ||
109086ce AN |
8798 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
8799 | { | |
8800 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8801 | struct net_device *dev = info->user_ptr[1]; | |
8802 | u8 action_code, dialog_token; | |
df942e7b | 8803 | u32 peer_capability = 0; |
109086ce AN |
8804 | u16 status_code; |
8805 | u8 *peer; | |
31fa97c5 | 8806 | bool initiator; |
109086ce AN |
8807 | |
8808 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
8809 | !rdev->ops->tdls_mgmt) | |
8810 | return -EOPNOTSUPP; | |
8811 | ||
8812 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
8813 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
8814 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
8815 | !info->attrs[NL80211_ATTR_IE] || | |
8816 | !info->attrs[NL80211_ATTR_MAC]) | |
8817 | return -EINVAL; | |
8818 | ||
8819 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8820 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
8821 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
8822 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 8823 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
8824 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
8825 | peer_capability = | |
8826 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 8827 | |
e35e4d28 | 8828 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 8829 | dialog_token, status_code, peer_capability, |
31fa97c5 | 8830 | initiator, |
e35e4d28 HG |
8831 | nla_data(info->attrs[NL80211_ATTR_IE]), |
8832 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
8833 | } |
8834 | ||
8835 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
8836 | { | |
8837 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8838 | struct net_device *dev = info->user_ptr[1]; | |
8839 | enum nl80211_tdls_operation operation; | |
8840 | u8 *peer; | |
8841 | ||
8842 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
8843 | !rdev->ops->tdls_oper) | |
8844 | return -EOPNOTSUPP; | |
8845 | ||
8846 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
8847 | !info->attrs[NL80211_ATTR_MAC]) | |
8848 | return -EINVAL; | |
8849 | ||
8850 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
8851 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8852 | ||
e35e4d28 | 8853 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
8854 | } |
8855 | ||
9588bbd5 JM |
8856 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
8857 | struct genl_info *info) | |
8858 | { | |
4c476991 | 8859 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8860 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 8861 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
8862 | struct sk_buff *msg; |
8863 | void *hdr; | |
8864 | u64 cookie; | |
683b6d3b | 8865 | u32 duration; |
9588bbd5 JM |
8866 | int err; |
8867 | ||
8868 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
8869 | !info->attrs[NL80211_ATTR_DURATION]) | |
8870 | return -EINVAL; | |
8871 | ||
8872 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
8873 | ||
ebf348fc JB |
8874 | if (!rdev->ops->remain_on_channel || |
8875 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
8876 | return -EOPNOTSUPP; | |
8877 | ||
9588bbd5 | 8878 | /* |
ebf348fc JB |
8879 | * We should be on that channel for at least a minimum amount of |
8880 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 8881 | */ |
ebf348fc | 8882 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 8883 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
8884 | return -EINVAL; |
8885 | ||
683b6d3b JB |
8886 | err = nl80211_parse_chandef(rdev, info, &chandef); |
8887 | if (err) | |
8888 | return err; | |
9588bbd5 JM |
8889 | |
8890 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
8891 | if (!msg) |
8892 | return -ENOMEM; | |
9588bbd5 | 8893 | |
15e47304 | 8894 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 8895 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
8896 | if (!hdr) { |
8897 | err = -ENOBUFS; | |
9588bbd5 JM |
8898 | goto free_msg; |
8899 | } | |
8900 | ||
683b6d3b JB |
8901 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
8902 | duration, &cookie); | |
9588bbd5 JM |
8903 | |
8904 | if (err) | |
8905 | goto free_msg; | |
8906 | ||
2dad624e ND |
8907 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
8908 | NL80211_ATTR_PAD)) | |
9360ffd1 | 8909 | goto nla_put_failure; |
9588bbd5 JM |
8910 | |
8911 | genlmsg_end(msg, hdr); | |
4c476991 JB |
8912 | |
8913 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
8914 | |
8915 | nla_put_failure: | |
8916 | err = -ENOBUFS; | |
8917 | free_msg: | |
8918 | nlmsg_free(msg); | |
9588bbd5 JM |
8919 | return err; |
8920 | } | |
8921 | ||
8922 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
8923 | struct genl_info *info) | |
8924 | { | |
4c476991 | 8925 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8926 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 8927 | u64 cookie; |
9588bbd5 JM |
8928 | |
8929 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8930 | return -EINVAL; | |
8931 | ||
4c476991 JB |
8932 | if (!rdev->ops->cancel_remain_on_channel) |
8933 | return -EOPNOTSUPP; | |
9588bbd5 | 8934 | |
9588bbd5 JM |
8935 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
8936 | ||
e35e4d28 | 8937 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
8938 | } |
8939 | ||
13ae75b1 JM |
8940 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
8941 | struct genl_info *info) | |
8942 | { | |
13ae75b1 | 8943 | struct cfg80211_bitrate_mask mask; |
a7c7fbff | 8944 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 8945 | struct net_device *dev = info->user_ptr[1]; |
a7c7fbff | 8946 | int err; |
13ae75b1 | 8947 | |
4c476991 JB |
8948 | if (!rdev->ops->set_bitrate_mask) |
8949 | return -EOPNOTSUPP; | |
13ae75b1 | 8950 | |
a7c7fbff PK |
8951 | err = nl80211_parse_tx_bitrate_mask(info, &mask); |
8952 | if (err) | |
8953 | return err; | |
13ae75b1 | 8954 | |
e35e4d28 | 8955 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
8956 | } |
8957 | ||
2e161f78 | 8958 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8959 | { |
4c476991 | 8960 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8961 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 8962 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
8963 | |
8964 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
8965 | return -EINVAL; | |
8966 | ||
2e161f78 JB |
8967 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
8968 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 8969 | |
71bbc994 JB |
8970 | switch (wdev->iftype) { |
8971 | case NL80211_IFTYPE_STATION: | |
8972 | case NL80211_IFTYPE_ADHOC: | |
8973 | case NL80211_IFTYPE_P2P_CLIENT: | |
8974 | case NL80211_IFTYPE_AP: | |
8975 | case NL80211_IFTYPE_AP_VLAN: | |
8976 | case NL80211_IFTYPE_MESH_POINT: | |
8977 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8978 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8979 | break; |
8980 | default: | |
4c476991 | 8981 | return -EOPNOTSUPP; |
71bbc994 | 8982 | } |
026331c4 JM |
8983 | |
8984 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
8985 | if (!rdev->ops->mgmt_tx) |
8986 | return -EOPNOTSUPP; | |
026331c4 | 8987 | |
15e47304 | 8988 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
8989 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
8990 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
8991 | } |
8992 | ||
2e161f78 | 8993 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8994 | { |
4c476991 | 8995 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8996 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 8997 | struct cfg80211_chan_def chandef; |
026331c4 | 8998 | int err; |
d64d373f | 8999 | void *hdr = NULL; |
026331c4 | 9000 | u64 cookie; |
e247bd90 | 9001 | struct sk_buff *msg = NULL; |
b176e629 AO |
9002 | struct cfg80211_mgmt_tx_params params = { |
9003 | .dont_wait_for_ack = | |
9004 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
9005 | }; | |
026331c4 | 9006 | |
683b6d3b | 9007 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
9008 | return -EINVAL; |
9009 | ||
4c476991 JB |
9010 | if (!rdev->ops->mgmt_tx) |
9011 | return -EOPNOTSUPP; | |
026331c4 | 9012 | |
71bbc994 | 9013 | switch (wdev->iftype) { |
ea141b75 AQ |
9014 | case NL80211_IFTYPE_P2P_DEVICE: |
9015 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
9016 | return -EINVAL; | |
71bbc994 JB |
9017 | case NL80211_IFTYPE_STATION: |
9018 | case NL80211_IFTYPE_ADHOC: | |
9019 | case NL80211_IFTYPE_P2P_CLIENT: | |
9020 | case NL80211_IFTYPE_AP: | |
9021 | case NL80211_IFTYPE_AP_VLAN: | |
9022 | case NL80211_IFTYPE_MESH_POINT: | |
9023 | case NL80211_IFTYPE_P2P_GO: | |
9024 | break; | |
9025 | default: | |
4c476991 | 9026 | return -EOPNOTSUPP; |
71bbc994 | 9027 | } |
026331c4 | 9028 | |
f7ca38df | 9029 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 9030 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 9031 | return -EINVAL; |
b176e629 | 9032 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
9033 | |
9034 | /* | |
9035 | * We should wait on the channel for at least a minimum amount | |
9036 | * of time (10ms) but no longer than the driver supports. | |
9037 | */ | |
b176e629 AO |
9038 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
9039 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc | 9040 | return -EINVAL; |
f7ca38df JB |
9041 | } |
9042 | ||
b176e629 | 9043 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 9044 | |
b176e629 | 9045 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
9046 | return -EINVAL; |
9047 | ||
b176e629 | 9048 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 9049 | |
ea141b75 AQ |
9050 | /* get the channel if any has been specified, otherwise pass NULL to |
9051 | * the driver. The latter will use the current one | |
9052 | */ | |
9053 | chandef.chan = NULL; | |
9054 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
9055 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
9056 | if (err) | |
9057 | return err; | |
9058 | } | |
9059 | ||
b176e629 | 9060 | if (!chandef.chan && params.offchan) |
ea141b75 | 9061 | return -EINVAL; |
026331c4 | 9062 | |
34d22ce2 AO |
9063 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
9064 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
9065 | ||
9066 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
9067 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
9068 | int i; | |
9069 | ||
9070 | if (len % sizeof(u16)) | |
9071 | return -EINVAL; | |
9072 | ||
9073 | params.n_csa_offsets = len / sizeof(u16); | |
9074 | params.csa_offsets = | |
9075 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
9076 | ||
9077 | /* check that all the offsets fit the frame */ | |
9078 | for (i = 0; i < params.n_csa_offsets; i++) { | |
9079 | if (params.csa_offsets[i] >= params.len) | |
9080 | return -EINVAL; | |
9081 | } | |
9082 | } | |
9083 | ||
b176e629 | 9084 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
9085 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
9086 | if (!msg) | |
9087 | return -ENOMEM; | |
026331c4 | 9088 | |
15e47304 | 9089 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 9090 | NL80211_CMD_FRAME); |
cb35fba3 DC |
9091 | if (!hdr) { |
9092 | err = -ENOBUFS; | |
e247bd90 JB |
9093 | goto free_msg; |
9094 | } | |
026331c4 | 9095 | } |
e247bd90 | 9096 | |
b176e629 AO |
9097 | params.chan = chandef.chan; |
9098 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
9099 | if (err) |
9100 | goto free_msg; | |
9101 | ||
e247bd90 | 9102 | if (msg) { |
2dad624e ND |
9103 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
9104 | NL80211_ATTR_PAD)) | |
9360ffd1 | 9105 | goto nla_put_failure; |
026331c4 | 9106 | |
e247bd90 JB |
9107 | genlmsg_end(msg, hdr); |
9108 | return genlmsg_reply(msg, info); | |
9109 | } | |
9110 | ||
9111 | return 0; | |
026331c4 JM |
9112 | |
9113 | nla_put_failure: | |
9114 | err = -ENOBUFS; | |
9115 | free_msg: | |
9116 | nlmsg_free(msg); | |
026331c4 JM |
9117 | return err; |
9118 | } | |
9119 | ||
f7ca38df JB |
9120 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
9121 | { | |
9122 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 9123 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
9124 | u64 cookie; |
9125 | ||
9126 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
9127 | return -EINVAL; | |
9128 | ||
9129 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
9130 | return -EOPNOTSUPP; | |
9131 | ||
71bbc994 JB |
9132 | switch (wdev->iftype) { |
9133 | case NL80211_IFTYPE_STATION: | |
9134 | case NL80211_IFTYPE_ADHOC: | |
9135 | case NL80211_IFTYPE_P2P_CLIENT: | |
9136 | case NL80211_IFTYPE_AP: | |
9137 | case NL80211_IFTYPE_AP_VLAN: | |
9138 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 9139 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
9140 | break; |
9141 | default: | |
f7ca38df | 9142 | return -EOPNOTSUPP; |
71bbc994 | 9143 | } |
f7ca38df JB |
9144 | |
9145 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
9146 | ||
e35e4d28 | 9147 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
9148 | } |
9149 | ||
ffb9eb3d KV |
9150 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
9151 | { | |
4c476991 | 9152 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 9153 | struct wireless_dev *wdev; |
4c476991 | 9154 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
9155 | u8 ps_state; |
9156 | bool state; | |
9157 | int err; | |
9158 | ||
4c476991 JB |
9159 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
9160 | return -EINVAL; | |
ffb9eb3d KV |
9161 | |
9162 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
9163 | ||
4c476991 JB |
9164 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
9165 | return -EINVAL; | |
ffb9eb3d KV |
9166 | |
9167 | wdev = dev->ieee80211_ptr; | |
9168 | ||
4c476991 JB |
9169 | if (!rdev->ops->set_power_mgmt) |
9170 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
9171 | |
9172 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
9173 | ||
9174 | if (state == wdev->ps) | |
4c476991 | 9175 | return 0; |
ffb9eb3d | 9176 | |
e35e4d28 | 9177 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
9178 | if (!err) |
9179 | wdev->ps = state; | |
ffb9eb3d KV |
9180 | return err; |
9181 | } | |
9182 | ||
9183 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
9184 | { | |
4c476991 | 9185 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
9186 | enum nl80211_ps_state ps_state; |
9187 | struct wireless_dev *wdev; | |
4c476991 | 9188 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
9189 | struct sk_buff *msg; |
9190 | void *hdr; | |
9191 | int err; | |
9192 | ||
ffb9eb3d KV |
9193 | wdev = dev->ieee80211_ptr; |
9194 | ||
4c476991 JB |
9195 | if (!rdev->ops->set_power_mgmt) |
9196 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
9197 | |
9198 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
9199 | if (!msg) |
9200 | return -ENOMEM; | |
ffb9eb3d | 9201 | |
15e47304 | 9202 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
9203 | NL80211_CMD_GET_POWER_SAVE); |
9204 | if (!hdr) { | |
4c476991 | 9205 | err = -ENOBUFS; |
ffb9eb3d KV |
9206 | goto free_msg; |
9207 | } | |
9208 | ||
9209 | if (wdev->ps) | |
9210 | ps_state = NL80211_PS_ENABLED; | |
9211 | else | |
9212 | ps_state = NL80211_PS_DISABLED; | |
9213 | ||
9360ffd1 DM |
9214 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
9215 | goto nla_put_failure; | |
ffb9eb3d KV |
9216 | |
9217 | genlmsg_end(msg, hdr); | |
4c476991 | 9218 | return genlmsg_reply(msg, info); |
ffb9eb3d | 9219 | |
4c476991 | 9220 | nla_put_failure: |
ffb9eb3d | 9221 | err = -ENOBUFS; |
4c476991 | 9222 | free_msg: |
ffb9eb3d | 9223 | nlmsg_free(msg); |
ffb9eb3d KV |
9224 | return err; |
9225 | } | |
9226 | ||
94e860f1 JB |
9227 | static const struct nla_policy |
9228 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
9229 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
9230 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
9231 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
9232 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
9233 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
9234 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
9235 | }; |
9236 | ||
84f10708 | 9237 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 9238 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
9239 | { |
9240 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 9241 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 9242 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 9243 | |
d9d8b019 | 9244 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
9245 | return -EINVAL; |
9246 | ||
84f10708 TP |
9247 | if (!rdev->ops->set_cqm_txe_config) |
9248 | return -EOPNOTSUPP; | |
9249 | ||
9250 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
9251 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
9252 | return -EOPNOTSUPP; | |
9253 | ||
e35e4d28 | 9254 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
9255 | } |
9256 | ||
d6dc1a38 JO |
9257 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
9258 | s32 threshold, u32 hysteresis) | |
9259 | { | |
4c476991 | 9260 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 9261 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 9262 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
9263 | |
9264 | if (threshold > 0) | |
9265 | return -EINVAL; | |
9266 | ||
1da5fcc8 JB |
9267 | /* disabling - hysteresis should also be zero then */ |
9268 | if (threshold == 0) | |
9269 | hysteresis = 0; | |
d6dc1a38 | 9270 | |
4c476991 JB |
9271 | if (!rdev->ops->set_cqm_rssi_config) |
9272 | return -EOPNOTSUPP; | |
d6dc1a38 | 9273 | |
074ac8df | 9274 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
9275 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
9276 | return -EOPNOTSUPP; | |
d6dc1a38 | 9277 | |
e35e4d28 | 9278 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
9279 | } |
9280 | ||
9281 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
9282 | { | |
9283 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
9284 | struct nlattr *cqm; | |
9285 | int err; | |
9286 | ||
9287 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
9288 | if (!cqm) |
9289 | return -EINVAL; | |
d6dc1a38 JO |
9290 | |
9291 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
9292 | nl80211_attr_cqm_policy); | |
9293 | if (err) | |
1da5fcc8 | 9294 | return err; |
d6dc1a38 JO |
9295 | |
9296 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
9297 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
9298 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
9299 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 9300 | |
1da5fcc8 JB |
9301 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
9302 | } | |
9303 | ||
9304 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
9305 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
9306 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
9307 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
9308 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
9309 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
9310 | ||
9311 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
9312 | } | |
9313 | ||
9314 | return -EINVAL; | |
d6dc1a38 JO |
9315 | } |
9316 | ||
6e0bd6c3 RL |
9317 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
9318 | { | |
9319 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9320 | struct net_device *dev = info->user_ptr[1]; | |
9321 | struct ocb_setup setup = {}; | |
9322 | int err; | |
9323 | ||
9324 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | |
9325 | if (err) | |
9326 | return err; | |
9327 | ||
9328 | return cfg80211_join_ocb(rdev, dev, &setup); | |
9329 | } | |
9330 | ||
9331 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | |
9332 | { | |
9333 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9334 | struct net_device *dev = info->user_ptr[1]; | |
9335 | ||
9336 | return cfg80211_leave_ocb(rdev, dev); | |
9337 | } | |
9338 | ||
29cbe68c JB |
9339 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
9340 | { | |
9341 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9342 | struct net_device *dev = info->user_ptr[1]; | |
9343 | struct mesh_config cfg; | |
c80d545d | 9344 | struct mesh_setup setup; |
29cbe68c JB |
9345 | int err; |
9346 | ||
9347 | /* start with default */ | |
9348 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 9349 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 9350 | |
24bdd9f4 | 9351 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 9352 | /* and parse parameters if given */ |
24bdd9f4 | 9353 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
9354 | if (err) |
9355 | return err; | |
9356 | } | |
9357 | ||
9358 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
9359 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
9360 | return -EINVAL; | |
9361 | ||
c80d545d JC |
9362 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
9363 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
9364 | ||
4bb62344 CYY |
9365 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
9366 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
9367 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
9368 | return -EINVAL; | |
9369 | ||
9bdbf04d MP |
9370 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
9371 | setup.beacon_interval = | |
9372 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
12d20fc9 PK |
9373 | |
9374 | err = cfg80211_validate_beacon_int(rdev, setup.beacon_interval); | |
9375 | if (err) | |
9376 | return err; | |
9bdbf04d MP |
9377 | } |
9378 | ||
9379 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
9380 | setup.dtim_period = | |
9381 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
9382 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
9383 | return -EINVAL; | |
9384 | } | |
9385 | ||
c80d545d JC |
9386 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
9387 | /* parse additional setup parameters if given */ | |
9388 | err = nl80211_parse_mesh_setup(info, &setup); | |
9389 | if (err) | |
9390 | return err; | |
9391 | } | |
9392 | ||
d37bb18a TP |
9393 | if (setup.user_mpm) |
9394 | cfg.auto_open_plinks = false; | |
9395 | ||
cc1d2806 | 9396 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
9397 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
9398 | if (err) | |
9399 | return err; | |
cc1d2806 JB |
9400 | } else { |
9401 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 9402 | setup.chandef.chan = NULL; |
cc1d2806 JB |
9403 | } |
9404 | ||
ffb3cf30 AN |
9405 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
9406 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
9407 | int n_rates = | |
9408 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
9409 | struct ieee80211_supported_band *sband; | |
9410 | ||
9411 | if (!setup.chandef.chan) | |
9412 | return -EINVAL; | |
9413 | ||
9414 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
9415 | ||
9416 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
9417 | &setup.basic_rates); | |
9418 | if (err) | |
9419 | return err; | |
9420 | } | |
9421 | ||
8564e382 JB |
9422 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
9423 | err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate); | |
9424 | if (err) | |
9425 | return err; | |
9426 | ||
9427 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, | |
9428 | &setup.beacon_rate); | |
9429 | if (err) | |
9430 | return err; | |
9431 | } | |
9432 | ||
c80d545d | 9433 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
9434 | } |
9435 | ||
9436 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
9437 | { | |
9438 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9439 | struct net_device *dev = info->user_ptr[1]; | |
9440 | ||
9441 | return cfg80211_leave_mesh(rdev, dev); | |
9442 | } | |
9443 | ||
dfb89c56 | 9444 | #ifdef CONFIG_PM |
bb92d199 AK |
9445 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
9446 | struct cfg80211_registered_device *rdev) | |
9447 | { | |
6abb9cb9 | 9448 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
9449 | struct nlattr *nl_pats, *nl_pat; |
9450 | int i, pat_len; | |
9451 | ||
6abb9cb9 | 9452 | if (!wowlan->n_patterns) |
bb92d199 AK |
9453 | return 0; |
9454 | ||
9455 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
9456 | if (!nl_pats) | |
9457 | return -ENOBUFS; | |
9458 | ||
6abb9cb9 | 9459 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
9460 | nl_pat = nla_nest_start(msg, i + 1); |
9461 | if (!nl_pat) | |
9462 | return -ENOBUFS; | |
6abb9cb9 | 9463 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 9464 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 9465 | wowlan->patterns[i].mask) || |
50ac6607 AK |
9466 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
9467 | wowlan->patterns[i].pattern) || | |
9468 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 9469 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
9470 | return -ENOBUFS; |
9471 | nla_nest_end(msg, nl_pat); | |
9472 | } | |
9473 | nla_nest_end(msg, nl_pats); | |
9474 | ||
9475 | return 0; | |
9476 | } | |
9477 | ||
2a0e047e JB |
9478 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
9479 | struct cfg80211_wowlan_tcp *tcp) | |
9480 | { | |
9481 | struct nlattr *nl_tcp; | |
9482 | ||
9483 | if (!tcp) | |
9484 | return 0; | |
9485 | ||
9486 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
9487 | if (!nl_tcp) | |
9488 | return -ENOBUFS; | |
9489 | ||
930345ea JB |
9490 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
9491 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
2a0e047e JB |
9492 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
9493 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
9494 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
9495 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
9496 | tcp->payload_len, tcp->payload) || | |
9497 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
9498 | tcp->data_interval) || | |
9499 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
9500 | tcp->wake_len, tcp->wake_data) || | |
9501 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
9502 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
9503 | return -ENOBUFS; | |
9504 | ||
9505 | if (tcp->payload_seq.len && | |
9506 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
9507 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
9508 | return -ENOBUFS; | |
9509 | ||
9510 | if (tcp->payload_tok.len && | |
9511 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
9512 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
9513 | &tcp->payload_tok)) | |
9514 | return -ENOBUFS; | |
9515 | ||
e248ad30 JB |
9516 | nla_nest_end(msg, nl_tcp); |
9517 | ||
2a0e047e JB |
9518 | return 0; |
9519 | } | |
9520 | ||
75453ccb LC |
9521 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
9522 | struct cfg80211_sched_scan_request *req) | |
9523 | { | |
3b06d277 | 9524 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
75453ccb LC |
9525 | int i; |
9526 | ||
9527 | if (!req) | |
9528 | return 0; | |
9529 | ||
9530 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); | |
9531 | if (!nd) | |
9532 | return -ENOBUFS; | |
9533 | ||
3b06d277 AS |
9534 | if (req->n_scan_plans == 1 && |
9535 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, | |
9536 | req->scan_plans[0].interval * 1000)) | |
75453ccb LC |
9537 | return -ENOBUFS; |
9538 | ||
21fea567 LC |
9539 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
9540 | return -ENOBUFS; | |
9541 | ||
75453ccb LC |
9542 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
9543 | if (!freqs) | |
9544 | return -ENOBUFS; | |
9545 | ||
53b18980 JB |
9546 | for (i = 0; i < req->n_channels; i++) { |
9547 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
9548 | return -ENOBUFS; | |
9549 | } | |
75453ccb LC |
9550 | |
9551 | nla_nest_end(msg, freqs); | |
9552 | ||
9553 | if (req->n_match_sets) { | |
9554 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); | |
76e1fb4b JB |
9555 | if (!matches) |
9556 | return -ENOBUFS; | |
9557 | ||
75453ccb LC |
9558 | for (i = 0; i < req->n_match_sets; i++) { |
9559 | match = nla_nest_start(msg, i); | |
76e1fb4b JB |
9560 | if (!match) |
9561 | return -ENOBUFS; | |
9562 | ||
53b18980 JB |
9563 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
9564 | req->match_sets[i].ssid.ssid_len, | |
9565 | req->match_sets[i].ssid.ssid)) | |
9566 | return -ENOBUFS; | |
75453ccb LC |
9567 | nla_nest_end(msg, match); |
9568 | } | |
9569 | nla_nest_end(msg, matches); | |
9570 | } | |
9571 | ||
3b06d277 AS |
9572 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
9573 | if (!scan_plans) | |
9574 | return -ENOBUFS; | |
9575 | ||
9576 | for (i = 0; i < req->n_scan_plans; i++) { | |
9577 | scan_plan = nla_nest_start(msg, i + 1); | |
76e1fb4b JB |
9578 | if (!scan_plan) |
9579 | return -ENOBUFS; | |
9580 | ||
3b06d277 AS |
9581 | if (!scan_plan || |
9582 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, | |
9583 | req->scan_plans[i].interval) || | |
9584 | (req->scan_plans[i].iterations && | |
9585 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, | |
9586 | req->scan_plans[i].iterations))) | |
9587 | return -ENOBUFS; | |
9588 | nla_nest_end(msg, scan_plan); | |
9589 | } | |
9590 | nla_nest_end(msg, scan_plans); | |
9591 | ||
75453ccb LC |
9592 | nla_nest_end(msg, nd); |
9593 | ||
9594 | return 0; | |
9595 | } | |
9596 | ||
ff1b6e69 JB |
9597 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
9598 | { | |
9599 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9600 | struct sk_buff *msg; | |
9601 | void *hdr; | |
2a0e047e | 9602 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 9603 | |
964dc9e2 | 9604 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
9605 | return -EOPNOTSUPP; |
9606 | ||
6abb9cb9 | 9607 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 9608 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
9609 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
9610 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
9611 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
9612 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
9613 | } |
9614 | ||
9615 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
9616 | if (!msg) |
9617 | return -ENOMEM; | |
9618 | ||
15e47304 | 9619 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
9620 | NL80211_CMD_GET_WOWLAN); |
9621 | if (!hdr) | |
9622 | goto nla_put_failure; | |
9623 | ||
6abb9cb9 | 9624 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
9625 | struct nlattr *nl_wowlan; |
9626 | ||
9627 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
9628 | if (!nl_wowlan) | |
9629 | goto nla_put_failure; | |
9630 | ||
6abb9cb9 | 9631 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 9632 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 9633 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 9634 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 9635 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 9636 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 9637 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 9638 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 9639 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 9640 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 9641 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 9642 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 9643 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
9644 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
9645 | goto nla_put_failure; | |
2a0e047e | 9646 | |
bb92d199 AK |
9647 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
9648 | goto nla_put_failure; | |
2a0e047e | 9649 | |
6abb9cb9 JB |
9650 | if (nl80211_send_wowlan_tcp(msg, |
9651 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e | 9652 | goto nla_put_failure; |
75453ccb LC |
9653 | |
9654 | if (nl80211_send_wowlan_nd( | |
9655 | msg, | |
9656 | rdev->wiphy.wowlan_config->nd_config)) | |
9657 | goto nla_put_failure; | |
2a0e047e | 9658 | |
ff1b6e69 JB |
9659 | nla_nest_end(msg, nl_wowlan); |
9660 | } | |
9661 | ||
9662 | genlmsg_end(msg, hdr); | |
9663 | return genlmsg_reply(msg, info); | |
9664 | ||
9665 | nla_put_failure: | |
9666 | nlmsg_free(msg); | |
9667 | return -ENOBUFS; | |
9668 | } | |
9669 | ||
2a0e047e JB |
9670 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
9671 | struct nlattr *attr, | |
9672 | struct cfg80211_wowlan *trig) | |
9673 | { | |
9674 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
9675 | struct cfg80211_wowlan_tcp *cfg; | |
9676 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
9677 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
9678 | u32 size; | |
9679 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
9680 | int err, port; | |
9681 | ||
964dc9e2 | 9682 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
9683 | return -EINVAL; |
9684 | ||
9685 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
9686 | nla_data(attr), nla_len(attr), | |
9687 | nl80211_wowlan_tcp_policy); | |
9688 | if (err) | |
9689 | return err; | |
9690 | ||
9691 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
9692 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
9693 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
9694 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
9695 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
9696 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
9697 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
9698 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
9699 | return -EINVAL; | |
9700 | ||
9701 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 9702 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
9703 | return -EINVAL; |
9704 | ||
9705 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 9706 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 9707 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
9708 | return -EINVAL; |
9709 | ||
9710 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 9711 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
9712 | return -EINVAL; |
9713 | ||
9714 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
9715 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
9716 | return -EINVAL; | |
9717 | ||
9718 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
9719 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
9720 | ||
9721 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
9722 | tokens_size = tokln - sizeof(*tok); | |
9723 | ||
9724 | if (!tok->len || tokens_size % tok->len) | |
9725 | return -EINVAL; | |
964dc9e2 | 9726 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 9727 | return -EINVAL; |
964dc9e2 | 9728 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 9729 | return -EINVAL; |
964dc9e2 | 9730 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 9731 | return -EINVAL; |
964dc9e2 | 9732 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
9733 | return -EINVAL; |
9734 | if (tok->offset + tok->len > data_size) | |
9735 | return -EINVAL; | |
9736 | } | |
9737 | ||
9738 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
9739 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 9740 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
9741 | return -EINVAL; |
9742 | if (seq->len == 0 || seq->len > 4) | |
9743 | return -EINVAL; | |
9744 | if (seq->len + seq->offset > data_size) | |
9745 | return -EINVAL; | |
9746 | } | |
9747 | ||
9748 | size = sizeof(*cfg); | |
9749 | size += data_size; | |
9750 | size += wake_size + wake_mask_size; | |
9751 | size += tokens_size; | |
9752 | ||
9753 | cfg = kzalloc(size, GFP_KERNEL); | |
9754 | if (!cfg) | |
9755 | return -ENOMEM; | |
67b61f6c JB |
9756 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
9757 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
2a0e047e JB |
9758 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
9759 | ETH_ALEN); | |
9760 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
9761 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
9762 | else | |
9763 | port = 0; | |
9764 | #ifdef CONFIG_INET | |
9765 | /* allocate a socket and port for it and use it */ | |
9766 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
9767 | IPPROTO_TCP, &cfg->sock, 1); | |
9768 | if (err) { | |
9769 | kfree(cfg); | |
9770 | return err; | |
9771 | } | |
9772 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
9773 | sock_release(cfg->sock); | |
9774 | kfree(cfg); | |
9775 | return -EADDRINUSE; | |
9776 | } | |
9777 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
9778 | #else | |
9779 | if (!port) { | |
9780 | kfree(cfg); | |
9781 | return -EINVAL; | |
9782 | } | |
9783 | cfg->src_port = port; | |
9784 | #endif | |
9785 | ||
9786 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
9787 | cfg->payload_len = data_size; | |
9788 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
9789 | memcpy((void *)cfg->payload, | |
9790 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
9791 | data_size); | |
9792 | if (seq) | |
9793 | cfg->payload_seq = *seq; | |
9794 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
9795 | cfg->wake_len = wake_size; | |
9796 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
9797 | memcpy((void *)cfg->wake_data, | |
9798 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
9799 | wake_size); | |
9800 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
9801 | data_size + wake_size; | |
9802 | memcpy((void *)cfg->wake_mask, | |
9803 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
9804 | wake_mask_size); | |
9805 | if (tok) { | |
9806 | cfg->tokens_size = tokens_size; | |
9807 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
9808 | } | |
9809 | ||
9810 | trig->tcp = cfg; | |
9811 | ||
9812 | return 0; | |
9813 | } | |
9814 | ||
8cd4d456 LC |
9815 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
9816 | const struct wiphy_wowlan_support *wowlan, | |
9817 | struct nlattr *attr, | |
9818 | struct cfg80211_wowlan *trig) | |
9819 | { | |
9820 | struct nlattr **tb; | |
9821 | int err; | |
9822 | ||
9823 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); | |
9824 | if (!tb) | |
9825 | return -ENOMEM; | |
9826 | ||
9827 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | |
9828 | err = -EOPNOTSUPP; | |
9829 | goto out; | |
9830 | } | |
9831 | ||
9832 | err = nla_parse(tb, NL80211_ATTR_MAX, | |
9833 | nla_data(attr), nla_len(attr), | |
9834 | nl80211_policy); | |
9835 | if (err) | |
9836 | goto out; | |
9837 | ||
ad2b26ab | 9838 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
8cd4d456 LC |
9839 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
9840 | if (err) | |
9841 | trig->nd_config = NULL; | |
9842 | ||
9843 | out: | |
9844 | kfree(tb); | |
9845 | return err; | |
9846 | } | |
9847 | ||
ff1b6e69 JB |
9848 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
9849 | { | |
9850 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9851 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 9852 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 9853 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 9854 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 9855 | int err, i; |
6abb9cb9 | 9856 | bool prev_enabled = rdev->wiphy.wowlan_config; |
98fc4386 | 9857 | bool regular = false; |
ff1b6e69 | 9858 | |
964dc9e2 | 9859 | if (!wowlan) |
ff1b6e69 JB |
9860 | return -EOPNOTSUPP; |
9861 | ||
ae33bd81 JB |
9862 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
9863 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 9864 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
9865 | goto set_wakeup; |
9866 | } | |
ff1b6e69 JB |
9867 | |
9868 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
9869 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9870 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9871 | nl80211_wowlan_policy); | |
9872 | if (err) | |
9873 | return err; | |
9874 | ||
9875 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
9876 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
9877 | return -EINVAL; | |
9878 | new_triggers.any = true; | |
9879 | } | |
9880 | ||
9881 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
9882 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
9883 | return -EINVAL; | |
9884 | new_triggers.disconnect = true; | |
98fc4386 | 9885 | regular = true; |
ff1b6e69 JB |
9886 | } |
9887 | ||
9888 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
9889 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
9890 | return -EINVAL; | |
9891 | new_triggers.magic_pkt = true; | |
98fc4386 | 9892 | regular = true; |
ff1b6e69 JB |
9893 | } |
9894 | ||
77dbbb13 JB |
9895 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
9896 | return -EINVAL; | |
9897 | ||
9898 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
9899 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
9900 | return -EINVAL; | |
9901 | new_triggers.gtk_rekey_failure = true; | |
98fc4386 | 9902 | regular = true; |
77dbbb13 JB |
9903 | } |
9904 | ||
9905 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
9906 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
9907 | return -EINVAL; | |
9908 | new_triggers.eap_identity_req = true; | |
98fc4386 | 9909 | regular = true; |
77dbbb13 JB |
9910 | } |
9911 | ||
9912 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
9913 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
9914 | return -EINVAL; | |
9915 | new_triggers.four_way_handshake = true; | |
98fc4386 | 9916 | regular = true; |
77dbbb13 JB |
9917 | } |
9918 | ||
9919 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
9920 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
9921 | return -EINVAL; | |
9922 | new_triggers.rfkill_release = true; | |
98fc4386 | 9923 | regular = true; |
77dbbb13 JB |
9924 | } |
9925 | ||
ff1b6e69 JB |
9926 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
9927 | struct nlattr *pat; | |
9928 | int n_patterns = 0; | |
bb92d199 | 9929 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 9930 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 | 9931 | |
98fc4386 JB |
9932 | regular = true; |
9933 | ||
ff1b6e69 JB |
9934 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
9935 | rem) | |
9936 | n_patterns++; | |
9937 | if (n_patterns > wowlan->n_patterns) | |
9938 | return -EINVAL; | |
9939 | ||
9940 | new_triggers.patterns = kcalloc(n_patterns, | |
9941 | sizeof(new_triggers.patterns[0]), | |
9942 | GFP_KERNEL); | |
9943 | if (!new_triggers.patterns) | |
9944 | return -ENOMEM; | |
9945 | ||
9946 | new_triggers.n_patterns = n_patterns; | |
9947 | i = 0; | |
9948 | ||
9949 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9950 | rem) { | |
922bd80f JB |
9951 | u8 *mask_pat; |
9952 | ||
50ac6607 AK |
9953 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9954 | nla_len(pat), NULL); | |
ff1b6e69 | 9955 | err = -EINVAL; |
50ac6607 AK |
9956 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
9957 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 9958 | goto error; |
50ac6607 | 9959 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 9960 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 9961 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
9962 | goto error; |
9963 | if (pat_len > wowlan->pattern_max_len || | |
9964 | pat_len < wowlan->pattern_min_len) | |
9965 | goto error; | |
9966 | ||
50ac6607 | 9967 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
9968 | pkt_offset = 0; |
9969 | else | |
9970 | pkt_offset = nla_get_u32( | |
50ac6607 | 9971 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
9972 | if (pkt_offset > wowlan->max_pkt_offset) |
9973 | goto error; | |
9974 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
9975 | ||
922bd80f JB |
9976 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9977 | if (!mask_pat) { | |
ff1b6e69 JB |
9978 | err = -ENOMEM; |
9979 | goto error; | |
9980 | } | |
922bd80f JB |
9981 | new_triggers.patterns[i].mask = mask_pat; |
9982 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 9983 | mask_len); |
922bd80f JB |
9984 | mask_pat += mask_len; |
9985 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 9986 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 9987 | memcpy(mask_pat, |
50ac6607 | 9988 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
9989 | pat_len); |
9990 | i++; | |
9991 | } | |
9992 | } | |
9993 | ||
2a0e047e | 9994 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
98fc4386 | 9995 | regular = true; |
2a0e047e JB |
9996 | err = nl80211_parse_wowlan_tcp( |
9997 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
9998 | &new_triggers); | |
9999 | if (err) | |
10000 | goto error; | |
10001 | } | |
10002 | ||
8cd4d456 | 10003 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
98fc4386 | 10004 | regular = true; |
8cd4d456 LC |
10005 | err = nl80211_parse_wowlan_nd( |
10006 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | |
10007 | &new_triggers); | |
10008 | if (err) | |
10009 | goto error; | |
10010 | } | |
10011 | ||
98fc4386 JB |
10012 | /* The 'any' trigger means the device continues operating more or less |
10013 | * as in its normal operation mode and wakes up the host on most of the | |
10014 | * normal interrupts (like packet RX, ...) | |
10015 | * It therefore makes little sense to combine with the more constrained | |
10016 | * wakeup trigger modes. | |
10017 | */ | |
10018 | if (new_triggers.any && regular) { | |
10019 | err = -EINVAL; | |
10020 | goto error; | |
10021 | } | |
10022 | ||
ae33bd81 JB |
10023 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
10024 | if (!ntrig) { | |
10025 | err = -ENOMEM; | |
10026 | goto error; | |
ff1b6e69 | 10027 | } |
ae33bd81 | 10028 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 10029 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 10030 | |
ae33bd81 | 10031 | set_wakeup: |
6abb9cb9 JB |
10032 | if (rdev->ops->set_wakeup && |
10033 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
10034 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 10035 | |
ff1b6e69 JB |
10036 | return 0; |
10037 | error: | |
10038 | for (i = 0; i < new_triggers.n_patterns; i++) | |
10039 | kfree(new_triggers.patterns[i].mask); | |
10040 | kfree(new_triggers.patterns); | |
2a0e047e JB |
10041 | if (new_triggers.tcp && new_triggers.tcp->sock) |
10042 | sock_release(new_triggers.tcp->sock); | |
10043 | kfree(new_triggers.tcp); | |
e5dbe070 | 10044 | kfree(new_triggers.nd_config); |
ff1b6e69 JB |
10045 | return err; |
10046 | } | |
dfb89c56 | 10047 | #endif |
ff1b6e69 | 10048 | |
be29b99a AK |
10049 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
10050 | struct cfg80211_registered_device *rdev) | |
10051 | { | |
10052 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
10053 | int i, j, pat_len; | |
10054 | struct cfg80211_coalesce_rules *rule; | |
10055 | ||
10056 | if (!rdev->coalesce->n_rules) | |
10057 | return 0; | |
10058 | ||
10059 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
10060 | if (!nl_rules) | |
10061 | return -ENOBUFS; | |
10062 | ||
10063 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
10064 | nl_rule = nla_nest_start(msg, i + 1); | |
10065 | if (!nl_rule) | |
10066 | return -ENOBUFS; | |
10067 | ||
10068 | rule = &rdev->coalesce->rules[i]; | |
10069 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
10070 | rule->delay)) | |
10071 | return -ENOBUFS; | |
10072 | ||
10073 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
10074 | rule->condition)) | |
10075 | return -ENOBUFS; | |
10076 | ||
10077 | nl_pats = nla_nest_start(msg, | |
10078 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
10079 | if (!nl_pats) | |
10080 | return -ENOBUFS; | |
10081 | ||
10082 | for (j = 0; j < rule->n_patterns; j++) { | |
10083 | nl_pat = nla_nest_start(msg, j + 1); | |
10084 | if (!nl_pat) | |
10085 | return -ENOBUFS; | |
10086 | pat_len = rule->patterns[j].pattern_len; | |
10087 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
10088 | DIV_ROUND_UP(pat_len, 8), | |
10089 | rule->patterns[j].mask) || | |
10090 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
10091 | rule->patterns[j].pattern) || | |
10092 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
10093 | rule->patterns[j].pkt_offset)) | |
10094 | return -ENOBUFS; | |
10095 | nla_nest_end(msg, nl_pat); | |
10096 | } | |
10097 | nla_nest_end(msg, nl_pats); | |
10098 | nla_nest_end(msg, nl_rule); | |
10099 | } | |
10100 | nla_nest_end(msg, nl_rules); | |
10101 | ||
10102 | return 0; | |
10103 | } | |
10104 | ||
10105 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
10106 | { | |
10107 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10108 | struct sk_buff *msg; | |
10109 | void *hdr; | |
10110 | ||
10111 | if (!rdev->wiphy.coalesce) | |
10112 | return -EOPNOTSUPP; | |
10113 | ||
10114 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10115 | if (!msg) | |
10116 | return -ENOMEM; | |
10117 | ||
10118 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
10119 | NL80211_CMD_GET_COALESCE); | |
10120 | if (!hdr) | |
10121 | goto nla_put_failure; | |
10122 | ||
10123 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
10124 | goto nla_put_failure; | |
10125 | ||
10126 | genlmsg_end(msg, hdr); | |
10127 | return genlmsg_reply(msg, info); | |
10128 | ||
10129 | nla_put_failure: | |
10130 | nlmsg_free(msg); | |
10131 | return -ENOBUFS; | |
10132 | } | |
10133 | ||
10134 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
10135 | { | |
10136 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
10137 | int i, j; | |
10138 | struct cfg80211_coalesce_rules *rule; | |
10139 | ||
10140 | if (!coalesce) | |
10141 | return; | |
10142 | ||
10143 | for (i = 0; i < coalesce->n_rules; i++) { | |
10144 | rule = &coalesce->rules[i]; | |
10145 | for (j = 0; j < rule->n_patterns; j++) | |
10146 | kfree(rule->patterns[j].mask); | |
10147 | kfree(rule->patterns); | |
10148 | } | |
10149 | kfree(coalesce->rules); | |
10150 | kfree(coalesce); | |
10151 | rdev->coalesce = NULL; | |
10152 | } | |
10153 | ||
10154 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
10155 | struct nlattr *rule, | |
10156 | struct cfg80211_coalesce_rules *new_rule) | |
10157 | { | |
10158 | int err, i; | |
10159 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
10160 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
10161 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
10162 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
10163 | ||
10164 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
10165 | nla_len(rule), nl80211_coalesce_policy); | |
10166 | if (err) | |
10167 | return err; | |
10168 | ||
10169 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
10170 | new_rule->delay = | |
10171 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
10172 | if (new_rule->delay > coalesce->max_delay) | |
10173 | return -EINVAL; | |
10174 | ||
10175 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
10176 | new_rule->condition = | |
10177 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
10178 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
10179 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
10180 | return -EINVAL; | |
10181 | ||
10182 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
10183 | return -EINVAL; | |
10184 | ||
10185 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
10186 | rem) | |
10187 | n_patterns++; | |
10188 | if (n_patterns > coalesce->n_patterns) | |
10189 | return -EINVAL; | |
10190 | ||
10191 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
10192 | GFP_KERNEL); | |
10193 | if (!new_rule->patterns) | |
10194 | return -ENOMEM; | |
10195 | ||
10196 | new_rule->n_patterns = n_patterns; | |
10197 | i = 0; | |
10198 | ||
10199 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
10200 | rem) { | |
922bd80f JB |
10201 | u8 *mask_pat; |
10202 | ||
be29b99a AK |
10203 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
10204 | nla_len(pat), NULL); | |
10205 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
10206 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
10207 | return -EINVAL; | |
10208 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
10209 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
10210 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
10211 | return -EINVAL; | |
10212 | if (pat_len > coalesce->pattern_max_len || | |
10213 | pat_len < coalesce->pattern_min_len) | |
10214 | return -EINVAL; | |
10215 | ||
10216 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
10217 | pkt_offset = 0; | |
10218 | else | |
10219 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
10220 | if (pkt_offset > coalesce->max_pkt_offset) | |
10221 | return -EINVAL; | |
10222 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
10223 | ||
922bd80f JB |
10224 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
10225 | if (!mask_pat) | |
be29b99a | 10226 | return -ENOMEM; |
922bd80f JB |
10227 | |
10228 | new_rule->patterns[i].mask = mask_pat; | |
10229 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
10230 | mask_len); | |
10231 | ||
10232 | mask_pat += mask_len; | |
10233 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 10234 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
10235 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
10236 | pat_len); | |
be29b99a AK |
10237 | i++; |
10238 | } | |
10239 | ||
10240 | return 0; | |
10241 | } | |
10242 | ||
10243 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
10244 | { | |
10245 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10246 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
10247 | struct cfg80211_coalesce new_coalesce = {}; | |
10248 | struct cfg80211_coalesce *n_coalesce; | |
10249 | int err, rem_rule, n_rules = 0, i, j; | |
10250 | struct nlattr *rule; | |
10251 | struct cfg80211_coalesce_rules *tmp_rule; | |
10252 | ||
10253 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
10254 | return -EOPNOTSUPP; | |
10255 | ||
10256 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
10257 | cfg80211_rdev_free_coalesce(rdev); | |
a1056b1b | 10258 | rdev_set_coalesce(rdev, NULL); |
be29b99a AK |
10259 | return 0; |
10260 | } | |
10261 | ||
10262 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
10263 | rem_rule) | |
10264 | n_rules++; | |
10265 | if (n_rules > coalesce->n_rules) | |
10266 | return -EINVAL; | |
10267 | ||
10268 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
10269 | GFP_KERNEL); | |
10270 | if (!new_coalesce.rules) | |
10271 | return -ENOMEM; | |
10272 | ||
10273 | new_coalesce.n_rules = n_rules; | |
10274 | i = 0; | |
10275 | ||
10276 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
10277 | rem_rule) { | |
10278 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
10279 | &new_coalesce.rules[i]); | |
10280 | if (err) | |
10281 | goto error; | |
10282 | ||
10283 | i++; | |
10284 | } | |
10285 | ||
a1056b1b | 10286 | err = rdev_set_coalesce(rdev, &new_coalesce); |
be29b99a AK |
10287 | if (err) |
10288 | goto error; | |
10289 | ||
10290 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
10291 | if (!n_coalesce) { | |
10292 | err = -ENOMEM; | |
10293 | goto error; | |
10294 | } | |
10295 | cfg80211_rdev_free_coalesce(rdev); | |
10296 | rdev->coalesce = n_coalesce; | |
10297 | ||
10298 | return 0; | |
10299 | error: | |
10300 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
10301 | tmp_rule = &new_coalesce.rules[i]; | |
10302 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
10303 | kfree(tmp_rule->patterns[j].mask); | |
10304 | kfree(tmp_rule->patterns); | |
10305 | } | |
10306 | kfree(new_coalesce.rules); | |
10307 | ||
10308 | return err; | |
10309 | } | |
10310 | ||
e5497d76 JB |
10311 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
10312 | { | |
10313 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10314 | struct net_device *dev = info->user_ptr[1]; | |
10315 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10316 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
10317 | struct cfg80211_gtk_rekey_data rekey_data; | |
10318 | int err; | |
10319 | ||
10320 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
10321 | return -EINVAL; | |
10322 | ||
10323 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
10324 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
10325 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
10326 | nl80211_rekey_policy); | |
10327 | if (err) | |
10328 | return err; | |
10329 | ||
10330 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
10331 | return -ERANGE; | |
10332 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
10333 | return -ERANGE; | |
10334 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
10335 | return -ERANGE; | |
10336 | ||
78f686ca JB |
10337 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
10338 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | |
10339 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | |
e5497d76 JB |
10340 | |
10341 | wdev_lock(wdev); | |
10342 | if (!wdev->current_bss) { | |
10343 | err = -ENOTCONN; | |
10344 | goto out; | |
10345 | } | |
10346 | ||
10347 | if (!rdev->ops->set_rekey_data) { | |
10348 | err = -EOPNOTSUPP; | |
10349 | goto out; | |
10350 | } | |
10351 | ||
e35e4d28 | 10352 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
10353 | out: |
10354 | wdev_unlock(wdev); | |
10355 | return err; | |
10356 | } | |
10357 | ||
28946da7 JB |
10358 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
10359 | struct genl_info *info) | |
10360 | { | |
10361 | struct net_device *dev = info->user_ptr[1]; | |
10362 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10363 | ||
10364 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
10365 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
10366 | return -EINVAL; | |
10367 | ||
15e47304 | 10368 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
10369 | return -EBUSY; |
10370 | ||
15e47304 | 10371 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
10372 | return 0; |
10373 | } | |
10374 | ||
7f6cf311 JB |
10375 | static int nl80211_probe_client(struct sk_buff *skb, |
10376 | struct genl_info *info) | |
10377 | { | |
10378 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10379 | struct net_device *dev = info->user_ptr[1]; | |
10380 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10381 | struct sk_buff *msg; | |
10382 | void *hdr; | |
10383 | const u8 *addr; | |
10384 | u64 cookie; | |
10385 | int err; | |
10386 | ||
10387 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
10388 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
10389 | return -EOPNOTSUPP; | |
10390 | ||
10391 | if (!info->attrs[NL80211_ATTR_MAC]) | |
10392 | return -EINVAL; | |
10393 | ||
10394 | if (!rdev->ops->probe_client) | |
10395 | return -EOPNOTSUPP; | |
10396 | ||
10397 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10398 | if (!msg) | |
10399 | return -ENOMEM; | |
10400 | ||
15e47304 | 10401 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 10402 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
10403 | if (!hdr) { |
10404 | err = -ENOBUFS; | |
7f6cf311 JB |
10405 | goto free_msg; |
10406 | } | |
10407 | ||
10408 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10409 | ||
e35e4d28 | 10410 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
10411 | if (err) |
10412 | goto free_msg; | |
10413 | ||
2dad624e ND |
10414 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
10415 | NL80211_ATTR_PAD)) | |
9360ffd1 | 10416 | goto nla_put_failure; |
7f6cf311 JB |
10417 | |
10418 | genlmsg_end(msg, hdr); | |
10419 | ||
10420 | return genlmsg_reply(msg, info); | |
10421 | ||
10422 | nla_put_failure: | |
10423 | err = -ENOBUFS; | |
10424 | free_msg: | |
10425 | nlmsg_free(msg); | |
10426 | return err; | |
10427 | } | |
10428 | ||
5e760230 JB |
10429 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
10430 | { | |
10431 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
10432 | struct cfg80211_beacon_registration *reg, *nreg; |
10433 | int rv; | |
5e760230 JB |
10434 | |
10435 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
10436 | return -EOPNOTSUPP; | |
10437 | ||
37c73b5f BG |
10438 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
10439 | if (!nreg) | |
10440 | return -ENOMEM; | |
10441 | ||
10442 | /* First, check if already registered. */ | |
10443 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
10444 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
10445 | if (reg->nlportid == info->snd_portid) { | |
10446 | rv = -EALREADY; | |
10447 | goto out_err; | |
10448 | } | |
10449 | } | |
10450 | /* Add it to the list */ | |
10451 | nreg->nlportid = info->snd_portid; | |
10452 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 10453 | |
37c73b5f | 10454 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
10455 | |
10456 | return 0; | |
37c73b5f BG |
10457 | out_err: |
10458 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
10459 | kfree(nreg); | |
10460 | return rv; | |
5e760230 JB |
10461 | } |
10462 | ||
98104fde JB |
10463 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
10464 | { | |
10465 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10466 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10467 | int err; | |
10468 | ||
10469 | if (!rdev->ops->start_p2p_device) | |
10470 | return -EOPNOTSUPP; | |
10471 | ||
10472 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
10473 | return -EOPNOTSUPP; | |
10474 | ||
10475 | if (wdev->p2p_started) | |
10476 | return 0; | |
10477 | ||
b6a55015 LC |
10478 | if (rfkill_blocked(rdev->rfkill)) |
10479 | return -ERFKILL; | |
98104fde | 10480 | |
eeb126e9 | 10481 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
10482 | if (err) |
10483 | return err; | |
10484 | ||
10485 | wdev->p2p_started = true; | |
98104fde | 10486 | rdev->opencount++; |
98104fde JB |
10487 | |
10488 | return 0; | |
10489 | } | |
10490 | ||
10491 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
10492 | { | |
10493 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10494 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10495 | ||
10496 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
10497 | return -EOPNOTSUPP; | |
10498 | ||
10499 | if (!rdev->ops->stop_p2p_device) | |
10500 | return -EOPNOTSUPP; | |
10501 | ||
f9f47529 | 10502 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
10503 | |
10504 | return 0; | |
10505 | } | |
10506 | ||
3713b4e3 JB |
10507 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
10508 | struct genl_info *info) | |
10509 | { | |
10510 | void *hdr; | |
10511 | struct sk_buff *msg; | |
10512 | ||
10513 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10514 | if (!msg) | |
10515 | return -ENOMEM; | |
10516 | ||
10517 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
10518 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
10519 | if (!hdr) | |
10520 | goto nla_put_failure; | |
10521 | ||
10522 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
10523 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
10524 | goto nla_put_failure; | |
10525 | ||
10526 | genlmsg_end(msg, hdr); | |
10527 | return genlmsg_reply(msg, info); | |
10528 | ||
10529 | nla_put_failure: | |
10530 | kfree_skb(msg); | |
10531 | return -ENOBUFS; | |
10532 | } | |
10533 | ||
355199e0 JM |
10534 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
10535 | { | |
10536 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10537 | struct cfg80211_update_ft_ies_params ft_params; | |
10538 | struct net_device *dev = info->user_ptr[1]; | |
10539 | ||
10540 | if (!rdev->ops->update_ft_ies) | |
10541 | return -EOPNOTSUPP; | |
10542 | ||
10543 | if (!info->attrs[NL80211_ATTR_MDID] || | |
10544 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
10545 | return -EINVAL; | |
10546 | ||
10547 | memset(&ft_params, 0, sizeof(ft_params)); | |
10548 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
10549 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
10550 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
10551 | ||
10552 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
10553 | } | |
10554 | ||
5de17984 AS |
10555 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
10556 | 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 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
10561 | u16 duration; | |
10562 | int ret; | |
10563 | ||
10564 | if (!rdev->ops->crit_proto_start) | |
10565 | return -EOPNOTSUPP; | |
10566 | ||
10567 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
10568 | return -EINVAL; | |
10569 | ||
10570 | if (rdev->crit_proto_nlportid) | |
10571 | return -EBUSY; | |
10572 | ||
10573 | /* determine protocol if provided */ | |
10574 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
10575 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
10576 | ||
10577 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
10578 | return -EINVAL; | |
10579 | ||
10580 | /* timeout must be provided */ | |
10581 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
10582 | return -EINVAL; | |
10583 | ||
10584 | duration = | |
10585 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
10586 | ||
10587 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
10588 | return -ERANGE; | |
10589 | ||
10590 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
10591 | if (!ret) | |
10592 | rdev->crit_proto_nlportid = info->snd_portid; | |
10593 | ||
10594 | return ret; | |
10595 | } | |
10596 | ||
10597 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
10598 | struct genl_info *info) | |
10599 | { | |
10600 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10601 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10602 | ||
10603 | if (!rdev->ops->crit_proto_stop) | |
10604 | return -EOPNOTSUPP; | |
10605 | ||
10606 | if (rdev->crit_proto_nlportid) { | |
10607 | rdev->crit_proto_nlportid = 0; | |
10608 | rdev_crit_proto_stop(rdev, wdev); | |
10609 | } | |
10610 | return 0; | |
10611 | } | |
10612 | ||
ad7e718c JB |
10613 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
10614 | { | |
10615 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10616 | struct wireless_dev *wdev = | |
10617 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
10618 | int i, err; | |
10619 | u32 vid, subcmd; | |
10620 | ||
10621 | if (!rdev->wiphy.vendor_commands) | |
10622 | return -EOPNOTSUPP; | |
10623 | ||
10624 | if (IS_ERR(wdev)) { | |
10625 | err = PTR_ERR(wdev); | |
10626 | if (err != -EINVAL) | |
10627 | return err; | |
10628 | wdev = NULL; | |
10629 | } else if (wdev->wiphy != &rdev->wiphy) { | |
10630 | return -EINVAL; | |
10631 | } | |
10632 | ||
10633 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
10634 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
10635 | return -EINVAL; | |
10636 | ||
10637 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
10638 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
10639 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
10640 | const struct wiphy_vendor_command *vcmd; | |
10641 | void *data = NULL; | |
10642 | int len = 0; | |
10643 | ||
10644 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
10645 | ||
10646 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
10647 | continue; | |
10648 | ||
10649 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
10650 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
10651 | if (!wdev) | |
10652 | return -EINVAL; | |
10653 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
10654 | !wdev->netdev) | |
10655 | return -EINVAL; | |
10656 | ||
10657 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
10658 | if (wdev->netdev && | |
10659 | !netif_running(wdev->netdev)) | |
10660 | return -ENETDOWN; | |
10661 | if (!wdev->netdev && !wdev->p2p_started) | |
10662 | return -ENETDOWN; | |
10663 | } | |
7bdbe400 JB |
10664 | |
10665 | if (!vcmd->doit) | |
10666 | return -EOPNOTSUPP; | |
ad7e718c JB |
10667 | } else { |
10668 | wdev = NULL; | |
10669 | } | |
10670 | ||
10671 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
10672 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
10673 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
10674 | } | |
10675 | ||
10676 | rdev->cur_cmd_info = info; | |
10677 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
10678 | data, len); | |
10679 | rdev->cur_cmd_info = NULL; | |
10680 | return err; | |
10681 | } | |
10682 | ||
10683 | return -EOPNOTSUPP; | |
10684 | } | |
10685 | ||
7bdbe400 JB |
10686 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
10687 | struct netlink_callback *cb, | |
10688 | struct cfg80211_registered_device **rdev, | |
10689 | struct wireless_dev **wdev) | |
10690 | { | |
10691 | u32 vid, subcmd; | |
10692 | unsigned int i; | |
10693 | int vcmd_idx = -1; | |
10694 | int err; | |
10695 | void *data = NULL; | |
10696 | unsigned int data_len = 0; | |
10697 | ||
10698 | rtnl_lock(); | |
10699 | ||
10700 | if (cb->args[0]) { | |
10701 | /* subtract the 1 again here */ | |
10702 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
10703 | struct wireless_dev *tmp; | |
10704 | ||
10705 | if (!wiphy) { | |
10706 | err = -ENODEV; | |
10707 | goto out_unlock; | |
10708 | } | |
10709 | *rdev = wiphy_to_rdev(wiphy); | |
10710 | *wdev = NULL; | |
10711 | ||
10712 | if (cb->args[1]) { | |
53873f13 | 10713 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
7bdbe400 JB |
10714 | if (tmp->identifier == cb->args[1] - 1) { |
10715 | *wdev = tmp; | |
10716 | break; | |
10717 | } | |
10718 | } | |
10719 | } | |
10720 | ||
10721 | /* keep rtnl locked in successful case */ | |
10722 | return 0; | |
10723 | } | |
10724 | ||
10725 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
10726 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
10727 | nl80211_policy); | |
10728 | if (err) | |
10729 | goto out_unlock; | |
10730 | ||
10731 | if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] || | |
10732 | !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { | |
10733 | err = -EINVAL; | |
10734 | goto out_unlock; | |
10735 | } | |
10736 | ||
10737 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), | |
10738 | nl80211_fam.attrbuf); | |
10739 | if (IS_ERR(*wdev)) | |
10740 | *wdev = NULL; | |
10741 | ||
10742 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), | |
10743 | nl80211_fam.attrbuf); | |
10744 | if (IS_ERR(*rdev)) { | |
10745 | err = PTR_ERR(*rdev); | |
10746 | goto out_unlock; | |
10747 | } | |
10748 | ||
10749 | vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]); | |
10750 | subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); | |
10751 | ||
10752 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { | |
10753 | const struct wiphy_vendor_command *vcmd; | |
10754 | ||
10755 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; | |
10756 | ||
10757 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
10758 | continue; | |
10759 | ||
10760 | if (!vcmd->dumpit) { | |
10761 | err = -EOPNOTSUPP; | |
10762 | goto out_unlock; | |
10763 | } | |
10764 | ||
10765 | vcmd_idx = i; | |
10766 | break; | |
10767 | } | |
10768 | ||
10769 | if (vcmd_idx < 0) { | |
10770 | err = -EOPNOTSUPP; | |
10771 | goto out_unlock; | |
10772 | } | |
10773 | ||
10774 | if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) { | |
10775 | data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); | |
10776 | data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); | |
10777 | } | |
10778 | ||
10779 | /* 0 is the first index - add 1 to parse only once */ | |
10780 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
10781 | /* add 1 to know if it was NULL */ | |
10782 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; | |
10783 | cb->args[2] = vcmd_idx; | |
10784 | cb->args[3] = (unsigned long)data; | |
10785 | cb->args[4] = data_len; | |
10786 | ||
10787 | /* keep rtnl locked in successful case */ | |
10788 | return 0; | |
10789 | out_unlock: | |
10790 | rtnl_unlock(); | |
10791 | return err; | |
10792 | } | |
10793 | ||
10794 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, | |
10795 | struct netlink_callback *cb) | |
10796 | { | |
10797 | struct cfg80211_registered_device *rdev; | |
10798 | struct wireless_dev *wdev; | |
10799 | unsigned int vcmd_idx; | |
10800 | const struct wiphy_vendor_command *vcmd; | |
10801 | void *data; | |
10802 | int data_len; | |
10803 | int err; | |
10804 | struct nlattr *vendor_data; | |
10805 | ||
10806 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); | |
10807 | if (err) | |
10808 | return err; | |
10809 | ||
10810 | vcmd_idx = cb->args[2]; | |
10811 | data = (void *)cb->args[3]; | |
10812 | data_len = cb->args[4]; | |
10813 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; | |
10814 | ||
10815 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
10816 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
10817 | if (!wdev) | |
10818 | return -EINVAL; | |
10819 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
10820 | !wdev->netdev) | |
10821 | return -EINVAL; | |
10822 | ||
10823 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
10824 | if (wdev->netdev && | |
10825 | !netif_running(wdev->netdev)) | |
10826 | return -ENETDOWN; | |
10827 | if (!wdev->netdev && !wdev->p2p_started) | |
10828 | return -ENETDOWN; | |
10829 | } | |
10830 | } | |
10831 | ||
10832 | while (1) { | |
10833 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, | |
10834 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
10835 | NL80211_CMD_VENDOR); | |
10836 | if (!hdr) | |
10837 | break; | |
10838 | ||
10839 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
10840 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
10841 | wdev_id(wdev), | |
10842 | NL80211_ATTR_PAD))) { | |
7bdbe400 JB |
10843 | genlmsg_cancel(skb, hdr); |
10844 | break; | |
10845 | } | |
10846 | ||
10847 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); | |
10848 | if (!vendor_data) { | |
10849 | genlmsg_cancel(skb, hdr); | |
10850 | break; | |
10851 | } | |
10852 | ||
10853 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, | |
10854 | (unsigned long *)&cb->args[5]); | |
10855 | nla_nest_end(skb, vendor_data); | |
10856 | ||
10857 | if (err == -ENOBUFS || err == -ENOENT) { | |
10858 | genlmsg_cancel(skb, hdr); | |
10859 | break; | |
10860 | } else if (err) { | |
10861 | genlmsg_cancel(skb, hdr); | |
10862 | goto out; | |
10863 | } | |
10864 | ||
10865 | genlmsg_end(skb, hdr); | |
10866 | } | |
10867 | ||
10868 | err = skb->len; | |
10869 | out: | |
10870 | rtnl_unlock(); | |
10871 | return err; | |
10872 | } | |
10873 | ||
ad7e718c JB |
10874 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
10875 | enum nl80211_commands cmd, | |
10876 | enum nl80211_attrs attr, | |
10877 | int approxlen) | |
10878 | { | |
f26cbf40 | 10879 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
10880 | |
10881 | if (WARN_ON(!rdev->cur_cmd_info)) | |
10882 | return NULL; | |
10883 | ||
6c09e791 | 10884 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
ad7e718c JB |
10885 | rdev->cur_cmd_info->snd_portid, |
10886 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 10887 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
10888 | } |
10889 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
10890 | ||
10891 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
10892 | { | |
10893 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
10894 | void *hdr = ((void **)skb->cb)[1]; | |
10895 | struct nlattr *data = ((void **)skb->cb)[2]; | |
10896 | ||
bd8c78e7 JB |
10897 | /* clear CB data for netlink core to own from now on */ |
10898 | memset(skb->cb, 0, sizeof(skb->cb)); | |
10899 | ||
ad7e718c JB |
10900 | if (WARN_ON(!rdev->cur_cmd_info)) { |
10901 | kfree_skb(skb); | |
10902 | return -EINVAL; | |
10903 | } | |
10904 | ||
10905 | nla_nest_end(skb, data); | |
10906 | genlmsg_end(skb, hdr); | |
10907 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
10908 | } | |
10909 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
10910 | ||
fa9ffc74 KP |
10911 | static int nl80211_set_qos_map(struct sk_buff *skb, |
10912 | struct genl_info *info) | |
10913 | { | |
10914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10915 | struct cfg80211_qos_map *qos_map = NULL; | |
10916 | struct net_device *dev = info->user_ptr[1]; | |
10917 | u8 *pos, len, num_des, des_len, des; | |
10918 | int ret; | |
10919 | ||
10920 | if (!rdev->ops->set_qos_map) | |
10921 | return -EOPNOTSUPP; | |
10922 | ||
10923 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
10924 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
10925 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
10926 | ||
10927 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
10928 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
10929 | return -EINVAL; | |
10930 | ||
10931 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
10932 | if (!qos_map) | |
10933 | return -ENOMEM; | |
10934 | ||
10935 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
10936 | if (num_des) { | |
10937 | des_len = num_des * | |
10938 | sizeof(struct cfg80211_dscp_exception); | |
10939 | memcpy(qos_map->dscp_exception, pos, des_len); | |
10940 | qos_map->num_des = num_des; | |
10941 | for (des = 0; des < num_des; des++) { | |
10942 | if (qos_map->dscp_exception[des].up > 7) { | |
10943 | kfree(qos_map); | |
10944 | return -EINVAL; | |
10945 | } | |
10946 | } | |
10947 | pos += des_len; | |
10948 | } | |
10949 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
10950 | } | |
10951 | ||
10952 | wdev_lock(dev->ieee80211_ptr); | |
10953 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
10954 | if (!ret) | |
10955 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
10956 | wdev_unlock(dev->ieee80211_ptr); | |
10957 | ||
10958 | kfree(qos_map); | |
10959 | return ret; | |
10960 | } | |
10961 | ||
960d01ac JB |
10962 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
10963 | { | |
10964 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10965 | struct net_device *dev = info->user_ptr[1]; | |
10966 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10967 | const u8 *peer; | |
10968 | u8 tsid, up; | |
10969 | u16 admitted_time = 0; | |
10970 | int err; | |
10971 | ||
723e73ac | 10972 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
960d01ac JB |
10973 | return -EOPNOTSUPP; |
10974 | ||
10975 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | |
10976 | !info->attrs[NL80211_ATTR_USER_PRIO]) | |
10977 | return -EINVAL; | |
10978 | ||
10979 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
10980 | if (tsid >= IEEE80211_NUM_TIDS) | |
10981 | return -EINVAL; | |
10982 | ||
10983 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); | |
10984 | if (up >= IEEE80211_NUM_UPS) | |
10985 | return -EINVAL; | |
10986 | ||
10987 | /* WMM uses TIDs 0-7 even for TSPEC */ | |
723e73ac | 10988 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
960d01ac | 10989 | /* TODO: handle 802.11 TSPEC/admission control |
723e73ac JB |
10990 | * need more attributes for that (e.g. BA session requirement); |
10991 | * change the WMM adminssion test above to allow both then | |
960d01ac JB |
10992 | */ |
10993 | return -EINVAL; | |
10994 | } | |
10995 | ||
10996 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10997 | ||
10998 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | |
10999 | admitted_time = | |
11000 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | |
11001 | if (!admitted_time) | |
11002 | return -EINVAL; | |
11003 | } | |
11004 | ||
11005 | wdev_lock(wdev); | |
11006 | switch (wdev->iftype) { | |
11007 | case NL80211_IFTYPE_STATION: | |
11008 | case NL80211_IFTYPE_P2P_CLIENT: | |
11009 | if (wdev->current_bss) | |
11010 | break; | |
11011 | err = -ENOTCONN; | |
11012 | goto out; | |
11013 | default: | |
11014 | err = -EOPNOTSUPP; | |
11015 | goto out; | |
11016 | } | |
11017 | ||
11018 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | |
11019 | ||
11020 | out: | |
11021 | wdev_unlock(wdev); | |
11022 | return err; | |
11023 | } | |
11024 | ||
11025 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | |
11026 | { | |
11027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11028 | struct net_device *dev = info->user_ptr[1]; | |
11029 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11030 | const u8 *peer; | |
11031 | u8 tsid; | |
11032 | int err; | |
11033 | ||
11034 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | |
11035 | return -EINVAL; | |
11036 | ||
11037 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
11038 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
11039 | ||
11040 | wdev_lock(wdev); | |
11041 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | |
11042 | wdev_unlock(wdev); | |
11043 | ||
11044 | return err; | |
11045 | } | |
11046 | ||
1057d35e AN |
11047 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
11048 | struct genl_info *info) | |
11049 | { | |
11050 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11051 | struct net_device *dev = info->user_ptr[1]; | |
11052 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11053 | struct cfg80211_chan_def chandef = {}; | |
11054 | const u8 *addr; | |
11055 | u8 oper_class; | |
11056 | int err; | |
11057 | ||
11058 | if (!rdev->ops->tdls_channel_switch || | |
11059 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
11060 | return -EOPNOTSUPP; | |
11061 | ||
11062 | switch (dev->ieee80211_ptr->iftype) { | |
11063 | case NL80211_IFTYPE_STATION: | |
11064 | case NL80211_IFTYPE_P2P_CLIENT: | |
11065 | break; | |
11066 | default: | |
11067 | return -EOPNOTSUPP; | |
11068 | } | |
11069 | ||
11070 | if (!info->attrs[NL80211_ATTR_MAC] || | |
11071 | !info->attrs[NL80211_ATTR_OPER_CLASS]) | |
11072 | return -EINVAL; | |
11073 | ||
11074 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
11075 | if (err) | |
11076 | return err; | |
11077 | ||
11078 | /* | |
11079 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | |
11080 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | |
11081 | * specification is not defined for them. | |
11082 | */ | |
57fbcce3 | 11083 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
1057d35e AN |
11084 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
11085 | chandef.width != NL80211_CHAN_WIDTH_20) | |
11086 | return -EINVAL; | |
11087 | ||
11088 | /* we will be active on the TDLS link */ | |
923b352f AN |
11089 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
11090 | wdev->iftype)) | |
1057d35e AN |
11091 | return -EINVAL; |
11092 | ||
11093 | /* don't allow switching to DFS channels */ | |
11094 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | |
11095 | return -EINVAL; | |
11096 | ||
11097 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
11098 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | |
11099 | ||
11100 | wdev_lock(wdev); | |
11101 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | |
11102 | wdev_unlock(wdev); | |
11103 | ||
11104 | return err; | |
11105 | } | |
11106 | ||
11107 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | |
11108 | struct genl_info *info) | |
11109 | { | |
11110 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11111 | struct net_device *dev = info->user_ptr[1]; | |
11112 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11113 | const u8 *addr; | |
11114 | ||
11115 | if (!rdev->ops->tdls_channel_switch || | |
11116 | !rdev->ops->tdls_cancel_channel_switch || | |
11117 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
11118 | return -EOPNOTSUPP; | |
11119 | ||
11120 | switch (dev->ieee80211_ptr->iftype) { | |
11121 | case NL80211_IFTYPE_STATION: | |
11122 | case NL80211_IFTYPE_P2P_CLIENT: | |
11123 | break; | |
11124 | default: | |
11125 | return -EOPNOTSUPP; | |
11126 | } | |
11127 | ||
11128 | if (!info->attrs[NL80211_ATTR_MAC]) | |
11129 | return -EINVAL; | |
11130 | ||
11131 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
11132 | ||
11133 | wdev_lock(wdev); | |
11134 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); | |
11135 | wdev_unlock(wdev); | |
11136 | ||
11137 | return 0; | |
11138 | } | |
11139 | ||
4c476991 JB |
11140 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
11141 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
11142 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
11143 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
11144 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
11145 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 11146 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 11147 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
11148 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
11149 | NL80211_FLAG_CHECK_NETDEV_UP) | |
5393b917 | 11150 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
4c476991 | 11151 | |
f84f771d | 11152 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
11153 | struct genl_info *info) |
11154 | { | |
11155 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 11156 | struct wireless_dev *wdev; |
4c476991 | 11157 | struct net_device *dev; |
4c476991 JB |
11158 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
11159 | ||
11160 | if (rtnl) | |
11161 | rtnl_lock(); | |
11162 | ||
11163 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 11164 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
11165 | if (IS_ERR(rdev)) { |
11166 | if (rtnl) | |
11167 | rtnl_unlock(); | |
11168 | return PTR_ERR(rdev); | |
11169 | } | |
11170 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
11171 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
11172 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
11173 | ASSERT_RTNL(); |
11174 | ||
89a54e48 JB |
11175 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
11176 | info->attrs); | |
11177 | if (IS_ERR(wdev)) { | |
4c476991 JB |
11178 | if (rtnl) |
11179 | rtnl_unlock(); | |
89a54e48 | 11180 | return PTR_ERR(wdev); |
4c476991 | 11181 | } |
89a54e48 | 11182 | |
89a54e48 | 11183 | dev = wdev->netdev; |
f26cbf40 | 11184 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 11185 | |
1bf614ef JB |
11186 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
11187 | if (!dev) { | |
1bf614ef JB |
11188 | if (rtnl) |
11189 | rtnl_unlock(); | |
11190 | return -EINVAL; | |
11191 | } | |
11192 | ||
11193 | info->user_ptr[1] = dev; | |
11194 | } else { | |
11195 | info->user_ptr[1] = wdev; | |
41265714 | 11196 | } |
1bf614ef JB |
11197 | |
11198 | if (dev) { | |
11199 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
11200 | !netif_running(dev)) { | |
1bf614ef JB |
11201 | if (rtnl) |
11202 | rtnl_unlock(); | |
11203 | return -ENETDOWN; | |
11204 | } | |
11205 | ||
11206 | dev_hold(dev); | |
98104fde JB |
11207 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
11208 | if (!wdev->p2p_started) { | |
98104fde JB |
11209 | if (rtnl) |
11210 | rtnl_unlock(); | |
11211 | return -ENETDOWN; | |
11212 | } | |
41265714 | 11213 | } |
89a54e48 | 11214 | |
4c476991 | 11215 | info->user_ptr[0] = rdev; |
4c476991 JB |
11216 | } |
11217 | ||
11218 | return 0; | |
11219 | } | |
11220 | ||
f84f771d | 11221 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
11222 | struct genl_info *info) |
11223 | { | |
1bf614ef JB |
11224 | if (info->user_ptr[1]) { |
11225 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
11226 | struct wireless_dev *wdev = info->user_ptr[1]; | |
11227 | ||
11228 | if (wdev->netdev) | |
11229 | dev_put(wdev->netdev); | |
11230 | } else { | |
11231 | dev_put(info->user_ptr[1]); | |
11232 | } | |
11233 | } | |
5393b917 | 11234 | |
4c476991 JB |
11235 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
11236 | rtnl_unlock(); | |
5393b917 JB |
11237 | |
11238 | /* If needed, clear the netlink message payload from the SKB | |
11239 | * as it might contain key data that shouldn't stick around on | |
11240 | * the heap after the SKB is freed. The netlink message header | |
11241 | * is still needed for further processing, so leave it intact. | |
11242 | */ | |
11243 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | |
11244 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | |
11245 | ||
11246 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | |
11247 | } | |
4c476991 JB |
11248 | } |
11249 | ||
4534de83 | 11250 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
11251 | { |
11252 | .cmd = NL80211_CMD_GET_WIPHY, | |
11253 | .doit = nl80211_get_wiphy, | |
11254 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 11255 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
11256 | .policy = nl80211_policy, |
11257 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
11258 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11259 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
11260 | }, |
11261 | { | |
11262 | .cmd = NL80211_CMD_SET_WIPHY, | |
11263 | .doit = nl80211_set_wiphy, | |
11264 | .policy = nl80211_policy, | |
5617c6cd | 11265 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 | 11266 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
11267 | }, |
11268 | { | |
11269 | .cmd = NL80211_CMD_GET_INTERFACE, | |
11270 | .doit = nl80211_get_interface, | |
11271 | .dumpit = nl80211_dump_interface, | |
11272 | .policy = nl80211_policy, | |
11273 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
11274 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
11275 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
11276 | }, |
11277 | { | |
11278 | .cmd = NL80211_CMD_SET_INTERFACE, | |
11279 | .doit = nl80211_set_interface, | |
11280 | .policy = nl80211_policy, | |
5617c6cd | 11281 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11282 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11283 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
11284 | }, |
11285 | { | |
11286 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
11287 | .doit = nl80211_new_interface, | |
11288 | .policy = nl80211_policy, | |
5617c6cd | 11289 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11290 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11291 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
11292 | }, |
11293 | { | |
11294 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
11295 | .doit = nl80211_del_interface, | |
11296 | .policy = nl80211_policy, | |
5617c6cd | 11297 | .flags = GENL_UNS_ADMIN_PERM, |
84efbb84 | 11298 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 11299 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
11300 | }, |
11301 | { | |
11302 | .cmd = NL80211_CMD_GET_KEY, | |
11303 | .doit = nl80211_get_key, | |
11304 | .policy = nl80211_policy, | |
5617c6cd | 11305 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11306 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11307 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
11308 | }, |
11309 | { | |
11310 | .cmd = NL80211_CMD_SET_KEY, | |
11311 | .doit = nl80211_set_key, | |
11312 | .policy = nl80211_policy, | |
5617c6cd | 11313 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11314 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
11315 | NL80211_FLAG_NEED_RTNL | |
11316 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
11317 | }, |
11318 | { | |
11319 | .cmd = NL80211_CMD_NEW_KEY, | |
11320 | .doit = nl80211_new_key, | |
11321 | .policy = nl80211_policy, | |
5617c6cd | 11322 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11323 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
11324 | NL80211_FLAG_NEED_RTNL | |
11325 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
11326 | }, |
11327 | { | |
11328 | .cmd = NL80211_CMD_DEL_KEY, | |
11329 | .doit = nl80211_del_key, | |
11330 | .policy = nl80211_policy, | |
5617c6cd | 11331 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11332 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11333 | NL80211_FLAG_NEED_RTNL, |
55682965 | 11334 | }, |
ed1b6cc7 JB |
11335 | { |
11336 | .cmd = NL80211_CMD_SET_BEACON, | |
11337 | .policy = nl80211_policy, | |
5617c6cd | 11338 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 11339 | .doit = nl80211_set_beacon, |
2b5f8b0b | 11340 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11341 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
11342 | }, |
11343 | { | |
8860020e | 11344 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 | 11345 | .policy = nl80211_policy, |
5617c6cd | 11346 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 11347 | .doit = nl80211_start_ap, |
2b5f8b0b | 11348 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11349 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
11350 | }, |
11351 | { | |
8860020e | 11352 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 | 11353 | .policy = nl80211_policy, |
5617c6cd | 11354 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 11355 | .doit = nl80211_stop_ap, |
2b5f8b0b | 11356 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11357 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 11358 | }, |
5727ef1b JB |
11359 | { |
11360 | .cmd = NL80211_CMD_GET_STATION, | |
11361 | .doit = nl80211_get_station, | |
2ec600d6 | 11362 | .dumpit = nl80211_dump_station, |
5727ef1b | 11363 | .policy = nl80211_policy, |
4c476991 JB |
11364 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11365 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
11366 | }, |
11367 | { | |
11368 | .cmd = NL80211_CMD_SET_STATION, | |
11369 | .doit = nl80211_set_station, | |
11370 | .policy = nl80211_policy, | |
5617c6cd | 11371 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11372 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11373 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
11374 | }, |
11375 | { | |
11376 | .cmd = NL80211_CMD_NEW_STATION, | |
11377 | .doit = nl80211_new_station, | |
11378 | .policy = nl80211_policy, | |
5617c6cd | 11379 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11380 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11381 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
11382 | }, |
11383 | { | |
11384 | .cmd = NL80211_CMD_DEL_STATION, | |
11385 | .doit = nl80211_del_station, | |
11386 | .policy = nl80211_policy, | |
5617c6cd | 11387 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11388 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11389 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
11390 | }, |
11391 | { | |
11392 | .cmd = NL80211_CMD_GET_MPATH, | |
11393 | .doit = nl80211_get_mpath, | |
11394 | .dumpit = nl80211_dump_mpath, | |
11395 | .policy = nl80211_policy, | |
5617c6cd | 11396 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11397 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11398 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 | 11399 | }, |
66be7d2b HR |
11400 | { |
11401 | .cmd = NL80211_CMD_GET_MPP, | |
11402 | .doit = nl80211_get_mpp, | |
11403 | .dumpit = nl80211_dump_mpp, | |
11404 | .policy = nl80211_policy, | |
5617c6cd | 11405 | .flags = GENL_UNS_ADMIN_PERM, |
66be7d2b HR |
11406 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11407 | NL80211_FLAG_NEED_RTNL, | |
11408 | }, | |
2ec600d6 LCC |
11409 | { |
11410 | .cmd = NL80211_CMD_SET_MPATH, | |
11411 | .doit = nl80211_set_mpath, | |
11412 | .policy = nl80211_policy, | |
5617c6cd | 11413 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11414 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11415 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
11416 | }, |
11417 | { | |
11418 | .cmd = NL80211_CMD_NEW_MPATH, | |
11419 | .doit = nl80211_new_mpath, | |
11420 | .policy = nl80211_policy, | |
5617c6cd | 11421 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11422 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11423 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
11424 | }, |
11425 | { | |
11426 | .cmd = NL80211_CMD_DEL_MPATH, | |
11427 | .doit = nl80211_del_mpath, | |
11428 | .policy = nl80211_policy, | |
5617c6cd | 11429 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11430 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11431 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
11432 | }, |
11433 | { | |
11434 | .cmd = NL80211_CMD_SET_BSS, | |
11435 | .doit = nl80211_set_bss, | |
11436 | .policy = nl80211_policy, | |
5617c6cd | 11437 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11438 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11439 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 11440 | }, |
f130347c LR |
11441 | { |
11442 | .cmd = NL80211_CMD_GET_REG, | |
ad30ca2c AN |
11443 | .doit = nl80211_get_reg_do, |
11444 | .dumpit = nl80211_get_reg_dump, | |
f130347c | 11445 | .policy = nl80211_policy, |
5fe231e8 | 11446 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
11447 | /* can be retrieved by unprivileged users */ |
11448 | }, | |
b6863036 | 11449 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
b2e1b302 LR |
11450 | { |
11451 | .cmd = NL80211_CMD_SET_REG, | |
11452 | .doit = nl80211_set_reg, | |
11453 | .policy = nl80211_policy, | |
11454 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 11455 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 11456 | }, |
b6863036 | 11457 | #endif |
b2e1b302 LR |
11458 | { |
11459 | .cmd = NL80211_CMD_REQ_SET_REG, | |
11460 | .doit = nl80211_req_set_reg, | |
11461 | .policy = nl80211_policy, | |
93da9cc1 | 11462 | .flags = GENL_ADMIN_PERM, |
11463 | }, | |
11464 | { | |
24bdd9f4 JC |
11465 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
11466 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 11467 | .policy = nl80211_policy, |
11468 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 11469 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11470 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 11471 | }, |
11472 | { | |
24bdd9f4 JC |
11473 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
11474 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 11475 | .policy = nl80211_policy, |
5617c6cd | 11476 | .flags = GENL_UNS_ADMIN_PERM, |
29cbe68c | 11477 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11478 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 11479 | }, |
2a519311 JB |
11480 | { |
11481 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
11482 | .doit = nl80211_trigger_scan, | |
11483 | .policy = nl80211_policy, | |
5617c6cd | 11484 | .flags = GENL_UNS_ADMIN_PERM, |
fd014284 | 11485 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 11486 | NL80211_FLAG_NEED_RTNL, |
2a519311 | 11487 | }, |
91d3ab46 VK |
11488 | { |
11489 | .cmd = NL80211_CMD_ABORT_SCAN, | |
11490 | .doit = nl80211_abort_scan, | |
11491 | .policy = nl80211_policy, | |
5617c6cd | 11492 | .flags = GENL_UNS_ADMIN_PERM, |
91d3ab46 VK |
11493 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
11494 | NL80211_FLAG_NEED_RTNL, | |
11495 | }, | |
2a519311 JB |
11496 | { |
11497 | .cmd = NL80211_CMD_GET_SCAN, | |
11498 | .policy = nl80211_policy, | |
11499 | .dumpit = nl80211_dump_scan, | |
11500 | }, | |
807f8a8c LC |
11501 | { |
11502 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
11503 | .doit = nl80211_start_sched_scan, | |
11504 | .policy = nl80211_policy, | |
5617c6cd | 11505 | .flags = GENL_UNS_ADMIN_PERM, |
807f8a8c LC |
11506 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11507 | NL80211_FLAG_NEED_RTNL, | |
11508 | }, | |
11509 | { | |
11510 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
11511 | .doit = nl80211_stop_sched_scan, | |
11512 | .policy = nl80211_policy, | |
5617c6cd | 11513 | .flags = GENL_UNS_ADMIN_PERM, |
807f8a8c LC |
11514 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11515 | NL80211_FLAG_NEED_RTNL, | |
11516 | }, | |
636a5d36 JM |
11517 | { |
11518 | .cmd = NL80211_CMD_AUTHENTICATE, | |
11519 | .doit = nl80211_authenticate, | |
11520 | .policy = nl80211_policy, | |
5617c6cd | 11521 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11522 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
11523 | NL80211_FLAG_NEED_RTNL | |
11524 | NL80211_FLAG_CLEAR_SKB, | |
636a5d36 JM |
11525 | }, |
11526 | { | |
11527 | .cmd = NL80211_CMD_ASSOCIATE, | |
11528 | .doit = nl80211_associate, | |
11529 | .policy = nl80211_policy, | |
5617c6cd | 11530 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11531 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11532 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
11533 | }, |
11534 | { | |
11535 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
11536 | .doit = nl80211_deauthenticate, | |
11537 | .policy = nl80211_policy, | |
5617c6cd | 11538 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11539 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11540 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
11541 | }, |
11542 | { | |
11543 | .cmd = NL80211_CMD_DISASSOCIATE, | |
11544 | .doit = nl80211_disassociate, | |
11545 | .policy = nl80211_policy, | |
5617c6cd | 11546 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11547 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11548 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 11549 | }, |
04a773ad JB |
11550 | { |
11551 | .cmd = NL80211_CMD_JOIN_IBSS, | |
11552 | .doit = nl80211_join_ibss, | |
11553 | .policy = nl80211_policy, | |
5617c6cd | 11554 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11555 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11556 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
11557 | }, |
11558 | { | |
11559 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
11560 | .doit = nl80211_leave_ibss, | |
11561 | .policy = nl80211_policy, | |
5617c6cd | 11562 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11563 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11564 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 11565 | }, |
aff89a9b JB |
11566 | #ifdef CONFIG_NL80211_TESTMODE |
11567 | { | |
11568 | .cmd = NL80211_CMD_TESTMODE, | |
11569 | .doit = nl80211_testmode_do, | |
71063f0e | 11570 | .dumpit = nl80211_testmode_dump, |
aff89a9b | 11571 | .policy = nl80211_policy, |
5617c6cd | 11572 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11573 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11574 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
11575 | }, |
11576 | #endif | |
b23aa676 SO |
11577 | { |
11578 | .cmd = NL80211_CMD_CONNECT, | |
11579 | .doit = nl80211_connect, | |
11580 | .policy = nl80211_policy, | |
5617c6cd | 11581 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11582 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11583 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
11584 | }, |
11585 | { | |
11586 | .cmd = NL80211_CMD_DISCONNECT, | |
11587 | .doit = nl80211_disconnect, | |
11588 | .policy = nl80211_policy, | |
5617c6cd | 11589 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11590 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11591 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 11592 | }, |
463d0183 JB |
11593 | { |
11594 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
11595 | .doit = nl80211_wiphy_netns, | |
11596 | .policy = nl80211_policy, | |
5617c6cd | 11597 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11598 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11599 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 11600 | }, |
61fa713c HS |
11601 | { |
11602 | .cmd = NL80211_CMD_GET_SURVEY, | |
11603 | .policy = nl80211_policy, | |
11604 | .dumpit = nl80211_dump_survey, | |
11605 | }, | |
67fbb16b SO |
11606 | { |
11607 | .cmd = NL80211_CMD_SET_PMKSA, | |
11608 | .doit = nl80211_setdel_pmksa, | |
11609 | .policy = nl80211_policy, | |
5617c6cd | 11610 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11611 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11612 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
11613 | }, |
11614 | { | |
11615 | .cmd = NL80211_CMD_DEL_PMKSA, | |
11616 | .doit = nl80211_setdel_pmksa, | |
11617 | .policy = nl80211_policy, | |
5617c6cd | 11618 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11619 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11620 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
11621 | }, |
11622 | { | |
11623 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
11624 | .doit = nl80211_flush_pmksa, | |
11625 | .policy = nl80211_policy, | |
5617c6cd | 11626 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11627 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11628 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 11629 | }, |
9588bbd5 JM |
11630 | { |
11631 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
11632 | .doit = nl80211_remain_on_channel, | |
11633 | .policy = nl80211_policy, | |
5617c6cd | 11634 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 11635 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 11636 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
11637 | }, |
11638 | { | |
11639 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
11640 | .doit = nl80211_cancel_remain_on_channel, | |
11641 | .policy = nl80211_policy, | |
5617c6cd | 11642 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 11643 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 11644 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 11645 | }, |
13ae75b1 JM |
11646 | { |
11647 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
11648 | .doit = nl80211_set_tx_bitrate_mask, | |
11649 | .policy = nl80211_policy, | |
5617c6cd | 11650 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11651 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11652 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 11653 | }, |
026331c4 | 11654 | { |
2e161f78 JB |
11655 | .cmd = NL80211_CMD_REGISTER_FRAME, |
11656 | .doit = nl80211_register_mgmt, | |
026331c4 | 11657 | .policy = nl80211_policy, |
5617c6cd | 11658 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 11659 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 11660 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
11661 | }, |
11662 | { | |
2e161f78 JB |
11663 | .cmd = NL80211_CMD_FRAME, |
11664 | .doit = nl80211_tx_mgmt, | |
026331c4 | 11665 | .policy = nl80211_policy, |
5617c6cd | 11666 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 11667 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
11668 | NL80211_FLAG_NEED_RTNL, |
11669 | }, | |
11670 | { | |
11671 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
11672 | .doit = nl80211_tx_mgmt_cancel_wait, | |
11673 | .policy = nl80211_policy, | |
5617c6cd | 11674 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 11675 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 11676 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 11677 | }, |
ffb9eb3d KV |
11678 | { |
11679 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
11680 | .doit = nl80211_set_power_save, | |
11681 | .policy = nl80211_policy, | |
5617c6cd | 11682 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11683 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11684 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
11685 | }, |
11686 | { | |
11687 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
11688 | .doit = nl80211_get_power_save, | |
11689 | .policy = nl80211_policy, | |
11690 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
11691 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11692 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 11693 | }, |
d6dc1a38 JO |
11694 | { |
11695 | .cmd = NL80211_CMD_SET_CQM, | |
11696 | .doit = nl80211_set_cqm, | |
11697 | .policy = nl80211_policy, | |
5617c6cd | 11698 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11699 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11700 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 11701 | }, |
f444de05 JB |
11702 | { |
11703 | .cmd = NL80211_CMD_SET_CHANNEL, | |
11704 | .doit = nl80211_set_channel, | |
11705 | .policy = nl80211_policy, | |
5617c6cd | 11706 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11707 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11708 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 11709 | }, |
e8347eba BJ |
11710 | { |
11711 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
11712 | .doit = nl80211_set_wds_peer, | |
11713 | .policy = nl80211_policy, | |
5617c6cd | 11714 | .flags = GENL_UNS_ADMIN_PERM, |
43b19952 JB |
11715 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11716 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 11717 | }, |
29cbe68c JB |
11718 | { |
11719 | .cmd = NL80211_CMD_JOIN_MESH, | |
11720 | .doit = nl80211_join_mesh, | |
11721 | .policy = nl80211_policy, | |
5617c6cd | 11722 | .flags = GENL_UNS_ADMIN_PERM, |
29cbe68c JB |
11723 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11724 | NL80211_FLAG_NEED_RTNL, | |
11725 | }, | |
11726 | { | |
11727 | .cmd = NL80211_CMD_LEAVE_MESH, | |
11728 | .doit = nl80211_leave_mesh, | |
11729 | .policy = nl80211_policy, | |
5617c6cd | 11730 | .flags = GENL_UNS_ADMIN_PERM, |
29cbe68c JB |
11731 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11732 | NL80211_FLAG_NEED_RTNL, | |
11733 | }, | |
6e0bd6c3 RL |
11734 | { |
11735 | .cmd = NL80211_CMD_JOIN_OCB, | |
11736 | .doit = nl80211_join_ocb, | |
11737 | .policy = nl80211_policy, | |
5617c6cd | 11738 | .flags = GENL_UNS_ADMIN_PERM, |
6e0bd6c3 RL |
11739 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11740 | NL80211_FLAG_NEED_RTNL, | |
11741 | }, | |
11742 | { | |
11743 | .cmd = NL80211_CMD_LEAVE_OCB, | |
11744 | .doit = nl80211_leave_ocb, | |
11745 | .policy = nl80211_policy, | |
5617c6cd | 11746 | .flags = GENL_UNS_ADMIN_PERM, |
6e0bd6c3 RL |
11747 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11748 | NL80211_FLAG_NEED_RTNL, | |
11749 | }, | |
dfb89c56 | 11750 | #ifdef CONFIG_PM |
ff1b6e69 JB |
11751 | { |
11752 | .cmd = NL80211_CMD_GET_WOWLAN, | |
11753 | .doit = nl80211_get_wowlan, | |
11754 | .policy = nl80211_policy, | |
11755 | /* can be retrieved by unprivileged users */ | |
11756 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
11757 | NL80211_FLAG_NEED_RTNL, | |
11758 | }, | |
11759 | { | |
11760 | .cmd = NL80211_CMD_SET_WOWLAN, | |
11761 | .doit = nl80211_set_wowlan, | |
11762 | .policy = nl80211_policy, | |
5617c6cd | 11763 | .flags = GENL_UNS_ADMIN_PERM, |
ff1b6e69 JB |
11764 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11765 | NL80211_FLAG_NEED_RTNL, | |
11766 | }, | |
dfb89c56 | 11767 | #endif |
e5497d76 JB |
11768 | { |
11769 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
11770 | .doit = nl80211_set_rekey_data, | |
11771 | .policy = nl80211_policy, | |
5617c6cd | 11772 | .flags = GENL_UNS_ADMIN_PERM, |
e5497d76 | 11773 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
11774 | NL80211_FLAG_NEED_RTNL | |
11775 | NL80211_FLAG_CLEAR_SKB, | |
e5497d76 | 11776 | }, |
109086ce AN |
11777 | { |
11778 | .cmd = NL80211_CMD_TDLS_MGMT, | |
11779 | .doit = nl80211_tdls_mgmt, | |
11780 | .policy = nl80211_policy, | |
5617c6cd | 11781 | .flags = GENL_UNS_ADMIN_PERM, |
109086ce AN |
11782 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11783 | NL80211_FLAG_NEED_RTNL, | |
11784 | }, | |
11785 | { | |
11786 | .cmd = NL80211_CMD_TDLS_OPER, | |
11787 | .doit = nl80211_tdls_oper, | |
11788 | .policy = nl80211_policy, | |
5617c6cd | 11789 | .flags = GENL_UNS_ADMIN_PERM, |
109086ce AN |
11790 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11791 | NL80211_FLAG_NEED_RTNL, | |
11792 | }, | |
28946da7 JB |
11793 | { |
11794 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
11795 | .doit = nl80211_register_unexpected_frame, | |
11796 | .policy = nl80211_policy, | |
5617c6cd | 11797 | .flags = GENL_UNS_ADMIN_PERM, |
28946da7 JB |
11798 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11799 | NL80211_FLAG_NEED_RTNL, | |
11800 | }, | |
7f6cf311 JB |
11801 | { |
11802 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
11803 | .doit = nl80211_probe_client, | |
11804 | .policy = nl80211_policy, | |
5617c6cd | 11805 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11806 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
11807 | NL80211_FLAG_NEED_RTNL, |
11808 | }, | |
5e760230 JB |
11809 | { |
11810 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
11811 | .doit = nl80211_register_beacons, | |
11812 | .policy = nl80211_policy, | |
5617c6cd | 11813 | .flags = GENL_UNS_ADMIN_PERM, |
5e760230 JB |
11814 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11815 | NL80211_FLAG_NEED_RTNL, | |
11816 | }, | |
1d9d9213 SW |
11817 | { |
11818 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
11819 | .doit = nl80211_set_noack_map, | |
11820 | .policy = nl80211_policy, | |
5617c6cd | 11821 | .flags = GENL_UNS_ADMIN_PERM, |
1d9d9213 SW |
11822 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11823 | NL80211_FLAG_NEED_RTNL, | |
11824 | }, | |
98104fde JB |
11825 | { |
11826 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
11827 | .doit = nl80211_start_p2p_device, | |
11828 | .policy = nl80211_policy, | |
5617c6cd | 11829 | .flags = GENL_UNS_ADMIN_PERM, |
98104fde JB |
11830 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
11831 | NL80211_FLAG_NEED_RTNL, | |
11832 | }, | |
11833 | { | |
11834 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
11835 | .doit = nl80211_stop_p2p_device, | |
11836 | .policy = nl80211_policy, | |
5617c6cd | 11837 | .flags = GENL_UNS_ADMIN_PERM, |
98104fde JB |
11838 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
11839 | NL80211_FLAG_NEED_RTNL, | |
11840 | }, | |
f4e583c8 AQ |
11841 | { |
11842 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
11843 | .doit = nl80211_set_mcast_rate, | |
77765eaf | 11844 | .policy = nl80211_policy, |
5617c6cd | 11845 | .flags = GENL_UNS_ADMIN_PERM, |
77765eaf VT |
11846 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11847 | NL80211_FLAG_NEED_RTNL, | |
11848 | }, | |
11849 | { | |
11850 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
11851 | .doit = nl80211_set_mac_acl, | |
f4e583c8 | 11852 | .policy = nl80211_policy, |
5617c6cd | 11853 | .flags = GENL_UNS_ADMIN_PERM, |
f4e583c8 AQ |
11854 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11855 | NL80211_FLAG_NEED_RTNL, | |
11856 | }, | |
04f39047 SW |
11857 | { |
11858 | .cmd = NL80211_CMD_RADAR_DETECT, | |
11859 | .doit = nl80211_start_radar_detection, | |
11860 | .policy = nl80211_policy, | |
5617c6cd | 11861 | .flags = GENL_UNS_ADMIN_PERM, |
04f39047 SW |
11862 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11863 | NL80211_FLAG_NEED_RTNL, | |
11864 | }, | |
3713b4e3 JB |
11865 | { |
11866 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
11867 | .doit = nl80211_get_protocol_features, | |
11868 | .policy = nl80211_policy, | |
11869 | }, | |
355199e0 JM |
11870 | { |
11871 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
11872 | .doit = nl80211_update_ft_ies, | |
11873 | .policy = nl80211_policy, | |
5617c6cd | 11874 | .flags = GENL_UNS_ADMIN_PERM, |
355199e0 JM |
11875 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11876 | NL80211_FLAG_NEED_RTNL, | |
11877 | }, | |
5de17984 AS |
11878 | { |
11879 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
11880 | .doit = nl80211_crit_protocol_start, | |
11881 | .policy = nl80211_policy, | |
5617c6cd | 11882 | .flags = GENL_UNS_ADMIN_PERM, |
5de17984 AS |
11883 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
11884 | NL80211_FLAG_NEED_RTNL, | |
11885 | }, | |
11886 | { | |
11887 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
11888 | .doit = nl80211_crit_protocol_stop, | |
11889 | .policy = nl80211_policy, | |
5617c6cd | 11890 | .flags = GENL_UNS_ADMIN_PERM, |
5de17984 AS |
11891 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
11892 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
11893 | }, |
11894 | { | |
11895 | .cmd = NL80211_CMD_GET_COALESCE, | |
11896 | .doit = nl80211_get_coalesce, | |
11897 | .policy = nl80211_policy, | |
11898 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
11899 | NL80211_FLAG_NEED_RTNL, | |
11900 | }, | |
11901 | { | |
11902 | .cmd = NL80211_CMD_SET_COALESCE, | |
11903 | .doit = nl80211_set_coalesce, | |
11904 | .policy = nl80211_policy, | |
5617c6cd | 11905 | .flags = GENL_UNS_ADMIN_PERM, |
be29b99a AK |
11906 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11907 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
11908 | }, |
11909 | { | |
11910 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
11911 | .doit = nl80211_channel_switch, | |
11912 | .policy = nl80211_policy, | |
5617c6cd | 11913 | .flags = GENL_UNS_ADMIN_PERM, |
16ef1fe2 SW |
11914 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11915 | NL80211_FLAG_NEED_RTNL, | |
11916 | }, | |
ad7e718c JB |
11917 | { |
11918 | .cmd = NL80211_CMD_VENDOR, | |
11919 | .doit = nl80211_vendor_cmd, | |
7bdbe400 | 11920 | .dumpit = nl80211_vendor_cmd_dump, |
ad7e718c | 11921 | .policy = nl80211_policy, |
5617c6cd | 11922 | .flags = GENL_UNS_ADMIN_PERM, |
ad7e718c JB |
11923 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11924 | NL80211_FLAG_NEED_RTNL, | |
11925 | }, | |
fa9ffc74 KP |
11926 | { |
11927 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
11928 | .doit = nl80211_set_qos_map, | |
11929 | .policy = nl80211_policy, | |
5617c6cd | 11930 | .flags = GENL_UNS_ADMIN_PERM, |
fa9ffc74 KP |
11931 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11932 | NL80211_FLAG_NEED_RTNL, | |
11933 | }, | |
960d01ac JB |
11934 | { |
11935 | .cmd = NL80211_CMD_ADD_TX_TS, | |
11936 | .doit = nl80211_add_tx_ts, | |
11937 | .policy = nl80211_policy, | |
5617c6cd | 11938 | .flags = GENL_UNS_ADMIN_PERM, |
960d01ac JB |
11939 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11940 | NL80211_FLAG_NEED_RTNL, | |
11941 | }, | |
11942 | { | |
11943 | .cmd = NL80211_CMD_DEL_TX_TS, | |
11944 | .doit = nl80211_del_tx_ts, | |
11945 | .policy = nl80211_policy, | |
5617c6cd | 11946 | .flags = GENL_UNS_ADMIN_PERM, |
960d01ac JB |
11947 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11948 | NL80211_FLAG_NEED_RTNL, | |
11949 | }, | |
1057d35e AN |
11950 | { |
11951 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | |
11952 | .doit = nl80211_tdls_channel_switch, | |
11953 | .policy = nl80211_policy, | |
5617c6cd | 11954 | .flags = GENL_UNS_ADMIN_PERM, |
1057d35e AN |
11955 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11956 | NL80211_FLAG_NEED_RTNL, | |
11957 | }, | |
11958 | { | |
11959 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | |
11960 | .doit = nl80211_tdls_cancel_channel_switch, | |
11961 | .policy = nl80211_policy, | |
5617c6cd | 11962 | .flags = GENL_UNS_ADMIN_PERM, |
1057d35e AN |
11963 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11964 | NL80211_FLAG_NEED_RTNL, | |
11965 | }, | |
55682965 | 11966 | }; |
9588bbd5 | 11967 | |
55682965 JB |
11968 | /* notification functions */ |
11969 | ||
3bb20556 JB |
11970 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
11971 | enum nl80211_commands cmd) | |
55682965 JB |
11972 | { |
11973 | struct sk_buff *msg; | |
86e8cf98 | 11974 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 11975 | |
3bb20556 JB |
11976 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
11977 | cmd != NL80211_CMD_DEL_WIPHY); | |
11978 | ||
fd2120ca | 11979 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
11980 | if (!msg) |
11981 | return; | |
11982 | ||
3bb20556 | 11983 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
11984 | nlmsg_free(msg); |
11985 | return; | |
11986 | } | |
11987 | ||
68eb5503 | 11988 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11989 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
11990 | } |
11991 | ||
896ff063 DK |
11992 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
11993 | struct wireless_dev *wdev, | |
11994 | enum nl80211_commands cmd) | |
11995 | { | |
11996 | struct sk_buff *msg; | |
11997 | ||
11998 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && | |
11999 | cmd != NL80211_CMD_DEL_INTERFACE); | |
12000 | ||
12001 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12002 | if (!msg) | |
12003 | return; | |
12004 | ||
12005 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, | |
12006 | cmd == NL80211_CMD_DEL_INTERFACE) < 0) { | |
12007 | nlmsg_free(msg); | |
12008 | return; | |
12009 | } | |
12010 | ||
12011 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | |
12012 | NL80211_MCGRP_CONFIG, GFP_KERNEL); | |
12013 | } | |
12014 | ||
362a415d JB |
12015 | static int nl80211_add_scan_req(struct sk_buff *msg, |
12016 | struct cfg80211_registered_device *rdev) | |
12017 | { | |
12018 | struct cfg80211_scan_request *req = rdev->scan_req; | |
12019 | struct nlattr *nest; | |
12020 | int i; | |
12021 | ||
12022 | if (WARN_ON(!req)) | |
12023 | return 0; | |
12024 | ||
12025 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
12026 | if (!nest) | |
12027 | goto nla_put_failure; | |
9360ffd1 DM |
12028 | for (i = 0; i < req->n_ssids; i++) { |
12029 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
12030 | goto nla_put_failure; | |
12031 | } | |
362a415d JB |
12032 | nla_nest_end(msg, nest); |
12033 | ||
12034 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
12035 | if (!nest) | |
12036 | goto nla_put_failure; | |
9360ffd1 DM |
12037 | for (i = 0; i < req->n_channels; i++) { |
12038 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
12039 | goto nla_put_failure; | |
12040 | } | |
362a415d JB |
12041 | nla_nest_end(msg, nest); |
12042 | ||
9360ffd1 DM |
12043 | if (req->ie && |
12044 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
12045 | goto nla_put_failure; | |
362a415d | 12046 | |
ae917c9f JB |
12047 | if (req->flags && |
12048 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
12049 | goto nla_put_failure; | |
ed473771 | 12050 | |
1d76250b AS |
12051 | if (req->info.scan_start_tsf && |
12052 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, | |
12053 | req->info.scan_start_tsf, NL80211_BSS_PAD) || | |
12054 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, | |
12055 | req->info.tsf_bssid))) | |
12056 | goto nla_put_failure; | |
12057 | ||
362a415d JB |
12058 | return 0; |
12059 | nla_put_failure: | |
12060 | return -ENOBUFS; | |
12061 | } | |
12062 | ||
a538e2d5 JB |
12063 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
12064 | struct cfg80211_registered_device *rdev, | |
fd014284 | 12065 | struct wireless_dev *wdev, |
15e47304 | 12066 | u32 portid, u32 seq, int flags, |
a538e2d5 | 12067 | u32 cmd) |
2a519311 JB |
12068 | { |
12069 | void *hdr; | |
12070 | ||
15e47304 | 12071 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
12072 | if (!hdr) |
12073 | return -1; | |
12074 | ||
9360ffd1 | 12075 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
12076 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
12077 | wdev->netdev->ifindex)) || | |
2dad624e ND |
12078 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
12079 | NL80211_ATTR_PAD)) | |
9360ffd1 | 12080 | goto nla_put_failure; |
2a519311 | 12081 | |
362a415d JB |
12082 | /* ignore errors and send incomplete event anyway */ |
12083 | nl80211_add_scan_req(msg, rdev); | |
2a519311 | 12084 | |
053c095a JB |
12085 | genlmsg_end(msg, hdr); |
12086 | return 0; | |
2a519311 JB |
12087 | |
12088 | nla_put_failure: | |
12089 | genlmsg_cancel(msg, hdr); | |
12090 | return -EMSGSIZE; | |
12091 | } | |
12092 | ||
807f8a8c LC |
12093 | static int |
12094 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
12095 | struct cfg80211_registered_device *rdev, | |
12096 | struct net_device *netdev, | |
15e47304 | 12097 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
12098 | { |
12099 | void *hdr; | |
12100 | ||
15e47304 | 12101 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
12102 | if (!hdr) |
12103 | return -1; | |
12104 | ||
9360ffd1 DM |
12105 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12106 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
12107 | goto nla_put_failure; | |
807f8a8c | 12108 | |
053c095a JB |
12109 | genlmsg_end(msg, hdr); |
12110 | return 0; | |
807f8a8c LC |
12111 | |
12112 | nla_put_failure: | |
12113 | genlmsg_cancel(msg, hdr); | |
12114 | return -EMSGSIZE; | |
12115 | } | |
12116 | ||
a538e2d5 | 12117 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 12118 | struct wireless_dev *wdev) |
a538e2d5 JB |
12119 | { |
12120 | struct sk_buff *msg; | |
12121 | ||
58050fce | 12122 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
12123 | if (!msg) |
12124 | return; | |
12125 | ||
fd014284 | 12126 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
12127 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
12128 | nlmsg_free(msg); | |
12129 | return; | |
12130 | } | |
12131 | ||
68eb5503 | 12132 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12133 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
12134 | } |
12135 | ||
f9d15d16 JB |
12136 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
12137 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
12138 | { |
12139 | struct sk_buff *msg; | |
12140 | ||
fd2120ca | 12141 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 12142 | if (!msg) |
f9d15d16 | 12143 | return NULL; |
2a519311 | 12144 | |
fd014284 | 12145 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
12146 | aborted ? NL80211_CMD_SCAN_ABORTED : |
12147 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 12148 | nlmsg_free(msg); |
f9d15d16 | 12149 | return NULL; |
2a519311 JB |
12150 | } |
12151 | ||
f9d15d16 | 12152 | return msg; |
2a519311 JB |
12153 | } |
12154 | ||
f9d15d16 JB |
12155 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
12156 | struct sk_buff *msg) | |
2a519311 | 12157 | { |
2a519311 JB |
12158 | if (!msg) |
12159 | return; | |
12160 | ||
68eb5503 | 12161 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12162 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
12163 | } |
12164 | ||
807f8a8c LC |
12165 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
12166 | struct net_device *netdev) | |
12167 | { | |
12168 | struct sk_buff *msg; | |
12169 | ||
12170 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12171 | if (!msg) | |
12172 | return; | |
12173 | ||
12174 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
12175 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
12176 | nlmsg_free(msg); | |
12177 | return; | |
12178 | } | |
12179 | ||
68eb5503 | 12180 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12181 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
12182 | } |
12183 | ||
12184 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
12185 | struct net_device *netdev, u32 cmd) | |
12186 | { | |
12187 | struct sk_buff *msg; | |
12188 | ||
58050fce | 12189 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
12190 | if (!msg) |
12191 | return; | |
12192 | ||
12193 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
12194 | nlmsg_free(msg); | |
12195 | return; | |
12196 | } | |
12197 | ||
68eb5503 | 12198 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12199 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
12200 | } |
12201 | ||
b0d7aa59 JD |
12202 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
12203 | struct regulatory_request *request) | |
73d54c9e | 12204 | { |
73d54c9e | 12205 | /* Userspace can always count this one always being set */ |
9360ffd1 DM |
12206 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
12207 | goto nla_put_failure; | |
12208 | ||
12209 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
12210 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
12211 | NL80211_REGDOM_TYPE_WORLD)) | |
12212 | goto nla_put_failure; | |
12213 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
12214 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
12215 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
12216 | goto nla_put_failure; | |
12217 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
12218 | request->intersect) { | |
12219 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
12220 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
12221 | goto nla_put_failure; | |
12222 | } else { | |
12223 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
12224 | NL80211_REGDOM_TYPE_COUNTRY) || | |
12225 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
12226 | request->alpha2)) | |
12227 | goto nla_put_failure; | |
12228 | } | |
12229 | ||
ad30ca2c AN |
12230 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
12231 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); | |
12232 | ||
12233 | if (wiphy && | |
12234 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | |
12235 | goto nla_put_failure; | |
1bdd716c AN |
12236 | |
12237 | if (wiphy && | |
12238 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | |
12239 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
12240 | goto nla_put_failure; | |
ad30ca2c | 12241 | } |
73d54c9e | 12242 | |
b0d7aa59 JD |
12243 | return true; |
12244 | ||
12245 | nla_put_failure: | |
12246 | return false; | |
12247 | } | |
12248 | ||
12249 | /* | |
12250 | * This can happen on global regulatory changes or device specific settings | |
12251 | * based on custom regulatory domains. | |
12252 | */ | |
12253 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, | |
12254 | struct regulatory_request *request) | |
12255 | { | |
12256 | struct sk_buff *msg; | |
12257 | void *hdr; | |
12258 | ||
12259 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12260 | if (!msg) | |
12261 | return; | |
12262 | ||
12263 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); | |
12264 | if (!hdr) { | |
12265 | nlmsg_free(msg); | |
12266 | return; | |
12267 | } | |
12268 | ||
12269 | if (nl80211_reg_change_event_fill(msg, request) == false) | |
12270 | goto nla_put_failure; | |
12271 | ||
3b7b72ee | 12272 | genlmsg_end(msg, hdr); |
73d54c9e | 12273 | |
bc43b28c | 12274 | rcu_read_lock(); |
68eb5503 | 12275 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 12276 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 12277 | rcu_read_unlock(); |
73d54c9e LR |
12278 | |
12279 | return; | |
12280 | ||
12281 | nla_put_failure: | |
12282 | genlmsg_cancel(msg, hdr); | |
12283 | nlmsg_free(msg); | |
12284 | } | |
12285 | ||
6039f6d2 JM |
12286 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
12287 | struct net_device *netdev, | |
12288 | const u8 *buf, size_t len, | |
b0b6aa2c EP |
12289 | enum nl80211_commands cmd, gfp_t gfp, |
12290 | int uapsd_queues) | |
6039f6d2 JM |
12291 | { |
12292 | struct sk_buff *msg; | |
12293 | void *hdr; | |
12294 | ||
e6d6e342 | 12295 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
12296 | if (!msg) |
12297 | return; | |
12298 | ||
12299 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
12300 | if (!hdr) { | |
12301 | nlmsg_free(msg); | |
12302 | return; | |
12303 | } | |
12304 | ||
9360ffd1 DM |
12305 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12306 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12307 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
12308 | goto nla_put_failure; | |
6039f6d2 | 12309 | |
b0b6aa2c EP |
12310 | if (uapsd_queues >= 0) { |
12311 | struct nlattr *nla_wmm = | |
12312 | nla_nest_start(msg, NL80211_ATTR_STA_WME); | |
12313 | if (!nla_wmm) | |
12314 | goto nla_put_failure; | |
12315 | ||
12316 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
12317 | uapsd_queues)) | |
12318 | goto nla_put_failure; | |
12319 | ||
12320 | nla_nest_end(msg, nla_wmm); | |
12321 | } | |
12322 | ||
3b7b72ee | 12323 | genlmsg_end(msg, hdr); |
6039f6d2 | 12324 | |
68eb5503 | 12325 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12326 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
12327 | return; |
12328 | ||
12329 | nla_put_failure: | |
12330 | genlmsg_cancel(msg, hdr); | |
12331 | nlmsg_free(msg); | |
12332 | } | |
12333 | ||
12334 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
12335 | struct net_device *netdev, const u8 *buf, |
12336 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
12337 | { |
12338 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 12339 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
6039f6d2 JM |
12340 | } |
12341 | ||
12342 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
12343 | struct net_device *netdev, const u8 *buf, | |
b0b6aa2c | 12344 | size_t len, gfp_t gfp, int uapsd_queues) |
6039f6d2 | 12345 | { |
e6d6e342 | 12346 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
b0b6aa2c | 12347 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
6039f6d2 JM |
12348 | } |
12349 | ||
53b46b84 | 12350 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
12351 | struct net_device *netdev, const u8 *buf, |
12352 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
12353 | { |
12354 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 12355 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
6039f6d2 JM |
12356 | } |
12357 | ||
53b46b84 JM |
12358 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
12359 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 12360 | size_t len, gfp_t gfp) |
6039f6d2 JM |
12361 | { |
12362 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 12363 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
6039f6d2 JM |
12364 | } |
12365 | ||
6ff57cf8 JB |
12366 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
12367 | size_t len) | |
cf4e594e | 12368 | { |
947add36 JB |
12369 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
12370 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12371 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
12372 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
12373 | u32 cmd; | |
947add36 | 12374 | |
6ff57cf8 JB |
12375 | if (WARN_ON(len < 2)) |
12376 | return; | |
cf4e594e | 12377 | |
6ff57cf8 JB |
12378 | if (ieee80211_is_deauth(mgmt->frame_control)) |
12379 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
12380 | else | |
12381 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 12382 | |
6ff57cf8 | 12383 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
b0b6aa2c | 12384 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
cf4e594e | 12385 | } |
6ff57cf8 | 12386 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 12387 | |
1b06bb40 LR |
12388 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
12389 | struct net_device *netdev, int cmd, | |
e6d6e342 | 12390 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
12391 | { |
12392 | struct sk_buff *msg; | |
12393 | void *hdr; | |
12394 | ||
e6d6e342 | 12395 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
12396 | if (!msg) |
12397 | return; | |
12398 | ||
12399 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
12400 | if (!hdr) { | |
12401 | nlmsg_free(msg); | |
12402 | return; | |
12403 | } | |
12404 | ||
9360ffd1 DM |
12405 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12406 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12407 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
12408 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
12409 | goto nla_put_failure; | |
1965c853 | 12410 | |
3b7b72ee | 12411 | genlmsg_end(msg, hdr); |
1965c853 | 12412 | |
68eb5503 | 12413 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12414 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
12415 | return; |
12416 | ||
12417 | nla_put_failure: | |
12418 | genlmsg_cancel(msg, hdr); | |
12419 | nlmsg_free(msg); | |
12420 | } | |
12421 | ||
12422 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
12423 | struct net_device *netdev, const u8 *addr, |
12424 | gfp_t gfp) | |
1965c853 JM |
12425 | { |
12426 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 12427 | addr, gfp); |
1965c853 JM |
12428 | } |
12429 | ||
12430 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
12431 | struct net_device *netdev, const u8 *addr, |
12432 | gfp_t gfp) | |
1965c853 | 12433 | { |
e6d6e342 JB |
12434 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
12435 | addr, gfp); | |
1965c853 JM |
12436 | } |
12437 | ||
b23aa676 SO |
12438 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
12439 | struct net_device *netdev, const u8 *bssid, | |
12440 | const u8 *req_ie, size_t req_ie_len, | |
12441 | const u8 *resp_ie, size_t resp_ie_len, | |
bf1ecd21 | 12442 | int status, gfp_t gfp) |
b23aa676 SO |
12443 | { |
12444 | struct sk_buff *msg; | |
12445 | void *hdr; | |
12446 | ||
58050fce | 12447 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
12448 | if (!msg) |
12449 | return; | |
12450 | ||
12451 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
12452 | if (!hdr) { | |
12453 | nlmsg_free(msg); | |
12454 | return; | |
12455 | } | |
12456 | ||
9360ffd1 DM |
12457 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12458 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12459 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
bf1ecd21 JM |
12460 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
12461 | status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : | |
12462 | status) || | |
12463 | (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) || | |
9360ffd1 DM |
12464 | (req_ie && |
12465 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
12466 | (resp_ie && | |
12467 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
12468 | goto nla_put_failure; | |
b23aa676 | 12469 | |
3b7b72ee | 12470 | genlmsg_end(msg, hdr); |
b23aa676 | 12471 | |
68eb5503 | 12472 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12473 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
12474 | return; |
12475 | ||
12476 | nla_put_failure: | |
12477 | genlmsg_cancel(msg, hdr); | |
12478 | nlmsg_free(msg); | |
b23aa676 SO |
12479 | } |
12480 | ||
12481 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
12482 | struct net_device *netdev, const u8 *bssid, | |
12483 | const u8 *req_ie, size_t req_ie_len, | |
12484 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
12485 | { | |
12486 | struct sk_buff *msg; | |
12487 | void *hdr; | |
12488 | ||
58050fce | 12489 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
12490 | if (!msg) |
12491 | return; | |
12492 | ||
12493 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
12494 | if (!hdr) { | |
12495 | nlmsg_free(msg); | |
12496 | return; | |
12497 | } | |
12498 | ||
9360ffd1 DM |
12499 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12500 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12501 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
12502 | (req_ie && | |
12503 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
12504 | (resp_ie && | |
12505 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
12506 | goto nla_put_failure; | |
b23aa676 | 12507 | |
3b7b72ee | 12508 | genlmsg_end(msg, hdr); |
b23aa676 | 12509 | |
68eb5503 | 12510 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12511 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
12512 | return; |
12513 | ||
12514 | nla_put_failure: | |
12515 | genlmsg_cancel(msg, hdr); | |
12516 | nlmsg_free(msg); | |
b23aa676 SO |
12517 | } |
12518 | ||
12519 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
12520 | struct net_device *netdev, u16 reason, | |
667503dd | 12521 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
12522 | { |
12523 | struct sk_buff *msg; | |
12524 | void *hdr; | |
12525 | ||
58050fce | 12526 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
12527 | if (!msg) |
12528 | return; | |
12529 | ||
12530 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
12531 | if (!hdr) { | |
12532 | nlmsg_free(msg); | |
12533 | return; | |
12534 | } | |
12535 | ||
9360ffd1 DM |
12536 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12537 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12538 | (from_ap && reason && | |
12539 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
12540 | (from_ap && | |
12541 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
12542 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
12543 | goto nla_put_failure; | |
b23aa676 | 12544 | |
3b7b72ee | 12545 | genlmsg_end(msg, hdr); |
b23aa676 | 12546 | |
68eb5503 | 12547 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12548 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
12549 | return; |
12550 | ||
12551 | nla_put_failure: | |
12552 | genlmsg_cancel(msg, hdr); | |
12553 | nlmsg_free(msg); | |
b23aa676 SO |
12554 | } |
12555 | ||
04a773ad JB |
12556 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
12557 | struct net_device *netdev, const u8 *bssid, | |
12558 | gfp_t gfp) | |
12559 | { | |
12560 | struct sk_buff *msg; | |
12561 | void *hdr; | |
12562 | ||
fd2120ca | 12563 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
12564 | if (!msg) |
12565 | return; | |
12566 | ||
12567 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
12568 | if (!hdr) { | |
12569 | nlmsg_free(msg); | |
12570 | return; | |
12571 | } | |
12572 | ||
9360ffd1 DM |
12573 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12574 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12575 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
12576 | goto nla_put_failure; | |
04a773ad | 12577 | |
3b7b72ee | 12578 | genlmsg_end(msg, hdr); |
04a773ad | 12579 | |
68eb5503 | 12580 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12581 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
12582 | return; |
12583 | ||
12584 | nla_put_failure: | |
12585 | genlmsg_cancel(msg, hdr); | |
12586 | nlmsg_free(msg); | |
12587 | } | |
12588 | ||
947add36 JB |
12589 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
12590 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 12591 | { |
947add36 | 12592 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 12593 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
12594 | struct sk_buff *msg; |
12595 | void *hdr; | |
12596 | ||
947add36 JB |
12597 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
12598 | return; | |
12599 | ||
12600 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
12601 | ||
c93b5e71 JC |
12602 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
12603 | if (!msg) | |
12604 | return; | |
12605 | ||
12606 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
12607 | if (!hdr) { | |
12608 | nlmsg_free(msg); | |
12609 | return; | |
12610 | } | |
12611 | ||
9360ffd1 | 12612 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
12613 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
12614 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
12615 | (ie_len && ie && |
12616 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
12617 | goto nla_put_failure; | |
c93b5e71 | 12618 | |
3b7b72ee | 12619 | genlmsg_end(msg, hdr); |
c93b5e71 | 12620 | |
68eb5503 | 12621 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12622 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
12623 | return; |
12624 | ||
12625 | nla_put_failure: | |
12626 | genlmsg_cancel(msg, hdr); | |
12627 | nlmsg_free(msg); | |
12628 | } | |
947add36 | 12629 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 12630 | |
a3b8b056 JM |
12631 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
12632 | struct net_device *netdev, const u8 *addr, | |
12633 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 12634 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
12635 | { |
12636 | struct sk_buff *msg; | |
12637 | void *hdr; | |
12638 | ||
e6d6e342 | 12639 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
12640 | if (!msg) |
12641 | return; | |
12642 | ||
12643 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
12644 | if (!hdr) { | |
12645 | nlmsg_free(msg); | |
12646 | return; | |
12647 | } | |
12648 | ||
9360ffd1 DM |
12649 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12650 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12651 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
12652 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
12653 | (key_id != -1 && | |
12654 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
12655 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
12656 | goto nla_put_failure; | |
a3b8b056 | 12657 | |
3b7b72ee | 12658 | genlmsg_end(msg, hdr); |
a3b8b056 | 12659 | |
68eb5503 | 12660 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12661 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
12662 | return; |
12663 | ||
12664 | nla_put_failure: | |
12665 | genlmsg_cancel(msg, hdr); | |
12666 | nlmsg_free(msg); | |
12667 | } | |
12668 | ||
6bad8766 LR |
12669 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
12670 | struct ieee80211_channel *channel_before, | |
12671 | struct ieee80211_channel *channel_after) | |
12672 | { | |
12673 | struct sk_buff *msg; | |
12674 | void *hdr; | |
12675 | struct nlattr *nl_freq; | |
12676 | ||
fd2120ca | 12677 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
12678 | if (!msg) |
12679 | return; | |
12680 | ||
12681 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
12682 | if (!hdr) { | |
12683 | nlmsg_free(msg); | |
12684 | return; | |
12685 | } | |
12686 | ||
12687 | /* | |
12688 | * Since we are applying the beacon hint to a wiphy we know its | |
12689 | * wiphy_idx is valid | |
12690 | */ | |
9360ffd1 DM |
12691 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
12692 | goto nla_put_failure; | |
6bad8766 LR |
12693 | |
12694 | /* Before */ | |
12695 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
12696 | if (!nl_freq) | |
12697 | goto nla_put_failure; | |
cdc89b97 | 12698 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
12699 | goto nla_put_failure; |
12700 | nla_nest_end(msg, nl_freq); | |
12701 | ||
12702 | /* After */ | |
12703 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
12704 | if (!nl_freq) | |
12705 | goto nla_put_failure; | |
cdc89b97 | 12706 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
12707 | goto nla_put_failure; |
12708 | nla_nest_end(msg, nl_freq); | |
12709 | ||
3b7b72ee | 12710 | genlmsg_end(msg, hdr); |
6bad8766 | 12711 | |
463d0183 | 12712 | rcu_read_lock(); |
68eb5503 | 12713 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 12714 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 12715 | rcu_read_unlock(); |
6bad8766 LR |
12716 | |
12717 | return; | |
12718 | ||
12719 | nla_put_failure: | |
12720 | genlmsg_cancel(msg, hdr); | |
12721 | nlmsg_free(msg); | |
12722 | } | |
12723 | ||
9588bbd5 JM |
12724 | static void nl80211_send_remain_on_chan_event( |
12725 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 12726 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 12727 | struct ieee80211_channel *chan, |
9588bbd5 JM |
12728 | unsigned int duration, gfp_t gfp) |
12729 | { | |
12730 | struct sk_buff *msg; | |
12731 | void *hdr; | |
12732 | ||
12733 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12734 | if (!msg) | |
12735 | return; | |
12736 | ||
12737 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
12738 | if (!hdr) { | |
12739 | nlmsg_free(msg); | |
12740 | return; | |
12741 | } | |
12742 | ||
9360ffd1 | 12743 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
12744 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
12745 | wdev->netdev->ifindex)) || | |
2dad624e ND |
12746 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
12747 | NL80211_ATTR_PAD) || | |
9360ffd1 | 12748 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
12749 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
12750 | NL80211_CHAN_NO_HT) || | |
2dad624e ND |
12751 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
12752 | NL80211_ATTR_PAD)) | |
9360ffd1 | 12753 | goto nla_put_failure; |
9588bbd5 | 12754 | |
9360ffd1 DM |
12755 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
12756 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
12757 | goto nla_put_failure; | |
9588bbd5 | 12758 | |
3b7b72ee | 12759 | genlmsg_end(msg, hdr); |
9588bbd5 | 12760 | |
68eb5503 | 12761 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12762 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
12763 | return; |
12764 | ||
12765 | nla_put_failure: | |
12766 | genlmsg_cancel(msg, hdr); | |
12767 | nlmsg_free(msg); | |
12768 | } | |
12769 | ||
947add36 JB |
12770 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
12771 | struct ieee80211_channel *chan, | |
12772 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 12773 | { |
947add36 | 12774 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 12775 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12776 | |
12777 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 12778 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 12779 | rdev, wdev, cookie, chan, |
42d97a59 | 12780 | duration, gfp); |
9588bbd5 | 12781 | } |
947add36 | 12782 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 12783 | |
947add36 JB |
12784 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
12785 | struct ieee80211_channel *chan, | |
12786 | gfp_t gfp) | |
9588bbd5 | 12787 | { |
947add36 | 12788 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 12789 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12790 | |
12791 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 12792 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 12793 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 12794 | } |
947add36 | 12795 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 12796 | |
947add36 JB |
12797 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
12798 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 12799 | { |
947add36 | 12800 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 12801 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
12802 | struct sk_buff *msg; |
12803 | ||
947add36 JB |
12804 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
12805 | ||
58050fce | 12806 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
12807 | if (!msg) |
12808 | return; | |
12809 | ||
cf5ead82 | 12810 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
66266b3a | 12811 | rdev, dev, mac_addr, sinfo) < 0) { |
98b62183 JB |
12812 | nlmsg_free(msg); |
12813 | return; | |
12814 | } | |
12815 | ||
68eb5503 | 12816 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12817 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 12818 | } |
947add36 | 12819 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 12820 | |
cf5ead82 JB |
12821 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
12822 | struct station_info *sinfo, gfp_t gfp) | |
ec15e68b | 12823 | { |
947add36 | 12824 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 12825 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b | 12826 | struct sk_buff *msg; |
cf5ead82 JB |
12827 | struct station_info empty_sinfo = {}; |
12828 | ||
12829 | if (!sinfo) | |
12830 | sinfo = &empty_sinfo; | |
ec15e68b | 12831 | |
947add36 JB |
12832 | trace_cfg80211_del_sta(dev, mac_addr); |
12833 | ||
58050fce | 12834 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
12835 | if (!msg) |
12836 | return; | |
12837 | ||
cf5ead82 | 12838 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
57007121 | 12839 | rdev, dev, mac_addr, sinfo) < 0) { |
ec15e68b JM |
12840 | nlmsg_free(msg); |
12841 | return; | |
12842 | } | |
12843 | ||
68eb5503 | 12844 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12845 | NL80211_MCGRP_MLME, gfp); |
ec15e68b | 12846 | } |
cf5ead82 | 12847 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
ec15e68b | 12848 | |
947add36 JB |
12849 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
12850 | enum nl80211_connect_failed_reason reason, | |
12851 | gfp_t gfp) | |
ed44a951 | 12852 | { |
947add36 | 12853 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 12854 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
12855 | struct sk_buff *msg; |
12856 | void *hdr; | |
12857 | ||
12858 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
12859 | if (!msg) | |
12860 | return; | |
12861 | ||
12862 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
12863 | if (!hdr) { | |
12864 | nlmsg_free(msg); | |
12865 | return; | |
12866 | } | |
12867 | ||
12868 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12869 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
12870 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
12871 | goto nla_put_failure; | |
12872 | ||
12873 | genlmsg_end(msg, hdr); | |
12874 | ||
68eb5503 | 12875 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12876 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
12877 | return; |
12878 | ||
12879 | nla_put_failure: | |
12880 | genlmsg_cancel(msg, hdr); | |
12881 | nlmsg_free(msg); | |
12882 | } | |
947add36 | 12883 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 12884 | |
b92ab5d8 JB |
12885 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
12886 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
12887 | { |
12888 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12889 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
12890 | struct sk_buff *msg; |
12891 | void *hdr; | |
15e47304 | 12892 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 12893 | |
15e47304 | 12894 | if (!nlportid) |
28946da7 JB |
12895 | return false; |
12896 | ||
12897 | msg = nlmsg_new(100, gfp); | |
12898 | if (!msg) | |
12899 | return true; | |
12900 | ||
b92ab5d8 | 12901 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
12902 | if (!hdr) { |
12903 | nlmsg_free(msg); | |
12904 | return true; | |
12905 | } | |
12906 | ||
9360ffd1 DM |
12907 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12908 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12909 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
12910 | goto nla_put_failure; | |
28946da7 | 12911 | |
9c90a9f6 | 12912 | genlmsg_end(msg, hdr); |
15e47304 | 12913 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
12914 | return true; |
12915 | ||
12916 | nla_put_failure: | |
12917 | genlmsg_cancel(msg, hdr); | |
12918 | nlmsg_free(msg); | |
12919 | return true; | |
12920 | } | |
12921 | ||
947add36 JB |
12922 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
12923 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 12924 | { |
947add36 JB |
12925 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
12926 | bool ret; | |
12927 | ||
12928 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
12929 | ||
12930 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
12931 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
12932 | trace_cfg80211_return_bool(false); | |
12933 | return false; | |
12934 | } | |
12935 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
12936 | addr, gfp); | |
12937 | trace_cfg80211_return_bool(ret); | |
12938 | return ret; | |
b92ab5d8 | 12939 | } |
947add36 | 12940 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 12941 | |
947add36 JB |
12942 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
12943 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 12944 | { |
947add36 JB |
12945 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
12946 | bool ret; | |
12947 | ||
12948 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
12949 | ||
12950 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
12951 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
12952 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
12953 | trace_cfg80211_return_bool(false); | |
12954 | return false; | |
12955 | } | |
12956 | ret = __nl80211_unexpected_frame(dev, | |
12957 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
12958 | addr, gfp); | |
12959 | trace_cfg80211_return_bool(ret); | |
12960 | return ret; | |
b92ab5d8 | 12961 | } |
947add36 | 12962 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 12963 | |
2e161f78 | 12964 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 12965 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 12966 | int freq, int sig_dbm, |
19504cf5 | 12967 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 12968 | { |
71bbc994 | 12969 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
12970 | struct sk_buff *msg; |
12971 | void *hdr; | |
026331c4 JM |
12972 | |
12973 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12974 | if (!msg) | |
12975 | return -ENOMEM; | |
12976 | ||
2e161f78 | 12977 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
12978 | if (!hdr) { |
12979 | nlmsg_free(msg); | |
12980 | return -ENOMEM; | |
12981 | } | |
12982 | ||
9360ffd1 | 12983 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
12984 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
12985 | netdev->ifindex)) || | |
2dad624e ND |
12986 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
12987 | NL80211_ATTR_PAD) || | |
9360ffd1 DM |
12988 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
12989 | (sig_dbm && | |
12990 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
12991 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
12992 | (flags && | |
12993 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 12994 | goto nla_put_failure; |
026331c4 | 12995 | |
3b7b72ee | 12996 | genlmsg_end(msg, hdr); |
026331c4 | 12997 | |
15e47304 | 12998 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
12999 | |
13000 | nla_put_failure: | |
13001 | genlmsg_cancel(msg, hdr); | |
13002 | nlmsg_free(msg); | |
13003 | return -ENOBUFS; | |
13004 | } | |
13005 | ||
947add36 JB |
13006 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
13007 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 13008 | { |
947add36 | 13009 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 13010 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 13011 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
13012 | struct sk_buff *msg; |
13013 | void *hdr; | |
13014 | ||
947add36 JB |
13015 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
13016 | ||
026331c4 JM |
13017 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
13018 | if (!msg) | |
13019 | return; | |
13020 | ||
2e161f78 | 13021 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
13022 | if (!hdr) { |
13023 | nlmsg_free(msg); | |
13024 | return; | |
13025 | } | |
13026 | ||
9360ffd1 | 13027 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
13028 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
13029 | netdev->ifindex)) || | |
2dad624e ND |
13030 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
13031 | NL80211_ATTR_PAD) || | |
9360ffd1 | 13032 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
2dad624e ND |
13033 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
13034 | NL80211_ATTR_PAD) || | |
9360ffd1 DM |
13035 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
13036 | goto nla_put_failure; | |
026331c4 | 13037 | |
3b7b72ee | 13038 | genlmsg_end(msg, hdr); |
026331c4 | 13039 | |
68eb5503 | 13040 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13041 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
13042 | return; |
13043 | ||
13044 | nla_put_failure: | |
13045 | genlmsg_cancel(msg, hdr); | |
13046 | nlmsg_free(msg); | |
13047 | } | |
947add36 | 13048 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 13049 | |
5b97f49d JB |
13050 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
13051 | const char *mac, gfp_t gfp) | |
d6dc1a38 | 13052 | { |
947add36 | 13053 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5b97f49d JB |
13054 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
13055 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
13056 | void **cb; | |
947add36 | 13057 | |
d6dc1a38 | 13058 | if (!msg) |
5b97f49d | 13059 | return NULL; |
d6dc1a38 | 13060 | |
5b97f49d JB |
13061 | cb = (void **)msg->cb; |
13062 | ||
13063 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
13064 | if (!cb[0]) { | |
d6dc1a38 | 13065 | nlmsg_free(msg); |
5b97f49d | 13066 | return NULL; |
d6dc1a38 JO |
13067 | } |
13068 | ||
9360ffd1 | 13069 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 13070 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 13071 | goto nla_put_failure; |
d6dc1a38 | 13072 | |
5b97f49d | 13073 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
d6dc1a38 JO |
13074 | goto nla_put_failure; |
13075 | ||
5b97f49d JB |
13076 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
13077 | if (!cb[1]) | |
9360ffd1 | 13078 | goto nla_put_failure; |
d6dc1a38 | 13079 | |
5b97f49d | 13080 | cb[2] = rdev; |
d6dc1a38 | 13081 | |
5b97f49d JB |
13082 | return msg; |
13083 | nla_put_failure: | |
13084 | nlmsg_free(msg); | |
13085 | return NULL; | |
13086 | } | |
13087 | ||
13088 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) | |
13089 | { | |
13090 | void **cb = (void **)msg->cb; | |
13091 | struct cfg80211_registered_device *rdev = cb[2]; | |
13092 | ||
13093 | nla_nest_end(msg, cb[1]); | |
13094 | genlmsg_end(msg, cb[0]); | |
13095 | ||
13096 | memset(msg->cb, 0, sizeof(msg->cb)); | |
d6dc1a38 | 13097 | |
68eb5503 | 13098 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13099 | NL80211_MCGRP_MLME, gfp); |
5b97f49d JB |
13100 | } |
13101 | ||
13102 | void cfg80211_cqm_rssi_notify(struct net_device *dev, | |
13103 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
13104 | gfp_t gfp) | |
13105 | { | |
13106 | struct sk_buff *msg; | |
13107 | ||
13108 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); | |
13109 | ||
98f03342 JB |
13110 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
13111 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) | |
13112 | return; | |
13113 | ||
5b97f49d JB |
13114 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
13115 | if (!msg) | |
13116 | return; | |
13117 | ||
13118 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
13119 | rssi_event)) | |
13120 | goto nla_put_failure; | |
13121 | ||
13122 | cfg80211_send_cqm(msg, gfp); | |
13123 | ||
d6dc1a38 JO |
13124 | return; |
13125 | ||
13126 | nla_put_failure: | |
d6dc1a38 JO |
13127 | nlmsg_free(msg); |
13128 | } | |
947add36 | 13129 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 13130 | |
5b97f49d JB |
13131 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
13132 | const u8 *peer, u32 num_packets, | |
13133 | u32 rate, u32 intvl, gfp_t gfp) | |
13134 | { | |
13135 | struct sk_buff *msg; | |
13136 | ||
13137 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
13138 | if (!msg) | |
13139 | return; | |
13140 | ||
13141 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
13142 | goto nla_put_failure; | |
13143 | ||
13144 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
13145 | goto nla_put_failure; | |
13146 | ||
13147 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
13148 | goto nla_put_failure; | |
13149 | ||
13150 | cfg80211_send_cqm(msg, gfp); | |
13151 | return; | |
13152 | ||
13153 | nla_put_failure: | |
13154 | nlmsg_free(msg); | |
13155 | } | |
13156 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); | |
13157 | ||
13158 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, | |
13159 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
13160 | { | |
13161 | struct sk_buff *msg; | |
13162 | ||
13163 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); | |
13164 | ||
13165 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
13166 | if (!msg) | |
13167 | return; | |
13168 | ||
13169 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) | |
13170 | goto nla_put_failure; | |
13171 | ||
13172 | cfg80211_send_cqm(msg, gfp); | |
13173 | return; | |
13174 | ||
13175 | nla_put_failure: | |
13176 | nlmsg_free(msg); | |
13177 | } | |
13178 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); | |
13179 | ||
98f03342 JB |
13180 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
13181 | { | |
13182 | struct sk_buff *msg; | |
13183 | ||
13184 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); | |
13185 | if (!msg) | |
13186 | return; | |
13187 | ||
13188 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) | |
13189 | goto nla_put_failure; | |
13190 | ||
13191 | cfg80211_send_cqm(msg, gfp); | |
13192 | return; | |
13193 | ||
13194 | nla_put_failure: | |
13195 | nlmsg_free(msg); | |
13196 | } | |
13197 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); | |
13198 | ||
947add36 JB |
13199 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
13200 | struct net_device *netdev, const u8 *bssid, | |
13201 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
13202 | { |
13203 | struct sk_buff *msg; | |
13204 | struct nlattr *rekey_attr; | |
13205 | void *hdr; | |
13206 | ||
58050fce | 13207 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
13208 | if (!msg) |
13209 | return; | |
13210 | ||
13211 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
13212 | if (!hdr) { | |
13213 | nlmsg_free(msg); | |
13214 | return; | |
13215 | } | |
13216 | ||
9360ffd1 DM |
13217 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13218 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13219 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
13220 | goto nla_put_failure; | |
e5497d76 JB |
13221 | |
13222 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
13223 | if (!rekey_attr) | |
13224 | goto nla_put_failure; | |
13225 | ||
9360ffd1 DM |
13226 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
13227 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
13228 | goto nla_put_failure; | |
e5497d76 JB |
13229 | |
13230 | nla_nest_end(msg, rekey_attr); | |
13231 | ||
3b7b72ee | 13232 | genlmsg_end(msg, hdr); |
e5497d76 | 13233 | |
68eb5503 | 13234 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13235 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
13236 | return; |
13237 | ||
13238 | nla_put_failure: | |
13239 | genlmsg_cancel(msg, hdr); | |
13240 | nlmsg_free(msg); | |
13241 | } | |
13242 | ||
947add36 JB |
13243 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
13244 | const u8 *replay_ctr, gfp_t gfp) | |
13245 | { | |
13246 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13247 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 13248 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
13249 | |
13250 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
13251 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
13252 | } | |
13253 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
13254 | ||
13255 | static void | |
13256 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
13257 | struct net_device *netdev, int index, | |
13258 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
13259 | { |
13260 | struct sk_buff *msg; | |
13261 | struct nlattr *attr; | |
13262 | void *hdr; | |
13263 | ||
58050fce | 13264 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
13265 | if (!msg) |
13266 | return; | |
13267 | ||
13268 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
13269 | if (!hdr) { | |
13270 | nlmsg_free(msg); | |
13271 | return; | |
13272 | } | |
13273 | ||
9360ffd1 DM |
13274 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13275 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
13276 | goto nla_put_failure; | |
c9df56b4 JM |
13277 | |
13278 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
13279 | if (!attr) | |
13280 | goto nla_put_failure; | |
13281 | ||
9360ffd1 DM |
13282 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
13283 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
13284 | (preauth && | |
13285 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
13286 | goto nla_put_failure; | |
c9df56b4 JM |
13287 | |
13288 | nla_nest_end(msg, attr); | |
13289 | ||
3b7b72ee | 13290 | genlmsg_end(msg, hdr); |
c9df56b4 | 13291 | |
68eb5503 | 13292 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13293 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
13294 | return; |
13295 | ||
13296 | nla_put_failure: | |
13297 | genlmsg_cancel(msg, hdr); | |
13298 | nlmsg_free(msg); | |
13299 | } | |
13300 | ||
947add36 JB |
13301 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
13302 | const u8 *bssid, bool preauth, gfp_t gfp) | |
13303 | { | |
13304 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13305 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 13306 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
13307 | |
13308 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
13309 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
13310 | } | |
13311 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
13312 | ||
13313 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
13314 | struct net_device *netdev, | |
13315 | struct cfg80211_chan_def *chandef, | |
f8d7552e LC |
13316 | gfp_t gfp, |
13317 | enum nl80211_commands notif, | |
13318 | u8 count) | |
5314526b TP |
13319 | { |
13320 | struct sk_buff *msg; | |
13321 | void *hdr; | |
13322 | ||
58050fce | 13323 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
13324 | if (!msg) |
13325 | return; | |
13326 | ||
f8d7552e | 13327 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
5314526b TP |
13328 | if (!hdr) { |
13329 | nlmsg_free(msg); | |
13330 | return; | |
13331 | } | |
13332 | ||
683b6d3b JB |
13333 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
13334 | goto nla_put_failure; | |
13335 | ||
13336 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 13337 | goto nla_put_failure; |
5314526b | 13338 | |
f8d7552e LC |
13339 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
13340 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) | |
13341 | goto nla_put_failure; | |
13342 | ||
5314526b TP |
13343 | genlmsg_end(msg, hdr); |
13344 | ||
68eb5503 | 13345 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13346 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
13347 | return; |
13348 | ||
13349 | nla_put_failure: | |
13350 | genlmsg_cancel(msg, hdr); | |
13351 | nlmsg_free(msg); | |
13352 | } | |
13353 | ||
947add36 JB |
13354 | void cfg80211_ch_switch_notify(struct net_device *dev, |
13355 | struct cfg80211_chan_def *chandef) | |
84f10708 | 13356 | { |
947add36 JB |
13357 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
13358 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 13359 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 13360 | |
e487eaeb | 13361 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 13362 | |
e487eaeb | 13363 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 | 13364 | |
9e0e2961 | 13365 | wdev->chandef = *chandef; |
96f55f12 | 13366 | wdev->preset_chandef = *chandef; |
f8d7552e LC |
13367 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
13368 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); | |
947add36 JB |
13369 | } |
13370 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
13371 | ||
f8d7552e LC |
13372 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
13373 | struct cfg80211_chan_def *chandef, | |
13374 | u8 count) | |
13375 | { | |
13376 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13377 | struct wiphy *wiphy = wdev->wiphy; | |
13378 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
13379 | ||
13380 | trace_cfg80211_ch_switch_started_notify(dev, chandef); | |
13381 | ||
13382 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | |
13383 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); | |
13384 | } | |
13385 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | |
13386 | ||
04f39047 SW |
13387 | void |
13388 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 13389 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
13390 | enum nl80211_radar_event event, |
13391 | struct net_device *netdev, gfp_t gfp) | |
13392 | { | |
13393 | struct sk_buff *msg; | |
13394 | void *hdr; | |
13395 | ||
13396 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
13397 | if (!msg) | |
13398 | return; | |
13399 | ||
13400 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
13401 | if (!hdr) { | |
13402 | nlmsg_free(msg); | |
13403 | return; | |
13404 | } | |
13405 | ||
13406 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
13407 | goto nla_put_failure; | |
13408 | ||
13409 | /* NOP and radar events don't need a netdev parameter */ | |
13410 | if (netdev) { | |
13411 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
13412 | ||
13413 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
2dad624e ND |
13414 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
13415 | NL80211_ATTR_PAD)) | |
04f39047 SW |
13416 | goto nla_put_failure; |
13417 | } | |
13418 | ||
13419 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
13420 | goto nla_put_failure; | |
13421 | ||
13422 | if (nl80211_send_chandef(msg, chandef)) | |
13423 | goto nla_put_failure; | |
13424 | ||
9c90a9f6 | 13425 | genlmsg_end(msg, hdr); |
04f39047 | 13426 | |
68eb5503 | 13427 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13428 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
13429 | return; |
13430 | ||
13431 | nla_put_failure: | |
13432 | genlmsg_cancel(msg, hdr); | |
13433 | nlmsg_free(msg); | |
13434 | } | |
13435 | ||
7f6cf311 JB |
13436 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
13437 | u64 cookie, bool acked, gfp_t gfp) | |
13438 | { | |
13439 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 13440 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
13441 | struct sk_buff *msg; |
13442 | void *hdr; | |
7f6cf311 | 13443 | |
4ee3e063 BL |
13444 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
13445 | ||
58050fce | 13446 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 13447 | |
7f6cf311 JB |
13448 | if (!msg) |
13449 | return; | |
13450 | ||
13451 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
13452 | if (!hdr) { | |
13453 | nlmsg_free(msg); | |
13454 | return; | |
13455 | } | |
13456 | ||
9360ffd1 DM |
13457 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13458 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
13459 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
2dad624e ND |
13460 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
13461 | NL80211_ATTR_PAD) || | |
9360ffd1 DM |
13462 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
13463 | goto nla_put_failure; | |
7f6cf311 | 13464 | |
9c90a9f6 | 13465 | genlmsg_end(msg, hdr); |
7f6cf311 | 13466 | |
68eb5503 | 13467 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13468 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
13469 | return; |
13470 | ||
13471 | nla_put_failure: | |
13472 | genlmsg_cancel(msg, hdr); | |
13473 | nlmsg_free(msg); | |
13474 | } | |
13475 | EXPORT_SYMBOL(cfg80211_probe_status); | |
13476 | ||
5e760230 JB |
13477 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
13478 | const u8 *frame, size_t len, | |
37c73b5f | 13479 | int freq, int sig_dbm) |
5e760230 | 13480 | { |
f26cbf40 | 13481 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
13482 | struct sk_buff *msg; |
13483 | void *hdr; | |
37c73b5f | 13484 | struct cfg80211_beacon_registration *reg; |
5e760230 | 13485 | |
4ee3e063 BL |
13486 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
13487 | ||
37c73b5f BG |
13488 | spin_lock_bh(&rdev->beacon_registrations_lock); |
13489 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
13490 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
13491 | if (!msg) { | |
13492 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
13493 | return; | |
13494 | } | |
5e760230 | 13495 | |
37c73b5f BG |
13496 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
13497 | if (!hdr) | |
13498 | goto nla_put_failure; | |
5e760230 | 13499 | |
37c73b5f BG |
13500 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13501 | (freq && | |
13502 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
13503 | (sig_dbm && | |
13504 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
13505 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
13506 | goto nla_put_failure; | |
5e760230 | 13507 | |
37c73b5f | 13508 | genlmsg_end(msg, hdr); |
5e760230 | 13509 | |
37c73b5f BG |
13510 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
13511 | } | |
13512 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
13513 | return; |
13514 | ||
13515 | nla_put_failure: | |
37c73b5f BG |
13516 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
13517 | if (hdr) | |
13518 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
13519 | nlmsg_free(msg); |
13520 | } | |
13521 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
13522 | ||
cd8f7cb4 | 13523 | #ifdef CONFIG_PM |
8cd4d456 LC |
13524 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
13525 | struct cfg80211_wowlan_wakeup *wakeup) | |
13526 | { | |
13527 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | |
13528 | struct nlattr *nl_results, *nl_match, *nl_freqs; | |
13529 | int i, j; | |
13530 | ||
13531 | nl_results = nla_nest_start( | |
13532 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | |
13533 | if (!nl_results) | |
13534 | return -EMSGSIZE; | |
13535 | ||
13536 | for (i = 0; i < nd->n_matches; i++) { | |
13537 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | |
13538 | ||
13539 | nl_match = nla_nest_start(msg, i); | |
13540 | if (!nl_match) | |
13541 | break; | |
13542 | ||
13543 | /* The SSID attribute is optional in nl80211, but for | |
13544 | * simplicity reasons it's always present in the | |
13545 | * cfg80211 structure. If a driver can't pass the | |
13546 | * SSID, that needs to be changed. A zero length SSID | |
13547 | * is still a valid SSID (wildcard), so it cannot be | |
13548 | * used for this purpose. | |
13549 | */ | |
13550 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | |
13551 | match->ssid.ssid)) { | |
13552 | nla_nest_cancel(msg, nl_match); | |
13553 | goto out; | |
13554 | } | |
13555 | ||
13556 | if (match->n_channels) { | |
13557 | nl_freqs = nla_nest_start( | |
13558 | msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
13559 | if (!nl_freqs) { | |
13560 | nla_nest_cancel(msg, nl_match); | |
13561 | goto out; | |
13562 | } | |
13563 | ||
13564 | for (j = 0; j < match->n_channels; j++) { | |
5528fae8 | 13565 | if (nla_put_u32(msg, j, match->channels[j])) { |
8cd4d456 LC |
13566 | nla_nest_cancel(msg, nl_freqs); |
13567 | nla_nest_cancel(msg, nl_match); | |
13568 | goto out; | |
13569 | } | |
13570 | } | |
13571 | ||
13572 | nla_nest_end(msg, nl_freqs); | |
13573 | } | |
13574 | ||
13575 | nla_nest_end(msg, nl_match); | |
13576 | } | |
13577 | ||
13578 | out: | |
13579 | nla_nest_end(msg, nl_results); | |
13580 | return 0; | |
13581 | } | |
13582 | ||
cd8f7cb4 JB |
13583 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
13584 | struct cfg80211_wowlan_wakeup *wakeup, | |
13585 | gfp_t gfp) | |
13586 | { | |
f26cbf40 | 13587 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
13588 | struct sk_buff *msg; |
13589 | void *hdr; | |
9c90a9f6 | 13590 | int size = 200; |
cd8f7cb4 JB |
13591 | |
13592 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
13593 | ||
13594 | if (wakeup) | |
13595 | size += wakeup->packet_present_len; | |
13596 | ||
13597 | msg = nlmsg_new(size, gfp); | |
13598 | if (!msg) | |
13599 | return; | |
13600 | ||
13601 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
13602 | if (!hdr) | |
13603 | goto free_msg; | |
13604 | ||
13605 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
13606 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
13607 | NL80211_ATTR_PAD)) | |
cd8f7cb4 JB |
13608 | goto free_msg; |
13609 | ||
13610 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
13611 | wdev->netdev->ifindex)) | |
13612 | goto free_msg; | |
13613 | ||
13614 | if (wakeup) { | |
13615 | struct nlattr *reasons; | |
13616 | ||
13617 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
13618 | if (!reasons) |
13619 | goto free_msg; | |
cd8f7cb4 JB |
13620 | |
13621 | if (wakeup->disconnect && | |
13622 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
13623 | goto free_msg; | |
13624 | if (wakeup->magic_pkt && | |
13625 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
13626 | goto free_msg; | |
13627 | if (wakeup->gtk_rekey_failure && | |
13628 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
13629 | goto free_msg; | |
13630 | if (wakeup->eap_identity_req && | |
13631 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
13632 | goto free_msg; | |
13633 | if (wakeup->four_way_handshake && | |
13634 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
13635 | goto free_msg; | |
13636 | if (wakeup->rfkill_release && | |
13637 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
13638 | goto free_msg; | |
13639 | ||
13640 | if (wakeup->pattern_idx >= 0 && | |
13641 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
13642 | wakeup->pattern_idx)) | |
13643 | goto free_msg; | |
13644 | ||
ae917c9f JB |
13645 | if (wakeup->tcp_match && |
13646 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
13647 | goto free_msg; | |
2a0e047e | 13648 | |
ae917c9f JB |
13649 | if (wakeup->tcp_connlost && |
13650 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
13651 | goto free_msg; | |
2a0e047e | 13652 | |
ae917c9f JB |
13653 | if (wakeup->tcp_nomoretokens && |
13654 | nla_put_flag(msg, | |
13655 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
13656 | goto free_msg; | |
2a0e047e | 13657 | |
cd8f7cb4 JB |
13658 | if (wakeup->packet) { |
13659 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
13660 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
13661 | ||
13662 | if (!wakeup->packet_80211) { | |
13663 | pkt_attr = | |
13664 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
13665 | len_attr = | |
13666 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
13667 | } | |
13668 | ||
13669 | if (wakeup->packet_len && | |
13670 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
13671 | goto free_msg; | |
13672 | ||
13673 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
13674 | wakeup->packet)) | |
13675 | goto free_msg; | |
13676 | } | |
13677 | ||
8cd4d456 LC |
13678 | if (wakeup->net_detect && |
13679 | cfg80211_net_detect_results(msg, wakeup)) | |
13680 | goto free_msg; | |
13681 | ||
cd8f7cb4 JB |
13682 | nla_nest_end(msg, reasons); |
13683 | } | |
13684 | ||
9c90a9f6 | 13685 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 13686 | |
68eb5503 | 13687 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13688 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
13689 | return; |
13690 | ||
13691 | free_msg: | |
13692 | nlmsg_free(msg); | |
13693 | } | |
13694 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
13695 | #endif | |
13696 | ||
3475b094 JM |
13697 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
13698 | enum nl80211_tdls_operation oper, | |
13699 | u16 reason_code, gfp_t gfp) | |
13700 | { | |
13701 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 13702 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
13703 | struct sk_buff *msg; |
13704 | void *hdr; | |
3475b094 JM |
13705 | |
13706 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
13707 | reason_code); | |
13708 | ||
13709 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
13710 | if (!msg) | |
13711 | return; | |
13712 | ||
13713 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
13714 | if (!hdr) { | |
13715 | nlmsg_free(msg); | |
13716 | return; | |
13717 | } | |
13718 | ||
13719 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
13720 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
13721 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
13722 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
13723 | (reason_code > 0 && | |
13724 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
13725 | goto nla_put_failure; | |
13726 | ||
9c90a9f6 | 13727 | genlmsg_end(msg, hdr); |
3475b094 | 13728 | |
68eb5503 | 13729 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13730 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
13731 | return; |
13732 | ||
13733 | nla_put_failure: | |
13734 | genlmsg_cancel(msg, hdr); | |
13735 | nlmsg_free(msg); | |
13736 | } | |
13737 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
13738 | ||
026331c4 JM |
13739 | static int nl80211_netlink_notify(struct notifier_block * nb, |
13740 | unsigned long state, | |
13741 | void *_notify) | |
13742 | { | |
13743 | struct netlink_notify *notify = _notify; | |
13744 | struct cfg80211_registered_device *rdev; | |
13745 | struct wireless_dev *wdev; | |
37c73b5f | 13746 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 | 13747 | |
8f815cdd | 13748 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
026331c4 JM |
13749 | return NOTIFY_DONE; |
13750 | ||
13751 | rcu_read_lock(); | |
13752 | ||
5e760230 | 13753 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
78f22b6a | 13754 | bool schedule_destroy_work = false; |
93a1e86c JR |
13755 | bool schedule_scan_stop = false; |
13756 | struct cfg80211_sched_scan_request *sched_scan_req = | |
13757 | rcu_dereference(rdev->sched_scan_req); | |
13758 | ||
13759 | if (sched_scan_req && notify->portid && | |
13760 | sched_scan_req->owner_nlportid == notify->portid) | |
13761 | schedule_scan_stop = true; | |
78f22b6a | 13762 | |
53873f13 | 13763 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
15e47304 | 13764 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 13765 | |
78f22b6a JB |
13766 | if (wdev->owner_nlportid == notify->portid) |
13767 | schedule_destroy_work = true; | |
13768 | } | |
13769 | ||
37c73b5f BG |
13770 | spin_lock_bh(&rdev->beacon_registrations_lock); |
13771 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
13772 | list) { | |
13773 | if (reg->nlportid == notify->portid) { | |
13774 | list_del(®->list); | |
13775 | kfree(reg); | |
13776 | break; | |
13777 | } | |
13778 | } | |
13779 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
78f22b6a JB |
13780 | |
13781 | if (schedule_destroy_work) { | |
13782 | struct cfg80211_iface_destroy *destroy; | |
13783 | ||
13784 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | |
13785 | if (destroy) { | |
13786 | destroy->nlportid = notify->portid; | |
13787 | spin_lock(&rdev->destroy_list_lock); | |
13788 | list_add(&destroy->list, &rdev->destroy_list); | |
13789 | spin_unlock(&rdev->destroy_list_lock); | |
13790 | schedule_work(&rdev->destroy_work); | |
13791 | } | |
93a1e86c JR |
13792 | } else if (schedule_scan_stop) { |
13793 | sched_scan_req->owner_nlportid = 0; | |
13794 | ||
13795 | if (rdev->ops->sched_scan_stop && | |
13796 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
13797 | schedule_work(&rdev->sched_scan_stop_wk); | |
78f22b6a | 13798 | } |
5e760230 | 13799 | } |
026331c4 JM |
13800 | |
13801 | rcu_read_unlock(); | |
13802 | ||
05050753 I |
13803 | /* |
13804 | * It is possible that the user space process that is controlling the | |
13805 | * indoor setting disappeared, so notify the regulatory core. | |
13806 | */ | |
13807 | regulatory_netlink_notify(notify->portid); | |
6784c7db | 13808 | return NOTIFY_OK; |
026331c4 JM |
13809 | } |
13810 | ||
13811 | static struct notifier_block nl80211_netlink_notifier = { | |
13812 | .notifier_call = nl80211_netlink_notify, | |
13813 | }; | |
13814 | ||
355199e0 JM |
13815 | void cfg80211_ft_event(struct net_device *netdev, |
13816 | struct cfg80211_ft_event_params *ft_event) | |
13817 | { | |
13818 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 13819 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
13820 | struct sk_buff *msg; |
13821 | void *hdr; | |
355199e0 JM |
13822 | |
13823 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
13824 | ||
13825 | if (!ft_event->target_ap) | |
13826 | return; | |
13827 | ||
13828 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
13829 | if (!msg) | |
13830 | return; | |
13831 | ||
13832 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
13833 | if (!hdr) |
13834 | goto out; | |
355199e0 | 13835 | |
ae917c9f JB |
13836 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13837 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13838 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
13839 | goto out; | |
355199e0 | 13840 | |
ae917c9f JB |
13841 | if (ft_event->ies && |
13842 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
13843 | goto out; | |
13844 | if (ft_event->ric_ies && | |
13845 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
13846 | ft_event->ric_ies)) | |
13847 | goto out; | |
355199e0 | 13848 | |
9c90a9f6 | 13849 | genlmsg_end(msg, hdr); |
355199e0 | 13850 | |
68eb5503 | 13851 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13852 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
13853 | return; |
13854 | out: | |
13855 | nlmsg_free(msg); | |
355199e0 JM |
13856 | } |
13857 | EXPORT_SYMBOL(cfg80211_ft_event); | |
13858 | ||
5de17984 AS |
13859 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
13860 | { | |
13861 | struct cfg80211_registered_device *rdev; | |
13862 | struct sk_buff *msg; | |
13863 | void *hdr; | |
13864 | u32 nlportid; | |
13865 | ||
f26cbf40 | 13866 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
13867 | if (!rdev->crit_proto_nlportid) |
13868 | return; | |
13869 | ||
13870 | nlportid = rdev->crit_proto_nlportid; | |
13871 | rdev->crit_proto_nlportid = 0; | |
13872 | ||
13873 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
13874 | if (!msg) | |
13875 | return; | |
13876 | ||
13877 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
13878 | if (!hdr) | |
13879 | goto nla_put_failure; | |
13880 | ||
13881 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
13882 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
13883 | NL80211_ATTR_PAD)) | |
5de17984 AS |
13884 | goto nla_put_failure; |
13885 | ||
13886 | genlmsg_end(msg, hdr); | |
13887 | ||
13888 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
13889 | return; | |
13890 | ||
13891 | nla_put_failure: | |
13892 | if (hdr) | |
13893 | genlmsg_cancel(msg, hdr); | |
13894 | nlmsg_free(msg); | |
5de17984 AS |
13895 | } |
13896 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
13897 | ||
348baf0e JB |
13898 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
13899 | { | |
13900 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 13901 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
13902 | struct sk_buff *msg; |
13903 | void *hdr; | |
13904 | ||
13905 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
13906 | if (!msg) | |
13907 | return; | |
13908 | ||
13909 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
13910 | if (!hdr) | |
13911 | goto out; | |
13912 | ||
13913 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
13914 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
2dad624e ND |
13915 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
13916 | NL80211_ATTR_PAD)) | |
348baf0e JB |
13917 | goto out; |
13918 | ||
13919 | genlmsg_end(msg, hdr); | |
13920 | ||
13921 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
13922 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
13923 | return; | |
13924 | out: | |
13925 | nlmsg_free(msg); | |
13926 | } | |
13927 | ||
55682965 JB |
13928 | /* initialisation/exit functions */ |
13929 | ||
13930 | int nl80211_init(void) | |
13931 | { | |
0d63cbb5 | 13932 | int err; |
55682965 | 13933 | |
2a94fe48 JB |
13934 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
13935 | nl80211_mcgrps); | |
55682965 JB |
13936 | if (err) |
13937 | return err; | |
13938 | ||
026331c4 JM |
13939 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
13940 | if (err) | |
13941 | goto err_out; | |
13942 | ||
55682965 JB |
13943 | return 0; |
13944 | err_out: | |
13945 | genl_unregister_family(&nl80211_fam); | |
13946 | return err; | |
13947 | } | |
13948 | ||
13949 | void nl80211_exit(void) | |
13950 | { | |
026331c4 | 13951 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
13952 | genl_unregister_family(&nl80211_fam); |
13953 | } |