]>
Commit | Line | Data |
---|---|---|
55682965 JB |
1 | /* |
2 | * This is the new netlink-based wireless configuration interface. | |
3 | * | |
026331c4 | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
2740f0cf | 5 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
55682965 JB |
6 | */ |
7 | ||
8 | #include <linux/if.h> | |
9 | #include <linux/module.h> | |
10 | #include <linux/err.h> | |
5a0e3ad6 | 11 | #include <linux/slab.h> |
55682965 JB |
12 | #include <linux/list.h> |
13 | #include <linux/if_ether.h> | |
14 | #include <linux/ieee80211.h> | |
15 | #include <linux/nl80211.h> | |
16 | #include <linux/rtnetlink.h> | |
17 | #include <linux/netlink.h> | |
2a519311 | 18 | #include <linux/etherdevice.h> |
463d0183 | 19 | #include <net/net_namespace.h> |
55682965 JB |
20 | #include <net/genetlink.h> |
21 | #include <net/cfg80211.h> | |
463d0183 | 22 | #include <net/sock.h> |
2a0e047e | 23 | #include <net/inet_connection_sock.h> |
55682965 JB |
24 | #include "core.h" |
25 | #include "nl80211.h" | |
b2e1b302 | 26 | #include "reg.h" |
e35e4d28 | 27 | #include "rdev-ops.h" |
55682965 | 28 | |
5fb628e9 JM |
29 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
30 | struct genl_info *info, | |
31 | struct cfg80211_crypto_settings *settings, | |
32 | int cipher_limit); | |
33 | ||
f84f771d | 34 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 | 35 | struct genl_info *info); |
f84f771d | 36 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
37 | struct genl_info *info); |
38 | ||
55682965 JB |
39 | /* the netlink family */ |
40 | static struct genl_family nl80211_fam = { | |
fb4e1568 MH |
41 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
42 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ | |
43 | .hdrsize = 0, /* no private header */ | |
44 | .version = 1, /* no particular meaning now */ | |
55682965 | 45 | .maxattr = NL80211_ATTR_MAX, |
463d0183 | 46 | .netnsok = true, |
4c476991 JB |
47 | .pre_doit = nl80211_pre_doit, |
48 | .post_doit = nl80211_post_doit, | |
55682965 JB |
49 | }; |
50 | ||
2a94fe48 JB |
51 | /* multicast groups */ |
52 | enum nl80211_multicast_groups { | |
53 | NL80211_MCGRP_CONFIG, | |
54 | NL80211_MCGRP_SCAN, | |
55 | NL80211_MCGRP_REGULATORY, | |
56 | NL80211_MCGRP_MLME, | |
567ffc35 | 57 | NL80211_MCGRP_VENDOR, |
2a94fe48 JB |
58 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
59 | }; | |
60 | ||
61 | static const struct genl_multicast_group nl80211_mcgrps[] = { | |
71b836ec JB |
62 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
63 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, | |
64 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, | |
65 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, | |
66 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, | |
2a94fe48 | 67 | #ifdef CONFIG_NL80211_TESTMODE |
71b836ec | 68 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
2a94fe48 JB |
69 | #endif |
70 | }; | |
71 | ||
89a54e48 JB |
72 | /* returns ERR_PTR values */ |
73 | static struct wireless_dev * | |
74 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 75 | { |
89a54e48 JB |
76 | struct cfg80211_registered_device *rdev; |
77 | struct wireless_dev *result = NULL; | |
78 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
79 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
80 | u64 wdev_id; | |
81 | int wiphy_idx = -1; | |
82 | int ifidx = -1; | |
55682965 | 83 | |
5fe231e8 | 84 | ASSERT_RTNL(); |
55682965 | 85 | |
89a54e48 JB |
86 | if (!have_ifidx && !have_wdev_id) |
87 | return ERR_PTR(-EINVAL); | |
55682965 | 88 | |
89a54e48 JB |
89 | if (have_ifidx) |
90 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
91 | if (have_wdev_id) { | |
92 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
93 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
94 | } |
95 | ||
89a54e48 JB |
96 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
97 | struct wireless_dev *wdev; | |
98 | ||
99 | if (wiphy_net(&rdev->wiphy) != netns) | |
100 | continue; | |
101 | ||
102 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
103 | continue; | |
104 | ||
89a54e48 JB |
105 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
106 | if (have_ifidx && wdev->netdev && | |
107 | wdev->netdev->ifindex == ifidx) { | |
108 | result = wdev; | |
109 | break; | |
110 | } | |
111 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
112 | result = wdev; | |
113 | break; | |
114 | } | |
115 | } | |
89a54e48 JB |
116 | |
117 | if (result) | |
118 | break; | |
119 | } | |
120 | ||
121 | if (result) | |
122 | return result; | |
123 | return ERR_PTR(-ENODEV); | |
55682965 JB |
124 | } |
125 | ||
a9455408 | 126 | static struct cfg80211_registered_device * |
878d9ec7 | 127 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 128 | { |
7fee4778 JB |
129 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
130 | struct net_device *netdev; | |
a9455408 | 131 | |
5fe231e8 | 132 | ASSERT_RTNL(); |
a9455408 | 133 | |
878d9ec7 | 134 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
135 | !attrs[NL80211_ATTR_IFINDEX] && |
136 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
137 | return ERR_PTR(-EINVAL); |
138 | ||
878d9ec7 | 139 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 140 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 141 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 142 | |
89a54e48 JB |
143 | if (attrs[NL80211_ATTR_WDEV]) { |
144 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
145 | struct wireless_dev *wdev; | |
146 | bool found = false; | |
147 | ||
148 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
149 | if (tmp) { | |
150 | /* make sure wdev exists */ | |
89a54e48 JB |
151 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
152 | if (wdev->identifier != (u32)wdev_id) | |
153 | continue; | |
154 | found = true; | |
155 | break; | |
156 | } | |
89a54e48 JB |
157 | |
158 | if (!found) | |
159 | tmp = NULL; | |
160 | ||
161 | if (rdev && tmp != rdev) | |
162 | return ERR_PTR(-EINVAL); | |
163 | rdev = tmp; | |
164 | } | |
165 | } | |
166 | ||
878d9ec7 JB |
167 | if (attrs[NL80211_ATTR_IFINDEX]) { |
168 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
7f2b8562 | 169 | netdev = __dev_get_by_index(netns, ifindex); |
7fee4778 JB |
170 | if (netdev) { |
171 | if (netdev->ieee80211_ptr) | |
f26cbf40 ZG |
172 | tmp = wiphy_to_rdev( |
173 | netdev->ieee80211_ptr->wiphy); | |
7fee4778 JB |
174 | else |
175 | tmp = NULL; | |
176 | ||
7fee4778 JB |
177 | /* not wireless device -- return error */ |
178 | if (!tmp) | |
179 | return ERR_PTR(-EINVAL); | |
180 | ||
181 | /* mismatch -- return error */ | |
182 | if (rdev && tmp != rdev) | |
183 | return ERR_PTR(-EINVAL); | |
184 | ||
185 | rdev = tmp; | |
a9455408 | 186 | } |
a9455408 | 187 | } |
a9455408 | 188 | |
4f7eff10 JB |
189 | if (!rdev) |
190 | return ERR_PTR(-ENODEV); | |
a9455408 | 191 | |
4f7eff10 JB |
192 | if (netns != wiphy_net(&rdev->wiphy)) |
193 | return ERR_PTR(-ENODEV); | |
194 | ||
195 | return rdev; | |
a9455408 JB |
196 | } |
197 | ||
198 | /* | |
199 | * This function returns a pointer to the driver | |
200 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
201 | * |
202 | * The result of this can be a PTR_ERR and hence must | |
203 | * be checked with IS_ERR() for errors. | |
204 | */ | |
205 | static struct cfg80211_registered_device * | |
4f7eff10 | 206 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 207 | { |
5fe231e8 | 208 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
209 | } |
210 | ||
55682965 | 211 | /* policy for the attributes */ |
8cd4d456 | 212 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
55682965 JB |
213 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
214 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 215 | .len = 20-1 }, |
31888487 | 216 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 217 | |
72bdcf34 | 218 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 219 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
220 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
221 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
222 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
223 | ||
b9a5f8ca JM |
224 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
225 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
226 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
227 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 228 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
3057dbfd | 229 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
55682965 JB |
230 | |
231 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
232 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
233 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 234 | |
e007b857 EP |
235 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
236 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 237 | |
b9454e83 | 238 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
239 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
240 | .len = WLAN_MAX_KEY_LEN }, | |
241 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
242 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
243 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 244 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 245 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
246 | |
247 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
248 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
249 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
250 | .len = IEEE80211_MAX_DATA_LEN }, | |
251 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
252 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
253 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
254 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
255 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
256 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
257 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 258 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 259 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 260 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 261 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 262 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 263 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 264 | |
b2e1b302 LR |
265 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
266 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
267 | ||
9f1ba906 JM |
268 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
269 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
270 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
271 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
272 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 273 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 274 | |
24bdd9f4 | 275 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 276 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 277 | |
6c739419 | 278 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
279 | |
280 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
281 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
282 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
283 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
284 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
285 | |
286 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
287 | .len = IEEE80211_MAX_SSID_LEN }, | |
288 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
289 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 290 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 291 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 292 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
293 | [NL80211_ATTR_STA_FLAGS2] = { |
294 | .len = sizeof(struct nl80211_sta_flag_update), | |
295 | }, | |
3f77316c | 296 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
297 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
298 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
299 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
300 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
301 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 302 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 303 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
304 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
305 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
306 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
307 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 308 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
309 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
310 | .len = IEEE80211_MAX_DATA_LEN }, | |
311 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 312 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 313 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 314 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 315 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
316 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
317 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 318 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
319 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
320 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 321 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 322 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 323 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 324 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 325 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 326 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 327 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 328 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 329 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
330 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
331 | .len = IEEE80211_MAX_DATA_LEN }, | |
332 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
333 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 334 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 335 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 336 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
337 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
338 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
339 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
340 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
341 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
31fa97c5 | 342 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
e247bd90 | 343 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
344 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
345 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 346 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
347 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
348 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
349 | .len = NL80211_HT_CAPABILITY_LEN | |
350 | }, | |
1d9d9213 | 351 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 352 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 353 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 354 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 355 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
e39e5b5e | 356 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
f461be3e | 357 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
ed473771 | 358 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
53cabad7 JB |
359 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
360 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | |
77765eaf VT |
361 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
362 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
363 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
364 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 365 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
366 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
367 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
368 | .len = NL80211_VHT_CAPABILITY_LEN, | |
369 | }, | |
355199e0 JM |
370 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
371 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
372 | .len = IEEE80211_MAX_DATA_LEN }, | |
5e4b6f56 | 373 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
16ef1fe2 SW |
374 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
375 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | |
376 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | |
9a774c78 AO |
377 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
378 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, | |
c01fc9ad SD |
379 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
380 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, | |
5336fa88 | 381 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
60f4a7b1 | 382 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
ad7e718c JB |
383 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
384 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, | |
385 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, | |
fa9ffc74 KP |
386 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
387 | .len = IEEE80211_QOS_MAP_LEN_MAX }, | |
1df4a510 JM |
388 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
389 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, | |
df942e7b | 390 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
18e5ca65 | 391 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
34d22ce2 | 392 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
bab5ab7d | 393 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
960d01ac JB |
394 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
395 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, | |
396 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, | |
18998c38 | 397 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
ad2b26ab | 398 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
1bdd716c | 399 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
55682965 JB |
400 | }; |
401 | ||
e31b8213 | 402 | /* policy for the key attributes */ |
b54452b0 | 403 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 404 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
405 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
406 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 407 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
408 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
409 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 410 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
411 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
412 | }; | |
413 | ||
414 | /* policy for the key default flags */ | |
415 | static const struct nla_policy | |
416 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
417 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
418 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
419 | }; |
420 | ||
ff1b6e69 JB |
421 | /* policy for WoWLAN attributes */ |
422 | static const struct nla_policy | |
423 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
424 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
425 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
426 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
427 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
428 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
429 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
430 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
431 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e | 432 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
8cd4d456 | 433 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
2a0e047e JB |
434 | }; |
435 | ||
436 | static const struct nla_policy | |
437 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
438 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
439 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
440 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
441 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
442 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
443 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
444 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
445 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
446 | }, | |
447 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
448 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
449 | }, | |
450 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
451 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
452 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
453 | }; |
454 | ||
be29b99a AK |
455 | /* policy for coalesce rule attributes */ |
456 | static const struct nla_policy | |
457 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
458 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
459 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
460 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
461 | }; | |
462 | ||
e5497d76 JB |
463 | /* policy for GTK rekey offload attributes */ |
464 | static const struct nla_policy | |
465 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
466 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
467 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
468 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
469 | }; | |
470 | ||
a1f1c21c LC |
471 | static const struct nla_policy |
472 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 473 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 474 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 475 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
476 | }; |
477 | ||
97990a06 JB |
478 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
479 | struct netlink_callback *cb, | |
480 | struct cfg80211_registered_device **rdev, | |
481 | struct wireless_dev **wdev) | |
a043897a | 482 | { |
97990a06 | 483 | int err; |
a043897a | 484 | |
97990a06 | 485 | rtnl_lock(); |
a043897a | 486 | |
97990a06 JB |
487 | if (!cb->args[0]) { |
488 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
489 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
490 | nl80211_policy); | |
491 | if (err) | |
492 | goto out_unlock; | |
67748893 | 493 | |
97990a06 JB |
494 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
495 | nl80211_fam.attrbuf); | |
496 | if (IS_ERR(*wdev)) { | |
497 | err = PTR_ERR(*wdev); | |
498 | goto out_unlock; | |
499 | } | |
f26cbf40 | 500 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
501 | /* 0 is the first index - add 1 to parse only once */ |
502 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
503 | cb->args[1] = (*wdev)->identifier; |
504 | } else { | |
c319d50b JB |
505 | /* subtract the 1 again here */ |
506 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 507 | struct wireless_dev *tmp; |
67748893 | 508 | |
97990a06 JB |
509 | if (!wiphy) { |
510 | err = -ENODEV; | |
511 | goto out_unlock; | |
512 | } | |
f26cbf40 | 513 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 514 | *wdev = NULL; |
67748893 | 515 | |
97990a06 JB |
516 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
517 | if (tmp->identifier == cb->args[1]) { | |
518 | *wdev = tmp; | |
519 | break; | |
520 | } | |
521 | } | |
67748893 | 522 | |
97990a06 JB |
523 | if (!*wdev) { |
524 | err = -ENODEV; | |
525 | goto out_unlock; | |
526 | } | |
67748893 JB |
527 | } |
528 | ||
67748893 | 529 | return 0; |
97990a06 | 530 | out_unlock: |
67748893 JB |
531 | rtnl_unlock(); |
532 | return err; | |
533 | } | |
534 | ||
97990a06 | 535 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 536 | { |
67748893 JB |
537 | rtnl_unlock(); |
538 | } | |
539 | ||
f4a11bb0 JB |
540 | /* IE validation */ |
541 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
542 | { | |
543 | const u8 *pos; | |
544 | int len; | |
545 | ||
546 | if (!attr) | |
547 | return true; | |
548 | ||
549 | pos = nla_data(attr); | |
550 | len = nla_len(attr); | |
551 | ||
552 | while (len) { | |
553 | u8 elemlen; | |
554 | ||
555 | if (len < 2) | |
556 | return false; | |
557 | len -= 2; | |
558 | ||
559 | elemlen = pos[1]; | |
560 | if (elemlen > len) | |
561 | return false; | |
562 | ||
563 | len -= elemlen; | |
564 | pos += 2 + elemlen; | |
565 | } | |
566 | ||
567 | return true; | |
568 | } | |
569 | ||
55682965 | 570 | /* message building helper */ |
15e47304 | 571 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
572 | int flags, u8 cmd) |
573 | { | |
574 | /* since there is no private header just add the generic one */ | |
15e47304 | 575 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
576 | } |
577 | ||
5dab3b8a | 578 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
579 | struct ieee80211_channel *chan, |
580 | bool large) | |
5dab3b8a | 581 | { |
ea077c1c RL |
582 | /* Some channels must be completely excluded from the |
583 | * list to protect old user-space tools from breaking | |
584 | */ | |
585 | if (!large && chan->flags & | |
586 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
587 | return 0; | |
588 | ||
9360ffd1 DM |
589 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
590 | chan->center_freq)) | |
591 | goto nla_put_failure; | |
5dab3b8a | 592 | |
9360ffd1 DM |
593 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
594 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
595 | goto nla_put_failure; | |
8fe02e16 LR |
596 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
597 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
598 | goto nla_put_failure; | |
599 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
600 | goto nla_put_failure; | |
601 | } | |
cdc89b97 JB |
602 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
603 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
604 | goto nla_put_failure; | |
605 | if (large) { | |
606 | u32 time; | |
607 | ||
608 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
609 | ||
610 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
611 | chan->dfs_state)) | |
612 | goto nla_put_failure; | |
613 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
614 | time)) | |
615 | goto nla_put_failure; | |
089027e5 JD |
616 | if (nla_put_u32(msg, |
617 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
618 | chan->dfs_cac_ms)) | |
619 | goto nla_put_failure; | |
cdc89b97 JB |
620 | } |
621 | } | |
5dab3b8a | 622 | |
fe1abafd JB |
623 | if (large) { |
624 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
625 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
626 | goto nla_put_failure; | |
627 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
628 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
629 | goto nla_put_failure; | |
630 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
631 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
632 | goto nla_put_failure; | |
633 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
634 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
635 | goto nla_put_failure; | |
570dbde1 DS |
636 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
637 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
638 | goto nla_put_failure; | |
639 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && | |
640 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) | |
641 | goto nla_put_failure; | |
ea077c1c RL |
642 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
643 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
644 | goto nla_put_failure; | |
645 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
646 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
647 | goto nla_put_failure; | |
fe1abafd JB |
648 | } |
649 | ||
9360ffd1 DM |
650 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
651 | DBM_TO_MBM(chan->max_power))) | |
652 | goto nla_put_failure; | |
5dab3b8a LR |
653 | |
654 | return 0; | |
655 | ||
656 | nla_put_failure: | |
657 | return -ENOBUFS; | |
658 | } | |
659 | ||
55682965 JB |
660 | /* netlink command implementations */ |
661 | ||
b9454e83 JB |
662 | struct key_parse { |
663 | struct key_params p; | |
664 | int idx; | |
e31b8213 | 665 | int type; |
b9454e83 | 666 | bool def, defmgmt; |
dbd2fd65 | 667 | bool def_uni, def_multi; |
b9454e83 JB |
668 | }; |
669 | ||
670 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
671 | { | |
672 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
673 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
674 | nl80211_key_policy); | |
675 | if (err) | |
676 | return err; | |
677 | ||
678 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
679 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
680 | ||
dbd2fd65 JB |
681 | if (k->def) { |
682 | k->def_uni = true; | |
683 | k->def_multi = true; | |
684 | } | |
685 | if (k->defmgmt) | |
686 | k->def_multi = true; | |
687 | ||
b9454e83 JB |
688 | if (tb[NL80211_KEY_IDX]) |
689 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
690 | ||
691 | if (tb[NL80211_KEY_DATA]) { | |
692 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
693 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
694 | } | |
695 | ||
696 | if (tb[NL80211_KEY_SEQ]) { | |
697 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
698 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
699 | } | |
700 | ||
701 | if (tb[NL80211_KEY_CIPHER]) | |
702 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
703 | ||
e31b8213 JB |
704 | if (tb[NL80211_KEY_TYPE]) { |
705 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
706 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
707 | return -EINVAL; | |
708 | } | |
709 | ||
dbd2fd65 JB |
710 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
711 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
712 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
713 | tb[NL80211_KEY_DEFAULT_TYPES], | |
714 | nl80211_key_default_policy); | |
dbd2fd65 JB |
715 | if (err) |
716 | return err; | |
717 | ||
718 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
719 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
720 | } | |
721 | ||
b9454e83 JB |
722 | return 0; |
723 | } | |
724 | ||
725 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
726 | { | |
727 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
728 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
729 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
730 | } | |
731 | ||
732 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
733 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
734 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
735 | } | |
736 | ||
737 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
738 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
739 | ||
740 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
741 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
742 | ||
743 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
744 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
745 | ||
dbd2fd65 JB |
746 | if (k->def) { |
747 | k->def_uni = true; | |
748 | k->def_multi = true; | |
749 | } | |
750 | if (k->defmgmt) | |
751 | k->def_multi = true; | |
752 | ||
e31b8213 JB |
753 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
754 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
755 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
756 | return -EINVAL; | |
757 | } | |
758 | ||
dbd2fd65 JB |
759 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
760 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
761 | int err = nla_parse_nested( | |
762 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
763 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
764 | nl80211_key_default_policy); | |
765 | if (err) | |
766 | return err; | |
767 | ||
768 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
769 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
770 | } | |
771 | ||
b9454e83 JB |
772 | return 0; |
773 | } | |
774 | ||
775 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
776 | { | |
777 | int err; | |
778 | ||
779 | memset(k, 0, sizeof(*k)); | |
780 | k->idx = -1; | |
e31b8213 | 781 | k->type = -1; |
b9454e83 JB |
782 | |
783 | if (info->attrs[NL80211_ATTR_KEY]) | |
784 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
785 | else | |
786 | err = nl80211_parse_key_old(info, k); | |
787 | ||
788 | if (err) | |
789 | return err; | |
790 | ||
791 | if (k->def && k->defmgmt) | |
792 | return -EINVAL; | |
793 | ||
dbd2fd65 JB |
794 | if (k->defmgmt) { |
795 | if (k->def_uni || !k->def_multi) | |
796 | return -EINVAL; | |
797 | } | |
798 | ||
b9454e83 JB |
799 | if (k->idx != -1) { |
800 | if (k->defmgmt) { | |
801 | if (k->idx < 4 || k->idx > 5) | |
802 | return -EINVAL; | |
803 | } else if (k->def) { | |
804 | if (k->idx < 0 || k->idx > 3) | |
805 | return -EINVAL; | |
806 | } else { | |
807 | if (k->idx < 0 || k->idx > 5) | |
808 | return -EINVAL; | |
809 | } | |
810 | } | |
811 | ||
812 | return 0; | |
813 | } | |
814 | ||
fffd0934 JB |
815 | static struct cfg80211_cached_keys * |
816 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 817 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
818 | { |
819 | struct key_parse parse; | |
820 | struct nlattr *key; | |
821 | struct cfg80211_cached_keys *result; | |
822 | int rem, err, def = 0; | |
823 | ||
824 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
825 | if (!result) | |
826 | return ERR_PTR(-ENOMEM); | |
827 | ||
828 | result->def = -1; | |
829 | result->defmgmt = -1; | |
830 | ||
831 | nla_for_each_nested(key, keys, rem) { | |
832 | memset(&parse, 0, sizeof(parse)); | |
833 | parse.idx = -1; | |
834 | ||
835 | err = nl80211_parse_key_new(key, &parse); | |
836 | if (err) | |
837 | goto error; | |
838 | err = -EINVAL; | |
839 | if (!parse.p.key) | |
840 | goto error; | |
841 | if (parse.idx < 0 || parse.idx > 4) | |
842 | goto error; | |
843 | if (parse.def) { | |
844 | if (def) | |
845 | goto error; | |
846 | def = 1; | |
847 | result->def = parse.idx; | |
dbd2fd65 JB |
848 | if (!parse.def_uni || !parse.def_multi) |
849 | goto error; | |
fffd0934 JB |
850 | } else if (parse.defmgmt) |
851 | goto error; | |
852 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 853 | parse.idx, false, NULL); |
fffd0934 JB |
854 | if (err) |
855 | goto error; | |
856 | result->params[parse.idx].cipher = parse.p.cipher; | |
857 | result->params[parse.idx].key_len = parse.p.key_len; | |
858 | result->params[parse.idx].key = result->data[parse.idx]; | |
859 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
860 | |
861 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
862 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
863 | if (no_ht) | |
864 | *no_ht = true; | |
865 | } | |
fffd0934 JB |
866 | } |
867 | ||
868 | return result; | |
869 | error: | |
870 | kfree(result); | |
871 | return ERR_PTR(err); | |
872 | } | |
873 | ||
874 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
875 | { | |
876 | ASSERT_WDEV_LOCK(wdev); | |
877 | ||
fffd0934 JB |
878 | switch (wdev->iftype) { |
879 | case NL80211_IFTYPE_AP: | |
880 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 881 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 882 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
883 | break; |
884 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 885 | case NL80211_IFTYPE_STATION: |
074ac8df | 886 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 887 | if (!wdev->current_bss) |
fffd0934 JB |
888 | return -ENOLINK; |
889 | break; | |
de4fcbad | 890 | case NL80211_IFTYPE_UNSPECIFIED: |
6e0bd6c3 | 891 | case NL80211_IFTYPE_OCB: |
de4fcbad JB |
892 | case NL80211_IFTYPE_MONITOR: |
893 | case NL80211_IFTYPE_P2P_DEVICE: | |
894 | case NL80211_IFTYPE_WDS: | |
895 | case NUM_NL80211_IFTYPES: | |
fffd0934 JB |
896 | return -EINVAL; |
897 | } | |
898 | ||
899 | return 0; | |
900 | } | |
901 | ||
664834de JM |
902 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
903 | struct nlattr *tb) | |
904 | { | |
905 | struct ieee80211_channel *chan; | |
906 | ||
907 | if (tb == NULL) | |
908 | return NULL; | |
909 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
910 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
911 | return NULL; | |
912 | return chan; | |
913 | } | |
914 | ||
7527a782 JB |
915 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
916 | { | |
917 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
918 | int i; | |
919 | ||
920 | if (!nl_modes) | |
921 | goto nla_put_failure; | |
922 | ||
923 | i = 0; | |
924 | while (ifmodes) { | |
9360ffd1 DM |
925 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
926 | goto nla_put_failure; | |
7527a782 JB |
927 | ifmodes >>= 1; |
928 | i++; | |
929 | } | |
930 | ||
931 | nla_nest_end(msg, nl_modes); | |
932 | return 0; | |
933 | ||
934 | nla_put_failure: | |
935 | return -ENOBUFS; | |
936 | } | |
937 | ||
938 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
939 | struct sk_buff *msg, |
940 | bool large) | |
7527a782 JB |
941 | { |
942 | struct nlattr *nl_combis; | |
943 | int i, j; | |
944 | ||
945 | nl_combis = nla_nest_start(msg, | |
946 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
947 | if (!nl_combis) | |
948 | goto nla_put_failure; | |
949 | ||
950 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
951 | const struct ieee80211_iface_combination *c; | |
952 | struct nlattr *nl_combi, *nl_limits; | |
953 | ||
954 | c = &wiphy->iface_combinations[i]; | |
955 | ||
956 | nl_combi = nla_nest_start(msg, i + 1); | |
957 | if (!nl_combi) | |
958 | goto nla_put_failure; | |
959 | ||
960 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
961 | if (!nl_limits) | |
962 | goto nla_put_failure; | |
963 | ||
964 | for (j = 0; j < c->n_limits; j++) { | |
965 | struct nlattr *nl_limit; | |
966 | ||
967 | nl_limit = nla_nest_start(msg, j + 1); | |
968 | if (!nl_limit) | |
969 | goto nla_put_failure; | |
9360ffd1 DM |
970 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
971 | c->limits[j].max)) | |
972 | goto nla_put_failure; | |
7527a782 JB |
973 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
974 | c->limits[j].types)) | |
975 | goto nla_put_failure; | |
976 | nla_nest_end(msg, nl_limit); | |
977 | } | |
978 | ||
979 | nla_nest_end(msg, nl_limits); | |
980 | ||
9360ffd1 DM |
981 | if (c->beacon_int_infra_match && |
982 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
983 | goto nla_put_failure; | |
984 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
985 | c->num_different_channels) || | |
986 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
987 | c->max_interfaces)) | |
988 | goto nla_put_failure; | |
cdc89b97 | 989 | if (large && |
8c48b50a FF |
990 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
991 | c->radar_detect_widths) || | |
992 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
993 | c->radar_detect_regions))) | |
cdc89b97 | 994 | goto nla_put_failure; |
7527a782 JB |
995 | |
996 | nla_nest_end(msg, nl_combi); | |
997 | } | |
998 | ||
999 | nla_nest_end(msg, nl_combis); | |
1000 | ||
1001 | return 0; | |
1002 | nla_put_failure: | |
1003 | return -ENOBUFS; | |
1004 | } | |
1005 | ||
3713b4e3 | 1006 | #ifdef CONFIG_PM |
b56cf720 JB |
1007 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
1008 | struct sk_buff *msg) | |
1009 | { | |
964dc9e2 | 1010 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
1011 | struct nlattr *nl_tcp; |
1012 | ||
1013 | if (!tcp) | |
1014 | return 0; | |
1015 | ||
1016 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
1017 | if (!nl_tcp) | |
1018 | return -ENOBUFS; | |
1019 | ||
1020 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1021 | tcp->data_payload_max)) | |
1022 | return -ENOBUFS; | |
1023 | ||
1024 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1025 | tcp->data_payload_max)) | |
1026 | return -ENOBUFS; | |
1027 | ||
1028 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1029 | return -ENOBUFS; | |
1030 | ||
1031 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1032 | sizeof(*tcp->tok), tcp->tok)) | |
1033 | return -ENOBUFS; | |
1034 | ||
1035 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1036 | tcp->data_interval_max)) | |
1037 | return -ENOBUFS; | |
1038 | ||
1039 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1040 | tcp->wake_payload_max)) | |
1041 | return -ENOBUFS; | |
1042 | ||
1043 | nla_nest_end(msg, nl_tcp); | |
1044 | return 0; | |
1045 | } | |
1046 | ||
3713b4e3 | 1047 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1048 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1049 | bool large) |
55682965 | 1050 | { |
3713b4e3 | 1051 | struct nlattr *nl_wowlan; |
55682965 | 1052 | |
1b8ec87a | 1053 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1054 | return 0; |
55682965 | 1055 | |
3713b4e3 JB |
1056 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1057 | if (!nl_wowlan) | |
1058 | return -ENOBUFS; | |
9360ffd1 | 1059 | |
1b8ec87a | 1060 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1061 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1062 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1063 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1064 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1065 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1066 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1067 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1068 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1069 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1070 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1071 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1072 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1073 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1074 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1075 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1076 | return -ENOBUFS; | |
9360ffd1 | 1077 | |
1b8ec87a | 1078 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1079 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1080 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1081 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1082 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1083 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1084 | }; |
9360ffd1 | 1085 | |
3713b4e3 JB |
1086 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1087 | sizeof(pat), &pat)) | |
1088 | return -ENOBUFS; | |
1089 | } | |
9360ffd1 | 1090 | |
75453ccb LC |
1091 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
1092 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, | |
1093 | rdev->wiphy.wowlan->max_nd_match_sets)) | |
1094 | return -ENOBUFS; | |
1095 | ||
1b8ec87a | 1096 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1097 | return -ENOBUFS; |
1098 | ||
8cd4d456 LC |
1099 | /* TODO: send wowlan net detect */ |
1100 | ||
3713b4e3 | 1101 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1102 | |
3713b4e3 JB |
1103 | return 0; |
1104 | } | |
1105 | #endif | |
9360ffd1 | 1106 | |
be29b99a | 1107 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1108 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1109 | { |
1110 | struct nl80211_coalesce_rule_support rule; | |
1111 | ||
1b8ec87a | 1112 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1113 | return 0; |
1114 | ||
1b8ec87a ZG |
1115 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1116 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1117 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1118 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1119 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1120 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1121 | |
1122 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1123 | return -ENOBUFS; | |
1124 | ||
1125 | return 0; | |
1126 | } | |
1127 | ||
3713b4e3 JB |
1128 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1129 | struct ieee80211_supported_band *sband) | |
1130 | { | |
1131 | struct nlattr *nl_rates, *nl_rate; | |
1132 | struct ieee80211_rate *rate; | |
1133 | int i; | |
87bbbe22 | 1134 | |
3713b4e3 JB |
1135 | /* add HT info */ |
1136 | if (sband->ht_cap.ht_supported && | |
1137 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1138 | sizeof(sband->ht_cap.mcs), | |
1139 | &sband->ht_cap.mcs) || | |
1140 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1141 | sband->ht_cap.cap) || | |
1142 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1143 | sband->ht_cap.ampdu_factor) || | |
1144 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1145 | sband->ht_cap.ampdu_density))) | |
1146 | return -ENOBUFS; | |
afe0cbf8 | 1147 | |
3713b4e3 JB |
1148 | /* add VHT info */ |
1149 | if (sband->vht_cap.vht_supported && | |
1150 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1151 | sizeof(sband->vht_cap.vht_mcs), | |
1152 | &sband->vht_cap.vht_mcs) || | |
1153 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1154 | sband->vht_cap.cap))) | |
1155 | return -ENOBUFS; | |
f59ac048 | 1156 | |
3713b4e3 JB |
1157 | /* add bitrates */ |
1158 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1159 | if (!nl_rates) | |
1160 | return -ENOBUFS; | |
ee688b00 | 1161 | |
3713b4e3 JB |
1162 | for (i = 0; i < sband->n_bitrates; i++) { |
1163 | nl_rate = nla_nest_start(msg, i); | |
1164 | if (!nl_rate) | |
1165 | return -ENOBUFS; | |
ee688b00 | 1166 | |
3713b4e3 JB |
1167 | rate = &sband->bitrates[i]; |
1168 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1169 | rate->bitrate)) | |
1170 | return -ENOBUFS; | |
1171 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1172 | nla_put_flag(msg, | |
1173 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1174 | return -ENOBUFS; | |
ee688b00 | 1175 | |
3713b4e3 JB |
1176 | nla_nest_end(msg, nl_rate); |
1177 | } | |
d51626df | 1178 | |
3713b4e3 | 1179 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1180 | |
3713b4e3 JB |
1181 | return 0; |
1182 | } | |
ee688b00 | 1183 | |
3713b4e3 JB |
1184 | static int |
1185 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1186 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1187 | { | |
1188 | u16 stypes; | |
1189 | struct nlattr *nl_ftypes, *nl_ifs; | |
1190 | enum nl80211_iftype ift; | |
1191 | int i; | |
ee688b00 | 1192 | |
3713b4e3 JB |
1193 | if (!mgmt_stypes) |
1194 | return 0; | |
5dab3b8a | 1195 | |
3713b4e3 JB |
1196 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1197 | if (!nl_ifs) | |
1198 | return -ENOBUFS; | |
e2f367f2 | 1199 | |
3713b4e3 JB |
1200 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1201 | nl_ftypes = nla_nest_start(msg, ift); | |
1202 | if (!nl_ftypes) | |
1203 | return -ENOBUFS; | |
1204 | i = 0; | |
1205 | stypes = mgmt_stypes[ift].tx; | |
1206 | while (stypes) { | |
1207 | if ((stypes & 1) && | |
1208 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1209 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1210 | return -ENOBUFS; | |
1211 | stypes >>= 1; | |
1212 | i++; | |
ee688b00 | 1213 | } |
3713b4e3 JB |
1214 | nla_nest_end(msg, nl_ftypes); |
1215 | } | |
ee688b00 | 1216 | |
3713b4e3 | 1217 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1218 | |
3713b4e3 JB |
1219 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1220 | if (!nl_ifs) | |
1221 | return -ENOBUFS; | |
ee688b00 | 1222 | |
3713b4e3 JB |
1223 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1224 | nl_ftypes = nla_nest_start(msg, ift); | |
1225 | if (!nl_ftypes) | |
1226 | return -ENOBUFS; | |
1227 | i = 0; | |
1228 | stypes = mgmt_stypes[ift].rx; | |
1229 | while (stypes) { | |
1230 | if ((stypes & 1) && | |
1231 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1232 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1233 | return -ENOBUFS; | |
1234 | stypes >>= 1; | |
1235 | i++; | |
1236 | } | |
1237 | nla_nest_end(msg, nl_ftypes); | |
1238 | } | |
1239 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1240 | |
3713b4e3 JB |
1241 | return 0; |
1242 | } | |
ee688b00 | 1243 | |
86e8cf98 JB |
1244 | struct nl80211_dump_wiphy_state { |
1245 | s64 filter_wiphy; | |
1246 | long start; | |
1247 | long split_start, band_start, chan_start; | |
1248 | bool split; | |
1249 | }; | |
1250 | ||
1b8ec87a | 1251 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 1252 | enum nl80211_commands cmd, |
3713b4e3 | 1253 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1254 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1255 | { |
1256 | void *hdr; | |
1257 | struct nlattr *nl_bands, *nl_band; | |
1258 | struct nlattr *nl_freqs, *nl_freq; | |
1259 | struct nlattr *nl_cmds; | |
1260 | enum ieee80211_band band; | |
1261 | struct ieee80211_channel *chan; | |
1262 | int i; | |
1263 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1264 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1265 | u32 features; |
ee688b00 | 1266 | |
3bb20556 | 1267 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
1268 | if (!hdr) |
1269 | return -ENOBUFS; | |
ee688b00 | 1270 | |
86e8cf98 JB |
1271 | if (WARN_ON(!state)) |
1272 | return -EINVAL; | |
ee688b00 | 1273 | |
1b8ec87a | 1274 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1275 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1276 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1277 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1278 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1279 | goto nla_put_failure; |
1280 | ||
3bb20556 JB |
1281 | if (cmd != NL80211_CMD_NEW_WIPHY) |
1282 | goto finish; | |
1283 | ||
86e8cf98 | 1284 | switch (state->split_start) { |
3713b4e3 JB |
1285 | case 0: |
1286 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1287 | rdev->wiphy.retry_short) || |
3713b4e3 | 1288 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1289 | rdev->wiphy.retry_long) || |
3713b4e3 | 1290 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1291 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1292 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1293 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1294 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1295 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1296 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1297 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1298 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1299 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1300 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1301 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1302 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1303 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1304 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
1b8ec87a | 1305 | rdev->wiphy.max_match_sets)) |
9360ffd1 | 1306 | goto nla_put_failure; |
3713b4e3 | 1307 | |
1b8ec87a | 1308 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1309 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1310 | goto nla_put_failure; |
1b8ec87a | 1311 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1312 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1313 | goto nla_put_failure; | |
1b8ec87a | 1314 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1315 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1316 | goto nla_put_failure; | |
1b8ec87a | 1317 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1318 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1319 | goto nla_put_failure; | |
1b8ec87a | 1320 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1321 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1322 | goto nla_put_failure; | |
1b8ec87a | 1323 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1324 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1325 | goto nla_put_failure; |
86e8cf98 JB |
1326 | state->split_start++; |
1327 | if (state->split) | |
3713b4e3 JB |
1328 | break; |
1329 | case 1: | |
1330 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1331 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1332 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1333 | goto nla_put_failure; |
4745fc09 | 1334 | |
3713b4e3 | 1335 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1336 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1337 | goto nla_put_failure; |
b23aa676 | 1338 | |
1b8ec87a | 1339 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1340 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1341 | goto nla_put_failure; |
b23aa676 | 1342 | |
3713b4e3 | 1343 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1344 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1345 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1346 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1347 | goto nla_put_failure; |
b23aa676 | 1348 | |
1b8ec87a | 1349 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1350 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1351 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1352 | goto nla_put_failure; |
8fdc621d | 1353 | |
1b8ec87a ZG |
1354 | if ((rdev->wiphy.available_antennas_tx || |
1355 | rdev->wiphy.available_antennas_rx) && | |
1356 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1357 | u32 tx_ant = 0, rx_ant = 0; |
1358 | int res; | |
1b8ec87a | 1359 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1360 | if (!res) { |
1361 | if (nla_put_u32(msg, | |
1362 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1363 | tx_ant) || | |
1364 | nla_put_u32(msg, | |
1365 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1366 | rx_ant)) | |
1367 | goto nla_put_failure; | |
1368 | } | |
1369 | } | |
a293911d | 1370 | |
86e8cf98 JB |
1371 | state->split_start++; |
1372 | if (state->split) | |
3713b4e3 JB |
1373 | break; |
1374 | case 2: | |
1375 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1376 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1377 | goto nla_put_failure; |
86e8cf98 JB |
1378 | state->split_start++; |
1379 | if (state->split) | |
3713b4e3 JB |
1380 | break; |
1381 | case 3: | |
1382 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1383 | if (!nl_bands) | |
1384 | goto nla_put_failure; | |
f7ca38df | 1385 | |
86e8cf98 JB |
1386 | for (band = state->band_start; |
1387 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1388 | struct ieee80211_supported_band *sband; |
2e161f78 | 1389 | |
1b8ec87a | 1390 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1391 | |
3713b4e3 JB |
1392 | if (!sband) |
1393 | continue; | |
1394 | ||
1395 | nl_band = nla_nest_start(msg, band); | |
1396 | if (!nl_band) | |
2e161f78 | 1397 | goto nla_put_failure; |
3713b4e3 | 1398 | |
86e8cf98 | 1399 | switch (state->chan_start) { |
3713b4e3 JB |
1400 | case 0: |
1401 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1402 | goto nla_put_failure; |
86e8cf98 JB |
1403 | state->chan_start++; |
1404 | if (state->split) | |
3713b4e3 JB |
1405 | break; |
1406 | default: | |
1407 | /* add frequencies */ | |
1408 | nl_freqs = nla_nest_start( | |
1409 | msg, NL80211_BAND_ATTR_FREQS); | |
1410 | if (!nl_freqs) | |
1411 | goto nla_put_failure; | |
1412 | ||
86e8cf98 | 1413 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1414 | i < sband->n_channels; |
1415 | i++) { | |
1416 | nl_freq = nla_nest_start(msg, i); | |
1417 | if (!nl_freq) | |
1418 | goto nla_put_failure; | |
1419 | ||
1420 | chan = &sband->channels[i]; | |
1421 | ||
86e8cf98 JB |
1422 | if (nl80211_msg_put_channel( |
1423 | msg, chan, | |
1424 | state->split)) | |
3713b4e3 JB |
1425 | goto nla_put_failure; |
1426 | ||
1427 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1428 | if (state->split) |
3713b4e3 JB |
1429 | break; |
1430 | } | |
1431 | if (i < sband->n_channels) | |
86e8cf98 | 1432 | state->chan_start = i + 2; |
3713b4e3 | 1433 | else |
86e8cf98 | 1434 | state->chan_start = 0; |
3713b4e3 JB |
1435 | nla_nest_end(msg, nl_freqs); |
1436 | } | |
1437 | ||
1438 | nla_nest_end(msg, nl_band); | |
1439 | ||
86e8cf98 | 1440 | if (state->split) { |
3713b4e3 | 1441 | /* start again here */ |
86e8cf98 | 1442 | if (state->chan_start) |
3713b4e3 JB |
1443 | band--; |
1444 | break; | |
2e161f78 | 1445 | } |
2e161f78 | 1446 | } |
3713b4e3 | 1447 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1448 | |
3713b4e3 | 1449 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1450 | state->band_start = band + 1; |
3713b4e3 | 1451 | else |
86e8cf98 | 1452 | state->band_start = 0; |
74b70a4e | 1453 | |
3713b4e3 | 1454 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1455 | if (state->band_start == 0 && state->chan_start == 0) |
1456 | state->split_start++; | |
1457 | if (state->split) | |
3713b4e3 JB |
1458 | break; |
1459 | case 4: | |
1460 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1461 | if (!nl_cmds) | |
2e161f78 JB |
1462 | goto nla_put_failure; |
1463 | ||
3713b4e3 JB |
1464 | i = 0; |
1465 | #define CMD(op, n) \ | |
1466 | do { \ | |
1b8ec87a | 1467 | if (rdev->ops->op) { \ |
3713b4e3 JB |
1468 | i++; \ |
1469 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1470 | goto nla_put_failure; \ | |
1471 | } \ | |
1472 | } while (0) | |
1473 | ||
1474 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1475 | CMD(change_virtual_intf, SET_INTERFACE); | |
1476 | CMD(add_key, NEW_KEY); | |
1477 | CMD(start_ap, START_AP); | |
1478 | CMD(add_station, NEW_STATION); | |
1479 | CMD(add_mpath, NEW_MPATH); | |
1480 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1481 | CMD(change_bss, SET_BSS); | |
1482 | CMD(auth, AUTHENTICATE); | |
1483 | CMD(assoc, ASSOCIATE); | |
1484 | CMD(deauth, DEAUTHENTICATE); | |
1485 | CMD(disassoc, DISASSOCIATE); | |
1486 | CMD(join_ibss, JOIN_IBSS); | |
1487 | CMD(join_mesh, JOIN_MESH); | |
1488 | CMD(set_pmksa, SET_PMKSA); | |
1489 | CMD(del_pmksa, DEL_PMKSA); | |
1490 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1b8ec87a | 1491 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
3713b4e3 JB |
1492 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
1493 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1494 | CMD(mgmt_tx, FRAME); | |
1495 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1b8ec87a | 1496 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
3713b4e3 JB |
1497 | i++; |
1498 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1499 | goto nla_put_failure; |
2e161f78 | 1500 | } |
1b8ec87a ZG |
1501 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
1502 | rdev->ops->join_mesh) { | |
3713b4e3 JB |
1503 | i++; |
1504 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1505 | goto nla_put_failure; | |
1506 | } | |
1507 | CMD(set_wds_peer, SET_WDS_PEER); | |
1b8ec87a | 1508 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
3713b4e3 JB |
1509 | CMD(tdls_mgmt, TDLS_MGMT); |
1510 | CMD(tdls_oper, TDLS_OPER); | |
1511 | } | |
1b8ec87a | 1512 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
3713b4e3 JB |
1513 | CMD(sched_scan_start, START_SCHED_SCAN); |
1514 | CMD(probe_client, PROBE_CLIENT); | |
1515 | CMD(set_noack_map, SET_NOACK_MAP); | |
1b8ec87a | 1516 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
3713b4e3 JB |
1517 | i++; |
1518 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1519 | goto nla_put_failure; | |
1520 | } | |
1521 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1522 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
02df00eb JB |
1523 | #ifdef CONFIG_NL80211_TESTMODE |
1524 | CMD(testmode_cmd, TESTMODE); | |
1525 | #endif | |
86e8cf98 | 1526 | if (state->split) { |
5de17984 AS |
1527 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1528 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 1529 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 1530 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 1531 | CMD(set_qos_map, SET_QOS_MAP); |
723e73ac JB |
1532 | if (rdev->wiphy.features & |
1533 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | |
960d01ac | 1534 | CMD(add_tx_ts, ADD_TX_TS); |
5de17984 | 1535 | } |
02df00eb | 1536 | /* add into the if now */ |
3713b4e3 | 1537 | #undef CMD |
ff1b6e69 | 1538 | |
1b8ec87a | 1539 | if (rdev->ops->connect || rdev->ops->auth) { |
3713b4e3 JB |
1540 | i++; |
1541 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1542 | goto nla_put_failure; |
ff1b6e69 JB |
1543 | } |
1544 | ||
1b8ec87a | 1545 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
3713b4e3 JB |
1546 | i++; |
1547 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1548 | goto nla_put_failure; | |
1549 | } | |
1550 | ||
1551 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1552 | state->split_start++; |
1553 | if (state->split) | |
3713b4e3 JB |
1554 | break; |
1555 | case 5: | |
1b8ec87a ZG |
1556 | if (rdev->ops->remain_on_channel && |
1557 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
1558 | nla_put_u32(msg, |
1559 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 1560 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
1561 | goto nla_put_failure; |
1562 | ||
1b8ec87a | 1563 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
1564 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
1565 | goto nla_put_failure; | |
1566 | ||
1567 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1568 | goto nla_put_failure; | |
86e8cf98 JB |
1569 | state->split_start++; |
1570 | if (state->split) | |
3713b4e3 JB |
1571 | break; |
1572 | case 6: | |
1573 | #ifdef CONFIG_PM | |
1b8ec87a | 1574 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 1575 | goto nla_put_failure; |
86e8cf98 JB |
1576 | state->split_start++; |
1577 | if (state->split) | |
3713b4e3 JB |
1578 | break; |
1579 | #else | |
86e8cf98 | 1580 | state->split_start++; |
dfb89c56 | 1581 | #endif |
3713b4e3 JB |
1582 | case 7: |
1583 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 1584 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 1585 | goto nla_put_failure; |
ff1b6e69 | 1586 | |
1b8ec87a | 1587 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 1588 | state->split)) |
3713b4e3 | 1589 | goto nla_put_failure; |
7527a782 | 1590 | |
86e8cf98 JB |
1591 | state->split_start++; |
1592 | if (state->split) | |
3713b4e3 JB |
1593 | break; |
1594 | case 8: | |
1b8ec87a | 1595 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 1596 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 1597 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 1598 | goto nla_put_failure; |
7527a782 | 1599 | |
1b8ec87a | 1600 | features = rdev->wiphy.features; |
fe1abafd JB |
1601 | /* |
1602 | * We can only add the per-channel limit information if the | |
1603 | * dump is split, otherwise it makes it too big. Therefore | |
1604 | * only advertise it in that case. | |
1605 | */ | |
86e8cf98 | 1606 | if (state->split) |
fe1abafd JB |
1607 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1608 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1609 | goto nla_put_failure; |
562a7480 | 1610 | |
1b8ec87a | 1611 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 1612 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
1613 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
1614 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 1615 | goto nla_put_failure; |
1f074bd8 | 1616 | |
1b8ec87a ZG |
1617 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1618 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 1619 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 1620 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 1621 | goto nla_put_failure; |
7e7c8926 | 1622 | |
3713b4e3 JB |
1623 | /* |
1624 | * Any information below this point is only available to | |
1625 | * applications that can deal with it being split. This | |
1626 | * helps ensure that newly added capabilities don't break | |
1627 | * older tools by overrunning their buffers. | |
1628 | * | |
1629 | * We still increment split_start so that in the split | |
1630 | * case we'll continue with more data in the next round, | |
1631 | * but break unconditionally so unsplit data stops here. | |
1632 | */ | |
86e8cf98 | 1633 | state->split_start++; |
3713b4e3 JB |
1634 | break; |
1635 | case 9: | |
1b8ec87a | 1636 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 1637 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
1638 | rdev->wiphy.extended_capabilities_len, |
1639 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 1640 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
1641 | rdev->wiphy.extended_capabilities_len, |
1642 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 1643 | goto nla_put_failure; |
a50df0c4 | 1644 | |
1b8ec87a | 1645 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 1646 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
1647 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
1648 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
1649 | goto nla_put_failure; |
1650 | ||
be29b99a AK |
1651 | state->split_start++; |
1652 | break; | |
1653 | case 10: | |
1b8ec87a | 1654 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
1655 | goto nla_put_failure; |
1656 | ||
1b8ec87a | 1657 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
1658 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
1659 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1660 | goto nla_put_failure; | |
b43504cf | 1661 | |
1b8ec87a | 1662 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 1663 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 1664 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
1665 | goto nla_put_failure; |
1666 | ||
ad7e718c JB |
1667 | state->split_start++; |
1668 | break; | |
1669 | case 11: | |
1b8ec87a | 1670 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
1671 | const struct nl80211_vendor_cmd_info *info; |
1672 | struct nlattr *nested; | |
1673 | ||
1674 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1675 | if (!nested) | |
1676 | goto nla_put_failure; | |
1677 | ||
1b8ec87a ZG |
1678 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
1679 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
1680 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1681 | goto nla_put_failure; | |
1682 | } | |
1683 | nla_nest_end(msg, nested); | |
1684 | } | |
1685 | ||
1b8ec87a | 1686 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
1687 | const struct nl80211_vendor_cmd_info *info; |
1688 | struct nlattr *nested; | |
ad7e718c | 1689 | |
567ffc35 JB |
1690 | nested = nla_nest_start(msg, |
1691 | NL80211_ATTR_VENDOR_EVENTS); | |
1692 | if (!nested) | |
ad7e718c | 1693 | goto nla_put_failure; |
567ffc35 | 1694 | |
1b8ec87a ZG |
1695 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
1696 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
1697 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1698 | goto nla_put_failure; | |
1699 | } | |
1700 | nla_nest_end(msg, nested); | |
1701 | } | |
9a774c78 AO |
1702 | state->split_start++; |
1703 | break; | |
1704 | case 12: | |
1705 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
1706 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
1707 | rdev->wiphy.max_num_csa_counters)) | |
1708 | goto nla_put_failure; | |
01e0daa4 | 1709 | |
1bdd716c AN |
1710 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
1711 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
1712 | goto nla_put_failure; | |
1713 | ||
d75bb06b GKS |
1714 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
1715 | sizeof(rdev->wiphy.ext_features), | |
1716 | rdev->wiphy.ext_features)) | |
1717 | goto nla_put_failure; | |
1718 | ||
3713b4e3 | 1719 | /* done */ |
86e8cf98 | 1720 | state->split_start = 0; |
3713b4e3 JB |
1721 | break; |
1722 | } | |
3bb20556 | 1723 | finish: |
55682965 JB |
1724 | return genlmsg_end(msg, hdr); |
1725 | ||
1726 | nla_put_failure: | |
bc3ed28c TG |
1727 | genlmsg_cancel(msg, hdr); |
1728 | return -EMSGSIZE; | |
55682965 JB |
1729 | } |
1730 | ||
86e8cf98 JB |
1731 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1732 | struct netlink_callback *cb, | |
1733 | struct nl80211_dump_wiphy_state *state) | |
1734 | { | |
1735 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1736 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1737 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1738 | /* ignore parse errors for backward compatibility */ | |
1739 | if (ret) | |
1740 | return 0; | |
1741 | ||
1742 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1743 | if (tb[NL80211_ATTR_WIPHY]) | |
1744 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1745 | if (tb[NL80211_ATTR_WDEV]) | |
1746 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1747 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1748 | struct net_device *netdev; | |
1749 | struct cfg80211_registered_device *rdev; | |
1750 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1751 | ||
7f2b8562 | 1752 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1753 | if (!netdev) |
1754 | return -ENODEV; | |
1755 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1756 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1757 | netdev->ieee80211_ptr->wiphy); |
1758 | state->filter_wiphy = rdev->wiphy_idx; | |
1759 | } | |
86e8cf98 JB |
1760 | } |
1761 | ||
1762 | return 0; | |
1763 | } | |
1764 | ||
55682965 JB |
1765 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1766 | { | |
645e77de | 1767 | int idx = 0, ret; |
86e8cf98 | 1768 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1769 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1770 | |
5fe231e8 | 1771 | rtnl_lock(); |
86e8cf98 JB |
1772 | if (!state) { |
1773 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1774 | if (!state) { |
1775 | rtnl_unlock(); | |
86e8cf98 | 1776 | return -ENOMEM; |
3713b4e3 | 1777 | } |
86e8cf98 JB |
1778 | state->filter_wiphy = -1; |
1779 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1780 | if (ret) { | |
1781 | kfree(state); | |
1782 | rtnl_unlock(); | |
1783 | return ret; | |
3713b4e3 | 1784 | } |
86e8cf98 | 1785 | cb->args[0] = (long)state; |
3713b4e3 JB |
1786 | } |
1787 | ||
1b8ec87a ZG |
1788 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1789 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1790 | continue; |
86e8cf98 | 1791 | if (++idx <= state->start) |
55682965 | 1792 | continue; |
86e8cf98 | 1793 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1794 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1795 | continue; |
1796 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1797 | do { | |
3bb20556 JB |
1798 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
1799 | skb, | |
3713b4e3 JB |
1800 | NETLINK_CB(cb->skb).portid, |
1801 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1802 | NLM_F_MULTI, state); |
3713b4e3 JB |
1803 | if (ret < 0) { |
1804 | /* | |
1805 | * If sending the wiphy data didn't fit (ENOBUFS | |
1806 | * or EMSGSIZE returned), this SKB is still | |
1807 | * empty (so it's not too big because another | |
1808 | * wiphy dataset is already in the skb) and | |
1809 | * we've not tried to adjust the dump allocation | |
1810 | * yet ... then adjust the alloc size to be | |
1811 | * bigger, and return 1 but with the empty skb. | |
1812 | * This results in an empty message being RX'ed | |
1813 | * in userspace, but that is ignored. | |
1814 | * | |
1815 | * We can then retry with the larger buffer. | |
1816 | */ | |
1817 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1818 | !skb->len && !state->split && |
3713b4e3 JB |
1819 | cb->min_dump_alloc < 4096) { |
1820 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1821 | state->split_start = 0; |
d98cae64 | 1822 | rtnl_unlock(); |
3713b4e3 JB |
1823 | return 1; |
1824 | } | |
1825 | idx--; | |
1826 | break; | |
645e77de | 1827 | } |
86e8cf98 | 1828 | } while (state->split_start > 0); |
3713b4e3 | 1829 | break; |
55682965 | 1830 | } |
5fe231e8 | 1831 | rtnl_unlock(); |
55682965 | 1832 | |
86e8cf98 | 1833 | state->start = idx; |
55682965 JB |
1834 | |
1835 | return skb->len; | |
1836 | } | |
1837 | ||
86e8cf98 JB |
1838 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1839 | { | |
1840 | kfree((void *)cb->args[0]); | |
1841 | return 0; | |
1842 | } | |
1843 | ||
55682965 JB |
1844 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1845 | { | |
1846 | struct sk_buff *msg; | |
1b8ec87a | 1847 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 1848 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1849 | |
645e77de | 1850 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1851 | if (!msg) |
4c476991 | 1852 | return -ENOMEM; |
55682965 | 1853 | |
3bb20556 JB |
1854 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
1855 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 1856 | &state) < 0) { |
4c476991 JB |
1857 | nlmsg_free(msg); |
1858 | return -ENOBUFS; | |
1859 | } | |
55682965 | 1860 | |
134e6375 | 1861 | return genlmsg_reply(msg, info); |
55682965 JB |
1862 | } |
1863 | ||
31888487 JM |
1864 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1865 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1866 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1867 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1868 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1869 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1870 | }; | |
1871 | ||
1872 | static int parse_txq_params(struct nlattr *tb[], | |
1873 | struct ieee80211_txq_params *txq_params) | |
1874 | { | |
a3304b0a | 1875 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1876 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1877 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1878 | return -EINVAL; | |
1879 | ||
a3304b0a | 1880 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1881 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1882 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1883 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1884 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1885 | ||
a3304b0a JB |
1886 | if (txq_params->ac >= NL80211_NUM_ACS) |
1887 | return -EINVAL; | |
1888 | ||
31888487 JM |
1889 | return 0; |
1890 | } | |
1891 | ||
f444de05 JB |
1892 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1893 | { | |
1894 | /* | |
cc1d2806 JB |
1895 | * You can only set the channel explicitly for WDS interfaces, |
1896 | * all others have their channel managed via their respective | |
1897 | * "establish a connection" command (connect, join, ...) | |
1898 | * | |
1899 | * For AP/GO and mesh mode, the channel can be set with the | |
1900 | * channel userspace API, but is only stored and passed to the | |
1901 | * low-level driver when the AP starts or the mesh is joined. | |
1902 | * This is for backward compatibility, userspace can also give | |
1903 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1904 | * |
1905 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1906 | * whatever else is going on, so they have their own special |
1907 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1908 | */ |
1909 | return !wdev || | |
1910 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1911 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1912 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1913 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1914 | } |
1915 | ||
683b6d3b JB |
1916 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1917 | struct genl_info *info, | |
1918 | struct cfg80211_chan_def *chandef) | |
1919 | { | |
dbeca2ea | 1920 | u32 control_freq; |
683b6d3b JB |
1921 | |
1922 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1923 | return -EINVAL; | |
1924 | ||
1925 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1926 | ||
1927 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1928 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1929 | chandef->center_freq1 = control_freq; | |
1930 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1931 | |
1932 | /* Primary channel not allowed */ | |
1933 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1934 | return -EINVAL; | |
1935 | ||
3d9d1d66 JB |
1936 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1937 | enum nl80211_channel_type chantype; | |
1938 | ||
1939 | chantype = nla_get_u32( | |
1940 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1941 | ||
1942 | switch (chantype) { | |
1943 | case NL80211_CHAN_NO_HT: | |
1944 | case NL80211_CHAN_HT20: | |
1945 | case NL80211_CHAN_HT40PLUS: | |
1946 | case NL80211_CHAN_HT40MINUS: | |
1947 | cfg80211_chandef_create(chandef, chandef->chan, | |
1948 | chantype); | |
1949 | break; | |
1950 | default: | |
1951 | return -EINVAL; | |
1952 | } | |
1953 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1954 | chandef->width = | |
1955 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1956 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1957 | chandef->center_freq1 = | |
1958 | nla_get_u32( | |
1959 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1960 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1961 | chandef->center_freq2 = | |
1962 | nla_get_u32( | |
1963 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1964 | } | |
1965 | ||
9f5e8f6e | 1966 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1967 | return -EINVAL; |
1968 | ||
9f5e8f6e JB |
1969 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1970 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1971 | return -EINVAL; |
1972 | ||
2f301ab2 SW |
1973 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1974 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1975 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1976 | return -EINVAL; | |
1977 | ||
683b6d3b JB |
1978 | return 0; |
1979 | } | |
1980 | ||
f444de05 | 1981 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 1982 | struct net_device *dev, |
f444de05 JB |
1983 | struct genl_info *info) |
1984 | { | |
683b6d3b | 1985 | struct cfg80211_chan_def chandef; |
f444de05 | 1986 | int result; |
e8c9bd5b | 1987 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 1988 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 1989 | |
e16821bc JM |
1990 | if (dev) |
1991 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
1992 | if (!nl80211_can_set_dev_channel(wdev)) |
1993 | return -EOPNOTSUPP; | |
e16821bc JM |
1994 | if (wdev) |
1995 | iftype = wdev->iftype; | |
f444de05 | 1996 | |
683b6d3b JB |
1997 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1998 | if (result) | |
1999 | return result; | |
f444de05 | 2000 | |
e8c9bd5b | 2001 | switch (iftype) { |
aa430da4 JB |
2002 | case NL80211_IFTYPE_AP: |
2003 | case NL80211_IFTYPE_P2P_GO: | |
174e0cd2 | 2004 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
aa430da4 JB |
2005 | result = -EINVAL; |
2006 | break; | |
2007 | } | |
e16821bc JM |
2008 | if (wdev->beacon_interval) { |
2009 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
2010 | !(rdev->wiphy.features & | |
2011 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
2012 | result = -EBUSY; | |
2013 | break; | |
2014 | } | |
2015 | ||
2016 | /* Only allow dynamic channel width changes */ | |
2017 | if (chandef.chan != wdev->preset_chandef.chan) { | |
2018 | result = -EBUSY; | |
2019 | break; | |
2020 | } | |
2021 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
2022 | if (result) | |
2023 | break; | |
2024 | } | |
683b6d3b | 2025 | wdev->preset_chandef = chandef; |
aa430da4 JB |
2026 | result = 0; |
2027 | break; | |
cc1d2806 | 2028 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 2029 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 2030 | break; |
e8c9bd5b | 2031 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 2032 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 2033 | break; |
aa430da4 | 2034 | default: |
e8c9bd5b | 2035 | result = -EINVAL; |
f444de05 | 2036 | } |
f444de05 JB |
2037 | |
2038 | return result; | |
2039 | } | |
2040 | ||
2041 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2042 | { | |
4c476991 JB |
2043 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2044 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2045 | |
e16821bc | 2046 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2047 | } |
2048 | ||
e8347eba BJ |
2049 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2050 | { | |
43b19952 JB |
2051 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2052 | struct net_device *dev = info->user_ptr[1]; | |
2053 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2054 | const u8 *bssid; |
e8347eba BJ |
2055 | |
2056 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2057 | return -EINVAL; | |
2058 | ||
43b19952 JB |
2059 | if (netif_running(dev)) |
2060 | return -EBUSY; | |
e8347eba | 2061 | |
43b19952 JB |
2062 | if (!rdev->ops->set_wds_peer) |
2063 | return -EOPNOTSUPP; | |
e8347eba | 2064 | |
43b19952 JB |
2065 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2066 | return -EOPNOTSUPP; | |
e8347eba BJ |
2067 | |
2068 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2069 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2070 | } |
2071 | ||
2072 | ||
55682965 JB |
2073 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2074 | { | |
2075 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2076 | struct net_device *netdev = NULL; |
2077 | struct wireless_dev *wdev; | |
a1e567c8 | 2078 | int result = 0, rem_txq_params = 0; |
31888487 | 2079 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2080 | u32 changed; |
2081 | u8 retry_short = 0, retry_long = 0; | |
2082 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2083 | u8 coverage_class = 0; |
55682965 | 2084 | |
5fe231e8 JB |
2085 | ASSERT_RTNL(); |
2086 | ||
f444de05 JB |
2087 | /* |
2088 | * Try to find the wiphy and netdev. Normally this | |
2089 | * function shouldn't need the netdev, but this is | |
2090 | * done for backward compatibility -- previously | |
2091 | * setting the channel was done per wiphy, but now | |
2092 | * it is per netdev. Previous userland like hostapd | |
2093 | * also passed a netdev to set_wiphy, so that it is | |
2094 | * possible to let that go to the right netdev! | |
2095 | */ | |
4bbf4d56 | 2096 | |
f444de05 JB |
2097 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2098 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2099 | ||
7f2b8562 | 2100 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2101 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2102 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2103 | else |
f444de05 | 2104 | netdev = NULL; |
4bbf4d56 JB |
2105 | } |
2106 | ||
f444de05 | 2107 | if (!netdev) { |
878d9ec7 JB |
2108 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2109 | info->attrs); | |
5fe231e8 | 2110 | if (IS_ERR(rdev)) |
4c476991 | 2111 | return PTR_ERR(rdev); |
f444de05 JB |
2112 | wdev = NULL; |
2113 | netdev = NULL; | |
2114 | result = 0; | |
71fe96bf | 2115 | } else |
f444de05 | 2116 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2117 | |
2118 | /* | |
2119 | * end workaround code, by now the rdev is available | |
2120 | * and locked, and wdev may or may not be NULL. | |
2121 | */ | |
4bbf4d56 JB |
2122 | |
2123 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2124 | result = cfg80211_dev_rename( |
2125 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2126 | |
4bbf4d56 | 2127 | if (result) |
7f2b8562 | 2128 | return result; |
31888487 JM |
2129 | |
2130 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2131 | struct ieee80211_txq_params txq_params; | |
2132 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2133 | ||
7f2b8562 YX |
2134 | if (!rdev->ops->set_txq_params) |
2135 | return -EOPNOTSUPP; | |
31888487 | 2136 | |
7f2b8562 YX |
2137 | if (!netdev) |
2138 | return -EINVAL; | |
f70f01c2 | 2139 | |
133a3ff2 | 2140 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2141 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2142 | return -EINVAL; | |
133a3ff2 | 2143 | |
7f2b8562 YX |
2144 | if (!netif_running(netdev)) |
2145 | return -ENETDOWN; | |
2b5f8b0b | 2146 | |
31888487 JM |
2147 | nla_for_each_nested(nl_txq_params, |
2148 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2149 | rem_txq_params) { | |
ae811e21 JB |
2150 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2151 | nla_data(nl_txq_params), | |
2152 | nla_len(nl_txq_params), | |
2153 | txq_params_policy); | |
2154 | if (result) | |
2155 | return result; | |
31888487 JM |
2156 | result = parse_txq_params(tb, &txq_params); |
2157 | if (result) | |
7f2b8562 | 2158 | return result; |
31888487 | 2159 | |
e35e4d28 HG |
2160 | result = rdev_set_txq_params(rdev, netdev, |
2161 | &txq_params); | |
31888487 | 2162 | if (result) |
7f2b8562 | 2163 | return result; |
31888487 JM |
2164 | } |
2165 | } | |
55682965 | 2166 | |
72bdcf34 | 2167 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2168 | result = __nl80211_set_channel( |
2169 | rdev, | |
2170 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2171 | info); | |
72bdcf34 | 2172 | if (result) |
7f2b8562 | 2173 | return result; |
72bdcf34 JM |
2174 | } |
2175 | ||
98d2ff8b | 2176 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2177 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2178 | enum nl80211_tx_power_setting type; |
2179 | int idx, mbm = 0; | |
2180 | ||
c8442118 JB |
2181 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2182 | txp_wdev = NULL; | |
2183 | ||
7f2b8562 YX |
2184 | if (!rdev->ops->set_tx_power) |
2185 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2186 | |
2187 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2188 | type = nla_get_u32(info->attrs[idx]); | |
2189 | ||
2190 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2191 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2192 | return -EINVAL; | |
98d2ff8b JO |
2193 | |
2194 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2195 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2196 | mbm = nla_get_u32(info->attrs[idx]); | |
2197 | } | |
2198 | ||
c8442118 | 2199 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2200 | if (result) |
7f2b8562 | 2201 | return result; |
98d2ff8b JO |
2202 | } |
2203 | ||
afe0cbf8 BR |
2204 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2205 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2206 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2207 | if ((!rdev->wiphy.available_antennas_tx && |
2208 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2209 | !rdev->ops->set_antenna) |
2210 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2211 | |
2212 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2213 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2214 | ||
a7ffac95 | 2215 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2216 | * available antenna masks, except for the "all" mask */ |
2217 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2218 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2219 | return -EINVAL; | |
a7ffac95 | 2220 | |
7f531e03 BR |
2221 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2222 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2223 | |
e35e4d28 | 2224 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2225 | if (result) |
7f2b8562 | 2226 | return result; |
afe0cbf8 BR |
2227 | } |
2228 | ||
b9a5f8ca JM |
2229 | changed = 0; |
2230 | ||
2231 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2232 | retry_short = nla_get_u8( | |
2233 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2234 | if (retry_short == 0) |
2235 | return -EINVAL; | |
2236 | ||
b9a5f8ca JM |
2237 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2238 | } | |
2239 | ||
2240 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2241 | retry_long = nla_get_u8( | |
2242 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2243 | if (retry_long == 0) |
2244 | return -EINVAL; | |
2245 | ||
b9a5f8ca JM |
2246 | changed |= WIPHY_PARAM_RETRY_LONG; |
2247 | } | |
2248 | ||
2249 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2250 | frag_threshold = nla_get_u32( | |
2251 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2252 | if (frag_threshold < 256) |
2253 | return -EINVAL; | |
2254 | ||
b9a5f8ca JM |
2255 | if (frag_threshold != (u32) -1) { |
2256 | /* | |
2257 | * Fragments (apart from the last one) are required to | |
2258 | * have even length. Make the fragmentation code | |
2259 | * simpler by stripping LSB should someone try to use | |
2260 | * odd threshold value. | |
2261 | */ | |
2262 | frag_threshold &= ~0x1; | |
2263 | } | |
2264 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2265 | } | |
2266 | ||
2267 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2268 | rts_threshold = nla_get_u32( | |
2269 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2270 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2271 | } | |
2272 | ||
81077e82 | 2273 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
3057dbfd LB |
2274 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
2275 | return -EINVAL; | |
2276 | ||
81077e82 LT |
2277 | coverage_class = nla_get_u8( |
2278 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2279 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2280 | } | |
2281 | ||
3057dbfd LB |
2282 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
2283 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | |
2284 | return -EOPNOTSUPP; | |
2285 | ||
2286 | changed |= WIPHY_PARAM_DYN_ACK; | |
81077e82 LT |
2287 | } |
2288 | ||
b9a5f8ca JM |
2289 | if (changed) { |
2290 | u8 old_retry_short, old_retry_long; | |
2291 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2292 | u8 old_coverage_class; |
b9a5f8ca | 2293 | |
7f2b8562 YX |
2294 | if (!rdev->ops->set_wiphy_params) |
2295 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2296 | |
2297 | old_retry_short = rdev->wiphy.retry_short; | |
2298 | old_retry_long = rdev->wiphy.retry_long; | |
2299 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2300 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2301 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2302 | |
2303 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2304 | rdev->wiphy.retry_short = retry_short; | |
2305 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2306 | rdev->wiphy.retry_long = retry_long; | |
2307 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2308 | rdev->wiphy.frag_threshold = frag_threshold; | |
2309 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2310 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2311 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2312 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2313 | |
e35e4d28 | 2314 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2315 | if (result) { |
2316 | rdev->wiphy.retry_short = old_retry_short; | |
2317 | rdev->wiphy.retry_long = old_retry_long; | |
2318 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2319 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2320 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2321 | } |
2322 | } | |
7f2b8562 | 2323 | return 0; |
55682965 JB |
2324 | } |
2325 | ||
71bbc994 JB |
2326 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2327 | { | |
2328 | return (u64)wdev->identifier | | |
f26cbf40 | 2329 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2330 | } |
55682965 | 2331 | |
683b6d3b | 2332 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2333 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2334 | { |
601555cd JB |
2335 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
2336 | return -EINVAL; | |
3d9d1d66 | 2337 | |
683b6d3b JB |
2338 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2339 | chandef->chan->center_freq)) | |
2340 | return -ENOBUFS; | |
3d9d1d66 JB |
2341 | switch (chandef->width) { |
2342 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2343 | case NL80211_CHAN_WIDTH_20: | |
2344 | case NL80211_CHAN_WIDTH_40: | |
2345 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2346 | cfg80211_get_chandef_type(chandef))) | |
2347 | return -ENOBUFS; | |
2348 | break; | |
2349 | default: | |
2350 | break; | |
2351 | } | |
2352 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2353 | return -ENOBUFS; | |
2354 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2355 | return -ENOBUFS; | |
2356 | if (chandef->center_freq2 && | |
2357 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2358 | return -ENOBUFS; |
2359 | return 0; | |
2360 | } | |
2361 | ||
15e47304 | 2362 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2363 | struct cfg80211_registered_device *rdev, |
8f894be2 | 2364 | struct wireless_dev *wdev, bool removal) |
55682965 | 2365 | { |
72fb2abc | 2366 | struct net_device *dev = wdev->netdev; |
8f894be2 | 2367 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
55682965 JB |
2368 | void *hdr; |
2369 | ||
8f894be2 TB |
2370 | if (removal) |
2371 | cmd = NL80211_CMD_DEL_INTERFACE; | |
2372 | ||
2373 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | |
55682965 JB |
2374 | if (!hdr) |
2375 | return -1; | |
2376 | ||
72fb2abc JB |
2377 | if (dev && |
2378 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2379 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2380 | goto nla_put_failure; |
2381 | ||
2382 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2383 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2384 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2385 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2386 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2387 | rdev->devlist_generation ^ | |
2388 | (cfg80211_rdev_list_generation << 2))) | |
2389 | goto nla_put_failure; | |
f5ea9120 | 2390 | |
5b7ccaf3 | 2391 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2392 | int ret; |
2393 | struct cfg80211_chan_def chandef; | |
2394 | ||
2395 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2396 | if (ret == 0) { | |
2397 | if (nl80211_send_chandef(msg, &chandef)) | |
2398 | goto nla_put_failure; | |
2399 | } | |
d91df0e3 PF |
2400 | } |
2401 | ||
b84e7a05 AQ |
2402 | if (wdev->ssid_len) { |
2403 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2404 | goto nla_put_failure; | |
2405 | } | |
2406 | ||
55682965 JB |
2407 | return genlmsg_end(msg, hdr); |
2408 | ||
2409 | nla_put_failure: | |
bc3ed28c TG |
2410 | genlmsg_cancel(msg, hdr); |
2411 | return -EMSGSIZE; | |
55682965 JB |
2412 | } |
2413 | ||
2414 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2415 | { | |
2416 | int wp_idx = 0; | |
2417 | int if_idx = 0; | |
2418 | int wp_start = cb->args[0]; | |
2419 | int if_start = cb->args[1]; | |
f5ea9120 | 2420 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2421 | struct wireless_dev *wdev; |
2422 | ||
5fe231e8 | 2423 | rtnl_lock(); |
f5ea9120 JB |
2424 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2425 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2426 | continue; |
bba95fef JB |
2427 | if (wp_idx < wp_start) { |
2428 | wp_idx++; | |
55682965 | 2429 | continue; |
bba95fef | 2430 | } |
55682965 JB |
2431 | if_idx = 0; |
2432 | ||
89a54e48 | 2433 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2434 | if (if_idx < if_start) { |
2435 | if_idx++; | |
55682965 | 2436 | continue; |
bba95fef | 2437 | } |
15e47304 | 2438 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2439 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
8f894be2 | 2440 | rdev, wdev, false) < 0) { |
bba95fef JB |
2441 | goto out; |
2442 | } | |
2443 | if_idx++; | |
55682965 | 2444 | } |
bba95fef JB |
2445 | |
2446 | wp_idx++; | |
55682965 | 2447 | } |
bba95fef | 2448 | out: |
5fe231e8 | 2449 | rtnl_unlock(); |
55682965 JB |
2450 | |
2451 | cb->args[0] = wp_idx; | |
2452 | cb->args[1] = if_idx; | |
2453 | ||
2454 | return skb->len; | |
2455 | } | |
2456 | ||
2457 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2458 | { | |
2459 | struct sk_buff *msg; | |
1b8ec87a | 2460 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2461 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2462 | |
fd2120ca | 2463 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2464 | if (!msg) |
4c476991 | 2465 | return -ENOMEM; |
55682965 | 2466 | |
15e47304 | 2467 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2468 | rdev, wdev, false) < 0) { |
4c476991 JB |
2469 | nlmsg_free(msg); |
2470 | return -ENOBUFS; | |
2471 | } | |
55682965 | 2472 | |
134e6375 | 2473 | return genlmsg_reply(msg, info); |
55682965 JB |
2474 | } |
2475 | ||
66f7ac50 MW |
2476 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2477 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2478 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2479 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2480 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2481 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2482 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2483 | }; |
2484 | ||
2485 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2486 | { | |
2487 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2488 | int flag; | |
2489 | ||
2490 | *mntrflags = 0; | |
2491 | ||
2492 | if (!nla) | |
2493 | return -EINVAL; | |
2494 | ||
2495 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2496 | nla, mntr_flags_policy)) | |
2497 | return -EINVAL; | |
2498 | ||
2499 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2500 | if (flags[flag]) | |
2501 | *mntrflags |= (1<<flag); | |
2502 | ||
2503 | return 0; | |
2504 | } | |
2505 | ||
9bc383de | 2506 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2507 | struct net_device *netdev, u8 use_4addr, |
2508 | enum nl80211_iftype iftype) | |
9bc383de | 2509 | { |
ad4bb6f8 | 2510 | if (!use_4addr) { |
f350a0a8 | 2511 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2512 | return -EBUSY; |
9bc383de | 2513 | return 0; |
ad4bb6f8 | 2514 | } |
9bc383de JB |
2515 | |
2516 | switch (iftype) { | |
2517 | case NL80211_IFTYPE_AP_VLAN: | |
2518 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2519 | return 0; | |
2520 | break; | |
2521 | case NL80211_IFTYPE_STATION: | |
2522 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2523 | return 0; | |
2524 | break; | |
2525 | default: | |
2526 | break; | |
2527 | } | |
2528 | ||
2529 | return -EOPNOTSUPP; | |
2530 | } | |
2531 | ||
55682965 JB |
2532 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2533 | { | |
4c476991 | 2534 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2535 | struct vif_params params; |
e36d56b6 | 2536 | int err; |
04a773ad | 2537 | enum nl80211_iftype otype, ntype; |
4c476991 | 2538 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2539 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2540 | bool change = false; |
55682965 | 2541 | |
2ec600d6 LCC |
2542 | memset(¶ms, 0, sizeof(params)); |
2543 | ||
04a773ad | 2544 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2545 | |
723b038d | 2546 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2547 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2548 | if (otype != ntype) |
ac7f9cfa | 2549 | change = true; |
4c476991 JB |
2550 | if (ntype > NL80211_IFTYPE_MAX) |
2551 | return -EINVAL; | |
723b038d JB |
2552 | } |
2553 | ||
92ffe055 | 2554 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2555 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2556 | ||
4c476991 JB |
2557 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2558 | return -EINVAL; | |
29cbe68c JB |
2559 | if (netif_running(dev)) |
2560 | return -EBUSY; | |
2561 | ||
2562 | wdev_lock(wdev); | |
2563 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2564 | IEEE80211_MAX_MESH_ID_LEN); | |
2565 | wdev->mesh_id_up_len = | |
2566 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2567 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2568 | wdev->mesh_id_up_len); | |
2569 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2570 | } |
2571 | ||
8b787643 FF |
2572 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2573 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2574 | change = true; | |
ad4bb6f8 | 2575 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2576 | if (err) |
4c476991 | 2577 | return err; |
8b787643 FF |
2578 | } else { |
2579 | params.use_4addr = -1; | |
2580 | } | |
2581 | ||
92ffe055 | 2582 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2583 | if (ntype != NL80211_IFTYPE_MONITOR) |
2584 | return -EINVAL; | |
92ffe055 JB |
2585 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2586 | &_flags); | |
ac7f9cfa | 2587 | if (err) |
4c476991 | 2588 | return err; |
ac7f9cfa JB |
2589 | |
2590 | flags = &_flags; | |
2591 | change = true; | |
92ffe055 | 2592 | } |
3b85875a | 2593 | |
18003297 | 2594 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2595 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2596 | return -EOPNOTSUPP; | |
2597 | ||
ac7f9cfa | 2598 | if (change) |
3d54d255 | 2599 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2600 | else |
2601 | err = 0; | |
60719ffd | 2602 | |
9bc383de JB |
2603 | if (!err && params.use_4addr != -1) |
2604 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2605 | ||
55682965 JB |
2606 | return err; |
2607 | } | |
2608 | ||
2609 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2610 | { | |
4c476991 | 2611 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2612 | struct vif_params params; |
84efbb84 | 2613 | struct wireless_dev *wdev; |
8f894be2 | 2614 | struct sk_buff *msg, *event; |
55682965 JB |
2615 | int err; |
2616 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2617 | u32 flags; |
55682965 | 2618 | |
78f22b6a JB |
2619 | /* to avoid failing a new interface creation due to pending removal */ |
2620 | cfg80211_destroy_ifaces(rdev); | |
2621 | ||
2ec600d6 LCC |
2622 | memset(¶ms, 0, sizeof(params)); |
2623 | ||
55682965 JB |
2624 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2625 | return -EINVAL; | |
2626 | ||
2627 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2628 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2629 | if (type > NL80211_IFTYPE_MAX) | |
2630 | return -EINVAL; | |
2631 | } | |
2632 | ||
79c97e97 | 2633 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2634 | !(rdev->wiphy.interface_modes & (1 << type))) |
2635 | return -EOPNOTSUPP; | |
55682965 | 2636 | |
e8f479b1 BG |
2637 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
2638 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && | |
2639 | info->attrs[NL80211_ATTR_MAC]) { | |
1c18f145 AS |
2640 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
2641 | ETH_ALEN); | |
2642 | if (!is_valid_ether_addr(params.macaddr)) | |
2643 | return -EADDRNOTAVAIL; | |
2644 | } | |
2645 | ||
9bc383de | 2646 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2647 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2648 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2649 | if (err) |
4c476991 | 2650 | return err; |
9bc383de | 2651 | } |
8b787643 | 2652 | |
1c90f9d4 JB |
2653 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2654 | if (!msg) | |
2655 | return -ENOMEM; | |
2656 | ||
66f7ac50 MW |
2657 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2658 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2659 | &flags); | |
e057d3c3 | 2660 | |
18003297 | 2661 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2662 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2663 | return -EOPNOTSUPP; | |
2664 | ||
e35e4d28 HG |
2665 | wdev = rdev_add_virtual_intf(rdev, |
2666 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2667 | type, err ? NULL : &flags, ¶ms); | |
d687cbb7 RM |
2668 | if (WARN_ON(!wdev)) { |
2669 | nlmsg_free(msg); | |
2670 | return -EPROTO; | |
2671 | } else if (IS_ERR(wdev)) { | |
1c90f9d4 | 2672 | nlmsg_free(msg); |
84efbb84 | 2673 | return PTR_ERR(wdev); |
1c90f9d4 | 2674 | } |
2ec600d6 | 2675 | |
18e5ca65 | 2676 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
78f22b6a JB |
2677 | wdev->owner_nlportid = info->snd_portid; |
2678 | ||
98104fde JB |
2679 | switch (type) { |
2680 | case NL80211_IFTYPE_MESH_POINT: | |
2681 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2682 | break; | |
29cbe68c JB |
2683 | wdev_lock(wdev); |
2684 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2685 | IEEE80211_MAX_MESH_ID_LEN); | |
2686 | wdev->mesh_id_up_len = | |
2687 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2688 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2689 | wdev->mesh_id_up_len); | |
2690 | wdev_unlock(wdev); | |
98104fde JB |
2691 | break; |
2692 | case NL80211_IFTYPE_P2P_DEVICE: | |
2693 | /* | |
2694 | * P2P Device doesn't have a netdev, so doesn't go | |
2695 | * through the netdev notifier and must be added here | |
2696 | */ | |
2697 | mutex_init(&wdev->mtx); | |
2698 | INIT_LIST_HEAD(&wdev->event_list); | |
2699 | spin_lock_init(&wdev->event_lock); | |
2700 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2701 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2702 | ||
98104fde JB |
2703 | wdev->identifier = ++rdev->wdev_id; |
2704 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2705 | rdev->devlist_generation++; | |
98104fde JB |
2706 | break; |
2707 | default: | |
2708 | break; | |
29cbe68c JB |
2709 | } |
2710 | ||
15e47304 | 2711 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2712 | rdev, wdev, false) < 0) { |
1c90f9d4 JB |
2713 | nlmsg_free(msg); |
2714 | return -ENOBUFS; | |
2715 | } | |
2716 | ||
8f894be2 TB |
2717 | event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2718 | if (event) { | |
2719 | if (nl80211_send_iface(event, 0, 0, 0, | |
2720 | rdev, wdev, false) < 0) { | |
2721 | nlmsg_free(event); | |
2722 | goto out; | |
2723 | } | |
2724 | ||
2725 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
2726 | event, 0, NL80211_MCGRP_CONFIG, | |
2727 | GFP_KERNEL); | |
2728 | } | |
2729 | ||
2730 | out: | |
1c90f9d4 | 2731 | return genlmsg_reply(msg, info); |
55682965 JB |
2732 | } |
2733 | ||
2734 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2735 | { | |
4c476991 | 2736 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2737 | struct wireless_dev *wdev = info->user_ptr[1]; |
8f894be2 TB |
2738 | struct sk_buff *msg; |
2739 | int status; | |
55682965 | 2740 | |
4c476991 JB |
2741 | if (!rdev->ops->del_virtual_intf) |
2742 | return -EOPNOTSUPP; | |
55682965 | 2743 | |
8f894be2 TB |
2744 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2745 | if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) { | |
2746 | nlmsg_free(msg); | |
2747 | msg = NULL; | |
2748 | } | |
2749 | ||
84efbb84 JB |
2750 | /* |
2751 | * If we remove a wireless device without a netdev then clear | |
2752 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2753 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2754 | * since the wdev has been freed, unlike with a netdev where | |
2755 | * we need the dev_put() for the netdev to really be freed. | |
2756 | */ | |
2757 | if (!wdev->netdev) | |
2758 | info->user_ptr[1] = NULL; | |
2759 | ||
8f894be2 TB |
2760 | status = rdev_del_virtual_intf(rdev, wdev); |
2761 | if (status >= 0 && msg) | |
2762 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
2763 | msg, 0, NL80211_MCGRP_CONFIG, | |
2764 | GFP_KERNEL); | |
2765 | else | |
2766 | nlmsg_free(msg); | |
2767 | ||
2768 | return status; | |
55682965 JB |
2769 | } |
2770 | ||
1d9d9213 SW |
2771 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2772 | { | |
2773 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2774 | struct net_device *dev = info->user_ptr[1]; | |
2775 | u16 noack_map; | |
2776 | ||
2777 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2778 | return -EINVAL; | |
2779 | ||
2780 | if (!rdev->ops->set_noack_map) | |
2781 | return -EOPNOTSUPP; | |
2782 | ||
2783 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2784 | ||
e35e4d28 | 2785 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2786 | } |
2787 | ||
41ade00f JB |
2788 | struct get_key_cookie { |
2789 | struct sk_buff *msg; | |
2790 | int error; | |
b9454e83 | 2791 | int idx; |
41ade00f JB |
2792 | }; |
2793 | ||
2794 | static void get_key_callback(void *c, struct key_params *params) | |
2795 | { | |
b9454e83 | 2796 | struct nlattr *key; |
41ade00f JB |
2797 | struct get_key_cookie *cookie = c; |
2798 | ||
9360ffd1 DM |
2799 | if ((params->key && |
2800 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2801 | params->key_len, params->key)) || | |
2802 | (params->seq && | |
2803 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2804 | params->seq_len, params->seq)) || | |
2805 | (params->cipher && | |
2806 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2807 | params->cipher))) | |
2808 | goto nla_put_failure; | |
41ade00f | 2809 | |
b9454e83 JB |
2810 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2811 | if (!key) | |
2812 | goto nla_put_failure; | |
2813 | ||
9360ffd1 DM |
2814 | if ((params->key && |
2815 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2816 | params->key_len, params->key)) || | |
2817 | (params->seq && | |
2818 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2819 | params->seq_len, params->seq)) || | |
2820 | (params->cipher && | |
2821 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2822 | params->cipher))) | |
2823 | goto nla_put_failure; | |
b9454e83 | 2824 | |
9360ffd1 DM |
2825 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2826 | goto nla_put_failure; | |
b9454e83 JB |
2827 | |
2828 | nla_nest_end(cookie->msg, key); | |
2829 | ||
41ade00f JB |
2830 | return; |
2831 | nla_put_failure: | |
2832 | cookie->error = 1; | |
2833 | } | |
2834 | ||
2835 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2836 | { | |
4c476991 | 2837 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2838 | int err; |
4c476991 | 2839 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2840 | u8 key_idx = 0; |
e31b8213 JB |
2841 | const u8 *mac_addr = NULL; |
2842 | bool pairwise; | |
41ade00f JB |
2843 | struct get_key_cookie cookie = { |
2844 | .error = 0, | |
2845 | }; | |
2846 | void *hdr; | |
2847 | struct sk_buff *msg; | |
2848 | ||
2849 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2850 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2851 | ||
3cfcf6ac | 2852 | if (key_idx > 5) |
41ade00f JB |
2853 | return -EINVAL; |
2854 | ||
2855 | if (info->attrs[NL80211_ATTR_MAC]) | |
2856 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2857 | ||
e31b8213 JB |
2858 | pairwise = !!mac_addr; |
2859 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2860 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2861 | if (kt >= NUM_NL80211_KEYTYPES) | |
2862 | return -EINVAL; | |
2863 | if (kt != NL80211_KEYTYPE_GROUP && | |
2864 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2865 | return -EINVAL; | |
2866 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2867 | } | |
2868 | ||
4c476991 JB |
2869 | if (!rdev->ops->get_key) |
2870 | return -EOPNOTSUPP; | |
41ade00f | 2871 | |
fd2120ca | 2872 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2873 | if (!msg) |
2874 | return -ENOMEM; | |
41ade00f | 2875 | |
15e47304 | 2876 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2877 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 2878 | if (!hdr) |
9fe271af | 2879 | goto nla_put_failure; |
41ade00f JB |
2880 | |
2881 | cookie.msg = msg; | |
b9454e83 | 2882 | cookie.idx = key_idx; |
41ade00f | 2883 | |
9360ffd1 DM |
2884 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2885 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2886 | goto nla_put_failure; | |
2887 | if (mac_addr && | |
2888 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2889 | goto nla_put_failure; | |
41ade00f | 2890 | |
e31b8213 JB |
2891 | if (pairwise && mac_addr && |
2892 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2893 | return -ENOENT; | |
2894 | ||
e35e4d28 HG |
2895 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2896 | get_key_callback); | |
41ade00f JB |
2897 | |
2898 | if (err) | |
6c95e2a2 | 2899 | goto free_msg; |
41ade00f JB |
2900 | |
2901 | if (cookie.error) | |
2902 | goto nla_put_failure; | |
2903 | ||
2904 | genlmsg_end(msg, hdr); | |
4c476991 | 2905 | return genlmsg_reply(msg, info); |
41ade00f JB |
2906 | |
2907 | nla_put_failure: | |
2908 | err = -ENOBUFS; | |
6c95e2a2 | 2909 | free_msg: |
41ade00f | 2910 | nlmsg_free(msg); |
41ade00f JB |
2911 | return err; |
2912 | } | |
2913 | ||
2914 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2915 | { | |
4c476991 | 2916 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2917 | struct key_parse key; |
41ade00f | 2918 | int err; |
4c476991 | 2919 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2920 | |
b9454e83 JB |
2921 | err = nl80211_parse_key(info, &key); |
2922 | if (err) | |
2923 | return err; | |
41ade00f | 2924 | |
b9454e83 | 2925 | if (key.idx < 0) |
41ade00f JB |
2926 | return -EINVAL; |
2927 | ||
b9454e83 JB |
2928 | /* only support setting default key */ |
2929 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2930 | return -EINVAL; |
2931 | ||
dbd2fd65 | 2932 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2933 | |
dbd2fd65 JB |
2934 | if (key.def) { |
2935 | if (!rdev->ops->set_default_key) { | |
2936 | err = -EOPNOTSUPP; | |
2937 | goto out; | |
2938 | } | |
41ade00f | 2939 | |
dbd2fd65 JB |
2940 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2941 | if (err) | |
2942 | goto out; | |
2943 | ||
e35e4d28 | 2944 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2945 | key.def_uni, key.def_multi); |
2946 | ||
2947 | if (err) | |
2948 | goto out; | |
fffd0934 | 2949 | |
3d23e349 | 2950 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2951 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2952 | #endif | |
2953 | } else { | |
2954 | if (key.def_uni || !key.def_multi) { | |
2955 | err = -EINVAL; | |
2956 | goto out; | |
2957 | } | |
2958 | ||
2959 | if (!rdev->ops->set_default_mgmt_key) { | |
2960 | err = -EOPNOTSUPP; | |
2961 | goto out; | |
2962 | } | |
2963 | ||
2964 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2965 | if (err) | |
2966 | goto out; | |
2967 | ||
e35e4d28 | 2968 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2969 | if (err) |
2970 | goto out; | |
2971 | ||
2972 | #ifdef CONFIG_CFG80211_WEXT | |
2973 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2974 | #endif |
dbd2fd65 JB |
2975 | } |
2976 | ||
2977 | out: | |
fffd0934 | 2978 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2979 | |
41ade00f JB |
2980 | return err; |
2981 | } | |
2982 | ||
2983 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2984 | { | |
4c476991 | 2985 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2986 | int err; |
4c476991 | 2987 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2988 | struct key_parse key; |
e31b8213 | 2989 | const u8 *mac_addr = NULL; |
41ade00f | 2990 | |
b9454e83 JB |
2991 | err = nl80211_parse_key(info, &key); |
2992 | if (err) | |
2993 | return err; | |
41ade00f | 2994 | |
b9454e83 | 2995 | if (!key.p.key) |
41ade00f JB |
2996 | return -EINVAL; |
2997 | ||
41ade00f JB |
2998 | if (info->attrs[NL80211_ATTR_MAC]) |
2999 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3000 | ||
e31b8213 JB |
3001 | if (key.type == -1) { |
3002 | if (mac_addr) | |
3003 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3004 | else | |
3005 | key.type = NL80211_KEYTYPE_GROUP; | |
3006 | } | |
3007 | ||
3008 | /* for now */ | |
3009 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3010 | key.type != NL80211_KEYTYPE_GROUP) | |
3011 | return -EINVAL; | |
3012 | ||
4c476991 JB |
3013 | if (!rdev->ops->add_key) |
3014 | return -EOPNOTSUPP; | |
25e47c18 | 3015 | |
e31b8213 JB |
3016 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
3017 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3018 | mac_addr)) | |
4c476991 | 3019 | return -EINVAL; |
41ade00f | 3020 | |
fffd0934 JB |
3021 | wdev_lock(dev->ieee80211_ptr); |
3022 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3023 | if (!err) | |
e35e4d28 HG |
3024 | err = rdev_add_key(rdev, dev, key.idx, |
3025 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3026 | mac_addr, &key.p); | |
fffd0934 | 3027 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3028 | |
41ade00f JB |
3029 | return err; |
3030 | } | |
3031 | ||
3032 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
3033 | { | |
4c476991 | 3034 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3035 | int err; |
4c476991 | 3036 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3037 | u8 *mac_addr = NULL; |
b9454e83 | 3038 | struct key_parse key; |
41ade00f | 3039 | |
b9454e83 JB |
3040 | err = nl80211_parse_key(info, &key); |
3041 | if (err) | |
3042 | return err; | |
41ade00f JB |
3043 | |
3044 | if (info->attrs[NL80211_ATTR_MAC]) | |
3045 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3046 | ||
e31b8213 JB |
3047 | if (key.type == -1) { |
3048 | if (mac_addr) | |
3049 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3050 | else | |
3051 | key.type = NL80211_KEYTYPE_GROUP; | |
3052 | } | |
3053 | ||
3054 | /* for now */ | |
3055 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3056 | key.type != NL80211_KEYTYPE_GROUP) | |
3057 | return -EINVAL; | |
3058 | ||
4c476991 JB |
3059 | if (!rdev->ops->del_key) |
3060 | return -EOPNOTSUPP; | |
41ade00f | 3061 | |
fffd0934 JB |
3062 | wdev_lock(dev->ieee80211_ptr); |
3063 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
3064 | |
3065 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
3066 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
3067 | err = -ENOENT; | |
3068 | ||
fffd0934 | 3069 | if (!err) |
e35e4d28 HG |
3070 | err = rdev_del_key(rdev, dev, key.idx, |
3071 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3072 | mac_addr); | |
41ade00f | 3073 | |
3d23e349 | 3074 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 3075 | if (!err) { |
b9454e83 | 3076 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 3077 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 3078 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
3079 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
3080 | } | |
3081 | #endif | |
fffd0934 | 3082 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 3083 | |
41ade00f JB |
3084 | return err; |
3085 | } | |
3086 | ||
77765eaf VT |
3087 | /* This function returns an error or the number of nested attributes */ |
3088 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
3089 | { | |
3090 | struct nlattr *attr; | |
3091 | int n_entries = 0, tmp; | |
3092 | ||
3093 | nla_for_each_nested(attr, nl_attr, tmp) { | |
3094 | if (nla_len(attr) != ETH_ALEN) | |
3095 | return -EINVAL; | |
3096 | ||
3097 | n_entries++; | |
3098 | } | |
3099 | ||
3100 | return n_entries; | |
3101 | } | |
3102 | ||
3103 | /* | |
3104 | * This function parses ACL information and allocates memory for ACL data. | |
3105 | * On successful return, the calling function is responsible to free the | |
3106 | * ACL buffer returned by this function. | |
3107 | */ | |
3108 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3109 | struct genl_info *info) | |
3110 | { | |
3111 | enum nl80211_acl_policy acl_policy; | |
3112 | struct nlattr *attr; | |
3113 | struct cfg80211_acl_data *acl; | |
3114 | int i = 0, n_entries, tmp; | |
3115 | ||
3116 | if (!wiphy->max_acl_mac_addrs) | |
3117 | return ERR_PTR(-EOPNOTSUPP); | |
3118 | ||
3119 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3120 | return ERR_PTR(-EINVAL); | |
3121 | ||
3122 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3123 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3124 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3125 | return ERR_PTR(-EINVAL); | |
3126 | ||
3127 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3128 | return ERR_PTR(-EINVAL); | |
3129 | ||
3130 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3131 | if (n_entries < 0) | |
3132 | return ERR_PTR(n_entries); | |
3133 | ||
3134 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3135 | return ERR_PTR(-ENOTSUPP); | |
3136 | ||
3137 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
3138 | GFP_KERNEL); | |
3139 | if (!acl) | |
3140 | return ERR_PTR(-ENOMEM); | |
3141 | ||
3142 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3143 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3144 | i++; | |
3145 | } | |
3146 | ||
3147 | acl->n_acl_entries = n_entries; | |
3148 | acl->acl_policy = acl_policy; | |
3149 | ||
3150 | return acl; | |
3151 | } | |
3152 | ||
3153 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3154 | { | |
3155 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3156 | struct net_device *dev = info->user_ptr[1]; | |
3157 | struct cfg80211_acl_data *acl; | |
3158 | int err; | |
3159 | ||
3160 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3161 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3162 | return -EOPNOTSUPP; | |
3163 | ||
3164 | if (!dev->ieee80211_ptr->beacon_interval) | |
3165 | return -EINVAL; | |
3166 | ||
3167 | acl = parse_acl_data(&rdev->wiphy, info); | |
3168 | if (IS_ERR(acl)) | |
3169 | return PTR_ERR(acl); | |
3170 | ||
3171 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3172 | ||
3173 | kfree(acl); | |
3174 | ||
3175 | return err; | |
3176 | } | |
3177 | ||
a1193be8 | 3178 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3179 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3180 | { |
8860020e | 3181 | bool haveinfo = false; |
ed1b6cc7 | 3182 | |
a1193be8 SW |
3183 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3184 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3185 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3186 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3187 | return -EINVAL; |
3188 | ||
8860020e | 3189 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3190 | |
a1193be8 SW |
3191 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3192 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3193 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3194 | if (!bcn->head_len) |
3195 | return -EINVAL; | |
3196 | haveinfo = true; | |
ed1b6cc7 JB |
3197 | } |
3198 | ||
a1193be8 SW |
3199 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3200 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3201 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3202 | haveinfo = true; |
ed1b6cc7 JB |
3203 | } |
3204 | ||
4c476991 JB |
3205 | if (!haveinfo) |
3206 | return -EINVAL; | |
3b85875a | 3207 | |
a1193be8 SW |
3208 | if (attrs[NL80211_ATTR_IE]) { |
3209 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3210 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3211 | } |
3212 | ||
a1193be8 | 3213 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3214 | bcn->proberesp_ies = |
a1193be8 | 3215 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3216 | bcn->proberesp_ies_len = |
a1193be8 | 3217 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3218 | } |
3219 | ||
a1193be8 | 3220 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3221 | bcn->assocresp_ies = |
a1193be8 | 3222 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3223 | bcn->assocresp_ies_len = |
a1193be8 | 3224 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3225 | } |
3226 | ||
a1193be8 SW |
3227 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3228 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3229 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3230 | } |
3231 | ||
8860020e JB |
3232 | return 0; |
3233 | } | |
3234 | ||
46c1dd0c FF |
3235 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3236 | struct cfg80211_ap_settings *params) | |
3237 | { | |
3238 | struct wireless_dev *wdev; | |
3239 | bool ret = false; | |
3240 | ||
89a54e48 | 3241 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3242 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3243 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3244 | continue; | |
3245 | ||
683b6d3b | 3246 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3247 | continue; |
3248 | ||
683b6d3b | 3249 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3250 | ret = true; |
3251 | break; | |
3252 | } | |
3253 | ||
46c1dd0c FF |
3254 | return ret; |
3255 | } | |
3256 | ||
e39e5b5e JM |
3257 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3258 | enum nl80211_auth_type auth_type, | |
3259 | enum nl80211_commands cmd) | |
3260 | { | |
3261 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3262 | return false; | |
3263 | ||
3264 | switch (cmd) { | |
3265 | case NL80211_CMD_AUTHENTICATE: | |
3266 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3267 | auth_type == NL80211_AUTHTYPE_SAE) | |
3268 | return false; | |
3269 | return true; | |
3270 | case NL80211_CMD_CONNECT: | |
3271 | case NL80211_CMD_START_AP: | |
3272 | /* SAE not supported yet */ | |
3273 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3274 | return false; | |
3275 | return true; | |
3276 | default: | |
3277 | return false; | |
3278 | } | |
3279 | } | |
3280 | ||
8860020e JB |
3281 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3282 | { | |
3283 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3284 | struct net_device *dev = info->user_ptr[1]; | |
3285 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3286 | struct cfg80211_ap_settings params; | |
3287 | int err; | |
3288 | ||
3289 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3290 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3291 | return -EOPNOTSUPP; | |
3292 | ||
3293 | if (!rdev->ops->start_ap) | |
3294 | return -EOPNOTSUPP; | |
3295 | ||
3296 | if (wdev->beacon_interval) | |
3297 | return -EALREADY; | |
3298 | ||
3299 | memset(¶ms, 0, sizeof(params)); | |
3300 | ||
3301 | /* these are required for START_AP */ | |
3302 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3303 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3304 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3305 | return -EINVAL; | |
3306 | ||
a1193be8 | 3307 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3308 | if (err) |
3309 | return err; | |
3310 | ||
3311 | params.beacon_interval = | |
3312 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3313 | params.dtim_period = | |
3314 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3315 | ||
3316 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3317 | if (err) | |
3318 | return err; | |
3319 | ||
3320 | /* | |
3321 | * In theory, some of these attributes should be required here | |
3322 | * but since they were not used when the command was originally | |
3323 | * added, keep them optional for old user space programs to let | |
3324 | * them continue to work with drivers that do not need the | |
3325 | * additional information -- drivers must check! | |
3326 | */ | |
3327 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3328 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3329 | params.ssid_len = | |
3330 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3331 | if (params.ssid_len == 0 || | |
3332 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3333 | return -EINVAL; | |
3334 | } | |
3335 | ||
3336 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3337 | params.hidden_ssid = nla_get_u32( | |
3338 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3339 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3340 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3341 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3342 | return -EINVAL; | |
3343 | } | |
3344 | ||
3345 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3346 | ||
3347 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3348 | params.auth_type = nla_get_u32( | |
3349 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3350 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3351 | NL80211_CMD_START_AP)) | |
8860020e JB |
3352 | return -EINVAL; |
3353 | } else | |
3354 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3355 | ||
3356 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3357 | NL80211_MAX_NR_CIPHER_SUITES); | |
3358 | if (err) | |
3359 | return err; | |
3360 | ||
1b658f11 VT |
3361 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3362 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3363 | return -EOPNOTSUPP; | |
3364 | params.inactivity_timeout = nla_get_u16( | |
3365 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3366 | } | |
3367 | ||
53cabad7 JB |
3368 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3369 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3370 | return -EINVAL; | |
3371 | params.p2p_ctwindow = | |
3372 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3373 | if (params.p2p_ctwindow > 127) | |
3374 | return -EINVAL; | |
3375 | if (params.p2p_ctwindow != 0 && | |
3376 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3377 | return -EINVAL; | |
3378 | } | |
3379 | ||
3380 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3381 | u8 tmp; | |
3382 | ||
3383 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3384 | return -EINVAL; | |
3385 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3386 | if (tmp > 1) | |
3387 | return -EINVAL; | |
3388 | params.p2p_opp_ps = tmp; | |
3389 | if (params.p2p_opp_ps != 0 && | |
3390 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3391 | return -EINVAL; | |
3392 | } | |
3393 | ||
aa430da4 | 3394 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3395 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3396 | if (err) | |
3397 | return err; | |
3398 | } else if (wdev->preset_chandef.chan) { | |
3399 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3400 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3401 | return -EINVAL; |
3402 | ||
174e0cd2 IP |
3403 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
3404 | wdev->iftype)) | |
aa430da4 JB |
3405 | return -EINVAL; |
3406 | ||
77765eaf VT |
3407 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3408 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3409 | if (IS_ERR(params.acl)) | |
3410 | return PTR_ERR(params.acl); | |
3411 | } | |
3412 | ||
18998c38 EP |
3413 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
3414 | params.smps_mode = | |
3415 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); | |
3416 | switch (params.smps_mode) { | |
3417 | case NL80211_SMPS_OFF: | |
3418 | break; | |
3419 | case NL80211_SMPS_STATIC: | |
3420 | if (!(rdev->wiphy.features & | |
3421 | NL80211_FEATURE_STATIC_SMPS)) | |
3422 | return -EINVAL; | |
3423 | break; | |
3424 | case NL80211_SMPS_DYNAMIC: | |
3425 | if (!(rdev->wiphy.features & | |
3426 | NL80211_FEATURE_DYNAMIC_SMPS)) | |
3427 | return -EINVAL; | |
3428 | break; | |
3429 | default: | |
3430 | return -EINVAL; | |
3431 | } | |
3432 | } else { | |
3433 | params.smps_mode = NL80211_SMPS_OFF; | |
3434 | } | |
3435 | ||
c56589ed | 3436 | wdev_lock(wdev); |
e35e4d28 | 3437 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3438 | if (!err) { |
683b6d3b | 3439 | wdev->preset_chandef = params.chandef; |
8860020e | 3440 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 3441 | wdev->chandef = params.chandef; |
06e191e2 AQ |
3442 | wdev->ssid_len = params.ssid_len; |
3443 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3444 | } |
c56589ed | 3445 | wdev_unlock(wdev); |
77765eaf VT |
3446 | |
3447 | kfree(params.acl); | |
3448 | ||
56d1893d | 3449 | return err; |
ed1b6cc7 JB |
3450 | } |
3451 | ||
8860020e JB |
3452 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3453 | { | |
3454 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3455 | struct net_device *dev = info->user_ptr[1]; | |
3456 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3457 | struct cfg80211_beacon_data params; | |
3458 | int err; | |
3459 | ||
3460 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3461 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3462 | return -EOPNOTSUPP; | |
3463 | ||
3464 | if (!rdev->ops->change_beacon) | |
3465 | return -EOPNOTSUPP; | |
3466 | ||
3467 | if (!wdev->beacon_interval) | |
3468 | return -EINVAL; | |
3469 | ||
a1193be8 | 3470 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3471 | if (err) |
3472 | return err; | |
3473 | ||
c56589ed SW |
3474 | wdev_lock(wdev); |
3475 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3476 | wdev_unlock(wdev); | |
3477 | ||
3478 | return err; | |
8860020e JB |
3479 | } |
3480 | ||
3481 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3482 | { |
4c476991 JB |
3483 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3484 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3485 | |
7c8d5e03 | 3486 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
3487 | } |
3488 | ||
5727ef1b JB |
3489 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3490 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3491 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3492 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3493 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3494 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3495 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3496 | }; |
3497 | ||
eccb8e8f | 3498 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3499 | enum nl80211_iftype iftype, |
eccb8e8f | 3500 | struct station_parameters *params) |
5727ef1b JB |
3501 | { |
3502 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3503 | struct nlattr *nla; |
5727ef1b JB |
3504 | int flag; |
3505 | ||
eccb8e8f JB |
3506 | /* |
3507 | * Try parsing the new attribute first so userspace | |
3508 | * can specify both for older kernels. | |
3509 | */ | |
3510 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3511 | if (nla) { | |
3512 | struct nl80211_sta_flag_update *sta_flags; | |
3513 | ||
3514 | sta_flags = nla_data(nla); | |
3515 | params->sta_flags_mask = sta_flags->mask; | |
3516 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3517 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3518 | if ((params->sta_flags_mask | |
3519 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3520 | return -EINVAL; | |
3521 | return 0; | |
3522 | } | |
3523 | ||
3524 | /* if present, parse the old attribute */ | |
5727ef1b | 3525 | |
eccb8e8f | 3526 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3527 | if (!nla) |
3528 | return 0; | |
3529 | ||
3530 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3531 | nla, sta_flags_policy)) | |
3532 | return -EINVAL; | |
3533 | ||
bdd3ae3d JB |
3534 | /* |
3535 | * Only allow certain flags for interface types so that | |
3536 | * other attributes are silently ignored. Remember that | |
3537 | * this is backward compatibility code with old userspace | |
3538 | * and shouldn't be hit in other cases anyway. | |
3539 | */ | |
3540 | switch (iftype) { | |
3541 | case NL80211_IFTYPE_AP: | |
3542 | case NL80211_IFTYPE_AP_VLAN: | |
3543 | case NL80211_IFTYPE_P2P_GO: | |
3544 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3545 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3546 | BIT(NL80211_STA_FLAG_WME) | | |
3547 | BIT(NL80211_STA_FLAG_MFP); | |
3548 | break; | |
3549 | case NL80211_IFTYPE_P2P_CLIENT: | |
3550 | case NL80211_IFTYPE_STATION: | |
3551 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3552 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3553 | break; | |
3554 | case NL80211_IFTYPE_MESH_POINT: | |
3555 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3556 | BIT(NL80211_STA_FLAG_MFP) | | |
3557 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3558 | default: | |
3559 | return -EINVAL; | |
3560 | } | |
5727ef1b | 3561 | |
3383b5a6 JB |
3562 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3563 | if (flags[flag]) { | |
eccb8e8f | 3564 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3565 | |
3383b5a6 JB |
3566 | /* no longer support new API additions in old API */ |
3567 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3568 | return -EINVAL; | |
3569 | } | |
3570 | } | |
3571 | ||
5727ef1b JB |
3572 | return 0; |
3573 | } | |
3574 | ||
c8dcfd8a FF |
3575 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3576 | int attr) | |
3577 | { | |
3578 | struct nlattr *rate; | |
8eb41c8d VK |
3579 | u32 bitrate; |
3580 | u16 bitrate_compat; | |
b51f3bee | 3581 | enum nl80211_attrs rate_flg; |
c8dcfd8a FF |
3582 | |
3583 | rate = nla_nest_start(msg, attr); | |
3584 | if (!rate) | |
db9c64cf | 3585 | return false; |
c8dcfd8a FF |
3586 | |
3587 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3588 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3589 | /* report 16-bit bitrate only if we can */ |
3590 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3591 | if (bitrate > 0 && |
3592 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3593 | return false; | |
3594 | if (bitrate_compat > 0 && | |
3595 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3596 | return false; | |
3597 | ||
b51f3bee JB |
3598 | switch (info->bw) { |
3599 | case RATE_INFO_BW_5: | |
3600 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; | |
3601 | break; | |
3602 | case RATE_INFO_BW_10: | |
3603 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; | |
3604 | break; | |
3605 | default: | |
3606 | WARN_ON(1); | |
3607 | /* fall through */ | |
3608 | case RATE_INFO_BW_20: | |
3609 | rate_flg = 0; | |
3610 | break; | |
3611 | case RATE_INFO_BW_40: | |
3612 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; | |
3613 | break; | |
3614 | case RATE_INFO_BW_80: | |
3615 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; | |
3616 | break; | |
3617 | case RATE_INFO_BW_160: | |
3618 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; | |
3619 | break; | |
3620 | } | |
3621 | ||
3622 | if (rate_flg && nla_put_flag(msg, rate_flg)) | |
3623 | return false; | |
3624 | ||
db9c64cf JB |
3625 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
3626 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3627 | return false; | |
db9c64cf JB |
3628 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
3629 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3630 | return false; | |
3631 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3632 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3633 | return false; | |
3634 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3635 | return false; | |
db9c64cf JB |
3636 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
3637 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3638 | return false; | |
3639 | } | |
c8dcfd8a FF |
3640 | |
3641 | nla_nest_end(msg, rate); | |
3642 | return true; | |
c8dcfd8a FF |
3643 | } |
3644 | ||
119363c7 FF |
3645 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3646 | int id) | |
3647 | { | |
3648 | void *attr; | |
3649 | int i = 0; | |
3650 | ||
3651 | if (!mask) | |
3652 | return true; | |
3653 | ||
3654 | attr = nla_nest_start(msg, id); | |
3655 | if (!attr) | |
3656 | return false; | |
3657 | ||
3658 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3659 | if (!(mask & BIT(i))) | |
3660 | continue; | |
3661 | ||
3662 | if (nla_put_u8(msg, i, signal[i])) | |
3663 | return false; | |
3664 | } | |
3665 | ||
3666 | nla_nest_end(msg, attr); | |
3667 | ||
3668 | return true; | |
3669 | } | |
3670 | ||
cf5ead82 JB |
3671 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
3672 | u32 seq, int flags, | |
66266b3a JL |
3673 | struct cfg80211_registered_device *rdev, |
3674 | struct net_device *dev, | |
98b62183 | 3675 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3676 | { |
3677 | void *hdr; | |
f4263c98 | 3678 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3679 | |
cf5ead82 | 3680 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
fd5b74dc JB |
3681 | if (!hdr) |
3682 | return -1; | |
3683 | ||
9360ffd1 DM |
3684 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3685 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3686 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3687 | goto nla_put_failure; | |
f5ea9120 | 3688 | |
2ec600d6 LCC |
3689 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3690 | if (!sinfoattr) | |
fd5b74dc | 3691 | goto nla_put_failure; |
319090bf JB |
3692 | |
3693 | #define PUT_SINFO(attr, memb, type) do { \ | |
3694 | if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \ | |
3695 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ | |
3696 | sinfo->memb)) \ | |
3697 | goto nla_put_failure; \ | |
3698 | } while (0) | |
3699 | ||
3700 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); | |
3701 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); | |
3702 | ||
3703 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | | |
3704 | BIT(NL80211_STA_INFO_RX_BYTES64)) && | |
9360ffd1 | 3705 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3706 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3707 | goto nla_put_failure; |
319090bf JB |
3708 | |
3709 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | | |
3710 | BIT(NL80211_STA_INFO_TX_BYTES64)) && | |
9360ffd1 | 3711 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3712 | (u32)sinfo->tx_bytes)) |
3713 | goto nla_put_failure; | |
319090bf JB |
3714 | |
3715 | PUT_SINFO(RX_BYTES64, rx_bytes, u64); | |
3716 | PUT_SINFO(TX_BYTES64, tx_bytes, u64); | |
3717 | PUT_SINFO(LLID, llid, u16); | |
3718 | PUT_SINFO(PLID, plid, u16); | |
3719 | PUT_SINFO(PLINK_STATE, plink_state, u8); | |
3720 | ||
66266b3a JL |
3721 | switch (rdev->wiphy.signal_type) { |
3722 | case CFG80211_SIGNAL_TYPE_MBM: | |
319090bf JB |
3723 | PUT_SINFO(SIGNAL, signal, u8); |
3724 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); | |
66266b3a JL |
3725 | break; |
3726 | default: | |
3727 | break; | |
3728 | } | |
319090bf | 3729 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
119363c7 FF |
3730 | if (!nl80211_put_signal(msg, sinfo->chains, |
3731 | sinfo->chain_signal, | |
3732 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3733 | goto nla_put_failure; | |
3734 | } | |
319090bf | 3735 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
119363c7 FF |
3736 | if (!nl80211_put_signal(msg, sinfo->chains, |
3737 | sinfo->chain_signal_avg, | |
3738 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3739 | goto nla_put_failure; | |
3740 | } | |
319090bf | 3741 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
c8dcfd8a FF |
3742 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3743 | NL80211_STA_INFO_TX_BITRATE)) | |
3744 | goto nla_put_failure; | |
3745 | } | |
319090bf | 3746 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
c8dcfd8a FF |
3747 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
3748 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3749 | goto nla_put_failure; |
420e7fab | 3750 | } |
319090bf JB |
3751 | |
3752 | PUT_SINFO(RX_PACKETS, rx_packets, u32); | |
3753 | PUT_SINFO(TX_PACKETS, tx_packets, u32); | |
3754 | PUT_SINFO(TX_RETRIES, tx_retries, u32); | |
3755 | PUT_SINFO(TX_FAILED, tx_failed, u32); | |
3756 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); | |
3757 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); | |
3758 | PUT_SINFO(LOCAL_PM, local_pm, u32); | |
3759 | PUT_SINFO(PEER_PM, peer_pm, u32); | |
3760 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); | |
3761 | ||
3762 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { | |
f4263c98 PS |
3763 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
3764 | if (!bss_param) | |
3765 | goto nla_put_failure; | |
3766 | ||
9360ffd1 DM |
3767 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3768 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3769 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3770 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3771 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3772 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3773 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3774 | sinfo->bss_param.dtim_period) || | |
3775 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3776 | sinfo->bss_param.beacon_interval)) | |
3777 | goto nla_put_failure; | |
f4263c98 PS |
3778 | |
3779 | nla_nest_end(msg, bss_param); | |
3780 | } | |
319090bf | 3781 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
9360ffd1 DM |
3782 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
3783 | sizeof(struct nl80211_sta_flag_update), | |
3784 | &sinfo->sta_flags)) | |
3785 | goto nla_put_failure; | |
319090bf JB |
3786 | |
3787 | PUT_SINFO(T_OFFSET, t_offset, u64); | |
3788 | PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64); | |
a76b1942 JB |
3789 | PUT_SINFO(BEACON_RX, rx_beacon, u64); |
3790 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); | |
319090bf JB |
3791 | |
3792 | #undef PUT_SINFO | |
6de39808 JB |
3793 | |
3794 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { | |
3795 | struct nlattr *tidsattr; | |
3796 | int tid; | |
3797 | ||
3798 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); | |
3799 | if (!tidsattr) | |
3800 | goto nla_put_failure; | |
3801 | ||
3802 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { | |
3803 | struct cfg80211_tid_stats *tidstats; | |
3804 | struct nlattr *tidattr; | |
3805 | ||
3806 | tidstats = &sinfo->pertid[tid]; | |
3807 | ||
3808 | if (!tidstats->filled) | |
3809 | continue; | |
3810 | ||
3811 | tidattr = nla_nest_start(msg, tid + 1); | |
3812 | if (!tidattr) | |
3813 | goto nla_put_failure; | |
3814 | ||
3815 | #define PUT_TIDVAL(attr, memb, type) do { \ | |
3816 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ | |
3817 | nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \ | |
3818 | tidstats->memb)) \ | |
3819 | goto nla_put_failure; \ | |
3820 | } while (0) | |
3821 | ||
3822 | PUT_TIDVAL(RX_MSDU, rx_msdu, u64); | |
3823 | PUT_TIDVAL(TX_MSDU, tx_msdu, u64); | |
3824 | PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64); | |
3825 | PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64); | |
3826 | ||
3827 | #undef PUT_TIDVAL | |
3828 | nla_nest_end(msg, tidattr); | |
3829 | } | |
3830 | ||
3831 | nla_nest_end(msg, tidsattr); | |
3832 | } | |
3833 | ||
2ec600d6 | 3834 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3835 | |
319090bf | 3836 | if (sinfo->assoc_req_ies_len && |
9360ffd1 DM |
3837 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
3838 | sinfo->assoc_req_ies)) | |
3839 | goto nla_put_failure; | |
50d3dfb7 | 3840 | |
fd5b74dc JB |
3841 | return genlmsg_end(msg, hdr); |
3842 | ||
3843 | nla_put_failure: | |
bc3ed28c TG |
3844 | genlmsg_cancel(msg, hdr); |
3845 | return -EMSGSIZE; | |
fd5b74dc JB |
3846 | } |
3847 | ||
2ec600d6 | 3848 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3849 | struct netlink_callback *cb) |
2ec600d6 | 3850 | { |
2ec600d6 | 3851 | struct station_info sinfo; |
1b8ec87a | 3852 | struct cfg80211_registered_device *rdev; |
97990a06 | 3853 | struct wireless_dev *wdev; |
2ec600d6 | 3854 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3855 | int sta_idx = cb->args[2]; |
2ec600d6 | 3856 | int err; |
2ec600d6 | 3857 | |
1b8ec87a | 3858 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
3859 | if (err) |
3860 | return err; | |
bba95fef | 3861 | |
97990a06 JB |
3862 | if (!wdev->netdev) { |
3863 | err = -EINVAL; | |
3864 | goto out_err; | |
3865 | } | |
3866 | ||
1b8ec87a | 3867 | if (!rdev->ops->dump_station) { |
eec60b03 | 3868 | err = -EOPNOTSUPP; |
bba95fef JB |
3869 | goto out_err; |
3870 | } | |
3871 | ||
bba95fef | 3872 | while (1) { |
f612cedf | 3873 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 3874 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
e35e4d28 | 3875 | mac_addr, &sinfo); |
bba95fef JB |
3876 | if (err == -ENOENT) |
3877 | break; | |
3878 | if (err) | |
3b85875a | 3879 | goto out_err; |
bba95fef | 3880 | |
cf5ead82 | 3881 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
15e47304 | 3882 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3883 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 3884 | rdev, wdev->netdev, mac_addr, |
bba95fef JB |
3885 | &sinfo) < 0) |
3886 | goto out; | |
3887 | ||
3888 | sta_idx++; | |
3889 | } | |
3890 | ||
3891 | ||
3892 | out: | |
97990a06 | 3893 | cb->args[2] = sta_idx; |
bba95fef | 3894 | err = skb->len; |
bba95fef | 3895 | out_err: |
1b8ec87a | 3896 | nl80211_finish_wdev_dump(rdev); |
bba95fef JB |
3897 | |
3898 | return err; | |
2ec600d6 | 3899 | } |
fd5b74dc | 3900 | |
5727ef1b JB |
3901 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3902 | { | |
4c476991 JB |
3903 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3904 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3905 | struct station_info sinfo; |
fd5b74dc JB |
3906 | struct sk_buff *msg; |
3907 | u8 *mac_addr = NULL; | |
4c476991 | 3908 | int err; |
fd5b74dc | 3909 | |
2ec600d6 | 3910 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3911 | |
3912 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3913 | return -EINVAL; | |
3914 | ||
3915 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3916 | ||
4c476991 JB |
3917 | if (!rdev->ops->get_station) |
3918 | return -EOPNOTSUPP; | |
3b85875a | 3919 | |
e35e4d28 | 3920 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3921 | if (err) |
4c476991 | 3922 | return err; |
2ec600d6 | 3923 | |
fd2120ca | 3924 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3925 | if (!msg) |
4c476991 | 3926 | return -ENOMEM; |
fd5b74dc | 3927 | |
cf5ead82 JB |
3928 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
3929 | info->snd_portid, info->snd_seq, 0, | |
66266b3a | 3930 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3931 | nlmsg_free(msg); |
3932 | return -ENOBUFS; | |
3933 | } | |
3b85875a | 3934 | |
4c476991 | 3935 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3936 | } |
3937 | ||
77ee7c89 JB |
3938 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3939 | struct station_parameters *params, | |
3940 | enum cfg80211_station_type statype) | |
3941 | { | |
3942 | if (params->listen_interval != -1) | |
3943 | return -EINVAL; | |
c72e1140 AN |
3944 | if (params->aid && |
3945 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
77ee7c89 JB |
3946 | return -EINVAL; |
3947 | ||
3948 | /* When you run into this, adjust the code below for the new flag */ | |
3949 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3950 | ||
3951 | switch (statype) { | |
eef941e6 TP |
3952 | case CFG80211_STA_MESH_PEER_KERNEL: |
3953 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3954 | /* |
3955 | * No ignoring the TDLS flag here -- the userspace mesh | |
3956 | * code doesn't have the bug of including TDLS in the | |
3957 | * mask everywhere. | |
3958 | */ | |
3959 | if (params->sta_flags_mask & | |
3960 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3961 | BIT(NL80211_STA_FLAG_MFP) | | |
3962 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3963 | return -EINVAL; | |
3964 | break; | |
3965 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3966 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3967 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3968 | return -EINVAL; | |
3969 | /* ignore since it can't change */ | |
3970 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3971 | break; | |
3972 | default: | |
3973 | /* disallow mesh-specific things */ | |
3974 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3975 | return -EINVAL; | |
3976 | if (params->local_pm) | |
3977 | return -EINVAL; | |
3978 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3979 | return -EINVAL; | |
3980 | } | |
3981 | ||
3982 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3983 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3984 | /* TDLS can't be set, ... */ | |
3985 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3986 | return -EINVAL; | |
3987 | /* | |
3988 | * ... but don't bother the driver with it. This works around | |
3989 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3990 | * TLDS_PEER flag in the mask even for AP mode. | |
3991 | */ | |
3992 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3993 | } | |
3994 | ||
3995 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3996 | /* reject other things that can't change */ | |
3997 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3998 | return -EINVAL; | |
3999 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
4000 | return -EINVAL; | |
4001 | if (params->supported_rates) | |
4002 | return -EINVAL; | |
4003 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
4004 | return -EINVAL; | |
4005 | } | |
4006 | ||
4007 | if (statype != CFG80211_STA_AP_CLIENT) { | |
4008 | if (params->vlan) | |
4009 | return -EINVAL; | |
4010 | } | |
4011 | ||
4012 | switch (statype) { | |
4013 | case CFG80211_STA_AP_MLME_CLIENT: | |
4014 | /* Use this only for authorizing/unauthorizing a station */ | |
4015 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
4016 | return -EOPNOTSUPP; | |
4017 | break; | |
4018 | case CFG80211_STA_AP_CLIENT: | |
4019 | /* accept only the listed bits */ | |
4020 | if (params->sta_flags_mask & | |
4021 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4022 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4023 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4024 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
4025 | BIT(NL80211_STA_FLAG_WME) | | |
4026 | BIT(NL80211_STA_FLAG_MFP))) | |
4027 | return -EINVAL; | |
4028 | ||
4029 | /* but authenticated/associated only if driver handles it */ | |
4030 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4031 | params->sta_flags_mask & | |
4032 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4033 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4034 | return -EINVAL; | |
4035 | break; | |
4036 | case CFG80211_STA_IBSS: | |
4037 | case CFG80211_STA_AP_STA: | |
4038 | /* reject any changes other than AUTHORIZED */ | |
4039 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
4040 | return -EINVAL; | |
4041 | break; | |
4042 | case CFG80211_STA_TDLS_PEER_SETUP: | |
4043 | /* reject any changes other than AUTHORIZED or WME */ | |
4044 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4045 | BIT(NL80211_STA_FLAG_WME))) | |
4046 | return -EINVAL; | |
4047 | /* force (at least) rates when authorizing */ | |
4048 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
4049 | !params->supported_rates) | |
4050 | return -EINVAL; | |
4051 | break; | |
4052 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
4053 | /* reject any changes */ | |
4054 | return -EINVAL; | |
eef941e6 | 4055 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
4056 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
4057 | return -EINVAL; | |
4058 | break; | |
eef941e6 | 4059 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
4060 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
4061 | return -EINVAL; | |
4062 | break; | |
4063 | } | |
4064 | ||
4065 | return 0; | |
4066 | } | |
4067 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
4068 | ||
5727ef1b | 4069 | /* |
c258d2de | 4070 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 4071 | */ |
80b99899 JB |
4072 | static struct net_device *get_vlan(struct genl_info *info, |
4073 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 4074 | { |
463d0183 | 4075 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
4076 | struct net_device *v; |
4077 | int ret; | |
4078 | ||
4079 | if (!vlanattr) | |
4080 | return NULL; | |
4081 | ||
4082 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
4083 | if (!v) | |
4084 | return ERR_PTR(-ENODEV); | |
4085 | ||
4086 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
4087 | ret = -EINVAL; | |
4088 | goto error; | |
5727ef1b | 4089 | } |
80b99899 | 4090 | |
77ee7c89 JB |
4091 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
4092 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4093 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
4094 | ret = -EINVAL; | |
4095 | goto error; | |
4096 | } | |
4097 | ||
80b99899 JB |
4098 | if (!netif_running(v)) { |
4099 | ret = -ENETDOWN; | |
4100 | goto error; | |
4101 | } | |
4102 | ||
4103 | return v; | |
4104 | error: | |
4105 | dev_put(v); | |
4106 | return ERR_PTR(ret); | |
5727ef1b JB |
4107 | } |
4108 | ||
94e860f1 JB |
4109 | static const struct nla_policy |
4110 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
4111 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
4112 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
4113 | }; | |
4114 | ||
ff276691 JB |
4115 | static int nl80211_parse_sta_wme(struct genl_info *info, |
4116 | struct station_parameters *params) | |
df881293 | 4117 | { |
df881293 JM |
4118 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
4119 | struct nlattr *nla; | |
4120 | int err; | |
4121 | ||
df881293 JM |
4122 | /* parse WME attributes if present */ |
4123 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
4124 | return 0; | |
4125 | ||
4126 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
4127 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
4128 | nl80211_sta_wme_policy); | |
4129 | if (err) | |
4130 | return err; | |
4131 | ||
4132 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
4133 | params->uapsd_queues = nla_get_u8( | |
4134 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4135 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
4136 | return -EINVAL; | |
4137 | ||
4138 | if (tb[NL80211_STA_WME_MAX_SP]) | |
4139 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4140 | ||
4141 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
4142 | return -EINVAL; | |
4143 | ||
4144 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
4145 | ||
4146 | return 0; | |
4147 | } | |
4148 | ||
c01fc9ad SD |
4149 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4150 | struct station_parameters *params) | |
4151 | { | |
4152 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4153 | params->supported_channels = | |
4154 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4155 | params->supported_channels_len = | |
4156 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4157 | /* | |
4158 | * Need to include at least one (first channel, number of | |
4159 | * channels) tuple for each subband, and must have proper | |
4160 | * tuples for the rest of the data as well. | |
4161 | */ | |
4162 | if (params->supported_channels_len < 2) | |
4163 | return -EINVAL; | |
4164 | if (params->supported_channels_len % 2) | |
4165 | return -EINVAL; | |
4166 | } | |
4167 | ||
4168 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4169 | params->supported_oper_classes = | |
4170 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4171 | params->supported_oper_classes_len = | |
4172 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4173 | /* | |
4174 | * The value of the Length field of the Supported Operating | |
4175 | * Classes element is between 2 and 253. | |
4176 | */ | |
4177 | if (params->supported_oper_classes_len < 2 || | |
4178 | params->supported_oper_classes_len > 253) | |
4179 | return -EINVAL; | |
4180 | } | |
4181 | return 0; | |
4182 | } | |
4183 | ||
ff276691 JB |
4184 | static int nl80211_set_station_tdls(struct genl_info *info, |
4185 | struct station_parameters *params) | |
4186 | { | |
c01fc9ad | 4187 | int err; |
ff276691 | 4188 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4189 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4190 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4191 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4192 | params->ht_capa = | |
4193 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4194 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4195 | params->vht_capa = | |
4196 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4197 | ||
c01fc9ad SD |
4198 | err = nl80211_parse_sta_channel_info(info, params); |
4199 | if (err) | |
4200 | return err; | |
4201 | ||
ff276691 JB |
4202 | return nl80211_parse_sta_wme(info, params); |
4203 | } | |
4204 | ||
5727ef1b JB |
4205 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4206 | { | |
4c476991 | 4207 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4208 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4209 | struct station_parameters params; |
77ee7c89 JB |
4210 | u8 *mac_addr; |
4211 | int err; | |
5727ef1b JB |
4212 | |
4213 | memset(¶ms, 0, sizeof(params)); | |
4214 | ||
4215 | params.listen_interval = -1; | |
4216 | ||
77ee7c89 JB |
4217 | if (!rdev->ops->change_station) |
4218 | return -EOPNOTSUPP; | |
4219 | ||
5727ef1b JB |
4220 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4221 | return -EINVAL; | |
4222 | ||
4223 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4224 | return -EINVAL; | |
4225 | ||
4226 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4227 | ||
4228 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4229 | params.supported_rates = | |
4230 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4231 | params.supported_rates_len = | |
4232 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4233 | } | |
4234 | ||
9d62a986 JM |
4235 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4236 | params.capability = | |
4237 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4238 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4239 | } | |
4240 | ||
4241 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4242 | params.ext_capab = | |
4243 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4244 | params.ext_capab_len = | |
4245 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4246 | } | |
4247 | ||
df881293 | 4248 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 4249 | return -EINVAL; |
36aedc90 | 4250 | |
bdd3ae3d | 4251 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4252 | return -EINVAL; |
4253 | ||
f8bacc21 | 4254 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4255 | params.plink_action = |
f8bacc21 JB |
4256 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4257 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4258 | return -EINVAL; | |
4259 | } | |
2ec600d6 | 4260 | |
f8bacc21 | 4261 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4262 | params.plink_state = |
f8bacc21 JB |
4263 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4264 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4265 | return -EINVAL; | |
4266 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
4267 | } | |
9c3990aa | 4268 | |
3b1c5a53 MP |
4269 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4270 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4271 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4272 | ||
4273 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4274 | pm > NL80211_MESH_POWER_MAX) | |
4275 | return -EINVAL; | |
4276 | ||
4277 | params.local_pm = pm; | |
4278 | } | |
4279 | ||
77ee7c89 JB |
4280 | /* Include parameters for TDLS peer (will check later) */ |
4281 | err = nl80211_set_station_tdls(info, ¶ms); | |
4282 | if (err) | |
4283 | return err; | |
4284 | ||
4285 | params.vlan = get_vlan(info, rdev); | |
4286 | if (IS_ERR(params.vlan)) | |
4287 | return PTR_ERR(params.vlan); | |
4288 | ||
a97f4424 JB |
4289 | switch (dev->ieee80211_ptr->iftype) { |
4290 | case NL80211_IFTYPE_AP: | |
4291 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4292 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4293 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4294 | case NL80211_IFTYPE_STATION: |
267335d6 | 4295 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4296 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4297 | break; |
4298 | default: | |
77ee7c89 JB |
4299 | err = -EOPNOTSUPP; |
4300 | goto out_put_vlan; | |
034d655e JB |
4301 | } |
4302 | ||
77ee7c89 | 4303 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4304 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4305 | |
77ee7c89 | 4306 | out_put_vlan: |
5727ef1b JB |
4307 | if (params.vlan) |
4308 | dev_put(params.vlan); | |
3b85875a | 4309 | |
5727ef1b JB |
4310 | return err; |
4311 | } | |
4312 | ||
4313 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4314 | { | |
4c476991 | 4315 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4316 | int err; |
4c476991 | 4317 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4318 | struct station_parameters params; |
4319 | u8 *mac_addr = NULL; | |
4320 | ||
4321 | memset(¶ms, 0, sizeof(params)); | |
4322 | ||
984c311b JB |
4323 | if (!rdev->ops->add_station) |
4324 | return -EOPNOTSUPP; | |
4325 | ||
5727ef1b JB |
4326 | if (!info->attrs[NL80211_ATTR_MAC]) |
4327 | return -EINVAL; | |
4328 | ||
5727ef1b JB |
4329 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4330 | return -EINVAL; | |
4331 | ||
4332 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4333 | return -EINVAL; | |
4334 | ||
5e4b6f56 JM |
4335 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4336 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4337 | return -EINVAL; |
4338 | ||
5727ef1b JB |
4339 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4340 | params.supported_rates = | |
4341 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4342 | params.supported_rates_len = | |
4343 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4344 | params.listen_interval = | |
4345 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4346 | |
3d124ea2 | 4347 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4348 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4349 | else |
4350 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4351 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4352 | return -EINVAL; | |
51b50fbe | 4353 | |
9d62a986 JM |
4354 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4355 | params.capability = | |
4356 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4357 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4358 | } | |
4359 | ||
4360 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4361 | params.ext_capab = | |
4362 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4363 | params.ext_capab_len = | |
4364 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4365 | } | |
4366 | ||
36aedc90 JM |
4367 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4368 | params.ht_capa = | |
4369 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4370 | |
f461be3e MP |
4371 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4372 | params.vht_capa = | |
4373 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4374 | ||
60f4a7b1 MK |
4375 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4376 | params.opmode_notif_used = true; | |
4377 | params.opmode_notif = | |
4378 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4379 | } | |
4380 | ||
f8bacc21 | 4381 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4382 | params.plink_action = |
f8bacc21 JB |
4383 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4384 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4385 | return -EINVAL; | |
4386 | } | |
96b78dff | 4387 | |
c01fc9ad SD |
4388 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4389 | if (err) | |
4390 | return err; | |
4391 | ||
ff276691 JB |
4392 | err = nl80211_parse_sta_wme(info, ¶ms); |
4393 | if (err) | |
4394 | return err; | |
bdd90d5e | 4395 | |
bdd3ae3d | 4396 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4397 | return -EINVAL; |
4398 | ||
77ee7c89 JB |
4399 | /* When you run into this, adjust the code below for the new flag */ |
4400 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4401 | ||
bdd90d5e JB |
4402 | switch (dev->ieee80211_ptr->iftype) { |
4403 | case NL80211_IFTYPE_AP: | |
4404 | case NL80211_IFTYPE_AP_VLAN: | |
4405 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4406 | /* ignore WME attributes if iface/sta is not capable */ |
4407 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4408 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4409 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4410 | |
bdd90d5e | 4411 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4412 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4413 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4414 | return -EINVAL; |
bdd90d5e JB |
4415 | /* but don't bother the driver with it */ |
4416 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4417 | |
d582cffb JB |
4418 | /* allow authenticated/associated only if driver handles it */ |
4419 | if (!(rdev->wiphy.features & | |
4420 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4421 | params.sta_flags_mask & | |
4422 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4423 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4424 | return -EINVAL; | |
4425 | ||
bdd90d5e JB |
4426 | /* must be last in here for error handling */ |
4427 | params.vlan = get_vlan(info, rdev); | |
4428 | if (IS_ERR(params.vlan)) | |
4429 | return PTR_ERR(params.vlan); | |
4430 | break; | |
4431 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4432 | /* ignore uAPSD data */ |
4433 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4434 | ||
d582cffb JB |
4435 | /* associated is disallowed */ |
4436 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4437 | return -EINVAL; | |
bdd90d5e | 4438 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4439 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4440 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4441 | return -EINVAL; |
4442 | break; | |
4443 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4444 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4445 | /* ignore uAPSD data */ |
4446 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4447 | ||
77ee7c89 JB |
4448 | /* these are disallowed */ |
4449 | if (params.sta_flags_mask & | |
4450 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4451 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4452 | return -EINVAL; |
bdd90d5e JB |
4453 | /* Only TDLS peers can be added */ |
4454 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4455 | return -EINVAL; | |
4456 | /* Can only add if TDLS ... */ | |
4457 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4458 | return -EOPNOTSUPP; | |
4459 | /* ... with external setup is supported */ | |
4460 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4461 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4462 | /* |
4463 | * Older wpa_supplicant versions always mark the TDLS peer | |
4464 | * as authorized, but it shouldn't yet be. | |
4465 | */ | |
4466 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4467 | break; |
4468 | default: | |
4469 | return -EOPNOTSUPP; | |
c75786c9 EP |
4470 | } |
4471 | ||
bdd90d5e | 4472 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4473 | |
e35e4d28 | 4474 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4475 | |
5727ef1b JB |
4476 | if (params.vlan) |
4477 | dev_put(params.vlan); | |
5727ef1b JB |
4478 | return err; |
4479 | } | |
4480 | ||
4481 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4482 | { | |
4c476991 JB |
4483 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4484 | struct net_device *dev = info->user_ptr[1]; | |
89c771e5 JM |
4485 | struct station_del_parameters params; |
4486 | ||
4487 | memset(¶ms, 0, sizeof(params)); | |
5727ef1b JB |
4488 | |
4489 | if (info->attrs[NL80211_ATTR_MAC]) | |
89c771e5 | 4490 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5727ef1b | 4491 | |
e80cf853 | 4492 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4493 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4494 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4495 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4496 | return -EINVAL; | |
5727ef1b | 4497 | |
4c476991 JB |
4498 | if (!rdev->ops->del_station) |
4499 | return -EOPNOTSUPP; | |
3b85875a | 4500 | |
98856866 JM |
4501 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
4502 | params.subtype = | |
4503 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | |
4504 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | |
4505 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | |
4506 | return -EINVAL; | |
4507 | } else { | |
4508 | /* Default to Deauthentication frame */ | |
4509 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | |
4510 | } | |
4511 | ||
4512 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | |
4513 | params.reason_code = | |
4514 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
4515 | if (params.reason_code == 0) | |
4516 | return -EINVAL; /* 0 is reserved */ | |
4517 | } else { | |
4518 | /* Default to reason code 2 */ | |
4519 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | |
4520 | } | |
4521 | ||
89c771e5 | 4522 | return rdev_del_station(rdev, dev, ¶ms); |
5727ef1b JB |
4523 | } |
4524 | ||
15e47304 | 4525 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4526 | int flags, struct net_device *dev, |
4527 | u8 *dst, u8 *next_hop, | |
4528 | struct mpath_info *pinfo) | |
4529 | { | |
4530 | void *hdr; | |
4531 | struct nlattr *pinfoattr; | |
4532 | ||
1ef4c850 | 4533 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
2ec600d6 LCC |
4534 | if (!hdr) |
4535 | return -1; | |
4536 | ||
9360ffd1 DM |
4537 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4538 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4539 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4540 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4541 | goto nla_put_failure; | |
f5ea9120 | 4542 | |
2ec600d6 LCC |
4543 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4544 | if (!pinfoattr) | |
4545 | goto nla_put_failure; | |
9360ffd1 DM |
4546 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4547 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4548 | pinfo->frame_qlen)) | |
4549 | goto nla_put_failure; | |
4550 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4551 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4552 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4553 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4554 | pinfo->metric)) || | |
4555 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4556 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4557 | pinfo->exptime)) || | |
4558 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4559 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4560 | pinfo->flags)) || | |
4561 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4562 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4563 | pinfo->discovery_timeout)) || | |
4564 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4565 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4566 | pinfo->discovery_retries))) | |
4567 | goto nla_put_failure; | |
2ec600d6 LCC |
4568 | |
4569 | nla_nest_end(msg, pinfoattr); | |
4570 | ||
4571 | return genlmsg_end(msg, hdr); | |
4572 | ||
4573 | nla_put_failure: | |
bc3ed28c TG |
4574 | genlmsg_cancel(msg, hdr); |
4575 | return -EMSGSIZE; | |
2ec600d6 LCC |
4576 | } |
4577 | ||
4578 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4579 | struct netlink_callback *cb) |
2ec600d6 | 4580 | { |
2ec600d6 | 4581 | struct mpath_info pinfo; |
1b8ec87a | 4582 | struct cfg80211_registered_device *rdev; |
97990a06 | 4583 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4584 | u8 dst[ETH_ALEN]; |
4585 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4586 | int path_idx = cb->args[2]; |
2ec600d6 | 4587 | int err; |
2ec600d6 | 4588 | |
1b8ec87a | 4589 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
4590 | if (err) |
4591 | return err; | |
bba95fef | 4592 | |
1b8ec87a | 4593 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 4594 | err = -EOPNOTSUPP; |
bba95fef JB |
4595 | goto out_err; |
4596 | } | |
4597 | ||
97990a06 | 4598 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4599 | err = -EOPNOTSUPP; |
0448b5fc | 4600 | goto out_err; |
eec60b03 JM |
4601 | } |
4602 | ||
bba95fef | 4603 | while (1) { |
1b8ec87a | 4604 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 4605 | next_hop, &pinfo); |
bba95fef | 4606 | if (err == -ENOENT) |
2ec600d6 | 4607 | break; |
bba95fef | 4608 | if (err) |
3b85875a | 4609 | goto out_err; |
2ec600d6 | 4610 | |
15e47304 | 4611 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4612 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4613 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4614 | &pinfo) < 0) |
4615 | goto out; | |
2ec600d6 | 4616 | |
bba95fef | 4617 | path_idx++; |
2ec600d6 | 4618 | } |
2ec600d6 | 4619 | |
2ec600d6 | 4620 | |
bba95fef | 4621 | out: |
97990a06 | 4622 | cb->args[2] = path_idx; |
bba95fef | 4623 | err = skb->len; |
bba95fef | 4624 | out_err: |
1b8ec87a | 4625 | nl80211_finish_wdev_dump(rdev); |
bba95fef | 4626 | return err; |
2ec600d6 LCC |
4627 | } |
4628 | ||
4629 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4630 | { | |
4c476991 | 4631 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4632 | int err; |
4c476991 | 4633 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4634 | struct mpath_info pinfo; |
4635 | struct sk_buff *msg; | |
4636 | u8 *dst = NULL; | |
4637 | u8 next_hop[ETH_ALEN]; | |
4638 | ||
4639 | memset(&pinfo, 0, sizeof(pinfo)); | |
4640 | ||
4641 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4642 | return -EINVAL; | |
4643 | ||
4644 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4645 | ||
4c476991 JB |
4646 | if (!rdev->ops->get_mpath) |
4647 | return -EOPNOTSUPP; | |
2ec600d6 | 4648 | |
4c476991 JB |
4649 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4650 | return -EOPNOTSUPP; | |
eec60b03 | 4651 | |
e35e4d28 | 4652 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4653 | if (err) |
4c476991 | 4654 | return err; |
2ec600d6 | 4655 | |
fd2120ca | 4656 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4657 | if (!msg) |
4c476991 | 4658 | return -ENOMEM; |
2ec600d6 | 4659 | |
15e47304 | 4660 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4661 | dev, dst, next_hop, &pinfo) < 0) { |
4662 | nlmsg_free(msg); | |
4663 | return -ENOBUFS; | |
4664 | } | |
3b85875a | 4665 | |
4c476991 | 4666 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4667 | } |
4668 | ||
4669 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4670 | { | |
4c476991 JB |
4671 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4672 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4673 | u8 *dst = NULL; |
4674 | u8 *next_hop = NULL; | |
4675 | ||
4676 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4677 | return -EINVAL; | |
4678 | ||
4679 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4680 | return -EINVAL; | |
4681 | ||
4682 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4683 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4684 | ||
4c476991 JB |
4685 | if (!rdev->ops->change_mpath) |
4686 | return -EOPNOTSUPP; | |
35a8efe1 | 4687 | |
4c476991 JB |
4688 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4689 | return -EOPNOTSUPP; | |
2ec600d6 | 4690 | |
e35e4d28 | 4691 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4692 | } |
4c476991 | 4693 | |
2ec600d6 LCC |
4694 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4695 | { | |
4c476991 JB |
4696 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4697 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4698 | u8 *dst = NULL; |
4699 | u8 *next_hop = NULL; | |
4700 | ||
4701 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4702 | return -EINVAL; | |
4703 | ||
4704 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4705 | return -EINVAL; | |
4706 | ||
4707 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4708 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4709 | ||
4c476991 JB |
4710 | if (!rdev->ops->add_mpath) |
4711 | return -EOPNOTSUPP; | |
35a8efe1 | 4712 | |
4c476991 JB |
4713 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4714 | return -EOPNOTSUPP; | |
2ec600d6 | 4715 | |
e35e4d28 | 4716 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4717 | } |
4718 | ||
4719 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4720 | { | |
4c476991 JB |
4721 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4722 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4723 | u8 *dst = NULL; |
4724 | ||
4725 | if (info->attrs[NL80211_ATTR_MAC]) | |
4726 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4727 | ||
4c476991 JB |
4728 | if (!rdev->ops->del_mpath) |
4729 | return -EOPNOTSUPP; | |
3b85875a | 4730 | |
e35e4d28 | 4731 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4732 | } |
4733 | ||
66be7d2b HR |
4734 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
4735 | { | |
4736 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4737 | int err; | |
4738 | struct net_device *dev = info->user_ptr[1]; | |
4739 | struct mpath_info pinfo; | |
4740 | struct sk_buff *msg; | |
4741 | u8 *dst = NULL; | |
4742 | u8 mpp[ETH_ALEN]; | |
4743 | ||
4744 | memset(&pinfo, 0, sizeof(pinfo)); | |
4745 | ||
4746 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4747 | return -EINVAL; | |
4748 | ||
4749 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4750 | ||
4751 | if (!rdev->ops->get_mpp) | |
4752 | return -EOPNOTSUPP; | |
4753 | ||
4754 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
4755 | return -EOPNOTSUPP; | |
4756 | ||
4757 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | |
4758 | if (err) | |
4759 | return err; | |
4760 | ||
4761 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4762 | if (!msg) | |
4763 | return -ENOMEM; | |
4764 | ||
4765 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | |
4766 | dev, dst, mpp, &pinfo) < 0) { | |
4767 | nlmsg_free(msg); | |
4768 | return -ENOBUFS; | |
4769 | } | |
4770 | ||
4771 | return genlmsg_reply(msg, info); | |
4772 | } | |
4773 | ||
4774 | static int nl80211_dump_mpp(struct sk_buff *skb, | |
4775 | struct netlink_callback *cb) | |
4776 | { | |
4777 | struct mpath_info pinfo; | |
4778 | struct cfg80211_registered_device *rdev; | |
4779 | struct wireless_dev *wdev; | |
4780 | u8 dst[ETH_ALEN]; | |
4781 | u8 mpp[ETH_ALEN]; | |
4782 | int path_idx = cb->args[2]; | |
4783 | int err; | |
4784 | ||
4785 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | |
4786 | if (err) | |
4787 | return err; | |
4788 | ||
4789 | if (!rdev->ops->dump_mpp) { | |
4790 | err = -EOPNOTSUPP; | |
4791 | goto out_err; | |
4792 | } | |
4793 | ||
4794 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | |
4795 | err = -EOPNOTSUPP; | |
4796 | goto out_err; | |
4797 | } | |
4798 | ||
4799 | while (1) { | |
4800 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | |
4801 | mpp, &pinfo); | |
4802 | if (err == -ENOENT) | |
4803 | break; | |
4804 | if (err) | |
4805 | goto out_err; | |
4806 | ||
4807 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | |
4808 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
4809 | wdev->netdev, dst, mpp, | |
4810 | &pinfo) < 0) | |
4811 | goto out; | |
4812 | ||
4813 | path_idx++; | |
4814 | } | |
4815 | ||
4816 | out: | |
4817 | cb->args[2] = path_idx; | |
4818 | err = skb->len; | |
4819 | out_err: | |
4820 | nl80211_finish_wdev_dump(rdev); | |
4821 | return err; | |
4822 | } | |
4823 | ||
9f1ba906 JM |
4824 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4825 | { | |
4c476991 JB |
4826 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4827 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 4828 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 4829 | struct bss_parameters params; |
c56589ed | 4830 | int err; |
9f1ba906 JM |
4831 | |
4832 | memset(¶ms, 0, sizeof(params)); | |
4833 | /* default to not changing parameters */ | |
4834 | params.use_cts_prot = -1; | |
4835 | params.use_short_preamble = -1; | |
4836 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4837 | params.ap_isolate = -1; |
50b12f59 | 4838 | params.ht_opmode = -1; |
53cabad7 JB |
4839 | params.p2p_ctwindow = -1; |
4840 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4841 | |
4842 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4843 | params.use_cts_prot = | |
4844 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4845 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4846 | params.use_short_preamble = | |
4847 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4848 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4849 | params.use_short_slot_time = | |
4850 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4851 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4852 | params.basic_rates = | |
4853 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4854 | params.basic_rates_len = | |
4855 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4856 | } | |
fd8aaaf3 FF |
4857 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4858 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4859 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4860 | params.ht_opmode = | |
4861 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4862 | |
53cabad7 JB |
4863 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4864 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4865 | return -EINVAL; | |
4866 | params.p2p_ctwindow = | |
4867 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4868 | if (params.p2p_ctwindow < 0) | |
4869 | return -EINVAL; | |
4870 | if (params.p2p_ctwindow != 0 && | |
4871 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4872 | return -EINVAL; | |
4873 | } | |
4874 | ||
4875 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4876 | u8 tmp; | |
4877 | ||
4878 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4879 | return -EINVAL; | |
4880 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4881 | if (tmp > 1) | |
4882 | return -EINVAL; | |
4883 | params.p2p_opp_ps = tmp; | |
4884 | if (params.p2p_opp_ps && | |
4885 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4886 | return -EINVAL; | |
4887 | } | |
4888 | ||
4c476991 JB |
4889 | if (!rdev->ops->change_bss) |
4890 | return -EOPNOTSUPP; | |
9f1ba906 | 4891 | |
074ac8df | 4892 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4893 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4894 | return -EOPNOTSUPP; | |
3b85875a | 4895 | |
c56589ed SW |
4896 | wdev_lock(wdev); |
4897 | err = rdev_change_bss(rdev, dev, ¶ms); | |
4898 | wdev_unlock(wdev); | |
4899 | ||
4900 | return err; | |
9f1ba906 JM |
4901 | } |
4902 | ||
b54452b0 | 4903 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4904 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4905 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4906 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4907 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4908 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4909 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
089027e5 | 4910 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
b2e1b302 LR |
4911 | }; |
4912 | ||
4913 | static int parse_reg_rule(struct nlattr *tb[], | |
4914 | struct ieee80211_reg_rule *reg_rule) | |
4915 | { | |
4916 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4917 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4918 | ||
4919 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4920 | return -EINVAL; | |
4921 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4922 | return -EINVAL; | |
4923 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4924 | return -EINVAL; | |
b0dfd2ea JD |
4925 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
4926 | return -EINVAL; | |
b2e1b302 LR |
4927 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
4928 | return -EINVAL; | |
4929 | ||
4930 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4931 | ||
4932 | freq_range->start_freq_khz = | |
4933 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4934 | freq_range->end_freq_khz = | |
4935 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
b0dfd2ea JD |
4936 | freq_range->max_bandwidth_khz = |
4937 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
b2e1b302 LR |
4938 | |
4939 | power_rule->max_eirp = | |
4940 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4941 | ||
4942 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4943 | power_rule->max_antenna_gain = | |
4944 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4945 | ||
089027e5 JD |
4946 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
4947 | reg_rule->dfs_cac_ms = | |
4948 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
4949 | ||
b2e1b302 LR |
4950 | return 0; |
4951 | } | |
4952 | ||
4953 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4954 | { | |
b2e1b302 | 4955 | char *data = NULL; |
57b5ce07 | 4956 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4957 | |
80778f18 LR |
4958 | /* |
4959 | * You should only get this when cfg80211 hasn't yet initialized | |
4960 | * completely when built-in to the kernel right between the time | |
4961 | * window between nl80211_init() and regulatory_init(), if that is | |
4962 | * even possible. | |
4963 | */ | |
458f4f9e | 4964 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4965 | return -EINPROGRESS; |
80778f18 | 4966 | |
57b5ce07 LR |
4967 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4968 | user_reg_hint_type = | |
4969 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4970 | else | |
4971 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4972 | ||
4973 | switch (user_reg_hint_type) { | |
4974 | case NL80211_USER_REG_HINT_USER: | |
4975 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
4976 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4977 | return -EINVAL; | |
4978 | ||
4979 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4980 | return regulatory_hint_user(data, user_reg_hint_type); | |
4981 | case NL80211_USER_REG_HINT_INDOOR: | |
4982 | return regulatory_hint_indoor_user(); | |
57b5ce07 LR |
4983 | default: |
4984 | return -EINVAL; | |
4985 | } | |
b2e1b302 LR |
4986 | } |
4987 | ||
24bdd9f4 | 4988 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4989 | struct genl_info *info) |
93da9cc1 | 4990 | { |
4c476991 | 4991 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4992 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4993 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4994 | struct mesh_config cur_params; | |
4995 | int err = 0; | |
93da9cc1 | 4996 | void *hdr; |
4997 | struct nlattr *pinfoattr; | |
4998 | struct sk_buff *msg; | |
4999 | ||
29cbe68c JB |
5000 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5001 | return -EOPNOTSUPP; | |
5002 | ||
24bdd9f4 | 5003 | if (!rdev->ops->get_mesh_config) |
4c476991 | 5004 | return -EOPNOTSUPP; |
f3f92586 | 5005 | |
29cbe68c JB |
5006 | wdev_lock(wdev); |
5007 | /* If not connected, get default parameters */ | |
5008 | if (!wdev->mesh_id_len) | |
5009 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
5010 | else | |
e35e4d28 | 5011 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
5012 | wdev_unlock(wdev); |
5013 | ||
93da9cc1 | 5014 | if (err) |
4c476991 | 5015 | return err; |
93da9cc1 | 5016 | |
5017 | /* Draw up a netlink message to send back */ | |
fd2120ca | 5018 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
5019 | if (!msg) |
5020 | return -ENOMEM; | |
15e47304 | 5021 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 5022 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 5023 | if (!hdr) |
efe1cf0c | 5024 | goto out; |
24bdd9f4 | 5025 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 5026 | if (!pinfoattr) |
5027 | goto nla_put_failure; | |
9360ffd1 DM |
5028 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5029 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
5030 | cur_params.dot11MeshRetryTimeout) || | |
5031 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
5032 | cur_params.dot11MeshConfirmTimeout) || | |
5033 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
5034 | cur_params.dot11MeshHoldingTimeout) || | |
5035 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
5036 | cur_params.dot11MeshMaxPeerLinks) || | |
5037 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
5038 | cur_params.dot11MeshMaxRetries) || | |
5039 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
5040 | cur_params.dot11MeshTTL) || | |
5041 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
5042 | cur_params.element_ttl) || | |
5043 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
5044 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
5045 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5046 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
5047 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5048 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
5049 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
5050 | cur_params.path_refresh_time) || | |
5051 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
5052 | cur_params.min_discovery_timeout) || | |
5053 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
5054 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
5055 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
5056 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
5057 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
5058 | cur_params.dot11MeshHWMPperrMinInterval) || | |
5059 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
5060 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
5061 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5062 | cur_params.dot11MeshHWMPRootMode) || | |
5063 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
5064 | cur_params.dot11MeshHWMPRannInterval) || | |
5065 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
5066 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
5067 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
5068 | cur_params.dot11MeshForwarding) || | |
5069 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
5070 | cur_params.rssi_threshold) || |
5071 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
5072 | cur_params.ht_opmode) || |
5073 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
5074 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
5075 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
5076 | cur_params.dot11MeshHWMProotInterval) || |
5077 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
5078 | cur_params.dot11MeshHWMPconfirmationInterval) || |
5079 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
5080 | cur_params.power_mode) || | |
5081 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
5082 | cur_params.dot11MeshAwakeWindowDuration) || |
5083 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5084 | cur_params.plink_timeout)) | |
9360ffd1 | 5085 | goto nla_put_failure; |
93da9cc1 | 5086 | nla_nest_end(msg, pinfoattr); |
5087 | genlmsg_end(msg, hdr); | |
4c476991 | 5088 | return genlmsg_reply(msg, info); |
93da9cc1 | 5089 | |
3b85875a | 5090 | nla_put_failure: |
93da9cc1 | 5091 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 5092 | out: |
d080e275 | 5093 | nlmsg_free(msg); |
4c476991 | 5094 | return -ENOBUFS; |
93da9cc1 | 5095 | } |
5096 | ||
b54452b0 | 5097 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 5098 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
5099 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
5100 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
5101 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
5102 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
5103 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 5104 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 5105 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 5106 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 5107 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
5108 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
5109 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
5110 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
5111 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 5112 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 5113 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 5114 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 5115 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 5116 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 5117 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
5118 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
5119 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
5120 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
5121 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 5122 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
5123 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
5124 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 5125 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 5126 | }; |
5127 | ||
c80d545d JC |
5128 | static const struct nla_policy |
5129 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 5130 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
5131 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
5132 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 5133 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 5134 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 5135 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 5136 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 5137 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 5138 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
5139 | }; |
5140 | ||
24bdd9f4 | 5141 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
5142 | struct mesh_config *cfg, |
5143 | u32 *mask_out) | |
93da9cc1 | 5144 | { |
93da9cc1 | 5145 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 5146 | u32 mask = 0; |
93da9cc1 | 5147 | |
ea54fba2 MP |
5148 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
5149 | do { \ | |
5150 | if (tb[attr]) { \ | |
5151 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
5152 | return -EINVAL; \ | |
5153 | cfg->param = fn(tb[attr]); \ | |
5154 | mask |= (1 << (attr - 1)); \ | |
5155 | } \ | |
5156 | } while (0) | |
bd90fdcc JB |
5157 | |
5158 | ||
24bdd9f4 | 5159 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 5160 | return -EINVAL; |
5161 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 5162 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 5163 | nl80211_meshconf_params_policy)) |
93da9cc1 | 5164 | return -EINVAL; |
5165 | ||
93da9cc1 | 5166 | /* This makes sure that there aren't more than 32 mesh config |
5167 | * parameters (otherwise our bitfield scheme would not work.) */ | |
5168 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
5169 | ||
5170 | /* Fill in the params struct */ | |
ea54fba2 | 5171 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
5172 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
5173 | nla_get_u16); | |
ea54fba2 | 5174 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
5175 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
5176 | nla_get_u16); | |
ea54fba2 | 5177 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
5178 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
5179 | nla_get_u16); | |
ea54fba2 | 5180 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
5181 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
5182 | nla_get_u16); | |
ea54fba2 | 5183 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
5184 | mask, NL80211_MESHCONF_MAX_RETRIES, |
5185 | nla_get_u8); | |
ea54fba2 | 5186 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 5187 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 5188 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
5189 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
5190 | nla_get_u8); | |
ea54fba2 | 5191 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
5192 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
5193 | nla_get_u8); | |
ea54fba2 MP |
5194 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
5195 | 1, 255, mask, | |
a4f606ea CYY |
5196 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5197 | nla_get_u32); | |
ea54fba2 | 5198 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
5199 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5200 | nla_get_u8); | |
ea54fba2 | 5201 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
5202 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
5203 | nla_get_u32); | |
ea54fba2 | 5204 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
5205 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
5206 | nla_get_u16); | |
ea54fba2 MP |
5207 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
5208 | 1, 65535, mask, | |
a4f606ea CYY |
5209 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
5210 | nla_get_u32); | |
93da9cc1 | 5211 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
5212 | 1, 65535, mask, |
5213 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 5214 | nla_get_u16); |
dca7e943 | 5215 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
5216 | 1, 65535, mask, |
5217 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 5218 | nla_get_u16); |
93da9cc1 | 5219 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5220 | dot11MeshHWMPnetDiameterTraversalTime, |
5221 | 1, 65535, mask, | |
a4f606ea CYY |
5222 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
5223 | nla_get_u16); | |
ea54fba2 MP |
5224 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
5225 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5226 | nla_get_u8); | |
5227 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
5228 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 5229 | nla_get_u16); |
63c5723b | 5230 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5231 | dot11MeshGateAnnouncementProtocol, 0, 1, |
5232 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 5233 | nla_get_u8); |
ea54fba2 | 5234 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
5235 | mask, NL80211_MESHCONF_FORWARDING, |
5236 | nla_get_u8); | |
83374fe9 | 5237 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 5238 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
83374fe9 | 5239 | nla_get_s32); |
ea54fba2 | 5240 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 5241 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
5242 | nla_get_u16); |
5243 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 5244 | 1, 65535, mask, |
ac1073a6 CYY |
5245 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
5246 | nla_get_u32); | |
ea54fba2 | 5247 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 5248 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
5249 | nla_get_u16); |
5250 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
5251 | dot11MeshHWMPconfirmationInterval, |
5252 | 1, 65535, mask, | |
728b19e5 | 5253 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 5254 | nla_get_u16); |
3b1c5a53 MP |
5255 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
5256 | NL80211_MESH_POWER_ACTIVE, | |
5257 | NL80211_MESH_POWER_MAX, | |
5258 | mask, NL80211_MESHCONF_POWER_MODE, | |
5259 | nla_get_u32); | |
5260 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
5261 | 0, 65535, mask, | |
5262 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
8e7c0538 CT |
5263 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
5264 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5265 | nla_get_u32); | |
bd90fdcc JB |
5266 | if (mask_out) |
5267 | *mask_out = mask; | |
c80d545d | 5268 | |
bd90fdcc JB |
5269 | return 0; |
5270 | ||
5271 | #undef FILL_IN_MESH_PARAM_IF_SET | |
5272 | } | |
5273 | ||
c80d545d JC |
5274 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
5275 | struct mesh_setup *setup) | |
5276 | { | |
bb2798d4 | 5277 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
5278 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
5279 | ||
5280 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
5281 | return -EINVAL; | |
5282 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
5283 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
5284 | nl80211_mesh_setup_params_policy)) | |
5285 | return -EINVAL; | |
5286 | ||
d299a1f2 JC |
5287 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
5288 | setup->sync_method = | |
5289 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
5290 | IEEE80211_SYNC_METHOD_VENDOR : | |
5291 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
5292 | ||
c80d545d JC |
5293 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
5294 | setup->path_sel_proto = | |
5295 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5296 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5297 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5298 | ||
5299 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5300 | setup->path_metric = | |
5301 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5302 | IEEE80211_PATH_METRIC_VENDOR : | |
5303 | IEEE80211_PATH_METRIC_AIRTIME; | |
5304 | ||
581a8b0f JC |
5305 | |
5306 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 5307 | struct nlattr *ieattr = |
581a8b0f | 5308 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5309 | if (!is_valid_ie_attr(ieattr)) |
5310 | return -EINVAL; | |
581a8b0f JC |
5311 | setup->ie = nla_data(ieattr); |
5312 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5313 | } |
bb2798d4 TP |
5314 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5315 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5316 | return -EINVAL; | |
5317 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5318 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5319 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5320 | if (setup->is_secure) |
5321 | setup->user_mpm = true; | |
c80d545d | 5322 | |
6e16d90b CT |
5323 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5324 | if (!setup->user_mpm) | |
5325 | return -EINVAL; | |
5326 | setup->auth_id = | |
5327 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5328 | } | |
5329 | ||
c80d545d JC |
5330 | return 0; |
5331 | } | |
5332 | ||
24bdd9f4 | 5333 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5334 | struct genl_info *info) |
bd90fdcc JB |
5335 | { |
5336 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5337 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5338 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5339 | struct mesh_config cfg; |
5340 | u32 mask; | |
5341 | int err; | |
5342 | ||
29cbe68c JB |
5343 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5344 | return -EOPNOTSUPP; | |
5345 | ||
24bdd9f4 | 5346 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5347 | return -EOPNOTSUPP; |
5348 | ||
24bdd9f4 | 5349 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5350 | if (err) |
5351 | return err; | |
5352 | ||
29cbe68c JB |
5353 | wdev_lock(wdev); |
5354 | if (!wdev->mesh_id_len) | |
5355 | err = -ENOLINK; | |
5356 | ||
5357 | if (!err) | |
e35e4d28 | 5358 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5359 | |
5360 | wdev_unlock(wdev); | |
5361 | ||
5362 | return err; | |
93da9cc1 | 5363 | } |
5364 | ||
ad30ca2c AN |
5365 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
5366 | struct sk_buff *msg) | |
f130347c | 5367 | { |
f130347c LR |
5368 | struct nlattr *nl_reg_rules; |
5369 | unsigned int i; | |
f130347c | 5370 | |
458f4f9e JB |
5371 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
5372 | (regdom->dfs_region && | |
5373 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
ad30ca2c | 5374 | goto nla_put_failure; |
458f4f9e | 5375 | |
f130347c LR |
5376 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5377 | if (!nl_reg_rules) | |
ad30ca2c | 5378 | goto nla_put_failure; |
f130347c | 5379 | |
458f4f9e | 5380 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5381 | struct nlattr *nl_reg_rule; |
5382 | const struct ieee80211_reg_rule *reg_rule; | |
5383 | const struct ieee80211_freq_range *freq_range; | |
5384 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 5385 | unsigned int max_bandwidth_khz; |
f130347c | 5386 | |
458f4f9e | 5387 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5388 | freq_range = ®_rule->freq_range; |
5389 | power_rule = ®_rule->power_rule; | |
5390 | ||
5391 | nl_reg_rule = nla_nest_start(msg, i); | |
5392 | if (!nl_reg_rule) | |
ad30ca2c | 5393 | goto nla_put_failure; |
f130347c | 5394 | |
97524820 JD |
5395 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
5396 | if (!max_bandwidth_khz) | |
5397 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
5398 | reg_rule); | |
5399 | ||
9360ffd1 DM |
5400 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5401 | reg_rule->flags) || | |
5402 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5403 | freq_range->start_freq_khz) || | |
5404 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5405 | freq_range->end_freq_khz) || | |
5406 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 5407 | max_bandwidth_khz) || |
9360ffd1 DM |
5408 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
5409 | power_rule->max_antenna_gain) || | |
5410 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
5411 | power_rule->max_eirp) || |
5412 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
5413 | reg_rule->dfs_cac_ms)) | |
ad30ca2c | 5414 | goto nla_put_failure; |
f130347c LR |
5415 | |
5416 | nla_nest_end(msg, nl_reg_rule); | |
5417 | } | |
5418 | ||
5419 | nla_nest_end(msg, nl_reg_rules); | |
ad30ca2c AN |
5420 | return 0; |
5421 | ||
5422 | nla_put_failure: | |
5423 | return -EMSGSIZE; | |
5424 | } | |
5425 | ||
5426 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) | |
5427 | { | |
5428 | const struct ieee80211_regdomain *regdom = NULL; | |
5429 | struct cfg80211_registered_device *rdev; | |
5430 | struct wiphy *wiphy = NULL; | |
5431 | struct sk_buff *msg; | |
5432 | void *hdr; | |
5433 | ||
5434 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5435 | if (!msg) | |
5436 | return -ENOBUFS; | |
5437 | ||
5438 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
5439 | NL80211_CMD_GET_REG); | |
5440 | if (!hdr) | |
5441 | goto put_failure; | |
5442 | ||
5443 | if (info->attrs[NL80211_ATTR_WIPHY]) { | |
1bdd716c AN |
5444 | bool self_managed; |
5445 | ||
ad30ca2c AN |
5446 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
5447 | if (IS_ERR(rdev)) { | |
5448 | nlmsg_free(msg); | |
5449 | return PTR_ERR(rdev); | |
5450 | } | |
5451 | ||
5452 | wiphy = &rdev->wiphy; | |
1bdd716c AN |
5453 | self_managed = wiphy->regulatory_flags & |
5454 | REGULATORY_WIPHY_SELF_MANAGED; | |
ad30ca2c AN |
5455 | regdom = get_wiphy_regdom(wiphy); |
5456 | ||
1bdd716c AN |
5457 | /* a self-managed-reg device must have a private regdom */ |
5458 | if (WARN_ON(!regdom && self_managed)) { | |
5459 | nlmsg_free(msg); | |
5460 | return -EINVAL; | |
5461 | } | |
5462 | ||
ad30ca2c AN |
5463 | if (regdom && |
5464 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5465 | goto nla_put_failure; | |
5466 | } | |
5467 | ||
5468 | if (!wiphy && reg_last_request_cell_base() && | |
5469 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5470 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5471 | goto nla_put_failure; | |
5472 | ||
5473 | rcu_read_lock(); | |
5474 | ||
5475 | if (!regdom) | |
5476 | regdom = rcu_dereference(cfg80211_regdomain); | |
5477 | ||
5478 | if (nl80211_put_regdom(regdom, msg)) | |
5479 | goto nla_put_failure_rcu; | |
5480 | ||
5481 | rcu_read_unlock(); | |
f130347c LR |
5482 | |
5483 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5484 | return genlmsg_reply(msg, info); |
f130347c | 5485 | |
458f4f9e JB |
5486 | nla_put_failure_rcu: |
5487 | rcu_read_unlock(); | |
f130347c LR |
5488 | nla_put_failure: |
5489 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5490 | put_failure: |
d080e275 | 5491 | nlmsg_free(msg); |
5fe231e8 | 5492 | return -EMSGSIZE; |
f130347c LR |
5493 | } |
5494 | ||
ad30ca2c AN |
5495 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
5496 | u32 seq, int flags, struct wiphy *wiphy, | |
5497 | const struct ieee80211_regdomain *regdom) | |
5498 | { | |
5499 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | |
5500 | NL80211_CMD_GET_REG); | |
5501 | ||
5502 | if (!hdr) | |
5503 | return -1; | |
5504 | ||
5505 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); | |
5506 | ||
5507 | if (nl80211_put_regdom(regdom, msg)) | |
5508 | goto nla_put_failure; | |
5509 | ||
5510 | if (!wiphy && reg_last_request_cell_base() && | |
5511 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5512 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5513 | goto nla_put_failure; | |
5514 | ||
5515 | if (wiphy && | |
5516 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5517 | goto nla_put_failure; | |
5518 | ||
1bdd716c AN |
5519 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
5520 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
5521 | goto nla_put_failure; | |
5522 | ||
ad30ca2c AN |
5523 | return genlmsg_end(msg, hdr); |
5524 | ||
5525 | nla_put_failure: | |
5526 | genlmsg_cancel(msg, hdr); | |
5527 | return -EMSGSIZE; | |
5528 | } | |
5529 | ||
5530 | static int nl80211_get_reg_dump(struct sk_buff *skb, | |
5531 | struct netlink_callback *cb) | |
5532 | { | |
5533 | const struct ieee80211_regdomain *regdom = NULL; | |
5534 | struct cfg80211_registered_device *rdev; | |
5535 | int err, reg_idx, start = cb->args[2]; | |
5536 | ||
5537 | rtnl_lock(); | |
5538 | ||
5539 | if (cfg80211_regdomain && start == 0) { | |
5540 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5541 | NLM_F_MULTI, NULL, | |
5542 | rtnl_dereference(cfg80211_regdomain)); | |
5543 | if (err < 0) | |
5544 | goto out_err; | |
5545 | } | |
5546 | ||
5547 | /* the global regdom is idx 0 */ | |
5548 | reg_idx = 1; | |
5549 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | |
5550 | regdom = get_wiphy_regdom(&rdev->wiphy); | |
5551 | if (!regdom) | |
5552 | continue; | |
5553 | ||
5554 | if (++reg_idx <= start) | |
5555 | continue; | |
5556 | ||
5557 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5558 | NLM_F_MULTI, &rdev->wiphy, regdom); | |
5559 | if (err < 0) { | |
5560 | reg_idx--; | |
5561 | break; | |
5562 | } | |
5563 | } | |
5564 | ||
5565 | cb->args[2] = reg_idx; | |
5566 | err = skb->len; | |
5567 | out_err: | |
5568 | rtnl_unlock(); | |
5569 | return err; | |
5570 | } | |
5571 | ||
b2e1b302 LR |
5572 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5573 | { | |
5574 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5575 | struct nlattr *nl_reg_rule; | |
ea372c54 JB |
5576 | char *alpha2; |
5577 | int rem_reg_rules, r; | |
b2e1b302 | 5578 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
4c7d3982 | 5579 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
ea372c54 | 5580 | struct ieee80211_regdomain *rd; |
b2e1b302 LR |
5581 | |
5582 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5583 | return -EINVAL; | |
5584 | ||
5585 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5586 | return -EINVAL; | |
5587 | ||
5588 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5589 | ||
8b60b078 LR |
5590 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5591 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5592 | ||
b2e1b302 | 5593 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5594 | rem_reg_rules) { |
b2e1b302 LR |
5595 | num_rules++; |
5596 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5597 | return -EINVAL; |
b2e1b302 LR |
5598 | } |
5599 | ||
e438768f LR |
5600 | if (!reg_is_valid_request(alpha2)) |
5601 | return -EINVAL; | |
5602 | ||
b2e1b302 | 5603 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5604 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5605 | |
5606 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5607 | if (!rd) |
5608 | return -ENOMEM; | |
b2e1b302 LR |
5609 | |
5610 | rd->n_reg_rules = num_rules; | |
5611 | rd->alpha2[0] = alpha2[0]; | |
5612 | rd->alpha2[1] = alpha2[1]; | |
5613 | ||
8b60b078 LR |
5614 | /* |
5615 | * Disable DFS master mode if the DFS region was | |
5616 | * not supported or known on this kernel. | |
5617 | */ | |
5618 | if (reg_supported_dfs_region(dfs_region)) | |
5619 | rd->dfs_region = dfs_region; | |
5620 | ||
b2e1b302 | 5621 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5622 | rem_reg_rules) { |
ae811e21 JB |
5623 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
5624 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
5625 | reg_rule_policy); | |
5626 | if (r) | |
5627 | goto bad_reg; | |
b2e1b302 LR |
5628 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5629 | if (r) | |
5630 | goto bad_reg; | |
5631 | ||
5632 | rule_idx++; | |
5633 | ||
d0e18f83 LR |
5634 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5635 | r = -EINVAL; | |
b2e1b302 | 5636 | goto bad_reg; |
d0e18f83 | 5637 | } |
b2e1b302 LR |
5638 | } |
5639 | ||
b2e1b302 | 5640 | r = set_regdom(rd); |
6913b49a | 5641 | /* set_regdom took ownership */ |
1a919318 | 5642 | rd = NULL; |
b2e1b302 | 5643 | |
d2372b31 | 5644 | bad_reg: |
b2e1b302 | 5645 | kfree(rd); |
d0e18f83 | 5646 | return r; |
b2e1b302 LR |
5647 | } |
5648 | ||
83f5e2cf JB |
5649 | static int validate_scan_freqs(struct nlattr *freqs) |
5650 | { | |
5651 | struct nlattr *attr1, *attr2; | |
5652 | int n_channels = 0, tmp1, tmp2; | |
5653 | ||
5654 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5655 | n_channels++; | |
5656 | /* | |
5657 | * Some hardware has a limited channel list for | |
5658 | * scanning, and it is pretty much nonsensical | |
5659 | * to scan for a channel twice, so disallow that | |
5660 | * and don't require drivers to check that the | |
5661 | * channel list they get isn't longer than what | |
5662 | * they can scan, as long as they can scan all | |
5663 | * the channels they registered at once. | |
5664 | */ | |
5665 | nla_for_each_nested(attr2, freqs, tmp2) | |
5666 | if (attr1 != attr2 && | |
5667 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5668 | return 0; | |
5669 | } | |
5670 | ||
5671 | return n_channels; | |
5672 | } | |
5673 | ||
ad2b26ab JB |
5674 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
5675 | u8 *mac_addr, u8 *mac_addr_mask) | |
5676 | { | |
5677 | int i; | |
5678 | ||
5679 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { | |
5680 | memset(mac_addr, 0, ETH_ALEN); | |
5681 | memset(mac_addr_mask, 0, ETH_ALEN); | |
5682 | mac_addr[0] = 0x2; | |
5683 | mac_addr_mask[0] = 0x3; | |
5684 | ||
5685 | return 0; | |
5686 | } | |
5687 | ||
5688 | /* need both or none */ | |
5689 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) | |
5690 | return -EINVAL; | |
5691 | ||
5692 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); | |
5693 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); | |
5694 | ||
5695 | /* don't allow or configure an mcast address */ | |
5696 | if (!is_multicast_ether_addr(mac_addr_mask) || | |
5697 | is_multicast_ether_addr(mac_addr)) | |
5698 | return -EINVAL; | |
5699 | ||
5700 | /* | |
5701 | * allow users to pass a MAC address that has bits set outside | |
5702 | * of the mask, but don't bother drivers with having to deal | |
5703 | * with such bits | |
5704 | */ | |
5705 | for (i = 0; i < ETH_ALEN; i++) | |
5706 | mac_addr[i] &= mac_addr_mask[i]; | |
5707 | ||
5708 | return 0; | |
5709 | } | |
5710 | ||
2a519311 JB |
5711 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5712 | { | |
4c476991 | 5713 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5714 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5715 | struct cfg80211_scan_request *request; |
2a519311 JB |
5716 | struct nlattr *attr; |
5717 | struct wiphy *wiphy; | |
83f5e2cf | 5718 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5719 | size_t ie_len; |
2a519311 | 5720 | |
f4a11bb0 JB |
5721 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5722 | return -EINVAL; | |
5723 | ||
79c97e97 | 5724 | wiphy = &rdev->wiphy; |
2a519311 | 5725 | |
4c476991 JB |
5726 | if (!rdev->ops->scan) |
5727 | return -EOPNOTSUPP; | |
2a519311 | 5728 | |
f9d15d16 | 5729 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
5730 | err = -EBUSY; |
5731 | goto unlock; | |
5732 | } | |
2a519311 JB |
5733 | |
5734 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5735 | n_channels = validate_scan_freqs( |
5736 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5737 | if (!n_channels) { |
5738 | err = -EINVAL; | |
5739 | goto unlock; | |
5740 | } | |
2a519311 | 5741 | } else { |
bdfbec2d | 5742 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
5743 | } |
5744 | ||
5745 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5746 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5747 | n_ssids++; | |
5748 | ||
f9f47529 JB |
5749 | if (n_ssids > wiphy->max_scan_ssids) { |
5750 | err = -EINVAL; | |
5751 | goto unlock; | |
5752 | } | |
2a519311 | 5753 | |
70692ad2 JM |
5754 | if (info->attrs[NL80211_ATTR_IE]) |
5755 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5756 | else | |
5757 | ie_len = 0; | |
5758 | ||
f9f47529 JB |
5759 | if (ie_len > wiphy->max_scan_ie_len) { |
5760 | err = -EINVAL; | |
5761 | goto unlock; | |
5762 | } | |
18a83659 | 5763 | |
2a519311 | 5764 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5765 | + sizeof(*request->ssids) * n_ssids |
5766 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5767 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5768 | if (!request) { |
5769 | err = -ENOMEM; | |
5770 | goto unlock; | |
5771 | } | |
2a519311 | 5772 | |
2a519311 | 5773 | if (n_ssids) |
5ba63533 | 5774 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5775 | request->n_ssids = n_ssids; |
70692ad2 JM |
5776 | if (ie_len) { |
5777 | if (request->ssids) | |
5778 | request->ie = (void *)(request->ssids + n_ssids); | |
5779 | else | |
5780 | request->ie = (void *)(request->channels + n_channels); | |
5781 | } | |
2a519311 | 5782 | |
584991dc | 5783 | i = 0; |
2a519311 JB |
5784 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5785 | /* user specified, bail out if channel not found */ | |
2a519311 | 5786 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5787 | struct ieee80211_channel *chan; |
5788 | ||
5789 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5790 | ||
5791 | if (!chan) { | |
2a519311 JB |
5792 | err = -EINVAL; |
5793 | goto out_free; | |
5794 | } | |
584991dc JB |
5795 | |
5796 | /* ignore disabled channels */ | |
5797 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5798 | continue; | |
5799 | ||
5800 | request->channels[i] = chan; | |
2a519311 JB |
5801 | i++; |
5802 | } | |
5803 | } else { | |
34850ab2 JB |
5804 | enum ieee80211_band band; |
5805 | ||
2a519311 | 5806 | /* all channels */ |
2a519311 JB |
5807 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5808 | int j; | |
5809 | if (!wiphy->bands[band]) | |
5810 | continue; | |
5811 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5812 | struct ieee80211_channel *chan; |
5813 | ||
5814 | chan = &wiphy->bands[band]->channels[j]; | |
5815 | ||
5816 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5817 | continue; | |
5818 | ||
5819 | request->channels[i] = chan; | |
2a519311 JB |
5820 | i++; |
5821 | } | |
5822 | } | |
5823 | } | |
5824 | ||
584991dc JB |
5825 | if (!i) { |
5826 | err = -EINVAL; | |
5827 | goto out_free; | |
5828 | } | |
5829 | ||
5830 | request->n_channels = i; | |
5831 | ||
2a519311 JB |
5832 | i = 0; |
5833 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5834 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5835 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5836 | err = -EINVAL; |
5837 | goto out_free; | |
5838 | } | |
57a27e1d | 5839 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5840 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5841 | i++; |
5842 | } | |
5843 | } | |
5844 | ||
70692ad2 JM |
5845 | if (info->attrs[NL80211_ATTR_IE]) { |
5846 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5847 | memcpy((void *)request->ie, |
5848 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5849 | request->ie_len); |
5850 | } | |
5851 | ||
34850ab2 | 5852 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5853 | if (wiphy->bands[i]) |
5854 | request->rates[i] = | |
5855 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5856 | |
5857 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5858 | nla_for_each_nested(attr, | |
5859 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5860 | tmp) { | |
5861 | enum ieee80211_band band = nla_type(attr); | |
5862 | ||
84404623 | 5863 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5864 | err = -EINVAL; |
5865 | goto out_free; | |
5866 | } | |
1b09cd82 FF |
5867 | |
5868 | if (!wiphy->bands[band]) | |
5869 | continue; | |
5870 | ||
34850ab2 JB |
5871 | err = ieee80211_get_ratemask(wiphy->bands[band], |
5872 | nla_data(attr), | |
5873 | nla_len(attr), | |
5874 | &request->rates[band]); | |
5875 | if (err) | |
5876 | goto out_free; | |
5877 | } | |
5878 | } | |
5879 | ||
46856bbf | 5880 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5881 | request->flags = nla_get_u32( |
5882 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5883 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5884 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5885 | err = -EOPNOTSUPP; |
5886 | goto out_free; | |
5887 | } | |
ad2b26ab JB |
5888 | |
5889 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
5890 | if (!(wiphy->features & | |
5891 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { | |
5892 | err = -EOPNOTSUPP; | |
5893 | goto out_free; | |
5894 | } | |
5895 | ||
5896 | if (wdev->current_bss) { | |
5897 | err = -EOPNOTSUPP; | |
5898 | goto out_free; | |
5899 | } | |
5900 | ||
5901 | err = nl80211_parse_random_mac(info->attrs, | |
5902 | request->mac_addr, | |
5903 | request->mac_addr_mask); | |
5904 | if (err) | |
5905 | goto out_free; | |
5906 | } | |
46856bbf | 5907 | } |
ed473771 | 5908 | |
e9f935e3 RM |
5909 | request->no_cck = |
5910 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5911 | ||
fd014284 | 5912 | request->wdev = wdev; |
79c97e97 | 5913 | request->wiphy = &rdev->wiphy; |
15d6030b | 5914 | request->scan_start = jiffies; |
2a519311 | 5915 | |
79c97e97 | 5916 | rdev->scan_req = request; |
e35e4d28 | 5917 | err = rdev_scan(rdev, request); |
2a519311 | 5918 | |
463d0183 | 5919 | if (!err) { |
fd014284 JB |
5920 | nl80211_send_scan_start(rdev, wdev); |
5921 | if (wdev->netdev) | |
5922 | dev_hold(wdev->netdev); | |
4c476991 | 5923 | } else { |
2a519311 | 5924 | out_free: |
79c97e97 | 5925 | rdev->scan_req = NULL; |
2a519311 JB |
5926 | kfree(request); |
5927 | } | |
3b85875a | 5928 | |
f9f47529 | 5929 | unlock: |
2a519311 JB |
5930 | return err; |
5931 | } | |
5932 | ||
256da02d | 5933 | static struct cfg80211_sched_scan_request * |
ad2b26ab | 5934 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
256da02d | 5935 | struct nlattr **attrs) |
807f8a8c LC |
5936 | { |
5937 | struct cfg80211_sched_scan_request *request; | |
807f8a8c | 5938 | struct nlattr *attr; |
a1f1c21c | 5939 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5940 | u32 interval; |
807f8a8c LC |
5941 | enum ieee80211_band band; |
5942 | size_t ie_len; | |
a1f1c21c | 5943 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 5944 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c | 5945 | |
256da02d LC |
5946 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
5947 | return ERR_PTR(-EINVAL); | |
807f8a8c | 5948 | |
256da02d LC |
5949 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5950 | return ERR_PTR(-EINVAL); | |
bbe6ad6d | 5951 | |
256da02d | 5952 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
bbe6ad6d | 5953 | if (interval == 0) |
256da02d | 5954 | return ERR_PTR(-EINVAL); |
807f8a8c | 5955 | |
256da02d | 5956 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c | 5957 | n_channels = validate_scan_freqs( |
256da02d | 5958 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
807f8a8c | 5959 | if (!n_channels) |
256da02d | 5960 | return ERR_PTR(-EINVAL); |
807f8a8c | 5961 | } else { |
bdfbec2d | 5962 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
5963 | } |
5964 | ||
256da02d LC |
5965 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
5966 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c LC |
5967 | tmp) |
5968 | n_ssids++; | |
5969 | ||
93b6aa69 | 5970 | if (n_ssids > wiphy->max_sched_scan_ssids) |
256da02d | 5971 | return ERR_PTR(-EINVAL); |
807f8a8c | 5972 | |
ea73cbce JB |
5973 | /* |
5974 | * First, count the number of 'real' matchsets. Due to an issue with | |
5975 | * the old implementation, matchsets containing only the RSSI attribute | |
5976 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
5977 | * RSSI for all matchsets, rather than their own matchset for reporting | |
5978 | * all APs with a strong RSSI. This is needed to be compatible with | |
5979 | * older userspace that treated a matchset with only the RSSI as the | |
5980 | * global RSSI for all other matchsets - if there are other matchsets. | |
5981 | */ | |
256da02d | 5982 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 5983 | nla_for_each_nested(attr, |
256da02d | 5984 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
ea73cbce JB |
5985 | tmp) { |
5986 | struct nlattr *rssi; | |
5987 | ||
5988 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5989 | nla_data(attr), nla_len(attr), | |
5990 | nl80211_match_policy); | |
5991 | if (err) | |
256da02d | 5992 | return ERR_PTR(err); |
ea73cbce JB |
5993 | /* add other standalone attributes here */ |
5994 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | |
5995 | n_match_sets++; | |
5996 | continue; | |
5997 | } | |
5998 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
5999 | if (rssi) | |
6000 | default_match_rssi = nla_get_s32(rssi); | |
6001 | } | |
6002 | } | |
6003 | ||
6004 | /* However, if there's no other matchset, add the RSSI one */ | |
6005 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
6006 | n_match_sets = 1; | |
a1f1c21c LC |
6007 | |
6008 | if (n_match_sets > wiphy->max_match_sets) | |
256da02d | 6009 | return ERR_PTR(-EINVAL); |
a1f1c21c | 6010 | |
256da02d LC |
6011 | if (attrs[NL80211_ATTR_IE]) |
6012 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); | |
807f8a8c LC |
6013 | else |
6014 | ie_len = 0; | |
6015 | ||
5a865bad | 6016 | if (ie_len > wiphy->max_sched_scan_ie_len) |
256da02d | 6017 | return ERR_PTR(-EINVAL); |
c10841ca | 6018 | |
807f8a8c | 6019 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 6020 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 6021 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 6022 | + sizeof(*request->channels) * n_channels |
807f8a8c | 6023 | + ie_len, GFP_KERNEL); |
256da02d LC |
6024 | if (!request) |
6025 | return ERR_PTR(-ENOMEM); | |
807f8a8c LC |
6026 | |
6027 | if (n_ssids) | |
6028 | request->ssids = (void *)&request->channels[n_channels]; | |
6029 | request->n_ssids = n_ssids; | |
6030 | if (ie_len) { | |
6031 | if (request->ssids) | |
6032 | request->ie = (void *)(request->ssids + n_ssids); | |
6033 | else | |
6034 | request->ie = (void *)(request->channels + n_channels); | |
6035 | } | |
6036 | ||
a1f1c21c LC |
6037 | if (n_match_sets) { |
6038 | if (request->ie) | |
6039 | request->match_sets = (void *)(request->ie + ie_len); | |
6040 | else if (request->ssids) | |
6041 | request->match_sets = | |
6042 | (void *)(request->ssids + n_ssids); | |
6043 | else | |
6044 | request->match_sets = | |
6045 | (void *)(request->channels + n_channels); | |
6046 | } | |
6047 | request->n_match_sets = n_match_sets; | |
6048 | ||
807f8a8c | 6049 | i = 0; |
256da02d | 6050 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c LC |
6051 | /* user specified, bail out if channel not found */ |
6052 | nla_for_each_nested(attr, | |
256da02d | 6053 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
807f8a8c LC |
6054 | tmp) { |
6055 | struct ieee80211_channel *chan; | |
6056 | ||
6057 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
6058 | ||
6059 | if (!chan) { | |
6060 | err = -EINVAL; | |
6061 | goto out_free; | |
6062 | } | |
6063 | ||
6064 | /* ignore disabled channels */ | |
6065 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6066 | continue; | |
6067 | ||
6068 | request->channels[i] = chan; | |
6069 | i++; | |
6070 | } | |
6071 | } else { | |
6072 | /* all channels */ | |
6073 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6074 | int j; | |
6075 | if (!wiphy->bands[band]) | |
6076 | continue; | |
6077 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
6078 | struct ieee80211_channel *chan; | |
6079 | ||
6080 | chan = &wiphy->bands[band]->channels[j]; | |
6081 | ||
6082 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6083 | continue; | |
6084 | ||
6085 | request->channels[i] = chan; | |
6086 | i++; | |
6087 | } | |
6088 | } | |
6089 | } | |
6090 | ||
6091 | if (!i) { | |
6092 | err = -EINVAL; | |
6093 | goto out_free; | |
6094 | } | |
6095 | ||
6096 | request->n_channels = i; | |
6097 | ||
6098 | i = 0; | |
256da02d LC |
6099 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) { |
6100 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c | 6101 | tmp) { |
57a27e1d | 6102 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
6103 | err = -EINVAL; |
6104 | goto out_free; | |
6105 | } | |
57a27e1d | 6106 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
6107 | memcpy(request->ssids[i].ssid, nla_data(attr), |
6108 | nla_len(attr)); | |
807f8a8c LC |
6109 | i++; |
6110 | } | |
6111 | } | |
6112 | ||
a1f1c21c | 6113 | i = 0; |
256da02d | 6114 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 6115 | nla_for_each_nested(attr, |
256da02d | 6116 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
a1f1c21c | 6117 | tmp) { |
88e920b4 | 6118 | struct nlattr *ssid, *rssi; |
a1f1c21c | 6119 | |
ae811e21 JB |
6120 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
6121 | nla_data(attr), nla_len(attr), | |
6122 | nl80211_match_policy); | |
6123 | if (err) | |
6124 | goto out_free; | |
4a4ab0d7 | 6125 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 6126 | if (ssid) { |
ea73cbce JB |
6127 | if (WARN_ON(i >= n_match_sets)) { |
6128 | /* this indicates a programming error, | |
6129 | * the loop above should have verified | |
6130 | * things properly | |
6131 | */ | |
6132 | err = -EINVAL; | |
6133 | goto out_free; | |
6134 | } | |
6135 | ||
a1f1c21c LC |
6136 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
6137 | err = -EINVAL; | |
6138 | goto out_free; | |
6139 | } | |
6140 | memcpy(request->match_sets[i].ssid.ssid, | |
6141 | nla_data(ssid), nla_len(ssid)); | |
6142 | request->match_sets[i].ssid.ssid_len = | |
6143 | nla_len(ssid); | |
ea73cbce JB |
6144 | /* special attribute - old implemenation w/a */ |
6145 | request->match_sets[i].rssi_thold = | |
6146 | default_match_rssi; | |
6147 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6148 | if (rssi) | |
6149 | request->match_sets[i].rssi_thold = | |
6150 | nla_get_s32(rssi); | |
a1f1c21c LC |
6151 | } |
6152 | i++; | |
6153 | } | |
ea73cbce JB |
6154 | |
6155 | /* there was no other matchset, so the RSSI one is alone */ | |
f89f46cf | 6156 | if (i == 0 && n_match_sets) |
ea73cbce JB |
6157 | request->match_sets[0].rssi_thold = default_match_rssi; |
6158 | ||
6159 | request->min_rssi_thold = INT_MAX; | |
6160 | for (i = 0; i < n_match_sets; i++) | |
6161 | request->min_rssi_thold = | |
6162 | min(request->match_sets[i].rssi_thold, | |
6163 | request->min_rssi_thold); | |
6164 | } else { | |
6165 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
6166 | } |
6167 | ||
9900e484 JB |
6168 | if (ie_len) { |
6169 | request->ie_len = ie_len; | |
807f8a8c | 6170 | memcpy((void *)request->ie, |
256da02d | 6171 | nla_data(attrs[NL80211_ATTR_IE]), |
807f8a8c LC |
6172 | request->ie_len); |
6173 | } | |
6174 | ||
256da02d | 6175 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 | 6176 | request->flags = nla_get_u32( |
256da02d | 6177 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
00c3a6ed JB |
6178 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
6179 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
6180 | err = -EOPNOTSUPP; |
6181 | goto out_free; | |
6182 | } | |
ad2b26ab JB |
6183 | |
6184 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
6185 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; | |
6186 | ||
6187 | if (!wdev) /* must be net-detect */ | |
6188 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
6189 | ||
6190 | if (!(wiphy->features & flg)) { | |
6191 | err = -EOPNOTSUPP; | |
6192 | goto out_free; | |
6193 | } | |
6194 | ||
6195 | if (wdev && wdev->current_bss) { | |
6196 | err = -EOPNOTSUPP; | |
6197 | goto out_free; | |
6198 | } | |
6199 | ||
6200 | err = nl80211_parse_random_mac(attrs, request->mac_addr, | |
6201 | request->mac_addr_mask); | |
6202 | if (err) | |
6203 | goto out_free; | |
6204 | } | |
46856bbf | 6205 | } |
ed473771 | 6206 | |
bbe6ad6d | 6207 | request->interval = interval; |
15d6030b | 6208 | request->scan_start = jiffies; |
807f8a8c | 6209 | |
256da02d | 6210 | return request; |
807f8a8c LC |
6211 | |
6212 | out_free: | |
6213 | kfree(request); | |
256da02d LC |
6214 | return ERR_PTR(err); |
6215 | } | |
6216 | ||
6217 | static int nl80211_start_sched_scan(struct sk_buff *skb, | |
6218 | struct genl_info *info) | |
6219 | { | |
6220 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6221 | struct net_device *dev = info->user_ptr[1]; | |
ad2b26ab | 6222 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
31a60ed1 | 6223 | struct cfg80211_sched_scan_request *sched_scan_req; |
256da02d LC |
6224 | int err; |
6225 | ||
6226 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6227 | !rdev->ops->sched_scan_start) | |
6228 | return -EOPNOTSUPP; | |
6229 | ||
6230 | if (rdev->sched_scan_req) | |
6231 | return -EINPROGRESS; | |
6232 | ||
31a60ed1 JR |
6233 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
6234 | info->attrs); | |
6235 | ||
6236 | err = PTR_ERR_OR_ZERO(sched_scan_req); | |
256da02d LC |
6237 | if (err) |
6238 | goto out_err; | |
6239 | ||
31a60ed1 | 6240 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
256da02d LC |
6241 | if (err) |
6242 | goto out_free; | |
6243 | ||
31a60ed1 JR |
6244 | sched_scan_req->dev = dev; |
6245 | sched_scan_req->wiphy = &rdev->wiphy; | |
6246 | ||
93a1e86c JR |
6247 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
6248 | sched_scan_req->owner_nlportid = info->snd_portid; | |
6249 | ||
31a60ed1 | 6250 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
256da02d LC |
6251 | |
6252 | nl80211_send_sched_scan(rdev, dev, | |
6253 | NL80211_CMD_START_SCHED_SCAN); | |
6254 | return 0; | |
6255 | ||
6256 | out_free: | |
31a60ed1 | 6257 | kfree(sched_scan_req); |
256da02d | 6258 | out_err: |
807f8a8c LC |
6259 | return err; |
6260 | } | |
6261 | ||
6262 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
6263 | struct genl_info *info) | |
6264 | { | |
6265 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6266 | ||
6267 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6268 | !rdev->ops->sched_scan_stop) | |
6269 | return -EOPNOTSUPP; | |
6270 | ||
5fe231e8 | 6271 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
6272 | } |
6273 | ||
04f39047 SW |
6274 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
6275 | struct genl_info *info) | |
6276 | { | |
6277 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6278 | struct net_device *dev = info->user_ptr[1]; | |
6279 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6280 | struct cfg80211_chan_def chandef; | |
55f7435c | 6281 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 6282 | unsigned int cac_time_ms; |
04f39047 SW |
6283 | int err; |
6284 | ||
55f7435c LR |
6285 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
6286 | if (dfs_region == NL80211_DFS_UNSET) | |
6287 | return -EINVAL; | |
6288 | ||
04f39047 SW |
6289 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6290 | if (err) | |
6291 | return err; | |
6292 | ||
ff311bc1 SW |
6293 | if (netif_carrier_ok(dev)) |
6294 | return -EBUSY; | |
6295 | ||
04f39047 SW |
6296 | if (wdev->cac_started) |
6297 | return -EBUSY; | |
6298 | ||
2beb6dab | 6299 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
00ec75fc | 6300 | wdev->iftype); |
04f39047 SW |
6301 | if (err < 0) |
6302 | return err; | |
6303 | ||
6304 | if (err == 0) | |
6305 | return -EINVAL; | |
6306 | ||
fe7c3a1f | 6307 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
6308 | return -EINVAL; |
6309 | ||
6310 | if (!rdev->ops->start_radar_detection) | |
6311 | return -EOPNOTSUPP; | |
6312 | ||
31559f35 JD |
6313 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
6314 | if (WARN_ON(!cac_time_ms)) | |
6315 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
6316 | ||
6317 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, | |
6318 | cac_time_ms); | |
04f39047 | 6319 | if (!err) { |
9e0e2961 | 6320 | wdev->chandef = chandef; |
04f39047 SW |
6321 | wdev->cac_started = true; |
6322 | wdev->cac_start_time = jiffies; | |
31559f35 | 6323 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 6324 | } |
04f39047 SW |
6325 | return err; |
6326 | } | |
6327 | ||
16ef1fe2 SW |
6328 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
6329 | { | |
6330 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6331 | struct net_device *dev = info->user_ptr[1]; | |
6332 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6333 | struct cfg80211_csa_settings params; | |
6334 | /* csa_attrs is defined static to avoid waste of stack size - this | |
6335 | * function is called under RTNL lock, so this should not be a problem. | |
6336 | */ | |
6337 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
16ef1fe2 | 6338 | int err; |
ee4bc9e7 | 6339 | bool need_new_beacon = false; |
9a774c78 | 6340 | int len, i; |
252e07ca | 6341 | u32 cs_count; |
16ef1fe2 SW |
6342 | |
6343 | if (!rdev->ops->channel_switch || | |
6344 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
6345 | return -EOPNOTSUPP; | |
6346 | ||
ee4bc9e7 SW |
6347 | switch (dev->ieee80211_ptr->iftype) { |
6348 | case NL80211_IFTYPE_AP: | |
6349 | case NL80211_IFTYPE_P2P_GO: | |
6350 | need_new_beacon = true; | |
6351 | ||
6352 | /* useless if AP is not running */ | |
6353 | if (!wdev->beacon_interval) | |
1ff79dfa | 6354 | return -ENOTCONN; |
ee4bc9e7 SW |
6355 | break; |
6356 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
6357 | if (!wdev->ssid_len) |
6358 | return -ENOTCONN; | |
6359 | break; | |
c6da674a | 6360 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
6361 | if (!wdev->mesh_id_len) |
6362 | return -ENOTCONN; | |
ee4bc9e7 SW |
6363 | break; |
6364 | default: | |
16ef1fe2 | 6365 | return -EOPNOTSUPP; |
ee4bc9e7 | 6366 | } |
16ef1fe2 SW |
6367 | |
6368 | memset(¶ms, 0, sizeof(params)); | |
6369 | ||
6370 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6371 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
6372 | return -EINVAL; | |
6373 | ||
6374 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 6375 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
6376 | return -EINVAL; |
6377 | ||
252e07ca LC |
6378 | /* Even though the attribute is u32, the specification says |
6379 | * u8, so let's make sure we don't overflow. | |
6380 | */ | |
6381 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
6382 | if (cs_count > 255) | |
6383 | return -EINVAL; | |
6384 | ||
6385 | params.count = cs_count; | |
16ef1fe2 | 6386 | |
ee4bc9e7 SW |
6387 | if (!need_new_beacon) |
6388 | goto skip_beacons; | |
6389 | ||
16ef1fe2 SW |
6390 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
6391 | if (err) | |
6392 | return err; | |
6393 | ||
6394 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
6395 | info->attrs[NL80211_ATTR_CSA_IES], | |
6396 | nl80211_policy); | |
6397 | if (err) | |
6398 | return err; | |
6399 | ||
6400 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
6401 | if (err) | |
6402 | return err; | |
6403 | ||
6404 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
6405 | return -EINVAL; | |
6406 | ||
9a774c78 AO |
6407 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
6408 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6409 | return -EINVAL; |
6410 | ||
9a774c78 AO |
6411 | params.n_counter_offsets_beacon = len / sizeof(u16); |
6412 | if (rdev->wiphy.max_num_csa_counters && | |
6413 | (params.n_counter_offsets_beacon > | |
6414 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
6415 | return -EINVAL; |
6416 | ||
9a774c78 AO |
6417 | params.counter_offsets_beacon = |
6418 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
6419 | ||
6420 | /* sanity checks - counters should fit and be the same */ | |
6421 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
6422 | u16 offset = params.counter_offsets_beacon[i]; | |
6423 | ||
6424 | if (offset >= params.beacon_csa.tail_len) | |
6425 | return -EINVAL; | |
6426 | ||
6427 | if (params.beacon_csa.tail[offset] != params.count) | |
6428 | return -EINVAL; | |
6429 | } | |
6430 | ||
16ef1fe2 | 6431 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
6432 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
6433 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6434 | return -EINVAL; |
6435 | ||
9a774c78 AO |
6436 | params.n_counter_offsets_presp = len / sizeof(u16); |
6437 | if (rdev->wiphy.max_num_csa_counters && | |
6438 | (params.n_counter_offsets_beacon > | |
6439 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 | 6440 | return -EINVAL; |
9a774c78 AO |
6441 | |
6442 | params.counter_offsets_presp = | |
6443 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
6444 | ||
6445 | /* sanity checks - counters should fit and be the same */ | |
6446 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
6447 | u16 offset = params.counter_offsets_presp[i]; | |
6448 | ||
6449 | if (offset >= params.beacon_csa.probe_resp_len) | |
6450 | return -EINVAL; | |
6451 | ||
6452 | if (params.beacon_csa.probe_resp[offset] != | |
6453 | params.count) | |
6454 | return -EINVAL; | |
6455 | } | |
16ef1fe2 SW |
6456 | } |
6457 | ||
ee4bc9e7 | 6458 | skip_beacons: |
16ef1fe2 SW |
6459 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
6460 | if (err) | |
6461 | return err; | |
6462 | ||
174e0cd2 IP |
6463 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
6464 | wdev->iftype)) | |
16ef1fe2 SW |
6465 | return -EINVAL; |
6466 | ||
2beb6dab LC |
6467 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
6468 | ¶ms.chandef, | |
6469 | wdev->iftype); | |
6470 | if (err < 0) | |
6471 | return err; | |
6472 | ||
dcc6c2f5 | 6473 | if (err > 0) |
2beb6dab | 6474 | params.radar_required = true; |
16ef1fe2 | 6475 | |
16ef1fe2 SW |
6476 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
6477 | params.block_tx = true; | |
6478 | ||
c56589ed SW |
6479 | wdev_lock(wdev); |
6480 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
6481 | wdev_unlock(wdev); | |
6482 | ||
6483 | return err; | |
16ef1fe2 SW |
6484 | } |
6485 | ||
9720bb3a JB |
6486 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
6487 | u32 seq, int flags, | |
2a519311 | 6488 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
6489 | struct wireless_dev *wdev, |
6490 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 6491 | { |
48ab905d | 6492 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 6493 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
6494 | void *hdr; |
6495 | struct nlattr *bss; | |
48ab905d JB |
6496 | |
6497 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 6498 | |
15e47304 | 6499 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
6500 | NL80211_CMD_NEW_SCAN_RESULTS); |
6501 | if (!hdr) | |
6502 | return -1; | |
6503 | ||
9720bb3a JB |
6504 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
6505 | ||
97990a06 JB |
6506 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
6507 | goto nla_put_failure; | |
6508 | if (wdev->netdev && | |
9360ffd1 DM |
6509 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
6510 | goto nla_put_failure; | |
97990a06 JB |
6511 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
6512 | goto nla_put_failure; | |
2a519311 JB |
6513 | |
6514 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
6515 | if (!bss) | |
6516 | goto nla_put_failure; | |
9360ffd1 | 6517 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 6518 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 6519 | goto nla_put_failure; |
9caf0364 JB |
6520 | |
6521 | rcu_read_lock(); | |
0e227084 JB |
6522 | /* indicate whether we have probe response data or not */ |
6523 | if (rcu_access_pointer(res->proberesp_ies) && | |
6524 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
6525 | goto fail_unlock_rcu; | |
6526 | ||
6527 | /* this pointer prefers to be pointed to probe response data | |
6528 | * but is always valid | |
6529 | */ | |
9caf0364 | 6530 | ies = rcu_dereference(res->ies); |
8cef2c9d JB |
6531 | if (ies) { |
6532 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
6533 | goto fail_unlock_rcu; | |
8cef2c9d JB |
6534 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
6535 | ies->len, ies->data)) | |
6536 | goto fail_unlock_rcu; | |
9caf0364 | 6537 | } |
0e227084 JB |
6538 | |
6539 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 6540 | ies = rcu_dereference(res->beacon_ies); |
0e227084 JB |
6541 | if (ies && ies->from_beacon) { |
6542 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) | |
8cef2c9d JB |
6543 | goto fail_unlock_rcu; |
6544 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
6545 | ies->len, ies->data)) | |
6546 | goto fail_unlock_rcu; | |
9caf0364 JB |
6547 | } |
6548 | rcu_read_unlock(); | |
6549 | ||
9360ffd1 DM |
6550 | if (res->beacon_interval && |
6551 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
6552 | goto nla_put_failure; | |
6553 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
6554 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 6555 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
6556 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
6557 | jiffies_to_msecs(jiffies - intbss->ts))) | |
6558 | goto nla_put_failure; | |
2a519311 | 6559 | |
77965c97 | 6560 | switch (rdev->wiphy.signal_type) { |
2a519311 | 6561 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
6562 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
6563 | goto nla_put_failure; | |
2a519311 JB |
6564 | break; |
6565 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
6566 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
6567 | goto nla_put_failure; | |
2a519311 JB |
6568 | break; |
6569 | default: | |
6570 | break; | |
6571 | } | |
6572 | ||
48ab905d | 6573 | switch (wdev->iftype) { |
074ac8df | 6574 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 6575 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
6576 | if (intbss == wdev->current_bss && |
6577 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6578 | NL80211_BSS_STATUS_ASSOCIATED)) | |
6579 | goto nla_put_failure; | |
48ab905d JB |
6580 | break; |
6581 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
6582 | if (intbss == wdev->current_bss && |
6583 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6584 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
6585 | goto nla_put_failure; | |
48ab905d JB |
6586 | break; |
6587 | default: | |
6588 | break; | |
6589 | } | |
6590 | ||
2a519311 JB |
6591 | nla_nest_end(msg, bss); |
6592 | ||
6593 | return genlmsg_end(msg, hdr); | |
6594 | ||
8cef2c9d JB |
6595 | fail_unlock_rcu: |
6596 | rcu_read_unlock(); | |
2a519311 JB |
6597 | nla_put_failure: |
6598 | genlmsg_cancel(msg, hdr); | |
6599 | return -EMSGSIZE; | |
6600 | } | |
6601 | ||
97990a06 | 6602 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 6603 | { |
48ab905d | 6604 | struct cfg80211_registered_device *rdev; |
2a519311 | 6605 | struct cfg80211_internal_bss *scan; |
48ab905d | 6606 | struct wireless_dev *wdev; |
97990a06 | 6607 | int start = cb->args[2], idx = 0; |
2a519311 JB |
6608 | int err; |
6609 | ||
97990a06 | 6610 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6611 | if (err) |
6612 | return err; | |
2a519311 | 6613 | |
48ab905d JB |
6614 | wdev_lock(wdev); |
6615 | spin_lock_bh(&rdev->bss_lock); | |
6616 | cfg80211_bss_expire(rdev); | |
6617 | ||
9720bb3a JB |
6618 | cb->seq = rdev->bss_generation; |
6619 | ||
48ab905d | 6620 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
6621 | if (++idx <= start) |
6622 | continue; | |
9720bb3a | 6623 | if (nl80211_send_bss(skb, cb, |
2a519311 | 6624 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 6625 | rdev, wdev, scan) < 0) { |
2a519311 | 6626 | idx--; |
67748893 | 6627 | break; |
2a519311 JB |
6628 | } |
6629 | } | |
6630 | ||
48ab905d JB |
6631 | spin_unlock_bh(&rdev->bss_lock); |
6632 | wdev_unlock(wdev); | |
2a519311 | 6633 | |
97990a06 JB |
6634 | cb->args[2] = idx; |
6635 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 6636 | |
67748893 | 6637 | return skb->len; |
2a519311 JB |
6638 | } |
6639 | ||
15e47304 | 6640 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
11f78ac3 JB |
6641 | int flags, struct net_device *dev, |
6642 | bool allow_radio_stats, | |
6643 | struct survey_info *survey) | |
61fa713c HS |
6644 | { |
6645 | void *hdr; | |
6646 | struct nlattr *infoattr; | |
6647 | ||
11f78ac3 JB |
6648 | /* skip radio stats if userspace didn't request them */ |
6649 | if (!survey->channel && !allow_radio_stats) | |
6650 | return 0; | |
6651 | ||
15e47304 | 6652 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
6653 | NL80211_CMD_NEW_SURVEY_RESULTS); |
6654 | if (!hdr) | |
6655 | return -ENOMEM; | |
6656 | ||
9360ffd1 DM |
6657 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
6658 | goto nla_put_failure; | |
61fa713c HS |
6659 | |
6660 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
6661 | if (!infoattr) | |
6662 | goto nla_put_failure; | |
6663 | ||
11f78ac3 JB |
6664 | if (survey->channel && |
6665 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
9360ffd1 DM |
6666 | survey->channel->center_freq)) |
6667 | goto nla_put_failure; | |
6668 | ||
6669 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
6670 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
6671 | goto nla_put_failure; | |
6672 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
6673 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
6674 | goto nla_put_failure; | |
4ed20beb JB |
6675 | if ((survey->filled & SURVEY_INFO_TIME) && |
6676 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME, | |
6677 | survey->time)) | |
9360ffd1 | 6678 | goto nla_put_failure; |
4ed20beb JB |
6679 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
6680 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY, | |
6681 | survey->time_busy)) | |
9360ffd1 | 6682 | goto nla_put_failure; |
4ed20beb JB |
6683 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
6684 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, | |
6685 | survey->time_ext_busy)) | |
9360ffd1 | 6686 | goto nla_put_failure; |
4ed20beb JB |
6687 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
6688 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX, | |
6689 | survey->time_rx)) | |
9360ffd1 | 6690 | goto nla_put_failure; |
4ed20beb JB |
6691 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
6692 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX, | |
6693 | survey->time_tx)) | |
9360ffd1 | 6694 | goto nla_put_failure; |
052536ab JB |
6695 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
6696 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN, | |
6697 | survey->time_scan)) | |
6698 | goto nla_put_failure; | |
61fa713c HS |
6699 | |
6700 | nla_nest_end(msg, infoattr); | |
6701 | ||
6702 | return genlmsg_end(msg, hdr); | |
6703 | ||
6704 | nla_put_failure: | |
6705 | genlmsg_cancel(msg, hdr); | |
6706 | return -EMSGSIZE; | |
6707 | } | |
6708 | ||
11f78ac3 | 6709 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
61fa713c HS |
6710 | { |
6711 | struct survey_info survey; | |
1b8ec87a | 6712 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
6713 | struct wireless_dev *wdev; |
6714 | int survey_idx = cb->args[2]; | |
61fa713c | 6715 | int res; |
11f78ac3 | 6716 | bool radio_stats; |
61fa713c | 6717 | |
1b8ec87a | 6718 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6719 | if (res) |
6720 | return res; | |
61fa713c | 6721 | |
11f78ac3 JB |
6722 | /* prepare_wdev_dump parsed the attributes */ |
6723 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; | |
6724 | ||
97990a06 JB |
6725 | if (!wdev->netdev) { |
6726 | res = -EINVAL; | |
6727 | goto out_err; | |
6728 | } | |
6729 | ||
1b8ec87a | 6730 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
6731 | res = -EOPNOTSUPP; |
6732 | goto out_err; | |
6733 | } | |
6734 | ||
6735 | while (1) { | |
1b8ec87a | 6736 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
6737 | if (res == -ENOENT) |
6738 | break; | |
6739 | if (res) | |
6740 | goto out_err; | |
6741 | ||
11f78ac3 JB |
6742 | /* don't send disabled channels, but do send non-channel data */ |
6743 | if (survey.channel && | |
6744 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { | |
180cdc79 LR |
6745 | survey_idx++; |
6746 | continue; | |
6747 | } | |
6748 | ||
61fa713c | 6749 | if (nl80211_send_survey(skb, |
15e47304 | 6750 | NETLINK_CB(cb->skb).portid, |
61fa713c | 6751 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
11f78ac3 | 6752 | wdev->netdev, radio_stats, &survey) < 0) |
61fa713c HS |
6753 | goto out; |
6754 | survey_idx++; | |
6755 | } | |
6756 | ||
6757 | out: | |
97990a06 | 6758 | cb->args[2] = survey_idx; |
61fa713c HS |
6759 | res = skb->len; |
6760 | out_err: | |
1b8ec87a | 6761 | nl80211_finish_wdev_dump(rdev); |
61fa713c HS |
6762 | return res; |
6763 | } | |
6764 | ||
b23aa676 SO |
6765 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
6766 | { | |
6767 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
6768 | NL80211_WPA_VERSION_2)); | |
6769 | } | |
6770 | ||
636a5d36 JM |
6771 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
6772 | { | |
4c476991 JB |
6773 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6774 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6775 | struct ieee80211_channel *chan; |
e39e5b5e JM |
6776 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
6777 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 6778 | enum nl80211_auth_type auth_type; |
fffd0934 | 6779 | struct key_parse key; |
d5cdfacb | 6780 | bool local_state_change; |
636a5d36 | 6781 | |
f4a11bb0 JB |
6782 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6783 | return -EINVAL; | |
6784 | ||
6785 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6786 | return -EINVAL; | |
6787 | ||
1778092e JM |
6788 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
6789 | return -EINVAL; | |
6790 | ||
19957bb3 JB |
6791 | if (!info->attrs[NL80211_ATTR_SSID]) |
6792 | return -EINVAL; | |
6793 | ||
6794 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
6795 | return -EINVAL; | |
6796 | ||
fffd0934 JB |
6797 | err = nl80211_parse_key(info, &key); |
6798 | if (err) | |
6799 | return err; | |
6800 | ||
6801 | if (key.idx >= 0) { | |
e31b8213 JB |
6802 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
6803 | return -EINVAL; | |
fffd0934 JB |
6804 | if (!key.p.key || !key.p.key_len) |
6805 | return -EINVAL; | |
6806 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
6807 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
6808 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
6809 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
6810 | return -EINVAL; | |
6811 | if (key.idx > 4) | |
6812 | return -EINVAL; | |
6813 | } else { | |
6814 | key.p.key_len = 0; | |
6815 | key.p.key = NULL; | |
6816 | } | |
6817 | ||
afea0b7a JB |
6818 | if (key.idx >= 0) { |
6819 | int i; | |
6820 | bool ok = false; | |
6821 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
6822 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
6823 | ok = true; | |
6824 | break; | |
6825 | } | |
6826 | } | |
4c476991 JB |
6827 | if (!ok) |
6828 | return -EINVAL; | |
afea0b7a JB |
6829 | } |
6830 | ||
4c476991 JB |
6831 | if (!rdev->ops->auth) |
6832 | return -EOPNOTSUPP; | |
636a5d36 | 6833 | |
074ac8df | 6834 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6835 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6836 | return -EOPNOTSUPP; | |
eec60b03 | 6837 | |
19957bb3 | 6838 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
6839 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6840 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6841 | if (!chan) | |
4c476991 | 6842 | return -EINVAL; |
636a5d36 | 6843 | |
19957bb3 JB |
6844 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6845 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6846 | |
6847 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6848 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6849 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6850 | } |
6851 | ||
19957bb3 | 6852 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 6853 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 6854 | return -EINVAL; |
636a5d36 | 6855 | |
e39e5b5e JM |
6856 | if (auth_type == NL80211_AUTHTYPE_SAE && |
6857 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
6858 | return -EINVAL; | |
6859 | ||
6860 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
6861 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
6862 | return -EINVAL; | |
6863 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6864 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6865 | /* need to include at least Auth Transaction and Status Code */ | |
6866 | if (sae_data_len < 4) | |
6867 | return -EINVAL; | |
6868 | } | |
6869 | ||
d5cdfacb JM |
6870 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6871 | ||
95de817b JB |
6872 | /* |
6873 | * Since we no longer track auth state, ignore | |
6874 | * requests to only change local state. | |
6875 | */ | |
6876 | if (local_state_change) | |
6877 | return 0; | |
6878 | ||
91bf9b26 JB |
6879 | wdev_lock(dev->ieee80211_ptr); |
6880 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
6881 | ssid, ssid_len, ie, ie_len, | |
6882 | key.p.key, key.p.key_len, key.idx, | |
6883 | sae_data, sae_data_len); | |
6884 | wdev_unlock(dev->ieee80211_ptr); | |
6885 | return err; | |
636a5d36 JM |
6886 | } |
6887 | ||
c0692b8f JB |
6888 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6889 | struct genl_info *info, | |
3dc27d25 JB |
6890 | struct cfg80211_crypto_settings *settings, |
6891 | int cipher_limit) | |
b23aa676 | 6892 | { |
c0b2bbd8 JB |
6893 | memset(settings, 0, sizeof(*settings)); |
6894 | ||
b23aa676 SO |
6895 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6896 | ||
c0692b8f JB |
6897 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6898 | u16 proto; | |
6899 | proto = nla_get_u16( | |
6900 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6901 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6902 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6903 | proto != ETH_P_PAE) | |
6904 | return -EINVAL; | |
6905 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6906 | settings->control_port_no_encrypt = true; | |
6907 | } else | |
6908 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6909 | ||
b23aa676 SO |
6910 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6911 | void *data; | |
6912 | int len, i; | |
6913 | ||
6914 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6915 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6916 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6917 | ||
6918 | if (len % sizeof(u32)) | |
6919 | return -EINVAL; | |
6920 | ||
3dc27d25 | 6921 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6922 | return -EINVAL; |
6923 | ||
6924 | memcpy(settings->ciphers_pairwise, data, len); | |
6925 | ||
6926 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6927 | if (!cfg80211_supported_cipher_suite( |
6928 | &rdev->wiphy, | |
b23aa676 SO |
6929 | settings->ciphers_pairwise[i])) |
6930 | return -EINVAL; | |
6931 | } | |
6932 | ||
6933 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6934 | settings->cipher_group = | |
6935 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6936 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6937 | settings->cipher_group)) | |
b23aa676 SO |
6938 | return -EINVAL; |
6939 | } | |
6940 | ||
6941 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6942 | settings->wpa_versions = | |
6943 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6944 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6945 | return -EINVAL; | |
6946 | } | |
6947 | ||
6948 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6949 | void *data; | |
6d30240e | 6950 | int len; |
b23aa676 SO |
6951 | |
6952 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6953 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6954 | settings->n_akm_suites = len / sizeof(u32); | |
6955 | ||
6956 | if (len % sizeof(u32)) | |
6957 | return -EINVAL; | |
6958 | ||
1b9ca027 JM |
6959 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6960 | return -EINVAL; | |
6961 | ||
b23aa676 | 6962 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6963 | } |
6964 | ||
6965 | return 0; | |
6966 | } | |
6967 | ||
636a5d36 JM |
6968 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6969 | { | |
4c476991 JB |
6970 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6971 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6972 | struct ieee80211_channel *chan; |
f62fab73 JB |
6973 | struct cfg80211_assoc_request req = {}; |
6974 | const u8 *bssid, *ssid; | |
6975 | int err, ssid_len = 0; | |
636a5d36 | 6976 | |
f4a11bb0 JB |
6977 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6978 | return -EINVAL; | |
6979 | ||
6980 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6981 | !info->attrs[NL80211_ATTR_SSID] || |
6982 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6983 | return -EINVAL; |
6984 | ||
4c476991 JB |
6985 | if (!rdev->ops->assoc) |
6986 | return -EOPNOTSUPP; | |
636a5d36 | 6987 | |
074ac8df | 6988 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6989 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6990 | return -EOPNOTSUPP; | |
eec60b03 | 6991 | |
19957bb3 | 6992 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6993 | |
664834de JM |
6994 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6995 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6996 | if (!chan) | |
4c476991 | 6997 | return -EINVAL; |
636a5d36 | 6998 | |
19957bb3 JB |
6999 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7000 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
7001 | |
7002 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
7003 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7004 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7005 | } |
7006 | ||
dc6382ce | 7007 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 7008 | enum nl80211_mfp mfp = |
dc6382ce | 7009 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 7010 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 7011 | req.use_mfp = true; |
4c476991 JB |
7012 | else if (mfp != NL80211_MFP_NO) |
7013 | return -EINVAL; | |
dc6382ce JM |
7014 | } |
7015 | ||
3e5d7649 | 7016 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 7017 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 7018 | |
7e7c8926 | 7019 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 7020 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
7021 | |
7022 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
7023 | memcpy(&req.ht_capa_mask, |
7024 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7025 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
7026 | |
7027 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 7028 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 7029 | return -EINVAL; |
f62fab73 JB |
7030 | memcpy(&req.ht_capa, |
7031 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7032 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
7033 | } |
7034 | ||
ee2aca34 | 7035 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 7036 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
7037 | |
7038 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
7039 | memcpy(&req.vht_capa_mask, |
7040 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7041 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
7042 | |
7043 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 7044 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 7045 | return -EINVAL; |
f62fab73 JB |
7046 | memcpy(&req.vht_capa, |
7047 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7048 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
7049 | } |
7050 | ||
bab5ab7d AK |
7051 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7052 | if (!(rdev->wiphy.features & | |
7053 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7054 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7055 | return -EINVAL; | |
7056 | req.flags |= ASSOC_REQ_USE_RRM; | |
7057 | } | |
7058 | ||
f62fab73 | 7059 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
7060 | if (!err) { |
7061 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
7062 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
7063 | ssid, ssid_len, &req); | |
91bf9b26 JB |
7064 | wdev_unlock(dev->ieee80211_ptr); |
7065 | } | |
636a5d36 | 7066 | |
636a5d36 JM |
7067 | return err; |
7068 | } | |
7069 | ||
7070 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
7071 | { | |
4c476991 JB |
7072 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7073 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7074 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7075 | int ie_len = 0, err; |
19957bb3 | 7076 | u16 reason_code; |
d5cdfacb | 7077 | bool local_state_change; |
636a5d36 | 7078 | |
f4a11bb0 JB |
7079 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7080 | return -EINVAL; | |
7081 | ||
7082 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7083 | return -EINVAL; | |
7084 | ||
7085 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7086 | return -EINVAL; | |
7087 | ||
4c476991 JB |
7088 | if (!rdev->ops->deauth) |
7089 | return -EOPNOTSUPP; | |
636a5d36 | 7090 | |
074ac8df | 7091 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7092 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7093 | return -EOPNOTSUPP; | |
eec60b03 | 7094 | |
19957bb3 | 7095 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7096 | |
19957bb3 JB |
7097 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7098 | if (reason_code == 0) { | |
f4a11bb0 | 7099 | /* Reason Code 0 is reserved */ |
4c476991 | 7100 | return -EINVAL; |
255e737e | 7101 | } |
636a5d36 JM |
7102 | |
7103 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7104 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7105 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7106 | } |
7107 | ||
d5cdfacb JM |
7108 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7109 | ||
91bf9b26 JB |
7110 | wdev_lock(dev->ieee80211_ptr); |
7111 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
7112 | local_state_change); | |
7113 | wdev_unlock(dev->ieee80211_ptr); | |
7114 | return err; | |
636a5d36 JM |
7115 | } |
7116 | ||
7117 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
7118 | { | |
4c476991 JB |
7119 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7120 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7121 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7122 | int ie_len = 0, err; |
19957bb3 | 7123 | u16 reason_code; |
d5cdfacb | 7124 | bool local_state_change; |
636a5d36 | 7125 | |
f4a11bb0 JB |
7126 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7127 | return -EINVAL; | |
7128 | ||
7129 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7130 | return -EINVAL; | |
7131 | ||
7132 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7133 | return -EINVAL; | |
7134 | ||
4c476991 JB |
7135 | if (!rdev->ops->disassoc) |
7136 | return -EOPNOTSUPP; | |
636a5d36 | 7137 | |
074ac8df | 7138 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7139 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7140 | return -EOPNOTSUPP; | |
eec60b03 | 7141 | |
19957bb3 | 7142 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7143 | |
19957bb3 JB |
7144 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7145 | if (reason_code == 0) { | |
f4a11bb0 | 7146 | /* Reason Code 0 is reserved */ |
4c476991 | 7147 | return -EINVAL; |
255e737e | 7148 | } |
636a5d36 JM |
7149 | |
7150 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7151 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7152 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7153 | } |
7154 | ||
d5cdfacb JM |
7155 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7156 | ||
91bf9b26 JB |
7157 | wdev_lock(dev->ieee80211_ptr); |
7158 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
7159 | local_state_change); | |
7160 | wdev_unlock(dev->ieee80211_ptr); | |
7161 | return err; | |
636a5d36 JM |
7162 | } |
7163 | ||
dd5b4cc7 FF |
7164 | static bool |
7165 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
7166 | int mcast_rate[IEEE80211_NUM_BANDS], | |
7167 | int rateval) | |
7168 | { | |
7169 | struct wiphy *wiphy = &rdev->wiphy; | |
7170 | bool found = false; | |
7171 | int band, i; | |
7172 | ||
7173 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
7174 | struct ieee80211_supported_band *sband; | |
7175 | ||
7176 | sband = wiphy->bands[band]; | |
7177 | if (!sband) | |
7178 | continue; | |
7179 | ||
7180 | for (i = 0; i < sband->n_bitrates; i++) { | |
7181 | if (sband->bitrates[i].bitrate == rateval) { | |
7182 | mcast_rate[band] = i + 1; | |
7183 | found = true; | |
7184 | break; | |
7185 | } | |
7186 | } | |
7187 | } | |
7188 | ||
7189 | return found; | |
7190 | } | |
7191 | ||
04a773ad JB |
7192 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
7193 | { | |
4c476991 JB |
7194 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7195 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
7196 | struct cfg80211_ibss_params ibss; |
7197 | struct wiphy *wiphy; | |
fffd0934 | 7198 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
7199 | int err; |
7200 | ||
8e30bc55 JB |
7201 | memset(&ibss, 0, sizeof(ibss)); |
7202 | ||
04a773ad JB |
7203 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7204 | return -EINVAL; | |
7205 | ||
683b6d3b | 7206 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
7207 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
7208 | return -EINVAL; | |
7209 | ||
8e30bc55 JB |
7210 | ibss.beacon_interval = 100; |
7211 | ||
7212 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
7213 | ibss.beacon_interval = | |
7214 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7215 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
7216 | return -EINVAL; | |
7217 | } | |
7218 | ||
4c476991 JB |
7219 | if (!rdev->ops->join_ibss) |
7220 | return -EOPNOTSUPP; | |
04a773ad | 7221 | |
4c476991 JB |
7222 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7223 | return -EOPNOTSUPP; | |
04a773ad | 7224 | |
79c97e97 | 7225 | wiphy = &rdev->wiphy; |
04a773ad | 7226 | |
39193498 | 7227 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 7228 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
7229 | |
7230 | if (!is_valid_ether_addr(ibss.bssid)) | |
7231 | return -EINVAL; | |
7232 | } | |
04a773ad JB |
7233 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7234 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7235 | ||
7236 | if (info->attrs[NL80211_ATTR_IE]) { | |
7237 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7238 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7239 | } | |
7240 | ||
683b6d3b JB |
7241 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
7242 | if (err) | |
7243 | return err; | |
04a773ad | 7244 | |
174e0cd2 IP |
7245 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
7246 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
7247 | return -EINVAL; |
7248 | ||
2f301ab2 | 7249 | switch (ibss.chandef.width) { |
bf372645 SW |
7250 | case NL80211_CHAN_WIDTH_5: |
7251 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
7252 | case NL80211_CHAN_WIDTH_20_NOHT: |
7253 | break; | |
7254 | case NL80211_CHAN_WIDTH_20: | |
7255 | case NL80211_CHAN_WIDTH_40: | |
7256 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | |
7257 | break; | |
7258 | default: | |
c04d6150 | 7259 | return -EINVAL; |
2f301ab2 | 7260 | } |
db9c64cf | 7261 | |
04a773ad | 7262 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
7263 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
7264 | ||
fbd2c8dc TP |
7265 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
7266 | u8 *rates = | |
7267 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7268 | int n_rates = | |
7269 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7270 | struct ieee80211_supported_band *sband = | |
683b6d3b | 7271 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 7272 | |
34850ab2 JB |
7273 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
7274 | &ibss.basic_rates); | |
7275 | if (err) | |
7276 | return err; | |
fbd2c8dc | 7277 | } |
dd5b4cc7 | 7278 | |
803768f5 SW |
7279 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7280 | memcpy(&ibss.ht_capa_mask, | |
7281 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7282 | sizeof(ibss.ht_capa_mask)); | |
7283 | ||
7284 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
7285 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7286 | return -EINVAL; | |
7287 | memcpy(&ibss.ht_capa, | |
7288 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7289 | sizeof(ibss.ht_capa)); | |
7290 | } | |
7291 | ||
dd5b4cc7 FF |
7292 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7293 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
7294 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7295 | return -EINVAL; | |
fbd2c8dc | 7296 | |
4c476991 | 7297 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
7298 | bool no_ht = false; |
7299 | ||
4c476991 | 7300 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
7301 | info->attrs[NL80211_ATTR_KEYS], |
7302 | &no_ht); | |
4c476991 JB |
7303 | if (IS_ERR(connkeys)) |
7304 | return PTR_ERR(connkeys); | |
de7044ee | 7305 | |
3d9d1d66 JB |
7306 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
7307 | no_ht) { | |
de7044ee SM |
7308 | kfree(connkeys); |
7309 | return -EINVAL; | |
7310 | } | |
4c476991 | 7311 | } |
04a773ad | 7312 | |
267335d6 AQ |
7313 | ibss.control_port = |
7314 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
7315 | ||
5336fa88 SW |
7316 | ibss.userspace_handles_dfs = |
7317 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
7318 | ||
4c476991 | 7319 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 | 7320 | if (err) |
b47f610b | 7321 | kzfree(connkeys); |
04a773ad JB |
7322 | return err; |
7323 | } | |
7324 | ||
7325 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
7326 | { | |
4c476991 JB |
7327 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7328 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 7329 | |
4c476991 JB |
7330 | if (!rdev->ops->leave_ibss) |
7331 | return -EOPNOTSUPP; | |
04a773ad | 7332 | |
4c476991 JB |
7333 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7334 | return -EOPNOTSUPP; | |
04a773ad | 7335 | |
4c476991 | 7336 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
7337 | } |
7338 | ||
f4e583c8 AQ |
7339 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
7340 | { | |
7341 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7342 | struct net_device *dev = info->user_ptr[1]; | |
7343 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
7344 | u32 nla_rate; | |
7345 | int err; | |
7346 | ||
7347 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
7348 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
7349 | return -EOPNOTSUPP; | |
7350 | ||
7351 | if (!rdev->ops->set_mcast_rate) | |
7352 | return -EOPNOTSUPP; | |
7353 | ||
7354 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
7355 | ||
7356 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
7357 | return -EINVAL; | |
7358 | ||
7359 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
7360 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
7361 | return -EINVAL; | |
7362 | ||
7363 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
7364 | ||
7365 | return err; | |
7366 | } | |
7367 | ||
ad7e718c JB |
7368 | static struct sk_buff * |
7369 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
7370 | int approxlen, u32 portid, u32 seq, | |
7371 | enum nl80211_commands cmd, | |
567ffc35 JB |
7372 | enum nl80211_attrs attr, |
7373 | const struct nl80211_vendor_cmd_info *info, | |
7374 | gfp_t gfp) | |
ad7e718c JB |
7375 | { |
7376 | struct sk_buff *skb; | |
7377 | void *hdr; | |
7378 | struct nlattr *data; | |
7379 | ||
7380 | skb = nlmsg_new(approxlen + 100, gfp); | |
7381 | if (!skb) | |
7382 | return NULL; | |
7383 | ||
7384 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
7385 | if (!hdr) { | |
7386 | kfree_skb(skb); | |
7387 | return NULL; | |
7388 | } | |
7389 | ||
7390 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
7391 | goto nla_put_failure; | |
567ffc35 JB |
7392 | |
7393 | if (info) { | |
7394 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
7395 | info->vendor_id)) | |
7396 | goto nla_put_failure; | |
7397 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
7398 | info->subcmd)) | |
7399 | goto nla_put_failure; | |
7400 | } | |
7401 | ||
ad7e718c JB |
7402 | data = nla_nest_start(skb, attr); |
7403 | ||
7404 | ((void **)skb->cb)[0] = rdev; | |
7405 | ((void **)skb->cb)[1] = hdr; | |
7406 | ((void **)skb->cb)[2] = data; | |
7407 | ||
7408 | return skb; | |
7409 | ||
7410 | nla_put_failure: | |
7411 | kfree_skb(skb); | |
7412 | return NULL; | |
7413 | } | |
f4e583c8 | 7414 | |
e03ad6ea JB |
7415 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
7416 | enum nl80211_commands cmd, | |
7417 | enum nl80211_attrs attr, | |
7418 | int vendor_event_idx, | |
7419 | int approxlen, gfp_t gfp) | |
7420 | { | |
f26cbf40 | 7421 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
7422 | const struct nl80211_vendor_cmd_info *info; |
7423 | ||
7424 | switch (cmd) { | |
7425 | case NL80211_CMD_TESTMODE: | |
7426 | if (WARN_ON(vendor_event_idx != -1)) | |
7427 | return NULL; | |
7428 | info = NULL; | |
7429 | break; | |
7430 | case NL80211_CMD_VENDOR: | |
7431 | if (WARN_ON(vendor_event_idx < 0 || | |
7432 | vendor_event_idx >= wiphy->n_vendor_events)) | |
7433 | return NULL; | |
7434 | info = &wiphy->vendor_events[vendor_event_idx]; | |
7435 | break; | |
7436 | default: | |
7437 | WARN_ON(1); | |
7438 | return NULL; | |
7439 | } | |
7440 | ||
7441 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, | |
7442 | cmd, attr, info, gfp); | |
7443 | } | |
7444 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
7445 | ||
7446 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
7447 | { | |
7448 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
7449 | void *hdr = ((void **)skb->cb)[1]; | |
7450 | struct nlattr *data = ((void **)skb->cb)[2]; | |
7451 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
7452 | ||
bd8c78e7 JB |
7453 | /* clear CB data for netlink core to own from now on */ |
7454 | memset(skb->cb, 0, sizeof(skb->cb)); | |
7455 | ||
e03ad6ea JB |
7456 | nla_nest_end(skb, data); |
7457 | genlmsg_end(skb, hdr); | |
7458 | ||
7459 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
7460 | mcgrp = NL80211_MCGRP_VENDOR; | |
7461 | ||
7462 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
7463 | mcgrp, gfp); | |
7464 | } | |
7465 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
7466 | ||
aff89a9b | 7467 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
7468 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
7469 | { | |
4c476991 | 7470 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
7471 | struct wireless_dev *wdev = |
7472 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
7473 | int err; |
7474 | ||
fc73f11f DS |
7475 | if (!rdev->ops->testmode_cmd) |
7476 | return -EOPNOTSUPP; | |
7477 | ||
7478 | if (IS_ERR(wdev)) { | |
7479 | err = PTR_ERR(wdev); | |
7480 | if (err != -EINVAL) | |
7481 | return err; | |
7482 | wdev = NULL; | |
7483 | } else if (wdev->wiphy != &rdev->wiphy) { | |
7484 | return -EINVAL; | |
7485 | } | |
7486 | ||
aff89a9b JB |
7487 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
7488 | return -EINVAL; | |
7489 | ||
ad7e718c | 7490 | rdev->cur_cmd_info = info; |
fc73f11f | 7491 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
7492 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
7493 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 7494 | rdev->cur_cmd_info = NULL; |
aff89a9b | 7495 | |
aff89a9b JB |
7496 | return err; |
7497 | } | |
7498 | ||
71063f0e WYG |
7499 | static int nl80211_testmode_dump(struct sk_buff *skb, |
7500 | struct netlink_callback *cb) | |
7501 | { | |
00918d33 | 7502 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
7503 | int err; |
7504 | long phy_idx; | |
7505 | void *data = NULL; | |
7506 | int data_len = 0; | |
7507 | ||
5fe231e8 JB |
7508 | rtnl_lock(); |
7509 | ||
71063f0e WYG |
7510 | if (cb->args[0]) { |
7511 | /* | |
7512 | * 0 is a valid index, but not valid for args[0], | |
7513 | * so we need to offset by 1. | |
7514 | */ | |
7515 | phy_idx = cb->args[0] - 1; | |
7516 | } else { | |
7517 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
7518 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
7519 | nl80211_policy); | |
7520 | if (err) | |
5fe231e8 | 7521 | goto out_err; |
00918d33 | 7522 | |
2bd7e35d JB |
7523 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
7524 | nl80211_fam.attrbuf); | |
7525 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
7526 | err = PTR_ERR(rdev); |
7527 | goto out_err; | |
00918d33 | 7528 | } |
2bd7e35d JB |
7529 | phy_idx = rdev->wiphy_idx; |
7530 | rdev = NULL; | |
2bd7e35d | 7531 | |
71063f0e WYG |
7532 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
7533 | cb->args[1] = | |
7534 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
7535 | } | |
7536 | ||
7537 | if (cb->args[1]) { | |
7538 | data = nla_data((void *)cb->args[1]); | |
7539 | data_len = nla_len((void *)cb->args[1]); | |
7540 | } | |
7541 | ||
00918d33 JB |
7542 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
7543 | if (!rdev) { | |
5fe231e8 JB |
7544 | err = -ENOENT; |
7545 | goto out_err; | |
71063f0e | 7546 | } |
71063f0e | 7547 | |
00918d33 | 7548 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
7549 | err = -EOPNOTSUPP; |
7550 | goto out_err; | |
7551 | } | |
7552 | ||
7553 | while (1) { | |
15e47304 | 7554 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
7555 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
7556 | NL80211_CMD_TESTMODE); | |
7557 | struct nlattr *tmdata; | |
7558 | ||
cb35fba3 DC |
7559 | if (!hdr) |
7560 | break; | |
7561 | ||
9360ffd1 | 7562 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
7563 | genlmsg_cancel(skb, hdr); |
7564 | break; | |
7565 | } | |
7566 | ||
7567 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
7568 | if (!tmdata) { | |
7569 | genlmsg_cancel(skb, hdr); | |
7570 | break; | |
7571 | } | |
e35e4d28 | 7572 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
7573 | nla_nest_end(skb, tmdata); |
7574 | ||
7575 | if (err == -ENOBUFS || err == -ENOENT) { | |
7576 | genlmsg_cancel(skb, hdr); | |
7577 | break; | |
7578 | } else if (err) { | |
7579 | genlmsg_cancel(skb, hdr); | |
7580 | goto out_err; | |
7581 | } | |
7582 | ||
7583 | genlmsg_end(skb, hdr); | |
7584 | } | |
7585 | ||
7586 | err = skb->len; | |
7587 | /* see above */ | |
7588 | cb->args[0] = phy_idx + 1; | |
7589 | out_err: | |
5fe231e8 | 7590 | rtnl_unlock(); |
71063f0e WYG |
7591 | return err; |
7592 | } | |
aff89a9b JB |
7593 | #endif |
7594 | ||
b23aa676 SO |
7595 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
7596 | { | |
4c476991 JB |
7597 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7598 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
7599 | struct cfg80211_connect_params connect; |
7600 | struct wiphy *wiphy; | |
fffd0934 | 7601 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
7602 | int err; |
7603 | ||
7604 | memset(&connect, 0, sizeof(connect)); | |
7605 | ||
7606 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
7607 | return -EINVAL; | |
7608 | ||
7609 | if (!info->attrs[NL80211_ATTR_SSID] || | |
7610 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
7611 | return -EINVAL; | |
7612 | ||
7613 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
7614 | connect.auth_type = | |
7615 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
7616 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
7617 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
7618 | return -EINVAL; |
7619 | } else | |
7620 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
7621 | ||
7622 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
7623 | ||
c0692b8f | 7624 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 7625 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
7626 | if (err) |
7627 | return err; | |
b23aa676 | 7628 | |
074ac8df | 7629 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7630 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7631 | return -EOPNOTSUPP; | |
b23aa676 | 7632 | |
79c97e97 | 7633 | wiphy = &rdev->wiphy; |
b23aa676 | 7634 | |
4486ea98 BS |
7635 | connect.bg_scan_period = -1; |
7636 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
7637 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
7638 | connect.bg_scan_period = | |
7639 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
7640 | } | |
7641 | ||
b23aa676 SO |
7642 | if (info->attrs[NL80211_ATTR_MAC]) |
7643 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
7644 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
7645 | connect.bssid_hint = | |
7646 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
7647 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7648 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7649 | ||
7650 | if (info->attrs[NL80211_ATTR_IE]) { | |
7651 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7652 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7653 | } | |
7654 | ||
cee00a95 JM |
7655 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
7656 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
7657 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
7658 | connect.mfp != NL80211_MFP_NO) | |
7659 | return -EINVAL; | |
7660 | } else { | |
7661 | connect.mfp = NL80211_MFP_NO; | |
7662 | } | |
7663 | ||
b23aa676 | 7664 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
7665 | connect.channel = nl80211_get_valid_chan( |
7666 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7667 | if (!connect.channel) | |
1df4a510 JM |
7668 | return -EINVAL; |
7669 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
7670 | connect.channel_hint = nl80211_get_valid_chan( |
7671 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
7672 | if (!connect.channel_hint) | |
4c476991 | 7673 | return -EINVAL; |
b23aa676 SO |
7674 | } |
7675 | ||
fffd0934 JB |
7676 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
7677 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 7678 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
7679 | if (IS_ERR(connkeys)) |
7680 | return PTR_ERR(connkeys); | |
fffd0934 JB |
7681 | } |
7682 | ||
7e7c8926 BG |
7683 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
7684 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
7685 | ||
7686 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7687 | memcpy(&connect.ht_capa_mask, | |
7688 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7689 | sizeof(connect.ht_capa_mask)); | |
7690 | ||
7691 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e | 7692 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
b47f610b | 7693 | kzfree(connkeys); |
7e7c8926 | 7694 | return -EINVAL; |
b4e4f47e | 7695 | } |
7e7c8926 BG |
7696 | memcpy(&connect.ht_capa, |
7697 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7698 | sizeof(connect.ht_capa)); | |
7699 | } | |
7700 | ||
ee2aca34 JB |
7701 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
7702 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
7703 | ||
7704 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
7705 | memcpy(&connect.vht_capa_mask, | |
7706 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7707 | sizeof(connect.vht_capa_mask)); | |
7708 | ||
7709 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
7710 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
b47f610b | 7711 | kzfree(connkeys); |
ee2aca34 JB |
7712 | return -EINVAL; |
7713 | } | |
7714 | memcpy(&connect.vht_capa, | |
7715 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7716 | sizeof(connect.vht_capa)); | |
7717 | } | |
7718 | ||
bab5ab7d AK |
7719 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7720 | if (!(rdev->wiphy.features & | |
7721 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7722 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7723 | return -EINVAL; | |
7724 | connect.flags |= ASSOC_REQ_USE_RRM; | |
7725 | } | |
7726 | ||
83739b03 JB |
7727 | wdev_lock(dev->ieee80211_ptr); |
7728 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
7729 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 | 7730 | if (err) |
b47f610b | 7731 | kzfree(connkeys); |
b23aa676 SO |
7732 | return err; |
7733 | } | |
7734 | ||
7735 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
7736 | { | |
4c476991 JB |
7737 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7738 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 7739 | u16 reason; |
83739b03 | 7740 | int ret; |
b23aa676 SO |
7741 | |
7742 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7743 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
7744 | else | |
7745 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
7746 | ||
7747 | if (reason == 0) | |
7748 | return -EINVAL; | |
7749 | ||
074ac8df | 7750 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7751 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7752 | return -EOPNOTSUPP; | |
b23aa676 | 7753 | |
83739b03 JB |
7754 | wdev_lock(dev->ieee80211_ptr); |
7755 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
7756 | wdev_unlock(dev->ieee80211_ptr); | |
7757 | return ret; | |
b23aa676 SO |
7758 | } |
7759 | ||
463d0183 JB |
7760 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
7761 | { | |
4c476991 | 7762 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
7763 | struct net *net; |
7764 | int err; | |
7765 | u32 pid; | |
7766 | ||
7767 | if (!info->attrs[NL80211_ATTR_PID]) | |
7768 | return -EINVAL; | |
7769 | ||
7770 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
7771 | ||
463d0183 | 7772 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
7773 | if (IS_ERR(net)) |
7774 | return PTR_ERR(net); | |
463d0183 JB |
7775 | |
7776 | err = 0; | |
7777 | ||
7778 | /* check if anything to do */ | |
4c476991 JB |
7779 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
7780 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 7781 | |
463d0183 | 7782 | put_net(net); |
463d0183 JB |
7783 | return err; |
7784 | } | |
7785 | ||
67fbb16b SO |
7786 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
7787 | { | |
4c476991 | 7788 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
7789 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
7790 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 7791 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
7792 | struct cfg80211_pmksa pmksa; |
7793 | ||
7794 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
7795 | ||
7796 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7797 | return -EINVAL; | |
7798 | ||
7799 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
7800 | return -EINVAL; | |
7801 | ||
67fbb16b SO |
7802 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
7803 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7804 | ||
074ac8df | 7805 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7806 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7807 | return -EOPNOTSUPP; | |
67fbb16b SO |
7808 | |
7809 | switch (info->genlhdr->cmd) { | |
7810 | case NL80211_CMD_SET_PMKSA: | |
7811 | rdev_ops = rdev->ops->set_pmksa; | |
7812 | break; | |
7813 | case NL80211_CMD_DEL_PMKSA: | |
7814 | rdev_ops = rdev->ops->del_pmksa; | |
7815 | break; | |
7816 | default: | |
7817 | WARN_ON(1); | |
7818 | break; | |
7819 | } | |
7820 | ||
4c476991 JB |
7821 | if (!rdev_ops) |
7822 | return -EOPNOTSUPP; | |
67fbb16b | 7823 | |
4c476991 | 7824 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
7825 | } |
7826 | ||
7827 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
7828 | { | |
4c476991 JB |
7829 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7830 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 7831 | |
074ac8df | 7832 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7833 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7834 | return -EOPNOTSUPP; | |
67fbb16b | 7835 | |
4c476991 JB |
7836 | if (!rdev->ops->flush_pmksa) |
7837 | return -EOPNOTSUPP; | |
67fbb16b | 7838 | |
e35e4d28 | 7839 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
7840 | } |
7841 | ||
109086ce AN |
7842 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
7843 | { | |
7844 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7845 | struct net_device *dev = info->user_ptr[1]; | |
7846 | u8 action_code, dialog_token; | |
df942e7b | 7847 | u32 peer_capability = 0; |
109086ce AN |
7848 | u16 status_code; |
7849 | u8 *peer; | |
31fa97c5 | 7850 | bool initiator; |
109086ce AN |
7851 | |
7852 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7853 | !rdev->ops->tdls_mgmt) | |
7854 | return -EOPNOTSUPP; | |
7855 | ||
7856 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
7857 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
7858 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
7859 | !info->attrs[NL80211_ATTR_IE] || | |
7860 | !info->attrs[NL80211_ATTR_MAC]) | |
7861 | return -EINVAL; | |
7862 | ||
7863 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7864 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
7865 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
7866 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 7867 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
7868 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
7869 | peer_capability = | |
7870 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 7871 | |
e35e4d28 | 7872 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 7873 | dialog_token, status_code, peer_capability, |
31fa97c5 | 7874 | initiator, |
e35e4d28 HG |
7875 | nla_data(info->attrs[NL80211_ATTR_IE]), |
7876 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
7877 | } |
7878 | ||
7879 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
7880 | { | |
7881 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7882 | struct net_device *dev = info->user_ptr[1]; | |
7883 | enum nl80211_tdls_operation operation; | |
7884 | u8 *peer; | |
7885 | ||
7886 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7887 | !rdev->ops->tdls_oper) | |
7888 | return -EOPNOTSUPP; | |
7889 | ||
7890 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
7891 | !info->attrs[NL80211_ATTR_MAC]) | |
7892 | return -EINVAL; | |
7893 | ||
7894 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
7895 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7896 | ||
e35e4d28 | 7897 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
7898 | } |
7899 | ||
9588bbd5 JM |
7900 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
7901 | struct genl_info *info) | |
7902 | { | |
4c476991 | 7903 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7904 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7905 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
7906 | struct sk_buff *msg; |
7907 | void *hdr; | |
7908 | u64 cookie; | |
683b6d3b | 7909 | u32 duration; |
9588bbd5 JM |
7910 | int err; |
7911 | ||
7912 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7913 | !info->attrs[NL80211_ATTR_DURATION]) | |
7914 | return -EINVAL; | |
7915 | ||
7916 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
7917 | ||
ebf348fc JB |
7918 | if (!rdev->ops->remain_on_channel || |
7919 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
7920 | return -EOPNOTSUPP; | |
7921 | ||
9588bbd5 | 7922 | /* |
ebf348fc JB |
7923 | * We should be on that channel for at least a minimum amount of |
7924 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 7925 | */ |
ebf348fc | 7926 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 7927 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
7928 | return -EINVAL; |
7929 | ||
683b6d3b JB |
7930 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7931 | if (err) | |
7932 | return err; | |
9588bbd5 JM |
7933 | |
7934 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7935 | if (!msg) |
7936 | return -ENOMEM; | |
9588bbd5 | 7937 | |
15e47304 | 7938 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 7939 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
7940 | if (!hdr) { |
7941 | err = -ENOBUFS; | |
9588bbd5 JM |
7942 | goto free_msg; |
7943 | } | |
7944 | ||
683b6d3b JB |
7945 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7946 | duration, &cookie); | |
9588bbd5 JM |
7947 | |
7948 | if (err) | |
7949 | goto free_msg; | |
7950 | ||
9360ffd1 DM |
7951 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7952 | goto nla_put_failure; | |
9588bbd5 JM |
7953 | |
7954 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7955 | |
7956 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7957 | |
7958 | nla_put_failure: | |
7959 | err = -ENOBUFS; | |
7960 | free_msg: | |
7961 | nlmsg_free(msg); | |
9588bbd5 JM |
7962 | return err; |
7963 | } | |
7964 | ||
7965 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
7966 | struct genl_info *info) | |
7967 | { | |
4c476991 | 7968 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7969 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 7970 | u64 cookie; |
9588bbd5 JM |
7971 | |
7972 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7973 | return -EINVAL; | |
7974 | ||
4c476991 JB |
7975 | if (!rdev->ops->cancel_remain_on_channel) |
7976 | return -EOPNOTSUPP; | |
9588bbd5 | 7977 | |
9588bbd5 JM |
7978 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
7979 | ||
e35e4d28 | 7980 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
7981 | } |
7982 | ||
13ae75b1 JM |
7983 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
7984 | u8 *rates, u8 rates_len) | |
7985 | { | |
7986 | u8 i; | |
7987 | u32 mask = 0; | |
7988 | ||
7989 | for (i = 0; i < rates_len; i++) { | |
7990 | int rate = (rates[i] & 0x7f) * 5; | |
7991 | int ridx; | |
7992 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
7993 | struct ieee80211_rate *srate = | |
7994 | &sband->bitrates[ridx]; | |
7995 | if (rate == srate->bitrate) { | |
7996 | mask |= 1 << ridx; | |
7997 | break; | |
7998 | } | |
7999 | } | |
8000 | if (ridx == sband->n_bitrates) | |
8001 | return 0; /* rate not found */ | |
8002 | } | |
8003 | ||
8004 | return mask; | |
8005 | } | |
8006 | ||
24db78c0 SW |
8007 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
8008 | u8 *rates, u8 rates_len, | |
8009 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
8010 | { | |
8011 | u8 i; | |
8012 | ||
8013 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
8014 | ||
8015 | for (i = 0; i < rates_len; i++) { | |
8016 | int ridx, rbit; | |
8017 | ||
8018 | ridx = rates[i] / 8; | |
8019 | rbit = BIT(rates[i] % 8); | |
8020 | ||
8021 | /* check validity */ | |
910570b5 | 8022 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
8023 | return false; |
8024 | ||
8025 | /* check availability */ | |
8026 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
8027 | mcs[ridx] |= rbit; | |
8028 | else | |
8029 | return false; | |
8030 | } | |
8031 | ||
8032 | return true; | |
8033 | } | |
8034 | ||
204e35a9 JD |
8035 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
8036 | { | |
8037 | u16 mcs_mask = 0; | |
8038 | ||
8039 | switch (vht_mcs_map) { | |
8040 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
8041 | break; | |
8042 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
8043 | mcs_mask = 0x00FF; | |
8044 | break; | |
8045 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
8046 | mcs_mask = 0x01FF; | |
8047 | break; | |
8048 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
8049 | mcs_mask = 0x03FF; | |
8050 | break; | |
8051 | default: | |
8052 | break; | |
8053 | } | |
8054 | ||
8055 | return mcs_mask; | |
8056 | } | |
8057 | ||
8058 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
8059 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
8060 | { | |
8061 | u8 nss; | |
8062 | ||
8063 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
8064 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
8065 | vht_mcs_map >>= 2; | |
8066 | } | |
8067 | } | |
8068 | ||
8069 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
8070 | struct nl80211_txrate_vht *txrate, | |
8071 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
8072 | { | |
8073 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8074 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
8075 | u8 i; | |
8076 | ||
8077 | if (!sband->vht_cap.vht_supported) | |
8078 | return false; | |
8079 | ||
8080 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
8081 | ||
8082 | /* Build vht_mcs_mask from VHT capabilities */ | |
8083 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
8084 | ||
8085 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
8086 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
8087 | mcs[i] = txrate->mcs[i]; | |
8088 | else | |
8089 | return false; | |
8090 | } | |
8091 | ||
8092 | return true; | |
8093 | } | |
8094 | ||
b54452b0 | 8095 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
8096 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
8097 | .len = NL80211_MAX_SUPP_RATES }, | |
d1e33e65 JD |
8098 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
8099 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
204e35a9 | 8100 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
0b9323f6 | 8101 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
13ae75b1 JM |
8102 | }; |
8103 | ||
8104 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
8105 | struct genl_info *info) | |
8106 | { | |
8107 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 8108 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 8109 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
8110 | int rem, i; |
8111 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
8112 | struct nlattr *tx_rates; |
8113 | struct ieee80211_supported_band *sband; | |
204e35a9 | 8114 | u16 vht_tx_mcs_map; |
13ae75b1 | 8115 | |
4c476991 JB |
8116 | if (!rdev->ops->set_bitrate_mask) |
8117 | return -EOPNOTSUPP; | |
13ae75b1 JM |
8118 | |
8119 | memset(&mask, 0, sizeof(mask)); | |
8120 | /* Default to all rates enabled */ | |
8121 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
8122 | sband = rdev->wiphy.bands[i]; | |
7869303b JD |
8123 | |
8124 | if (!sband) | |
8125 | continue; | |
8126 | ||
8127 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; | |
d1e33e65 | 8128 | memcpy(mask.control[i].ht_mcs, |
7869303b | 8129 | sband->ht_cap.mcs.rx_mask, |
d1e33e65 | 8130 | sizeof(mask.control[i].ht_mcs)); |
204e35a9 JD |
8131 | |
8132 | if (!sband->vht_cap.vht_supported) | |
8133 | continue; | |
8134 | ||
8135 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8136 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); | |
13ae75b1 JM |
8137 | } |
8138 | ||
b9243ab0 JD |
8139 | /* if no rates are given set it back to the defaults */ |
8140 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
8141 | goto out; | |
8142 | ||
13ae75b1 JM |
8143 | /* |
8144 | * The nested attribute uses enum nl80211_band as the index. This maps | |
8145 | * directly to the enum ieee80211_band values used in cfg80211. | |
8146 | */ | |
24db78c0 | 8147 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
ae811e21 | 8148 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
13ae75b1 | 8149 | enum ieee80211_band band = nla_type(tx_rates); |
ae811e21 JB |
8150 | int err; |
8151 | ||
4c476991 JB |
8152 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
8153 | return -EINVAL; | |
13ae75b1 | 8154 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
8155 | if (sband == NULL) |
8156 | return -EINVAL; | |
ae811e21 JB |
8157 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
8158 | nla_len(tx_rates), nl80211_txattr_policy); | |
8159 | if (err) | |
8160 | return err; | |
13ae75b1 JM |
8161 | if (tb[NL80211_TXRATE_LEGACY]) { |
8162 | mask.control[band].legacy = rateset_to_mask( | |
8163 | sband, | |
8164 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
8165 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
8166 | if ((mask.control[band].legacy == 0) && |
8167 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
8168 | return -EINVAL; | |
24db78c0 | 8169 | } |
d1e33e65 | 8170 | if (tb[NL80211_TXRATE_HT]) { |
24db78c0 SW |
8171 | if (!ht_rateset_to_mask( |
8172 | sband, | |
d1e33e65 JD |
8173 | nla_data(tb[NL80211_TXRATE_HT]), |
8174 | nla_len(tb[NL80211_TXRATE_HT]), | |
8175 | mask.control[band].ht_mcs)) | |
24db78c0 SW |
8176 | return -EINVAL; |
8177 | } | |
204e35a9 JD |
8178 | if (tb[NL80211_TXRATE_VHT]) { |
8179 | if (!vht_set_mcs_mask( | |
8180 | sband, | |
8181 | nla_data(tb[NL80211_TXRATE_VHT]), | |
8182 | mask.control[band].vht_mcs)) | |
8183 | return -EINVAL; | |
8184 | } | |
0b9323f6 JD |
8185 | if (tb[NL80211_TXRATE_GI]) { |
8186 | mask.control[band].gi = | |
8187 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
8188 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
8189 | return -EINVAL; | |
8190 | } | |
24db78c0 SW |
8191 | |
8192 | if (mask.control[band].legacy == 0) { | |
204e35a9 JD |
8193 | /* don't allow empty legacy rates if HT or VHT |
8194 | * are not even supported. | |
8195 | */ | |
8196 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
8197 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
24db78c0 SW |
8198 | return -EINVAL; |
8199 | ||
8200 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
d1e33e65 | 8201 | if (mask.control[band].ht_mcs[i]) |
204e35a9 JD |
8202 | goto out; |
8203 | ||
8204 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
8205 | if (mask.control[band].vht_mcs[i]) | |
8206 | goto out; | |
24db78c0 SW |
8207 | |
8208 | /* legacy and mcs rates may not be both empty */ | |
204e35a9 | 8209 | return -EINVAL; |
13ae75b1 JM |
8210 | } |
8211 | } | |
8212 | ||
b9243ab0 | 8213 | out: |
e35e4d28 | 8214 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
8215 | } |
8216 | ||
2e161f78 | 8217 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8218 | { |
4c476991 | 8219 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8220 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 8221 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
8222 | |
8223 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
8224 | return -EINVAL; | |
8225 | ||
2e161f78 JB |
8226 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
8227 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 8228 | |
71bbc994 JB |
8229 | switch (wdev->iftype) { |
8230 | case NL80211_IFTYPE_STATION: | |
8231 | case NL80211_IFTYPE_ADHOC: | |
8232 | case NL80211_IFTYPE_P2P_CLIENT: | |
8233 | case NL80211_IFTYPE_AP: | |
8234 | case NL80211_IFTYPE_AP_VLAN: | |
8235 | case NL80211_IFTYPE_MESH_POINT: | |
8236 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8237 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8238 | break; |
8239 | default: | |
4c476991 | 8240 | return -EOPNOTSUPP; |
71bbc994 | 8241 | } |
026331c4 JM |
8242 | |
8243 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
8244 | if (!rdev->ops->mgmt_tx) |
8245 | return -EOPNOTSUPP; | |
026331c4 | 8246 | |
15e47304 | 8247 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
8248 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
8249 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
8250 | } |
8251 | ||
2e161f78 | 8252 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8253 | { |
4c476991 | 8254 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8255 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 8256 | struct cfg80211_chan_def chandef; |
026331c4 | 8257 | int err; |
d64d373f | 8258 | void *hdr = NULL; |
026331c4 | 8259 | u64 cookie; |
e247bd90 | 8260 | struct sk_buff *msg = NULL; |
b176e629 AO |
8261 | struct cfg80211_mgmt_tx_params params = { |
8262 | .dont_wait_for_ack = | |
8263 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
8264 | }; | |
026331c4 | 8265 | |
683b6d3b | 8266 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
8267 | return -EINVAL; |
8268 | ||
4c476991 JB |
8269 | if (!rdev->ops->mgmt_tx) |
8270 | return -EOPNOTSUPP; | |
026331c4 | 8271 | |
71bbc994 | 8272 | switch (wdev->iftype) { |
ea141b75 AQ |
8273 | case NL80211_IFTYPE_P2P_DEVICE: |
8274 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
8275 | return -EINVAL; | |
71bbc994 JB |
8276 | case NL80211_IFTYPE_STATION: |
8277 | case NL80211_IFTYPE_ADHOC: | |
8278 | case NL80211_IFTYPE_P2P_CLIENT: | |
8279 | case NL80211_IFTYPE_AP: | |
8280 | case NL80211_IFTYPE_AP_VLAN: | |
8281 | case NL80211_IFTYPE_MESH_POINT: | |
8282 | case NL80211_IFTYPE_P2P_GO: | |
8283 | break; | |
8284 | default: | |
4c476991 | 8285 | return -EOPNOTSUPP; |
71bbc994 | 8286 | } |
026331c4 | 8287 | |
f7ca38df | 8288 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 8289 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 8290 | return -EINVAL; |
b176e629 | 8291 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
8292 | |
8293 | /* | |
8294 | * We should wait on the channel for at least a minimum amount | |
8295 | * of time (10ms) but no longer than the driver supports. | |
8296 | */ | |
b176e629 AO |
8297 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
8298 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc JB |
8299 | return -EINVAL; |
8300 | ||
f7ca38df JB |
8301 | } |
8302 | ||
b176e629 | 8303 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 8304 | |
b176e629 | 8305 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
8306 | return -EINVAL; |
8307 | ||
b176e629 | 8308 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 8309 | |
ea141b75 AQ |
8310 | /* get the channel if any has been specified, otherwise pass NULL to |
8311 | * the driver. The latter will use the current one | |
8312 | */ | |
8313 | chandef.chan = NULL; | |
8314 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
8315 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
8316 | if (err) | |
8317 | return err; | |
8318 | } | |
8319 | ||
b176e629 | 8320 | if (!chandef.chan && params.offchan) |
ea141b75 | 8321 | return -EINVAL; |
026331c4 | 8322 | |
34d22ce2 AO |
8323 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
8324 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
8325 | ||
8326 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
8327 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8328 | int i; | |
8329 | ||
8330 | if (len % sizeof(u16)) | |
8331 | return -EINVAL; | |
8332 | ||
8333 | params.n_csa_offsets = len / sizeof(u16); | |
8334 | params.csa_offsets = | |
8335 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8336 | ||
8337 | /* check that all the offsets fit the frame */ | |
8338 | for (i = 0; i < params.n_csa_offsets; i++) { | |
8339 | if (params.csa_offsets[i] >= params.len) | |
8340 | return -EINVAL; | |
8341 | } | |
8342 | } | |
8343 | ||
b176e629 | 8344 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
8345 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
8346 | if (!msg) | |
8347 | return -ENOMEM; | |
026331c4 | 8348 | |
15e47304 | 8349 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 8350 | NL80211_CMD_FRAME); |
cb35fba3 DC |
8351 | if (!hdr) { |
8352 | err = -ENOBUFS; | |
e247bd90 JB |
8353 | goto free_msg; |
8354 | } | |
026331c4 | 8355 | } |
e247bd90 | 8356 | |
b176e629 AO |
8357 | params.chan = chandef.chan; |
8358 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
8359 | if (err) |
8360 | goto free_msg; | |
8361 | ||
e247bd90 | 8362 | if (msg) { |
9360ffd1 DM |
8363 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8364 | goto nla_put_failure; | |
026331c4 | 8365 | |
e247bd90 JB |
8366 | genlmsg_end(msg, hdr); |
8367 | return genlmsg_reply(msg, info); | |
8368 | } | |
8369 | ||
8370 | return 0; | |
026331c4 JM |
8371 | |
8372 | nla_put_failure: | |
8373 | err = -ENOBUFS; | |
8374 | free_msg: | |
8375 | nlmsg_free(msg); | |
026331c4 JM |
8376 | return err; |
8377 | } | |
8378 | ||
f7ca38df JB |
8379 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
8380 | { | |
8381 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 8382 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
8383 | u64 cookie; |
8384 | ||
8385 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8386 | return -EINVAL; | |
8387 | ||
8388 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
8389 | return -EOPNOTSUPP; | |
8390 | ||
71bbc994 JB |
8391 | switch (wdev->iftype) { |
8392 | case NL80211_IFTYPE_STATION: | |
8393 | case NL80211_IFTYPE_ADHOC: | |
8394 | case NL80211_IFTYPE_P2P_CLIENT: | |
8395 | case NL80211_IFTYPE_AP: | |
8396 | case NL80211_IFTYPE_AP_VLAN: | |
8397 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8398 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8399 | break; |
8400 | default: | |
f7ca38df | 8401 | return -EOPNOTSUPP; |
71bbc994 | 8402 | } |
f7ca38df JB |
8403 | |
8404 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
8405 | ||
e35e4d28 | 8406 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
8407 | } |
8408 | ||
ffb9eb3d KV |
8409 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
8410 | { | |
4c476991 | 8411 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 8412 | struct wireless_dev *wdev; |
4c476991 | 8413 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8414 | u8 ps_state; |
8415 | bool state; | |
8416 | int err; | |
8417 | ||
4c476991 JB |
8418 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
8419 | return -EINVAL; | |
ffb9eb3d KV |
8420 | |
8421 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
8422 | ||
4c476991 JB |
8423 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
8424 | return -EINVAL; | |
ffb9eb3d KV |
8425 | |
8426 | wdev = dev->ieee80211_ptr; | |
8427 | ||
4c476991 JB |
8428 | if (!rdev->ops->set_power_mgmt) |
8429 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8430 | |
8431 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
8432 | ||
8433 | if (state == wdev->ps) | |
4c476991 | 8434 | return 0; |
ffb9eb3d | 8435 | |
e35e4d28 | 8436 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
8437 | if (!err) |
8438 | wdev->ps = state; | |
ffb9eb3d KV |
8439 | return err; |
8440 | } | |
8441 | ||
8442 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
8443 | { | |
4c476991 | 8444 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
8445 | enum nl80211_ps_state ps_state; |
8446 | struct wireless_dev *wdev; | |
4c476991 | 8447 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8448 | struct sk_buff *msg; |
8449 | void *hdr; | |
8450 | int err; | |
8451 | ||
ffb9eb3d KV |
8452 | wdev = dev->ieee80211_ptr; |
8453 | ||
4c476991 JB |
8454 | if (!rdev->ops->set_power_mgmt) |
8455 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8456 | |
8457 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
8458 | if (!msg) |
8459 | return -ENOMEM; | |
ffb9eb3d | 8460 | |
15e47304 | 8461 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
8462 | NL80211_CMD_GET_POWER_SAVE); |
8463 | if (!hdr) { | |
4c476991 | 8464 | err = -ENOBUFS; |
ffb9eb3d KV |
8465 | goto free_msg; |
8466 | } | |
8467 | ||
8468 | if (wdev->ps) | |
8469 | ps_state = NL80211_PS_ENABLED; | |
8470 | else | |
8471 | ps_state = NL80211_PS_DISABLED; | |
8472 | ||
9360ffd1 DM |
8473 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
8474 | goto nla_put_failure; | |
ffb9eb3d KV |
8475 | |
8476 | genlmsg_end(msg, hdr); | |
4c476991 | 8477 | return genlmsg_reply(msg, info); |
ffb9eb3d | 8478 | |
4c476991 | 8479 | nla_put_failure: |
ffb9eb3d | 8480 | err = -ENOBUFS; |
4c476991 | 8481 | free_msg: |
ffb9eb3d | 8482 | nlmsg_free(msg); |
ffb9eb3d KV |
8483 | return err; |
8484 | } | |
8485 | ||
94e860f1 JB |
8486 | static const struct nla_policy |
8487 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
8488 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
8489 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
8490 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
8491 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
8492 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
8493 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
8494 | }; |
8495 | ||
84f10708 | 8496 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 8497 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
8498 | { |
8499 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 8500 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8501 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 8502 | |
d9d8b019 | 8503 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
8504 | return -EINVAL; |
8505 | ||
84f10708 TP |
8506 | if (!rdev->ops->set_cqm_txe_config) |
8507 | return -EOPNOTSUPP; | |
8508 | ||
8509 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
8510 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
8511 | return -EOPNOTSUPP; | |
8512 | ||
e35e4d28 | 8513 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
8514 | } |
8515 | ||
d6dc1a38 JO |
8516 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
8517 | s32 threshold, u32 hysteresis) | |
8518 | { | |
4c476991 | 8519 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 8520 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8521 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
8522 | |
8523 | if (threshold > 0) | |
8524 | return -EINVAL; | |
8525 | ||
1da5fcc8 JB |
8526 | /* disabling - hysteresis should also be zero then */ |
8527 | if (threshold == 0) | |
8528 | hysteresis = 0; | |
d6dc1a38 | 8529 | |
4c476991 JB |
8530 | if (!rdev->ops->set_cqm_rssi_config) |
8531 | return -EOPNOTSUPP; | |
d6dc1a38 | 8532 | |
074ac8df | 8533 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8534 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8535 | return -EOPNOTSUPP; | |
d6dc1a38 | 8536 | |
e35e4d28 | 8537 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
8538 | } |
8539 | ||
8540 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
8541 | { | |
8542 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
8543 | struct nlattr *cqm; | |
8544 | int err; | |
8545 | ||
8546 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
8547 | if (!cqm) |
8548 | return -EINVAL; | |
d6dc1a38 JO |
8549 | |
8550 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
8551 | nl80211_attr_cqm_policy); | |
8552 | if (err) | |
1da5fcc8 | 8553 | return err; |
d6dc1a38 JO |
8554 | |
8555 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
8556 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
8557 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
8558 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 8559 | |
1da5fcc8 JB |
8560 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
8561 | } | |
8562 | ||
8563 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
8564 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
8565 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
8566 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
8567 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
8568 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
8569 | ||
8570 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
8571 | } | |
8572 | ||
8573 | return -EINVAL; | |
d6dc1a38 JO |
8574 | } |
8575 | ||
6e0bd6c3 RL |
8576 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
8577 | { | |
8578 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8579 | struct net_device *dev = info->user_ptr[1]; | |
8580 | struct ocb_setup setup = {}; | |
8581 | int err; | |
8582 | ||
8583 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | |
8584 | if (err) | |
8585 | return err; | |
8586 | ||
8587 | return cfg80211_join_ocb(rdev, dev, &setup); | |
8588 | } | |
8589 | ||
8590 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | |
8591 | { | |
8592 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8593 | struct net_device *dev = info->user_ptr[1]; | |
8594 | ||
8595 | return cfg80211_leave_ocb(rdev, dev); | |
8596 | } | |
8597 | ||
29cbe68c JB |
8598 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
8599 | { | |
8600 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8601 | struct net_device *dev = info->user_ptr[1]; | |
8602 | struct mesh_config cfg; | |
c80d545d | 8603 | struct mesh_setup setup; |
29cbe68c JB |
8604 | int err; |
8605 | ||
8606 | /* start with default */ | |
8607 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 8608 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 8609 | |
24bdd9f4 | 8610 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 8611 | /* and parse parameters if given */ |
24bdd9f4 | 8612 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
8613 | if (err) |
8614 | return err; | |
8615 | } | |
8616 | ||
8617 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
8618 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
8619 | return -EINVAL; | |
8620 | ||
c80d545d JC |
8621 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
8622 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
8623 | ||
4bb62344 CYY |
8624 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8625 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
8626 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8627 | return -EINVAL; | |
8628 | ||
9bdbf04d MP |
8629 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
8630 | setup.beacon_interval = | |
8631 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
8632 | if (setup.beacon_interval < 10 || | |
8633 | setup.beacon_interval > 10000) | |
8634 | return -EINVAL; | |
8635 | } | |
8636 | ||
8637 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
8638 | setup.dtim_period = | |
8639 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
8640 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
8641 | return -EINVAL; | |
8642 | } | |
8643 | ||
c80d545d JC |
8644 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
8645 | /* parse additional setup parameters if given */ | |
8646 | err = nl80211_parse_mesh_setup(info, &setup); | |
8647 | if (err) | |
8648 | return err; | |
8649 | } | |
8650 | ||
d37bb18a TP |
8651 | if (setup.user_mpm) |
8652 | cfg.auto_open_plinks = false; | |
8653 | ||
cc1d2806 | 8654 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
8655 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
8656 | if (err) | |
8657 | return err; | |
cc1d2806 JB |
8658 | } else { |
8659 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 8660 | setup.chandef.chan = NULL; |
cc1d2806 JB |
8661 | } |
8662 | ||
ffb3cf30 AN |
8663 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8664 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8665 | int n_rates = | |
8666 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8667 | struct ieee80211_supported_band *sband; | |
8668 | ||
8669 | if (!setup.chandef.chan) | |
8670 | return -EINVAL; | |
8671 | ||
8672 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
8673 | ||
8674 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
8675 | &setup.basic_rates); | |
8676 | if (err) | |
8677 | return err; | |
8678 | } | |
8679 | ||
c80d545d | 8680 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
8681 | } |
8682 | ||
8683 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
8684 | { | |
8685 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8686 | struct net_device *dev = info->user_ptr[1]; | |
8687 | ||
8688 | return cfg80211_leave_mesh(rdev, dev); | |
8689 | } | |
8690 | ||
dfb89c56 | 8691 | #ifdef CONFIG_PM |
bb92d199 AK |
8692 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
8693 | struct cfg80211_registered_device *rdev) | |
8694 | { | |
6abb9cb9 | 8695 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
8696 | struct nlattr *nl_pats, *nl_pat; |
8697 | int i, pat_len; | |
8698 | ||
6abb9cb9 | 8699 | if (!wowlan->n_patterns) |
bb92d199 AK |
8700 | return 0; |
8701 | ||
8702 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
8703 | if (!nl_pats) | |
8704 | return -ENOBUFS; | |
8705 | ||
6abb9cb9 | 8706 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
8707 | nl_pat = nla_nest_start(msg, i + 1); |
8708 | if (!nl_pat) | |
8709 | return -ENOBUFS; | |
6abb9cb9 | 8710 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 8711 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 8712 | wowlan->patterns[i].mask) || |
50ac6607 AK |
8713 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
8714 | wowlan->patterns[i].pattern) || | |
8715 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 8716 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
8717 | return -ENOBUFS; |
8718 | nla_nest_end(msg, nl_pat); | |
8719 | } | |
8720 | nla_nest_end(msg, nl_pats); | |
8721 | ||
8722 | return 0; | |
8723 | } | |
8724 | ||
2a0e047e JB |
8725 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
8726 | struct cfg80211_wowlan_tcp *tcp) | |
8727 | { | |
8728 | struct nlattr *nl_tcp; | |
8729 | ||
8730 | if (!tcp) | |
8731 | return 0; | |
8732 | ||
8733 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
8734 | if (!nl_tcp) | |
8735 | return -ENOBUFS; | |
8736 | ||
8737 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
8738 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
8739 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
8740 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
8741 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
8742 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
8743 | tcp->payload_len, tcp->payload) || | |
8744 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
8745 | tcp->data_interval) || | |
8746 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
8747 | tcp->wake_len, tcp->wake_data) || | |
8748 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
8749 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
8750 | return -ENOBUFS; | |
8751 | ||
8752 | if (tcp->payload_seq.len && | |
8753 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
8754 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
8755 | return -ENOBUFS; | |
8756 | ||
8757 | if (tcp->payload_tok.len && | |
8758 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
8759 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
8760 | &tcp->payload_tok)) | |
8761 | return -ENOBUFS; | |
8762 | ||
e248ad30 JB |
8763 | nla_nest_end(msg, nl_tcp); |
8764 | ||
2a0e047e JB |
8765 | return 0; |
8766 | } | |
8767 | ||
75453ccb LC |
8768 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
8769 | struct cfg80211_sched_scan_request *req) | |
8770 | { | |
8771 | struct nlattr *nd, *freqs, *matches, *match; | |
8772 | int i; | |
8773 | ||
8774 | if (!req) | |
8775 | return 0; | |
8776 | ||
8777 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); | |
8778 | if (!nd) | |
8779 | return -ENOBUFS; | |
8780 | ||
8781 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, req->interval)) | |
8782 | return -ENOBUFS; | |
8783 | ||
8784 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
8785 | if (!freqs) | |
8786 | return -ENOBUFS; | |
8787 | ||
8788 | for (i = 0; i < req->n_channels; i++) | |
8789 | nla_put_u32(msg, i, req->channels[i]->center_freq); | |
8790 | ||
8791 | nla_nest_end(msg, freqs); | |
8792 | ||
8793 | if (req->n_match_sets) { | |
8794 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); | |
8795 | for (i = 0; i < req->n_match_sets; i++) { | |
8796 | match = nla_nest_start(msg, i); | |
8797 | nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, | |
8798 | req->match_sets[i].ssid.ssid_len, | |
8799 | req->match_sets[i].ssid.ssid); | |
8800 | nla_nest_end(msg, match); | |
8801 | } | |
8802 | nla_nest_end(msg, matches); | |
8803 | } | |
8804 | ||
8805 | nla_nest_end(msg, nd); | |
8806 | ||
8807 | return 0; | |
8808 | } | |
8809 | ||
ff1b6e69 JB |
8810 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
8811 | { | |
8812 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8813 | struct sk_buff *msg; | |
8814 | void *hdr; | |
2a0e047e | 8815 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 8816 | |
964dc9e2 | 8817 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
8818 | return -EOPNOTSUPP; |
8819 | ||
6abb9cb9 | 8820 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 8821 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
8822 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
8823 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
8824 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
8825 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
8826 | } |
8827 | ||
8828 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
8829 | if (!msg) |
8830 | return -ENOMEM; | |
8831 | ||
15e47304 | 8832 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
8833 | NL80211_CMD_GET_WOWLAN); |
8834 | if (!hdr) | |
8835 | goto nla_put_failure; | |
8836 | ||
6abb9cb9 | 8837 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
8838 | struct nlattr *nl_wowlan; |
8839 | ||
8840 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
8841 | if (!nl_wowlan) | |
8842 | goto nla_put_failure; | |
8843 | ||
6abb9cb9 | 8844 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 8845 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 8846 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 8847 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 8848 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 8849 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 8850 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 8851 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 8852 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 8853 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 8854 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 8855 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 8856 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
8857 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
8858 | goto nla_put_failure; | |
2a0e047e | 8859 | |
bb92d199 AK |
8860 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
8861 | goto nla_put_failure; | |
2a0e047e | 8862 | |
6abb9cb9 JB |
8863 | if (nl80211_send_wowlan_tcp(msg, |
8864 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e | 8865 | goto nla_put_failure; |
75453ccb LC |
8866 | |
8867 | if (nl80211_send_wowlan_nd( | |
8868 | msg, | |
8869 | rdev->wiphy.wowlan_config->nd_config)) | |
8870 | goto nla_put_failure; | |
2a0e047e | 8871 | |
ff1b6e69 JB |
8872 | nla_nest_end(msg, nl_wowlan); |
8873 | } | |
8874 | ||
8875 | genlmsg_end(msg, hdr); | |
8876 | return genlmsg_reply(msg, info); | |
8877 | ||
8878 | nla_put_failure: | |
8879 | nlmsg_free(msg); | |
8880 | return -ENOBUFS; | |
8881 | } | |
8882 | ||
2a0e047e JB |
8883 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
8884 | struct nlattr *attr, | |
8885 | struct cfg80211_wowlan *trig) | |
8886 | { | |
8887 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
8888 | struct cfg80211_wowlan_tcp *cfg; | |
8889 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
8890 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
8891 | u32 size; | |
8892 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
8893 | int err, port; | |
8894 | ||
964dc9e2 | 8895 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
8896 | return -EINVAL; |
8897 | ||
8898 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
8899 | nla_data(attr), nla_len(attr), | |
8900 | nl80211_wowlan_tcp_policy); | |
8901 | if (err) | |
8902 | return err; | |
8903 | ||
8904 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
8905 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
8906 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
8907 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
8908 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
8909 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
8910 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
8911 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
8912 | return -EINVAL; | |
8913 | ||
8914 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 8915 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
8916 | return -EINVAL; |
8917 | ||
8918 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 8919 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 8920 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
8921 | return -EINVAL; |
8922 | ||
8923 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 8924 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
8925 | return -EINVAL; |
8926 | ||
8927 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
8928 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
8929 | return -EINVAL; | |
8930 | ||
8931 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
8932 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8933 | ||
8934 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8935 | tokens_size = tokln - sizeof(*tok); | |
8936 | ||
8937 | if (!tok->len || tokens_size % tok->len) | |
8938 | return -EINVAL; | |
964dc9e2 | 8939 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 8940 | return -EINVAL; |
964dc9e2 | 8941 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 8942 | return -EINVAL; |
964dc9e2 | 8943 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 8944 | return -EINVAL; |
964dc9e2 | 8945 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
8946 | return -EINVAL; |
8947 | if (tok->offset + tok->len > data_size) | |
8948 | return -EINVAL; | |
8949 | } | |
8950 | ||
8951 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
8952 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 8953 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
8954 | return -EINVAL; |
8955 | if (seq->len == 0 || seq->len > 4) | |
8956 | return -EINVAL; | |
8957 | if (seq->len + seq->offset > data_size) | |
8958 | return -EINVAL; | |
8959 | } | |
8960 | ||
8961 | size = sizeof(*cfg); | |
8962 | size += data_size; | |
8963 | size += wake_size + wake_mask_size; | |
8964 | size += tokens_size; | |
8965 | ||
8966 | cfg = kzalloc(size, GFP_KERNEL); | |
8967 | if (!cfg) | |
8968 | return -ENOMEM; | |
8969 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
8970 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
8971 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
8972 | ETH_ALEN); | |
8973 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
8974 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
8975 | else | |
8976 | port = 0; | |
8977 | #ifdef CONFIG_INET | |
8978 | /* allocate a socket and port for it and use it */ | |
8979 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
8980 | IPPROTO_TCP, &cfg->sock, 1); | |
8981 | if (err) { | |
8982 | kfree(cfg); | |
8983 | return err; | |
8984 | } | |
8985 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
8986 | sock_release(cfg->sock); | |
8987 | kfree(cfg); | |
8988 | return -EADDRINUSE; | |
8989 | } | |
8990 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
8991 | #else | |
8992 | if (!port) { | |
8993 | kfree(cfg); | |
8994 | return -EINVAL; | |
8995 | } | |
8996 | cfg->src_port = port; | |
8997 | #endif | |
8998 | ||
8999 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
9000 | cfg->payload_len = data_size; | |
9001 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
9002 | memcpy((void *)cfg->payload, | |
9003 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
9004 | data_size); | |
9005 | if (seq) | |
9006 | cfg->payload_seq = *seq; | |
9007 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
9008 | cfg->wake_len = wake_size; | |
9009 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
9010 | memcpy((void *)cfg->wake_data, | |
9011 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
9012 | wake_size); | |
9013 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
9014 | data_size + wake_size; | |
9015 | memcpy((void *)cfg->wake_mask, | |
9016 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
9017 | wake_mask_size); | |
9018 | if (tok) { | |
9019 | cfg->tokens_size = tokens_size; | |
9020 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
9021 | } | |
9022 | ||
9023 | trig->tcp = cfg; | |
9024 | ||
9025 | return 0; | |
9026 | } | |
9027 | ||
8cd4d456 LC |
9028 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
9029 | const struct wiphy_wowlan_support *wowlan, | |
9030 | struct nlattr *attr, | |
9031 | struct cfg80211_wowlan *trig) | |
9032 | { | |
9033 | struct nlattr **tb; | |
9034 | int err; | |
9035 | ||
9036 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); | |
9037 | if (!tb) | |
9038 | return -ENOMEM; | |
9039 | ||
9040 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | |
9041 | err = -EOPNOTSUPP; | |
9042 | goto out; | |
9043 | } | |
9044 | ||
9045 | err = nla_parse(tb, NL80211_ATTR_MAX, | |
9046 | nla_data(attr), nla_len(attr), | |
9047 | nl80211_policy); | |
9048 | if (err) | |
9049 | goto out; | |
9050 | ||
ad2b26ab | 9051 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
8cd4d456 LC |
9052 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
9053 | if (err) | |
9054 | trig->nd_config = NULL; | |
9055 | ||
9056 | out: | |
9057 | kfree(tb); | |
9058 | return err; | |
9059 | } | |
9060 | ||
ff1b6e69 JB |
9061 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
9062 | { | |
9063 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9064 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 9065 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 9066 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 9067 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 9068 | int err, i; |
6abb9cb9 | 9069 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 9070 | |
964dc9e2 | 9071 | if (!wowlan) |
ff1b6e69 JB |
9072 | return -EOPNOTSUPP; |
9073 | ||
ae33bd81 JB |
9074 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
9075 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 9076 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
9077 | goto set_wakeup; |
9078 | } | |
ff1b6e69 JB |
9079 | |
9080 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
9081 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9082 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9083 | nl80211_wowlan_policy); | |
9084 | if (err) | |
9085 | return err; | |
9086 | ||
9087 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
9088 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
9089 | return -EINVAL; | |
9090 | new_triggers.any = true; | |
9091 | } | |
9092 | ||
9093 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
9094 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
9095 | return -EINVAL; | |
9096 | new_triggers.disconnect = true; | |
9097 | } | |
9098 | ||
9099 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
9100 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
9101 | return -EINVAL; | |
9102 | new_triggers.magic_pkt = true; | |
9103 | } | |
9104 | ||
77dbbb13 JB |
9105 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
9106 | return -EINVAL; | |
9107 | ||
9108 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
9109 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
9110 | return -EINVAL; | |
9111 | new_triggers.gtk_rekey_failure = true; | |
9112 | } | |
9113 | ||
9114 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
9115 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
9116 | return -EINVAL; | |
9117 | new_triggers.eap_identity_req = true; | |
9118 | } | |
9119 | ||
9120 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
9121 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
9122 | return -EINVAL; | |
9123 | new_triggers.four_way_handshake = true; | |
9124 | } | |
9125 | ||
9126 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
9127 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
9128 | return -EINVAL; | |
9129 | new_triggers.rfkill_release = true; | |
9130 | } | |
9131 | ||
ff1b6e69 JB |
9132 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
9133 | struct nlattr *pat; | |
9134 | int n_patterns = 0; | |
bb92d199 | 9135 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 9136 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 JB |
9137 | |
9138 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9139 | rem) | |
9140 | n_patterns++; | |
9141 | if (n_patterns > wowlan->n_patterns) | |
9142 | return -EINVAL; | |
9143 | ||
9144 | new_triggers.patterns = kcalloc(n_patterns, | |
9145 | sizeof(new_triggers.patterns[0]), | |
9146 | GFP_KERNEL); | |
9147 | if (!new_triggers.patterns) | |
9148 | return -ENOMEM; | |
9149 | ||
9150 | new_triggers.n_patterns = n_patterns; | |
9151 | i = 0; | |
9152 | ||
9153 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9154 | rem) { | |
922bd80f JB |
9155 | u8 *mask_pat; |
9156 | ||
50ac6607 AK |
9157 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9158 | nla_len(pat), NULL); | |
ff1b6e69 | 9159 | err = -EINVAL; |
50ac6607 AK |
9160 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
9161 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 9162 | goto error; |
50ac6607 | 9163 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 9164 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 9165 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
9166 | goto error; |
9167 | if (pat_len > wowlan->pattern_max_len || | |
9168 | pat_len < wowlan->pattern_min_len) | |
9169 | goto error; | |
9170 | ||
50ac6607 | 9171 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
9172 | pkt_offset = 0; |
9173 | else | |
9174 | pkt_offset = nla_get_u32( | |
50ac6607 | 9175 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
9176 | if (pkt_offset > wowlan->max_pkt_offset) |
9177 | goto error; | |
9178 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
9179 | ||
922bd80f JB |
9180 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9181 | if (!mask_pat) { | |
ff1b6e69 JB |
9182 | err = -ENOMEM; |
9183 | goto error; | |
9184 | } | |
922bd80f JB |
9185 | new_triggers.patterns[i].mask = mask_pat; |
9186 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 9187 | mask_len); |
922bd80f JB |
9188 | mask_pat += mask_len; |
9189 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 9190 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 9191 | memcpy(mask_pat, |
50ac6607 | 9192 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
9193 | pat_len); |
9194 | i++; | |
9195 | } | |
9196 | } | |
9197 | ||
2a0e047e JB |
9198 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
9199 | err = nl80211_parse_wowlan_tcp( | |
9200 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
9201 | &new_triggers); | |
9202 | if (err) | |
9203 | goto error; | |
9204 | } | |
9205 | ||
8cd4d456 LC |
9206 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
9207 | err = nl80211_parse_wowlan_nd( | |
9208 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | |
9209 | &new_triggers); | |
9210 | if (err) | |
9211 | goto error; | |
9212 | } | |
9213 | ||
ae33bd81 JB |
9214 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
9215 | if (!ntrig) { | |
9216 | err = -ENOMEM; | |
9217 | goto error; | |
ff1b6e69 | 9218 | } |
ae33bd81 | 9219 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 9220 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 9221 | |
ae33bd81 | 9222 | set_wakeup: |
6abb9cb9 JB |
9223 | if (rdev->ops->set_wakeup && |
9224 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
9225 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 9226 | |
ff1b6e69 JB |
9227 | return 0; |
9228 | error: | |
9229 | for (i = 0; i < new_triggers.n_patterns; i++) | |
9230 | kfree(new_triggers.patterns[i].mask); | |
9231 | kfree(new_triggers.patterns); | |
2a0e047e JB |
9232 | if (new_triggers.tcp && new_triggers.tcp->sock) |
9233 | sock_release(new_triggers.tcp->sock); | |
9234 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
9235 | return err; |
9236 | } | |
dfb89c56 | 9237 | #endif |
ff1b6e69 | 9238 | |
be29b99a AK |
9239 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
9240 | struct cfg80211_registered_device *rdev) | |
9241 | { | |
9242 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
9243 | int i, j, pat_len; | |
9244 | struct cfg80211_coalesce_rules *rule; | |
9245 | ||
9246 | if (!rdev->coalesce->n_rules) | |
9247 | return 0; | |
9248 | ||
9249 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
9250 | if (!nl_rules) | |
9251 | return -ENOBUFS; | |
9252 | ||
9253 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
9254 | nl_rule = nla_nest_start(msg, i + 1); | |
9255 | if (!nl_rule) | |
9256 | return -ENOBUFS; | |
9257 | ||
9258 | rule = &rdev->coalesce->rules[i]; | |
9259 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
9260 | rule->delay)) | |
9261 | return -ENOBUFS; | |
9262 | ||
9263 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
9264 | rule->condition)) | |
9265 | return -ENOBUFS; | |
9266 | ||
9267 | nl_pats = nla_nest_start(msg, | |
9268 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
9269 | if (!nl_pats) | |
9270 | return -ENOBUFS; | |
9271 | ||
9272 | for (j = 0; j < rule->n_patterns; j++) { | |
9273 | nl_pat = nla_nest_start(msg, j + 1); | |
9274 | if (!nl_pat) | |
9275 | return -ENOBUFS; | |
9276 | pat_len = rule->patterns[j].pattern_len; | |
9277 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
9278 | DIV_ROUND_UP(pat_len, 8), | |
9279 | rule->patterns[j].mask) || | |
9280 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
9281 | rule->patterns[j].pattern) || | |
9282 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
9283 | rule->patterns[j].pkt_offset)) | |
9284 | return -ENOBUFS; | |
9285 | nla_nest_end(msg, nl_pat); | |
9286 | } | |
9287 | nla_nest_end(msg, nl_pats); | |
9288 | nla_nest_end(msg, nl_rule); | |
9289 | } | |
9290 | nla_nest_end(msg, nl_rules); | |
9291 | ||
9292 | return 0; | |
9293 | } | |
9294 | ||
9295 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9296 | { | |
9297 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9298 | struct sk_buff *msg; | |
9299 | void *hdr; | |
9300 | ||
9301 | if (!rdev->wiphy.coalesce) | |
9302 | return -EOPNOTSUPP; | |
9303 | ||
9304 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9305 | if (!msg) | |
9306 | return -ENOMEM; | |
9307 | ||
9308 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9309 | NL80211_CMD_GET_COALESCE); | |
9310 | if (!hdr) | |
9311 | goto nla_put_failure; | |
9312 | ||
9313 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
9314 | goto nla_put_failure; | |
9315 | ||
9316 | genlmsg_end(msg, hdr); | |
9317 | return genlmsg_reply(msg, info); | |
9318 | ||
9319 | nla_put_failure: | |
9320 | nlmsg_free(msg); | |
9321 | return -ENOBUFS; | |
9322 | } | |
9323 | ||
9324 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
9325 | { | |
9326 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
9327 | int i, j; | |
9328 | struct cfg80211_coalesce_rules *rule; | |
9329 | ||
9330 | if (!coalesce) | |
9331 | return; | |
9332 | ||
9333 | for (i = 0; i < coalesce->n_rules; i++) { | |
9334 | rule = &coalesce->rules[i]; | |
9335 | for (j = 0; j < rule->n_patterns; j++) | |
9336 | kfree(rule->patterns[j].mask); | |
9337 | kfree(rule->patterns); | |
9338 | } | |
9339 | kfree(coalesce->rules); | |
9340 | kfree(coalesce); | |
9341 | rdev->coalesce = NULL; | |
9342 | } | |
9343 | ||
9344 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
9345 | struct nlattr *rule, | |
9346 | struct cfg80211_coalesce_rules *new_rule) | |
9347 | { | |
9348 | int err, i; | |
9349 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9350 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
9351 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
9352 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
9353 | ||
9354 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
9355 | nla_len(rule), nl80211_coalesce_policy); | |
9356 | if (err) | |
9357 | return err; | |
9358 | ||
9359 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
9360 | new_rule->delay = | |
9361 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
9362 | if (new_rule->delay > coalesce->max_delay) | |
9363 | return -EINVAL; | |
9364 | ||
9365 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
9366 | new_rule->condition = | |
9367 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
9368 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
9369 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
9370 | return -EINVAL; | |
9371 | ||
9372 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
9373 | return -EINVAL; | |
9374 | ||
9375 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9376 | rem) | |
9377 | n_patterns++; | |
9378 | if (n_patterns > coalesce->n_patterns) | |
9379 | return -EINVAL; | |
9380 | ||
9381 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
9382 | GFP_KERNEL); | |
9383 | if (!new_rule->patterns) | |
9384 | return -ENOMEM; | |
9385 | ||
9386 | new_rule->n_patterns = n_patterns; | |
9387 | i = 0; | |
9388 | ||
9389 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9390 | rem) { | |
922bd80f JB |
9391 | u8 *mask_pat; |
9392 | ||
be29b99a AK |
9393 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9394 | nla_len(pat), NULL); | |
9395 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
9396 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
9397 | return -EINVAL; | |
9398 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
9399 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
9400 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
9401 | return -EINVAL; | |
9402 | if (pat_len > coalesce->pattern_max_len || | |
9403 | pat_len < coalesce->pattern_min_len) | |
9404 | return -EINVAL; | |
9405 | ||
9406 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
9407 | pkt_offset = 0; | |
9408 | else | |
9409 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
9410 | if (pkt_offset > coalesce->max_pkt_offset) | |
9411 | return -EINVAL; | |
9412 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
9413 | ||
922bd80f JB |
9414 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9415 | if (!mask_pat) | |
be29b99a | 9416 | return -ENOMEM; |
922bd80f JB |
9417 | |
9418 | new_rule->patterns[i].mask = mask_pat; | |
9419 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
9420 | mask_len); | |
9421 | ||
9422 | mask_pat += mask_len; | |
9423 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 9424 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
9425 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
9426 | pat_len); | |
be29b99a AK |
9427 | i++; |
9428 | } | |
9429 | ||
9430 | return 0; | |
9431 | } | |
9432 | ||
9433 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9434 | { | |
9435 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9436 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9437 | struct cfg80211_coalesce new_coalesce = {}; | |
9438 | struct cfg80211_coalesce *n_coalesce; | |
9439 | int err, rem_rule, n_rules = 0, i, j; | |
9440 | struct nlattr *rule; | |
9441 | struct cfg80211_coalesce_rules *tmp_rule; | |
9442 | ||
9443 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
9444 | return -EOPNOTSUPP; | |
9445 | ||
9446 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
9447 | cfg80211_rdev_free_coalesce(rdev); | |
9448 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
9449 | return 0; | |
9450 | } | |
9451 | ||
9452 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9453 | rem_rule) | |
9454 | n_rules++; | |
9455 | if (n_rules > coalesce->n_rules) | |
9456 | return -EINVAL; | |
9457 | ||
9458 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
9459 | GFP_KERNEL); | |
9460 | if (!new_coalesce.rules) | |
9461 | return -ENOMEM; | |
9462 | ||
9463 | new_coalesce.n_rules = n_rules; | |
9464 | i = 0; | |
9465 | ||
9466 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9467 | rem_rule) { | |
9468 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
9469 | &new_coalesce.rules[i]); | |
9470 | if (err) | |
9471 | goto error; | |
9472 | ||
9473 | i++; | |
9474 | } | |
9475 | ||
9476 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
9477 | if (err) | |
9478 | goto error; | |
9479 | ||
9480 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
9481 | if (!n_coalesce) { | |
9482 | err = -ENOMEM; | |
9483 | goto error; | |
9484 | } | |
9485 | cfg80211_rdev_free_coalesce(rdev); | |
9486 | rdev->coalesce = n_coalesce; | |
9487 | ||
9488 | return 0; | |
9489 | error: | |
9490 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
9491 | tmp_rule = &new_coalesce.rules[i]; | |
9492 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
9493 | kfree(tmp_rule->patterns[j].mask); | |
9494 | kfree(tmp_rule->patterns); | |
9495 | } | |
9496 | kfree(new_coalesce.rules); | |
9497 | ||
9498 | return err; | |
9499 | } | |
9500 | ||
e5497d76 JB |
9501 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
9502 | { | |
9503 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9504 | struct net_device *dev = info->user_ptr[1]; | |
9505 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9506 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
9507 | struct cfg80211_gtk_rekey_data rekey_data; | |
9508 | int err; | |
9509 | ||
9510 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
9511 | return -EINVAL; | |
9512 | ||
9513 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
9514 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9515 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9516 | nl80211_rekey_policy); | |
9517 | if (err) | |
9518 | return err; | |
9519 | ||
9520 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
9521 | return -ERANGE; | |
9522 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
9523 | return -ERANGE; | |
9524 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
9525 | return -ERANGE; | |
9526 | ||
78f686ca JB |
9527 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
9528 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | |
9529 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | |
e5497d76 JB |
9530 | |
9531 | wdev_lock(wdev); | |
9532 | if (!wdev->current_bss) { | |
9533 | err = -ENOTCONN; | |
9534 | goto out; | |
9535 | } | |
9536 | ||
9537 | if (!rdev->ops->set_rekey_data) { | |
9538 | err = -EOPNOTSUPP; | |
9539 | goto out; | |
9540 | } | |
9541 | ||
e35e4d28 | 9542 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
9543 | out: |
9544 | wdev_unlock(wdev); | |
9545 | return err; | |
9546 | } | |
9547 | ||
28946da7 JB |
9548 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
9549 | struct genl_info *info) | |
9550 | { | |
9551 | struct net_device *dev = info->user_ptr[1]; | |
9552 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9553 | ||
9554 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9555 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9556 | return -EINVAL; | |
9557 | ||
15e47304 | 9558 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
9559 | return -EBUSY; |
9560 | ||
15e47304 | 9561 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
9562 | return 0; |
9563 | } | |
9564 | ||
7f6cf311 JB |
9565 | static int nl80211_probe_client(struct sk_buff *skb, |
9566 | struct genl_info *info) | |
9567 | { | |
9568 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9569 | struct net_device *dev = info->user_ptr[1]; | |
9570 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9571 | struct sk_buff *msg; | |
9572 | void *hdr; | |
9573 | const u8 *addr; | |
9574 | u64 cookie; | |
9575 | int err; | |
9576 | ||
9577 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9578 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9579 | return -EOPNOTSUPP; | |
9580 | ||
9581 | if (!info->attrs[NL80211_ATTR_MAC]) | |
9582 | return -EINVAL; | |
9583 | ||
9584 | if (!rdev->ops->probe_client) | |
9585 | return -EOPNOTSUPP; | |
9586 | ||
9587 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9588 | if (!msg) | |
9589 | return -ENOMEM; | |
9590 | ||
15e47304 | 9591 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 9592 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
9593 | if (!hdr) { |
9594 | err = -ENOBUFS; | |
7f6cf311 JB |
9595 | goto free_msg; |
9596 | } | |
9597 | ||
9598 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9599 | ||
e35e4d28 | 9600 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
9601 | if (err) |
9602 | goto free_msg; | |
9603 | ||
9360ffd1 DM |
9604 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9605 | goto nla_put_failure; | |
7f6cf311 JB |
9606 | |
9607 | genlmsg_end(msg, hdr); | |
9608 | ||
9609 | return genlmsg_reply(msg, info); | |
9610 | ||
9611 | nla_put_failure: | |
9612 | err = -ENOBUFS; | |
9613 | free_msg: | |
9614 | nlmsg_free(msg); | |
9615 | return err; | |
9616 | } | |
9617 | ||
5e760230 JB |
9618 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
9619 | { | |
9620 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
9621 | struct cfg80211_beacon_registration *reg, *nreg; |
9622 | int rv; | |
5e760230 JB |
9623 | |
9624 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
9625 | return -EOPNOTSUPP; | |
9626 | ||
37c73b5f BG |
9627 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
9628 | if (!nreg) | |
9629 | return -ENOMEM; | |
9630 | ||
9631 | /* First, check if already registered. */ | |
9632 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
9633 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
9634 | if (reg->nlportid == info->snd_portid) { | |
9635 | rv = -EALREADY; | |
9636 | goto out_err; | |
9637 | } | |
9638 | } | |
9639 | /* Add it to the list */ | |
9640 | nreg->nlportid = info->snd_portid; | |
9641 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 9642 | |
37c73b5f | 9643 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
9644 | |
9645 | return 0; | |
37c73b5f BG |
9646 | out_err: |
9647 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
9648 | kfree(nreg); | |
9649 | return rv; | |
5e760230 JB |
9650 | } |
9651 | ||
98104fde JB |
9652 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
9653 | { | |
9654 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9655 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9656 | int err; | |
9657 | ||
9658 | if (!rdev->ops->start_p2p_device) | |
9659 | return -EOPNOTSUPP; | |
9660 | ||
9661 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9662 | return -EOPNOTSUPP; | |
9663 | ||
9664 | if (wdev->p2p_started) | |
9665 | return 0; | |
9666 | ||
b6a55015 LC |
9667 | if (rfkill_blocked(rdev->rfkill)) |
9668 | return -ERFKILL; | |
98104fde | 9669 | |
eeb126e9 | 9670 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
9671 | if (err) |
9672 | return err; | |
9673 | ||
9674 | wdev->p2p_started = true; | |
98104fde | 9675 | rdev->opencount++; |
98104fde JB |
9676 | |
9677 | return 0; | |
9678 | } | |
9679 | ||
9680 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
9681 | { | |
9682 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9683 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9684 | ||
9685 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9686 | return -EOPNOTSUPP; | |
9687 | ||
9688 | if (!rdev->ops->stop_p2p_device) | |
9689 | return -EOPNOTSUPP; | |
9690 | ||
f9f47529 | 9691 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
9692 | |
9693 | return 0; | |
9694 | } | |
9695 | ||
3713b4e3 JB |
9696 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
9697 | struct genl_info *info) | |
9698 | { | |
9699 | void *hdr; | |
9700 | struct sk_buff *msg; | |
9701 | ||
9702 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9703 | if (!msg) | |
9704 | return -ENOMEM; | |
9705 | ||
9706 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9707 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
9708 | if (!hdr) | |
9709 | goto nla_put_failure; | |
9710 | ||
9711 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
9712 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
9713 | goto nla_put_failure; | |
9714 | ||
9715 | genlmsg_end(msg, hdr); | |
9716 | return genlmsg_reply(msg, info); | |
9717 | ||
9718 | nla_put_failure: | |
9719 | kfree_skb(msg); | |
9720 | return -ENOBUFS; | |
9721 | } | |
9722 | ||
355199e0 JM |
9723 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
9724 | { | |
9725 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9726 | struct cfg80211_update_ft_ies_params ft_params; | |
9727 | struct net_device *dev = info->user_ptr[1]; | |
9728 | ||
9729 | if (!rdev->ops->update_ft_ies) | |
9730 | return -EOPNOTSUPP; | |
9731 | ||
9732 | if (!info->attrs[NL80211_ATTR_MDID] || | |
9733 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
9734 | return -EINVAL; | |
9735 | ||
9736 | memset(&ft_params, 0, sizeof(ft_params)); | |
9737 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
9738 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
9739 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9740 | ||
9741 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
9742 | } | |
9743 | ||
5de17984 AS |
9744 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
9745 | struct genl_info *info) | |
9746 | { | |
9747 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9748 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9749 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
9750 | u16 duration; | |
9751 | int ret; | |
9752 | ||
9753 | if (!rdev->ops->crit_proto_start) | |
9754 | return -EOPNOTSUPP; | |
9755 | ||
9756 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
9757 | return -EINVAL; | |
9758 | ||
9759 | if (rdev->crit_proto_nlportid) | |
9760 | return -EBUSY; | |
9761 | ||
9762 | /* determine protocol if provided */ | |
9763 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
9764 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
9765 | ||
9766 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
9767 | return -EINVAL; | |
9768 | ||
9769 | /* timeout must be provided */ | |
9770 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
9771 | return -EINVAL; | |
9772 | ||
9773 | duration = | |
9774 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
9775 | ||
9776 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
9777 | return -ERANGE; | |
9778 | ||
9779 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
9780 | if (!ret) | |
9781 | rdev->crit_proto_nlportid = info->snd_portid; | |
9782 | ||
9783 | return ret; | |
9784 | } | |
9785 | ||
9786 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
9787 | struct genl_info *info) | |
9788 | { | |
9789 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9790 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9791 | ||
9792 | if (!rdev->ops->crit_proto_stop) | |
9793 | return -EOPNOTSUPP; | |
9794 | ||
9795 | if (rdev->crit_proto_nlportid) { | |
9796 | rdev->crit_proto_nlportid = 0; | |
9797 | rdev_crit_proto_stop(rdev, wdev); | |
9798 | } | |
9799 | return 0; | |
9800 | } | |
9801 | ||
ad7e718c JB |
9802 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
9803 | { | |
9804 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9805 | struct wireless_dev *wdev = | |
9806 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
9807 | int i, err; | |
9808 | u32 vid, subcmd; | |
9809 | ||
9810 | if (!rdev->wiphy.vendor_commands) | |
9811 | return -EOPNOTSUPP; | |
9812 | ||
9813 | if (IS_ERR(wdev)) { | |
9814 | err = PTR_ERR(wdev); | |
9815 | if (err != -EINVAL) | |
9816 | return err; | |
9817 | wdev = NULL; | |
9818 | } else if (wdev->wiphy != &rdev->wiphy) { | |
9819 | return -EINVAL; | |
9820 | } | |
9821 | ||
9822 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
9823 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
9824 | return -EINVAL; | |
9825 | ||
9826 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
9827 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
9828 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
9829 | const struct wiphy_vendor_command *vcmd; | |
9830 | void *data = NULL; | |
9831 | int len = 0; | |
9832 | ||
9833 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
9834 | ||
9835 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
9836 | continue; | |
9837 | ||
9838 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
9839 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
9840 | if (!wdev) | |
9841 | return -EINVAL; | |
9842 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
9843 | !wdev->netdev) | |
9844 | return -EINVAL; | |
9845 | ||
9846 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
9847 | if (wdev->netdev && | |
9848 | !netif_running(wdev->netdev)) | |
9849 | return -ENETDOWN; | |
9850 | if (!wdev->netdev && !wdev->p2p_started) | |
9851 | return -ENETDOWN; | |
9852 | } | |
9853 | } else { | |
9854 | wdev = NULL; | |
9855 | } | |
9856 | ||
9857 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
9858 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9859 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9860 | } | |
9861 | ||
9862 | rdev->cur_cmd_info = info; | |
9863 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
9864 | data, len); | |
9865 | rdev->cur_cmd_info = NULL; | |
9866 | return err; | |
9867 | } | |
9868 | ||
9869 | return -EOPNOTSUPP; | |
9870 | } | |
9871 | ||
9872 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | |
9873 | enum nl80211_commands cmd, | |
9874 | enum nl80211_attrs attr, | |
9875 | int approxlen) | |
9876 | { | |
f26cbf40 | 9877 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
9878 | |
9879 | if (WARN_ON(!rdev->cur_cmd_info)) | |
9880 | return NULL; | |
9881 | ||
9882 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, | |
9883 | rdev->cur_cmd_info->snd_portid, | |
9884 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 9885 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
9886 | } |
9887 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
9888 | ||
9889 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
9890 | { | |
9891 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
9892 | void *hdr = ((void **)skb->cb)[1]; | |
9893 | struct nlattr *data = ((void **)skb->cb)[2]; | |
9894 | ||
bd8c78e7 JB |
9895 | /* clear CB data for netlink core to own from now on */ |
9896 | memset(skb->cb, 0, sizeof(skb->cb)); | |
9897 | ||
ad7e718c JB |
9898 | if (WARN_ON(!rdev->cur_cmd_info)) { |
9899 | kfree_skb(skb); | |
9900 | return -EINVAL; | |
9901 | } | |
9902 | ||
9903 | nla_nest_end(skb, data); | |
9904 | genlmsg_end(skb, hdr); | |
9905 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
9906 | } | |
9907 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
9908 | ||
9909 | ||
fa9ffc74 KP |
9910 | static int nl80211_set_qos_map(struct sk_buff *skb, |
9911 | struct genl_info *info) | |
9912 | { | |
9913 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9914 | struct cfg80211_qos_map *qos_map = NULL; | |
9915 | struct net_device *dev = info->user_ptr[1]; | |
9916 | u8 *pos, len, num_des, des_len, des; | |
9917 | int ret; | |
9918 | ||
9919 | if (!rdev->ops->set_qos_map) | |
9920 | return -EOPNOTSUPP; | |
9921 | ||
9922 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
9923 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9924 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9925 | ||
9926 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
9927 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
9928 | return -EINVAL; | |
9929 | ||
9930 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
9931 | if (!qos_map) | |
9932 | return -ENOMEM; | |
9933 | ||
9934 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
9935 | if (num_des) { | |
9936 | des_len = num_des * | |
9937 | sizeof(struct cfg80211_dscp_exception); | |
9938 | memcpy(qos_map->dscp_exception, pos, des_len); | |
9939 | qos_map->num_des = num_des; | |
9940 | for (des = 0; des < num_des; des++) { | |
9941 | if (qos_map->dscp_exception[des].up > 7) { | |
9942 | kfree(qos_map); | |
9943 | return -EINVAL; | |
9944 | } | |
9945 | } | |
9946 | pos += des_len; | |
9947 | } | |
9948 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
9949 | } | |
9950 | ||
9951 | wdev_lock(dev->ieee80211_ptr); | |
9952 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
9953 | if (!ret) | |
9954 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
9955 | wdev_unlock(dev->ieee80211_ptr); | |
9956 | ||
9957 | kfree(qos_map); | |
9958 | return ret; | |
9959 | } | |
9960 | ||
960d01ac JB |
9961 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
9962 | { | |
9963 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9964 | struct net_device *dev = info->user_ptr[1]; | |
9965 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9966 | const u8 *peer; | |
9967 | u8 tsid, up; | |
9968 | u16 admitted_time = 0; | |
9969 | int err; | |
9970 | ||
723e73ac | 9971 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
960d01ac JB |
9972 | return -EOPNOTSUPP; |
9973 | ||
9974 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | |
9975 | !info->attrs[NL80211_ATTR_USER_PRIO]) | |
9976 | return -EINVAL; | |
9977 | ||
9978 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
9979 | if (tsid >= IEEE80211_NUM_TIDS) | |
9980 | return -EINVAL; | |
9981 | ||
9982 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); | |
9983 | if (up >= IEEE80211_NUM_UPS) | |
9984 | return -EINVAL; | |
9985 | ||
9986 | /* WMM uses TIDs 0-7 even for TSPEC */ | |
723e73ac | 9987 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
960d01ac | 9988 | /* TODO: handle 802.11 TSPEC/admission control |
723e73ac JB |
9989 | * need more attributes for that (e.g. BA session requirement); |
9990 | * change the WMM adminssion test above to allow both then | |
960d01ac JB |
9991 | */ |
9992 | return -EINVAL; | |
9993 | } | |
9994 | ||
9995 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9996 | ||
9997 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | |
9998 | admitted_time = | |
9999 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | |
10000 | if (!admitted_time) | |
10001 | return -EINVAL; | |
10002 | } | |
10003 | ||
10004 | wdev_lock(wdev); | |
10005 | switch (wdev->iftype) { | |
10006 | case NL80211_IFTYPE_STATION: | |
10007 | case NL80211_IFTYPE_P2P_CLIENT: | |
10008 | if (wdev->current_bss) | |
10009 | break; | |
10010 | err = -ENOTCONN; | |
10011 | goto out; | |
10012 | default: | |
10013 | err = -EOPNOTSUPP; | |
10014 | goto out; | |
10015 | } | |
10016 | ||
10017 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | |
10018 | ||
10019 | out: | |
10020 | wdev_unlock(wdev); | |
10021 | return err; | |
10022 | } | |
10023 | ||
10024 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | |
10025 | { | |
10026 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10027 | struct net_device *dev = info->user_ptr[1]; | |
10028 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10029 | const u8 *peer; | |
10030 | u8 tsid; | |
10031 | int err; | |
10032 | ||
10033 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | |
10034 | return -EINVAL; | |
10035 | ||
10036 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
10037 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10038 | ||
10039 | wdev_lock(wdev); | |
10040 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | |
10041 | wdev_unlock(wdev); | |
10042 | ||
10043 | return err; | |
10044 | } | |
10045 | ||
1057d35e AN |
10046 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
10047 | struct genl_info *info) | |
10048 | { | |
10049 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10050 | struct net_device *dev = info->user_ptr[1]; | |
10051 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10052 | struct cfg80211_chan_def chandef = {}; | |
10053 | const u8 *addr; | |
10054 | u8 oper_class; | |
10055 | int err; | |
10056 | ||
10057 | if (!rdev->ops->tdls_channel_switch || | |
10058 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
10059 | return -EOPNOTSUPP; | |
10060 | ||
10061 | switch (dev->ieee80211_ptr->iftype) { | |
10062 | case NL80211_IFTYPE_STATION: | |
10063 | case NL80211_IFTYPE_P2P_CLIENT: | |
10064 | break; | |
10065 | default: | |
10066 | return -EOPNOTSUPP; | |
10067 | } | |
10068 | ||
10069 | if (!info->attrs[NL80211_ATTR_MAC] || | |
10070 | !info->attrs[NL80211_ATTR_OPER_CLASS]) | |
10071 | return -EINVAL; | |
10072 | ||
10073 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
10074 | if (err) | |
10075 | return err; | |
10076 | ||
10077 | /* | |
10078 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | |
10079 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | |
10080 | * specification is not defined for them. | |
10081 | */ | |
10082 | if (chandef.chan->band == IEEE80211_BAND_2GHZ && | |
10083 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | |
10084 | chandef.width != NL80211_CHAN_WIDTH_20) | |
10085 | return -EINVAL; | |
10086 | ||
10087 | /* we will be active on the TDLS link */ | |
10088 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype)) | |
10089 | return -EINVAL; | |
10090 | ||
10091 | /* don't allow switching to DFS channels */ | |
10092 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | |
10093 | return -EINVAL; | |
10094 | ||
10095 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10096 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | |
10097 | ||
10098 | wdev_lock(wdev); | |
10099 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | |
10100 | wdev_unlock(wdev); | |
10101 | ||
10102 | return err; | |
10103 | } | |
10104 | ||
10105 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | |
10106 | struct genl_info *info) | |
10107 | { | |
10108 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10109 | struct net_device *dev = info->user_ptr[1]; | |
10110 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10111 | const u8 *addr; | |
10112 | ||
10113 | if (!rdev->ops->tdls_channel_switch || | |
10114 | !rdev->ops->tdls_cancel_channel_switch || | |
10115 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
10116 | return -EOPNOTSUPP; | |
10117 | ||
10118 | switch (dev->ieee80211_ptr->iftype) { | |
10119 | case NL80211_IFTYPE_STATION: | |
10120 | case NL80211_IFTYPE_P2P_CLIENT: | |
10121 | break; | |
10122 | default: | |
10123 | return -EOPNOTSUPP; | |
10124 | } | |
10125 | ||
10126 | if (!info->attrs[NL80211_ATTR_MAC]) | |
10127 | return -EINVAL; | |
10128 | ||
10129 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10130 | ||
10131 | wdev_lock(wdev); | |
10132 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); | |
10133 | wdev_unlock(wdev); | |
10134 | ||
10135 | return 0; | |
10136 | } | |
10137 | ||
4c476991 JB |
10138 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
10139 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
10140 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
10141 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
10142 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
10143 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 10144 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 10145 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
10146 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
10147 | NL80211_FLAG_CHECK_NETDEV_UP) | |
5393b917 | 10148 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
4c476991 | 10149 | |
f84f771d | 10150 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10151 | struct genl_info *info) |
10152 | { | |
10153 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 10154 | struct wireless_dev *wdev; |
4c476991 | 10155 | struct net_device *dev; |
4c476991 JB |
10156 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
10157 | ||
10158 | if (rtnl) | |
10159 | rtnl_lock(); | |
10160 | ||
10161 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 10162 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
10163 | if (IS_ERR(rdev)) { |
10164 | if (rtnl) | |
10165 | rtnl_unlock(); | |
10166 | return PTR_ERR(rdev); | |
10167 | } | |
10168 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
10169 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
10170 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
10171 | ASSERT_RTNL(); |
10172 | ||
89a54e48 JB |
10173 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
10174 | info->attrs); | |
10175 | if (IS_ERR(wdev)) { | |
4c476991 JB |
10176 | if (rtnl) |
10177 | rtnl_unlock(); | |
89a54e48 | 10178 | return PTR_ERR(wdev); |
4c476991 | 10179 | } |
89a54e48 | 10180 | |
89a54e48 | 10181 | dev = wdev->netdev; |
f26cbf40 | 10182 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 10183 | |
1bf614ef JB |
10184 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
10185 | if (!dev) { | |
1bf614ef JB |
10186 | if (rtnl) |
10187 | rtnl_unlock(); | |
10188 | return -EINVAL; | |
10189 | } | |
10190 | ||
10191 | info->user_ptr[1] = dev; | |
10192 | } else { | |
10193 | info->user_ptr[1] = wdev; | |
41265714 | 10194 | } |
1bf614ef JB |
10195 | |
10196 | if (dev) { | |
10197 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
10198 | !netif_running(dev)) { | |
1bf614ef JB |
10199 | if (rtnl) |
10200 | rtnl_unlock(); | |
10201 | return -ENETDOWN; | |
10202 | } | |
10203 | ||
10204 | dev_hold(dev); | |
98104fde JB |
10205 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
10206 | if (!wdev->p2p_started) { | |
98104fde JB |
10207 | if (rtnl) |
10208 | rtnl_unlock(); | |
10209 | return -ENETDOWN; | |
10210 | } | |
41265714 | 10211 | } |
89a54e48 | 10212 | |
4c476991 | 10213 | info->user_ptr[0] = rdev; |
4c476991 JB |
10214 | } |
10215 | ||
10216 | return 0; | |
10217 | } | |
10218 | ||
f84f771d | 10219 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10220 | struct genl_info *info) |
10221 | { | |
1bf614ef JB |
10222 | if (info->user_ptr[1]) { |
10223 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
10224 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10225 | ||
10226 | if (wdev->netdev) | |
10227 | dev_put(wdev->netdev); | |
10228 | } else { | |
10229 | dev_put(info->user_ptr[1]); | |
10230 | } | |
10231 | } | |
5393b917 | 10232 | |
4c476991 JB |
10233 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
10234 | rtnl_unlock(); | |
5393b917 JB |
10235 | |
10236 | /* If needed, clear the netlink message payload from the SKB | |
10237 | * as it might contain key data that shouldn't stick around on | |
10238 | * the heap after the SKB is freed. The netlink message header | |
10239 | * is still needed for further processing, so leave it intact. | |
10240 | */ | |
10241 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | |
10242 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | |
10243 | ||
10244 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | |
10245 | } | |
4c476991 JB |
10246 | } |
10247 | ||
4534de83 | 10248 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
10249 | { |
10250 | .cmd = NL80211_CMD_GET_WIPHY, | |
10251 | .doit = nl80211_get_wiphy, | |
10252 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 10253 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
10254 | .policy = nl80211_policy, |
10255 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10256 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10257 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10258 | }, |
10259 | { | |
10260 | .cmd = NL80211_CMD_SET_WIPHY, | |
10261 | .doit = nl80211_set_wiphy, | |
10262 | .policy = nl80211_policy, | |
10263 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 10264 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
10265 | }, |
10266 | { | |
10267 | .cmd = NL80211_CMD_GET_INTERFACE, | |
10268 | .doit = nl80211_get_interface, | |
10269 | .dumpit = nl80211_dump_interface, | |
10270 | .policy = nl80211_policy, | |
10271 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10272 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
10273 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10274 | }, |
10275 | { | |
10276 | .cmd = NL80211_CMD_SET_INTERFACE, | |
10277 | .doit = nl80211_set_interface, | |
10278 | .policy = nl80211_policy, | |
10279 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10280 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10281 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10282 | }, |
10283 | { | |
10284 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
10285 | .doit = nl80211_new_interface, | |
10286 | .policy = nl80211_policy, | |
10287 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10288 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10289 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10290 | }, |
10291 | { | |
10292 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
10293 | .doit = nl80211_del_interface, | |
10294 | .policy = nl80211_policy, | |
41ade00f | 10295 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 10296 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10297 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10298 | }, |
10299 | { | |
10300 | .cmd = NL80211_CMD_GET_KEY, | |
10301 | .doit = nl80211_get_key, | |
10302 | .policy = nl80211_policy, | |
10303 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10304 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10305 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10306 | }, |
10307 | { | |
10308 | .cmd = NL80211_CMD_SET_KEY, | |
10309 | .doit = nl80211_set_key, | |
10310 | .policy = nl80211_policy, | |
10311 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10312 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10313 | NL80211_FLAG_NEED_RTNL | |
10314 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10315 | }, |
10316 | { | |
10317 | .cmd = NL80211_CMD_NEW_KEY, | |
10318 | .doit = nl80211_new_key, | |
10319 | .policy = nl80211_policy, | |
10320 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10321 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10322 | NL80211_FLAG_NEED_RTNL | |
10323 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10324 | }, |
10325 | { | |
10326 | .cmd = NL80211_CMD_DEL_KEY, | |
10327 | .doit = nl80211_del_key, | |
10328 | .policy = nl80211_policy, | |
55682965 | 10329 | .flags = GENL_ADMIN_PERM, |
41265714 | 10330 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10331 | NL80211_FLAG_NEED_RTNL, |
55682965 | 10332 | }, |
ed1b6cc7 JB |
10333 | { |
10334 | .cmd = NL80211_CMD_SET_BEACON, | |
10335 | .policy = nl80211_policy, | |
10336 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10337 | .doit = nl80211_set_beacon, |
2b5f8b0b | 10338 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10339 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10340 | }, |
10341 | { | |
8860020e | 10342 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
10343 | .policy = nl80211_policy, |
10344 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10345 | .doit = nl80211_start_ap, |
2b5f8b0b | 10346 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10347 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10348 | }, |
10349 | { | |
8860020e | 10350 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
10351 | .policy = nl80211_policy, |
10352 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10353 | .doit = nl80211_stop_ap, |
2b5f8b0b | 10354 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10355 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 10356 | }, |
5727ef1b JB |
10357 | { |
10358 | .cmd = NL80211_CMD_GET_STATION, | |
10359 | .doit = nl80211_get_station, | |
2ec600d6 | 10360 | .dumpit = nl80211_dump_station, |
5727ef1b | 10361 | .policy = nl80211_policy, |
4c476991 JB |
10362 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10363 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
10364 | }, |
10365 | { | |
10366 | .cmd = NL80211_CMD_SET_STATION, | |
10367 | .doit = nl80211_set_station, | |
10368 | .policy = nl80211_policy, | |
10369 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10370 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10371 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10372 | }, |
10373 | { | |
10374 | .cmd = NL80211_CMD_NEW_STATION, | |
10375 | .doit = nl80211_new_station, | |
10376 | .policy = nl80211_policy, | |
10377 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10378 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10379 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10380 | }, |
10381 | { | |
10382 | .cmd = NL80211_CMD_DEL_STATION, | |
10383 | .doit = nl80211_del_station, | |
10384 | .policy = nl80211_policy, | |
2ec600d6 | 10385 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10386 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10387 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10388 | }, |
10389 | { | |
10390 | .cmd = NL80211_CMD_GET_MPATH, | |
10391 | .doit = nl80211_get_mpath, | |
10392 | .dumpit = nl80211_dump_mpath, | |
10393 | .policy = nl80211_policy, | |
10394 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10395 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10396 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 | 10397 | }, |
66be7d2b HR |
10398 | { |
10399 | .cmd = NL80211_CMD_GET_MPP, | |
10400 | .doit = nl80211_get_mpp, | |
10401 | .dumpit = nl80211_dump_mpp, | |
10402 | .policy = nl80211_policy, | |
10403 | .flags = GENL_ADMIN_PERM, | |
10404 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10405 | NL80211_FLAG_NEED_RTNL, | |
10406 | }, | |
2ec600d6 LCC |
10407 | { |
10408 | .cmd = NL80211_CMD_SET_MPATH, | |
10409 | .doit = nl80211_set_mpath, | |
10410 | .policy = nl80211_policy, | |
10411 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10412 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10413 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10414 | }, |
10415 | { | |
10416 | .cmd = NL80211_CMD_NEW_MPATH, | |
10417 | .doit = nl80211_new_mpath, | |
10418 | .policy = nl80211_policy, | |
10419 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10420 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10421 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10422 | }, |
10423 | { | |
10424 | .cmd = NL80211_CMD_DEL_MPATH, | |
10425 | .doit = nl80211_del_mpath, | |
10426 | .policy = nl80211_policy, | |
9f1ba906 | 10427 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10428 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10429 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
10430 | }, |
10431 | { | |
10432 | .cmd = NL80211_CMD_SET_BSS, | |
10433 | .doit = nl80211_set_bss, | |
10434 | .policy = nl80211_policy, | |
b2e1b302 | 10435 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10436 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10437 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 10438 | }, |
f130347c LR |
10439 | { |
10440 | .cmd = NL80211_CMD_GET_REG, | |
ad30ca2c AN |
10441 | .doit = nl80211_get_reg_do, |
10442 | .dumpit = nl80211_get_reg_dump, | |
f130347c | 10443 | .policy = nl80211_policy, |
5fe231e8 | 10444 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
10445 | /* can be retrieved by unprivileged users */ |
10446 | }, | |
b2e1b302 LR |
10447 | { |
10448 | .cmd = NL80211_CMD_SET_REG, | |
10449 | .doit = nl80211_set_reg, | |
10450 | .policy = nl80211_policy, | |
10451 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 10452 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
10453 | }, |
10454 | { | |
10455 | .cmd = NL80211_CMD_REQ_SET_REG, | |
10456 | .doit = nl80211_req_set_reg, | |
10457 | .policy = nl80211_policy, | |
93da9cc1 | 10458 | .flags = GENL_ADMIN_PERM, |
10459 | }, | |
10460 | { | |
24bdd9f4 JC |
10461 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
10462 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 10463 | .policy = nl80211_policy, |
10464 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 10465 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10466 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 10467 | }, |
10468 | { | |
24bdd9f4 JC |
10469 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
10470 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 10471 | .policy = nl80211_policy, |
9aed3cc1 | 10472 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 10473 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10474 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 10475 | }, |
2a519311 JB |
10476 | { |
10477 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
10478 | .doit = nl80211_trigger_scan, | |
10479 | .policy = nl80211_policy, | |
10480 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 10481 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10482 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
10483 | }, |
10484 | { | |
10485 | .cmd = NL80211_CMD_GET_SCAN, | |
10486 | .policy = nl80211_policy, | |
10487 | .dumpit = nl80211_dump_scan, | |
10488 | }, | |
807f8a8c LC |
10489 | { |
10490 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
10491 | .doit = nl80211_start_sched_scan, | |
10492 | .policy = nl80211_policy, | |
10493 | .flags = GENL_ADMIN_PERM, | |
10494 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10495 | NL80211_FLAG_NEED_RTNL, | |
10496 | }, | |
10497 | { | |
10498 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
10499 | .doit = nl80211_stop_sched_scan, | |
10500 | .policy = nl80211_policy, | |
10501 | .flags = GENL_ADMIN_PERM, | |
10502 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10503 | NL80211_FLAG_NEED_RTNL, | |
10504 | }, | |
636a5d36 JM |
10505 | { |
10506 | .cmd = NL80211_CMD_AUTHENTICATE, | |
10507 | .doit = nl80211_authenticate, | |
10508 | .policy = nl80211_policy, | |
10509 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10510 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10511 | NL80211_FLAG_NEED_RTNL | |
10512 | NL80211_FLAG_CLEAR_SKB, | |
636a5d36 JM |
10513 | }, |
10514 | { | |
10515 | .cmd = NL80211_CMD_ASSOCIATE, | |
10516 | .doit = nl80211_associate, | |
10517 | .policy = nl80211_policy, | |
10518 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10519 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10520 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10521 | }, |
10522 | { | |
10523 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
10524 | .doit = nl80211_deauthenticate, | |
10525 | .policy = nl80211_policy, | |
10526 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10527 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10528 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10529 | }, |
10530 | { | |
10531 | .cmd = NL80211_CMD_DISASSOCIATE, | |
10532 | .doit = nl80211_disassociate, | |
10533 | .policy = nl80211_policy, | |
10534 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10535 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10536 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 10537 | }, |
04a773ad JB |
10538 | { |
10539 | .cmd = NL80211_CMD_JOIN_IBSS, | |
10540 | .doit = nl80211_join_ibss, | |
10541 | .policy = nl80211_policy, | |
10542 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10543 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10544 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
10545 | }, |
10546 | { | |
10547 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
10548 | .doit = nl80211_leave_ibss, | |
10549 | .policy = nl80211_policy, | |
10550 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10551 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10552 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 10553 | }, |
aff89a9b JB |
10554 | #ifdef CONFIG_NL80211_TESTMODE |
10555 | { | |
10556 | .cmd = NL80211_CMD_TESTMODE, | |
10557 | .doit = nl80211_testmode_do, | |
71063f0e | 10558 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
10559 | .policy = nl80211_policy, |
10560 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10561 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10562 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
10563 | }, |
10564 | #endif | |
b23aa676 SO |
10565 | { |
10566 | .cmd = NL80211_CMD_CONNECT, | |
10567 | .doit = nl80211_connect, | |
10568 | .policy = nl80211_policy, | |
10569 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10570 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10571 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
10572 | }, |
10573 | { | |
10574 | .cmd = NL80211_CMD_DISCONNECT, | |
10575 | .doit = nl80211_disconnect, | |
10576 | .policy = nl80211_policy, | |
10577 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10578 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10579 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 10580 | }, |
463d0183 JB |
10581 | { |
10582 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
10583 | .doit = nl80211_wiphy_netns, | |
10584 | .policy = nl80211_policy, | |
10585 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10586 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10587 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 10588 | }, |
61fa713c HS |
10589 | { |
10590 | .cmd = NL80211_CMD_GET_SURVEY, | |
10591 | .policy = nl80211_policy, | |
10592 | .dumpit = nl80211_dump_survey, | |
10593 | }, | |
67fbb16b SO |
10594 | { |
10595 | .cmd = NL80211_CMD_SET_PMKSA, | |
10596 | .doit = nl80211_setdel_pmksa, | |
10597 | .policy = nl80211_policy, | |
10598 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10599 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10600 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10601 | }, |
10602 | { | |
10603 | .cmd = NL80211_CMD_DEL_PMKSA, | |
10604 | .doit = nl80211_setdel_pmksa, | |
10605 | .policy = nl80211_policy, | |
10606 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10607 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10608 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10609 | }, |
10610 | { | |
10611 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
10612 | .doit = nl80211_flush_pmksa, | |
10613 | .policy = nl80211_policy, | |
10614 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10615 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10616 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 10617 | }, |
9588bbd5 JM |
10618 | { |
10619 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
10620 | .doit = nl80211_remain_on_channel, | |
10621 | .policy = nl80211_policy, | |
10622 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10623 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10624 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
10625 | }, |
10626 | { | |
10627 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
10628 | .doit = nl80211_cancel_remain_on_channel, | |
10629 | .policy = nl80211_policy, | |
10630 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10631 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10632 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 10633 | }, |
13ae75b1 JM |
10634 | { |
10635 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
10636 | .doit = nl80211_set_tx_bitrate_mask, | |
10637 | .policy = nl80211_policy, | |
10638 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10639 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10640 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 10641 | }, |
026331c4 | 10642 | { |
2e161f78 JB |
10643 | .cmd = NL80211_CMD_REGISTER_FRAME, |
10644 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
10645 | .policy = nl80211_policy, |
10646 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10647 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10648 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
10649 | }, |
10650 | { | |
2e161f78 JB |
10651 | .cmd = NL80211_CMD_FRAME, |
10652 | .doit = nl80211_tx_mgmt, | |
026331c4 | 10653 | .policy = nl80211_policy, |
f7ca38df | 10654 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10655 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
10656 | NL80211_FLAG_NEED_RTNL, |
10657 | }, | |
10658 | { | |
10659 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
10660 | .doit = nl80211_tx_mgmt_cancel_wait, | |
10661 | .policy = nl80211_policy, | |
026331c4 | 10662 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10663 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10664 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 10665 | }, |
ffb9eb3d KV |
10666 | { |
10667 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
10668 | .doit = nl80211_set_power_save, | |
10669 | .policy = nl80211_policy, | |
10670 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10671 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10672 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
10673 | }, |
10674 | { | |
10675 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
10676 | .doit = nl80211_get_power_save, | |
10677 | .policy = nl80211_policy, | |
10678 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
10679 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10680 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 10681 | }, |
d6dc1a38 JO |
10682 | { |
10683 | .cmd = NL80211_CMD_SET_CQM, | |
10684 | .doit = nl80211_set_cqm, | |
10685 | .policy = nl80211_policy, | |
10686 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10687 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10688 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 10689 | }, |
f444de05 JB |
10690 | { |
10691 | .cmd = NL80211_CMD_SET_CHANNEL, | |
10692 | .doit = nl80211_set_channel, | |
10693 | .policy = nl80211_policy, | |
10694 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10695 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10696 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 10697 | }, |
e8347eba BJ |
10698 | { |
10699 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
10700 | .doit = nl80211_set_wds_peer, | |
10701 | .policy = nl80211_policy, | |
10702 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
10703 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10704 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 10705 | }, |
29cbe68c JB |
10706 | { |
10707 | .cmd = NL80211_CMD_JOIN_MESH, | |
10708 | .doit = nl80211_join_mesh, | |
10709 | .policy = nl80211_policy, | |
10710 | .flags = GENL_ADMIN_PERM, | |
10711 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10712 | NL80211_FLAG_NEED_RTNL, | |
10713 | }, | |
10714 | { | |
10715 | .cmd = NL80211_CMD_LEAVE_MESH, | |
10716 | .doit = nl80211_leave_mesh, | |
10717 | .policy = nl80211_policy, | |
10718 | .flags = GENL_ADMIN_PERM, | |
10719 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10720 | NL80211_FLAG_NEED_RTNL, | |
10721 | }, | |
6e0bd6c3 RL |
10722 | { |
10723 | .cmd = NL80211_CMD_JOIN_OCB, | |
10724 | .doit = nl80211_join_ocb, | |
10725 | .policy = nl80211_policy, | |
10726 | .flags = GENL_ADMIN_PERM, | |
10727 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10728 | NL80211_FLAG_NEED_RTNL, | |
10729 | }, | |
10730 | { | |
10731 | .cmd = NL80211_CMD_LEAVE_OCB, | |
10732 | .doit = nl80211_leave_ocb, | |
10733 | .policy = nl80211_policy, | |
10734 | .flags = GENL_ADMIN_PERM, | |
10735 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10736 | NL80211_FLAG_NEED_RTNL, | |
10737 | }, | |
dfb89c56 | 10738 | #ifdef CONFIG_PM |
ff1b6e69 JB |
10739 | { |
10740 | .cmd = NL80211_CMD_GET_WOWLAN, | |
10741 | .doit = nl80211_get_wowlan, | |
10742 | .policy = nl80211_policy, | |
10743 | /* can be retrieved by unprivileged users */ | |
10744 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10745 | NL80211_FLAG_NEED_RTNL, | |
10746 | }, | |
10747 | { | |
10748 | .cmd = NL80211_CMD_SET_WOWLAN, | |
10749 | .doit = nl80211_set_wowlan, | |
10750 | .policy = nl80211_policy, | |
10751 | .flags = GENL_ADMIN_PERM, | |
10752 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10753 | NL80211_FLAG_NEED_RTNL, | |
10754 | }, | |
dfb89c56 | 10755 | #endif |
e5497d76 JB |
10756 | { |
10757 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
10758 | .doit = nl80211_set_rekey_data, | |
10759 | .policy = nl80211_policy, | |
10760 | .flags = GENL_ADMIN_PERM, | |
10761 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
5393b917 JB |
10762 | NL80211_FLAG_NEED_RTNL | |
10763 | NL80211_FLAG_CLEAR_SKB, | |
e5497d76 | 10764 | }, |
109086ce AN |
10765 | { |
10766 | .cmd = NL80211_CMD_TDLS_MGMT, | |
10767 | .doit = nl80211_tdls_mgmt, | |
10768 | .policy = nl80211_policy, | |
10769 | .flags = GENL_ADMIN_PERM, | |
10770 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10771 | NL80211_FLAG_NEED_RTNL, | |
10772 | }, | |
10773 | { | |
10774 | .cmd = NL80211_CMD_TDLS_OPER, | |
10775 | .doit = nl80211_tdls_oper, | |
10776 | .policy = nl80211_policy, | |
10777 | .flags = GENL_ADMIN_PERM, | |
10778 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10779 | NL80211_FLAG_NEED_RTNL, | |
10780 | }, | |
28946da7 JB |
10781 | { |
10782 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
10783 | .doit = nl80211_register_unexpected_frame, | |
10784 | .policy = nl80211_policy, | |
10785 | .flags = GENL_ADMIN_PERM, | |
10786 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10787 | NL80211_FLAG_NEED_RTNL, | |
10788 | }, | |
7f6cf311 JB |
10789 | { |
10790 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
10791 | .doit = nl80211_probe_client, | |
10792 | .policy = nl80211_policy, | |
10793 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10794 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
10795 | NL80211_FLAG_NEED_RTNL, |
10796 | }, | |
5e760230 JB |
10797 | { |
10798 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
10799 | .doit = nl80211_register_beacons, | |
10800 | .policy = nl80211_policy, | |
10801 | .flags = GENL_ADMIN_PERM, | |
10802 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10803 | NL80211_FLAG_NEED_RTNL, | |
10804 | }, | |
1d9d9213 SW |
10805 | { |
10806 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
10807 | .doit = nl80211_set_noack_map, | |
10808 | .policy = nl80211_policy, | |
10809 | .flags = GENL_ADMIN_PERM, | |
10810 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10811 | NL80211_FLAG_NEED_RTNL, | |
10812 | }, | |
98104fde JB |
10813 | { |
10814 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
10815 | .doit = nl80211_start_p2p_device, | |
10816 | .policy = nl80211_policy, | |
10817 | .flags = GENL_ADMIN_PERM, | |
10818 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
10819 | NL80211_FLAG_NEED_RTNL, | |
10820 | }, | |
10821 | { | |
10822 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
10823 | .doit = nl80211_stop_p2p_device, | |
10824 | .policy = nl80211_policy, | |
10825 | .flags = GENL_ADMIN_PERM, | |
10826 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10827 | NL80211_FLAG_NEED_RTNL, | |
10828 | }, | |
f4e583c8 AQ |
10829 | { |
10830 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
10831 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
10832 | .policy = nl80211_policy, |
10833 | .flags = GENL_ADMIN_PERM, | |
10834 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10835 | NL80211_FLAG_NEED_RTNL, | |
10836 | }, | |
10837 | { | |
10838 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
10839 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
10840 | .policy = nl80211_policy, |
10841 | .flags = GENL_ADMIN_PERM, | |
10842 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10843 | NL80211_FLAG_NEED_RTNL, | |
10844 | }, | |
04f39047 SW |
10845 | { |
10846 | .cmd = NL80211_CMD_RADAR_DETECT, | |
10847 | .doit = nl80211_start_radar_detection, | |
10848 | .policy = nl80211_policy, | |
10849 | .flags = GENL_ADMIN_PERM, | |
10850 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10851 | NL80211_FLAG_NEED_RTNL, | |
10852 | }, | |
3713b4e3 JB |
10853 | { |
10854 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
10855 | .doit = nl80211_get_protocol_features, | |
10856 | .policy = nl80211_policy, | |
10857 | }, | |
355199e0 JM |
10858 | { |
10859 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
10860 | .doit = nl80211_update_ft_ies, | |
10861 | .policy = nl80211_policy, | |
10862 | .flags = GENL_ADMIN_PERM, | |
10863 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10864 | NL80211_FLAG_NEED_RTNL, | |
10865 | }, | |
5de17984 AS |
10866 | { |
10867 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
10868 | .doit = nl80211_crit_protocol_start, | |
10869 | .policy = nl80211_policy, | |
10870 | .flags = GENL_ADMIN_PERM, | |
10871 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10872 | NL80211_FLAG_NEED_RTNL, | |
10873 | }, | |
10874 | { | |
10875 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
10876 | .doit = nl80211_crit_protocol_stop, | |
10877 | .policy = nl80211_policy, | |
10878 | .flags = GENL_ADMIN_PERM, | |
10879 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10880 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
10881 | }, |
10882 | { | |
10883 | .cmd = NL80211_CMD_GET_COALESCE, | |
10884 | .doit = nl80211_get_coalesce, | |
10885 | .policy = nl80211_policy, | |
10886 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10887 | NL80211_FLAG_NEED_RTNL, | |
10888 | }, | |
10889 | { | |
10890 | .cmd = NL80211_CMD_SET_COALESCE, | |
10891 | .doit = nl80211_set_coalesce, | |
10892 | .policy = nl80211_policy, | |
10893 | .flags = GENL_ADMIN_PERM, | |
10894 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10895 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
10896 | }, |
10897 | { | |
10898 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
10899 | .doit = nl80211_channel_switch, | |
10900 | .policy = nl80211_policy, | |
10901 | .flags = GENL_ADMIN_PERM, | |
10902 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10903 | NL80211_FLAG_NEED_RTNL, | |
10904 | }, | |
ad7e718c JB |
10905 | { |
10906 | .cmd = NL80211_CMD_VENDOR, | |
10907 | .doit = nl80211_vendor_cmd, | |
10908 | .policy = nl80211_policy, | |
10909 | .flags = GENL_ADMIN_PERM, | |
10910 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10911 | NL80211_FLAG_NEED_RTNL, | |
10912 | }, | |
fa9ffc74 KP |
10913 | { |
10914 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
10915 | .doit = nl80211_set_qos_map, | |
10916 | .policy = nl80211_policy, | |
10917 | .flags = GENL_ADMIN_PERM, | |
10918 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10919 | NL80211_FLAG_NEED_RTNL, | |
10920 | }, | |
960d01ac JB |
10921 | { |
10922 | .cmd = NL80211_CMD_ADD_TX_TS, | |
10923 | .doit = nl80211_add_tx_ts, | |
10924 | .policy = nl80211_policy, | |
10925 | .flags = GENL_ADMIN_PERM, | |
10926 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10927 | NL80211_FLAG_NEED_RTNL, | |
10928 | }, | |
10929 | { | |
10930 | .cmd = NL80211_CMD_DEL_TX_TS, | |
10931 | .doit = nl80211_del_tx_ts, | |
10932 | .policy = nl80211_policy, | |
10933 | .flags = GENL_ADMIN_PERM, | |
10934 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10935 | NL80211_FLAG_NEED_RTNL, | |
10936 | }, | |
1057d35e AN |
10937 | { |
10938 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | |
10939 | .doit = nl80211_tdls_channel_switch, | |
10940 | .policy = nl80211_policy, | |
10941 | .flags = GENL_ADMIN_PERM, | |
10942 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10943 | NL80211_FLAG_NEED_RTNL, | |
10944 | }, | |
10945 | { | |
10946 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | |
10947 | .doit = nl80211_tdls_cancel_channel_switch, | |
10948 | .policy = nl80211_policy, | |
10949 | .flags = GENL_ADMIN_PERM, | |
10950 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10951 | NL80211_FLAG_NEED_RTNL, | |
10952 | }, | |
55682965 | 10953 | }; |
9588bbd5 | 10954 | |
55682965 JB |
10955 | /* notification functions */ |
10956 | ||
3bb20556 JB |
10957 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
10958 | enum nl80211_commands cmd) | |
55682965 JB |
10959 | { |
10960 | struct sk_buff *msg; | |
86e8cf98 | 10961 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 10962 | |
3bb20556 JB |
10963 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
10964 | cmd != NL80211_CMD_DEL_WIPHY); | |
10965 | ||
fd2120ca | 10966 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
10967 | if (!msg) |
10968 | return; | |
10969 | ||
3bb20556 | 10970 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
10971 | nlmsg_free(msg); |
10972 | return; | |
10973 | } | |
10974 | ||
68eb5503 | 10975 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10976 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
10977 | } |
10978 | ||
362a415d JB |
10979 | static int nl80211_add_scan_req(struct sk_buff *msg, |
10980 | struct cfg80211_registered_device *rdev) | |
10981 | { | |
10982 | struct cfg80211_scan_request *req = rdev->scan_req; | |
10983 | struct nlattr *nest; | |
10984 | int i; | |
10985 | ||
10986 | if (WARN_ON(!req)) | |
10987 | return 0; | |
10988 | ||
10989 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
10990 | if (!nest) | |
10991 | goto nla_put_failure; | |
9360ffd1 DM |
10992 | for (i = 0; i < req->n_ssids; i++) { |
10993 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
10994 | goto nla_put_failure; | |
10995 | } | |
362a415d JB |
10996 | nla_nest_end(msg, nest); |
10997 | ||
10998 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
10999 | if (!nest) | |
11000 | goto nla_put_failure; | |
9360ffd1 DM |
11001 | for (i = 0; i < req->n_channels; i++) { |
11002 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
11003 | goto nla_put_failure; | |
11004 | } | |
362a415d JB |
11005 | nla_nest_end(msg, nest); |
11006 | ||
9360ffd1 DM |
11007 | if (req->ie && |
11008 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
11009 | goto nla_put_failure; | |
362a415d | 11010 | |
ae917c9f JB |
11011 | if (req->flags && |
11012 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
11013 | goto nla_put_failure; | |
ed473771 | 11014 | |
362a415d JB |
11015 | return 0; |
11016 | nla_put_failure: | |
11017 | return -ENOBUFS; | |
11018 | } | |
11019 | ||
a538e2d5 JB |
11020 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
11021 | struct cfg80211_registered_device *rdev, | |
fd014284 | 11022 | struct wireless_dev *wdev, |
15e47304 | 11023 | u32 portid, u32 seq, int flags, |
a538e2d5 | 11024 | u32 cmd) |
2a519311 JB |
11025 | { |
11026 | void *hdr; | |
11027 | ||
15e47304 | 11028 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
11029 | if (!hdr) |
11030 | return -1; | |
11031 | ||
9360ffd1 | 11032 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
11033 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11034 | wdev->netdev->ifindex)) || | |
11035 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 11036 | goto nla_put_failure; |
2a519311 | 11037 | |
362a415d JB |
11038 | /* ignore errors and send incomplete event anyway */ |
11039 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
11040 | |
11041 | return genlmsg_end(msg, hdr); | |
11042 | ||
11043 | nla_put_failure: | |
11044 | genlmsg_cancel(msg, hdr); | |
11045 | return -EMSGSIZE; | |
11046 | } | |
11047 | ||
807f8a8c LC |
11048 | static int |
11049 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
11050 | struct cfg80211_registered_device *rdev, | |
11051 | struct net_device *netdev, | |
15e47304 | 11052 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
11053 | { |
11054 | void *hdr; | |
11055 | ||
15e47304 | 11056 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
11057 | if (!hdr) |
11058 | return -1; | |
11059 | ||
9360ffd1 DM |
11060 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11061 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
11062 | goto nla_put_failure; | |
807f8a8c LC |
11063 | |
11064 | return genlmsg_end(msg, hdr); | |
11065 | ||
11066 | nla_put_failure: | |
11067 | genlmsg_cancel(msg, hdr); | |
11068 | return -EMSGSIZE; | |
11069 | } | |
11070 | ||
a538e2d5 | 11071 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 11072 | struct wireless_dev *wdev) |
a538e2d5 JB |
11073 | { |
11074 | struct sk_buff *msg; | |
11075 | ||
58050fce | 11076 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
11077 | if (!msg) |
11078 | return; | |
11079 | ||
fd014284 | 11080 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
11081 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
11082 | nlmsg_free(msg); | |
11083 | return; | |
11084 | } | |
11085 | ||
68eb5503 | 11086 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11087 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
11088 | } |
11089 | ||
f9d15d16 JB |
11090 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
11091 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
11092 | { |
11093 | struct sk_buff *msg; | |
11094 | ||
fd2120ca | 11095 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 11096 | if (!msg) |
f9d15d16 | 11097 | return NULL; |
2a519311 | 11098 | |
fd014284 | 11099 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
11100 | aborted ? NL80211_CMD_SCAN_ABORTED : |
11101 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 11102 | nlmsg_free(msg); |
f9d15d16 | 11103 | return NULL; |
2a519311 JB |
11104 | } |
11105 | ||
f9d15d16 | 11106 | return msg; |
2a519311 JB |
11107 | } |
11108 | ||
f9d15d16 JB |
11109 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
11110 | struct sk_buff *msg) | |
2a519311 | 11111 | { |
2a519311 JB |
11112 | if (!msg) |
11113 | return; | |
11114 | ||
68eb5503 | 11115 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11116 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
11117 | } |
11118 | ||
807f8a8c LC |
11119 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
11120 | struct net_device *netdev) | |
11121 | { | |
11122 | struct sk_buff *msg; | |
11123 | ||
11124 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11125 | if (!msg) | |
11126 | return; | |
11127 | ||
11128 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
11129 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
11130 | nlmsg_free(msg); | |
11131 | return; | |
11132 | } | |
11133 | ||
68eb5503 | 11134 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11135 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11136 | } |
11137 | ||
11138 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
11139 | struct net_device *netdev, u32 cmd) | |
11140 | { | |
11141 | struct sk_buff *msg; | |
11142 | ||
58050fce | 11143 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
11144 | if (!msg) |
11145 | return; | |
11146 | ||
11147 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
11148 | nlmsg_free(msg); | |
11149 | return; | |
11150 | } | |
11151 | ||
68eb5503 | 11152 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11153 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11154 | } |
11155 | ||
b0d7aa59 JD |
11156 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
11157 | struct regulatory_request *request) | |
73d54c9e | 11158 | { |
73d54c9e | 11159 | /* Userspace can always count this one always being set */ |
9360ffd1 DM |
11160 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
11161 | goto nla_put_failure; | |
11162 | ||
11163 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
11164 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11165 | NL80211_REGDOM_TYPE_WORLD)) | |
11166 | goto nla_put_failure; | |
11167 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
11168 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11169 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
11170 | goto nla_put_failure; | |
11171 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
11172 | request->intersect) { | |
11173 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11174 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
11175 | goto nla_put_failure; | |
11176 | } else { | |
11177 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11178 | NL80211_REGDOM_TYPE_COUNTRY) || | |
11179 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
11180 | request->alpha2)) | |
11181 | goto nla_put_failure; | |
11182 | } | |
11183 | ||
ad30ca2c AN |
11184 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
11185 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); | |
11186 | ||
11187 | if (wiphy && | |
11188 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | |
11189 | goto nla_put_failure; | |
1bdd716c AN |
11190 | |
11191 | if (wiphy && | |
11192 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | |
11193 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
11194 | goto nla_put_failure; | |
ad30ca2c | 11195 | } |
73d54c9e | 11196 | |
b0d7aa59 JD |
11197 | return true; |
11198 | ||
11199 | nla_put_failure: | |
11200 | return false; | |
11201 | } | |
11202 | ||
11203 | /* | |
11204 | * This can happen on global regulatory changes or device specific settings | |
11205 | * based on custom regulatory domains. | |
11206 | */ | |
11207 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, | |
11208 | struct regulatory_request *request) | |
11209 | { | |
11210 | struct sk_buff *msg; | |
11211 | void *hdr; | |
11212 | ||
11213 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11214 | if (!msg) | |
11215 | return; | |
11216 | ||
11217 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); | |
11218 | if (!hdr) { | |
11219 | nlmsg_free(msg); | |
11220 | return; | |
11221 | } | |
11222 | ||
11223 | if (nl80211_reg_change_event_fill(msg, request) == false) | |
11224 | goto nla_put_failure; | |
11225 | ||
3b7b72ee | 11226 | genlmsg_end(msg, hdr); |
73d54c9e | 11227 | |
bc43b28c | 11228 | rcu_read_lock(); |
68eb5503 | 11229 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11230 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 11231 | rcu_read_unlock(); |
73d54c9e LR |
11232 | |
11233 | return; | |
11234 | ||
11235 | nla_put_failure: | |
11236 | genlmsg_cancel(msg, hdr); | |
11237 | nlmsg_free(msg); | |
11238 | } | |
11239 | ||
6039f6d2 JM |
11240 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
11241 | struct net_device *netdev, | |
11242 | const u8 *buf, size_t len, | |
b0b6aa2c EP |
11243 | enum nl80211_commands cmd, gfp_t gfp, |
11244 | int uapsd_queues) | |
6039f6d2 JM |
11245 | { |
11246 | struct sk_buff *msg; | |
11247 | void *hdr; | |
11248 | ||
e6d6e342 | 11249 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
11250 | if (!msg) |
11251 | return; | |
11252 | ||
11253 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11254 | if (!hdr) { | |
11255 | nlmsg_free(msg); | |
11256 | return; | |
11257 | } | |
11258 | ||
9360ffd1 DM |
11259 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11260 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11261 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
11262 | goto nla_put_failure; | |
6039f6d2 | 11263 | |
b0b6aa2c EP |
11264 | if (uapsd_queues >= 0) { |
11265 | struct nlattr *nla_wmm = | |
11266 | nla_nest_start(msg, NL80211_ATTR_STA_WME); | |
11267 | if (!nla_wmm) | |
11268 | goto nla_put_failure; | |
11269 | ||
11270 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
11271 | uapsd_queues)) | |
11272 | goto nla_put_failure; | |
11273 | ||
11274 | nla_nest_end(msg, nla_wmm); | |
11275 | } | |
11276 | ||
3b7b72ee | 11277 | genlmsg_end(msg, hdr); |
6039f6d2 | 11278 | |
68eb5503 | 11279 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11280 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
11281 | return; |
11282 | ||
11283 | nla_put_failure: | |
11284 | genlmsg_cancel(msg, hdr); | |
11285 | nlmsg_free(msg); | |
11286 | } | |
11287 | ||
11288 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11289 | struct net_device *netdev, const u8 *buf, |
11290 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11291 | { |
11292 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11293 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11294 | } |
11295 | ||
11296 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
11297 | struct net_device *netdev, const u8 *buf, | |
b0b6aa2c | 11298 | size_t len, gfp_t gfp, int uapsd_queues) |
6039f6d2 | 11299 | { |
e6d6e342 | 11300 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
b0b6aa2c | 11301 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
6039f6d2 JM |
11302 | } |
11303 | ||
53b46b84 | 11304 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
11305 | struct net_device *netdev, const u8 *buf, |
11306 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11307 | { |
11308 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11309 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11310 | } |
11311 | ||
53b46b84 JM |
11312 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
11313 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 11314 | size_t len, gfp_t gfp) |
6039f6d2 JM |
11315 | { |
11316 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11317 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
6039f6d2 JM |
11318 | } |
11319 | ||
6ff57cf8 JB |
11320 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
11321 | size_t len) | |
cf4e594e | 11322 | { |
947add36 JB |
11323 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11324 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11325 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
11326 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
11327 | u32 cmd; | |
947add36 | 11328 | |
6ff57cf8 JB |
11329 | if (WARN_ON(len < 2)) |
11330 | return; | |
cf4e594e | 11331 | |
6ff57cf8 JB |
11332 | if (ieee80211_is_deauth(mgmt->frame_control)) |
11333 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
11334 | else | |
11335 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 11336 | |
6ff57cf8 | 11337 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
b0b6aa2c | 11338 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
cf4e594e | 11339 | } |
6ff57cf8 | 11340 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 11341 | |
1b06bb40 LR |
11342 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
11343 | struct net_device *netdev, int cmd, | |
e6d6e342 | 11344 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
11345 | { |
11346 | struct sk_buff *msg; | |
11347 | void *hdr; | |
11348 | ||
e6d6e342 | 11349 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
11350 | if (!msg) |
11351 | return; | |
11352 | ||
11353 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11354 | if (!hdr) { | |
11355 | nlmsg_free(msg); | |
11356 | return; | |
11357 | } | |
11358 | ||
9360ffd1 DM |
11359 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11360 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11361 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
11362 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11363 | goto nla_put_failure; | |
1965c853 | 11364 | |
3b7b72ee | 11365 | genlmsg_end(msg, hdr); |
1965c853 | 11366 | |
68eb5503 | 11367 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11368 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
11369 | return; |
11370 | ||
11371 | nla_put_failure: | |
11372 | genlmsg_cancel(msg, hdr); | |
11373 | nlmsg_free(msg); | |
11374 | } | |
11375 | ||
11376 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11377 | struct net_device *netdev, const u8 *addr, |
11378 | gfp_t gfp) | |
1965c853 JM |
11379 | { |
11380 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 11381 | addr, gfp); |
1965c853 JM |
11382 | } |
11383 | ||
11384 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11385 | struct net_device *netdev, const u8 *addr, |
11386 | gfp_t gfp) | |
1965c853 | 11387 | { |
e6d6e342 JB |
11388 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
11389 | addr, gfp); | |
1965c853 JM |
11390 | } |
11391 | ||
b23aa676 SO |
11392 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
11393 | struct net_device *netdev, const u8 *bssid, | |
11394 | const u8 *req_ie, size_t req_ie_len, | |
11395 | const u8 *resp_ie, size_t resp_ie_len, | |
11396 | u16 status, gfp_t gfp) | |
11397 | { | |
11398 | struct sk_buff *msg; | |
11399 | void *hdr; | |
11400 | ||
58050fce | 11401 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
11402 | if (!msg) |
11403 | return; | |
11404 | ||
11405 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
11406 | if (!hdr) { | |
11407 | nlmsg_free(msg); | |
11408 | return; | |
11409 | } | |
11410 | ||
9360ffd1 DM |
11411 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11412 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11413 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
11414 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
11415 | (req_ie && | |
11416 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11417 | (resp_ie && | |
11418 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11419 | goto nla_put_failure; | |
b23aa676 | 11420 | |
3b7b72ee | 11421 | genlmsg_end(msg, hdr); |
b23aa676 | 11422 | |
68eb5503 | 11423 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11424 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11425 | return; |
11426 | ||
11427 | nla_put_failure: | |
11428 | genlmsg_cancel(msg, hdr); | |
11429 | nlmsg_free(msg); | |
11430 | ||
11431 | } | |
11432 | ||
11433 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
11434 | struct net_device *netdev, const u8 *bssid, | |
11435 | const u8 *req_ie, size_t req_ie_len, | |
11436 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
11437 | { | |
11438 | struct sk_buff *msg; | |
11439 | void *hdr; | |
11440 | ||
58050fce | 11441 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
11442 | if (!msg) |
11443 | return; | |
11444 | ||
11445 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
11446 | if (!hdr) { | |
11447 | nlmsg_free(msg); | |
11448 | return; | |
11449 | } | |
11450 | ||
9360ffd1 DM |
11451 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11452 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11453 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
11454 | (req_ie && | |
11455 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11456 | (resp_ie && | |
11457 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11458 | goto nla_put_failure; | |
b23aa676 | 11459 | |
3b7b72ee | 11460 | genlmsg_end(msg, hdr); |
b23aa676 | 11461 | |
68eb5503 | 11462 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11463 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11464 | return; |
11465 | ||
11466 | nla_put_failure: | |
11467 | genlmsg_cancel(msg, hdr); | |
11468 | nlmsg_free(msg); | |
11469 | ||
11470 | } | |
11471 | ||
11472 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
11473 | struct net_device *netdev, u16 reason, | |
667503dd | 11474 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
11475 | { |
11476 | struct sk_buff *msg; | |
11477 | void *hdr; | |
11478 | ||
58050fce | 11479 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
11480 | if (!msg) |
11481 | return; | |
11482 | ||
11483 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
11484 | if (!hdr) { | |
11485 | nlmsg_free(msg); | |
11486 | return; | |
11487 | } | |
11488 | ||
9360ffd1 DM |
11489 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11490 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11491 | (from_ap && reason && | |
11492 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
11493 | (from_ap && | |
11494 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
11495 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
11496 | goto nla_put_failure; | |
b23aa676 | 11497 | |
3b7b72ee | 11498 | genlmsg_end(msg, hdr); |
b23aa676 | 11499 | |
68eb5503 | 11500 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11501 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
11502 | return; |
11503 | ||
11504 | nla_put_failure: | |
11505 | genlmsg_cancel(msg, hdr); | |
11506 | nlmsg_free(msg); | |
11507 | ||
11508 | } | |
11509 | ||
04a773ad JB |
11510 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
11511 | struct net_device *netdev, const u8 *bssid, | |
11512 | gfp_t gfp) | |
11513 | { | |
11514 | struct sk_buff *msg; | |
11515 | void *hdr; | |
11516 | ||
fd2120ca | 11517 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
11518 | if (!msg) |
11519 | return; | |
11520 | ||
11521 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
11522 | if (!hdr) { | |
11523 | nlmsg_free(msg); | |
11524 | return; | |
11525 | } | |
11526 | ||
9360ffd1 DM |
11527 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11528 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11529 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
11530 | goto nla_put_failure; | |
04a773ad | 11531 | |
3b7b72ee | 11532 | genlmsg_end(msg, hdr); |
04a773ad | 11533 | |
68eb5503 | 11534 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11535 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
11536 | return; |
11537 | ||
11538 | nla_put_failure: | |
11539 | genlmsg_cancel(msg, hdr); | |
11540 | nlmsg_free(msg); | |
11541 | } | |
11542 | ||
947add36 JB |
11543 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
11544 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 11545 | { |
947add36 | 11546 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 11547 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
11548 | struct sk_buff *msg; |
11549 | void *hdr; | |
11550 | ||
947add36 JB |
11551 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
11552 | return; | |
11553 | ||
11554 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
11555 | ||
c93b5e71 JC |
11556 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11557 | if (!msg) | |
11558 | return; | |
11559 | ||
11560 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
11561 | if (!hdr) { | |
11562 | nlmsg_free(msg); | |
11563 | return; | |
11564 | } | |
11565 | ||
9360ffd1 | 11566 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
11567 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
11568 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
11569 | (ie_len && ie && |
11570 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
11571 | goto nla_put_failure; | |
c93b5e71 | 11572 | |
3b7b72ee | 11573 | genlmsg_end(msg, hdr); |
c93b5e71 | 11574 | |
68eb5503 | 11575 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11576 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
11577 | return; |
11578 | ||
11579 | nla_put_failure: | |
11580 | genlmsg_cancel(msg, hdr); | |
11581 | nlmsg_free(msg); | |
11582 | } | |
947add36 | 11583 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 11584 | |
a3b8b056 JM |
11585 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
11586 | struct net_device *netdev, const u8 *addr, | |
11587 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 11588 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
11589 | { |
11590 | struct sk_buff *msg; | |
11591 | void *hdr; | |
11592 | ||
e6d6e342 | 11593 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
11594 | if (!msg) |
11595 | return; | |
11596 | ||
11597 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
11598 | if (!hdr) { | |
11599 | nlmsg_free(msg); | |
11600 | return; | |
11601 | } | |
11602 | ||
9360ffd1 DM |
11603 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11604 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11605 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
11606 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
11607 | (key_id != -1 && | |
11608 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
11609 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
11610 | goto nla_put_failure; | |
a3b8b056 | 11611 | |
3b7b72ee | 11612 | genlmsg_end(msg, hdr); |
a3b8b056 | 11613 | |
68eb5503 | 11614 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11615 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
11616 | return; |
11617 | ||
11618 | nla_put_failure: | |
11619 | genlmsg_cancel(msg, hdr); | |
11620 | nlmsg_free(msg); | |
11621 | } | |
11622 | ||
6bad8766 LR |
11623 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
11624 | struct ieee80211_channel *channel_before, | |
11625 | struct ieee80211_channel *channel_after) | |
11626 | { | |
11627 | struct sk_buff *msg; | |
11628 | void *hdr; | |
11629 | struct nlattr *nl_freq; | |
11630 | ||
fd2120ca | 11631 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
11632 | if (!msg) |
11633 | return; | |
11634 | ||
11635 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
11636 | if (!hdr) { | |
11637 | nlmsg_free(msg); | |
11638 | return; | |
11639 | } | |
11640 | ||
11641 | /* | |
11642 | * Since we are applying the beacon hint to a wiphy we know its | |
11643 | * wiphy_idx is valid | |
11644 | */ | |
9360ffd1 DM |
11645 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
11646 | goto nla_put_failure; | |
6bad8766 LR |
11647 | |
11648 | /* Before */ | |
11649 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
11650 | if (!nl_freq) | |
11651 | goto nla_put_failure; | |
cdc89b97 | 11652 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
11653 | goto nla_put_failure; |
11654 | nla_nest_end(msg, nl_freq); | |
11655 | ||
11656 | /* After */ | |
11657 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
11658 | if (!nl_freq) | |
11659 | goto nla_put_failure; | |
cdc89b97 | 11660 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
11661 | goto nla_put_failure; |
11662 | nla_nest_end(msg, nl_freq); | |
11663 | ||
3b7b72ee | 11664 | genlmsg_end(msg, hdr); |
6bad8766 | 11665 | |
463d0183 | 11666 | rcu_read_lock(); |
68eb5503 | 11667 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11668 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 11669 | rcu_read_unlock(); |
6bad8766 LR |
11670 | |
11671 | return; | |
11672 | ||
11673 | nla_put_failure: | |
11674 | genlmsg_cancel(msg, hdr); | |
11675 | nlmsg_free(msg); | |
11676 | } | |
11677 | ||
9588bbd5 JM |
11678 | static void nl80211_send_remain_on_chan_event( |
11679 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 11680 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 11681 | struct ieee80211_channel *chan, |
9588bbd5 JM |
11682 | unsigned int duration, gfp_t gfp) |
11683 | { | |
11684 | struct sk_buff *msg; | |
11685 | void *hdr; | |
11686 | ||
11687 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11688 | if (!msg) | |
11689 | return; | |
11690 | ||
11691 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11692 | if (!hdr) { | |
11693 | nlmsg_free(msg); | |
11694 | return; | |
11695 | } | |
11696 | ||
9360ffd1 | 11697 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11698 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11699 | wdev->netdev->ifindex)) || | |
00f53350 | 11700 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 11701 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
11702 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
11703 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
11704 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
11705 | goto nla_put_failure; | |
9588bbd5 | 11706 | |
9360ffd1 DM |
11707 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
11708 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
11709 | goto nla_put_failure; | |
9588bbd5 | 11710 | |
3b7b72ee | 11711 | genlmsg_end(msg, hdr); |
9588bbd5 | 11712 | |
68eb5503 | 11713 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11714 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
11715 | return; |
11716 | ||
11717 | nla_put_failure: | |
11718 | genlmsg_cancel(msg, hdr); | |
11719 | nlmsg_free(msg); | |
11720 | } | |
11721 | ||
947add36 JB |
11722 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
11723 | struct ieee80211_channel *chan, | |
11724 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 11725 | { |
947add36 | 11726 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11727 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11728 | |
11729 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 11730 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 11731 | rdev, wdev, cookie, chan, |
42d97a59 | 11732 | duration, gfp); |
9588bbd5 | 11733 | } |
947add36 | 11734 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 11735 | |
947add36 JB |
11736 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
11737 | struct ieee80211_channel *chan, | |
11738 | gfp_t gfp) | |
9588bbd5 | 11739 | { |
947add36 | 11740 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11741 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11742 | |
11743 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 11744 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 11745 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 11746 | } |
947add36 | 11747 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 11748 | |
947add36 JB |
11749 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
11750 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 11751 | { |
947add36 | 11752 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11753 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
11754 | struct sk_buff *msg; |
11755 | ||
947add36 JB |
11756 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
11757 | ||
58050fce | 11758 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
11759 | if (!msg) |
11760 | return; | |
11761 | ||
cf5ead82 | 11762 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
66266b3a | 11763 | rdev, dev, mac_addr, sinfo) < 0) { |
98b62183 JB |
11764 | nlmsg_free(msg); |
11765 | return; | |
11766 | } | |
11767 | ||
68eb5503 | 11768 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11769 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 11770 | } |
947add36 | 11771 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 11772 | |
cf5ead82 JB |
11773 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
11774 | struct station_info *sinfo, gfp_t gfp) | |
ec15e68b | 11775 | { |
947add36 | 11776 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11777 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b | 11778 | struct sk_buff *msg; |
cf5ead82 JB |
11779 | struct station_info empty_sinfo = {}; |
11780 | ||
11781 | if (!sinfo) | |
11782 | sinfo = &empty_sinfo; | |
ec15e68b | 11783 | |
947add36 JB |
11784 | trace_cfg80211_del_sta(dev, mac_addr); |
11785 | ||
58050fce | 11786 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
11787 | if (!msg) |
11788 | return; | |
11789 | ||
cf5ead82 JB |
11790 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
11791 | rdev, dev, mac_addr, sinfo)) { | |
ec15e68b JM |
11792 | nlmsg_free(msg); |
11793 | return; | |
11794 | } | |
11795 | ||
68eb5503 | 11796 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11797 | NL80211_MCGRP_MLME, gfp); |
ec15e68b | 11798 | } |
cf5ead82 | 11799 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
ec15e68b | 11800 | |
947add36 JB |
11801 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
11802 | enum nl80211_connect_failed_reason reason, | |
11803 | gfp_t gfp) | |
ed44a951 | 11804 | { |
947add36 | 11805 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11806 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
11807 | struct sk_buff *msg; |
11808 | void *hdr; | |
11809 | ||
11810 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
11811 | if (!msg) | |
11812 | return; | |
11813 | ||
11814 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
11815 | if (!hdr) { | |
11816 | nlmsg_free(msg); | |
11817 | return; | |
11818 | } | |
11819 | ||
11820 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11821 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
11822 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
11823 | goto nla_put_failure; | |
11824 | ||
11825 | genlmsg_end(msg, hdr); | |
11826 | ||
68eb5503 | 11827 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11828 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
11829 | return; |
11830 | ||
11831 | nla_put_failure: | |
11832 | genlmsg_cancel(msg, hdr); | |
11833 | nlmsg_free(msg); | |
11834 | } | |
947add36 | 11835 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 11836 | |
b92ab5d8 JB |
11837 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
11838 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
11839 | { |
11840 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 11841 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
11842 | struct sk_buff *msg; |
11843 | void *hdr; | |
15e47304 | 11844 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 11845 | |
15e47304 | 11846 | if (!nlportid) |
28946da7 JB |
11847 | return false; |
11848 | ||
11849 | msg = nlmsg_new(100, gfp); | |
11850 | if (!msg) | |
11851 | return true; | |
11852 | ||
b92ab5d8 | 11853 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
11854 | if (!hdr) { |
11855 | nlmsg_free(msg); | |
11856 | return true; | |
11857 | } | |
11858 | ||
9360ffd1 DM |
11859 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11860 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11861 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11862 | goto nla_put_failure; | |
28946da7 | 11863 | |
9c90a9f6 | 11864 | genlmsg_end(msg, hdr); |
15e47304 | 11865 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
11866 | return true; |
11867 | ||
11868 | nla_put_failure: | |
11869 | genlmsg_cancel(msg, hdr); | |
11870 | nlmsg_free(msg); | |
11871 | return true; | |
11872 | } | |
11873 | ||
947add36 JB |
11874 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
11875 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11876 | { |
947add36 JB |
11877 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11878 | bool ret; | |
11879 | ||
11880 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
11881 | ||
11882 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11883 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
11884 | trace_cfg80211_return_bool(false); | |
11885 | return false; | |
11886 | } | |
11887 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
11888 | addr, gfp); | |
11889 | trace_cfg80211_return_bool(ret); | |
11890 | return ret; | |
b92ab5d8 | 11891 | } |
947add36 | 11892 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 11893 | |
947add36 JB |
11894 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
11895 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11896 | { |
947add36 JB |
11897 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11898 | bool ret; | |
11899 | ||
11900 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
11901 | ||
11902 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11903 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
11904 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
11905 | trace_cfg80211_return_bool(false); | |
11906 | return false; | |
11907 | } | |
11908 | ret = __nl80211_unexpected_frame(dev, | |
11909 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
11910 | addr, gfp); | |
11911 | trace_cfg80211_return_bool(ret); | |
11912 | return ret; | |
b92ab5d8 | 11913 | } |
947add36 | 11914 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 11915 | |
2e161f78 | 11916 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 11917 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 11918 | int freq, int sig_dbm, |
19504cf5 | 11919 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 11920 | { |
71bbc994 | 11921 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11922 | struct sk_buff *msg; |
11923 | void *hdr; | |
026331c4 JM |
11924 | |
11925 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11926 | if (!msg) | |
11927 | return -ENOMEM; | |
11928 | ||
2e161f78 | 11929 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
11930 | if (!hdr) { |
11931 | nlmsg_free(msg); | |
11932 | return -ENOMEM; | |
11933 | } | |
11934 | ||
9360ffd1 | 11935 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11936 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11937 | netdev->ifindex)) || | |
a838490b | 11938 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11939 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
11940 | (sig_dbm && | |
11941 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
11942 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11943 | (flags && | |
11944 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 11945 | goto nla_put_failure; |
026331c4 | 11946 | |
3b7b72ee | 11947 | genlmsg_end(msg, hdr); |
026331c4 | 11948 | |
15e47304 | 11949 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
11950 | |
11951 | nla_put_failure: | |
11952 | genlmsg_cancel(msg, hdr); | |
11953 | nlmsg_free(msg); | |
11954 | return -ENOBUFS; | |
11955 | } | |
11956 | ||
947add36 JB |
11957 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
11958 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 11959 | { |
947add36 | 11960 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11961 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 11962 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11963 | struct sk_buff *msg; |
11964 | void *hdr; | |
11965 | ||
947add36 JB |
11966 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
11967 | ||
026331c4 JM |
11968 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11969 | if (!msg) | |
11970 | return; | |
11971 | ||
2e161f78 | 11972 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
11973 | if (!hdr) { |
11974 | nlmsg_free(msg); | |
11975 | return; | |
11976 | } | |
11977 | ||
9360ffd1 | 11978 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11979 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11980 | netdev->ifindex)) || | |
a838490b | 11981 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11982 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11983 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
11984 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
11985 | goto nla_put_failure; | |
026331c4 | 11986 | |
3b7b72ee | 11987 | genlmsg_end(msg, hdr); |
026331c4 | 11988 | |
68eb5503 | 11989 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11990 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
11991 | return; |
11992 | ||
11993 | nla_put_failure: | |
11994 | genlmsg_cancel(msg, hdr); | |
11995 | nlmsg_free(msg); | |
11996 | } | |
947add36 | 11997 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 11998 | |
5b97f49d JB |
11999 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
12000 | const char *mac, gfp_t gfp) | |
d6dc1a38 | 12001 | { |
947add36 | 12002 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5b97f49d JB |
12003 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
12004 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12005 | void **cb; | |
947add36 | 12006 | |
d6dc1a38 | 12007 | if (!msg) |
5b97f49d | 12008 | return NULL; |
d6dc1a38 | 12009 | |
5b97f49d JB |
12010 | cb = (void **)msg->cb; |
12011 | ||
12012 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
12013 | if (!cb[0]) { | |
d6dc1a38 | 12014 | nlmsg_free(msg); |
5b97f49d | 12015 | return NULL; |
d6dc1a38 JO |
12016 | } |
12017 | ||
9360ffd1 | 12018 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 12019 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 12020 | goto nla_put_failure; |
d6dc1a38 | 12021 | |
5b97f49d | 12022 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
d6dc1a38 JO |
12023 | goto nla_put_failure; |
12024 | ||
5b97f49d JB |
12025 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
12026 | if (!cb[1]) | |
9360ffd1 | 12027 | goto nla_put_failure; |
d6dc1a38 | 12028 | |
5b97f49d | 12029 | cb[2] = rdev; |
d6dc1a38 | 12030 | |
5b97f49d JB |
12031 | return msg; |
12032 | nla_put_failure: | |
12033 | nlmsg_free(msg); | |
12034 | return NULL; | |
12035 | } | |
12036 | ||
12037 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) | |
12038 | { | |
12039 | void **cb = (void **)msg->cb; | |
12040 | struct cfg80211_registered_device *rdev = cb[2]; | |
12041 | ||
12042 | nla_nest_end(msg, cb[1]); | |
12043 | genlmsg_end(msg, cb[0]); | |
12044 | ||
12045 | memset(msg->cb, 0, sizeof(msg->cb)); | |
d6dc1a38 | 12046 | |
68eb5503 | 12047 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12048 | NL80211_MCGRP_MLME, gfp); |
5b97f49d JB |
12049 | } |
12050 | ||
12051 | void cfg80211_cqm_rssi_notify(struct net_device *dev, | |
12052 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
12053 | gfp_t gfp) | |
12054 | { | |
12055 | struct sk_buff *msg; | |
12056 | ||
12057 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); | |
12058 | ||
98f03342 JB |
12059 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
12060 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) | |
12061 | return; | |
12062 | ||
5b97f49d JB |
12063 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
12064 | if (!msg) | |
12065 | return; | |
12066 | ||
12067 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
12068 | rssi_event)) | |
12069 | goto nla_put_failure; | |
12070 | ||
12071 | cfg80211_send_cqm(msg, gfp); | |
12072 | ||
d6dc1a38 JO |
12073 | return; |
12074 | ||
12075 | nla_put_failure: | |
d6dc1a38 JO |
12076 | nlmsg_free(msg); |
12077 | } | |
947add36 | 12078 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 12079 | |
5b97f49d JB |
12080 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
12081 | const u8 *peer, u32 num_packets, | |
12082 | u32 rate, u32 intvl, gfp_t gfp) | |
12083 | { | |
12084 | struct sk_buff *msg; | |
12085 | ||
12086 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12087 | if (!msg) | |
12088 | return; | |
12089 | ||
12090 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
12091 | goto nla_put_failure; | |
12092 | ||
12093 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
12094 | goto nla_put_failure; | |
12095 | ||
12096 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
12097 | goto nla_put_failure; | |
12098 | ||
12099 | cfg80211_send_cqm(msg, gfp); | |
12100 | return; | |
12101 | ||
12102 | nla_put_failure: | |
12103 | nlmsg_free(msg); | |
12104 | } | |
12105 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); | |
12106 | ||
12107 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, | |
12108 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
12109 | { | |
12110 | struct sk_buff *msg; | |
12111 | ||
12112 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); | |
12113 | ||
12114 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12115 | if (!msg) | |
12116 | return; | |
12117 | ||
12118 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) | |
12119 | goto nla_put_failure; | |
12120 | ||
12121 | cfg80211_send_cqm(msg, gfp); | |
12122 | return; | |
12123 | ||
12124 | nla_put_failure: | |
12125 | nlmsg_free(msg); | |
12126 | } | |
12127 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); | |
12128 | ||
98f03342 JB |
12129 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
12130 | { | |
12131 | struct sk_buff *msg; | |
12132 | ||
12133 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); | |
12134 | if (!msg) | |
12135 | return; | |
12136 | ||
12137 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) | |
12138 | goto nla_put_failure; | |
12139 | ||
12140 | cfg80211_send_cqm(msg, gfp); | |
12141 | return; | |
12142 | ||
12143 | nla_put_failure: | |
12144 | nlmsg_free(msg); | |
12145 | } | |
12146 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); | |
12147 | ||
947add36 JB |
12148 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
12149 | struct net_device *netdev, const u8 *bssid, | |
12150 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
12151 | { |
12152 | struct sk_buff *msg; | |
12153 | struct nlattr *rekey_attr; | |
12154 | void *hdr; | |
12155 | ||
58050fce | 12156 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
12157 | if (!msg) |
12158 | return; | |
12159 | ||
12160 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
12161 | if (!hdr) { | |
12162 | nlmsg_free(msg); | |
12163 | return; | |
12164 | } | |
12165 | ||
9360ffd1 DM |
12166 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12167 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12168 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
12169 | goto nla_put_failure; | |
e5497d76 JB |
12170 | |
12171 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
12172 | if (!rekey_attr) | |
12173 | goto nla_put_failure; | |
12174 | ||
9360ffd1 DM |
12175 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
12176 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
12177 | goto nla_put_failure; | |
e5497d76 JB |
12178 | |
12179 | nla_nest_end(msg, rekey_attr); | |
12180 | ||
3b7b72ee | 12181 | genlmsg_end(msg, hdr); |
e5497d76 | 12182 | |
68eb5503 | 12183 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12184 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
12185 | return; |
12186 | ||
12187 | nla_put_failure: | |
12188 | genlmsg_cancel(msg, hdr); | |
12189 | nlmsg_free(msg); | |
12190 | } | |
12191 | ||
947add36 JB |
12192 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
12193 | const u8 *replay_ctr, gfp_t gfp) | |
12194 | { | |
12195 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12196 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12197 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12198 | |
12199 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
12200 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
12201 | } | |
12202 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
12203 | ||
12204 | static void | |
12205 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
12206 | struct net_device *netdev, int index, | |
12207 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
12208 | { |
12209 | struct sk_buff *msg; | |
12210 | struct nlattr *attr; | |
12211 | void *hdr; | |
12212 | ||
58050fce | 12213 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
12214 | if (!msg) |
12215 | return; | |
12216 | ||
12217 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
12218 | if (!hdr) { | |
12219 | nlmsg_free(msg); | |
12220 | return; | |
12221 | } | |
12222 | ||
9360ffd1 DM |
12223 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12224 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
12225 | goto nla_put_failure; | |
c9df56b4 JM |
12226 | |
12227 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
12228 | if (!attr) | |
12229 | goto nla_put_failure; | |
12230 | ||
9360ffd1 DM |
12231 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
12232 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
12233 | (preauth && | |
12234 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
12235 | goto nla_put_failure; | |
c9df56b4 JM |
12236 | |
12237 | nla_nest_end(msg, attr); | |
12238 | ||
3b7b72ee | 12239 | genlmsg_end(msg, hdr); |
c9df56b4 | 12240 | |
68eb5503 | 12241 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12242 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
12243 | return; |
12244 | ||
12245 | nla_put_failure: | |
12246 | genlmsg_cancel(msg, hdr); | |
12247 | nlmsg_free(msg); | |
12248 | } | |
12249 | ||
947add36 JB |
12250 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
12251 | const u8 *bssid, bool preauth, gfp_t gfp) | |
12252 | { | |
12253 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12254 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12255 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12256 | |
12257 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
12258 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
12259 | } | |
12260 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
12261 | ||
12262 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
12263 | struct net_device *netdev, | |
12264 | struct cfg80211_chan_def *chandef, | |
f8d7552e LC |
12265 | gfp_t gfp, |
12266 | enum nl80211_commands notif, | |
12267 | u8 count) | |
5314526b TP |
12268 | { |
12269 | struct sk_buff *msg; | |
12270 | void *hdr; | |
12271 | ||
58050fce | 12272 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
12273 | if (!msg) |
12274 | return; | |
12275 | ||
f8d7552e | 12276 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
5314526b TP |
12277 | if (!hdr) { |
12278 | nlmsg_free(msg); | |
12279 | return; | |
12280 | } | |
12281 | ||
683b6d3b JB |
12282 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
12283 | goto nla_put_failure; | |
12284 | ||
12285 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 12286 | goto nla_put_failure; |
5314526b | 12287 | |
f8d7552e LC |
12288 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
12289 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) | |
12290 | goto nla_put_failure; | |
12291 | ||
5314526b TP |
12292 | genlmsg_end(msg, hdr); |
12293 | ||
68eb5503 | 12294 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12295 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
12296 | return; |
12297 | ||
12298 | nla_put_failure: | |
12299 | genlmsg_cancel(msg, hdr); | |
12300 | nlmsg_free(msg); | |
12301 | } | |
12302 | ||
947add36 JB |
12303 | void cfg80211_ch_switch_notify(struct net_device *dev, |
12304 | struct cfg80211_chan_def *chandef) | |
84f10708 | 12305 | { |
947add36 JB |
12306 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
12307 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12308 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 12309 | |
e487eaeb | 12310 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 12311 | |
e487eaeb | 12312 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 | 12313 | |
9e0e2961 | 12314 | wdev->chandef = *chandef; |
96f55f12 | 12315 | wdev->preset_chandef = *chandef; |
f8d7552e LC |
12316 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
12317 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); | |
947add36 JB |
12318 | } |
12319 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
12320 | ||
f8d7552e LC |
12321 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
12322 | struct cfg80211_chan_def *chandef, | |
12323 | u8 count) | |
12324 | { | |
12325 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12326 | struct wiphy *wiphy = wdev->wiphy; | |
12327 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
12328 | ||
12329 | trace_cfg80211_ch_switch_started_notify(dev, chandef); | |
12330 | ||
12331 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | |
12332 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); | |
12333 | } | |
12334 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | |
12335 | ||
04f39047 SW |
12336 | void |
12337 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 12338 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
12339 | enum nl80211_radar_event event, |
12340 | struct net_device *netdev, gfp_t gfp) | |
12341 | { | |
12342 | struct sk_buff *msg; | |
12343 | void *hdr; | |
12344 | ||
12345 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12346 | if (!msg) | |
12347 | return; | |
12348 | ||
12349 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
12350 | if (!hdr) { | |
12351 | nlmsg_free(msg); | |
12352 | return; | |
12353 | } | |
12354 | ||
12355 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
12356 | goto nla_put_failure; | |
12357 | ||
12358 | /* NOP and radar events don't need a netdev parameter */ | |
12359 | if (netdev) { | |
12360 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
12361 | ||
12362 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12363 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12364 | goto nla_put_failure; | |
12365 | } | |
12366 | ||
12367 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
12368 | goto nla_put_failure; | |
12369 | ||
12370 | if (nl80211_send_chandef(msg, chandef)) | |
12371 | goto nla_put_failure; | |
12372 | ||
9c90a9f6 | 12373 | genlmsg_end(msg, hdr); |
04f39047 | 12374 | |
68eb5503 | 12375 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12376 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
12377 | return; |
12378 | ||
12379 | nla_put_failure: | |
12380 | genlmsg_cancel(msg, hdr); | |
12381 | nlmsg_free(msg); | |
12382 | } | |
12383 | ||
7f6cf311 JB |
12384 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
12385 | u64 cookie, bool acked, gfp_t gfp) | |
12386 | { | |
12387 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12388 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
12389 | struct sk_buff *msg; |
12390 | void *hdr; | |
7f6cf311 | 12391 | |
4ee3e063 BL |
12392 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
12393 | ||
58050fce | 12394 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 12395 | |
7f6cf311 JB |
12396 | if (!msg) |
12397 | return; | |
12398 | ||
12399 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
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, dev->ifindex) || | |
12407 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
12408 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
12409 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
12410 | goto nla_put_failure; | |
7f6cf311 | 12411 | |
9c90a9f6 | 12412 | genlmsg_end(msg, hdr); |
7f6cf311 | 12413 | |
68eb5503 | 12414 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12415 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
12416 | return; |
12417 | ||
12418 | nla_put_failure: | |
12419 | genlmsg_cancel(msg, hdr); | |
12420 | nlmsg_free(msg); | |
12421 | } | |
12422 | EXPORT_SYMBOL(cfg80211_probe_status); | |
12423 | ||
5e760230 JB |
12424 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
12425 | const u8 *frame, size_t len, | |
37c73b5f | 12426 | int freq, int sig_dbm) |
5e760230 | 12427 | { |
f26cbf40 | 12428 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
12429 | struct sk_buff *msg; |
12430 | void *hdr; | |
37c73b5f | 12431 | struct cfg80211_beacon_registration *reg; |
5e760230 | 12432 | |
4ee3e063 BL |
12433 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
12434 | ||
37c73b5f BG |
12435 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12436 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
12437 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
12438 | if (!msg) { | |
12439 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
12440 | return; | |
12441 | } | |
5e760230 | 12442 | |
37c73b5f BG |
12443 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
12444 | if (!hdr) | |
12445 | goto nla_put_failure; | |
5e760230 | 12446 | |
37c73b5f BG |
12447 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12448 | (freq && | |
12449 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
12450 | (sig_dbm && | |
12451 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
12452 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
12453 | goto nla_put_failure; | |
5e760230 | 12454 | |
37c73b5f | 12455 | genlmsg_end(msg, hdr); |
5e760230 | 12456 | |
37c73b5f BG |
12457 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
12458 | } | |
12459 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
12460 | return; |
12461 | ||
12462 | nla_put_failure: | |
37c73b5f BG |
12463 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
12464 | if (hdr) | |
12465 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
12466 | nlmsg_free(msg); |
12467 | } | |
12468 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
12469 | ||
cd8f7cb4 | 12470 | #ifdef CONFIG_PM |
8cd4d456 LC |
12471 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
12472 | struct cfg80211_wowlan_wakeup *wakeup) | |
12473 | { | |
12474 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | |
12475 | struct nlattr *nl_results, *nl_match, *nl_freqs; | |
12476 | int i, j; | |
12477 | ||
12478 | nl_results = nla_nest_start( | |
12479 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | |
12480 | if (!nl_results) | |
12481 | return -EMSGSIZE; | |
12482 | ||
12483 | for (i = 0; i < nd->n_matches; i++) { | |
12484 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | |
12485 | ||
12486 | nl_match = nla_nest_start(msg, i); | |
12487 | if (!nl_match) | |
12488 | break; | |
12489 | ||
12490 | /* The SSID attribute is optional in nl80211, but for | |
12491 | * simplicity reasons it's always present in the | |
12492 | * cfg80211 structure. If a driver can't pass the | |
12493 | * SSID, that needs to be changed. A zero length SSID | |
12494 | * is still a valid SSID (wildcard), so it cannot be | |
12495 | * used for this purpose. | |
12496 | */ | |
12497 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | |
12498 | match->ssid.ssid)) { | |
12499 | nla_nest_cancel(msg, nl_match); | |
12500 | goto out; | |
12501 | } | |
12502 | ||
12503 | if (match->n_channels) { | |
12504 | nl_freqs = nla_nest_start( | |
12505 | msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
12506 | if (!nl_freqs) { | |
12507 | nla_nest_cancel(msg, nl_match); | |
12508 | goto out; | |
12509 | } | |
12510 | ||
12511 | for (j = 0; j < match->n_channels; j++) { | |
12512 | if (nla_put_u32(msg, | |
12513 | NL80211_ATTR_WIPHY_FREQ, | |
12514 | match->channels[j])) { | |
12515 | nla_nest_cancel(msg, nl_freqs); | |
12516 | nla_nest_cancel(msg, nl_match); | |
12517 | goto out; | |
12518 | } | |
12519 | } | |
12520 | ||
12521 | nla_nest_end(msg, nl_freqs); | |
12522 | } | |
12523 | ||
12524 | nla_nest_end(msg, nl_match); | |
12525 | } | |
12526 | ||
12527 | out: | |
12528 | nla_nest_end(msg, nl_results); | |
12529 | return 0; | |
12530 | } | |
12531 | ||
cd8f7cb4 JB |
12532 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
12533 | struct cfg80211_wowlan_wakeup *wakeup, | |
12534 | gfp_t gfp) | |
12535 | { | |
f26cbf40 | 12536 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
12537 | struct sk_buff *msg; |
12538 | void *hdr; | |
9c90a9f6 | 12539 | int size = 200; |
cd8f7cb4 JB |
12540 | |
12541 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
12542 | ||
12543 | if (wakeup) | |
12544 | size += wakeup->packet_present_len; | |
12545 | ||
12546 | msg = nlmsg_new(size, gfp); | |
12547 | if (!msg) | |
12548 | return; | |
12549 | ||
12550 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
12551 | if (!hdr) | |
12552 | goto free_msg; | |
12553 | ||
12554 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12555 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12556 | goto free_msg; | |
12557 | ||
12558 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
12559 | wdev->netdev->ifindex)) | |
12560 | goto free_msg; | |
12561 | ||
12562 | if (wakeup) { | |
12563 | struct nlattr *reasons; | |
12564 | ||
12565 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
12566 | if (!reasons) |
12567 | goto free_msg; | |
cd8f7cb4 JB |
12568 | |
12569 | if (wakeup->disconnect && | |
12570 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
12571 | goto free_msg; | |
12572 | if (wakeup->magic_pkt && | |
12573 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
12574 | goto free_msg; | |
12575 | if (wakeup->gtk_rekey_failure && | |
12576 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
12577 | goto free_msg; | |
12578 | if (wakeup->eap_identity_req && | |
12579 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
12580 | goto free_msg; | |
12581 | if (wakeup->four_way_handshake && | |
12582 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
12583 | goto free_msg; | |
12584 | if (wakeup->rfkill_release && | |
12585 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
12586 | goto free_msg; | |
12587 | ||
12588 | if (wakeup->pattern_idx >= 0 && | |
12589 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
12590 | wakeup->pattern_idx)) | |
12591 | goto free_msg; | |
12592 | ||
ae917c9f JB |
12593 | if (wakeup->tcp_match && |
12594 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
12595 | goto free_msg; | |
2a0e047e | 12596 | |
ae917c9f JB |
12597 | if (wakeup->tcp_connlost && |
12598 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
12599 | goto free_msg; | |
2a0e047e | 12600 | |
ae917c9f JB |
12601 | if (wakeup->tcp_nomoretokens && |
12602 | nla_put_flag(msg, | |
12603 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
12604 | goto free_msg; | |
2a0e047e | 12605 | |
cd8f7cb4 JB |
12606 | if (wakeup->packet) { |
12607 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
12608 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
12609 | ||
12610 | if (!wakeup->packet_80211) { | |
12611 | pkt_attr = | |
12612 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
12613 | len_attr = | |
12614 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
12615 | } | |
12616 | ||
12617 | if (wakeup->packet_len && | |
12618 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
12619 | goto free_msg; | |
12620 | ||
12621 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
12622 | wakeup->packet)) | |
12623 | goto free_msg; | |
12624 | } | |
12625 | ||
8cd4d456 LC |
12626 | if (wakeup->net_detect && |
12627 | cfg80211_net_detect_results(msg, wakeup)) | |
12628 | goto free_msg; | |
12629 | ||
cd8f7cb4 JB |
12630 | nla_nest_end(msg, reasons); |
12631 | } | |
12632 | ||
9c90a9f6 | 12633 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 12634 | |
68eb5503 | 12635 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12636 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
12637 | return; |
12638 | ||
12639 | free_msg: | |
12640 | nlmsg_free(msg); | |
12641 | } | |
12642 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
12643 | #endif | |
12644 | ||
3475b094 JM |
12645 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
12646 | enum nl80211_tdls_operation oper, | |
12647 | u16 reason_code, gfp_t gfp) | |
12648 | { | |
12649 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12650 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
12651 | struct sk_buff *msg; |
12652 | void *hdr; | |
3475b094 JM |
12653 | |
12654 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
12655 | reason_code); | |
12656 | ||
12657 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12658 | if (!msg) | |
12659 | return; | |
12660 | ||
12661 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
12662 | if (!hdr) { | |
12663 | nlmsg_free(msg); | |
12664 | return; | |
12665 | } | |
12666 | ||
12667 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12668 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12669 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
12670 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
12671 | (reason_code > 0 && | |
12672 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
12673 | goto nla_put_failure; | |
12674 | ||
9c90a9f6 | 12675 | genlmsg_end(msg, hdr); |
3475b094 | 12676 | |
68eb5503 | 12677 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12678 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
12679 | return; |
12680 | ||
12681 | nla_put_failure: | |
12682 | genlmsg_cancel(msg, hdr); | |
12683 | nlmsg_free(msg); | |
12684 | } | |
12685 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
12686 | ||
026331c4 JM |
12687 | static int nl80211_netlink_notify(struct notifier_block * nb, |
12688 | unsigned long state, | |
12689 | void *_notify) | |
12690 | { | |
12691 | struct netlink_notify *notify = _notify; | |
12692 | struct cfg80211_registered_device *rdev; | |
12693 | struct wireless_dev *wdev; | |
37c73b5f | 12694 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
12695 | |
12696 | if (state != NETLINK_URELEASE) | |
12697 | return NOTIFY_DONE; | |
12698 | ||
12699 | rcu_read_lock(); | |
12700 | ||
5e760230 | 12701 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
78f22b6a | 12702 | bool schedule_destroy_work = false; |
93a1e86c JR |
12703 | bool schedule_scan_stop = false; |
12704 | struct cfg80211_sched_scan_request *sched_scan_req = | |
12705 | rcu_dereference(rdev->sched_scan_req); | |
12706 | ||
12707 | if (sched_scan_req && notify->portid && | |
12708 | sched_scan_req->owner_nlportid == notify->portid) | |
12709 | schedule_scan_stop = true; | |
78f22b6a JB |
12710 | |
12711 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { | |
15e47304 | 12712 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 12713 | |
78f22b6a JB |
12714 | if (wdev->owner_nlportid == notify->portid) |
12715 | schedule_destroy_work = true; | |
12716 | } | |
12717 | ||
37c73b5f BG |
12718 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12719 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
12720 | list) { | |
12721 | if (reg->nlportid == notify->portid) { | |
12722 | list_del(®->list); | |
12723 | kfree(reg); | |
12724 | break; | |
12725 | } | |
12726 | } | |
12727 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
78f22b6a JB |
12728 | |
12729 | if (schedule_destroy_work) { | |
12730 | struct cfg80211_iface_destroy *destroy; | |
12731 | ||
12732 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | |
12733 | if (destroy) { | |
12734 | destroy->nlportid = notify->portid; | |
12735 | spin_lock(&rdev->destroy_list_lock); | |
12736 | list_add(&destroy->list, &rdev->destroy_list); | |
12737 | spin_unlock(&rdev->destroy_list_lock); | |
12738 | schedule_work(&rdev->destroy_work); | |
12739 | } | |
93a1e86c JR |
12740 | } else if (schedule_scan_stop) { |
12741 | sched_scan_req->owner_nlportid = 0; | |
12742 | ||
12743 | if (rdev->ops->sched_scan_stop && | |
12744 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
12745 | schedule_work(&rdev->sched_scan_stop_wk); | |
78f22b6a | 12746 | } |
5e760230 | 12747 | } |
026331c4 JM |
12748 | |
12749 | rcu_read_unlock(); | |
12750 | ||
6784c7db | 12751 | return NOTIFY_OK; |
026331c4 JM |
12752 | } |
12753 | ||
12754 | static struct notifier_block nl80211_netlink_notifier = { | |
12755 | .notifier_call = nl80211_netlink_notify, | |
12756 | }; | |
12757 | ||
355199e0 JM |
12758 | void cfg80211_ft_event(struct net_device *netdev, |
12759 | struct cfg80211_ft_event_params *ft_event) | |
12760 | { | |
12761 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 12762 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
12763 | struct sk_buff *msg; |
12764 | void *hdr; | |
355199e0 JM |
12765 | |
12766 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
12767 | ||
12768 | if (!ft_event->target_ap) | |
12769 | return; | |
12770 | ||
12771 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12772 | if (!msg) | |
12773 | return; | |
12774 | ||
12775 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
12776 | if (!hdr) |
12777 | goto out; | |
355199e0 | 12778 | |
ae917c9f JB |
12779 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12780 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12781 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
12782 | goto out; | |
355199e0 | 12783 | |
ae917c9f JB |
12784 | if (ft_event->ies && |
12785 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
12786 | goto out; | |
12787 | if (ft_event->ric_ies && | |
12788 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
12789 | ft_event->ric_ies)) | |
12790 | goto out; | |
355199e0 | 12791 | |
9c90a9f6 | 12792 | genlmsg_end(msg, hdr); |
355199e0 | 12793 | |
68eb5503 | 12794 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12795 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
12796 | return; |
12797 | out: | |
12798 | nlmsg_free(msg); | |
355199e0 JM |
12799 | } |
12800 | EXPORT_SYMBOL(cfg80211_ft_event); | |
12801 | ||
5de17984 AS |
12802 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
12803 | { | |
12804 | struct cfg80211_registered_device *rdev; | |
12805 | struct sk_buff *msg; | |
12806 | void *hdr; | |
12807 | u32 nlportid; | |
12808 | ||
f26cbf40 | 12809 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
12810 | if (!rdev->crit_proto_nlportid) |
12811 | return; | |
12812 | ||
12813 | nlportid = rdev->crit_proto_nlportid; | |
12814 | rdev->crit_proto_nlportid = 0; | |
12815 | ||
12816 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12817 | if (!msg) | |
12818 | return; | |
12819 | ||
12820 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
12821 | if (!hdr) | |
12822 | goto nla_put_failure; | |
12823 | ||
12824 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12825 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12826 | goto nla_put_failure; | |
12827 | ||
12828 | genlmsg_end(msg, hdr); | |
12829 | ||
12830 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
12831 | return; | |
12832 | ||
12833 | nla_put_failure: | |
12834 | if (hdr) | |
12835 | genlmsg_cancel(msg, hdr); | |
12836 | nlmsg_free(msg); | |
12837 | ||
12838 | } | |
12839 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
12840 | ||
348baf0e JB |
12841 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
12842 | { | |
12843 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12844 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
12845 | struct sk_buff *msg; |
12846 | void *hdr; | |
12847 | ||
12848 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12849 | if (!msg) | |
12850 | return; | |
12851 | ||
12852 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
12853 | if (!hdr) | |
12854 | goto out; | |
12855 | ||
12856 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12857 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
12858 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12859 | goto out; | |
12860 | ||
12861 | genlmsg_end(msg, hdr); | |
12862 | ||
12863 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
12864 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
12865 | return; | |
12866 | out: | |
12867 | nlmsg_free(msg); | |
12868 | } | |
12869 | ||
55682965 JB |
12870 | /* initialisation/exit functions */ |
12871 | ||
12872 | int nl80211_init(void) | |
12873 | { | |
0d63cbb5 | 12874 | int err; |
55682965 | 12875 | |
2a94fe48 JB |
12876 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
12877 | nl80211_mcgrps); | |
55682965 JB |
12878 | if (err) |
12879 | return err; | |
12880 | ||
026331c4 JM |
12881 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
12882 | if (err) | |
12883 | goto err_out; | |
12884 | ||
55682965 JB |
12885 | return 0; |
12886 | err_out: | |
12887 | genl_unregister_family(&nl80211_fam); | |
12888 | return err; | |
12889 | } | |
12890 | ||
12891 | void nl80211_exit(void) | |
12892 | { | |
026331c4 | 12893 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
12894 | genl_unregister_family(&nl80211_fam); |
12895 | } |