]>
Commit | Line | Data |
---|---|---|
55682965 JB |
1 | /* |
2 | * This is the new netlink-based wireless configuration interface. | |
3 | * | |
026331c4 | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
2740f0cf | 5 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
55682965 JB |
6 | */ |
7 | ||
8 | #include <linux/if.h> | |
9 | #include <linux/module.h> | |
10 | #include <linux/err.h> | |
5a0e3ad6 | 11 | #include <linux/slab.h> |
55682965 JB |
12 | #include <linux/list.h> |
13 | #include <linux/if_ether.h> | |
14 | #include <linux/ieee80211.h> | |
15 | #include <linux/nl80211.h> | |
16 | #include <linux/rtnetlink.h> | |
17 | #include <linux/netlink.h> | |
2a519311 | 18 | #include <linux/etherdevice.h> |
463d0183 | 19 | #include <net/net_namespace.h> |
55682965 JB |
20 | #include <net/genetlink.h> |
21 | #include <net/cfg80211.h> | |
463d0183 | 22 | #include <net/sock.h> |
2a0e047e | 23 | #include <net/inet_connection_sock.h> |
55682965 JB |
24 | #include "core.h" |
25 | #include "nl80211.h" | |
b2e1b302 | 26 | #include "reg.h" |
e35e4d28 | 27 | #include "rdev-ops.h" |
55682965 | 28 | |
5fb628e9 JM |
29 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
30 | struct genl_info *info, | |
31 | struct cfg80211_crypto_settings *settings, | |
32 | int cipher_limit); | |
33 | ||
f84f771d | 34 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 | 35 | struct genl_info *info); |
f84f771d | 36 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
37 | struct genl_info *info); |
38 | ||
55682965 JB |
39 | /* the netlink family */ |
40 | static struct genl_family nl80211_fam = { | |
fb4e1568 MH |
41 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
42 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ | |
43 | .hdrsize = 0, /* no private header */ | |
44 | .version = 1, /* no particular meaning now */ | |
55682965 | 45 | .maxattr = NL80211_ATTR_MAX, |
463d0183 | 46 | .netnsok = true, |
4c476991 JB |
47 | .pre_doit = nl80211_pre_doit, |
48 | .post_doit = nl80211_post_doit, | |
55682965 JB |
49 | }; |
50 | ||
2a94fe48 JB |
51 | /* multicast groups */ |
52 | enum nl80211_multicast_groups { | |
53 | NL80211_MCGRP_CONFIG, | |
54 | NL80211_MCGRP_SCAN, | |
55 | NL80211_MCGRP_REGULATORY, | |
56 | NL80211_MCGRP_MLME, | |
567ffc35 | 57 | NL80211_MCGRP_VENDOR, |
2a94fe48 JB |
58 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
59 | }; | |
60 | ||
61 | static const struct genl_multicast_group nl80211_mcgrps[] = { | |
71b836ec JB |
62 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
63 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, | |
64 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, | |
65 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, | |
66 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, | |
2a94fe48 | 67 | #ifdef CONFIG_NL80211_TESTMODE |
71b836ec | 68 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
2a94fe48 JB |
69 | #endif |
70 | }; | |
71 | ||
89a54e48 JB |
72 | /* returns ERR_PTR values */ |
73 | static struct wireless_dev * | |
74 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 75 | { |
89a54e48 JB |
76 | struct cfg80211_registered_device *rdev; |
77 | struct wireless_dev *result = NULL; | |
78 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
79 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
80 | u64 wdev_id; | |
81 | int wiphy_idx = -1; | |
82 | int ifidx = -1; | |
55682965 | 83 | |
5fe231e8 | 84 | ASSERT_RTNL(); |
55682965 | 85 | |
89a54e48 JB |
86 | if (!have_ifidx && !have_wdev_id) |
87 | return ERR_PTR(-EINVAL); | |
55682965 | 88 | |
89a54e48 JB |
89 | if (have_ifidx) |
90 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
91 | if (have_wdev_id) { | |
92 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
93 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
94 | } |
95 | ||
89a54e48 JB |
96 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
97 | struct wireless_dev *wdev; | |
98 | ||
99 | if (wiphy_net(&rdev->wiphy) != netns) | |
100 | continue; | |
101 | ||
102 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
103 | continue; | |
104 | ||
89a54e48 JB |
105 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
106 | if (have_ifidx && wdev->netdev && | |
107 | wdev->netdev->ifindex == ifidx) { | |
108 | result = wdev; | |
109 | break; | |
110 | } | |
111 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
112 | result = wdev; | |
113 | break; | |
114 | } | |
115 | } | |
89a54e48 JB |
116 | |
117 | if (result) | |
118 | break; | |
119 | } | |
120 | ||
121 | if (result) | |
122 | return result; | |
123 | return ERR_PTR(-ENODEV); | |
55682965 JB |
124 | } |
125 | ||
a9455408 | 126 | static struct cfg80211_registered_device * |
878d9ec7 | 127 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 128 | { |
7fee4778 JB |
129 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
130 | struct net_device *netdev; | |
a9455408 | 131 | |
5fe231e8 | 132 | ASSERT_RTNL(); |
a9455408 | 133 | |
878d9ec7 | 134 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
135 | !attrs[NL80211_ATTR_IFINDEX] && |
136 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
137 | return ERR_PTR(-EINVAL); |
138 | ||
878d9ec7 | 139 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 140 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 141 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 142 | |
89a54e48 JB |
143 | if (attrs[NL80211_ATTR_WDEV]) { |
144 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
145 | struct wireless_dev *wdev; | |
146 | bool found = false; | |
147 | ||
148 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
149 | if (tmp) { | |
150 | /* make sure wdev exists */ | |
89a54e48 JB |
151 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
152 | if (wdev->identifier != (u32)wdev_id) | |
153 | continue; | |
154 | found = true; | |
155 | break; | |
156 | } | |
89a54e48 JB |
157 | |
158 | if (!found) | |
159 | tmp = NULL; | |
160 | ||
161 | if (rdev && tmp != rdev) | |
162 | return ERR_PTR(-EINVAL); | |
163 | rdev = tmp; | |
164 | } | |
165 | } | |
166 | ||
878d9ec7 JB |
167 | if (attrs[NL80211_ATTR_IFINDEX]) { |
168 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
7f2b8562 | 169 | netdev = __dev_get_by_index(netns, ifindex); |
7fee4778 JB |
170 | if (netdev) { |
171 | if (netdev->ieee80211_ptr) | |
f26cbf40 ZG |
172 | tmp = wiphy_to_rdev( |
173 | netdev->ieee80211_ptr->wiphy); | |
7fee4778 JB |
174 | else |
175 | tmp = NULL; | |
176 | ||
7fee4778 JB |
177 | /* not wireless device -- return error */ |
178 | if (!tmp) | |
179 | return ERR_PTR(-EINVAL); | |
180 | ||
181 | /* mismatch -- return error */ | |
182 | if (rdev && tmp != rdev) | |
183 | return ERR_PTR(-EINVAL); | |
184 | ||
185 | rdev = tmp; | |
a9455408 | 186 | } |
a9455408 | 187 | } |
a9455408 | 188 | |
4f7eff10 JB |
189 | if (!rdev) |
190 | return ERR_PTR(-ENODEV); | |
a9455408 | 191 | |
4f7eff10 JB |
192 | if (netns != wiphy_net(&rdev->wiphy)) |
193 | return ERR_PTR(-ENODEV); | |
194 | ||
195 | return rdev; | |
a9455408 JB |
196 | } |
197 | ||
198 | /* | |
199 | * This function returns a pointer to the driver | |
200 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
201 | * |
202 | * The result of this can be a PTR_ERR and hence must | |
203 | * be checked with IS_ERR() for errors. | |
204 | */ | |
205 | static struct cfg80211_registered_device * | |
4f7eff10 | 206 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 207 | { |
5fe231e8 | 208 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
209 | } |
210 | ||
55682965 | 211 | /* policy for the attributes */ |
8cd4d456 | 212 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
55682965 JB |
213 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
214 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 215 | .len = 20-1 }, |
31888487 | 216 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 217 | |
72bdcf34 | 218 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 219 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
220 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
221 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
222 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
223 | ||
b9a5f8ca JM |
224 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
225 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
226 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
227 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 228 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
3057dbfd | 229 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
55682965 JB |
230 | |
231 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
232 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
233 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 234 | |
e007b857 EP |
235 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
236 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 237 | |
b9454e83 | 238 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
239 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
240 | .len = WLAN_MAX_KEY_LEN }, | |
241 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
242 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
243 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 244 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 245 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
246 | |
247 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
248 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
249 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
250 | .len = IEEE80211_MAX_DATA_LEN }, | |
251 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
252 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
253 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
254 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
255 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
256 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
257 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 258 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 259 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 260 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 261 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 262 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 263 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 264 | |
b2e1b302 LR |
265 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
266 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
267 | ||
9f1ba906 JM |
268 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
269 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
270 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
271 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
272 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 273 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 274 | |
24bdd9f4 | 275 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 276 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 277 | |
6c739419 | 278 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
279 | |
280 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
281 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
282 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
283 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
284 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
285 | |
286 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
287 | .len = IEEE80211_MAX_SSID_LEN }, | |
288 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
289 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 290 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 291 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 292 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
293 | [NL80211_ATTR_STA_FLAGS2] = { |
294 | .len = sizeof(struct nl80211_sta_flag_update), | |
295 | }, | |
3f77316c | 296 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
297 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
298 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
299 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
300 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
301 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 302 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 303 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
304 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
305 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
306 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
307 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 308 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
309 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
310 | .len = IEEE80211_MAX_DATA_LEN }, | |
311 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 312 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 313 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 314 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 315 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
316 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
317 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 318 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
319 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
320 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 321 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 322 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 323 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 324 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 325 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 326 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 327 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 328 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 329 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
330 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
331 | .len = IEEE80211_MAX_DATA_LEN }, | |
332 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
333 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 334 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 335 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 336 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
337 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
338 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
339 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
340 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
341 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
31fa97c5 | 342 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
e247bd90 | 343 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
344 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
345 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 346 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
347 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
348 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
349 | .len = NL80211_HT_CAPABILITY_LEN | |
350 | }, | |
1d9d9213 | 351 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 352 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 353 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 354 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 355 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
e39e5b5e | 356 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
f461be3e | 357 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
ed473771 | 358 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
53cabad7 JB |
359 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
360 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | |
77765eaf VT |
361 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
362 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
363 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
364 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 365 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
366 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
367 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
368 | .len = NL80211_VHT_CAPABILITY_LEN, | |
369 | }, | |
355199e0 JM |
370 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
371 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
372 | .len = IEEE80211_MAX_DATA_LEN }, | |
5e4b6f56 | 373 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
16ef1fe2 SW |
374 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
375 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | |
376 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | |
9a774c78 AO |
377 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
378 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, | |
c01fc9ad SD |
379 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
380 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, | |
5336fa88 | 381 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
60f4a7b1 | 382 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
ad7e718c JB |
383 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
384 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, | |
385 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, | |
fa9ffc74 KP |
386 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
387 | .len = IEEE80211_QOS_MAP_LEN_MAX }, | |
1df4a510 JM |
388 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
389 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, | |
df942e7b | 390 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
18e5ca65 | 391 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
34d22ce2 | 392 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
bab5ab7d | 393 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
960d01ac JB |
394 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
395 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, | |
396 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, | |
18998c38 | 397 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
ad2b26ab | 398 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
1bdd716c | 399 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
4b681c82 | 400 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
9c748934 | 401 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
55682965 JB |
402 | }; |
403 | ||
e31b8213 | 404 | /* policy for the key attributes */ |
b54452b0 | 405 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 406 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
407 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
408 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 409 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
410 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
411 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 412 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
413 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
414 | }; | |
415 | ||
416 | /* policy for the key default flags */ | |
417 | static const struct nla_policy | |
418 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
419 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
420 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
421 | }; |
422 | ||
ff1b6e69 JB |
423 | /* policy for WoWLAN attributes */ |
424 | static const struct nla_policy | |
425 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
426 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
427 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
428 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
429 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
430 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
431 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
432 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
433 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e | 434 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
8cd4d456 | 435 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
2a0e047e JB |
436 | }; |
437 | ||
438 | static const struct nla_policy | |
439 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
440 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
441 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
442 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
443 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
444 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
445 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
446 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
447 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
448 | }, | |
449 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
450 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
451 | }, | |
452 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
453 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
454 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
455 | }; |
456 | ||
be29b99a AK |
457 | /* policy for coalesce rule attributes */ |
458 | static const struct nla_policy | |
459 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
460 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
461 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
462 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
463 | }; | |
464 | ||
e5497d76 JB |
465 | /* policy for GTK rekey offload attributes */ |
466 | static const struct nla_policy | |
467 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
468 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
469 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
470 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
471 | }; | |
472 | ||
a1f1c21c LC |
473 | static const struct nla_policy |
474 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 475 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 476 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 477 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
478 | }; |
479 | ||
97990a06 JB |
480 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
481 | struct netlink_callback *cb, | |
482 | struct cfg80211_registered_device **rdev, | |
483 | struct wireless_dev **wdev) | |
a043897a | 484 | { |
97990a06 | 485 | int err; |
a043897a | 486 | |
97990a06 | 487 | rtnl_lock(); |
a043897a | 488 | |
97990a06 JB |
489 | if (!cb->args[0]) { |
490 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
491 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
492 | nl80211_policy); | |
493 | if (err) | |
494 | goto out_unlock; | |
67748893 | 495 | |
97990a06 JB |
496 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
497 | nl80211_fam.attrbuf); | |
498 | if (IS_ERR(*wdev)) { | |
499 | err = PTR_ERR(*wdev); | |
500 | goto out_unlock; | |
501 | } | |
f26cbf40 | 502 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
503 | /* 0 is the first index - add 1 to parse only once */ |
504 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
505 | cb->args[1] = (*wdev)->identifier; |
506 | } else { | |
c319d50b JB |
507 | /* subtract the 1 again here */ |
508 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 509 | struct wireless_dev *tmp; |
67748893 | 510 | |
97990a06 JB |
511 | if (!wiphy) { |
512 | err = -ENODEV; | |
513 | goto out_unlock; | |
514 | } | |
f26cbf40 | 515 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 516 | *wdev = NULL; |
67748893 | 517 | |
97990a06 JB |
518 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
519 | if (tmp->identifier == cb->args[1]) { | |
520 | *wdev = tmp; | |
521 | break; | |
522 | } | |
523 | } | |
67748893 | 524 | |
97990a06 JB |
525 | if (!*wdev) { |
526 | err = -ENODEV; | |
527 | goto out_unlock; | |
528 | } | |
67748893 JB |
529 | } |
530 | ||
67748893 | 531 | return 0; |
97990a06 | 532 | out_unlock: |
67748893 JB |
533 | rtnl_unlock(); |
534 | return err; | |
535 | } | |
536 | ||
97990a06 | 537 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 538 | { |
67748893 JB |
539 | rtnl_unlock(); |
540 | } | |
541 | ||
f4a11bb0 JB |
542 | /* IE validation */ |
543 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
544 | { | |
545 | const u8 *pos; | |
546 | int len; | |
547 | ||
548 | if (!attr) | |
549 | return true; | |
550 | ||
551 | pos = nla_data(attr); | |
552 | len = nla_len(attr); | |
553 | ||
554 | while (len) { | |
555 | u8 elemlen; | |
556 | ||
557 | if (len < 2) | |
558 | return false; | |
559 | len -= 2; | |
560 | ||
561 | elemlen = pos[1]; | |
562 | if (elemlen > len) | |
563 | return false; | |
564 | ||
565 | len -= elemlen; | |
566 | pos += 2 + elemlen; | |
567 | } | |
568 | ||
569 | return true; | |
570 | } | |
571 | ||
55682965 | 572 | /* message building helper */ |
15e47304 | 573 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
574 | int flags, u8 cmd) |
575 | { | |
576 | /* since there is no private header just add the generic one */ | |
15e47304 | 577 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
578 | } |
579 | ||
5dab3b8a | 580 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
581 | struct ieee80211_channel *chan, |
582 | bool large) | |
5dab3b8a | 583 | { |
ea077c1c RL |
584 | /* Some channels must be completely excluded from the |
585 | * list to protect old user-space tools from breaking | |
586 | */ | |
587 | if (!large && chan->flags & | |
588 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
589 | return 0; | |
590 | ||
9360ffd1 DM |
591 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
592 | chan->center_freq)) | |
593 | goto nla_put_failure; | |
5dab3b8a | 594 | |
9360ffd1 DM |
595 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
596 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
597 | goto nla_put_failure; | |
8fe02e16 LR |
598 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
599 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
600 | goto nla_put_failure; | |
601 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
602 | goto nla_put_failure; | |
603 | } | |
cdc89b97 JB |
604 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
605 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
606 | goto nla_put_failure; | |
607 | if (large) { | |
608 | u32 time; | |
609 | ||
610 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
611 | ||
612 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
613 | chan->dfs_state)) | |
614 | goto nla_put_failure; | |
615 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
616 | time)) | |
617 | goto nla_put_failure; | |
089027e5 JD |
618 | if (nla_put_u32(msg, |
619 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
620 | chan->dfs_cac_ms)) | |
621 | goto nla_put_failure; | |
cdc89b97 JB |
622 | } |
623 | } | |
5dab3b8a | 624 | |
fe1abafd JB |
625 | if (large) { |
626 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
627 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
628 | goto nla_put_failure; | |
629 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
630 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
631 | goto nla_put_failure; | |
632 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
633 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
634 | goto nla_put_failure; | |
635 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
636 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
637 | goto nla_put_failure; | |
570dbde1 DS |
638 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
639 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
640 | goto nla_put_failure; | |
641 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && | |
642 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) | |
643 | goto nla_put_failure; | |
ea077c1c RL |
644 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
645 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
646 | goto nla_put_failure; | |
647 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
648 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
649 | goto nla_put_failure; | |
fe1abafd JB |
650 | } |
651 | ||
9360ffd1 DM |
652 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
653 | DBM_TO_MBM(chan->max_power))) | |
654 | goto nla_put_failure; | |
5dab3b8a LR |
655 | |
656 | return 0; | |
657 | ||
658 | nla_put_failure: | |
659 | return -ENOBUFS; | |
660 | } | |
661 | ||
55682965 JB |
662 | /* netlink command implementations */ |
663 | ||
b9454e83 JB |
664 | struct key_parse { |
665 | struct key_params p; | |
666 | int idx; | |
e31b8213 | 667 | int type; |
b9454e83 | 668 | bool def, defmgmt; |
dbd2fd65 | 669 | bool def_uni, def_multi; |
b9454e83 JB |
670 | }; |
671 | ||
672 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
673 | { | |
674 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
675 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
676 | nl80211_key_policy); | |
677 | if (err) | |
678 | return err; | |
679 | ||
680 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
681 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
682 | ||
dbd2fd65 JB |
683 | if (k->def) { |
684 | k->def_uni = true; | |
685 | k->def_multi = true; | |
686 | } | |
687 | if (k->defmgmt) | |
688 | k->def_multi = true; | |
689 | ||
b9454e83 JB |
690 | if (tb[NL80211_KEY_IDX]) |
691 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
692 | ||
693 | if (tb[NL80211_KEY_DATA]) { | |
694 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
695 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
696 | } | |
697 | ||
698 | if (tb[NL80211_KEY_SEQ]) { | |
699 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
700 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
701 | } | |
702 | ||
703 | if (tb[NL80211_KEY_CIPHER]) | |
704 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
705 | ||
e31b8213 JB |
706 | if (tb[NL80211_KEY_TYPE]) { |
707 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
708 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
709 | return -EINVAL; | |
710 | } | |
711 | ||
dbd2fd65 JB |
712 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
713 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
714 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
715 | tb[NL80211_KEY_DEFAULT_TYPES], | |
716 | nl80211_key_default_policy); | |
dbd2fd65 JB |
717 | if (err) |
718 | return err; | |
719 | ||
720 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
721 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
722 | } | |
723 | ||
b9454e83 JB |
724 | return 0; |
725 | } | |
726 | ||
727 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
728 | { | |
729 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
730 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
731 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
732 | } | |
733 | ||
734 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
735 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
736 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
737 | } | |
738 | ||
739 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
740 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
741 | ||
742 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
743 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
744 | ||
745 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
746 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
747 | ||
dbd2fd65 JB |
748 | if (k->def) { |
749 | k->def_uni = true; | |
750 | k->def_multi = true; | |
751 | } | |
752 | if (k->defmgmt) | |
753 | k->def_multi = true; | |
754 | ||
e31b8213 JB |
755 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
756 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
757 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
758 | return -EINVAL; | |
759 | } | |
760 | ||
dbd2fd65 JB |
761 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
762 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
763 | int err = nla_parse_nested( | |
764 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
765 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
766 | nl80211_key_default_policy); | |
767 | if (err) | |
768 | return err; | |
769 | ||
770 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
771 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
772 | } | |
773 | ||
b9454e83 JB |
774 | return 0; |
775 | } | |
776 | ||
777 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
778 | { | |
779 | int err; | |
780 | ||
781 | memset(k, 0, sizeof(*k)); | |
782 | k->idx = -1; | |
e31b8213 | 783 | k->type = -1; |
b9454e83 JB |
784 | |
785 | if (info->attrs[NL80211_ATTR_KEY]) | |
786 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
787 | else | |
788 | err = nl80211_parse_key_old(info, k); | |
789 | ||
790 | if (err) | |
791 | return err; | |
792 | ||
793 | if (k->def && k->defmgmt) | |
794 | return -EINVAL; | |
795 | ||
dbd2fd65 JB |
796 | if (k->defmgmt) { |
797 | if (k->def_uni || !k->def_multi) | |
798 | return -EINVAL; | |
799 | } | |
800 | ||
b9454e83 JB |
801 | if (k->idx != -1) { |
802 | if (k->defmgmt) { | |
803 | if (k->idx < 4 || k->idx > 5) | |
804 | return -EINVAL; | |
805 | } else if (k->def) { | |
806 | if (k->idx < 0 || k->idx > 3) | |
807 | return -EINVAL; | |
808 | } else { | |
809 | if (k->idx < 0 || k->idx > 5) | |
810 | return -EINVAL; | |
811 | } | |
812 | } | |
813 | ||
814 | return 0; | |
815 | } | |
816 | ||
fffd0934 JB |
817 | static struct cfg80211_cached_keys * |
818 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 819 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
820 | { |
821 | struct key_parse parse; | |
822 | struct nlattr *key; | |
823 | struct cfg80211_cached_keys *result; | |
824 | int rem, err, def = 0; | |
825 | ||
826 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
827 | if (!result) | |
828 | return ERR_PTR(-ENOMEM); | |
829 | ||
830 | result->def = -1; | |
831 | result->defmgmt = -1; | |
832 | ||
833 | nla_for_each_nested(key, keys, rem) { | |
834 | memset(&parse, 0, sizeof(parse)); | |
835 | parse.idx = -1; | |
836 | ||
837 | err = nl80211_parse_key_new(key, &parse); | |
838 | if (err) | |
839 | goto error; | |
840 | err = -EINVAL; | |
841 | if (!parse.p.key) | |
842 | goto error; | |
843 | if (parse.idx < 0 || parse.idx > 4) | |
844 | goto error; | |
845 | if (parse.def) { | |
846 | if (def) | |
847 | goto error; | |
848 | def = 1; | |
849 | result->def = parse.idx; | |
dbd2fd65 JB |
850 | if (!parse.def_uni || !parse.def_multi) |
851 | goto error; | |
fffd0934 JB |
852 | } else if (parse.defmgmt) |
853 | goto error; | |
854 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 855 | parse.idx, false, NULL); |
fffd0934 JB |
856 | if (err) |
857 | goto error; | |
858 | result->params[parse.idx].cipher = parse.p.cipher; | |
859 | result->params[parse.idx].key_len = parse.p.key_len; | |
860 | result->params[parse.idx].key = result->data[parse.idx]; | |
861 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
862 | |
863 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
864 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
865 | if (no_ht) | |
866 | *no_ht = true; | |
867 | } | |
fffd0934 JB |
868 | } |
869 | ||
870 | return result; | |
871 | error: | |
872 | kfree(result); | |
873 | return ERR_PTR(err); | |
874 | } | |
875 | ||
876 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
877 | { | |
878 | ASSERT_WDEV_LOCK(wdev); | |
879 | ||
fffd0934 JB |
880 | switch (wdev->iftype) { |
881 | case NL80211_IFTYPE_AP: | |
882 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 883 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 884 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
885 | break; |
886 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 887 | case NL80211_IFTYPE_STATION: |
074ac8df | 888 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 889 | if (!wdev->current_bss) |
fffd0934 JB |
890 | return -ENOLINK; |
891 | break; | |
de4fcbad | 892 | case NL80211_IFTYPE_UNSPECIFIED: |
6e0bd6c3 | 893 | case NL80211_IFTYPE_OCB: |
de4fcbad JB |
894 | case NL80211_IFTYPE_MONITOR: |
895 | case NL80211_IFTYPE_P2P_DEVICE: | |
896 | case NL80211_IFTYPE_WDS: | |
897 | case NUM_NL80211_IFTYPES: | |
fffd0934 JB |
898 | return -EINVAL; |
899 | } | |
900 | ||
901 | return 0; | |
902 | } | |
903 | ||
664834de JM |
904 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
905 | struct nlattr *tb) | |
906 | { | |
907 | struct ieee80211_channel *chan; | |
908 | ||
909 | if (tb == NULL) | |
910 | return NULL; | |
911 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
912 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
913 | return NULL; | |
914 | return chan; | |
915 | } | |
916 | ||
7527a782 JB |
917 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
918 | { | |
919 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
920 | int i; | |
921 | ||
922 | if (!nl_modes) | |
923 | goto nla_put_failure; | |
924 | ||
925 | i = 0; | |
926 | while (ifmodes) { | |
9360ffd1 DM |
927 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
928 | goto nla_put_failure; | |
7527a782 JB |
929 | ifmodes >>= 1; |
930 | i++; | |
931 | } | |
932 | ||
933 | nla_nest_end(msg, nl_modes); | |
934 | return 0; | |
935 | ||
936 | nla_put_failure: | |
937 | return -ENOBUFS; | |
938 | } | |
939 | ||
940 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
941 | struct sk_buff *msg, |
942 | bool large) | |
7527a782 JB |
943 | { |
944 | struct nlattr *nl_combis; | |
945 | int i, j; | |
946 | ||
947 | nl_combis = nla_nest_start(msg, | |
948 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
949 | if (!nl_combis) | |
950 | goto nla_put_failure; | |
951 | ||
952 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
953 | const struct ieee80211_iface_combination *c; | |
954 | struct nlattr *nl_combi, *nl_limits; | |
955 | ||
956 | c = &wiphy->iface_combinations[i]; | |
957 | ||
958 | nl_combi = nla_nest_start(msg, i + 1); | |
959 | if (!nl_combi) | |
960 | goto nla_put_failure; | |
961 | ||
962 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
963 | if (!nl_limits) | |
964 | goto nla_put_failure; | |
965 | ||
966 | for (j = 0; j < c->n_limits; j++) { | |
967 | struct nlattr *nl_limit; | |
968 | ||
969 | nl_limit = nla_nest_start(msg, j + 1); | |
970 | if (!nl_limit) | |
971 | goto nla_put_failure; | |
9360ffd1 DM |
972 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
973 | c->limits[j].max)) | |
974 | goto nla_put_failure; | |
7527a782 JB |
975 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
976 | c->limits[j].types)) | |
977 | goto nla_put_failure; | |
978 | nla_nest_end(msg, nl_limit); | |
979 | } | |
980 | ||
981 | nla_nest_end(msg, nl_limits); | |
982 | ||
9360ffd1 DM |
983 | if (c->beacon_int_infra_match && |
984 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
985 | goto nla_put_failure; | |
986 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
987 | c->num_different_channels) || | |
988 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
989 | c->max_interfaces)) | |
990 | goto nla_put_failure; | |
cdc89b97 | 991 | if (large && |
8c48b50a FF |
992 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
993 | c->radar_detect_widths) || | |
994 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
995 | c->radar_detect_regions))) | |
cdc89b97 | 996 | goto nla_put_failure; |
7527a782 JB |
997 | |
998 | nla_nest_end(msg, nl_combi); | |
999 | } | |
1000 | ||
1001 | nla_nest_end(msg, nl_combis); | |
1002 | ||
1003 | return 0; | |
1004 | nla_put_failure: | |
1005 | return -ENOBUFS; | |
1006 | } | |
1007 | ||
3713b4e3 | 1008 | #ifdef CONFIG_PM |
b56cf720 JB |
1009 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
1010 | struct sk_buff *msg) | |
1011 | { | |
964dc9e2 | 1012 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
1013 | struct nlattr *nl_tcp; |
1014 | ||
1015 | if (!tcp) | |
1016 | return 0; | |
1017 | ||
1018 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
1019 | if (!nl_tcp) | |
1020 | return -ENOBUFS; | |
1021 | ||
1022 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1023 | tcp->data_payload_max)) | |
1024 | return -ENOBUFS; | |
1025 | ||
1026 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1027 | tcp->data_payload_max)) | |
1028 | return -ENOBUFS; | |
1029 | ||
1030 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1031 | return -ENOBUFS; | |
1032 | ||
1033 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1034 | sizeof(*tcp->tok), tcp->tok)) | |
1035 | return -ENOBUFS; | |
1036 | ||
1037 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1038 | tcp->data_interval_max)) | |
1039 | return -ENOBUFS; | |
1040 | ||
1041 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1042 | tcp->wake_payload_max)) | |
1043 | return -ENOBUFS; | |
1044 | ||
1045 | nla_nest_end(msg, nl_tcp); | |
1046 | return 0; | |
1047 | } | |
1048 | ||
3713b4e3 | 1049 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1050 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1051 | bool large) |
55682965 | 1052 | { |
3713b4e3 | 1053 | struct nlattr *nl_wowlan; |
55682965 | 1054 | |
1b8ec87a | 1055 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1056 | return 0; |
55682965 | 1057 | |
3713b4e3 JB |
1058 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1059 | if (!nl_wowlan) | |
1060 | return -ENOBUFS; | |
9360ffd1 | 1061 | |
1b8ec87a | 1062 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1063 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1064 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1065 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1066 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1067 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1068 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1069 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1070 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1071 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1072 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1073 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1074 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1075 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1076 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1077 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1078 | return -ENOBUFS; | |
9360ffd1 | 1079 | |
1b8ec87a | 1080 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1081 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1082 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1083 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1084 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1085 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1086 | }; |
9360ffd1 | 1087 | |
3713b4e3 JB |
1088 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1089 | sizeof(pat), &pat)) | |
1090 | return -ENOBUFS; | |
1091 | } | |
9360ffd1 | 1092 | |
75453ccb LC |
1093 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
1094 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, | |
1095 | rdev->wiphy.wowlan->max_nd_match_sets)) | |
1096 | return -ENOBUFS; | |
1097 | ||
1b8ec87a | 1098 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1099 | return -ENOBUFS; |
1100 | ||
8cd4d456 LC |
1101 | /* TODO: send wowlan net detect */ |
1102 | ||
3713b4e3 | 1103 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1104 | |
3713b4e3 JB |
1105 | return 0; |
1106 | } | |
1107 | #endif | |
9360ffd1 | 1108 | |
be29b99a | 1109 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1110 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1111 | { |
1112 | struct nl80211_coalesce_rule_support rule; | |
1113 | ||
1b8ec87a | 1114 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1115 | return 0; |
1116 | ||
1b8ec87a ZG |
1117 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1118 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1119 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1120 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1121 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1122 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1123 | |
1124 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1125 | return -ENOBUFS; | |
1126 | ||
1127 | return 0; | |
1128 | } | |
1129 | ||
3713b4e3 JB |
1130 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1131 | struct ieee80211_supported_band *sband) | |
1132 | { | |
1133 | struct nlattr *nl_rates, *nl_rate; | |
1134 | struct ieee80211_rate *rate; | |
1135 | int i; | |
87bbbe22 | 1136 | |
3713b4e3 JB |
1137 | /* add HT info */ |
1138 | if (sband->ht_cap.ht_supported && | |
1139 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1140 | sizeof(sband->ht_cap.mcs), | |
1141 | &sband->ht_cap.mcs) || | |
1142 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1143 | sband->ht_cap.cap) || | |
1144 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1145 | sband->ht_cap.ampdu_factor) || | |
1146 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1147 | sband->ht_cap.ampdu_density))) | |
1148 | return -ENOBUFS; | |
afe0cbf8 | 1149 | |
3713b4e3 JB |
1150 | /* add VHT info */ |
1151 | if (sband->vht_cap.vht_supported && | |
1152 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1153 | sizeof(sband->vht_cap.vht_mcs), | |
1154 | &sband->vht_cap.vht_mcs) || | |
1155 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1156 | sband->vht_cap.cap))) | |
1157 | return -ENOBUFS; | |
f59ac048 | 1158 | |
3713b4e3 JB |
1159 | /* add bitrates */ |
1160 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1161 | if (!nl_rates) | |
1162 | return -ENOBUFS; | |
ee688b00 | 1163 | |
3713b4e3 JB |
1164 | for (i = 0; i < sband->n_bitrates; i++) { |
1165 | nl_rate = nla_nest_start(msg, i); | |
1166 | if (!nl_rate) | |
1167 | return -ENOBUFS; | |
ee688b00 | 1168 | |
3713b4e3 JB |
1169 | rate = &sband->bitrates[i]; |
1170 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1171 | rate->bitrate)) | |
1172 | return -ENOBUFS; | |
1173 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1174 | nla_put_flag(msg, | |
1175 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1176 | return -ENOBUFS; | |
ee688b00 | 1177 | |
3713b4e3 JB |
1178 | nla_nest_end(msg, nl_rate); |
1179 | } | |
d51626df | 1180 | |
3713b4e3 | 1181 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1182 | |
3713b4e3 JB |
1183 | return 0; |
1184 | } | |
ee688b00 | 1185 | |
3713b4e3 JB |
1186 | static int |
1187 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1188 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1189 | { | |
1190 | u16 stypes; | |
1191 | struct nlattr *nl_ftypes, *nl_ifs; | |
1192 | enum nl80211_iftype ift; | |
1193 | int i; | |
ee688b00 | 1194 | |
3713b4e3 JB |
1195 | if (!mgmt_stypes) |
1196 | return 0; | |
5dab3b8a | 1197 | |
3713b4e3 JB |
1198 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1199 | if (!nl_ifs) | |
1200 | return -ENOBUFS; | |
e2f367f2 | 1201 | |
3713b4e3 JB |
1202 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1203 | nl_ftypes = nla_nest_start(msg, ift); | |
1204 | if (!nl_ftypes) | |
1205 | return -ENOBUFS; | |
1206 | i = 0; | |
1207 | stypes = mgmt_stypes[ift].tx; | |
1208 | while (stypes) { | |
1209 | if ((stypes & 1) && | |
1210 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1211 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1212 | return -ENOBUFS; | |
1213 | stypes >>= 1; | |
1214 | i++; | |
ee688b00 | 1215 | } |
3713b4e3 JB |
1216 | nla_nest_end(msg, nl_ftypes); |
1217 | } | |
ee688b00 | 1218 | |
3713b4e3 | 1219 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1220 | |
3713b4e3 JB |
1221 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1222 | if (!nl_ifs) | |
1223 | return -ENOBUFS; | |
ee688b00 | 1224 | |
3713b4e3 JB |
1225 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1226 | nl_ftypes = nla_nest_start(msg, ift); | |
1227 | if (!nl_ftypes) | |
1228 | return -ENOBUFS; | |
1229 | i = 0; | |
1230 | stypes = mgmt_stypes[ift].rx; | |
1231 | while (stypes) { | |
1232 | if ((stypes & 1) && | |
1233 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1234 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1235 | return -ENOBUFS; | |
1236 | stypes >>= 1; | |
1237 | i++; | |
1238 | } | |
1239 | nla_nest_end(msg, nl_ftypes); | |
1240 | } | |
1241 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1242 | |
3713b4e3 JB |
1243 | return 0; |
1244 | } | |
ee688b00 | 1245 | |
86e8cf98 JB |
1246 | struct nl80211_dump_wiphy_state { |
1247 | s64 filter_wiphy; | |
1248 | long start; | |
1249 | long split_start, band_start, chan_start; | |
1250 | bool split; | |
1251 | }; | |
1252 | ||
1b8ec87a | 1253 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 1254 | enum nl80211_commands cmd, |
3713b4e3 | 1255 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1256 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1257 | { |
1258 | void *hdr; | |
1259 | struct nlattr *nl_bands, *nl_band; | |
1260 | struct nlattr *nl_freqs, *nl_freq; | |
1261 | struct nlattr *nl_cmds; | |
1262 | enum ieee80211_band band; | |
1263 | struct ieee80211_channel *chan; | |
1264 | int i; | |
1265 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1266 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1267 | u32 features; |
ee688b00 | 1268 | |
3bb20556 | 1269 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
1270 | if (!hdr) |
1271 | return -ENOBUFS; | |
ee688b00 | 1272 | |
86e8cf98 JB |
1273 | if (WARN_ON(!state)) |
1274 | return -EINVAL; | |
ee688b00 | 1275 | |
1b8ec87a | 1276 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1277 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1278 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1279 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1280 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1281 | goto nla_put_failure; |
1282 | ||
3bb20556 JB |
1283 | if (cmd != NL80211_CMD_NEW_WIPHY) |
1284 | goto finish; | |
1285 | ||
86e8cf98 | 1286 | switch (state->split_start) { |
3713b4e3 JB |
1287 | case 0: |
1288 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1289 | rdev->wiphy.retry_short) || |
3713b4e3 | 1290 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1291 | rdev->wiphy.retry_long) || |
3713b4e3 | 1292 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1293 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1294 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1295 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1296 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1297 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1298 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1299 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1300 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1301 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1302 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1303 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1304 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1305 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1306 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
1b8ec87a | 1307 | rdev->wiphy.max_match_sets)) |
9360ffd1 | 1308 | goto nla_put_failure; |
3713b4e3 | 1309 | |
1b8ec87a | 1310 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1311 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1312 | goto nla_put_failure; |
1b8ec87a | 1313 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1314 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1315 | goto nla_put_failure; | |
1b8ec87a | 1316 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1317 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1318 | goto nla_put_failure; | |
1b8ec87a | 1319 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1320 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1321 | goto nla_put_failure; | |
1b8ec87a | 1322 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1323 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1324 | goto nla_put_failure; | |
1b8ec87a | 1325 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1326 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1327 | goto nla_put_failure; |
86e8cf98 JB |
1328 | state->split_start++; |
1329 | if (state->split) | |
3713b4e3 JB |
1330 | break; |
1331 | case 1: | |
1332 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1333 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1334 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1335 | goto nla_put_failure; |
4745fc09 | 1336 | |
3713b4e3 | 1337 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1338 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1339 | goto nla_put_failure; |
b23aa676 | 1340 | |
1b8ec87a | 1341 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1342 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1343 | goto nla_put_failure; |
b23aa676 | 1344 | |
3713b4e3 | 1345 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1346 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1347 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1348 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1349 | goto nla_put_failure; |
b23aa676 | 1350 | |
1b8ec87a | 1351 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1352 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1353 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1354 | goto nla_put_failure; |
8fdc621d | 1355 | |
1b8ec87a ZG |
1356 | if ((rdev->wiphy.available_antennas_tx || |
1357 | rdev->wiphy.available_antennas_rx) && | |
1358 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1359 | u32 tx_ant = 0, rx_ant = 0; |
1360 | int res; | |
1b8ec87a | 1361 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1362 | if (!res) { |
1363 | if (nla_put_u32(msg, | |
1364 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1365 | tx_ant) || | |
1366 | nla_put_u32(msg, | |
1367 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1368 | rx_ant)) | |
1369 | goto nla_put_failure; | |
1370 | } | |
1371 | } | |
a293911d | 1372 | |
86e8cf98 JB |
1373 | state->split_start++; |
1374 | if (state->split) | |
3713b4e3 JB |
1375 | break; |
1376 | case 2: | |
1377 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1378 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1379 | goto nla_put_failure; |
86e8cf98 JB |
1380 | state->split_start++; |
1381 | if (state->split) | |
3713b4e3 JB |
1382 | break; |
1383 | case 3: | |
1384 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1385 | if (!nl_bands) | |
1386 | goto nla_put_failure; | |
f7ca38df | 1387 | |
86e8cf98 JB |
1388 | for (band = state->band_start; |
1389 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1390 | struct ieee80211_supported_band *sband; |
2e161f78 | 1391 | |
1b8ec87a | 1392 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1393 | |
3713b4e3 JB |
1394 | if (!sband) |
1395 | continue; | |
1396 | ||
1397 | nl_band = nla_nest_start(msg, band); | |
1398 | if (!nl_band) | |
2e161f78 | 1399 | goto nla_put_failure; |
3713b4e3 | 1400 | |
86e8cf98 | 1401 | switch (state->chan_start) { |
3713b4e3 JB |
1402 | case 0: |
1403 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1404 | goto nla_put_failure; |
86e8cf98 JB |
1405 | state->chan_start++; |
1406 | if (state->split) | |
3713b4e3 JB |
1407 | break; |
1408 | default: | |
1409 | /* add frequencies */ | |
1410 | nl_freqs = nla_nest_start( | |
1411 | msg, NL80211_BAND_ATTR_FREQS); | |
1412 | if (!nl_freqs) | |
1413 | goto nla_put_failure; | |
1414 | ||
86e8cf98 | 1415 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1416 | i < sband->n_channels; |
1417 | i++) { | |
1418 | nl_freq = nla_nest_start(msg, i); | |
1419 | if (!nl_freq) | |
1420 | goto nla_put_failure; | |
1421 | ||
1422 | chan = &sband->channels[i]; | |
1423 | ||
86e8cf98 JB |
1424 | if (nl80211_msg_put_channel( |
1425 | msg, chan, | |
1426 | state->split)) | |
3713b4e3 JB |
1427 | goto nla_put_failure; |
1428 | ||
1429 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1430 | if (state->split) |
3713b4e3 JB |
1431 | break; |
1432 | } | |
1433 | if (i < sband->n_channels) | |
86e8cf98 | 1434 | state->chan_start = i + 2; |
3713b4e3 | 1435 | else |
86e8cf98 | 1436 | state->chan_start = 0; |
3713b4e3 JB |
1437 | nla_nest_end(msg, nl_freqs); |
1438 | } | |
1439 | ||
1440 | nla_nest_end(msg, nl_band); | |
1441 | ||
86e8cf98 | 1442 | if (state->split) { |
3713b4e3 | 1443 | /* start again here */ |
86e8cf98 | 1444 | if (state->chan_start) |
3713b4e3 JB |
1445 | band--; |
1446 | break; | |
2e161f78 | 1447 | } |
2e161f78 | 1448 | } |
3713b4e3 | 1449 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1450 | |
3713b4e3 | 1451 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1452 | state->band_start = band + 1; |
3713b4e3 | 1453 | else |
86e8cf98 | 1454 | state->band_start = 0; |
74b70a4e | 1455 | |
3713b4e3 | 1456 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1457 | if (state->band_start == 0 && state->chan_start == 0) |
1458 | state->split_start++; | |
1459 | if (state->split) | |
3713b4e3 JB |
1460 | break; |
1461 | case 4: | |
1462 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1463 | if (!nl_cmds) | |
2e161f78 JB |
1464 | goto nla_put_failure; |
1465 | ||
3713b4e3 JB |
1466 | i = 0; |
1467 | #define CMD(op, n) \ | |
1468 | do { \ | |
1b8ec87a | 1469 | if (rdev->ops->op) { \ |
3713b4e3 JB |
1470 | i++; \ |
1471 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1472 | goto nla_put_failure; \ | |
1473 | } \ | |
1474 | } while (0) | |
1475 | ||
1476 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1477 | CMD(change_virtual_intf, SET_INTERFACE); | |
1478 | CMD(add_key, NEW_KEY); | |
1479 | CMD(start_ap, START_AP); | |
1480 | CMD(add_station, NEW_STATION); | |
1481 | CMD(add_mpath, NEW_MPATH); | |
1482 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1483 | CMD(change_bss, SET_BSS); | |
1484 | CMD(auth, AUTHENTICATE); | |
1485 | CMD(assoc, ASSOCIATE); | |
1486 | CMD(deauth, DEAUTHENTICATE); | |
1487 | CMD(disassoc, DISASSOCIATE); | |
1488 | CMD(join_ibss, JOIN_IBSS); | |
1489 | CMD(join_mesh, JOIN_MESH); | |
1490 | CMD(set_pmksa, SET_PMKSA); | |
1491 | CMD(del_pmksa, DEL_PMKSA); | |
1492 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1b8ec87a | 1493 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
3713b4e3 JB |
1494 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
1495 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1496 | CMD(mgmt_tx, FRAME); | |
1497 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1b8ec87a | 1498 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
3713b4e3 JB |
1499 | i++; |
1500 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1501 | goto nla_put_failure; |
2e161f78 | 1502 | } |
1b8ec87a ZG |
1503 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
1504 | rdev->ops->join_mesh) { | |
3713b4e3 JB |
1505 | i++; |
1506 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1507 | goto nla_put_failure; | |
1508 | } | |
1509 | CMD(set_wds_peer, SET_WDS_PEER); | |
1b8ec87a | 1510 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
3713b4e3 JB |
1511 | CMD(tdls_mgmt, TDLS_MGMT); |
1512 | CMD(tdls_oper, TDLS_OPER); | |
1513 | } | |
1b8ec87a | 1514 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
3713b4e3 JB |
1515 | CMD(sched_scan_start, START_SCHED_SCAN); |
1516 | CMD(probe_client, PROBE_CLIENT); | |
1517 | CMD(set_noack_map, SET_NOACK_MAP); | |
1b8ec87a | 1518 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
3713b4e3 JB |
1519 | i++; |
1520 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1521 | goto nla_put_failure; | |
1522 | } | |
1523 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1524 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
02df00eb JB |
1525 | #ifdef CONFIG_NL80211_TESTMODE |
1526 | CMD(testmode_cmd, TESTMODE); | |
1527 | #endif | |
86e8cf98 | 1528 | if (state->split) { |
5de17984 AS |
1529 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1530 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 1531 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 1532 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 1533 | CMD(set_qos_map, SET_QOS_MAP); |
723e73ac JB |
1534 | if (rdev->wiphy.features & |
1535 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | |
960d01ac | 1536 | CMD(add_tx_ts, ADD_TX_TS); |
5de17984 | 1537 | } |
02df00eb | 1538 | /* add into the if now */ |
3713b4e3 | 1539 | #undef CMD |
ff1b6e69 | 1540 | |
1b8ec87a | 1541 | if (rdev->ops->connect || rdev->ops->auth) { |
3713b4e3 JB |
1542 | i++; |
1543 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1544 | goto nla_put_failure; |
ff1b6e69 JB |
1545 | } |
1546 | ||
1b8ec87a | 1547 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
3713b4e3 JB |
1548 | i++; |
1549 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1550 | goto nla_put_failure; | |
1551 | } | |
1552 | ||
1553 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1554 | state->split_start++; |
1555 | if (state->split) | |
3713b4e3 JB |
1556 | break; |
1557 | case 5: | |
1b8ec87a ZG |
1558 | if (rdev->ops->remain_on_channel && |
1559 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
1560 | nla_put_u32(msg, |
1561 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 1562 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
1563 | goto nla_put_failure; |
1564 | ||
1b8ec87a | 1565 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
1566 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
1567 | goto nla_put_failure; | |
1568 | ||
1569 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1570 | goto nla_put_failure; | |
86e8cf98 JB |
1571 | state->split_start++; |
1572 | if (state->split) | |
3713b4e3 JB |
1573 | break; |
1574 | case 6: | |
1575 | #ifdef CONFIG_PM | |
1b8ec87a | 1576 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 1577 | goto nla_put_failure; |
86e8cf98 JB |
1578 | state->split_start++; |
1579 | if (state->split) | |
3713b4e3 JB |
1580 | break; |
1581 | #else | |
86e8cf98 | 1582 | state->split_start++; |
dfb89c56 | 1583 | #endif |
3713b4e3 JB |
1584 | case 7: |
1585 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 1586 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 1587 | goto nla_put_failure; |
ff1b6e69 | 1588 | |
1b8ec87a | 1589 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 1590 | state->split)) |
3713b4e3 | 1591 | goto nla_put_failure; |
7527a782 | 1592 | |
86e8cf98 JB |
1593 | state->split_start++; |
1594 | if (state->split) | |
3713b4e3 JB |
1595 | break; |
1596 | case 8: | |
1b8ec87a | 1597 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 1598 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 1599 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 1600 | goto nla_put_failure; |
7527a782 | 1601 | |
1b8ec87a | 1602 | features = rdev->wiphy.features; |
fe1abafd JB |
1603 | /* |
1604 | * We can only add the per-channel limit information if the | |
1605 | * dump is split, otherwise it makes it too big. Therefore | |
1606 | * only advertise it in that case. | |
1607 | */ | |
86e8cf98 | 1608 | if (state->split) |
fe1abafd JB |
1609 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1610 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1611 | goto nla_put_failure; |
562a7480 | 1612 | |
1b8ec87a | 1613 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 1614 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
1615 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
1616 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 1617 | goto nla_put_failure; |
1f074bd8 | 1618 | |
1b8ec87a ZG |
1619 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1620 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 1621 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 1622 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 1623 | goto nla_put_failure; |
7e7c8926 | 1624 | |
3713b4e3 JB |
1625 | /* |
1626 | * Any information below this point is only available to | |
1627 | * applications that can deal with it being split. This | |
1628 | * helps ensure that newly added capabilities don't break | |
1629 | * older tools by overrunning their buffers. | |
1630 | * | |
1631 | * We still increment split_start so that in the split | |
1632 | * case we'll continue with more data in the next round, | |
1633 | * but break unconditionally so unsplit data stops here. | |
1634 | */ | |
86e8cf98 | 1635 | state->split_start++; |
3713b4e3 JB |
1636 | break; |
1637 | case 9: | |
1b8ec87a | 1638 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 1639 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
1640 | rdev->wiphy.extended_capabilities_len, |
1641 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 1642 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
1643 | rdev->wiphy.extended_capabilities_len, |
1644 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 1645 | goto nla_put_failure; |
a50df0c4 | 1646 | |
1b8ec87a | 1647 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 1648 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
1649 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
1650 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
1651 | goto nla_put_failure; |
1652 | ||
be29b99a AK |
1653 | state->split_start++; |
1654 | break; | |
1655 | case 10: | |
1b8ec87a | 1656 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
1657 | goto nla_put_failure; |
1658 | ||
1b8ec87a | 1659 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
1660 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
1661 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1662 | goto nla_put_failure; | |
b43504cf | 1663 | |
1b8ec87a | 1664 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 1665 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 1666 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
1667 | goto nla_put_failure; |
1668 | ||
ad7e718c JB |
1669 | state->split_start++; |
1670 | break; | |
1671 | case 11: | |
1b8ec87a | 1672 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
1673 | const struct nl80211_vendor_cmd_info *info; |
1674 | struct nlattr *nested; | |
1675 | ||
1676 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1677 | if (!nested) | |
1678 | goto nla_put_failure; | |
1679 | ||
1b8ec87a ZG |
1680 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
1681 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
1682 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1683 | goto nla_put_failure; | |
1684 | } | |
1685 | nla_nest_end(msg, nested); | |
1686 | } | |
1687 | ||
1b8ec87a | 1688 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
1689 | const struct nl80211_vendor_cmd_info *info; |
1690 | struct nlattr *nested; | |
ad7e718c | 1691 | |
567ffc35 JB |
1692 | nested = nla_nest_start(msg, |
1693 | NL80211_ATTR_VENDOR_EVENTS); | |
1694 | if (!nested) | |
ad7e718c | 1695 | goto nla_put_failure; |
567ffc35 | 1696 | |
1b8ec87a ZG |
1697 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
1698 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
1699 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1700 | goto nla_put_failure; | |
1701 | } | |
1702 | nla_nest_end(msg, nested); | |
1703 | } | |
9a774c78 AO |
1704 | state->split_start++; |
1705 | break; | |
1706 | case 12: | |
1707 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
1708 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
1709 | rdev->wiphy.max_num_csa_counters)) | |
1710 | goto nla_put_failure; | |
01e0daa4 | 1711 | |
1bdd716c AN |
1712 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
1713 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
1714 | goto nla_put_failure; | |
1715 | ||
d75bb06b GKS |
1716 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
1717 | sizeof(rdev->wiphy.ext_features), | |
1718 | rdev->wiphy.ext_features)) | |
1719 | goto nla_put_failure; | |
1720 | ||
3713b4e3 | 1721 | /* done */ |
86e8cf98 | 1722 | state->split_start = 0; |
3713b4e3 JB |
1723 | break; |
1724 | } | |
3bb20556 | 1725 | finish: |
053c095a JB |
1726 | genlmsg_end(msg, hdr); |
1727 | return 0; | |
55682965 JB |
1728 | |
1729 | nla_put_failure: | |
bc3ed28c TG |
1730 | genlmsg_cancel(msg, hdr); |
1731 | return -EMSGSIZE; | |
55682965 JB |
1732 | } |
1733 | ||
86e8cf98 JB |
1734 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1735 | struct netlink_callback *cb, | |
1736 | struct nl80211_dump_wiphy_state *state) | |
1737 | { | |
1738 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1739 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1740 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1741 | /* ignore parse errors for backward compatibility */ | |
1742 | if (ret) | |
1743 | return 0; | |
1744 | ||
1745 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1746 | if (tb[NL80211_ATTR_WIPHY]) | |
1747 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1748 | if (tb[NL80211_ATTR_WDEV]) | |
1749 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1750 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1751 | struct net_device *netdev; | |
1752 | struct cfg80211_registered_device *rdev; | |
1753 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1754 | ||
7f2b8562 | 1755 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1756 | if (!netdev) |
1757 | return -ENODEV; | |
1758 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1759 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1760 | netdev->ieee80211_ptr->wiphy); |
1761 | state->filter_wiphy = rdev->wiphy_idx; | |
1762 | } | |
86e8cf98 JB |
1763 | } |
1764 | ||
1765 | return 0; | |
1766 | } | |
1767 | ||
55682965 JB |
1768 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1769 | { | |
645e77de | 1770 | int idx = 0, ret; |
86e8cf98 | 1771 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1772 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1773 | |
5fe231e8 | 1774 | rtnl_lock(); |
86e8cf98 JB |
1775 | if (!state) { |
1776 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1777 | if (!state) { |
1778 | rtnl_unlock(); | |
86e8cf98 | 1779 | return -ENOMEM; |
3713b4e3 | 1780 | } |
86e8cf98 JB |
1781 | state->filter_wiphy = -1; |
1782 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1783 | if (ret) { | |
1784 | kfree(state); | |
1785 | rtnl_unlock(); | |
1786 | return ret; | |
3713b4e3 | 1787 | } |
86e8cf98 | 1788 | cb->args[0] = (long)state; |
3713b4e3 JB |
1789 | } |
1790 | ||
1b8ec87a ZG |
1791 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1792 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1793 | continue; |
86e8cf98 | 1794 | if (++idx <= state->start) |
55682965 | 1795 | continue; |
86e8cf98 | 1796 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1797 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1798 | continue; |
1799 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1800 | do { | |
3bb20556 JB |
1801 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
1802 | skb, | |
3713b4e3 JB |
1803 | NETLINK_CB(cb->skb).portid, |
1804 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1805 | NLM_F_MULTI, state); |
3713b4e3 JB |
1806 | if (ret < 0) { |
1807 | /* | |
1808 | * If sending the wiphy data didn't fit (ENOBUFS | |
1809 | * or EMSGSIZE returned), this SKB is still | |
1810 | * empty (so it's not too big because another | |
1811 | * wiphy dataset is already in the skb) and | |
1812 | * we've not tried to adjust the dump allocation | |
1813 | * yet ... then adjust the alloc size to be | |
1814 | * bigger, and return 1 but with the empty skb. | |
1815 | * This results in an empty message being RX'ed | |
1816 | * in userspace, but that is ignored. | |
1817 | * | |
1818 | * We can then retry with the larger buffer. | |
1819 | */ | |
1820 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1821 | !skb->len && !state->split && |
3713b4e3 JB |
1822 | cb->min_dump_alloc < 4096) { |
1823 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1824 | state->split_start = 0; |
d98cae64 | 1825 | rtnl_unlock(); |
3713b4e3 JB |
1826 | return 1; |
1827 | } | |
1828 | idx--; | |
1829 | break; | |
645e77de | 1830 | } |
86e8cf98 | 1831 | } while (state->split_start > 0); |
3713b4e3 | 1832 | break; |
55682965 | 1833 | } |
5fe231e8 | 1834 | rtnl_unlock(); |
55682965 | 1835 | |
86e8cf98 | 1836 | state->start = idx; |
55682965 JB |
1837 | |
1838 | return skb->len; | |
1839 | } | |
1840 | ||
86e8cf98 JB |
1841 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1842 | { | |
1843 | kfree((void *)cb->args[0]); | |
1844 | return 0; | |
1845 | } | |
1846 | ||
55682965 JB |
1847 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1848 | { | |
1849 | struct sk_buff *msg; | |
1b8ec87a | 1850 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 1851 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1852 | |
645e77de | 1853 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1854 | if (!msg) |
4c476991 | 1855 | return -ENOMEM; |
55682965 | 1856 | |
3bb20556 JB |
1857 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
1858 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 1859 | &state) < 0) { |
4c476991 JB |
1860 | nlmsg_free(msg); |
1861 | return -ENOBUFS; | |
1862 | } | |
55682965 | 1863 | |
134e6375 | 1864 | return genlmsg_reply(msg, info); |
55682965 JB |
1865 | } |
1866 | ||
31888487 JM |
1867 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1868 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1869 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1870 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1871 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1872 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1873 | }; | |
1874 | ||
1875 | static int parse_txq_params(struct nlattr *tb[], | |
1876 | struct ieee80211_txq_params *txq_params) | |
1877 | { | |
a3304b0a | 1878 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1879 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1880 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1881 | return -EINVAL; | |
1882 | ||
a3304b0a | 1883 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1884 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1885 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1886 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1887 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1888 | ||
a3304b0a JB |
1889 | if (txq_params->ac >= NL80211_NUM_ACS) |
1890 | return -EINVAL; | |
1891 | ||
31888487 JM |
1892 | return 0; |
1893 | } | |
1894 | ||
f444de05 JB |
1895 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1896 | { | |
1897 | /* | |
cc1d2806 JB |
1898 | * You can only set the channel explicitly for WDS interfaces, |
1899 | * all others have their channel managed via their respective | |
1900 | * "establish a connection" command (connect, join, ...) | |
1901 | * | |
1902 | * For AP/GO and mesh mode, the channel can be set with the | |
1903 | * channel userspace API, but is only stored and passed to the | |
1904 | * low-level driver when the AP starts or the mesh is joined. | |
1905 | * This is for backward compatibility, userspace can also give | |
1906 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1907 | * |
1908 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1909 | * whatever else is going on, so they have their own special |
1910 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1911 | */ |
1912 | return !wdev || | |
1913 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1914 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1915 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1916 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1917 | } |
1918 | ||
683b6d3b JB |
1919 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1920 | struct genl_info *info, | |
1921 | struct cfg80211_chan_def *chandef) | |
1922 | { | |
dbeca2ea | 1923 | u32 control_freq; |
683b6d3b JB |
1924 | |
1925 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1926 | return -EINVAL; | |
1927 | ||
1928 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1929 | ||
1930 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1931 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1932 | chandef->center_freq1 = control_freq; | |
1933 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1934 | |
1935 | /* Primary channel not allowed */ | |
1936 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1937 | return -EINVAL; | |
1938 | ||
3d9d1d66 JB |
1939 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1940 | enum nl80211_channel_type chantype; | |
1941 | ||
1942 | chantype = nla_get_u32( | |
1943 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1944 | ||
1945 | switch (chantype) { | |
1946 | case NL80211_CHAN_NO_HT: | |
1947 | case NL80211_CHAN_HT20: | |
1948 | case NL80211_CHAN_HT40PLUS: | |
1949 | case NL80211_CHAN_HT40MINUS: | |
1950 | cfg80211_chandef_create(chandef, chandef->chan, | |
1951 | chantype); | |
1952 | break; | |
1953 | default: | |
1954 | return -EINVAL; | |
1955 | } | |
1956 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1957 | chandef->width = | |
1958 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1959 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1960 | chandef->center_freq1 = | |
1961 | nla_get_u32( | |
1962 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1963 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1964 | chandef->center_freq2 = | |
1965 | nla_get_u32( | |
1966 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1967 | } | |
1968 | ||
9f5e8f6e | 1969 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1970 | return -EINVAL; |
1971 | ||
9f5e8f6e JB |
1972 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1973 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1974 | return -EINVAL; |
1975 | ||
2f301ab2 SW |
1976 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1977 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1978 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1979 | return -EINVAL; | |
1980 | ||
683b6d3b JB |
1981 | return 0; |
1982 | } | |
1983 | ||
f444de05 | 1984 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 1985 | struct net_device *dev, |
f444de05 JB |
1986 | struct genl_info *info) |
1987 | { | |
683b6d3b | 1988 | struct cfg80211_chan_def chandef; |
f444de05 | 1989 | int result; |
e8c9bd5b | 1990 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 1991 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 1992 | |
e16821bc JM |
1993 | if (dev) |
1994 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
1995 | if (!nl80211_can_set_dev_channel(wdev)) |
1996 | return -EOPNOTSUPP; | |
e16821bc JM |
1997 | if (wdev) |
1998 | iftype = wdev->iftype; | |
f444de05 | 1999 | |
683b6d3b JB |
2000 | result = nl80211_parse_chandef(rdev, info, &chandef); |
2001 | if (result) | |
2002 | return result; | |
f444de05 | 2003 | |
e8c9bd5b | 2004 | switch (iftype) { |
aa430da4 JB |
2005 | case NL80211_IFTYPE_AP: |
2006 | case NL80211_IFTYPE_P2P_GO: | |
174e0cd2 | 2007 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
aa430da4 JB |
2008 | result = -EINVAL; |
2009 | break; | |
2010 | } | |
e16821bc JM |
2011 | if (wdev->beacon_interval) { |
2012 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
2013 | !(rdev->wiphy.features & | |
2014 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
2015 | result = -EBUSY; | |
2016 | break; | |
2017 | } | |
2018 | ||
2019 | /* Only allow dynamic channel width changes */ | |
2020 | if (chandef.chan != wdev->preset_chandef.chan) { | |
2021 | result = -EBUSY; | |
2022 | break; | |
2023 | } | |
2024 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
2025 | if (result) | |
2026 | break; | |
2027 | } | |
683b6d3b | 2028 | wdev->preset_chandef = chandef; |
aa430da4 JB |
2029 | result = 0; |
2030 | break; | |
cc1d2806 | 2031 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 2032 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 2033 | break; |
e8c9bd5b | 2034 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 2035 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 2036 | break; |
aa430da4 | 2037 | default: |
e8c9bd5b | 2038 | result = -EINVAL; |
f444de05 | 2039 | } |
f444de05 JB |
2040 | |
2041 | return result; | |
2042 | } | |
2043 | ||
2044 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2045 | { | |
4c476991 JB |
2046 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2047 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2048 | |
e16821bc | 2049 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2050 | } |
2051 | ||
e8347eba BJ |
2052 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2053 | { | |
43b19952 JB |
2054 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2055 | struct net_device *dev = info->user_ptr[1]; | |
2056 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2057 | const u8 *bssid; |
e8347eba BJ |
2058 | |
2059 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2060 | return -EINVAL; | |
2061 | ||
43b19952 JB |
2062 | if (netif_running(dev)) |
2063 | return -EBUSY; | |
e8347eba | 2064 | |
43b19952 JB |
2065 | if (!rdev->ops->set_wds_peer) |
2066 | return -EOPNOTSUPP; | |
e8347eba | 2067 | |
43b19952 JB |
2068 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2069 | return -EOPNOTSUPP; | |
e8347eba BJ |
2070 | |
2071 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2072 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2073 | } |
2074 | ||
2075 | ||
55682965 JB |
2076 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2077 | { | |
2078 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2079 | struct net_device *netdev = NULL; |
2080 | struct wireless_dev *wdev; | |
a1e567c8 | 2081 | int result = 0, rem_txq_params = 0; |
31888487 | 2082 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2083 | u32 changed; |
2084 | u8 retry_short = 0, retry_long = 0; | |
2085 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2086 | u8 coverage_class = 0; |
55682965 | 2087 | |
5fe231e8 JB |
2088 | ASSERT_RTNL(); |
2089 | ||
f444de05 JB |
2090 | /* |
2091 | * Try to find the wiphy and netdev. Normally this | |
2092 | * function shouldn't need the netdev, but this is | |
2093 | * done for backward compatibility -- previously | |
2094 | * setting the channel was done per wiphy, but now | |
2095 | * it is per netdev. Previous userland like hostapd | |
2096 | * also passed a netdev to set_wiphy, so that it is | |
2097 | * possible to let that go to the right netdev! | |
2098 | */ | |
4bbf4d56 | 2099 | |
f444de05 JB |
2100 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2101 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2102 | ||
7f2b8562 | 2103 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2104 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2105 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2106 | else |
f444de05 | 2107 | netdev = NULL; |
4bbf4d56 JB |
2108 | } |
2109 | ||
f444de05 | 2110 | if (!netdev) { |
878d9ec7 JB |
2111 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2112 | info->attrs); | |
5fe231e8 | 2113 | if (IS_ERR(rdev)) |
4c476991 | 2114 | return PTR_ERR(rdev); |
f444de05 JB |
2115 | wdev = NULL; |
2116 | netdev = NULL; | |
2117 | result = 0; | |
71fe96bf | 2118 | } else |
f444de05 | 2119 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2120 | |
2121 | /* | |
2122 | * end workaround code, by now the rdev is available | |
2123 | * and locked, and wdev may or may not be NULL. | |
2124 | */ | |
4bbf4d56 JB |
2125 | |
2126 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2127 | result = cfg80211_dev_rename( |
2128 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2129 | |
4bbf4d56 | 2130 | if (result) |
7f2b8562 | 2131 | return result; |
31888487 JM |
2132 | |
2133 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2134 | struct ieee80211_txq_params txq_params; | |
2135 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2136 | ||
7f2b8562 YX |
2137 | if (!rdev->ops->set_txq_params) |
2138 | return -EOPNOTSUPP; | |
31888487 | 2139 | |
7f2b8562 YX |
2140 | if (!netdev) |
2141 | return -EINVAL; | |
f70f01c2 | 2142 | |
133a3ff2 | 2143 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2144 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2145 | return -EINVAL; | |
133a3ff2 | 2146 | |
7f2b8562 YX |
2147 | if (!netif_running(netdev)) |
2148 | return -ENETDOWN; | |
2b5f8b0b | 2149 | |
31888487 JM |
2150 | nla_for_each_nested(nl_txq_params, |
2151 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2152 | rem_txq_params) { | |
ae811e21 JB |
2153 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2154 | nla_data(nl_txq_params), | |
2155 | nla_len(nl_txq_params), | |
2156 | txq_params_policy); | |
2157 | if (result) | |
2158 | return result; | |
31888487 JM |
2159 | result = parse_txq_params(tb, &txq_params); |
2160 | if (result) | |
7f2b8562 | 2161 | return result; |
31888487 | 2162 | |
e35e4d28 HG |
2163 | result = rdev_set_txq_params(rdev, netdev, |
2164 | &txq_params); | |
31888487 | 2165 | if (result) |
7f2b8562 | 2166 | return result; |
31888487 JM |
2167 | } |
2168 | } | |
55682965 | 2169 | |
72bdcf34 | 2170 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2171 | result = __nl80211_set_channel( |
2172 | rdev, | |
2173 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2174 | info); | |
72bdcf34 | 2175 | if (result) |
7f2b8562 | 2176 | return result; |
72bdcf34 JM |
2177 | } |
2178 | ||
98d2ff8b | 2179 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2180 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2181 | enum nl80211_tx_power_setting type; |
2182 | int idx, mbm = 0; | |
2183 | ||
c8442118 JB |
2184 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2185 | txp_wdev = NULL; | |
2186 | ||
7f2b8562 YX |
2187 | if (!rdev->ops->set_tx_power) |
2188 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2189 | |
2190 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2191 | type = nla_get_u32(info->attrs[idx]); | |
2192 | ||
2193 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2194 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2195 | return -EINVAL; | |
98d2ff8b JO |
2196 | |
2197 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2198 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2199 | mbm = nla_get_u32(info->attrs[idx]); | |
2200 | } | |
2201 | ||
c8442118 | 2202 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2203 | if (result) |
7f2b8562 | 2204 | return result; |
98d2ff8b JO |
2205 | } |
2206 | ||
afe0cbf8 BR |
2207 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2208 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2209 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2210 | if ((!rdev->wiphy.available_antennas_tx && |
2211 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2212 | !rdev->ops->set_antenna) |
2213 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2214 | |
2215 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2216 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2217 | ||
a7ffac95 | 2218 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2219 | * available antenna masks, except for the "all" mask */ |
2220 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2221 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2222 | return -EINVAL; | |
a7ffac95 | 2223 | |
7f531e03 BR |
2224 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2225 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2226 | |
e35e4d28 | 2227 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2228 | if (result) |
7f2b8562 | 2229 | return result; |
afe0cbf8 BR |
2230 | } |
2231 | ||
b9a5f8ca JM |
2232 | changed = 0; |
2233 | ||
2234 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2235 | retry_short = nla_get_u8( | |
2236 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2237 | if (retry_short == 0) |
2238 | return -EINVAL; | |
2239 | ||
b9a5f8ca JM |
2240 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2241 | } | |
2242 | ||
2243 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2244 | retry_long = nla_get_u8( | |
2245 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2246 | if (retry_long == 0) |
2247 | return -EINVAL; | |
2248 | ||
b9a5f8ca JM |
2249 | changed |= WIPHY_PARAM_RETRY_LONG; |
2250 | } | |
2251 | ||
2252 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2253 | frag_threshold = nla_get_u32( | |
2254 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2255 | if (frag_threshold < 256) |
2256 | return -EINVAL; | |
2257 | ||
b9a5f8ca JM |
2258 | if (frag_threshold != (u32) -1) { |
2259 | /* | |
2260 | * Fragments (apart from the last one) are required to | |
2261 | * have even length. Make the fragmentation code | |
2262 | * simpler by stripping LSB should someone try to use | |
2263 | * odd threshold value. | |
2264 | */ | |
2265 | frag_threshold &= ~0x1; | |
2266 | } | |
2267 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2268 | } | |
2269 | ||
2270 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2271 | rts_threshold = nla_get_u32( | |
2272 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2273 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2274 | } | |
2275 | ||
81077e82 | 2276 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
3057dbfd LB |
2277 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
2278 | return -EINVAL; | |
2279 | ||
81077e82 LT |
2280 | coverage_class = nla_get_u8( |
2281 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2282 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2283 | } | |
2284 | ||
3057dbfd LB |
2285 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
2286 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | |
2287 | return -EOPNOTSUPP; | |
2288 | ||
2289 | changed |= WIPHY_PARAM_DYN_ACK; | |
81077e82 LT |
2290 | } |
2291 | ||
b9a5f8ca JM |
2292 | if (changed) { |
2293 | u8 old_retry_short, old_retry_long; | |
2294 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2295 | u8 old_coverage_class; |
b9a5f8ca | 2296 | |
7f2b8562 YX |
2297 | if (!rdev->ops->set_wiphy_params) |
2298 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2299 | |
2300 | old_retry_short = rdev->wiphy.retry_short; | |
2301 | old_retry_long = rdev->wiphy.retry_long; | |
2302 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2303 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2304 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2305 | |
2306 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2307 | rdev->wiphy.retry_short = retry_short; | |
2308 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2309 | rdev->wiphy.retry_long = retry_long; | |
2310 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2311 | rdev->wiphy.frag_threshold = frag_threshold; | |
2312 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2313 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2314 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2315 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2316 | |
e35e4d28 | 2317 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2318 | if (result) { |
2319 | rdev->wiphy.retry_short = old_retry_short; | |
2320 | rdev->wiphy.retry_long = old_retry_long; | |
2321 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2322 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2323 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2324 | } |
2325 | } | |
7f2b8562 | 2326 | return 0; |
55682965 JB |
2327 | } |
2328 | ||
71bbc994 JB |
2329 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2330 | { | |
2331 | return (u64)wdev->identifier | | |
f26cbf40 | 2332 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2333 | } |
55682965 | 2334 | |
683b6d3b | 2335 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2336 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2337 | { |
601555cd JB |
2338 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
2339 | return -EINVAL; | |
3d9d1d66 | 2340 | |
683b6d3b JB |
2341 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2342 | chandef->chan->center_freq)) | |
2343 | return -ENOBUFS; | |
3d9d1d66 JB |
2344 | switch (chandef->width) { |
2345 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2346 | case NL80211_CHAN_WIDTH_20: | |
2347 | case NL80211_CHAN_WIDTH_40: | |
2348 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2349 | cfg80211_get_chandef_type(chandef))) | |
2350 | return -ENOBUFS; | |
2351 | break; | |
2352 | default: | |
2353 | break; | |
2354 | } | |
2355 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2356 | return -ENOBUFS; | |
2357 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2358 | return -ENOBUFS; | |
2359 | if (chandef->center_freq2 && | |
2360 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2361 | return -ENOBUFS; |
2362 | return 0; | |
2363 | } | |
2364 | ||
15e47304 | 2365 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2366 | struct cfg80211_registered_device *rdev, |
8f894be2 | 2367 | struct wireless_dev *wdev, bool removal) |
55682965 | 2368 | { |
72fb2abc | 2369 | struct net_device *dev = wdev->netdev; |
8f894be2 | 2370 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
55682965 JB |
2371 | void *hdr; |
2372 | ||
8f894be2 TB |
2373 | if (removal) |
2374 | cmd = NL80211_CMD_DEL_INTERFACE; | |
2375 | ||
2376 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | |
55682965 JB |
2377 | if (!hdr) |
2378 | return -1; | |
2379 | ||
72fb2abc JB |
2380 | if (dev && |
2381 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2382 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2383 | goto nla_put_failure; |
2384 | ||
2385 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2386 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2387 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2388 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2389 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2390 | rdev->devlist_generation ^ | |
2391 | (cfg80211_rdev_list_generation << 2))) | |
2392 | goto nla_put_failure; | |
f5ea9120 | 2393 | |
5b7ccaf3 | 2394 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2395 | int ret; |
2396 | struct cfg80211_chan_def chandef; | |
2397 | ||
2398 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2399 | if (ret == 0) { | |
2400 | if (nl80211_send_chandef(msg, &chandef)) | |
2401 | goto nla_put_failure; | |
2402 | } | |
d91df0e3 PF |
2403 | } |
2404 | ||
b84e7a05 AQ |
2405 | if (wdev->ssid_len) { |
2406 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2407 | goto nla_put_failure; | |
2408 | } | |
2409 | ||
053c095a JB |
2410 | genlmsg_end(msg, hdr); |
2411 | return 0; | |
55682965 JB |
2412 | |
2413 | nla_put_failure: | |
bc3ed28c TG |
2414 | genlmsg_cancel(msg, hdr); |
2415 | return -EMSGSIZE; | |
55682965 JB |
2416 | } |
2417 | ||
2418 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2419 | { | |
2420 | int wp_idx = 0; | |
2421 | int if_idx = 0; | |
2422 | int wp_start = cb->args[0]; | |
2423 | int if_start = cb->args[1]; | |
f5ea9120 | 2424 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2425 | struct wireless_dev *wdev; |
2426 | ||
5fe231e8 | 2427 | rtnl_lock(); |
f5ea9120 JB |
2428 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2429 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2430 | continue; |
bba95fef JB |
2431 | if (wp_idx < wp_start) { |
2432 | wp_idx++; | |
55682965 | 2433 | continue; |
bba95fef | 2434 | } |
55682965 JB |
2435 | if_idx = 0; |
2436 | ||
89a54e48 | 2437 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2438 | if (if_idx < if_start) { |
2439 | if_idx++; | |
55682965 | 2440 | continue; |
bba95fef | 2441 | } |
15e47304 | 2442 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2443 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
8f894be2 | 2444 | rdev, wdev, false) < 0) { |
bba95fef JB |
2445 | goto out; |
2446 | } | |
2447 | if_idx++; | |
55682965 | 2448 | } |
bba95fef JB |
2449 | |
2450 | wp_idx++; | |
55682965 | 2451 | } |
bba95fef | 2452 | out: |
5fe231e8 | 2453 | rtnl_unlock(); |
55682965 JB |
2454 | |
2455 | cb->args[0] = wp_idx; | |
2456 | cb->args[1] = if_idx; | |
2457 | ||
2458 | return skb->len; | |
2459 | } | |
2460 | ||
2461 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2462 | { | |
2463 | struct sk_buff *msg; | |
1b8ec87a | 2464 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2465 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2466 | |
fd2120ca | 2467 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2468 | if (!msg) |
4c476991 | 2469 | return -ENOMEM; |
55682965 | 2470 | |
15e47304 | 2471 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2472 | rdev, wdev, false) < 0) { |
4c476991 JB |
2473 | nlmsg_free(msg); |
2474 | return -ENOBUFS; | |
2475 | } | |
55682965 | 2476 | |
134e6375 | 2477 | return genlmsg_reply(msg, info); |
55682965 JB |
2478 | } |
2479 | ||
66f7ac50 MW |
2480 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2481 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2482 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2483 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2484 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2485 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2486 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2487 | }; |
2488 | ||
2489 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2490 | { | |
2491 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2492 | int flag; | |
2493 | ||
2494 | *mntrflags = 0; | |
2495 | ||
2496 | if (!nla) | |
2497 | return -EINVAL; | |
2498 | ||
2499 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2500 | nla, mntr_flags_policy)) | |
2501 | return -EINVAL; | |
2502 | ||
2503 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2504 | if (flags[flag]) | |
2505 | *mntrflags |= (1<<flag); | |
2506 | ||
2507 | return 0; | |
2508 | } | |
2509 | ||
9bc383de | 2510 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2511 | struct net_device *netdev, u8 use_4addr, |
2512 | enum nl80211_iftype iftype) | |
9bc383de | 2513 | { |
ad4bb6f8 | 2514 | if (!use_4addr) { |
f350a0a8 | 2515 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2516 | return -EBUSY; |
9bc383de | 2517 | return 0; |
ad4bb6f8 | 2518 | } |
9bc383de JB |
2519 | |
2520 | switch (iftype) { | |
2521 | case NL80211_IFTYPE_AP_VLAN: | |
2522 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2523 | return 0; | |
2524 | break; | |
2525 | case NL80211_IFTYPE_STATION: | |
2526 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2527 | return 0; | |
2528 | break; | |
2529 | default: | |
2530 | break; | |
2531 | } | |
2532 | ||
2533 | return -EOPNOTSUPP; | |
2534 | } | |
2535 | ||
55682965 JB |
2536 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2537 | { | |
4c476991 | 2538 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2539 | struct vif_params params; |
e36d56b6 | 2540 | int err; |
04a773ad | 2541 | enum nl80211_iftype otype, ntype; |
4c476991 | 2542 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2543 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2544 | bool change = false; |
55682965 | 2545 | |
2ec600d6 LCC |
2546 | memset(¶ms, 0, sizeof(params)); |
2547 | ||
04a773ad | 2548 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2549 | |
723b038d | 2550 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2551 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2552 | if (otype != ntype) |
ac7f9cfa | 2553 | change = true; |
4c476991 JB |
2554 | if (ntype > NL80211_IFTYPE_MAX) |
2555 | return -EINVAL; | |
723b038d JB |
2556 | } |
2557 | ||
92ffe055 | 2558 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2559 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2560 | ||
4c476991 JB |
2561 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2562 | return -EINVAL; | |
29cbe68c JB |
2563 | if (netif_running(dev)) |
2564 | return -EBUSY; | |
2565 | ||
2566 | wdev_lock(wdev); | |
2567 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2568 | IEEE80211_MAX_MESH_ID_LEN); | |
2569 | wdev->mesh_id_up_len = | |
2570 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2571 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2572 | wdev->mesh_id_up_len); | |
2573 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2574 | } |
2575 | ||
8b787643 FF |
2576 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2577 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2578 | change = true; | |
ad4bb6f8 | 2579 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2580 | if (err) |
4c476991 | 2581 | return err; |
8b787643 FF |
2582 | } else { |
2583 | params.use_4addr = -1; | |
2584 | } | |
2585 | ||
92ffe055 | 2586 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2587 | if (ntype != NL80211_IFTYPE_MONITOR) |
2588 | return -EINVAL; | |
92ffe055 JB |
2589 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2590 | &_flags); | |
ac7f9cfa | 2591 | if (err) |
4c476991 | 2592 | return err; |
ac7f9cfa JB |
2593 | |
2594 | flags = &_flags; | |
2595 | change = true; | |
92ffe055 | 2596 | } |
3b85875a | 2597 | |
18003297 | 2598 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2599 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2600 | return -EOPNOTSUPP; | |
2601 | ||
ac7f9cfa | 2602 | if (change) |
3d54d255 | 2603 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2604 | else |
2605 | err = 0; | |
60719ffd | 2606 | |
9bc383de JB |
2607 | if (!err && params.use_4addr != -1) |
2608 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2609 | ||
55682965 JB |
2610 | return err; |
2611 | } | |
2612 | ||
2613 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2614 | { | |
4c476991 | 2615 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2616 | struct vif_params params; |
84efbb84 | 2617 | struct wireless_dev *wdev; |
8f894be2 | 2618 | struct sk_buff *msg, *event; |
55682965 JB |
2619 | int err; |
2620 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2621 | u32 flags; |
55682965 | 2622 | |
78f22b6a JB |
2623 | /* to avoid failing a new interface creation due to pending removal */ |
2624 | cfg80211_destroy_ifaces(rdev); | |
2625 | ||
2ec600d6 LCC |
2626 | memset(¶ms, 0, sizeof(params)); |
2627 | ||
55682965 JB |
2628 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2629 | return -EINVAL; | |
2630 | ||
2631 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2632 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2633 | if (type > NL80211_IFTYPE_MAX) | |
2634 | return -EINVAL; | |
2635 | } | |
2636 | ||
79c97e97 | 2637 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2638 | !(rdev->wiphy.interface_modes & (1 << type))) |
2639 | return -EOPNOTSUPP; | |
55682965 | 2640 | |
e8f479b1 BG |
2641 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
2642 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && | |
2643 | info->attrs[NL80211_ATTR_MAC]) { | |
1c18f145 AS |
2644 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
2645 | ETH_ALEN); | |
2646 | if (!is_valid_ether_addr(params.macaddr)) | |
2647 | return -EADDRNOTAVAIL; | |
2648 | } | |
2649 | ||
9bc383de | 2650 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2651 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2652 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2653 | if (err) |
4c476991 | 2654 | return err; |
9bc383de | 2655 | } |
8b787643 | 2656 | |
1c90f9d4 JB |
2657 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2658 | if (!msg) | |
2659 | return -ENOMEM; | |
2660 | ||
66f7ac50 MW |
2661 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2662 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2663 | &flags); | |
e057d3c3 | 2664 | |
18003297 | 2665 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2666 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2667 | return -EOPNOTSUPP; | |
2668 | ||
e35e4d28 HG |
2669 | wdev = rdev_add_virtual_intf(rdev, |
2670 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2671 | type, err ? NULL : &flags, ¶ms); | |
d687cbb7 RM |
2672 | if (WARN_ON(!wdev)) { |
2673 | nlmsg_free(msg); | |
2674 | return -EPROTO; | |
2675 | } else if (IS_ERR(wdev)) { | |
1c90f9d4 | 2676 | nlmsg_free(msg); |
84efbb84 | 2677 | return PTR_ERR(wdev); |
1c90f9d4 | 2678 | } |
2ec600d6 | 2679 | |
18e5ca65 | 2680 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
78f22b6a JB |
2681 | wdev->owner_nlportid = info->snd_portid; |
2682 | ||
98104fde JB |
2683 | switch (type) { |
2684 | case NL80211_IFTYPE_MESH_POINT: | |
2685 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2686 | break; | |
29cbe68c JB |
2687 | wdev_lock(wdev); |
2688 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2689 | IEEE80211_MAX_MESH_ID_LEN); | |
2690 | wdev->mesh_id_up_len = | |
2691 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2692 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2693 | wdev->mesh_id_up_len); | |
2694 | wdev_unlock(wdev); | |
98104fde JB |
2695 | break; |
2696 | case NL80211_IFTYPE_P2P_DEVICE: | |
2697 | /* | |
2698 | * P2P Device doesn't have a netdev, so doesn't go | |
2699 | * through the netdev notifier and must be added here | |
2700 | */ | |
2701 | mutex_init(&wdev->mtx); | |
2702 | INIT_LIST_HEAD(&wdev->event_list); | |
2703 | spin_lock_init(&wdev->event_lock); | |
2704 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2705 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2706 | ||
98104fde JB |
2707 | wdev->identifier = ++rdev->wdev_id; |
2708 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2709 | rdev->devlist_generation++; | |
98104fde JB |
2710 | break; |
2711 | default: | |
2712 | break; | |
29cbe68c JB |
2713 | } |
2714 | ||
15e47304 | 2715 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2716 | rdev, wdev, false) < 0) { |
1c90f9d4 JB |
2717 | nlmsg_free(msg); |
2718 | return -ENOBUFS; | |
2719 | } | |
2720 | ||
8f894be2 TB |
2721 | event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2722 | if (event) { | |
2723 | if (nl80211_send_iface(event, 0, 0, 0, | |
2724 | rdev, wdev, false) < 0) { | |
2725 | nlmsg_free(event); | |
2726 | goto out; | |
2727 | } | |
2728 | ||
2729 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
2730 | event, 0, NL80211_MCGRP_CONFIG, | |
2731 | GFP_KERNEL); | |
2732 | } | |
2733 | ||
2734 | out: | |
1c90f9d4 | 2735 | return genlmsg_reply(msg, info); |
55682965 JB |
2736 | } |
2737 | ||
2738 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2739 | { | |
4c476991 | 2740 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2741 | struct wireless_dev *wdev = info->user_ptr[1]; |
8f894be2 TB |
2742 | struct sk_buff *msg; |
2743 | int status; | |
55682965 | 2744 | |
4c476991 JB |
2745 | if (!rdev->ops->del_virtual_intf) |
2746 | return -EOPNOTSUPP; | |
55682965 | 2747 | |
8f894be2 TB |
2748 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2749 | if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) { | |
2750 | nlmsg_free(msg); | |
2751 | msg = NULL; | |
2752 | } | |
2753 | ||
84efbb84 JB |
2754 | /* |
2755 | * If we remove a wireless device without a netdev then clear | |
2756 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2757 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2758 | * since the wdev has been freed, unlike with a netdev where | |
2759 | * we need the dev_put() for the netdev to really be freed. | |
2760 | */ | |
2761 | if (!wdev->netdev) | |
2762 | info->user_ptr[1] = NULL; | |
2763 | ||
8f894be2 TB |
2764 | status = rdev_del_virtual_intf(rdev, wdev); |
2765 | if (status >= 0 && msg) | |
2766 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
2767 | msg, 0, NL80211_MCGRP_CONFIG, | |
2768 | GFP_KERNEL); | |
2769 | else | |
2770 | nlmsg_free(msg); | |
2771 | ||
2772 | return status; | |
55682965 JB |
2773 | } |
2774 | ||
1d9d9213 SW |
2775 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2776 | { | |
2777 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2778 | struct net_device *dev = info->user_ptr[1]; | |
2779 | u16 noack_map; | |
2780 | ||
2781 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2782 | return -EINVAL; | |
2783 | ||
2784 | if (!rdev->ops->set_noack_map) | |
2785 | return -EOPNOTSUPP; | |
2786 | ||
2787 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2788 | ||
e35e4d28 | 2789 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2790 | } |
2791 | ||
41ade00f JB |
2792 | struct get_key_cookie { |
2793 | struct sk_buff *msg; | |
2794 | int error; | |
b9454e83 | 2795 | int idx; |
41ade00f JB |
2796 | }; |
2797 | ||
2798 | static void get_key_callback(void *c, struct key_params *params) | |
2799 | { | |
b9454e83 | 2800 | struct nlattr *key; |
41ade00f JB |
2801 | struct get_key_cookie *cookie = c; |
2802 | ||
9360ffd1 DM |
2803 | if ((params->key && |
2804 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2805 | params->key_len, params->key)) || | |
2806 | (params->seq && | |
2807 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2808 | params->seq_len, params->seq)) || | |
2809 | (params->cipher && | |
2810 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2811 | params->cipher))) | |
2812 | goto nla_put_failure; | |
41ade00f | 2813 | |
b9454e83 JB |
2814 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2815 | if (!key) | |
2816 | goto nla_put_failure; | |
2817 | ||
9360ffd1 DM |
2818 | if ((params->key && |
2819 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2820 | params->key_len, params->key)) || | |
2821 | (params->seq && | |
2822 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2823 | params->seq_len, params->seq)) || | |
2824 | (params->cipher && | |
2825 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2826 | params->cipher))) | |
2827 | goto nla_put_failure; | |
b9454e83 | 2828 | |
9360ffd1 DM |
2829 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2830 | goto nla_put_failure; | |
b9454e83 JB |
2831 | |
2832 | nla_nest_end(cookie->msg, key); | |
2833 | ||
41ade00f JB |
2834 | return; |
2835 | nla_put_failure: | |
2836 | cookie->error = 1; | |
2837 | } | |
2838 | ||
2839 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2840 | { | |
4c476991 | 2841 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2842 | int err; |
4c476991 | 2843 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2844 | u8 key_idx = 0; |
e31b8213 JB |
2845 | const u8 *mac_addr = NULL; |
2846 | bool pairwise; | |
41ade00f JB |
2847 | struct get_key_cookie cookie = { |
2848 | .error = 0, | |
2849 | }; | |
2850 | void *hdr; | |
2851 | struct sk_buff *msg; | |
2852 | ||
2853 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2854 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2855 | ||
3cfcf6ac | 2856 | if (key_idx > 5) |
41ade00f JB |
2857 | return -EINVAL; |
2858 | ||
2859 | if (info->attrs[NL80211_ATTR_MAC]) | |
2860 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2861 | ||
e31b8213 JB |
2862 | pairwise = !!mac_addr; |
2863 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2864 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2865 | if (kt >= NUM_NL80211_KEYTYPES) | |
2866 | return -EINVAL; | |
2867 | if (kt != NL80211_KEYTYPE_GROUP && | |
2868 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2869 | return -EINVAL; | |
2870 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2871 | } | |
2872 | ||
4c476991 JB |
2873 | if (!rdev->ops->get_key) |
2874 | return -EOPNOTSUPP; | |
41ade00f | 2875 | |
0fa7b391 JB |
2876 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
2877 | return -ENOENT; | |
2878 | ||
fd2120ca | 2879 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2880 | if (!msg) |
2881 | return -ENOMEM; | |
41ade00f | 2882 | |
15e47304 | 2883 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2884 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 2885 | if (!hdr) |
9fe271af | 2886 | goto nla_put_failure; |
41ade00f JB |
2887 | |
2888 | cookie.msg = msg; | |
b9454e83 | 2889 | cookie.idx = key_idx; |
41ade00f | 2890 | |
9360ffd1 DM |
2891 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2892 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2893 | goto nla_put_failure; | |
2894 | if (mac_addr && | |
2895 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2896 | goto nla_put_failure; | |
41ade00f | 2897 | |
e35e4d28 HG |
2898 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2899 | get_key_callback); | |
41ade00f JB |
2900 | |
2901 | if (err) | |
6c95e2a2 | 2902 | goto free_msg; |
41ade00f JB |
2903 | |
2904 | if (cookie.error) | |
2905 | goto nla_put_failure; | |
2906 | ||
2907 | genlmsg_end(msg, hdr); | |
4c476991 | 2908 | return genlmsg_reply(msg, info); |
41ade00f JB |
2909 | |
2910 | nla_put_failure: | |
2911 | err = -ENOBUFS; | |
6c95e2a2 | 2912 | free_msg: |
41ade00f | 2913 | nlmsg_free(msg); |
41ade00f JB |
2914 | return err; |
2915 | } | |
2916 | ||
2917 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2918 | { | |
4c476991 | 2919 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2920 | struct key_parse key; |
41ade00f | 2921 | int err; |
4c476991 | 2922 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2923 | |
b9454e83 JB |
2924 | err = nl80211_parse_key(info, &key); |
2925 | if (err) | |
2926 | return err; | |
41ade00f | 2927 | |
b9454e83 | 2928 | if (key.idx < 0) |
41ade00f JB |
2929 | return -EINVAL; |
2930 | ||
b9454e83 JB |
2931 | /* only support setting default key */ |
2932 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2933 | return -EINVAL; |
2934 | ||
dbd2fd65 | 2935 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2936 | |
dbd2fd65 JB |
2937 | if (key.def) { |
2938 | if (!rdev->ops->set_default_key) { | |
2939 | err = -EOPNOTSUPP; | |
2940 | goto out; | |
2941 | } | |
41ade00f | 2942 | |
dbd2fd65 JB |
2943 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2944 | if (err) | |
2945 | goto out; | |
2946 | ||
e35e4d28 | 2947 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2948 | key.def_uni, key.def_multi); |
2949 | ||
2950 | if (err) | |
2951 | goto out; | |
fffd0934 | 2952 | |
3d23e349 | 2953 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2954 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2955 | #endif | |
2956 | } else { | |
2957 | if (key.def_uni || !key.def_multi) { | |
2958 | err = -EINVAL; | |
2959 | goto out; | |
2960 | } | |
2961 | ||
2962 | if (!rdev->ops->set_default_mgmt_key) { | |
2963 | err = -EOPNOTSUPP; | |
2964 | goto out; | |
2965 | } | |
2966 | ||
2967 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2968 | if (err) | |
2969 | goto out; | |
2970 | ||
e35e4d28 | 2971 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2972 | if (err) |
2973 | goto out; | |
2974 | ||
2975 | #ifdef CONFIG_CFG80211_WEXT | |
2976 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2977 | #endif |
dbd2fd65 JB |
2978 | } |
2979 | ||
2980 | out: | |
fffd0934 | 2981 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2982 | |
41ade00f JB |
2983 | return err; |
2984 | } | |
2985 | ||
2986 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2987 | { | |
4c476991 | 2988 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2989 | int err; |
4c476991 | 2990 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2991 | struct key_parse key; |
e31b8213 | 2992 | const u8 *mac_addr = NULL; |
41ade00f | 2993 | |
b9454e83 JB |
2994 | err = nl80211_parse_key(info, &key); |
2995 | if (err) | |
2996 | return err; | |
41ade00f | 2997 | |
b9454e83 | 2998 | if (!key.p.key) |
41ade00f JB |
2999 | return -EINVAL; |
3000 | ||
41ade00f JB |
3001 | if (info->attrs[NL80211_ATTR_MAC]) |
3002 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3003 | ||
e31b8213 JB |
3004 | if (key.type == -1) { |
3005 | if (mac_addr) | |
3006 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3007 | else | |
3008 | key.type = NL80211_KEYTYPE_GROUP; | |
3009 | } | |
3010 | ||
3011 | /* for now */ | |
3012 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3013 | key.type != NL80211_KEYTYPE_GROUP) | |
3014 | return -EINVAL; | |
3015 | ||
4c476991 JB |
3016 | if (!rdev->ops->add_key) |
3017 | return -EOPNOTSUPP; | |
25e47c18 | 3018 | |
e31b8213 JB |
3019 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
3020 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3021 | mac_addr)) | |
4c476991 | 3022 | return -EINVAL; |
41ade00f | 3023 | |
fffd0934 JB |
3024 | wdev_lock(dev->ieee80211_ptr); |
3025 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3026 | if (!err) | |
e35e4d28 HG |
3027 | err = rdev_add_key(rdev, dev, key.idx, |
3028 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3029 | mac_addr, &key.p); | |
fffd0934 | 3030 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3031 | |
41ade00f JB |
3032 | return err; |
3033 | } | |
3034 | ||
3035 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
3036 | { | |
4c476991 | 3037 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3038 | int err; |
4c476991 | 3039 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3040 | u8 *mac_addr = NULL; |
b9454e83 | 3041 | struct key_parse key; |
41ade00f | 3042 | |
b9454e83 JB |
3043 | err = nl80211_parse_key(info, &key); |
3044 | if (err) | |
3045 | return err; | |
41ade00f JB |
3046 | |
3047 | if (info->attrs[NL80211_ATTR_MAC]) | |
3048 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3049 | ||
e31b8213 JB |
3050 | if (key.type == -1) { |
3051 | if (mac_addr) | |
3052 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3053 | else | |
3054 | key.type = NL80211_KEYTYPE_GROUP; | |
3055 | } | |
3056 | ||
3057 | /* for now */ | |
3058 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3059 | key.type != NL80211_KEYTYPE_GROUP) | |
3060 | return -EINVAL; | |
3061 | ||
4c476991 JB |
3062 | if (!rdev->ops->del_key) |
3063 | return -EOPNOTSUPP; | |
41ade00f | 3064 | |
fffd0934 JB |
3065 | wdev_lock(dev->ieee80211_ptr); |
3066 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 | 3067 | |
0fa7b391 | 3068 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
e31b8213 JB |
3069 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
3070 | err = -ENOENT; | |
3071 | ||
fffd0934 | 3072 | if (!err) |
e35e4d28 HG |
3073 | err = rdev_del_key(rdev, dev, key.idx, |
3074 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3075 | mac_addr); | |
41ade00f | 3076 | |
3d23e349 | 3077 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 3078 | if (!err) { |
b9454e83 | 3079 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 3080 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 3081 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
3082 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
3083 | } | |
3084 | #endif | |
fffd0934 | 3085 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 3086 | |
41ade00f JB |
3087 | return err; |
3088 | } | |
3089 | ||
77765eaf VT |
3090 | /* This function returns an error or the number of nested attributes */ |
3091 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
3092 | { | |
3093 | struct nlattr *attr; | |
3094 | int n_entries = 0, tmp; | |
3095 | ||
3096 | nla_for_each_nested(attr, nl_attr, tmp) { | |
3097 | if (nla_len(attr) != ETH_ALEN) | |
3098 | return -EINVAL; | |
3099 | ||
3100 | n_entries++; | |
3101 | } | |
3102 | ||
3103 | return n_entries; | |
3104 | } | |
3105 | ||
3106 | /* | |
3107 | * This function parses ACL information and allocates memory for ACL data. | |
3108 | * On successful return, the calling function is responsible to free the | |
3109 | * ACL buffer returned by this function. | |
3110 | */ | |
3111 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3112 | struct genl_info *info) | |
3113 | { | |
3114 | enum nl80211_acl_policy acl_policy; | |
3115 | struct nlattr *attr; | |
3116 | struct cfg80211_acl_data *acl; | |
3117 | int i = 0, n_entries, tmp; | |
3118 | ||
3119 | if (!wiphy->max_acl_mac_addrs) | |
3120 | return ERR_PTR(-EOPNOTSUPP); | |
3121 | ||
3122 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3123 | return ERR_PTR(-EINVAL); | |
3124 | ||
3125 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3126 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3127 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3128 | return ERR_PTR(-EINVAL); | |
3129 | ||
3130 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3131 | return ERR_PTR(-EINVAL); | |
3132 | ||
3133 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3134 | if (n_entries < 0) | |
3135 | return ERR_PTR(n_entries); | |
3136 | ||
3137 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3138 | return ERR_PTR(-ENOTSUPP); | |
3139 | ||
3140 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
3141 | GFP_KERNEL); | |
3142 | if (!acl) | |
3143 | return ERR_PTR(-ENOMEM); | |
3144 | ||
3145 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3146 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3147 | i++; | |
3148 | } | |
3149 | ||
3150 | acl->n_acl_entries = n_entries; | |
3151 | acl->acl_policy = acl_policy; | |
3152 | ||
3153 | return acl; | |
3154 | } | |
3155 | ||
3156 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3157 | { | |
3158 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3159 | struct net_device *dev = info->user_ptr[1]; | |
3160 | struct cfg80211_acl_data *acl; | |
3161 | int err; | |
3162 | ||
3163 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3164 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3165 | return -EOPNOTSUPP; | |
3166 | ||
3167 | if (!dev->ieee80211_ptr->beacon_interval) | |
3168 | return -EINVAL; | |
3169 | ||
3170 | acl = parse_acl_data(&rdev->wiphy, info); | |
3171 | if (IS_ERR(acl)) | |
3172 | return PTR_ERR(acl); | |
3173 | ||
3174 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3175 | ||
3176 | kfree(acl); | |
3177 | ||
3178 | return err; | |
3179 | } | |
3180 | ||
a1193be8 | 3181 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3182 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3183 | { |
8860020e | 3184 | bool haveinfo = false; |
ed1b6cc7 | 3185 | |
a1193be8 SW |
3186 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3187 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3188 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3189 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3190 | return -EINVAL; |
3191 | ||
8860020e | 3192 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3193 | |
a1193be8 SW |
3194 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3195 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3196 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3197 | if (!bcn->head_len) |
3198 | return -EINVAL; | |
3199 | haveinfo = true; | |
ed1b6cc7 JB |
3200 | } |
3201 | ||
a1193be8 SW |
3202 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3203 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3204 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3205 | haveinfo = true; |
ed1b6cc7 JB |
3206 | } |
3207 | ||
4c476991 JB |
3208 | if (!haveinfo) |
3209 | return -EINVAL; | |
3b85875a | 3210 | |
a1193be8 SW |
3211 | if (attrs[NL80211_ATTR_IE]) { |
3212 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3213 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3214 | } |
3215 | ||
a1193be8 | 3216 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3217 | bcn->proberesp_ies = |
a1193be8 | 3218 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3219 | bcn->proberesp_ies_len = |
a1193be8 | 3220 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3221 | } |
3222 | ||
a1193be8 | 3223 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3224 | bcn->assocresp_ies = |
a1193be8 | 3225 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3226 | bcn->assocresp_ies_len = |
a1193be8 | 3227 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3228 | } |
3229 | ||
a1193be8 SW |
3230 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3231 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3232 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3233 | } |
3234 | ||
8860020e JB |
3235 | return 0; |
3236 | } | |
3237 | ||
46c1dd0c FF |
3238 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3239 | struct cfg80211_ap_settings *params) | |
3240 | { | |
3241 | struct wireless_dev *wdev; | |
3242 | bool ret = false; | |
3243 | ||
89a54e48 | 3244 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3245 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3246 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3247 | continue; | |
3248 | ||
683b6d3b | 3249 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3250 | continue; |
3251 | ||
683b6d3b | 3252 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3253 | ret = true; |
3254 | break; | |
3255 | } | |
3256 | ||
46c1dd0c FF |
3257 | return ret; |
3258 | } | |
3259 | ||
e39e5b5e JM |
3260 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3261 | enum nl80211_auth_type auth_type, | |
3262 | enum nl80211_commands cmd) | |
3263 | { | |
3264 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3265 | return false; | |
3266 | ||
3267 | switch (cmd) { | |
3268 | case NL80211_CMD_AUTHENTICATE: | |
3269 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3270 | auth_type == NL80211_AUTHTYPE_SAE) | |
3271 | return false; | |
3272 | return true; | |
3273 | case NL80211_CMD_CONNECT: | |
3274 | case NL80211_CMD_START_AP: | |
3275 | /* SAE not supported yet */ | |
3276 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3277 | return false; | |
3278 | return true; | |
3279 | default: | |
3280 | return false; | |
3281 | } | |
3282 | } | |
3283 | ||
8860020e JB |
3284 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3285 | { | |
3286 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3287 | struct net_device *dev = info->user_ptr[1]; | |
3288 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3289 | struct cfg80211_ap_settings params; | |
3290 | int err; | |
3291 | ||
3292 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3293 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3294 | return -EOPNOTSUPP; | |
3295 | ||
3296 | if (!rdev->ops->start_ap) | |
3297 | return -EOPNOTSUPP; | |
3298 | ||
3299 | if (wdev->beacon_interval) | |
3300 | return -EALREADY; | |
3301 | ||
3302 | memset(¶ms, 0, sizeof(params)); | |
3303 | ||
3304 | /* these are required for START_AP */ | |
3305 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3306 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3307 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3308 | return -EINVAL; | |
3309 | ||
a1193be8 | 3310 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3311 | if (err) |
3312 | return err; | |
3313 | ||
3314 | params.beacon_interval = | |
3315 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3316 | params.dtim_period = | |
3317 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3318 | ||
3319 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3320 | if (err) | |
3321 | return err; | |
3322 | ||
3323 | /* | |
3324 | * In theory, some of these attributes should be required here | |
3325 | * but since they were not used when the command was originally | |
3326 | * added, keep them optional for old user space programs to let | |
3327 | * them continue to work with drivers that do not need the | |
3328 | * additional information -- drivers must check! | |
3329 | */ | |
3330 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3331 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3332 | params.ssid_len = | |
3333 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3334 | if (params.ssid_len == 0 || | |
3335 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3336 | return -EINVAL; | |
3337 | } | |
3338 | ||
3339 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3340 | params.hidden_ssid = nla_get_u32( | |
3341 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3342 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3343 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3344 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3345 | return -EINVAL; | |
3346 | } | |
3347 | ||
3348 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3349 | ||
3350 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3351 | params.auth_type = nla_get_u32( | |
3352 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3353 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3354 | NL80211_CMD_START_AP)) | |
8860020e JB |
3355 | return -EINVAL; |
3356 | } else | |
3357 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3358 | ||
3359 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3360 | NL80211_MAX_NR_CIPHER_SUITES); | |
3361 | if (err) | |
3362 | return err; | |
3363 | ||
1b658f11 VT |
3364 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3365 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3366 | return -EOPNOTSUPP; | |
3367 | params.inactivity_timeout = nla_get_u16( | |
3368 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3369 | } | |
3370 | ||
53cabad7 JB |
3371 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3372 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3373 | return -EINVAL; | |
3374 | params.p2p_ctwindow = | |
3375 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3376 | if (params.p2p_ctwindow > 127) | |
3377 | return -EINVAL; | |
3378 | if (params.p2p_ctwindow != 0 && | |
3379 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3380 | return -EINVAL; | |
3381 | } | |
3382 | ||
3383 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3384 | u8 tmp; | |
3385 | ||
3386 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3387 | return -EINVAL; | |
3388 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3389 | if (tmp > 1) | |
3390 | return -EINVAL; | |
3391 | params.p2p_opp_ps = tmp; | |
3392 | if (params.p2p_opp_ps != 0 && | |
3393 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3394 | return -EINVAL; | |
3395 | } | |
3396 | ||
aa430da4 | 3397 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3398 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3399 | if (err) | |
3400 | return err; | |
3401 | } else if (wdev->preset_chandef.chan) { | |
3402 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3403 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3404 | return -EINVAL; |
3405 | ||
174e0cd2 IP |
3406 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
3407 | wdev->iftype)) | |
aa430da4 JB |
3408 | return -EINVAL; |
3409 | ||
77765eaf VT |
3410 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3411 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3412 | if (IS_ERR(params.acl)) | |
3413 | return PTR_ERR(params.acl); | |
3414 | } | |
3415 | ||
18998c38 EP |
3416 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
3417 | params.smps_mode = | |
3418 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); | |
3419 | switch (params.smps_mode) { | |
3420 | case NL80211_SMPS_OFF: | |
3421 | break; | |
3422 | case NL80211_SMPS_STATIC: | |
3423 | if (!(rdev->wiphy.features & | |
3424 | NL80211_FEATURE_STATIC_SMPS)) | |
3425 | return -EINVAL; | |
3426 | break; | |
3427 | case NL80211_SMPS_DYNAMIC: | |
3428 | if (!(rdev->wiphy.features & | |
3429 | NL80211_FEATURE_DYNAMIC_SMPS)) | |
3430 | return -EINVAL; | |
3431 | break; | |
3432 | default: | |
3433 | return -EINVAL; | |
3434 | } | |
3435 | } else { | |
3436 | params.smps_mode = NL80211_SMPS_OFF; | |
3437 | } | |
3438 | ||
c56589ed | 3439 | wdev_lock(wdev); |
e35e4d28 | 3440 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3441 | if (!err) { |
683b6d3b | 3442 | wdev->preset_chandef = params.chandef; |
8860020e | 3443 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 3444 | wdev->chandef = params.chandef; |
06e191e2 AQ |
3445 | wdev->ssid_len = params.ssid_len; |
3446 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3447 | } |
c56589ed | 3448 | wdev_unlock(wdev); |
77765eaf VT |
3449 | |
3450 | kfree(params.acl); | |
3451 | ||
56d1893d | 3452 | return err; |
ed1b6cc7 JB |
3453 | } |
3454 | ||
8860020e JB |
3455 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3456 | { | |
3457 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3458 | struct net_device *dev = info->user_ptr[1]; | |
3459 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3460 | struct cfg80211_beacon_data params; | |
3461 | int err; | |
3462 | ||
3463 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3464 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3465 | return -EOPNOTSUPP; | |
3466 | ||
3467 | if (!rdev->ops->change_beacon) | |
3468 | return -EOPNOTSUPP; | |
3469 | ||
3470 | if (!wdev->beacon_interval) | |
3471 | return -EINVAL; | |
3472 | ||
a1193be8 | 3473 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3474 | if (err) |
3475 | return err; | |
3476 | ||
c56589ed SW |
3477 | wdev_lock(wdev); |
3478 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3479 | wdev_unlock(wdev); | |
3480 | ||
3481 | return err; | |
8860020e JB |
3482 | } |
3483 | ||
3484 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3485 | { |
4c476991 JB |
3486 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3487 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3488 | |
7c8d5e03 | 3489 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
3490 | } |
3491 | ||
5727ef1b JB |
3492 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3493 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3494 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3495 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3496 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3497 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3498 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3499 | }; |
3500 | ||
eccb8e8f | 3501 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3502 | enum nl80211_iftype iftype, |
eccb8e8f | 3503 | struct station_parameters *params) |
5727ef1b JB |
3504 | { |
3505 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3506 | struct nlattr *nla; |
5727ef1b JB |
3507 | int flag; |
3508 | ||
eccb8e8f JB |
3509 | /* |
3510 | * Try parsing the new attribute first so userspace | |
3511 | * can specify both for older kernels. | |
3512 | */ | |
3513 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3514 | if (nla) { | |
3515 | struct nl80211_sta_flag_update *sta_flags; | |
3516 | ||
3517 | sta_flags = nla_data(nla); | |
3518 | params->sta_flags_mask = sta_flags->mask; | |
3519 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3520 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3521 | if ((params->sta_flags_mask | |
3522 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3523 | return -EINVAL; | |
3524 | return 0; | |
3525 | } | |
3526 | ||
3527 | /* if present, parse the old attribute */ | |
5727ef1b | 3528 | |
eccb8e8f | 3529 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3530 | if (!nla) |
3531 | return 0; | |
3532 | ||
3533 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3534 | nla, sta_flags_policy)) | |
3535 | return -EINVAL; | |
3536 | ||
bdd3ae3d JB |
3537 | /* |
3538 | * Only allow certain flags for interface types so that | |
3539 | * other attributes are silently ignored. Remember that | |
3540 | * this is backward compatibility code with old userspace | |
3541 | * and shouldn't be hit in other cases anyway. | |
3542 | */ | |
3543 | switch (iftype) { | |
3544 | case NL80211_IFTYPE_AP: | |
3545 | case NL80211_IFTYPE_AP_VLAN: | |
3546 | case NL80211_IFTYPE_P2P_GO: | |
3547 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3548 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3549 | BIT(NL80211_STA_FLAG_WME) | | |
3550 | BIT(NL80211_STA_FLAG_MFP); | |
3551 | break; | |
3552 | case NL80211_IFTYPE_P2P_CLIENT: | |
3553 | case NL80211_IFTYPE_STATION: | |
3554 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3555 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3556 | break; | |
3557 | case NL80211_IFTYPE_MESH_POINT: | |
3558 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3559 | BIT(NL80211_STA_FLAG_MFP) | | |
3560 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3561 | default: | |
3562 | return -EINVAL; | |
3563 | } | |
5727ef1b | 3564 | |
3383b5a6 JB |
3565 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3566 | if (flags[flag]) { | |
eccb8e8f | 3567 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3568 | |
3383b5a6 JB |
3569 | /* no longer support new API additions in old API */ |
3570 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3571 | return -EINVAL; | |
3572 | } | |
3573 | } | |
3574 | ||
5727ef1b JB |
3575 | return 0; |
3576 | } | |
3577 | ||
c8dcfd8a FF |
3578 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3579 | int attr) | |
3580 | { | |
3581 | struct nlattr *rate; | |
8eb41c8d VK |
3582 | u32 bitrate; |
3583 | u16 bitrate_compat; | |
b51f3bee | 3584 | enum nl80211_attrs rate_flg; |
c8dcfd8a FF |
3585 | |
3586 | rate = nla_nest_start(msg, attr); | |
3587 | if (!rate) | |
db9c64cf | 3588 | return false; |
c8dcfd8a FF |
3589 | |
3590 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3591 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3592 | /* report 16-bit bitrate only if we can */ |
3593 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3594 | if (bitrate > 0 && |
3595 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3596 | return false; | |
3597 | if (bitrate_compat > 0 && | |
3598 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3599 | return false; | |
3600 | ||
b51f3bee JB |
3601 | switch (info->bw) { |
3602 | case RATE_INFO_BW_5: | |
3603 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; | |
3604 | break; | |
3605 | case RATE_INFO_BW_10: | |
3606 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; | |
3607 | break; | |
3608 | default: | |
3609 | WARN_ON(1); | |
3610 | /* fall through */ | |
3611 | case RATE_INFO_BW_20: | |
3612 | rate_flg = 0; | |
3613 | break; | |
3614 | case RATE_INFO_BW_40: | |
3615 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; | |
3616 | break; | |
3617 | case RATE_INFO_BW_80: | |
3618 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; | |
3619 | break; | |
3620 | case RATE_INFO_BW_160: | |
3621 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; | |
3622 | break; | |
3623 | } | |
3624 | ||
3625 | if (rate_flg && nla_put_flag(msg, rate_flg)) | |
3626 | return false; | |
3627 | ||
db9c64cf JB |
3628 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
3629 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3630 | return false; | |
db9c64cf JB |
3631 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
3632 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3633 | return false; | |
3634 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3635 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3636 | return false; | |
3637 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3638 | return false; | |
db9c64cf JB |
3639 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
3640 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3641 | return false; | |
3642 | } | |
c8dcfd8a FF |
3643 | |
3644 | nla_nest_end(msg, rate); | |
3645 | return true; | |
c8dcfd8a FF |
3646 | } |
3647 | ||
119363c7 FF |
3648 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3649 | int id) | |
3650 | { | |
3651 | void *attr; | |
3652 | int i = 0; | |
3653 | ||
3654 | if (!mask) | |
3655 | return true; | |
3656 | ||
3657 | attr = nla_nest_start(msg, id); | |
3658 | if (!attr) | |
3659 | return false; | |
3660 | ||
3661 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3662 | if (!(mask & BIT(i))) | |
3663 | continue; | |
3664 | ||
3665 | if (nla_put_u8(msg, i, signal[i])) | |
3666 | return false; | |
3667 | } | |
3668 | ||
3669 | nla_nest_end(msg, attr); | |
3670 | ||
3671 | return true; | |
3672 | } | |
3673 | ||
cf5ead82 JB |
3674 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
3675 | u32 seq, int flags, | |
66266b3a JL |
3676 | struct cfg80211_registered_device *rdev, |
3677 | struct net_device *dev, | |
98b62183 | 3678 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3679 | { |
3680 | void *hdr; | |
f4263c98 | 3681 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3682 | |
cf5ead82 | 3683 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
fd5b74dc JB |
3684 | if (!hdr) |
3685 | return -1; | |
3686 | ||
9360ffd1 DM |
3687 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3688 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3689 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3690 | goto nla_put_failure; | |
f5ea9120 | 3691 | |
2ec600d6 LCC |
3692 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3693 | if (!sinfoattr) | |
fd5b74dc | 3694 | goto nla_put_failure; |
319090bf JB |
3695 | |
3696 | #define PUT_SINFO(attr, memb, type) do { \ | |
3697 | if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \ | |
3698 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ | |
3699 | sinfo->memb)) \ | |
3700 | goto nla_put_failure; \ | |
3701 | } while (0) | |
3702 | ||
3703 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); | |
3704 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); | |
3705 | ||
3706 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | | |
3707 | BIT(NL80211_STA_INFO_RX_BYTES64)) && | |
9360ffd1 | 3708 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3709 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3710 | goto nla_put_failure; |
319090bf JB |
3711 | |
3712 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | | |
3713 | BIT(NL80211_STA_INFO_TX_BYTES64)) && | |
9360ffd1 | 3714 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3715 | (u32)sinfo->tx_bytes)) |
3716 | goto nla_put_failure; | |
319090bf JB |
3717 | |
3718 | PUT_SINFO(RX_BYTES64, rx_bytes, u64); | |
3719 | PUT_SINFO(TX_BYTES64, tx_bytes, u64); | |
3720 | PUT_SINFO(LLID, llid, u16); | |
3721 | PUT_SINFO(PLID, plid, u16); | |
3722 | PUT_SINFO(PLINK_STATE, plink_state, u8); | |
3723 | ||
66266b3a JL |
3724 | switch (rdev->wiphy.signal_type) { |
3725 | case CFG80211_SIGNAL_TYPE_MBM: | |
319090bf JB |
3726 | PUT_SINFO(SIGNAL, signal, u8); |
3727 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); | |
66266b3a JL |
3728 | break; |
3729 | default: | |
3730 | break; | |
3731 | } | |
319090bf | 3732 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
119363c7 FF |
3733 | if (!nl80211_put_signal(msg, sinfo->chains, |
3734 | sinfo->chain_signal, | |
3735 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3736 | goto nla_put_failure; | |
3737 | } | |
319090bf | 3738 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
119363c7 FF |
3739 | if (!nl80211_put_signal(msg, sinfo->chains, |
3740 | sinfo->chain_signal_avg, | |
3741 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3742 | goto nla_put_failure; | |
3743 | } | |
319090bf | 3744 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
c8dcfd8a FF |
3745 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3746 | NL80211_STA_INFO_TX_BITRATE)) | |
3747 | goto nla_put_failure; | |
3748 | } | |
319090bf | 3749 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
c8dcfd8a FF |
3750 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
3751 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3752 | goto nla_put_failure; |
420e7fab | 3753 | } |
319090bf JB |
3754 | |
3755 | PUT_SINFO(RX_PACKETS, rx_packets, u32); | |
3756 | PUT_SINFO(TX_PACKETS, tx_packets, u32); | |
3757 | PUT_SINFO(TX_RETRIES, tx_retries, u32); | |
3758 | PUT_SINFO(TX_FAILED, tx_failed, u32); | |
3759 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); | |
3760 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); | |
3761 | PUT_SINFO(LOCAL_PM, local_pm, u32); | |
3762 | PUT_SINFO(PEER_PM, peer_pm, u32); | |
3763 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); | |
3764 | ||
3765 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { | |
f4263c98 PS |
3766 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
3767 | if (!bss_param) | |
3768 | goto nla_put_failure; | |
3769 | ||
9360ffd1 DM |
3770 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3771 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3772 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3773 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3774 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3775 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3776 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3777 | sinfo->bss_param.dtim_period) || | |
3778 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3779 | sinfo->bss_param.beacon_interval)) | |
3780 | goto nla_put_failure; | |
f4263c98 PS |
3781 | |
3782 | nla_nest_end(msg, bss_param); | |
3783 | } | |
319090bf | 3784 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
9360ffd1 DM |
3785 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
3786 | sizeof(struct nl80211_sta_flag_update), | |
3787 | &sinfo->sta_flags)) | |
3788 | goto nla_put_failure; | |
319090bf JB |
3789 | |
3790 | PUT_SINFO(T_OFFSET, t_offset, u64); | |
3791 | PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64); | |
a76b1942 JB |
3792 | PUT_SINFO(BEACON_RX, rx_beacon, u64); |
3793 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); | |
319090bf JB |
3794 | |
3795 | #undef PUT_SINFO | |
6de39808 JB |
3796 | |
3797 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { | |
3798 | struct nlattr *tidsattr; | |
3799 | int tid; | |
3800 | ||
3801 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); | |
3802 | if (!tidsattr) | |
3803 | goto nla_put_failure; | |
3804 | ||
3805 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { | |
3806 | struct cfg80211_tid_stats *tidstats; | |
3807 | struct nlattr *tidattr; | |
3808 | ||
3809 | tidstats = &sinfo->pertid[tid]; | |
3810 | ||
3811 | if (!tidstats->filled) | |
3812 | continue; | |
3813 | ||
3814 | tidattr = nla_nest_start(msg, tid + 1); | |
3815 | if (!tidattr) | |
3816 | goto nla_put_failure; | |
3817 | ||
3818 | #define PUT_TIDVAL(attr, memb, type) do { \ | |
3819 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ | |
3820 | nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \ | |
3821 | tidstats->memb)) \ | |
3822 | goto nla_put_failure; \ | |
3823 | } while (0) | |
3824 | ||
3825 | PUT_TIDVAL(RX_MSDU, rx_msdu, u64); | |
3826 | PUT_TIDVAL(TX_MSDU, tx_msdu, u64); | |
3827 | PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64); | |
3828 | PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64); | |
3829 | ||
3830 | #undef PUT_TIDVAL | |
3831 | nla_nest_end(msg, tidattr); | |
3832 | } | |
3833 | ||
3834 | nla_nest_end(msg, tidsattr); | |
3835 | } | |
3836 | ||
2ec600d6 | 3837 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3838 | |
319090bf | 3839 | if (sinfo->assoc_req_ies_len && |
9360ffd1 DM |
3840 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
3841 | sinfo->assoc_req_ies)) | |
3842 | goto nla_put_failure; | |
50d3dfb7 | 3843 | |
053c095a JB |
3844 | genlmsg_end(msg, hdr); |
3845 | return 0; | |
fd5b74dc JB |
3846 | |
3847 | nla_put_failure: | |
bc3ed28c TG |
3848 | genlmsg_cancel(msg, hdr); |
3849 | return -EMSGSIZE; | |
fd5b74dc JB |
3850 | } |
3851 | ||
2ec600d6 | 3852 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3853 | struct netlink_callback *cb) |
2ec600d6 | 3854 | { |
2ec600d6 | 3855 | struct station_info sinfo; |
1b8ec87a | 3856 | struct cfg80211_registered_device *rdev; |
97990a06 | 3857 | struct wireless_dev *wdev; |
2ec600d6 | 3858 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3859 | int sta_idx = cb->args[2]; |
2ec600d6 | 3860 | int err; |
2ec600d6 | 3861 | |
1b8ec87a | 3862 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
3863 | if (err) |
3864 | return err; | |
bba95fef | 3865 | |
97990a06 JB |
3866 | if (!wdev->netdev) { |
3867 | err = -EINVAL; | |
3868 | goto out_err; | |
3869 | } | |
3870 | ||
1b8ec87a | 3871 | if (!rdev->ops->dump_station) { |
eec60b03 | 3872 | err = -EOPNOTSUPP; |
bba95fef JB |
3873 | goto out_err; |
3874 | } | |
3875 | ||
bba95fef | 3876 | while (1) { |
f612cedf | 3877 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 3878 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
e35e4d28 | 3879 | mac_addr, &sinfo); |
bba95fef JB |
3880 | if (err == -ENOENT) |
3881 | break; | |
3882 | if (err) | |
3b85875a | 3883 | goto out_err; |
bba95fef | 3884 | |
cf5ead82 | 3885 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
15e47304 | 3886 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3887 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 3888 | rdev, wdev->netdev, mac_addr, |
bba95fef JB |
3889 | &sinfo) < 0) |
3890 | goto out; | |
3891 | ||
3892 | sta_idx++; | |
3893 | } | |
3894 | ||
3895 | ||
3896 | out: | |
97990a06 | 3897 | cb->args[2] = sta_idx; |
bba95fef | 3898 | err = skb->len; |
bba95fef | 3899 | out_err: |
1b8ec87a | 3900 | nl80211_finish_wdev_dump(rdev); |
bba95fef JB |
3901 | |
3902 | return err; | |
2ec600d6 | 3903 | } |
fd5b74dc | 3904 | |
5727ef1b JB |
3905 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3906 | { | |
4c476991 JB |
3907 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3908 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3909 | struct station_info sinfo; |
fd5b74dc JB |
3910 | struct sk_buff *msg; |
3911 | u8 *mac_addr = NULL; | |
4c476991 | 3912 | int err; |
fd5b74dc | 3913 | |
2ec600d6 | 3914 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3915 | |
3916 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3917 | return -EINVAL; | |
3918 | ||
3919 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3920 | ||
4c476991 JB |
3921 | if (!rdev->ops->get_station) |
3922 | return -EOPNOTSUPP; | |
3b85875a | 3923 | |
e35e4d28 | 3924 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3925 | if (err) |
4c476991 | 3926 | return err; |
2ec600d6 | 3927 | |
fd2120ca | 3928 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3929 | if (!msg) |
4c476991 | 3930 | return -ENOMEM; |
fd5b74dc | 3931 | |
cf5ead82 JB |
3932 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
3933 | info->snd_portid, info->snd_seq, 0, | |
66266b3a | 3934 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3935 | nlmsg_free(msg); |
3936 | return -ENOBUFS; | |
3937 | } | |
3b85875a | 3938 | |
4c476991 | 3939 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3940 | } |
3941 | ||
77ee7c89 JB |
3942 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3943 | struct station_parameters *params, | |
3944 | enum cfg80211_station_type statype) | |
3945 | { | |
3946 | if (params->listen_interval != -1) | |
3947 | return -EINVAL; | |
c72e1140 AN |
3948 | if (params->aid && |
3949 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
77ee7c89 JB |
3950 | return -EINVAL; |
3951 | ||
3952 | /* When you run into this, adjust the code below for the new flag */ | |
3953 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3954 | ||
3955 | switch (statype) { | |
eef941e6 TP |
3956 | case CFG80211_STA_MESH_PEER_KERNEL: |
3957 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3958 | /* |
3959 | * No ignoring the TDLS flag here -- the userspace mesh | |
3960 | * code doesn't have the bug of including TDLS in the | |
3961 | * mask everywhere. | |
3962 | */ | |
3963 | if (params->sta_flags_mask & | |
3964 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3965 | BIT(NL80211_STA_FLAG_MFP) | | |
3966 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3967 | return -EINVAL; | |
3968 | break; | |
3969 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3970 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3971 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3972 | return -EINVAL; | |
3973 | /* ignore since it can't change */ | |
3974 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3975 | break; | |
3976 | default: | |
3977 | /* disallow mesh-specific things */ | |
3978 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3979 | return -EINVAL; | |
3980 | if (params->local_pm) | |
3981 | return -EINVAL; | |
3982 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3983 | return -EINVAL; | |
3984 | } | |
3985 | ||
3986 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3987 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3988 | /* TDLS can't be set, ... */ | |
3989 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3990 | return -EINVAL; | |
3991 | /* | |
3992 | * ... but don't bother the driver with it. This works around | |
3993 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3994 | * TLDS_PEER flag in the mask even for AP mode. | |
3995 | */ | |
3996 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3997 | } | |
3998 | ||
3999 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
4000 | /* reject other things that can't change */ | |
4001 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
4002 | return -EINVAL; | |
4003 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
4004 | return -EINVAL; | |
4005 | if (params->supported_rates) | |
4006 | return -EINVAL; | |
4007 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
4008 | return -EINVAL; | |
4009 | } | |
4010 | ||
4011 | if (statype != CFG80211_STA_AP_CLIENT) { | |
4012 | if (params->vlan) | |
4013 | return -EINVAL; | |
4014 | } | |
4015 | ||
4016 | switch (statype) { | |
4017 | case CFG80211_STA_AP_MLME_CLIENT: | |
4018 | /* Use this only for authorizing/unauthorizing a station */ | |
4019 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
4020 | return -EOPNOTSUPP; | |
4021 | break; | |
4022 | case CFG80211_STA_AP_CLIENT: | |
4023 | /* accept only the listed bits */ | |
4024 | if (params->sta_flags_mask & | |
4025 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4026 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4027 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4028 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
4029 | BIT(NL80211_STA_FLAG_WME) | | |
4030 | BIT(NL80211_STA_FLAG_MFP))) | |
4031 | return -EINVAL; | |
4032 | ||
4033 | /* but authenticated/associated only if driver handles it */ | |
4034 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4035 | params->sta_flags_mask & | |
4036 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4037 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4038 | return -EINVAL; | |
4039 | break; | |
4040 | case CFG80211_STA_IBSS: | |
4041 | case CFG80211_STA_AP_STA: | |
4042 | /* reject any changes other than AUTHORIZED */ | |
4043 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
4044 | return -EINVAL; | |
4045 | break; | |
4046 | case CFG80211_STA_TDLS_PEER_SETUP: | |
4047 | /* reject any changes other than AUTHORIZED or WME */ | |
4048 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4049 | BIT(NL80211_STA_FLAG_WME))) | |
4050 | return -EINVAL; | |
4051 | /* force (at least) rates when authorizing */ | |
4052 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
4053 | !params->supported_rates) | |
4054 | return -EINVAL; | |
4055 | break; | |
4056 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
4057 | /* reject any changes */ | |
4058 | return -EINVAL; | |
eef941e6 | 4059 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
4060 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
4061 | return -EINVAL; | |
4062 | break; | |
eef941e6 | 4063 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
4064 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
4065 | return -EINVAL; | |
4066 | break; | |
4067 | } | |
4068 | ||
4069 | return 0; | |
4070 | } | |
4071 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
4072 | ||
5727ef1b | 4073 | /* |
c258d2de | 4074 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 4075 | */ |
80b99899 JB |
4076 | static struct net_device *get_vlan(struct genl_info *info, |
4077 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 4078 | { |
463d0183 | 4079 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
4080 | struct net_device *v; |
4081 | int ret; | |
4082 | ||
4083 | if (!vlanattr) | |
4084 | return NULL; | |
4085 | ||
4086 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
4087 | if (!v) | |
4088 | return ERR_PTR(-ENODEV); | |
4089 | ||
4090 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
4091 | ret = -EINVAL; | |
4092 | goto error; | |
5727ef1b | 4093 | } |
80b99899 | 4094 | |
77ee7c89 JB |
4095 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
4096 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4097 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
4098 | ret = -EINVAL; | |
4099 | goto error; | |
4100 | } | |
4101 | ||
80b99899 JB |
4102 | if (!netif_running(v)) { |
4103 | ret = -ENETDOWN; | |
4104 | goto error; | |
4105 | } | |
4106 | ||
4107 | return v; | |
4108 | error: | |
4109 | dev_put(v); | |
4110 | return ERR_PTR(ret); | |
5727ef1b JB |
4111 | } |
4112 | ||
94e860f1 JB |
4113 | static const struct nla_policy |
4114 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
4115 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
4116 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
4117 | }; | |
4118 | ||
ff276691 JB |
4119 | static int nl80211_parse_sta_wme(struct genl_info *info, |
4120 | struct station_parameters *params) | |
df881293 | 4121 | { |
df881293 JM |
4122 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
4123 | struct nlattr *nla; | |
4124 | int err; | |
4125 | ||
df881293 JM |
4126 | /* parse WME attributes if present */ |
4127 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
4128 | return 0; | |
4129 | ||
4130 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
4131 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
4132 | nl80211_sta_wme_policy); | |
4133 | if (err) | |
4134 | return err; | |
4135 | ||
4136 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
4137 | params->uapsd_queues = nla_get_u8( | |
4138 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4139 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
4140 | return -EINVAL; | |
4141 | ||
4142 | if (tb[NL80211_STA_WME_MAX_SP]) | |
4143 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4144 | ||
4145 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
4146 | return -EINVAL; | |
4147 | ||
4148 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
4149 | ||
4150 | return 0; | |
4151 | } | |
4152 | ||
c01fc9ad SD |
4153 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4154 | struct station_parameters *params) | |
4155 | { | |
4156 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4157 | params->supported_channels = | |
4158 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4159 | params->supported_channels_len = | |
4160 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4161 | /* | |
4162 | * Need to include at least one (first channel, number of | |
4163 | * channels) tuple for each subband, and must have proper | |
4164 | * tuples for the rest of the data as well. | |
4165 | */ | |
4166 | if (params->supported_channels_len < 2) | |
4167 | return -EINVAL; | |
4168 | if (params->supported_channels_len % 2) | |
4169 | return -EINVAL; | |
4170 | } | |
4171 | ||
4172 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4173 | params->supported_oper_classes = | |
4174 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4175 | params->supported_oper_classes_len = | |
4176 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4177 | /* | |
4178 | * The value of the Length field of the Supported Operating | |
4179 | * Classes element is between 2 and 253. | |
4180 | */ | |
4181 | if (params->supported_oper_classes_len < 2 || | |
4182 | params->supported_oper_classes_len > 253) | |
4183 | return -EINVAL; | |
4184 | } | |
4185 | return 0; | |
4186 | } | |
4187 | ||
ff276691 JB |
4188 | static int nl80211_set_station_tdls(struct genl_info *info, |
4189 | struct station_parameters *params) | |
4190 | { | |
c01fc9ad | 4191 | int err; |
ff276691 | 4192 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4193 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4194 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4195 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4196 | params->ht_capa = | |
4197 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4198 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4199 | params->vht_capa = | |
4200 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4201 | ||
c01fc9ad SD |
4202 | err = nl80211_parse_sta_channel_info(info, params); |
4203 | if (err) | |
4204 | return err; | |
4205 | ||
ff276691 JB |
4206 | return nl80211_parse_sta_wme(info, params); |
4207 | } | |
4208 | ||
5727ef1b JB |
4209 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4210 | { | |
4c476991 | 4211 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4212 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4213 | struct station_parameters params; |
77ee7c89 JB |
4214 | u8 *mac_addr; |
4215 | int err; | |
5727ef1b JB |
4216 | |
4217 | memset(¶ms, 0, sizeof(params)); | |
4218 | ||
4219 | params.listen_interval = -1; | |
4220 | ||
77ee7c89 JB |
4221 | if (!rdev->ops->change_station) |
4222 | return -EOPNOTSUPP; | |
4223 | ||
5727ef1b JB |
4224 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4225 | return -EINVAL; | |
4226 | ||
4227 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4228 | return -EINVAL; | |
4229 | ||
4230 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4231 | ||
4232 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4233 | params.supported_rates = | |
4234 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4235 | params.supported_rates_len = | |
4236 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4237 | } | |
4238 | ||
9d62a986 JM |
4239 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4240 | params.capability = | |
4241 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4242 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4243 | } | |
4244 | ||
4245 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4246 | params.ext_capab = | |
4247 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4248 | params.ext_capab_len = | |
4249 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4250 | } | |
4251 | ||
df881293 | 4252 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 4253 | return -EINVAL; |
36aedc90 | 4254 | |
bdd3ae3d | 4255 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4256 | return -EINVAL; |
4257 | ||
f8bacc21 | 4258 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4259 | params.plink_action = |
f8bacc21 JB |
4260 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4261 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4262 | return -EINVAL; | |
4263 | } | |
2ec600d6 | 4264 | |
f8bacc21 | 4265 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4266 | params.plink_state = |
f8bacc21 JB |
4267 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4268 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4269 | return -EINVAL; | |
4270 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
4271 | } | |
9c3990aa | 4272 | |
3b1c5a53 MP |
4273 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4274 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4275 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4276 | ||
4277 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4278 | pm > NL80211_MESH_POWER_MAX) | |
4279 | return -EINVAL; | |
4280 | ||
4281 | params.local_pm = pm; | |
4282 | } | |
4283 | ||
77ee7c89 JB |
4284 | /* Include parameters for TDLS peer (will check later) */ |
4285 | err = nl80211_set_station_tdls(info, ¶ms); | |
4286 | if (err) | |
4287 | return err; | |
4288 | ||
4289 | params.vlan = get_vlan(info, rdev); | |
4290 | if (IS_ERR(params.vlan)) | |
4291 | return PTR_ERR(params.vlan); | |
4292 | ||
a97f4424 JB |
4293 | switch (dev->ieee80211_ptr->iftype) { |
4294 | case NL80211_IFTYPE_AP: | |
4295 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4296 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4297 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4298 | case NL80211_IFTYPE_STATION: |
267335d6 | 4299 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4300 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4301 | break; |
4302 | default: | |
77ee7c89 JB |
4303 | err = -EOPNOTSUPP; |
4304 | goto out_put_vlan; | |
034d655e JB |
4305 | } |
4306 | ||
77ee7c89 | 4307 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4308 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4309 | |
77ee7c89 | 4310 | out_put_vlan: |
5727ef1b JB |
4311 | if (params.vlan) |
4312 | dev_put(params.vlan); | |
3b85875a | 4313 | |
5727ef1b JB |
4314 | return err; |
4315 | } | |
4316 | ||
4317 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4318 | { | |
4c476991 | 4319 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4320 | int err; |
4c476991 | 4321 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4322 | struct station_parameters params; |
4323 | u8 *mac_addr = NULL; | |
4324 | ||
4325 | memset(¶ms, 0, sizeof(params)); | |
4326 | ||
984c311b JB |
4327 | if (!rdev->ops->add_station) |
4328 | return -EOPNOTSUPP; | |
4329 | ||
5727ef1b JB |
4330 | if (!info->attrs[NL80211_ATTR_MAC]) |
4331 | return -EINVAL; | |
4332 | ||
5727ef1b JB |
4333 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4334 | return -EINVAL; | |
4335 | ||
4336 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4337 | return -EINVAL; | |
4338 | ||
5e4b6f56 JM |
4339 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4340 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4341 | return -EINVAL; |
4342 | ||
5727ef1b JB |
4343 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4344 | params.supported_rates = | |
4345 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4346 | params.supported_rates_len = | |
4347 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4348 | params.listen_interval = | |
4349 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4350 | |
3d124ea2 | 4351 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4352 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4353 | else |
4354 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4355 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4356 | return -EINVAL; | |
51b50fbe | 4357 | |
9d62a986 JM |
4358 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4359 | params.capability = | |
4360 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4361 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4362 | } | |
4363 | ||
4364 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4365 | params.ext_capab = | |
4366 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4367 | params.ext_capab_len = | |
4368 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4369 | } | |
4370 | ||
36aedc90 JM |
4371 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4372 | params.ht_capa = | |
4373 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4374 | |
f461be3e MP |
4375 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4376 | params.vht_capa = | |
4377 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4378 | ||
60f4a7b1 MK |
4379 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4380 | params.opmode_notif_used = true; | |
4381 | params.opmode_notif = | |
4382 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4383 | } | |
4384 | ||
f8bacc21 | 4385 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4386 | params.plink_action = |
f8bacc21 JB |
4387 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4388 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4389 | return -EINVAL; | |
4390 | } | |
96b78dff | 4391 | |
c01fc9ad SD |
4392 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4393 | if (err) | |
4394 | return err; | |
4395 | ||
ff276691 JB |
4396 | err = nl80211_parse_sta_wme(info, ¶ms); |
4397 | if (err) | |
4398 | return err; | |
bdd90d5e | 4399 | |
bdd3ae3d | 4400 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4401 | return -EINVAL; |
4402 | ||
77ee7c89 JB |
4403 | /* When you run into this, adjust the code below for the new flag */ |
4404 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4405 | ||
bdd90d5e JB |
4406 | switch (dev->ieee80211_ptr->iftype) { |
4407 | case NL80211_IFTYPE_AP: | |
4408 | case NL80211_IFTYPE_AP_VLAN: | |
4409 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4410 | /* ignore WME attributes if iface/sta is not capable */ |
4411 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4412 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4413 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4414 | |
bdd90d5e | 4415 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4416 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4417 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4418 | return -EINVAL; |
bdd90d5e JB |
4419 | /* but don't bother the driver with it */ |
4420 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4421 | |
d582cffb JB |
4422 | /* allow authenticated/associated only if driver handles it */ |
4423 | if (!(rdev->wiphy.features & | |
4424 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4425 | params.sta_flags_mask & | |
4426 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4427 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4428 | return -EINVAL; | |
4429 | ||
bdd90d5e JB |
4430 | /* must be last in here for error handling */ |
4431 | params.vlan = get_vlan(info, rdev); | |
4432 | if (IS_ERR(params.vlan)) | |
4433 | return PTR_ERR(params.vlan); | |
4434 | break; | |
4435 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4436 | /* ignore uAPSD data */ |
4437 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4438 | ||
d582cffb JB |
4439 | /* associated is disallowed */ |
4440 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4441 | return -EINVAL; | |
bdd90d5e | 4442 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4443 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4444 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4445 | return -EINVAL; |
4446 | break; | |
4447 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4448 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4449 | /* ignore uAPSD data */ |
4450 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4451 | ||
77ee7c89 JB |
4452 | /* these are disallowed */ |
4453 | if (params.sta_flags_mask & | |
4454 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4455 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4456 | return -EINVAL; |
bdd90d5e JB |
4457 | /* Only TDLS peers can be added */ |
4458 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4459 | return -EINVAL; | |
4460 | /* Can only add if TDLS ... */ | |
4461 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4462 | return -EOPNOTSUPP; | |
4463 | /* ... with external setup is supported */ | |
4464 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4465 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4466 | /* |
4467 | * Older wpa_supplicant versions always mark the TDLS peer | |
4468 | * as authorized, but it shouldn't yet be. | |
4469 | */ | |
4470 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4471 | break; |
4472 | default: | |
4473 | return -EOPNOTSUPP; | |
c75786c9 EP |
4474 | } |
4475 | ||
bdd90d5e | 4476 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4477 | |
e35e4d28 | 4478 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4479 | |
5727ef1b JB |
4480 | if (params.vlan) |
4481 | dev_put(params.vlan); | |
5727ef1b JB |
4482 | return err; |
4483 | } | |
4484 | ||
4485 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4486 | { | |
4c476991 JB |
4487 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4488 | struct net_device *dev = info->user_ptr[1]; | |
89c771e5 JM |
4489 | struct station_del_parameters params; |
4490 | ||
4491 | memset(¶ms, 0, sizeof(params)); | |
5727ef1b JB |
4492 | |
4493 | if (info->attrs[NL80211_ATTR_MAC]) | |
89c771e5 | 4494 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5727ef1b | 4495 | |
e80cf853 | 4496 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4497 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4498 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4499 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4500 | return -EINVAL; | |
5727ef1b | 4501 | |
4c476991 JB |
4502 | if (!rdev->ops->del_station) |
4503 | return -EOPNOTSUPP; | |
3b85875a | 4504 | |
98856866 JM |
4505 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
4506 | params.subtype = | |
4507 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | |
4508 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | |
4509 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | |
4510 | return -EINVAL; | |
4511 | } else { | |
4512 | /* Default to Deauthentication frame */ | |
4513 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | |
4514 | } | |
4515 | ||
4516 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | |
4517 | params.reason_code = | |
4518 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
4519 | if (params.reason_code == 0) | |
4520 | return -EINVAL; /* 0 is reserved */ | |
4521 | } else { | |
4522 | /* Default to reason code 2 */ | |
4523 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | |
4524 | } | |
4525 | ||
89c771e5 | 4526 | return rdev_del_station(rdev, dev, ¶ms); |
5727ef1b JB |
4527 | } |
4528 | ||
15e47304 | 4529 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4530 | int flags, struct net_device *dev, |
4531 | u8 *dst, u8 *next_hop, | |
4532 | struct mpath_info *pinfo) | |
4533 | { | |
4534 | void *hdr; | |
4535 | struct nlattr *pinfoattr; | |
4536 | ||
1ef4c850 | 4537 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
2ec600d6 LCC |
4538 | if (!hdr) |
4539 | return -1; | |
4540 | ||
9360ffd1 DM |
4541 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4542 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4543 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4544 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4545 | goto nla_put_failure; | |
f5ea9120 | 4546 | |
2ec600d6 LCC |
4547 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4548 | if (!pinfoattr) | |
4549 | goto nla_put_failure; | |
9360ffd1 DM |
4550 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4551 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4552 | pinfo->frame_qlen)) | |
4553 | goto nla_put_failure; | |
4554 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4555 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4556 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4557 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4558 | pinfo->metric)) || | |
4559 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4560 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4561 | pinfo->exptime)) || | |
4562 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4563 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4564 | pinfo->flags)) || | |
4565 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4566 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4567 | pinfo->discovery_timeout)) || | |
4568 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4569 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4570 | pinfo->discovery_retries))) | |
4571 | goto nla_put_failure; | |
2ec600d6 LCC |
4572 | |
4573 | nla_nest_end(msg, pinfoattr); | |
4574 | ||
053c095a JB |
4575 | genlmsg_end(msg, hdr); |
4576 | return 0; | |
2ec600d6 LCC |
4577 | |
4578 | nla_put_failure: | |
bc3ed28c TG |
4579 | genlmsg_cancel(msg, hdr); |
4580 | return -EMSGSIZE; | |
2ec600d6 LCC |
4581 | } |
4582 | ||
4583 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4584 | struct netlink_callback *cb) |
2ec600d6 | 4585 | { |
2ec600d6 | 4586 | struct mpath_info pinfo; |
1b8ec87a | 4587 | struct cfg80211_registered_device *rdev; |
97990a06 | 4588 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4589 | u8 dst[ETH_ALEN]; |
4590 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4591 | int path_idx = cb->args[2]; |
2ec600d6 | 4592 | int err; |
2ec600d6 | 4593 | |
1b8ec87a | 4594 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
4595 | if (err) |
4596 | return err; | |
bba95fef | 4597 | |
1b8ec87a | 4598 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 4599 | err = -EOPNOTSUPP; |
bba95fef JB |
4600 | goto out_err; |
4601 | } | |
4602 | ||
97990a06 | 4603 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4604 | err = -EOPNOTSUPP; |
0448b5fc | 4605 | goto out_err; |
eec60b03 JM |
4606 | } |
4607 | ||
bba95fef | 4608 | while (1) { |
1b8ec87a | 4609 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 4610 | next_hop, &pinfo); |
bba95fef | 4611 | if (err == -ENOENT) |
2ec600d6 | 4612 | break; |
bba95fef | 4613 | if (err) |
3b85875a | 4614 | goto out_err; |
2ec600d6 | 4615 | |
15e47304 | 4616 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4617 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4618 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4619 | &pinfo) < 0) |
4620 | goto out; | |
2ec600d6 | 4621 | |
bba95fef | 4622 | path_idx++; |
2ec600d6 | 4623 | } |
2ec600d6 | 4624 | |
2ec600d6 | 4625 | |
bba95fef | 4626 | out: |
97990a06 | 4627 | cb->args[2] = path_idx; |
bba95fef | 4628 | err = skb->len; |
bba95fef | 4629 | out_err: |
1b8ec87a | 4630 | nl80211_finish_wdev_dump(rdev); |
bba95fef | 4631 | return err; |
2ec600d6 LCC |
4632 | } |
4633 | ||
4634 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4635 | { | |
4c476991 | 4636 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4637 | int err; |
4c476991 | 4638 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4639 | struct mpath_info pinfo; |
4640 | struct sk_buff *msg; | |
4641 | u8 *dst = NULL; | |
4642 | u8 next_hop[ETH_ALEN]; | |
4643 | ||
4644 | memset(&pinfo, 0, sizeof(pinfo)); | |
4645 | ||
4646 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4647 | return -EINVAL; | |
4648 | ||
4649 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4650 | ||
4c476991 JB |
4651 | if (!rdev->ops->get_mpath) |
4652 | return -EOPNOTSUPP; | |
2ec600d6 | 4653 | |
4c476991 JB |
4654 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4655 | return -EOPNOTSUPP; | |
eec60b03 | 4656 | |
e35e4d28 | 4657 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4658 | if (err) |
4c476991 | 4659 | return err; |
2ec600d6 | 4660 | |
fd2120ca | 4661 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4662 | if (!msg) |
4c476991 | 4663 | return -ENOMEM; |
2ec600d6 | 4664 | |
15e47304 | 4665 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4666 | dev, dst, next_hop, &pinfo) < 0) { |
4667 | nlmsg_free(msg); | |
4668 | return -ENOBUFS; | |
4669 | } | |
3b85875a | 4670 | |
4c476991 | 4671 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4672 | } |
4673 | ||
4674 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4675 | { | |
4c476991 JB |
4676 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4677 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4678 | u8 *dst = NULL; |
4679 | u8 *next_hop = NULL; | |
4680 | ||
4681 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4682 | return -EINVAL; | |
4683 | ||
4684 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4685 | return -EINVAL; | |
4686 | ||
4687 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4688 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4689 | ||
4c476991 JB |
4690 | if (!rdev->ops->change_mpath) |
4691 | return -EOPNOTSUPP; | |
35a8efe1 | 4692 | |
4c476991 JB |
4693 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4694 | return -EOPNOTSUPP; | |
2ec600d6 | 4695 | |
e35e4d28 | 4696 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4697 | } |
4c476991 | 4698 | |
2ec600d6 LCC |
4699 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4700 | { | |
4c476991 JB |
4701 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4702 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4703 | u8 *dst = NULL; |
4704 | u8 *next_hop = NULL; | |
4705 | ||
4706 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4707 | return -EINVAL; | |
4708 | ||
4709 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4710 | return -EINVAL; | |
4711 | ||
4712 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4713 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4714 | ||
4c476991 JB |
4715 | if (!rdev->ops->add_mpath) |
4716 | return -EOPNOTSUPP; | |
35a8efe1 | 4717 | |
4c476991 JB |
4718 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4719 | return -EOPNOTSUPP; | |
2ec600d6 | 4720 | |
e35e4d28 | 4721 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4722 | } |
4723 | ||
4724 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4725 | { | |
4c476991 JB |
4726 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4727 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4728 | u8 *dst = NULL; |
4729 | ||
4730 | if (info->attrs[NL80211_ATTR_MAC]) | |
4731 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4732 | ||
4c476991 JB |
4733 | if (!rdev->ops->del_mpath) |
4734 | return -EOPNOTSUPP; | |
3b85875a | 4735 | |
e35e4d28 | 4736 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4737 | } |
4738 | ||
66be7d2b HR |
4739 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
4740 | { | |
4741 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4742 | int err; | |
4743 | struct net_device *dev = info->user_ptr[1]; | |
4744 | struct mpath_info pinfo; | |
4745 | struct sk_buff *msg; | |
4746 | u8 *dst = NULL; | |
4747 | u8 mpp[ETH_ALEN]; | |
4748 | ||
4749 | memset(&pinfo, 0, sizeof(pinfo)); | |
4750 | ||
4751 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4752 | return -EINVAL; | |
4753 | ||
4754 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4755 | ||
4756 | if (!rdev->ops->get_mpp) | |
4757 | return -EOPNOTSUPP; | |
4758 | ||
4759 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
4760 | return -EOPNOTSUPP; | |
4761 | ||
4762 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | |
4763 | if (err) | |
4764 | return err; | |
4765 | ||
4766 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4767 | if (!msg) | |
4768 | return -ENOMEM; | |
4769 | ||
4770 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | |
4771 | dev, dst, mpp, &pinfo) < 0) { | |
4772 | nlmsg_free(msg); | |
4773 | return -ENOBUFS; | |
4774 | } | |
4775 | ||
4776 | return genlmsg_reply(msg, info); | |
4777 | } | |
4778 | ||
4779 | static int nl80211_dump_mpp(struct sk_buff *skb, | |
4780 | struct netlink_callback *cb) | |
4781 | { | |
4782 | struct mpath_info pinfo; | |
4783 | struct cfg80211_registered_device *rdev; | |
4784 | struct wireless_dev *wdev; | |
4785 | u8 dst[ETH_ALEN]; | |
4786 | u8 mpp[ETH_ALEN]; | |
4787 | int path_idx = cb->args[2]; | |
4788 | int err; | |
4789 | ||
4790 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | |
4791 | if (err) | |
4792 | return err; | |
4793 | ||
4794 | if (!rdev->ops->dump_mpp) { | |
4795 | err = -EOPNOTSUPP; | |
4796 | goto out_err; | |
4797 | } | |
4798 | ||
4799 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | |
4800 | err = -EOPNOTSUPP; | |
4801 | goto out_err; | |
4802 | } | |
4803 | ||
4804 | while (1) { | |
4805 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | |
4806 | mpp, &pinfo); | |
4807 | if (err == -ENOENT) | |
4808 | break; | |
4809 | if (err) | |
4810 | goto out_err; | |
4811 | ||
4812 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | |
4813 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
4814 | wdev->netdev, dst, mpp, | |
4815 | &pinfo) < 0) | |
4816 | goto out; | |
4817 | ||
4818 | path_idx++; | |
4819 | } | |
4820 | ||
4821 | out: | |
4822 | cb->args[2] = path_idx; | |
4823 | err = skb->len; | |
4824 | out_err: | |
4825 | nl80211_finish_wdev_dump(rdev); | |
4826 | return err; | |
4827 | } | |
4828 | ||
9f1ba906 JM |
4829 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4830 | { | |
4c476991 JB |
4831 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4832 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 4833 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 4834 | struct bss_parameters params; |
c56589ed | 4835 | int err; |
9f1ba906 JM |
4836 | |
4837 | memset(¶ms, 0, sizeof(params)); | |
4838 | /* default to not changing parameters */ | |
4839 | params.use_cts_prot = -1; | |
4840 | params.use_short_preamble = -1; | |
4841 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4842 | params.ap_isolate = -1; |
50b12f59 | 4843 | params.ht_opmode = -1; |
53cabad7 JB |
4844 | params.p2p_ctwindow = -1; |
4845 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4846 | |
4847 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4848 | params.use_cts_prot = | |
4849 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4850 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4851 | params.use_short_preamble = | |
4852 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4853 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4854 | params.use_short_slot_time = | |
4855 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4856 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4857 | params.basic_rates = | |
4858 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4859 | params.basic_rates_len = | |
4860 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4861 | } | |
fd8aaaf3 FF |
4862 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4863 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4864 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4865 | params.ht_opmode = | |
4866 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4867 | |
53cabad7 JB |
4868 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4869 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4870 | return -EINVAL; | |
4871 | params.p2p_ctwindow = | |
4872 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4873 | if (params.p2p_ctwindow < 0) | |
4874 | return -EINVAL; | |
4875 | if (params.p2p_ctwindow != 0 && | |
4876 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4877 | return -EINVAL; | |
4878 | } | |
4879 | ||
4880 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4881 | u8 tmp; | |
4882 | ||
4883 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4884 | return -EINVAL; | |
4885 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4886 | if (tmp > 1) | |
4887 | return -EINVAL; | |
4888 | params.p2p_opp_ps = tmp; | |
4889 | if (params.p2p_opp_ps && | |
4890 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4891 | return -EINVAL; | |
4892 | } | |
4893 | ||
4c476991 JB |
4894 | if (!rdev->ops->change_bss) |
4895 | return -EOPNOTSUPP; | |
9f1ba906 | 4896 | |
074ac8df | 4897 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4898 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4899 | return -EOPNOTSUPP; | |
3b85875a | 4900 | |
c56589ed SW |
4901 | wdev_lock(wdev); |
4902 | err = rdev_change_bss(rdev, dev, ¶ms); | |
4903 | wdev_unlock(wdev); | |
4904 | ||
4905 | return err; | |
9f1ba906 JM |
4906 | } |
4907 | ||
b54452b0 | 4908 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4909 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4910 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4911 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4912 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4913 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4914 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
089027e5 | 4915 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
b2e1b302 LR |
4916 | }; |
4917 | ||
4918 | static int parse_reg_rule(struct nlattr *tb[], | |
4919 | struct ieee80211_reg_rule *reg_rule) | |
4920 | { | |
4921 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4922 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4923 | ||
4924 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4925 | return -EINVAL; | |
4926 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4927 | return -EINVAL; | |
4928 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4929 | return -EINVAL; | |
b0dfd2ea JD |
4930 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
4931 | return -EINVAL; | |
b2e1b302 LR |
4932 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
4933 | return -EINVAL; | |
4934 | ||
4935 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4936 | ||
4937 | freq_range->start_freq_khz = | |
4938 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4939 | freq_range->end_freq_khz = | |
4940 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
b0dfd2ea JD |
4941 | freq_range->max_bandwidth_khz = |
4942 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
b2e1b302 LR |
4943 | |
4944 | power_rule->max_eirp = | |
4945 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4946 | ||
4947 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4948 | power_rule->max_antenna_gain = | |
4949 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4950 | ||
089027e5 JD |
4951 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
4952 | reg_rule->dfs_cac_ms = | |
4953 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
4954 | ||
b2e1b302 LR |
4955 | return 0; |
4956 | } | |
4957 | ||
4958 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4959 | { | |
b2e1b302 | 4960 | char *data = NULL; |
57b5ce07 | 4961 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4962 | |
80778f18 LR |
4963 | /* |
4964 | * You should only get this when cfg80211 hasn't yet initialized | |
4965 | * completely when built-in to the kernel right between the time | |
4966 | * window between nl80211_init() and regulatory_init(), if that is | |
4967 | * even possible. | |
4968 | */ | |
458f4f9e | 4969 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4970 | return -EINPROGRESS; |
80778f18 | 4971 | |
57b5ce07 LR |
4972 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4973 | user_reg_hint_type = | |
4974 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4975 | else | |
4976 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4977 | ||
4978 | switch (user_reg_hint_type) { | |
4979 | case NL80211_USER_REG_HINT_USER: | |
4980 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
4981 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4982 | return -EINVAL; | |
4983 | ||
4984 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4985 | return regulatory_hint_user(data, user_reg_hint_type); | |
4986 | case NL80211_USER_REG_HINT_INDOOR: | |
4987 | return regulatory_hint_indoor_user(); | |
57b5ce07 LR |
4988 | default: |
4989 | return -EINVAL; | |
4990 | } | |
b2e1b302 LR |
4991 | } |
4992 | ||
24bdd9f4 | 4993 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4994 | struct genl_info *info) |
93da9cc1 | 4995 | { |
4c476991 | 4996 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4997 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4998 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4999 | struct mesh_config cur_params; | |
5000 | int err = 0; | |
93da9cc1 | 5001 | void *hdr; |
5002 | struct nlattr *pinfoattr; | |
5003 | struct sk_buff *msg; | |
5004 | ||
29cbe68c JB |
5005 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5006 | return -EOPNOTSUPP; | |
5007 | ||
24bdd9f4 | 5008 | if (!rdev->ops->get_mesh_config) |
4c476991 | 5009 | return -EOPNOTSUPP; |
f3f92586 | 5010 | |
29cbe68c JB |
5011 | wdev_lock(wdev); |
5012 | /* If not connected, get default parameters */ | |
5013 | if (!wdev->mesh_id_len) | |
5014 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
5015 | else | |
e35e4d28 | 5016 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
5017 | wdev_unlock(wdev); |
5018 | ||
93da9cc1 | 5019 | if (err) |
4c476991 | 5020 | return err; |
93da9cc1 | 5021 | |
5022 | /* Draw up a netlink message to send back */ | |
fd2120ca | 5023 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
5024 | if (!msg) |
5025 | return -ENOMEM; | |
15e47304 | 5026 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 5027 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 5028 | if (!hdr) |
efe1cf0c | 5029 | goto out; |
24bdd9f4 | 5030 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 5031 | if (!pinfoattr) |
5032 | goto nla_put_failure; | |
9360ffd1 DM |
5033 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5034 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
5035 | cur_params.dot11MeshRetryTimeout) || | |
5036 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
5037 | cur_params.dot11MeshConfirmTimeout) || | |
5038 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
5039 | cur_params.dot11MeshHoldingTimeout) || | |
5040 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
5041 | cur_params.dot11MeshMaxPeerLinks) || | |
5042 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
5043 | cur_params.dot11MeshMaxRetries) || | |
5044 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
5045 | cur_params.dot11MeshTTL) || | |
5046 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
5047 | cur_params.element_ttl) || | |
5048 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
5049 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
5050 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5051 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
5052 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5053 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
5054 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
5055 | cur_params.path_refresh_time) || | |
5056 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
5057 | cur_params.min_discovery_timeout) || | |
5058 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
5059 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
5060 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
5061 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
5062 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
5063 | cur_params.dot11MeshHWMPperrMinInterval) || | |
5064 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
5065 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
5066 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5067 | cur_params.dot11MeshHWMPRootMode) || | |
5068 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
5069 | cur_params.dot11MeshHWMPRannInterval) || | |
5070 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
5071 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
5072 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
5073 | cur_params.dot11MeshForwarding) || | |
5074 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
5075 | cur_params.rssi_threshold) || |
5076 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
5077 | cur_params.ht_opmode) || |
5078 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
5079 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
5080 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
5081 | cur_params.dot11MeshHWMProotInterval) || |
5082 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
5083 | cur_params.dot11MeshHWMPconfirmationInterval) || |
5084 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
5085 | cur_params.power_mode) || | |
5086 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
5087 | cur_params.dot11MeshAwakeWindowDuration) || |
5088 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5089 | cur_params.plink_timeout)) | |
9360ffd1 | 5090 | goto nla_put_failure; |
93da9cc1 | 5091 | nla_nest_end(msg, pinfoattr); |
5092 | genlmsg_end(msg, hdr); | |
4c476991 | 5093 | return genlmsg_reply(msg, info); |
93da9cc1 | 5094 | |
3b85875a | 5095 | nla_put_failure: |
93da9cc1 | 5096 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 5097 | out: |
d080e275 | 5098 | nlmsg_free(msg); |
4c476991 | 5099 | return -ENOBUFS; |
93da9cc1 | 5100 | } |
5101 | ||
b54452b0 | 5102 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 5103 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
5104 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
5105 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
5106 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
5107 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
5108 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 5109 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 5110 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 5111 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 5112 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
5113 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
5114 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
5115 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
5116 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 5117 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 5118 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 5119 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 5120 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 5121 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 5122 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
5123 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
5124 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
5125 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
5126 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 5127 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
5128 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
5129 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 5130 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 5131 | }; |
5132 | ||
c80d545d JC |
5133 | static const struct nla_policy |
5134 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 5135 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
5136 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
5137 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 5138 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 5139 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 5140 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 5141 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 5142 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 5143 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
5144 | }; |
5145 | ||
24bdd9f4 | 5146 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
5147 | struct mesh_config *cfg, |
5148 | u32 *mask_out) | |
93da9cc1 | 5149 | { |
93da9cc1 | 5150 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 5151 | u32 mask = 0; |
93da9cc1 | 5152 | |
ea54fba2 MP |
5153 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
5154 | do { \ | |
5155 | if (tb[attr]) { \ | |
5156 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
5157 | return -EINVAL; \ | |
5158 | cfg->param = fn(tb[attr]); \ | |
5159 | mask |= (1 << (attr - 1)); \ | |
5160 | } \ | |
5161 | } while (0) | |
bd90fdcc JB |
5162 | |
5163 | ||
24bdd9f4 | 5164 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 5165 | return -EINVAL; |
5166 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 5167 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 5168 | nl80211_meshconf_params_policy)) |
93da9cc1 | 5169 | return -EINVAL; |
5170 | ||
93da9cc1 | 5171 | /* This makes sure that there aren't more than 32 mesh config |
5172 | * parameters (otherwise our bitfield scheme would not work.) */ | |
5173 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
5174 | ||
5175 | /* Fill in the params struct */ | |
ea54fba2 | 5176 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
5177 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
5178 | nla_get_u16); | |
ea54fba2 | 5179 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
5180 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
5181 | nla_get_u16); | |
ea54fba2 | 5182 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
5183 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
5184 | nla_get_u16); | |
ea54fba2 | 5185 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
5186 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
5187 | nla_get_u16); | |
ea54fba2 | 5188 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
5189 | mask, NL80211_MESHCONF_MAX_RETRIES, |
5190 | nla_get_u8); | |
ea54fba2 | 5191 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 5192 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 5193 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
5194 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
5195 | nla_get_u8); | |
ea54fba2 | 5196 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
5197 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
5198 | nla_get_u8); | |
ea54fba2 MP |
5199 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
5200 | 1, 255, mask, | |
a4f606ea CYY |
5201 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5202 | nla_get_u32); | |
ea54fba2 | 5203 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
5204 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5205 | nla_get_u8); | |
ea54fba2 | 5206 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
5207 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
5208 | nla_get_u32); | |
ea54fba2 | 5209 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
5210 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
5211 | nla_get_u16); | |
ea54fba2 MP |
5212 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
5213 | 1, 65535, mask, | |
a4f606ea CYY |
5214 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
5215 | nla_get_u32); | |
93da9cc1 | 5216 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
5217 | 1, 65535, mask, |
5218 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 5219 | nla_get_u16); |
dca7e943 | 5220 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
5221 | 1, 65535, mask, |
5222 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 5223 | nla_get_u16); |
93da9cc1 | 5224 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5225 | dot11MeshHWMPnetDiameterTraversalTime, |
5226 | 1, 65535, mask, | |
a4f606ea CYY |
5227 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
5228 | nla_get_u16); | |
ea54fba2 MP |
5229 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
5230 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5231 | nla_get_u8); | |
5232 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
5233 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 5234 | nla_get_u16); |
63c5723b | 5235 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5236 | dot11MeshGateAnnouncementProtocol, 0, 1, |
5237 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 5238 | nla_get_u8); |
ea54fba2 | 5239 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
5240 | mask, NL80211_MESHCONF_FORWARDING, |
5241 | nla_get_u8); | |
83374fe9 | 5242 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 5243 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
83374fe9 | 5244 | nla_get_s32); |
ea54fba2 | 5245 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 5246 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
5247 | nla_get_u16); |
5248 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 5249 | 1, 65535, mask, |
ac1073a6 CYY |
5250 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
5251 | nla_get_u32); | |
ea54fba2 | 5252 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 5253 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
5254 | nla_get_u16); |
5255 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
5256 | dot11MeshHWMPconfirmationInterval, |
5257 | 1, 65535, mask, | |
728b19e5 | 5258 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 5259 | nla_get_u16); |
3b1c5a53 MP |
5260 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
5261 | NL80211_MESH_POWER_ACTIVE, | |
5262 | NL80211_MESH_POWER_MAX, | |
5263 | mask, NL80211_MESHCONF_POWER_MODE, | |
5264 | nla_get_u32); | |
5265 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
5266 | 0, 65535, mask, | |
5267 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
31f909a2 | 5268 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
8e7c0538 CT |
5269 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
5270 | nla_get_u32); | |
bd90fdcc JB |
5271 | if (mask_out) |
5272 | *mask_out = mask; | |
c80d545d | 5273 | |
bd90fdcc JB |
5274 | return 0; |
5275 | ||
5276 | #undef FILL_IN_MESH_PARAM_IF_SET | |
5277 | } | |
5278 | ||
c80d545d JC |
5279 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
5280 | struct mesh_setup *setup) | |
5281 | { | |
bb2798d4 | 5282 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
5283 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
5284 | ||
5285 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
5286 | return -EINVAL; | |
5287 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
5288 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
5289 | nl80211_mesh_setup_params_policy)) | |
5290 | return -EINVAL; | |
5291 | ||
d299a1f2 JC |
5292 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
5293 | setup->sync_method = | |
5294 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
5295 | IEEE80211_SYNC_METHOD_VENDOR : | |
5296 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
5297 | ||
c80d545d JC |
5298 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
5299 | setup->path_sel_proto = | |
5300 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5301 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5302 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5303 | ||
5304 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5305 | setup->path_metric = | |
5306 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5307 | IEEE80211_PATH_METRIC_VENDOR : | |
5308 | IEEE80211_PATH_METRIC_AIRTIME; | |
5309 | ||
581a8b0f JC |
5310 | |
5311 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 5312 | struct nlattr *ieattr = |
581a8b0f | 5313 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5314 | if (!is_valid_ie_attr(ieattr)) |
5315 | return -EINVAL; | |
581a8b0f JC |
5316 | setup->ie = nla_data(ieattr); |
5317 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5318 | } |
bb2798d4 TP |
5319 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5320 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5321 | return -EINVAL; | |
5322 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5323 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5324 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5325 | if (setup->is_secure) |
5326 | setup->user_mpm = true; | |
c80d545d | 5327 | |
6e16d90b CT |
5328 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5329 | if (!setup->user_mpm) | |
5330 | return -EINVAL; | |
5331 | setup->auth_id = | |
5332 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5333 | } | |
5334 | ||
c80d545d JC |
5335 | return 0; |
5336 | } | |
5337 | ||
24bdd9f4 | 5338 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5339 | struct genl_info *info) |
bd90fdcc JB |
5340 | { |
5341 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5342 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5343 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5344 | struct mesh_config cfg; |
5345 | u32 mask; | |
5346 | int err; | |
5347 | ||
29cbe68c JB |
5348 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5349 | return -EOPNOTSUPP; | |
5350 | ||
24bdd9f4 | 5351 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5352 | return -EOPNOTSUPP; |
5353 | ||
24bdd9f4 | 5354 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5355 | if (err) |
5356 | return err; | |
5357 | ||
29cbe68c JB |
5358 | wdev_lock(wdev); |
5359 | if (!wdev->mesh_id_len) | |
5360 | err = -ENOLINK; | |
5361 | ||
5362 | if (!err) | |
e35e4d28 | 5363 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5364 | |
5365 | wdev_unlock(wdev); | |
5366 | ||
5367 | return err; | |
93da9cc1 | 5368 | } |
5369 | ||
ad30ca2c AN |
5370 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
5371 | struct sk_buff *msg) | |
f130347c | 5372 | { |
f130347c LR |
5373 | struct nlattr *nl_reg_rules; |
5374 | unsigned int i; | |
f130347c | 5375 | |
458f4f9e JB |
5376 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
5377 | (regdom->dfs_region && | |
5378 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
ad30ca2c | 5379 | goto nla_put_failure; |
458f4f9e | 5380 | |
f130347c LR |
5381 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5382 | if (!nl_reg_rules) | |
ad30ca2c | 5383 | goto nla_put_failure; |
f130347c | 5384 | |
458f4f9e | 5385 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5386 | struct nlattr *nl_reg_rule; |
5387 | const struct ieee80211_reg_rule *reg_rule; | |
5388 | const struct ieee80211_freq_range *freq_range; | |
5389 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 5390 | unsigned int max_bandwidth_khz; |
f130347c | 5391 | |
458f4f9e | 5392 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5393 | freq_range = ®_rule->freq_range; |
5394 | power_rule = ®_rule->power_rule; | |
5395 | ||
5396 | nl_reg_rule = nla_nest_start(msg, i); | |
5397 | if (!nl_reg_rule) | |
ad30ca2c | 5398 | goto nla_put_failure; |
f130347c | 5399 | |
97524820 JD |
5400 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
5401 | if (!max_bandwidth_khz) | |
5402 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
5403 | reg_rule); | |
5404 | ||
9360ffd1 DM |
5405 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5406 | reg_rule->flags) || | |
5407 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5408 | freq_range->start_freq_khz) || | |
5409 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5410 | freq_range->end_freq_khz) || | |
5411 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 5412 | max_bandwidth_khz) || |
9360ffd1 DM |
5413 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
5414 | power_rule->max_antenna_gain) || | |
5415 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
5416 | power_rule->max_eirp) || |
5417 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
5418 | reg_rule->dfs_cac_ms)) | |
ad30ca2c | 5419 | goto nla_put_failure; |
f130347c LR |
5420 | |
5421 | nla_nest_end(msg, nl_reg_rule); | |
5422 | } | |
5423 | ||
5424 | nla_nest_end(msg, nl_reg_rules); | |
ad30ca2c AN |
5425 | return 0; |
5426 | ||
5427 | nla_put_failure: | |
5428 | return -EMSGSIZE; | |
5429 | } | |
5430 | ||
5431 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) | |
5432 | { | |
5433 | const struct ieee80211_regdomain *regdom = NULL; | |
5434 | struct cfg80211_registered_device *rdev; | |
5435 | struct wiphy *wiphy = NULL; | |
5436 | struct sk_buff *msg; | |
5437 | void *hdr; | |
5438 | ||
5439 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5440 | if (!msg) | |
5441 | return -ENOBUFS; | |
5442 | ||
5443 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
5444 | NL80211_CMD_GET_REG); | |
5445 | if (!hdr) | |
5446 | goto put_failure; | |
5447 | ||
5448 | if (info->attrs[NL80211_ATTR_WIPHY]) { | |
1bdd716c AN |
5449 | bool self_managed; |
5450 | ||
ad30ca2c AN |
5451 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
5452 | if (IS_ERR(rdev)) { | |
5453 | nlmsg_free(msg); | |
5454 | return PTR_ERR(rdev); | |
5455 | } | |
5456 | ||
5457 | wiphy = &rdev->wiphy; | |
1bdd716c AN |
5458 | self_managed = wiphy->regulatory_flags & |
5459 | REGULATORY_WIPHY_SELF_MANAGED; | |
ad30ca2c AN |
5460 | regdom = get_wiphy_regdom(wiphy); |
5461 | ||
1bdd716c AN |
5462 | /* a self-managed-reg device must have a private regdom */ |
5463 | if (WARN_ON(!regdom && self_managed)) { | |
5464 | nlmsg_free(msg); | |
5465 | return -EINVAL; | |
5466 | } | |
5467 | ||
ad30ca2c AN |
5468 | if (regdom && |
5469 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5470 | goto nla_put_failure; | |
5471 | } | |
5472 | ||
5473 | if (!wiphy && reg_last_request_cell_base() && | |
5474 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5475 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5476 | goto nla_put_failure; | |
5477 | ||
5478 | rcu_read_lock(); | |
5479 | ||
5480 | if (!regdom) | |
5481 | regdom = rcu_dereference(cfg80211_regdomain); | |
5482 | ||
5483 | if (nl80211_put_regdom(regdom, msg)) | |
5484 | goto nla_put_failure_rcu; | |
5485 | ||
5486 | rcu_read_unlock(); | |
f130347c LR |
5487 | |
5488 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5489 | return genlmsg_reply(msg, info); |
f130347c | 5490 | |
458f4f9e JB |
5491 | nla_put_failure_rcu: |
5492 | rcu_read_unlock(); | |
f130347c LR |
5493 | nla_put_failure: |
5494 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5495 | put_failure: |
d080e275 | 5496 | nlmsg_free(msg); |
5fe231e8 | 5497 | return -EMSGSIZE; |
f130347c LR |
5498 | } |
5499 | ||
ad30ca2c AN |
5500 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
5501 | u32 seq, int flags, struct wiphy *wiphy, | |
5502 | const struct ieee80211_regdomain *regdom) | |
5503 | { | |
5504 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | |
5505 | NL80211_CMD_GET_REG); | |
5506 | ||
5507 | if (!hdr) | |
5508 | return -1; | |
5509 | ||
5510 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); | |
5511 | ||
5512 | if (nl80211_put_regdom(regdom, msg)) | |
5513 | goto nla_put_failure; | |
5514 | ||
5515 | if (!wiphy && reg_last_request_cell_base() && | |
5516 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5517 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5518 | goto nla_put_failure; | |
5519 | ||
5520 | if (wiphy && | |
5521 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5522 | goto nla_put_failure; | |
5523 | ||
1bdd716c AN |
5524 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
5525 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
5526 | goto nla_put_failure; | |
5527 | ||
053c095a JB |
5528 | genlmsg_end(msg, hdr); |
5529 | return 0; | |
ad30ca2c AN |
5530 | |
5531 | nla_put_failure: | |
5532 | genlmsg_cancel(msg, hdr); | |
5533 | return -EMSGSIZE; | |
5534 | } | |
5535 | ||
5536 | static int nl80211_get_reg_dump(struct sk_buff *skb, | |
5537 | struct netlink_callback *cb) | |
5538 | { | |
5539 | const struct ieee80211_regdomain *regdom = NULL; | |
5540 | struct cfg80211_registered_device *rdev; | |
5541 | int err, reg_idx, start = cb->args[2]; | |
5542 | ||
5543 | rtnl_lock(); | |
5544 | ||
5545 | if (cfg80211_regdomain && start == 0) { | |
5546 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5547 | NLM_F_MULTI, NULL, | |
5548 | rtnl_dereference(cfg80211_regdomain)); | |
5549 | if (err < 0) | |
5550 | goto out_err; | |
5551 | } | |
5552 | ||
5553 | /* the global regdom is idx 0 */ | |
5554 | reg_idx = 1; | |
5555 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | |
5556 | regdom = get_wiphy_regdom(&rdev->wiphy); | |
5557 | if (!regdom) | |
5558 | continue; | |
5559 | ||
5560 | if (++reg_idx <= start) | |
5561 | continue; | |
5562 | ||
5563 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5564 | NLM_F_MULTI, &rdev->wiphy, regdom); | |
5565 | if (err < 0) { | |
5566 | reg_idx--; | |
5567 | break; | |
5568 | } | |
5569 | } | |
5570 | ||
5571 | cb->args[2] = reg_idx; | |
5572 | err = skb->len; | |
5573 | out_err: | |
5574 | rtnl_unlock(); | |
5575 | return err; | |
5576 | } | |
5577 | ||
b2e1b302 LR |
5578 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5579 | { | |
5580 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5581 | struct nlattr *nl_reg_rule; | |
ea372c54 JB |
5582 | char *alpha2; |
5583 | int rem_reg_rules, r; | |
b2e1b302 | 5584 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
4c7d3982 | 5585 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
ea372c54 | 5586 | struct ieee80211_regdomain *rd; |
b2e1b302 LR |
5587 | |
5588 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5589 | return -EINVAL; | |
5590 | ||
5591 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5592 | return -EINVAL; | |
5593 | ||
5594 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5595 | ||
8b60b078 LR |
5596 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5597 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5598 | ||
b2e1b302 | 5599 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5600 | rem_reg_rules) { |
b2e1b302 LR |
5601 | num_rules++; |
5602 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5603 | return -EINVAL; |
b2e1b302 LR |
5604 | } |
5605 | ||
e438768f LR |
5606 | if (!reg_is_valid_request(alpha2)) |
5607 | return -EINVAL; | |
5608 | ||
b2e1b302 | 5609 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5610 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5611 | |
5612 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5613 | if (!rd) |
5614 | return -ENOMEM; | |
b2e1b302 LR |
5615 | |
5616 | rd->n_reg_rules = num_rules; | |
5617 | rd->alpha2[0] = alpha2[0]; | |
5618 | rd->alpha2[1] = alpha2[1]; | |
5619 | ||
8b60b078 LR |
5620 | /* |
5621 | * Disable DFS master mode if the DFS region was | |
5622 | * not supported or known on this kernel. | |
5623 | */ | |
5624 | if (reg_supported_dfs_region(dfs_region)) | |
5625 | rd->dfs_region = dfs_region; | |
5626 | ||
b2e1b302 | 5627 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5628 | rem_reg_rules) { |
ae811e21 JB |
5629 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
5630 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
5631 | reg_rule_policy); | |
5632 | if (r) | |
5633 | goto bad_reg; | |
b2e1b302 LR |
5634 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5635 | if (r) | |
5636 | goto bad_reg; | |
5637 | ||
5638 | rule_idx++; | |
5639 | ||
d0e18f83 LR |
5640 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5641 | r = -EINVAL; | |
b2e1b302 | 5642 | goto bad_reg; |
d0e18f83 | 5643 | } |
b2e1b302 LR |
5644 | } |
5645 | ||
b2e1b302 | 5646 | r = set_regdom(rd); |
6913b49a | 5647 | /* set_regdom took ownership */ |
1a919318 | 5648 | rd = NULL; |
b2e1b302 | 5649 | |
d2372b31 | 5650 | bad_reg: |
b2e1b302 | 5651 | kfree(rd); |
d0e18f83 | 5652 | return r; |
b2e1b302 LR |
5653 | } |
5654 | ||
83f5e2cf JB |
5655 | static int validate_scan_freqs(struct nlattr *freqs) |
5656 | { | |
5657 | struct nlattr *attr1, *attr2; | |
5658 | int n_channels = 0, tmp1, tmp2; | |
5659 | ||
5660 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5661 | n_channels++; | |
5662 | /* | |
5663 | * Some hardware has a limited channel list for | |
5664 | * scanning, and it is pretty much nonsensical | |
5665 | * to scan for a channel twice, so disallow that | |
5666 | * and don't require drivers to check that the | |
5667 | * channel list they get isn't longer than what | |
5668 | * they can scan, as long as they can scan all | |
5669 | * the channels they registered at once. | |
5670 | */ | |
5671 | nla_for_each_nested(attr2, freqs, tmp2) | |
5672 | if (attr1 != attr2 && | |
5673 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5674 | return 0; | |
5675 | } | |
5676 | ||
5677 | return n_channels; | |
5678 | } | |
5679 | ||
ad2b26ab JB |
5680 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
5681 | u8 *mac_addr, u8 *mac_addr_mask) | |
5682 | { | |
5683 | int i; | |
5684 | ||
5685 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { | |
5686 | memset(mac_addr, 0, ETH_ALEN); | |
5687 | memset(mac_addr_mask, 0, ETH_ALEN); | |
5688 | mac_addr[0] = 0x2; | |
5689 | mac_addr_mask[0] = 0x3; | |
5690 | ||
5691 | return 0; | |
5692 | } | |
5693 | ||
5694 | /* need both or none */ | |
5695 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) | |
5696 | return -EINVAL; | |
5697 | ||
5698 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); | |
5699 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); | |
5700 | ||
5701 | /* don't allow or configure an mcast address */ | |
5702 | if (!is_multicast_ether_addr(mac_addr_mask) || | |
5703 | is_multicast_ether_addr(mac_addr)) | |
5704 | return -EINVAL; | |
5705 | ||
5706 | /* | |
5707 | * allow users to pass a MAC address that has bits set outside | |
5708 | * of the mask, but don't bother drivers with having to deal | |
5709 | * with such bits | |
5710 | */ | |
5711 | for (i = 0; i < ETH_ALEN; i++) | |
5712 | mac_addr[i] &= mac_addr_mask[i]; | |
5713 | ||
5714 | return 0; | |
5715 | } | |
5716 | ||
2a519311 JB |
5717 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5718 | { | |
4c476991 | 5719 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5720 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5721 | struct cfg80211_scan_request *request; |
2a519311 JB |
5722 | struct nlattr *attr; |
5723 | struct wiphy *wiphy; | |
83f5e2cf | 5724 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5725 | size_t ie_len; |
2a519311 | 5726 | |
f4a11bb0 JB |
5727 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5728 | return -EINVAL; | |
5729 | ||
79c97e97 | 5730 | wiphy = &rdev->wiphy; |
2a519311 | 5731 | |
4c476991 JB |
5732 | if (!rdev->ops->scan) |
5733 | return -EOPNOTSUPP; | |
2a519311 | 5734 | |
f9d15d16 | 5735 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
5736 | err = -EBUSY; |
5737 | goto unlock; | |
5738 | } | |
2a519311 JB |
5739 | |
5740 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5741 | n_channels = validate_scan_freqs( |
5742 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5743 | if (!n_channels) { |
5744 | err = -EINVAL; | |
5745 | goto unlock; | |
5746 | } | |
2a519311 | 5747 | } else { |
bdfbec2d | 5748 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
5749 | } |
5750 | ||
5751 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5752 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5753 | n_ssids++; | |
5754 | ||
f9f47529 JB |
5755 | if (n_ssids > wiphy->max_scan_ssids) { |
5756 | err = -EINVAL; | |
5757 | goto unlock; | |
5758 | } | |
2a519311 | 5759 | |
70692ad2 JM |
5760 | if (info->attrs[NL80211_ATTR_IE]) |
5761 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5762 | else | |
5763 | ie_len = 0; | |
5764 | ||
f9f47529 JB |
5765 | if (ie_len > wiphy->max_scan_ie_len) { |
5766 | err = -EINVAL; | |
5767 | goto unlock; | |
5768 | } | |
18a83659 | 5769 | |
2a519311 | 5770 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5771 | + sizeof(*request->ssids) * n_ssids |
5772 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5773 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5774 | if (!request) { |
5775 | err = -ENOMEM; | |
5776 | goto unlock; | |
5777 | } | |
2a519311 | 5778 | |
2a519311 | 5779 | if (n_ssids) |
5ba63533 | 5780 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5781 | request->n_ssids = n_ssids; |
70692ad2 | 5782 | if (ie_len) { |
13874e4b | 5783 | if (n_ssids) |
70692ad2 JM |
5784 | request->ie = (void *)(request->ssids + n_ssids); |
5785 | else | |
5786 | request->ie = (void *)(request->channels + n_channels); | |
5787 | } | |
2a519311 | 5788 | |
584991dc | 5789 | i = 0; |
2a519311 JB |
5790 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5791 | /* user specified, bail out if channel not found */ | |
2a519311 | 5792 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5793 | struct ieee80211_channel *chan; |
5794 | ||
5795 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5796 | ||
5797 | if (!chan) { | |
2a519311 JB |
5798 | err = -EINVAL; |
5799 | goto out_free; | |
5800 | } | |
584991dc JB |
5801 | |
5802 | /* ignore disabled channels */ | |
5803 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5804 | continue; | |
5805 | ||
5806 | request->channels[i] = chan; | |
2a519311 JB |
5807 | i++; |
5808 | } | |
5809 | } else { | |
34850ab2 JB |
5810 | enum ieee80211_band band; |
5811 | ||
2a519311 | 5812 | /* all channels */ |
2a519311 JB |
5813 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5814 | int j; | |
5815 | if (!wiphy->bands[band]) | |
5816 | continue; | |
5817 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5818 | struct ieee80211_channel *chan; |
5819 | ||
5820 | chan = &wiphy->bands[band]->channels[j]; | |
5821 | ||
5822 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5823 | continue; | |
5824 | ||
5825 | request->channels[i] = chan; | |
2a519311 JB |
5826 | i++; |
5827 | } | |
5828 | } | |
5829 | } | |
5830 | ||
584991dc JB |
5831 | if (!i) { |
5832 | err = -EINVAL; | |
5833 | goto out_free; | |
5834 | } | |
5835 | ||
5836 | request->n_channels = i; | |
5837 | ||
2a519311 | 5838 | i = 0; |
13874e4b | 5839 | if (n_ssids) { |
2a519311 | 5840 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
57a27e1d | 5841 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5842 | err = -EINVAL; |
5843 | goto out_free; | |
5844 | } | |
57a27e1d | 5845 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5846 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5847 | i++; |
5848 | } | |
5849 | } | |
5850 | ||
70692ad2 JM |
5851 | if (info->attrs[NL80211_ATTR_IE]) { |
5852 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5853 | memcpy((void *)request->ie, |
5854 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5855 | request->ie_len); |
5856 | } | |
5857 | ||
34850ab2 | 5858 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5859 | if (wiphy->bands[i]) |
5860 | request->rates[i] = | |
5861 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5862 | |
5863 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5864 | nla_for_each_nested(attr, | |
5865 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5866 | tmp) { | |
5867 | enum ieee80211_band band = nla_type(attr); | |
5868 | ||
84404623 | 5869 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5870 | err = -EINVAL; |
5871 | goto out_free; | |
5872 | } | |
1b09cd82 FF |
5873 | |
5874 | if (!wiphy->bands[band]) | |
5875 | continue; | |
5876 | ||
34850ab2 JB |
5877 | err = ieee80211_get_ratemask(wiphy->bands[band], |
5878 | nla_data(attr), | |
5879 | nla_len(attr), | |
5880 | &request->rates[band]); | |
5881 | if (err) | |
5882 | goto out_free; | |
5883 | } | |
5884 | } | |
5885 | ||
46856bbf | 5886 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5887 | request->flags = nla_get_u32( |
5888 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5889 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5890 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5891 | err = -EOPNOTSUPP; |
5892 | goto out_free; | |
5893 | } | |
ad2b26ab JB |
5894 | |
5895 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
5896 | if (!(wiphy->features & | |
5897 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { | |
5898 | err = -EOPNOTSUPP; | |
5899 | goto out_free; | |
5900 | } | |
5901 | ||
5902 | if (wdev->current_bss) { | |
5903 | err = -EOPNOTSUPP; | |
5904 | goto out_free; | |
5905 | } | |
5906 | ||
5907 | err = nl80211_parse_random_mac(info->attrs, | |
5908 | request->mac_addr, | |
5909 | request->mac_addr_mask); | |
5910 | if (err) | |
5911 | goto out_free; | |
5912 | } | |
46856bbf | 5913 | } |
ed473771 | 5914 | |
e9f935e3 RM |
5915 | request->no_cck = |
5916 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5917 | ||
fd014284 | 5918 | request->wdev = wdev; |
79c97e97 | 5919 | request->wiphy = &rdev->wiphy; |
15d6030b | 5920 | request->scan_start = jiffies; |
2a519311 | 5921 | |
79c97e97 | 5922 | rdev->scan_req = request; |
e35e4d28 | 5923 | err = rdev_scan(rdev, request); |
2a519311 | 5924 | |
463d0183 | 5925 | if (!err) { |
fd014284 JB |
5926 | nl80211_send_scan_start(rdev, wdev); |
5927 | if (wdev->netdev) | |
5928 | dev_hold(wdev->netdev); | |
4c476991 | 5929 | } else { |
2a519311 | 5930 | out_free: |
79c97e97 | 5931 | rdev->scan_req = NULL; |
2a519311 JB |
5932 | kfree(request); |
5933 | } | |
3b85875a | 5934 | |
f9f47529 | 5935 | unlock: |
2a519311 JB |
5936 | return err; |
5937 | } | |
5938 | ||
256da02d | 5939 | static struct cfg80211_sched_scan_request * |
ad2b26ab | 5940 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
256da02d | 5941 | struct nlattr **attrs) |
807f8a8c LC |
5942 | { |
5943 | struct cfg80211_sched_scan_request *request; | |
807f8a8c | 5944 | struct nlattr *attr; |
a1f1c21c | 5945 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5946 | u32 interval; |
807f8a8c LC |
5947 | enum ieee80211_band band; |
5948 | size_t ie_len; | |
a1f1c21c | 5949 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 5950 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c | 5951 | |
256da02d LC |
5952 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
5953 | return ERR_PTR(-EINVAL); | |
807f8a8c | 5954 | |
256da02d LC |
5955 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5956 | return ERR_PTR(-EINVAL); | |
bbe6ad6d | 5957 | |
256da02d | 5958 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
bbe6ad6d | 5959 | if (interval == 0) |
256da02d | 5960 | return ERR_PTR(-EINVAL); |
807f8a8c | 5961 | |
256da02d | 5962 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c | 5963 | n_channels = validate_scan_freqs( |
256da02d | 5964 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
807f8a8c | 5965 | if (!n_channels) |
256da02d | 5966 | return ERR_PTR(-EINVAL); |
807f8a8c | 5967 | } else { |
bdfbec2d | 5968 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
5969 | } |
5970 | ||
256da02d LC |
5971 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
5972 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c LC |
5973 | tmp) |
5974 | n_ssids++; | |
5975 | ||
93b6aa69 | 5976 | if (n_ssids > wiphy->max_sched_scan_ssids) |
256da02d | 5977 | return ERR_PTR(-EINVAL); |
807f8a8c | 5978 | |
ea73cbce JB |
5979 | /* |
5980 | * First, count the number of 'real' matchsets. Due to an issue with | |
5981 | * the old implementation, matchsets containing only the RSSI attribute | |
5982 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
5983 | * RSSI for all matchsets, rather than their own matchset for reporting | |
5984 | * all APs with a strong RSSI. This is needed to be compatible with | |
5985 | * older userspace that treated a matchset with only the RSSI as the | |
5986 | * global RSSI for all other matchsets - if there are other matchsets. | |
5987 | */ | |
256da02d | 5988 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 5989 | nla_for_each_nested(attr, |
256da02d | 5990 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
ea73cbce JB |
5991 | tmp) { |
5992 | struct nlattr *rssi; | |
5993 | ||
5994 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5995 | nla_data(attr), nla_len(attr), | |
5996 | nl80211_match_policy); | |
5997 | if (err) | |
256da02d | 5998 | return ERR_PTR(err); |
ea73cbce JB |
5999 | /* add other standalone attributes here */ |
6000 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | |
6001 | n_match_sets++; | |
6002 | continue; | |
6003 | } | |
6004 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6005 | if (rssi) | |
6006 | default_match_rssi = nla_get_s32(rssi); | |
6007 | } | |
6008 | } | |
6009 | ||
6010 | /* However, if there's no other matchset, add the RSSI one */ | |
6011 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
6012 | n_match_sets = 1; | |
a1f1c21c LC |
6013 | |
6014 | if (n_match_sets > wiphy->max_match_sets) | |
256da02d | 6015 | return ERR_PTR(-EINVAL); |
a1f1c21c | 6016 | |
256da02d LC |
6017 | if (attrs[NL80211_ATTR_IE]) |
6018 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); | |
807f8a8c LC |
6019 | else |
6020 | ie_len = 0; | |
6021 | ||
5a865bad | 6022 | if (ie_len > wiphy->max_sched_scan_ie_len) |
256da02d | 6023 | return ERR_PTR(-EINVAL); |
c10841ca | 6024 | |
807f8a8c | 6025 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 6026 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 6027 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 6028 | + sizeof(*request->channels) * n_channels |
807f8a8c | 6029 | + ie_len, GFP_KERNEL); |
256da02d LC |
6030 | if (!request) |
6031 | return ERR_PTR(-ENOMEM); | |
807f8a8c LC |
6032 | |
6033 | if (n_ssids) | |
6034 | request->ssids = (void *)&request->channels[n_channels]; | |
6035 | request->n_ssids = n_ssids; | |
6036 | if (ie_len) { | |
13874e4b | 6037 | if (n_ssids) |
807f8a8c LC |
6038 | request->ie = (void *)(request->ssids + n_ssids); |
6039 | else | |
6040 | request->ie = (void *)(request->channels + n_channels); | |
6041 | } | |
6042 | ||
a1f1c21c LC |
6043 | if (n_match_sets) { |
6044 | if (request->ie) | |
6045 | request->match_sets = (void *)(request->ie + ie_len); | |
13874e4b | 6046 | else if (n_ssids) |
a1f1c21c LC |
6047 | request->match_sets = |
6048 | (void *)(request->ssids + n_ssids); | |
6049 | else | |
6050 | request->match_sets = | |
6051 | (void *)(request->channels + n_channels); | |
6052 | } | |
6053 | request->n_match_sets = n_match_sets; | |
6054 | ||
807f8a8c | 6055 | i = 0; |
256da02d | 6056 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c LC |
6057 | /* user specified, bail out if channel not found */ |
6058 | nla_for_each_nested(attr, | |
256da02d | 6059 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
807f8a8c LC |
6060 | tmp) { |
6061 | struct ieee80211_channel *chan; | |
6062 | ||
6063 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
6064 | ||
6065 | if (!chan) { | |
6066 | err = -EINVAL; | |
6067 | goto out_free; | |
6068 | } | |
6069 | ||
6070 | /* ignore disabled channels */ | |
6071 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6072 | continue; | |
6073 | ||
6074 | request->channels[i] = chan; | |
6075 | i++; | |
6076 | } | |
6077 | } else { | |
6078 | /* all channels */ | |
6079 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6080 | int j; | |
6081 | if (!wiphy->bands[band]) | |
6082 | continue; | |
6083 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
6084 | struct ieee80211_channel *chan; | |
6085 | ||
6086 | chan = &wiphy->bands[band]->channels[j]; | |
6087 | ||
6088 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6089 | continue; | |
6090 | ||
6091 | request->channels[i] = chan; | |
6092 | i++; | |
6093 | } | |
6094 | } | |
6095 | } | |
6096 | ||
6097 | if (!i) { | |
6098 | err = -EINVAL; | |
6099 | goto out_free; | |
6100 | } | |
6101 | ||
6102 | request->n_channels = i; | |
6103 | ||
6104 | i = 0; | |
13874e4b | 6105 | if (n_ssids) { |
256da02d | 6106 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
807f8a8c | 6107 | tmp) { |
57a27e1d | 6108 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
6109 | err = -EINVAL; |
6110 | goto out_free; | |
6111 | } | |
57a27e1d | 6112 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
6113 | memcpy(request->ssids[i].ssid, nla_data(attr), |
6114 | nla_len(attr)); | |
807f8a8c LC |
6115 | i++; |
6116 | } | |
6117 | } | |
6118 | ||
a1f1c21c | 6119 | i = 0; |
256da02d | 6120 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 6121 | nla_for_each_nested(attr, |
256da02d | 6122 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
a1f1c21c | 6123 | tmp) { |
88e920b4 | 6124 | struct nlattr *ssid, *rssi; |
a1f1c21c | 6125 | |
ae811e21 JB |
6126 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
6127 | nla_data(attr), nla_len(attr), | |
6128 | nl80211_match_policy); | |
6129 | if (err) | |
6130 | goto out_free; | |
4a4ab0d7 | 6131 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 6132 | if (ssid) { |
ea73cbce JB |
6133 | if (WARN_ON(i >= n_match_sets)) { |
6134 | /* this indicates a programming error, | |
6135 | * the loop above should have verified | |
6136 | * things properly | |
6137 | */ | |
6138 | err = -EINVAL; | |
6139 | goto out_free; | |
6140 | } | |
6141 | ||
a1f1c21c LC |
6142 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
6143 | err = -EINVAL; | |
6144 | goto out_free; | |
6145 | } | |
6146 | memcpy(request->match_sets[i].ssid.ssid, | |
6147 | nla_data(ssid), nla_len(ssid)); | |
6148 | request->match_sets[i].ssid.ssid_len = | |
6149 | nla_len(ssid); | |
ea73cbce JB |
6150 | /* special attribute - old implemenation w/a */ |
6151 | request->match_sets[i].rssi_thold = | |
6152 | default_match_rssi; | |
6153 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6154 | if (rssi) | |
6155 | request->match_sets[i].rssi_thold = | |
6156 | nla_get_s32(rssi); | |
a1f1c21c LC |
6157 | } |
6158 | i++; | |
6159 | } | |
ea73cbce JB |
6160 | |
6161 | /* there was no other matchset, so the RSSI one is alone */ | |
f89f46cf | 6162 | if (i == 0 && n_match_sets) |
ea73cbce JB |
6163 | request->match_sets[0].rssi_thold = default_match_rssi; |
6164 | ||
6165 | request->min_rssi_thold = INT_MAX; | |
6166 | for (i = 0; i < n_match_sets; i++) | |
6167 | request->min_rssi_thold = | |
6168 | min(request->match_sets[i].rssi_thold, | |
6169 | request->min_rssi_thold); | |
6170 | } else { | |
6171 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
6172 | } |
6173 | ||
9900e484 JB |
6174 | if (ie_len) { |
6175 | request->ie_len = ie_len; | |
807f8a8c | 6176 | memcpy((void *)request->ie, |
256da02d | 6177 | nla_data(attrs[NL80211_ATTR_IE]), |
807f8a8c LC |
6178 | request->ie_len); |
6179 | } | |
6180 | ||
256da02d | 6181 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 | 6182 | request->flags = nla_get_u32( |
256da02d | 6183 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
00c3a6ed JB |
6184 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
6185 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
6186 | err = -EOPNOTSUPP; |
6187 | goto out_free; | |
6188 | } | |
ad2b26ab JB |
6189 | |
6190 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
6191 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; | |
6192 | ||
6193 | if (!wdev) /* must be net-detect */ | |
6194 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
6195 | ||
6196 | if (!(wiphy->features & flg)) { | |
6197 | err = -EOPNOTSUPP; | |
6198 | goto out_free; | |
6199 | } | |
6200 | ||
6201 | if (wdev && wdev->current_bss) { | |
6202 | err = -EOPNOTSUPP; | |
6203 | goto out_free; | |
6204 | } | |
6205 | ||
6206 | err = nl80211_parse_random_mac(attrs, request->mac_addr, | |
6207 | request->mac_addr_mask); | |
6208 | if (err) | |
6209 | goto out_free; | |
6210 | } | |
46856bbf | 6211 | } |
ed473771 | 6212 | |
9c748934 LC |
6213 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
6214 | request->delay = | |
6215 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); | |
6216 | ||
bbe6ad6d | 6217 | request->interval = interval; |
15d6030b | 6218 | request->scan_start = jiffies; |
807f8a8c | 6219 | |
256da02d | 6220 | return request; |
807f8a8c LC |
6221 | |
6222 | out_free: | |
6223 | kfree(request); | |
256da02d LC |
6224 | return ERR_PTR(err); |
6225 | } | |
6226 | ||
6227 | static int nl80211_start_sched_scan(struct sk_buff *skb, | |
6228 | struct genl_info *info) | |
6229 | { | |
6230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6231 | struct net_device *dev = info->user_ptr[1]; | |
ad2b26ab | 6232 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
31a60ed1 | 6233 | struct cfg80211_sched_scan_request *sched_scan_req; |
256da02d LC |
6234 | int err; |
6235 | ||
6236 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6237 | !rdev->ops->sched_scan_start) | |
6238 | return -EOPNOTSUPP; | |
6239 | ||
6240 | if (rdev->sched_scan_req) | |
6241 | return -EINPROGRESS; | |
6242 | ||
31a60ed1 JR |
6243 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
6244 | info->attrs); | |
6245 | ||
6246 | err = PTR_ERR_OR_ZERO(sched_scan_req); | |
256da02d LC |
6247 | if (err) |
6248 | goto out_err; | |
6249 | ||
31a60ed1 | 6250 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
256da02d LC |
6251 | if (err) |
6252 | goto out_free; | |
6253 | ||
31a60ed1 JR |
6254 | sched_scan_req->dev = dev; |
6255 | sched_scan_req->wiphy = &rdev->wiphy; | |
6256 | ||
93a1e86c JR |
6257 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
6258 | sched_scan_req->owner_nlportid = info->snd_portid; | |
6259 | ||
31a60ed1 | 6260 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
256da02d LC |
6261 | |
6262 | nl80211_send_sched_scan(rdev, dev, | |
6263 | NL80211_CMD_START_SCHED_SCAN); | |
6264 | return 0; | |
6265 | ||
6266 | out_free: | |
31a60ed1 | 6267 | kfree(sched_scan_req); |
256da02d | 6268 | out_err: |
807f8a8c LC |
6269 | return err; |
6270 | } | |
6271 | ||
6272 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
6273 | struct genl_info *info) | |
6274 | { | |
6275 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6276 | ||
6277 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6278 | !rdev->ops->sched_scan_stop) | |
6279 | return -EOPNOTSUPP; | |
6280 | ||
5fe231e8 | 6281 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
6282 | } |
6283 | ||
04f39047 SW |
6284 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
6285 | struct genl_info *info) | |
6286 | { | |
6287 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6288 | struct net_device *dev = info->user_ptr[1]; | |
6289 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6290 | struct cfg80211_chan_def chandef; | |
55f7435c | 6291 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 6292 | unsigned int cac_time_ms; |
04f39047 SW |
6293 | int err; |
6294 | ||
55f7435c LR |
6295 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
6296 | if (dfs_region == NL80211_DFS_UNSET) | |
6297 | return -EINVAL; | |
6298 | ||
04f39047 SW |
6299 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6300 | if (err) | |
6301 | return err; | |
6302 | ||
ff311bc1 SW |
6303 | if (netif_carrier_ok(dev)) |
6304 | return -EBUSY; | |
6305 | ||
04f39047 SW |
6306 | if (wdev->cac_started) |
6307 | return -EBUSY; | |
6308 | ||
2beb6dab | 6309 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
00ec75fc | 6310 | wdev->iftype); |
04f39047 SW |
6311 | if (err < 0) |
6312 | return err; | |
6313 | ||
6314 | if (err == 0) | |
6315 | return -EINVAL; | |
6316 | ||
fe7c3a1f | 6317 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
6318 | return -EINVAL; |
6319 | ||
6320 | if (!rdev->ops->start_radar_detection) | |
6321 | return -EOPNOTSUPP; | |
6322 | ||
31559f35 JD |
6323 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
6324 | if (WARN_ON(!cac_time_ms)) | |
6325 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
6326 | ||
6327 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, | |
6328 | cac_time_ms); | |
04f39047 | 6329 | if (!err) { |
9e0e2961 | 6330 | wdev->chandef = chandef; |
04f39047 SW |
6331 | wdev->cac_started = true; |
6332 | wdev->cac_start_time = jiffies; | |
31559f35 | 6333 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 6334 | } |
04f39047 SW |
6335 | return err; |
6336 | } | |
6337 | ||
16ef1fe2 SW |
6338 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
6339 | { | |
6340 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6341 | struct net_device *dev = info->user_ptr[1]; | |
6342 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6343 | struct cfg80211_csa_settings params; | |
6344 | /* csa_attrs is defined static to avoid waste of stack size - this | |
6345 | * function is called under RTNL lock, so this should not be a problem. | |
6346 | */ | |
6347 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
16ef1fe2 | 6348 | int err; |
ee4bc9e7 | 6349 | bool need_new_beacon = false; |
9a774c78 | 6350 | int len, i; |
252e07ca | 6351 | u32 cs_count; |
16ef1fe2 SW |
6352 | |
6353 | if (!rdev->ops->channel_switch || | |
6354 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
6355 | return -EOPNOTSUPP; | |
6356 | ||
ee4bc9e7 SW |
6357 | switch (dev->ieee80211_ptr->iftype) { |
6358 | case NL80211_IFTYPE_AP: | |
6359 | case NL80211_IFTYPE_P2P_GO: | |
6360 | need_new_beacon = true; | |
6361 | ||
6362 | /* useless if AP is not running */ | |
6363 | if (!wdev->beacon_interval) | |
1ff79dfa | 6364 | return -ENOTCONN; |
ee4bc9e7 SW |
6365 | break; |
6366 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
6367 | if (!wdev->ssid_len) |
6368 | return -ENOTCONN; | |
6369 | break; | |
c6da674a | 6370 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
6371 | if (!wdev->mesh_id_len) |
6372 | return -ENOTCONN; | |
ee4bc9e7 SW |
6373 | break; |
6374 | default: | |
16ef1fe2 | 6375 | return -EOPNOTSUPP; |
ee4bc9e7 | 6376 | } |
16ef1fe2 SW |
6377 | |
6378 | memset(¶ms, 0, sizeof(params)); | |
6379 | ||
6380 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6381 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
6382 | return -EINVAL; | |
6383 | ||
6384 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 6385 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
6386 | return -EINVAL; |
6387 | ||
252e07ca LC |
6388 | /* Even though the attribute is u32, the specification says |
6389 | * u8, so let's make sure we don't overflow. | |
6390 | */ | |
6391 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
6392 | if (cs_count > 255) | |
6393 | return -EINVAL; | |
6394 | ||
6395 | params.count = cs_count; | |
16ef1fe2 | 6396 | |
ee4bc9e7 SW |
6397 | if (!need_new_beacon) |
6398 | goto skip_beacons; | |
6399 | ||
16ef1fe2 SW |
6400 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
6401 | if (err) | |
6402 | return err; | |
6403 | ||
6404 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
6405 | info->attrs[NL80211_ATTR_CSA_IES], | |
6406 | nl80211_policy); | |
6407 | if (err) | |
6408 | return err; | |
6409 | ||
6410 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
6411 | if (err) | |
6412 | return err; | |
6413 | ||
6414 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
6415 | return -EINVAL; | |
6416 | ||
9a774c78 AO |
6417 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
6418 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6419 | return -EINVAL; |
6420 | ||
9a774c78 AO |
6421 | params.n_counter_offsets_beacon = len / sizeof(u16); |
6422 | if (rdev->wiphy.max_num_csa_counters && | |
6423 | (params.n_counter_offsets_beacon > | |
6424 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
6425 | return -EINVAL; |
6426 | ||
9a774c78 AO |
6427 | params.counter_offsets_beacon = |
6428 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
6429 | ||
6430 | /* sanity checks - counters should fit and be the same */ | |
6431 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
6432 | u16 offset = params.counter_offsets_beacon[i]; | |
6433 | ||
6434 | if (offset >= params.beacon_csa.tail_len) | |
6435 | return -EINVAL; | |
6436 | ||
6437 | if (params.beacon_csa.tail[offset] != params.count) | |
6438 | return -EINVAL; | |
6439 | } | |
6440 | ||
16ef1fe2 | 6441 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
6442 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
6443 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6444 | return -EINVAL; |
6445 | ||
9a774c78 AO |
6446 | params.n_counter_offsets_presp = len / sizeof(u16); |
6447 | if (rdev->wiphy.max_num_csa_counters && | |
6448 | (params.n_counter_offsets_beacon > | |
6449 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 | 6450 | return -EINVAL; |
9a774c78 AO |
6451 | |
6452 | params.counter_offsets_presp = | |
6453 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
6454 | ||
6455 | /* sanity checks - counters should fit and be the same */ | |
6456 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
6457 | u16 offset = params.counter_offsets_presp[i]; | |
6458 | ||
6459 | if (offset >= params.beacon_csa.probe_resp_len) | |
6460 | return -EINVAL; | |
6461 | ||
6462 | if (params.beacon_csa.probe_resp[offset] != | |
6463 | params.count) | |
6464 | return -EINVAL; | |
6465 | } | |
16ef1fe2 SW |
6466 | } |
6467 | ||
ee4bc9e7 | 6468 | skip_beacons: |
16ef1fe2 SW |
6469 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
6470 | if (err) | |
6471 | return err; | |
6472 | ||
174e0cd2 IP |
6473 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
6474 | wdev->iftype)) | |
16ef1fe2 SW |
6475 | return -EINVAL; |
6476 | ||
2beb6dab LC |
6477 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
6478 | ¶ms.chandef, | |
6479 | wdev->iftype); | |
6480 | if (err < 0) | |
6481 | return err; | |
6482 | ||
dcc6c2f5 | 6483 | if (err > 0) |
2beb6dab | 6484 | params.radar_required = true; |
16ef1fe2 | 6485 | |
16ef1fe2 SW |
6486 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
6487 | params.block_tx = true; | |
6488 | ||
c56589ed SW |
6489 | wdev_lock(wdev); |
6490 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
6491 | wdev_unlock(wdev); | |
6492 | ||
6493 | return err; | |
16ef1fe2 SW |
6494 | } |
6495 | ||
9720bb3a JB |
6496 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
6497 | u32 seq, int flags, | |
2a519311 | 6498 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
6499 | struct wireless_dev *wdev, |
6500 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 6501 | { |
48ab905d | 6502 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 6503 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
6504 | void *hdr; |
6505 | struct nlattr *bss; | |
48ab905d JB |
6506 | |
6507 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 6508 | |
15e47304 | 6509 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
6510 | NL80211_CMD_NEW_SCAN_RESULTS); |
6511 | if (!hdr) | |
6512 | return -1; | |
6513 | ||
9720bb3a JB |
6514 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
6515 | ||
97990a06 JB |
6516 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
6517 | goto nla_put_failure; | |
6518 | if (wdev->netdev && | |
9360ffd1 DM |
6519 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
6520 | goto nla_put_failure; | |
97990a06 JB |
6521 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
6522 | goto nla_put_failure; | |
2a519311 JB |
6523 | |
6524 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
6525 | if (!bss) | |
6526 | goto nla_put_failure; | |
9360ffd1 | 6527 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 6528 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 6529 | goto nla_put_failure; |
9caf0364 JB |
6530 | |
6531 | rcu_read_lock(); | |
0e227084 JB |
6532 | /* indicate whether we have probe response data or not */ |
6533 | if (rcu_access_pointer(res->proberesp_ies) && | |
6534 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
6535 | goto fail_unlock_rcu; | |
6536 | ||
6537 | /* this pointer prefers to be pointed to probe response data | |
6538 | * but is always valid | |
6539 | */ | |
9caf0364 | 6540 | ies = rcu_dereference(res->ies); |
8cef2c9d JB |
6541 | if (ies) { |
6542 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
6543 | goto fail_unlock_rcu; | |
8cef2c9d JB |
6544 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
6545 | ies->len, ies->data)) | |
6546 | goto fail_unlock_rcu; | |
9caf0364 | 6547 | } |
0e227084 JB |
6548 | |
6549 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 6550 | ies = rcu_dereference(res->beacon_ies); |
0e227084 JB |
6551 | if (ies && ies->from_beacon) { |
6552 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) | |
8cef2c9d JB |
6553 | goto fail_unlock_rcu; |
6554 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
6555 | ies->len, ies->data)) | |
6556 | goto fail_unlock_rcu; | |
9caf0364 JB |
6557 | } |
6558 | rcu_read_unlock(); | |
6559 | ||
9360ffd1 DM |
6560 | if (res->beacon_interval && |
6561 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
6562 | goto nla_put_failure; | |
6563 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
6564 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 6565 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
6566 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
6567 | jiffies_to_msecs(jiffies - intbss->ts))) | |
6568 | goto nla_put_failure; | |
2a519311 | 6569 | |
77965c97 | 6570 | switch (rdev->wiphy.signal_type) { |
2a519311 | 6571 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
6572 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
6573 | goto nla_put_failure; | |
2a519311 JB |
6574 | break; |
6575 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
6576 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
6577 | goto nla_put_failure; | |
2a519311 JB |
6578 | break; |
6579 | default: | |
6580 | break; | |
6581 | } | |
6582 | ||
48ab905d | 6583 | switch (wdev->iftype) { |
074ac8df | 6584 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 6585 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
6586 | if (intbss == wdev->current_bss && |
6587 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6588 | NL80211_BSS_STATUS_ASSOCIATED)) | |
6589 | goto nla_put_failure; | |
48ab905d JB |
6590 | break; |
6591 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
6592 | if (intbss == wdev->current_bss && |
6593 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6594 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
6595 | goto nla_put_failure; | |
48ab905d JB |
6596 | break; |
6597 | default: | |
6598 | break; | |
6599 | } | |
6600 | ||
2a519311 JB |
6601 | nla_nest_end(msg, bss); |
6602 | ||
053c095a JB |
6603 | genlmsg_end(msg, hdr); |
6604 | return 0; | |
2a519311 | 6605 | |
8cef2c9d JB |
6606 | fail_unlock_rcu: |
6607 | rcu_read_unlock(); | |
2a519311 JB |
6608 | nla_put_failure: |
6609 | genlmsg_cancel(msg, hdr); | |
6610 | return -EMSGSIZE; | |
6611 | } | |
6612 | ||
97990a06 | 6613 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 6614 | { |
48ab905d | 6615 | struct cfg80211_registered_device *rdev; |
2a519311 | 6616 | struct cfg80211_internal_bss *scan; |
48ab905d | 6617 | struct wireless_dev *wdev; |
97990a06 | 6618 | int start = cb->args[2], idx = 0; |
2a519311 JB |
6619 | int err; |
6620 | ||
97990a06 | 6621 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6622 | if (err) |
6623 | return err; | |
2a519311 | 6624 | |
48ab905d JB |
6625 | wdev_lock(wdev); |
6626 | spin_lock_bh(&rdev->bss_lock); | |
6627 | cfg80211_bss_expire(rdev); | |
6628 | ||
9720bb3a JB |
6629 | cb->seq = rdev->bss_generation; |
6630 | ||
48ab905d | 6631 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
6632 | if (++idx <= start) |
6633 | continue; | |
9720bb3a | 6634 | if (nl80211_send_bss(skb, cb, |
2a519311 | 6635 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 6636 | rdev, wdev, scan) < 0) { |
2a519311 | 6637 | idx--; |
67748893 | 6638 | break; |
2a519311 JB |
6639 | } |
6640 | } | |
6641 | ||
48ab905d JB |
6642 | spin_unlock_bh(&rdev->bss_lock); |
6643 | wdev_unlock(wdev); | |
2a519311 | 6644 | |
97990a06 JB |
6645 | cb->args[2] = idx; |
6646 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 6647 | |
67748893 | 6648 | return skb->len; |
2a519311 JB |
6649 | } |
6650 | ||
15e47304 | 6651 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
11f78ac3 JB |
6652 | int flags, struct net_device *dev, |
6653 | bool allow_radio_stats, | |
6654 | struct survey_info *survey) | |
61fa713c HS |
6655 | { |
6656 | void *hdr; | |
6657 | struct nlattr *infoattr; | |
6658 | ||
11f78ac3 JB |
6659 | /* skip radio stats if userspace didn't request them */ |
6660 | if (!survey->channel && !allow_radio_stats) | |
6661 | return 0; | |
6662 | ||
15e47304 | 6663 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
6664 | NL80211_CMD_NEW_SURVEY_RESULTS); |
6665 | if (!hdr) | |
6666 | return -ENOMEM; | |
6667 | ||
9360ffd1 DM |
6668 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
6669 | goto nla_put_failure; | |
61fa713c HS |
6670 | |
6671 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
6672 | if (!infoattr) | |
6673 | goto nla_put_failure; | |
6674 | ||
11f78ac3 JB |
6675 | if (survey->channel && |
6676 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
9360ffd1 DM |
6677 | survey->channel->center_freq)) |
6678 | goto nla_put_failure; | |
6679 | ||
6680 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
6681 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
6682 | goto nla_put_failure; | |
6683 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
6684 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
6685 | goto nla_put_failure; | |
4ed20beb JB |
6686 | if ((survey->filled & SURVEY_INFO_TIME) && |
6687 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME, | |
6688 | survey->time)) | |
9360ffd1 | 6689 | goto nla_put_failure; |
4ed20beb JB |
6690 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
6691 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY, | |
6692 | survey->time_busy)) | |
9360ffd1 | 6693 | goto nla_put_failure; |
4ed20beb JB |
6694 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
6695 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, | |
6696 | survey->time_ext_busy)) | |
9360ffd1 | 6697 | goto nla_put_failure; |
4ed20beb JB |
6698 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
6699 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX, | |
6700 | survey->time_rx)) | |
9360ffd1 | 6701 | goto nla_put_failure; |
4ed20beb JB |
6702 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
6703 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX, | |
6704 | survey->time_tx)) | |
9360ffd1 | 6705 | goto nla_put_failure; |
052536ab JB |
6706 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
6707 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN, | |
6708 | survey->time_scan)) | |
6709 | goto nla_put_failure; | |
61fa713c HS |
6710 | |
6711 | nla_nest_end(msg, infoattr); | |
6712 | ||
053c095a JB |
6713 | genlmsg_end(msg, hdr); |
6714 | return 0; | |
61fa713c HS |
6715 | |
6716 | nla_put_failure: | |
6717 | genlmsg_cancel(msg, hdr); | |
6718 | return -EMSGSIZE; | |
6719 | } | |
6720 | ||
11f78ac3 | 6721 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
61fa713c HS |
6722 | { |
6723 | struct survey_info survey; | |
1b8ec87a | 6724 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
6725 | struct wireless_dev *wdev; |
6726 | int survey_idx = cb->args[2]; | |
61fa713c | 6727 | int res; |
11f78ac3 | 6728 | bool radio_stats; |
61fa713c | 6729 | |
1b8ec87a | 6730 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6731 | if (res) |
6732 | return res; | |
61fa713c | 6733 | |
11f78ac3 JB |
6734 | /* prepare_wdev_dump parsed the attributes */ |
6735 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; | |
6736 | ||
97990a06 JB |
6737 | if (!wdev->netdev) { |
6738 | res = -EINVAL; | |
6739 | goto out_err; | |
6740 | } | |
6741 | ||
1b8ec87a | 6742 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
6743 | res = -EOPNOTSUPP; |
6744 | goto out_err; | |
6745 | } | |
6746 | ||
6747 | while (1) { | |
1b8ec87a | 6748 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
6749 | if (res == -ENOENT) |
6750 | break; | |
6751 | if (res) | |
6752 | goto out_err; | |
6753 | ||
11f78ac3 JB |
6754 | /* don't send disabled channels, but do send non-channel data */ |
6755 | if (survey.channel && | |
6756 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { | |
180cdc79 LR |
6757 | survey_idx++; |
6758 | continue; | |
6759 | } | |
6760 | ||
61fa713c | 6761 | if (nl80211_send_survey(skb, |
15e47304 | 6762 | NETLINK_CB(cb->skb).portid, |
61fa713c | 6763 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
11f78ac3 | 6764 | wdev->netdev, radio_stats, &survey) < 0) |
61fa713c HS |
6765 | goto out; |
6766 | survey_idx++; | |
6767 | } | |
6768 | ||
6769 | out: | |
97990a06 | 6770 | cb->args[2] = survey_idx; |
61fa713c HS |
6771 | res = skb->len; |
6772 | out_err: | |
1b8ec87a | 6773 | nl80211_finish_wdev_dump(rdev); |
61fa713c HS |
6774 | return res; |
6775 | } | |
6776 | ||
b23aa676 SO |
6777 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
6778 | { | |
6779 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
6780 | NL80211_WPA_VERSION_2)); | |
6781 | } | |
6782 | ||
636a5d36 JM |
6783 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
6784 | { | |
4c476991 JB |
6785 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6786 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6787 | struct ieee80211_channel *chan; |
e39e5b5e JM |
6788 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
6789 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 6790 | enum nl80211_auth_type auth_type; |
fffd0934 | 6791 | struct key_parse key; |
d5cdfacb | 6792 | bool local_state_change; |
636a5d36 | 6793 | |
f4a11bb0 JB |
6794 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6795 | return -EINVAL; | |
6796 | ||
6797 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6798 | return -EINVAL; | |
6799 | ||
1778092e JM |
6800 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
6801 | return -EINVAL; | |
6802 | ||
19957bb3 JB |
6803 | if (!info->attrs[NL80211_ATTR_SSID]) |
6804 | return -EINVAL; | |
6805 | ||
6806 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
6807 | return -EINVAL; | |
6808 | ||
fffd0934 JB |
6809 | err = nl80211_parse_key(info, &key); |
6810 | if (err) | |
6811 | return err; | |
6812 | ||
6813 | if (key.idx >= 0) { | |
e31b8213 JB |
6814 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
6815 | return -EINVAL; | |
fffd0934 JB |
6816 | if (!key.p.key || !key.p.key_len) |
6817 | return -EINVAL; | |
6818 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
6819 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
6820 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
6821 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
6822 | return -EINVAL; | |
6823 | if (key.idx > 4) | |
6824 | return -EINVAL; | |
6825 | } else { | |
6826 | key.p.key_len = 0; | |
6827 | key.p.key = NULL; | |
6828 | } | |
6829 | ||
afea0b7a JB |
6830 | if (key.idx >= 0) { |
6831 | int i; | |
6832 | bool ok = false; | |
6833 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
6834 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
6835 | ok = true; | |
6836 | break; | |
6837 | } | |
6838 | } | |
4c476991 JB |
6839 | if (!ok) |
6840 | return -EINVAL; | |
afea0b7a JB |
6841 | } |
6842 | ||
4c476991 JB |
6843 | if (!rdev->ops->auth) |
6844 | return -EOPNOTSUPP; | |
636a5d36 | 6845 | |
074ac8df | 6846 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6847 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6848 | return -EOPNOTSUPP; | |
eec60b03 | 6849 | |
19957bb3 | 6850 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
6851 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6852 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6853 | if (!chan) | |
4c476991 | 6854 | return -EINVAL; |
636a5d36 | 6855 | |
19957bb3 JB |
6856 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6857 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6858 | |
6859 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6860 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6861 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6862 | } |
6863 | ||
19957bb3 | 6864 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 6865 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 6866 | return -EINVAL; |
636a5d36 | 6867 | |
e39e5b5e JM |
6868 | if (auth_type == NL80211_AUTHTYPE_SAE && |
6869 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
6870 | return -EINVAL; | |
6871 | ||
6872 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
6873 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
6874 | return -EINVAL; | |
6875 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6876 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6877 | /* need to include at least Auth Transaction and Status Code */ | |
6878 | if (sae_data_len < 4) | |
6879 | return -EINVAL; | |
6880 | } | |
6881 | ||
d5cdfacb JM |
6882 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6883 | ||
95de817b JB |
6884 | /* |
6885 | * Since we no longer track auth state, ignore | |
6886 | * requests to only change local state. | |
6887 | */ | |
6888 | if (local_state_change) | |
6889 | return 0; | |
6890 | ||
91bf9b26 JB |
6891 | wdev_lock(dev->ieee80211_ptr); |
6892 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
6893 | ssid, ssid_len, ie, ie_len, | |
6894 | key.p.key, key.p.key_len, key.idx, | |
6895 | sae_data, sae_data_len); | |
6896 | wdev_unlock(dev->ieee80211_ptr); | |
6897 | return err; | |
636a5d36 JM |
6898 | } |
6899 | ||
c0692b8f JB |
6900 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6901 | struct genl_info *info, | |
3dc27d25 JB |
6902 | struct cfg80211_crypto_settings *settings, |
6903 | int cipher_limit) | |
b23aa676 | 6904 | { |
c0b2bbd8 JB |
6905 | memset(settings, 0, sizeof(*settings)); |
6906 | ||
b23aa676 SO |
6907 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6908 | ||
c0692b8f JB |
6909 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6910 | u16 proto; | |
6911 | proto = nla_get_u16( | |
6912 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6913 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6914 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6915 | proto != ETH_P_PAE) | |
6916 | return -EINVAL; | |
6917 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6918 | settings->control_port_no_encrypt = true; | |
6919 | } else | |
6920 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6921 | ||
b23aa676 SO |
6922 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6923 | void *data; | |
6924 | int len, i; | |
6925 | ||
6926 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6927 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6928 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6929 | ||
6930 | if (len % sizeof(u32)) | |
6931 | return -EINVAL; | |
6932 | ||
3dc27d25 | 6933 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6934 | return -EINVAL; |
6935 | ||
6936 | memcpy(settings->ciphers_pairwise, data, len); | |
6937 | ||
6938 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6939 | if (!cfg80211_supported_cipher_suite( |
6940 | &rdev->wiphy, | |
b23aa676 SO |
6941 | settings->ciphers_pairwise[i])) |
6942 | return -EINVAL; | |
6943 | } | |
6944 | ||
6945 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6946 | settings->cipher_group = | |
6947 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6948 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6949 | settings->cipher_group)) | |
b23aa676 SO |
6950 | return -EINVAL; |
6951 | } | |
6952 | ||
6953 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6954 | settings->wpa_versions = | |
6955 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6956 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6957 | return -EINVAL; | |
6958 | } | |
6959 | ||
6960 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6961 | void *data; | |
6d30240e | 6962 | int len; |
b23aa676 SO |
6963 | |
6964 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6965 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6966 | settings->n_akm_suites = len / sizeof(u32); | |
6967 | ||
6968 | if (len % sizeof(u32)) | |
6969 | return -EINVAL; | |
6970 | ||
1b9ca027 JM |
6971 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6972 | return -EINVAL; | |
6973 | ||
b23aa676 | 6974 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6975 | } |
6976 | ||
6977 | return 0; | |
6978 | } | |
6979 | ||
636a5d36 JM |
6980 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6981 | { | |
4c476991 JB |
6982 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6983 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6984 | struct ieee80211_channel *chan; |
f62fab73 JB |
6985 | struct cfg80211_assoc_request req = {}; |
6986 | const u8 *bssid, *ssid; | |
6987 | int err, ssid_len = 0; | |
636a5d36 | 6988 | |
f4a11bb0 JB |
6989 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6990 | return -EINVAL; | |
6991 | ||
6992 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6993 | !info->attrs[NL80211_ATTR_SSID] || |
6994 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6995 | return -EINVAL; |
6996 | ||
4c476991 JB |
6997 | if (!rdev->ops->assoc) |
6998 | return -EOPNOTSUPP; | |
636a5d36 | 6999 | |
074ac8df | 7000 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7001 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7002 | return -EOPNOTSUPP; | |
eec60b03 | 7003 | |
19957bb3 | 7004 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7005 | |
664834de JM |
7006 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
7007 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7008 | if (!chan) | |
4c476991 | 7009 | return -EINVAL; |
636a5d36 | 7010 | |
19957bb3 JB |
7011 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7012 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
7013 | |
7014 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
7015 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7016 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7017 | } |
7018 | ||
dc6382ce | 7019 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 7020 | enum nl80211_mfp mfp = |
dc6382ce | 7021 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 7022 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 7023 | req.use_mfp = true; |
4c476991 JB |
7024 | else if (mfp != NL80211_MFP_NO) |
7025 | return -EINVAL; | |
dc6382ce JM |
7026 | } |
7027 | ||
3e5d7649 | 7028 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 7029 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 7030 | |
7e7c8926 | 7031 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 7032 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
7033 | |
7034 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
7035 | memcpy(&req.ht_capa_mask, |
7036 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7037 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
7038 | |
7039 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 7040 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 7041 | return -EINVAL; |
f62fab73 JB |
7042 | memcpy(&req.ht_capa, |
7043 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7044 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
7045 | } |
7046 | ||
ee2aca34 | 7047 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 7048 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
7049 | |
7050 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
7051 | memcpy(&req.vht_capa_mask, |
7052 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7053 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
7054 | |
7055 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 7056 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 7057 | return -EINVAL; |
f62fab73 JB |
7058 | memcpy(&req.vht_capa, |
7059 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7060 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
7061 | } |
7062 | ||
bab5ab7d AK |
7063 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7064 | if (!(rdev->wiphy.features & | |
7065 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7066 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7067 | return -EINVAL; | |
7068 | req.flags |= ASSOC_REQ_USE_RRM; | |
7069 | } | |
7070 | ||
f62fab73 | 7071 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
7072 | if (!err) { |
7073 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
7074 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
7075 | ssid, ssid_len, &req); | |
91bf9b26 JB |
7076 | wdev_unlock(dev->ieee80211_ptr); |
7077 | } | |
636a5d36 | 7078 | |
636a5d36 JM |
7079 | return err; |
7080 | } | |
7081 | ||
7082 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
7083 | { | |
4c476991 JB |
7084 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7085 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7086 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7087 | int ie_len = 0, err; |
19957bb3 | 7088 | u16 reason_code; |
d5cdfacb | 7089 | bool local_state_change; |
636a5d36 | 7090 | |
f4a11bb0 JB |
7091 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7092 | return -EINVAL; | |
7093 | ||
7094 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7095 | return -EINVAL; | |
7096 | ||
7097 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7098 | return -EINVAL; | |
7099 | ||
4c476991 JB |
7100 | if (!rdev->ops->deauth) |
7101 | return -EOPNOTSUPP; | |
636a5d36 | 7102 | |
074ac8df | 7103 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7104 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7105 | return -EOPNOTSUPP; | |
eec60b03 | 7106 | |
19957bb3 | 7107 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7108 | |
19957bb3 JB |
7109 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7110 | if (reason_code == 0) { | |
f4a11bb0 | 7111 | /* Reason Code 0 is reserved */ |
4c476991 | 7112 | return -EINVAL; |
255e737e | 7113 | } |
636a5d36 JM |
7114 | |
7115 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7116 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7117 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7118 | } |
7119 | ||
d5cdfacb JM |
7120 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7121 | ||
91bf9b26 JB |
7122 | wdev_lock(dev->ieee80211_ptr); |
7123 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
7124 | local_state_change); | |
7125 | wdev_unlock(dev->ieee80211_ptr); | |
7126 | return err; | |
636a5d36 JM |
7127 | } |
7128 | ||
7129 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
7130 | { | |
4c476991 JB |
7131 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7132 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7133 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7134 | int ie_len = 0, err; |
19957bb3 | 7135 | u16 reason_code; |
d5cdfacb | 7136 | bool local_state_change; |
636a5d36 | 7137 | |
f4a11bb0 JB |
7138 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7139 | return -EINVAL; | |
7140 | ||
7141 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7142 | return -EINVAL; | |
7143 | ||
7144 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7145 | return -EINVAL; | |
7146 | ||
4c476991 JB |
7147 | if (!rdev->ops->disassoc) |
7148 | return -EOPNOTSUPP; | |
636a5d36 | 7149 | |
074ac8df | 7150 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7151 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7152 | return -EOPNOTSUPP; | |
eec60b03 | 7153 | |
19957bb3 | 7154 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7155 | |
19957bb3 JB |
7156 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7157 | if (reason_code == 0) { | |
f4a11bb0 | 7158 | /* Reason Code 0 is reserved */ |
4c476991 | 7159 | return -EINVAL; |
255e737e | 7160 | } |
636a5d36 JM |
7161 | |
7162 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7163 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7164 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7165 | } |
7166 | ||
d5cdfacb JM |
7167 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7168 | ||
91bf9b26 JB |
7169 | wdev_lock(dev->ieee80211_ptr); |
7170 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
7171 | local_state_change); | |
7172 | wdev_unlock(dev->ieee80211_ptr); | |
7173 | return err; | |
636a5d36 JM |
7174 | } |
7175 | ||
dd5b4cc7 FF |
7176 | static bool |
7177 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
7178 | int mcast_rate[IEEE80211_NUM_BANDS], | |
7179 | int rateval) | |
7180 | { | |
7181 | struct wiphy *wiphy = &rdev->wiphy; | |
7182 | bool found = false; | |
7183 | int band, i; | |
7184 | ||
7185 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
7186 | struct ieee80211_supported_band *sband; | |
7187 | ||
7188 | sband = wiphy->bands[band]; | |
7189 | if (!sband) | |
7190 | continue; | |
7191 | ||
7192 | for (i = 0; i < sband->n_bitrates; i++) { | |
7193 | if (sband->bitrates[i].bitrate == rateval) { | |
7194 | mcast_rate[band] = i + 1; | |
7195 | found = true; | |
7196 | break; | |
7197 | } | |
7198 | } | |
7199 | } | |
7200 | ||
7201 | return found; | |
7202 | } | |
7203 | ||
04a773ad JB |
7204 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
7205 | { | |
4c476991 JB |
7206 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7207 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
7208 | struct cfg80211_ibss_params ibss; |
7209 | struct wiphy *wiphy; | |
fffd0934 | 7210 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
7211 | int err; |
7212 | ||
8e30bc55 JB |
7213 | memset(&ibss, 0, sizeof(ibss)); |
7214 | ||
04a773ad JB |
7215 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7216 | return -EINVAL; | |
7217 | ||
683b6d3b | 7218 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
7219 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
7220 | return -EINVAL; | |
7221 | ||
8e30bc55 JB |
7222 | ibss.beacon_interval = 100; |
7223 | ||
7224 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
7225 | ibss.beacon_interval = | |
7226 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7227 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
7228 | return -EINVAL; | |
7229 | } | |
7230 | ||
4c476991 JB |
7231 | if (!rdev->ops->join_ibss) |
7232 | return -EOPNOTSUPP; | |
04a773ad | 7233 | |
4c476991 JB |
7234 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7235 | return -EOPNOTSUPP; | |
04a773ad | 7236 | |
79c97e97 | 7237 | wiphy = &rdev->wiphy; |
04a773ad | 7238 | |
39193498 | 7239 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 7240 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
7241 | |
7242 | if (!is_valid_ether_addr(ibss.bssid)) | |
7243 | return -EINVAL; | |
7244 | } | |
04a773ad JB |
7245 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7246 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7247 | ||
7248 | if (info->attrs[NL80211_ATTR_IE]) { | |
7249 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7250 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7251 | } | |
7252 | ||
683b6d3b JB |
7253 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
7254 | if (err) | |
7255 | return err; | |
04a773ad | 7256 | |
174e0cd2 IP |
7257 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
7258 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
7259 | return -EINVAL; |
7260 | ||
2f301ab2 | 7261 | switch (ibss.chandef.width) { |
bf372645 SW |
7262 | case NL80211_CHAN_WIDTH_5: |
7263 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
7264 | case NL80211_CHAN_WIDTH_20_NOHT: |
7265 | break; | |
7266 | case NL80211_CHAN_WIDTH_20: | |
7267 | case NL80211_CHAN_WIDTH_40: | |
ffc11991 JD |
7268 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
7269 | return -EINVAL; | |
7270 | break; | |
7271 | case NL80211_CHAN_WIDTH_80: | |
7272 | case NL80211_CHAN_WIDTH_80P80: | |
7273 | case NL80211_CHAN_WIDTH_160: | |
7274 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | |
7275 | return -EINVAL; | |
7276 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
7277 | NL80211_EXT_FEATURE_VHT_IBSS)) | |
7278 | return -EINVAL; | |
7279 | break; | |
2f301ab2 | 7280 | default: |
c04d6150 | 7281 | return -EINVAL; |
2f301ab2 | 7282 | } |
db9c64cf | 7283 | |
04a773ad | 7284 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
7285 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
7286 | ||
fbd2c8dc TP |
7287 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
7288 | u8 *rates = | |
7289 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7290 | int n_rates = | |
7291 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7292 | struct ieee80211_supported_band *sband = | |
683b6d3b | 7293 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 7294 | |
34850ab2 JB |
7295 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
7296 | &ibss.basic_rates); | |
7297 | if (err) | |
7298 | return err; | |
fbd2c8dc | 7299 | } |
dd5b4cc7 | 7300 | |
803768f5 SW |
7301 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7302 | memcpy(&ibss.ht_capa_mask, | |
7303 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7304 | sizeof(ibss.ht_capa_mask)); | |
7305 | ||
7306 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
7307 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7308 | return -EINVAL; | |
7309 | memcpy(&ibss.ht_capa, | |
7310 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7311 | sizeof(ibss.ht_capa)); | |
7312 | } | |
7313 | ||
dd5b4cc7 FF |
7314 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7315 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
7316 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7317 | return -EINVAL; | |
fbd2c8dc | 7318 | |
4c476991 | 7319 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
7320 | bool no_ht = false; |
7321 | ||
4c476991 | 7322 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
7323 | info->attrs[NL80211_ATTR_KEYS], |
7324 | &no_ht); | |
4c476991 JB |
7325 | if (IS_ERR(connkeys)) |
7326 | return PTR_ERR(connkeys); | |
de7044ee | 7327 | |
3d9d1d66 JB |
7328 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
7329 | no_ht) { | |
de7044ee SM |
7330 | kfree(connkeys); |
7331 | return -EINVAL; | |
7332 | } | |
4c476991 | 7333 | } |
04a773ad | 7334 | |
267335d6 AQ |
7335 | ibss.control_port = |
7336 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
7337 | ||
5336fa88 SW |
7338 | ibss.userspace_handles_dfs = |
7339 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
7340 | ||
4c476991 | 7341 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 | 7342 | if (err) |
b47f610b | 7343 | kzfree(connkeys); |
04a773ad JB |
7344 | return err; |
7345 | } | |
7346 | ||
7347 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
7348 | { | |
4c476991 JB |
7349 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7350 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 7351 | |
4c476991 JB |
7352 | if (!rdev->ops->leave_ibss) |
7353 | return -EOPNOTSUPP; | |
04a773ad | 7354 | |
4c476991 JB |
7355 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7356 | return -EOPNOTSUPP; | |
04a773ad | 7357 | |
4c476991 | 7358 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
7359 | } |
7360 | ||
f4e583c8 AQ |
7361 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
7362 | { | |
7363 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7364 | struct net_device *dev = info->user_ptr[1]; | |
7365 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
7366 | u32 nla_rate; | |
7367 | int err; | |
7368 | ||
7369 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
7370 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
7371 | return -EOPNOTSUPP; | |
7372 | ||
7373 | if (!rdev->ops->set_mcast_rate) | |
7374 | return -EOPNOTSUPP; | |
7375 | ||
7376 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
7377 | ||
7378 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
7379 | return -EINVAL; | |
7380 | ||
7381 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
7382 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
7383 | return -EINVAL; | |
7384 | ||
7385 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
7386 | ||
7387 | return err; | |
7388 | } | |
7389 | ||
ad7e718c JB |
7390 | static struct sk_buff * |
7391 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
6c09e791 AK |
7392 | struct wireless_dev *wdev, int approxlen, |
7393 | u32 portid, u32 seq, enum nl80211_commands cmd, | |
567ffc35 JB |
7394 | enum nl80211_attrs attr, |
7395 | const struct nl80211_vendor_cmd_info *info, | |
7396 | gfp_t gfp) | |
ad7e718c JB |
7397 | { |
7398 | struct sk_buff *skb; | |
7399 | void *hdr; | |
7400 | struct nlattr *data; | |
7401 | ||
7402 | skb = nlmsg_new(approxlen + 100, gfp); | |
7403 | if (!skb) | |
7404 | return NULL; | |
7405 | ||
7406 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
7407 | if (!hdr) { | |
7408 | kfree_skb(skb); | |
7409 | return NULL; | |
7410 | } | |
7411 | ||
7412 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
7413 | goto nla_put_failure; | |
567ffc35 JB |
7414 | |
7415 | if (info) { | |
7416 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
7417 | info->vendor_id)) | |
7418 | goto nla_put_failure; | |
7419 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
7420 | info->subcmd)) | |
7421 | goto nla_put_failure; | |
7422 | } | |
7423 | ||
6c09e791 AK |
7424 | if (wdev) { |
7425 | if (nla_put_u64(skb, NL80211_ATTR_WDEV, | |
7426 | wdev_id(wdev))) | |
7427 | goto nla_put_failure; | |
7428 | if (wdev->netdev && | |
7429 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, | |
7430 | wdev->netdev->ifindex)) | |
7431 | goto nla_put_failure; | |
7432 | } | |
7433 | ||
ad7e718c JB |
7434 | data = nla_nest_start(skb, attr); |
7435 | ||
7436 | ((void **)skb->cb)[0] = rdev; | |
7437 | ((void **)skb->cb)[1] = hdr; | |
7438 | ((void **)skb->cb)[2] = data; | |
7439 | ||
7440 | return skb; | |
7441 | ||
7442 | nla_put_failure: | |
7443 | kfree_skb(skb); | |
7444 | return NULL; | |
7445 | } | |
f4e583c8 | 7446 | |
e03ad6ea | 7447 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
6c09e791 | 7448 | struct wireless_dev *wdev, |
e03ad6ea JB |
7449 | enum nl80211_commands cmd, |
7450 | enum nl80211_attrs attr, | |
7451 | int vendor_event_idx, | |
7452 | int approxlen, gfp_t gfp) | |
7453 | { | |
f26cbf40 | 7454 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
7455 | const struct nl80211_vendor_cmd_info *info; |
7456 | ||
7457 | switch (cmd) { | |
7458 | case NL80211_CMD_TESTMODE: | |
7459 | if (WARN_ON(vendor_event_idx != -1)) | |
7460 | return NULL; | |
7461 | info = NULL; | |
7462 | break; | |
7463 | case NL80211_CMD_VENDOR: | |
7464 | if (WARN_ON(vendor_event_idx < 0 || | |
7465 | vendor_event_idx >= wiphy->n_vendor_events)) | |
7466 | return NULL; | |
7467 | info = &wiphy->vendor_events[vendor_event_idx]; | |
7468 | break; | |
7469 | default: | |
7470 | WARN_ON(1); | |
7471 | return NULL; | |
7472 | } | |
7473 | ||
6c09e791 | 7474 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
e03ad6ea JB |
7475 | cmd, attr, info, gfp); |
7476 | } | |
7477 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
7478 | ||
7479 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
7480 | { | |
7481 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
7482 | void *hdr = ((void **)skb->cb)[1]; | |
7483 | struct nlattr *data = ((void **)skb->cb)[2]; | |
7484 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
7485 | ||
bd8c78e7 JB |
7486 | /* clear CB data for netlink core to own from now on */ |
7487 | memset(skb->cb, 0, sizeof(skb->cb)); | |
7488 | ||
e03ad6ea JB |
7489 | nla_nest_end(skb, data); |
7490 | genlmsg_end(skb, hdr); | |
7491 | ||
7492 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
7493 | mcgrp = NL80211_MCGRP_VENDOR; | |
7494 | ||
7495 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
7496 | mcgrp, gfp); | |
7497 | } | |
7498 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
7499 | ||
aff89a9b | 7500 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
7501 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
7502 | { | |
4c476991 | 7503 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
7504 | struct wireless_dev *wdev = |
7505 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
7506 | int err; |
7507 | ||
fc73f11f DS |
7508 | if (!rdev->ops->testmode_cmd) |
7509 | return -EOPNOTSUPP; | |
7510 | ||
7511 | if (IS_ERR(wdev)) { | |
7512 | err = PTR_ERR(wdev); | |
7513 | if (err != -EINVAL) | |
7514 | return err; | |
7515 | wdev = NULL; | |
7516 | } else if (wdev->wiphy != &rdev->wiphy) { | |
7517 | return -EINVAL; | |
7518 | } | |
7519 | ||
aff89a9b JB |
7520 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
7521 | return -EINVAL; | |
7522 | ||
ad7e718c | 7523 | rdev->cur_cmd_info = info; |
fc73f11f | 7524 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
7525 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
7526 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 7527 | rdev->cur_cmd_info = NULL; |
aff89a9b | 7528 | |
aff89a9b JB |
7529 | return err; |
7530 | } | |
7531 | ||
71063f0e WYG |
7532 | static int nl80211_testmode_dump(struct sk_buff *skb, |
7533 | struct netlink_callback *cb) | |
7534 | { | |
00918d33 | 7535 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
7536 | int err; |
7537 | long phy_idx; | |
7538 | void *data = NULL; | |
7539 | int data_len = 0; | |
7540 | ||
5fe231e8 JB |
7541 | rtnl_lock(); |
7542 | ||
71063f0e WYG |
7543 | if (cb->args[0]) { |
7544 | /* | |
7545 | * 0 is a valid index, but not valid for args[0], | |
7546 | * so we need to offset by 1. | |
7547 | */ | |
7548 | phy_idx = cb->args[0] - 1; | |
7549 | } else { | |
7550 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
7551 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
7552 | nl80211_policy); | |
7553 | if (err) | |
5fe231e8 | 7554 | goto out_err; |
00918d33 | 7555 | |
2bd7e35d JB |
7556 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
7557 | nl80211_fam.attrbuf); | |
7558 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
7559 | err = PTR_ERR(rdev); |
7560 | goto out_err; | |
00918d33 | 7561 | } |
2bd7e35d JB |
7562 | phy_idx = rdev->wiphy_idx; |
7563 | rdev = NULL; | |
2bd7e35d | 7564 | |
71063f0e WYG |
7565 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
7566 | cb->args[1] = | |
7567 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
7568 | } | |
7569 | ||
7570 | if (cb->args[1]) { | |
7571 | data = nla_data((void *)cb->args[1]); | |
7572 | data_len = nla_len((void *)cb->args[1]); | |
7573 | } | |
7574 | ||
00918d33 JB |
7575 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
7576 | if (!rdev) { | |
5fe231e8 JB |
7577 | err = -ENOENT; |
7578 | goto out_err; | |
71063f0e | 7579 | } |
71063f0e | 7580 | |
00918d33 | 7581 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
7582 | err = -EOPNOTSUPP; |
7583 | goto out_err; | |
7584 | } | |
7585 | ||
7586 | while (1) { | |
15e47304 | 7587 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
7588 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
7589 | NL80211_CMD_TESTMODE); | |
7590 | struct nlattr *tmdata; | |
7591 | ||
cb35fba3 DC |
7592 | if (!hdr) |
7593 | break; | |
7594 | ||
9360ffd1 | 7595 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
7596 | genlmsg_cancel(skb, hdr); |
7597 | break; | |
7598 | } | |
7599 | ||
7600 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
7601 | if (!tmdata) { | |
7602 | genlmsg_cancel(skb, hdr); | |
7603 | break; | |
7604 | } | |
e35e4d28 | 7605 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
7606 | nla_nest_end(skb, tmdata); |
7607 | ||
7608 | if (err == -ENOBUFS || err == -ENOENT) { | |
7609 | genlmsg_cancel(skb, hdr); | |
7610 | break; | |
7611 | } else if (err) { | |
7612 | genlmsg_cancel(skb, hdr); | |
7613 | goto out_err; | |
7614 | } | |
7615 | ||
7616 | genlmsg_end(skb, hdr); | |
7617 | } | |
7618 | ||
7619 | err = skb->len; | |
7620 | /* see above */ | |
7621 | cb->args[0] = phy_idx + 1; | |
7622 | out_err: | |
5fe231e8 | 7623 | rtnl_unlock(); |
71063f0e WYG |
7624 | return err; |
7625 | } | |
aff89a9b JB |
7626 | #endif |
7627 | ||
b23aa676 SO |
7628 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
7629 | { | |
4c476991 JB |
7630 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7631 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
7632 | struct cfg80211_connect_params connect; |
7633 | struct wiphy *wiphy; | |
fffd0934 | 7634 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
7635 | int err; |
7636 | ||
7637 | memset(&connect, 0, sizeof(connect)); | |
7638 | ||
7639 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
7640 | return -EINVAL; | |
7641 | ||
7642 | if (!info->attrs[NL80211_ATTR_SSID] || | |
7643 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
7644 | return -EINVAL; | |
7645 | ||
7646 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
7647 | connect.auth_type = | |
7648 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
7649 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
7650 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
7651 | return -EINVAL; |
7652 | } else | |
7653 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
7654 | ||
7655 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
7656 | ||
c0692b8f | 7657 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 7658 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
7659 | if (err) |
7660 | return err; | |
b23aa676 | 7661 | |
074ac8df | 7662 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7663 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7664 | return -EOPNOTSUPP; | |
b23aa676 | 7665 | |
79c97e97 | 7666 | wiphy = &rdev->wiphy; |
b23aa676 | 7667 | |
4486ea98 BS |
7668 | connect.bg_scan_period = -1; |
7669 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
7670 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
7671 | connect.bg_scan_period = | |
7672 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
7673 | } | |
7674 | ||
b23aa676 SO |
7675 | if (info->attrs[NL80211_ATTR_MAC]) |
7676 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
7677 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
7678 | connect.bssid_hint = | |
7679 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
7680 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7681 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7682 | ||
7683 | if (info->attrs[NL80211_ATTR_IE]) { | |
7684 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7685 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7686 | } | |
7687 | ||
cee00a95 JM |
7688 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
7689 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
7690 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
7691 | connect.mfp != NL80211_MFP_NO) | |
7692 | return -EINVAL; | |
7693 | } else { | |
7694 | connect.mfp = NL80211_MFP_NO; | |
7695 | } | |
7696 | ||
b23aa676 | 7697 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
7698 | connect.channel = nl80211_get_valid_chan( |
7699 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7700 | if (!connect.channel) | |
1df4a510 JM |
7701 | return -EINVAL; |
7702 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
7703 | connect.channel_hint = nl80211_get_valid_chan( |
7704 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
7705 | if (!connect.channel_hint) | |
4c476991 | 7706 | return -EINVAL; |
b23aa676 SO |
7707 | } |
7708 | ||
fffd0934 JB |
7709 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
7710 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 7711 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
7712 | if (IS_ERR(connkeys)) |
7713 | return PTR_ERR(connkeys); | |
fffd0934 JB |
7714 | } |
7715 | ||
7e7c8926 BG |
7716 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
7717 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
7718 | ||
7719 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7720 | memcpy(&connect.ht_capa_mask, | |
7721 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7722 | sizeof(connect.ht_capa_mask)); | |
7723 | ||
7724 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e | 7725 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
b47f610b | 7726 | kzfree(connkeys); |
7e7c8926 | 7727 | return -EINVAL; |
b4e4f47e | 7728 | } |
7e7c8926 BG |
7729 | memcpy(&connect.ht_capa, |
7730 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7731 | sizeof(connect.ht_capa)); | |
7732 | } | |
7733 | ||
ee2aca34 JB |
7734 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
7735 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
7736 | ||
7737 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
7738 | memcpy(&connect.vht_capa_mask, | |
7739 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7740 | sizeof(connect.vht_capa_mask)); | |
7741 | ||
7742 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
7743 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
b47f610b | 7744 | kzfree(connkeys); |
ee2aca34 JB |
7745 | return -EINVAL; |
7746 | } | |
7747 | memcpy(&connect.vht_capa, | |
7748 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7749 | sizeof(connect.vht_capa)); | |
7750 | } | |
7751 | ||
bab5ab7d AK |
7752 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7753 | if (!(rdev->wiphy.features & | |
7754 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7755 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7756 | return -EINVAL; | |
7757 | connect.flags |= ASSOC_REQ_USE_RRM; | |
7758 | } | |
7759 | ||
83739b03 JB |
7760 | wdev_lock(dev->ieee80211_ptr); |
7761 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
7762 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 | 7763 | if (err) |
b47f610b | 7764 | kzfree(connkeys); |
b23aa676 SO |
7765 | return err; |
7766 | } | |
7767 | ||
7768 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
7769 | { | |
4c476991 JB |
7770 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7771 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 7772 | u16 reason; |
83739b03 | 7773 | int ret; |
b23aa676 SO |
7774 | |
7775 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7776 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
7777 | else | |
7778 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
7779 | ||
7780 | if (reason == 0) | |
7781 | return -EINVAL; | |
7782 | ||
074ac8df | 7783 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7784 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7785 | return -EOPNOTSUPP; | |
b23aa676 | 7786 | |
83739b03 JB |
7787 | wdev_lock(dev->ieee80211_ptr); |
7788 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
7789 | wdev_unlock(dev->ieee80211_ptr); | |
7790 | return ret; | |
b23aa676 SO |
7791 | } |
7792 | ||
463d0183 JB |
7793 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
7794 | { | |
4c476991 | 7795 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
7796 | struct net *net; |
7797 | int err; | |
463d0183 | 7798 | |
4b681c82 VK |
7799 | if (info->attrs[NL80211_ATTR_PID]) { |
7800 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
7801 | ||
7802 | net = get_net_ns_by_pid(pid); | |
7803 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { | |
7804 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); | |
463d0183 | 7805 | |
4b681c82 VK |
7806 | net = get_net_ns_by_fd(fd); |
7807 | } else { | |
7808 | return -EINVAL; | |
7809 | } | |
463d0183 | 7810 | |
4c476991 JB |
7811 | if (IS_ERR(net)) |
7812 | return PTR_ERR(net); | |
463d0183 JB |
7813 | |
7814 | err = 0; | |
7815 | ||
7816 | /* check if anything to do */ | |
4c476991 JB |
7817 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
7818 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 7819 | |
463d0183 | 7820 | put_net(net); |
463d0183 JB |
7821 | return err; |
7822 | } | |
7823 | ||
67fbb16b SO |
7824 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
7825 | { | |
4c476991 | 7826 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
7827 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
7828 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 7829 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
7830 | struct cfg80211_pmksa pmksa; |
7831 | ||
7832 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
7833 | ||
7834 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7835 | return -EINVAL; | |
7836 | ||
7837 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
7838 | return -EINVAL; | |
7839 | ||
67fbb16b SO |
7840 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
7841 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7842 | ||
074ac8df | 7843 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7844 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7845 | return -EOPNOTSUPP; | |
67fbb16b SO |
7846 | |
7847 | switch (info->genlhdr->cmd) { | |
7848 | case NL80211_CMD_SET_PMKSA: | |
7849 | rdev_ops = rdev->ops->set_pmksa; | |
7850 | break; | |
7851 | case NL80211_CMD_DEL_PMKSA: | |
7852 | rdev_ops = rdev->ops->del_pmksa; | |
7853 | break; | |
7854 | default: | |
7855 | WARN_ON(1); | |
7856 | break; | |
7857 | } | |
7858 | ||
4c476991 JB |
7859 | if (!rdev_ops) |
7860 | return -EOPNOTSUPP; | |
67fbb16b | 7861 | |
4c476991 | 7862 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
7863 | } |
7864 | ||
7865 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
7866 | { | |
4c476991 JB |
7867 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7868 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 7869 | |
074ac8df | 7870 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7871 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7872 | return -EOPNOTSUPP; | |
67fbb16b | 7873 | |
4c476991 JB |
7874 | if (!rdev->ops->flush_pmksa) |
7875 | return -EOPNOTSUPP; | |
67fbb16b | 7876 | |
e35e4d28 | 7877 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
7878 | } |
7879 | ||
109086ce AN |
7880 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
7881 | { | |
7882 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7883 | struct net_device *dev = info->user_ptr[1]; | |
7884 | u8 action_code, dialog_token; | |
df942e7b | 7885 | u32 peer_capability = 0; |
109086ce AN |
7886 | u16 status_code; |
7887 | u8 *peer; | |
31fa97c5 | 7888 | bool initiator; |
109086ce AN |
7889 | |
7890 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7891 | !rdev->ops->tdls_mgmt) | |
7892 | return -EOPNOTSUPP; | |
7893 | ||
7894 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
7895 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
7896 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
7897 | !info->attrs[NL80211_ATTR_IE] || | |
7898 | !info->attrs[NL80211_ATTR_MAC]) | |
7899 | return -EINVAL; | |
7900 | ||
7901 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7902 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
7903 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
7904 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 7905 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
7906 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
7907 | peer_capability = | |
7908 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 7909 | |
e35e4d28 | 7910 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 7911 | dialog_token, status_code, peer_capability, |
31fa97c5 | 7912 | initiator, |
e35e4d28 HG |
7913 | nla_data(info->attrs[NL80211_ATTR_IE]), |
7914 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
7915 | } |
7916 | ||
7917 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
7918 | { | |
7919 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7920 | struct net_device *dev = info->user_ptr[1]; | |
7921 | enum nl80211_tdls_operation operation; | |
7922 | u8 *peer; | |
7923 | ||
7924 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7925 | !rdev->ops->tdls_oper) | |
7926 | return -EOPNOTSUPP; | |
7927 | ||
7928 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
7929 | !info->attrs[NL80211_ATTR_MAC]) | |
7930 | return -EINVAL; | |
7931 | ||
7932 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
7933 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7934 | ||
e35e4d28 | 7935 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
7936 | } |
7937 | ||
9588bbd5 JM |
7938 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
7939 | struct genl_info *info) | |
7940 | { | |
4c476991 | 7941 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7942 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7943 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
7944 | struct sk_buff *msg; |
7945 | void *hdr; | |
7946 | u64 cookie; | |
683b6d3b | 7947 | u32 duration; |
9588bbd5 JM |
7948 | int err; |
7949 | ||
7950 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7951 | !info->attrs[NL80211_ATTR_DURATION]) | |
7952 | return -EINVAL; | |
7953 | ||
7954 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
7955 | ||
ebf348fc JB |
7956 | if (!rdev->ops->remain_on_channel || |
7957 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
7958 | return -EOPNOTSUPP; | |
7959 | ||
9588bbd5 | 7960 | /* |
ebf348fc JB |
7961 | * We should be on that channel for at least a minimum amount of |
7962 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 7963 | */ |
ebf348fc | 7964 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 7965 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
7966 | return -EINVAL; |
7967 | ||
683b6d3b JB |
7968 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7969 | if (err) | |
7970 | return err; | |
9588bbd5 JM |
7971 | |
7972 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7973 | if (!msg) |
7974 | return -ENOMEM; | |
9588bbd5 | 7975 | |
15e47304 | 7976 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 7977 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
7978 | if (!hdr) { |
7979 | err = -ENOBUFS; | |
9588bbd5 JM |
7980 | goto free_msg; |
7981 | } | |
7982 | ||
683b6d3b JB |
7983 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7984 | duration, &cookie); | |
9588bbd5 JM |
7985 | |
7986 | if (err) | |
7987 | goto free_msg; | |
7988 | ||
9360ffd1 DM |
7989 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7990 | goto nla_put_failure; | |
9588bbd5 JM |
7991 | |
7992 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7993 | |
7994 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7995 | |
7996 | nla_put_failure: | |
7997 | err = -ENOBUFS; | |
7998 | free_msg: | |
7999 | nlmsg_free(msg); | |
9588bbd5 JM |
8000 | return err; |
8001 | } | |
8002 | ||
8003 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
8004 | struct genl_info *info) | |
8005 | { | |
4c476991 | 8006 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8007 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 8008 | u64 cookie; |
9588bbd5 JM |
8009 | |
8010 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8011 | return -EINVAL; | |
8012 | ||
4c476991 JB |
8013 | if (!rdev->ops->cancel_remain_on_channel) |
8014 | return -EOPNOTSUPP; | |
9588bbd5 | 8015 | |
9588bbd5 JM |
8016 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
8017 | ||
e35e4d28 | 8018 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
8019 | } |
8020 | ||
13ae75b1 JM |
8021 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
8022 | u8 *rates, u8 rates_len) | |
8023 | { | |
8024 | u8 i; | |
8025 | u32 mask = 0; | |
8026 | ||
8027 | for (i = 0; i < rates_len; i++) { | |
8028 | int rate = (rates[i] & 0x7f) * 5; | |
8029 | int ridx; | |
8030 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
8031 | struct ieee80211_rate *srate = | |
8032 | &sband->bitrates[ridx]; | |
8033 | if (rate == srate->bitrate) { | |
8034 | mask |= 1 << ridx; | |
8035 | break; | |
8036 | } | |
8037 | } | |
8038 | if (ridx == sband->n_bitrates) | |
8039 | return 0; /* rate not found */ | |
8040 | } | |
8041 | ||
8042 | return mask; | |
8043 | } | |
8044 | ||
24db78c0 SW |
8045 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
8046 | u8 *rates, u8 rates_len, | |
8047 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
8048 | { | |
8049 | u8 i; | |
8050 | ||
8051 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
8052 | ||
8053 | for (i = 0; i < rates_len; i++) { | |
8054 | int ridx, rbit; | |
8055 | ||
8056 | ridx = rates[i] / 8; | |
8057 | rbit = BIT(rates[i] % 8); | |
8058 | ||
8059 | /* check validity */ | |
910570b5 | 8060 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
8061 | return false; |
8062 | ||
8063 | /* check availability */ | |
8064 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
8065 | mcs[ridx] |= rbit; | |
8066 | else | |
8067 | return false; | |
8068 | } | |
8069 | ||
8070 | return true; | |
8071 | } | |
8072 | ||
204e35a9 JD |
8073 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
8074 | { | |
8075 | u16 mcs_mask = 0; | |
8076 | ||
8077 | switch (vht_mcs_map) { | |
8078 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
8079 | break; | |
8080 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
8081 | mcs_mask = 0x00FF; | |
8082 | break; | |
8083 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
8084 | mcs_mask = 0x01FF; | |
8085 | break; | |
8086 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
8087 | mcs_mask = 0x03FF; | |
8088 | break; | |
8089 | default: | |
8090 | break; | |
8091 | } | |
8092 | ||
8093 | return mcs_mask; | |
8094 | } | |
8095 | ||
8096 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
8097 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
8098 | { | |
8099 | u8 nss; | |
8100 | ||
8101 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
8102 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
8103 | vht_mcs_map >>= 2; | |
8104 | } | |
8105 | } | |
8106 | ||
8107 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
8108 | struct nl80211_txrate_vht *txrate, | |
8109 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
8110 | { | |
8111 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8112 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
8113 | u8 i; | |
8114 | ||
8115 | if (!sband->vht_cap.vht_supported) | |
8116 | return false; | |
8117 | ||
8118 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
8119 | ||
8120 | /* Build vht_mcs_mask from VHT capabilities */ | |
8121 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
8122 | ||
8123 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
8124 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
8125 | mcs[i] = txrate->mcs[i]; | |
8126 | else | |
8127 | return false; | |
8128 | } | |
8129 | ||
8130 | return true; | |
8131 | } | |
8132 | ||
b54452b0 | 8133 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
8134 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
8135 | .len = NL80211_MAX_SUPP_RATES }, | |
d1e33e65 JD |
8136 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
8137 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
204e35a9 | 8138 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
0b9323f6 | 8139 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
13ae75b1 JM |
8140 | }; |
8141 | ||
8142 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
8143 | struct genl_info *info) | |
8144 | { | |
8145 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 8146 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 8147 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
8148 | int rem, i; |
8149 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
8150 | struct nlattr *tx_rates; |
8151 | struct ieee80211_supported_band *sband; | |
204e35a9 | 8152 | u16 vht_tx_mcs_map; |
13ae75b1 | 8153 | |
4c476991 JB |
8154 | if (!rdev->ops->set_bitrate_mask) |
8155 | return -EOPNOTSUPP; | |
13ae75b1 JM |
8156 | |
8157 | memset(&mask, 0, sizeof(mask)); | |
8158 | /* Default to all rates enabled */ | |
8159 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
8160 | sband = rdev->wiphy.bands[i]; | |
7869303b JD |
8161 | |
8162 | if (!sband) | |
8163 | continue; | |
8164 | ||
8165 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; | |
d1e33e65 | 8166 | memcpy(mask.control[i].ht_mcs, |
7869303b | 8167 | sband->ht_cap.mcs.rx_mask, |
d1e33e65 | 8168 | sizeof(mask.control[i].ht_mcs)); |
204e35a9 JD |
8169 | |
8170 | if (!sband->vht_cap.vht_supported) | |
8171 | continue; | |
8172 | ||
8173 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8174 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); | |
13ae75b1 JM |
8175 | } |
8176 | ||
b9243ab0 JD |
8177 | /* if no rates are given set it back to the defaults */ |
8178 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
8179 | goto out; | |
8180 | ||
13ae75b1 JM |
8181 | /* |
8182 | * The nested attribute uses enum nl80211_band as the index. This maps | |
8183 | * directly to the enum ieee80211_band values used in cfg80211. | |
8184 | */ | |
24db78c0 | 8185 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
ae811e21 | 8186 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
13ae75b1 | 8187 | enum ieee80211_band band = nla_type(tx_rates); |
ae811e21 JB |
8188 | int err; |
8189 | ||
4c476991 JB |
8190 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
8191 | return -EINVAL; | |
13ae75b1 | 8192 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
8193 | if (sband == NULL) |
8194 | return -EINVAL; | |
ae811e21 JB |
8195 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
8196 | nla_len(tx_rates), nl80211_txattr_policy); | |
8197 | if (err) | |
8198 | return err; | |
13ae75b1 JM |
8199 | if (tb[NL80211_TXRATE_LEGACY]) { |
8200 | mask.control[band].legacy = rateset_to_mask( | |
8201 | sband, | |
8202 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
8203 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
8204 | if ((mask.control[band].legacy == 0) && |
8205 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
8206 | return -EINVAL; | |
24db78c0 | 8207 | } |
d1e33e65 | 8208 | if (tb[NL80211_TXRATE_HT]) { |
24db78c0 SW |
8209 | if (!ht_rateset_to_mask( |
8210 | sband, | |
d1e33e65 JD |
8211 | nla_data(tb[NL80211_TXRATE_HT]), |
8212 | nla_len(tb[NL80211_TXRATE_HT]), | |
8213 | mask.control[band].ht_mcs)) | |
24db78c0 SW |
8214 | return -EINVAL; |
8215 | } | |
204e35a9 JD |
8216 | if (tb[NL80211_TXRATE_VHT]) { |
8217 | if (!vht_set_mcs_mask( | |
8218 | sband, | |
8219 | nla_data(tb[NL80211_TXRATE_VHT]), | |
8220 | mask.control[band].vht_mcs)) | |
8221 | return -EINVAL; | |
8222 | } | |
0b9323f6 JD |
8223 | if (tb[NL80211_TXRATE_GI]) { |
8224 | mask.control[band].gi = | |
8225 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
8226 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
8227 | return -EINVAL; | |
8228 | } | |
24db78c0 SW |
8229 | |
8230 | if (mask.control[band].legacy == 0) { | |
204e35a9 JD |
8231 | /* don't allow empty legacy rates if HT or VHT |
8232 | * are not even supported. | |
8233 | */ | |
8234 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
8235 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
24db78c0 SW |
8236 | return -EINVAL; |
8237 | ||
8238 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
d1e33e65 | 8239 | if (mask.control[band].ht_mcs[i]) |
204e35a9 JD |
8240 | goto out; |
8241 | ||
8242 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
8243 | if (mask.control[band].vht_mcs[i]) | |
8244 | goto out; | |
24db78c0 SW |
8245 | |
8246 | /* legacy and mcs rates may not be both empty */ | |
204e35a9 | 8247 | return -EINVAL; |
13ae75b1 JM |
8248 | } |
8249 | } | |
8250 | ||
b9243ab0 | 8251 | out: |
e35e4d28 | 8252 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
8253 | } |
8254 | ||
2e161f78 | 8255 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8256 | { |
4c476991 | 8257 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8258 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 8259 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
8260 | |
8261 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
8262 | return -EINVAL; | |
8263 | ||
2e161f78 JB |
8264 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
8265 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 8266 | |
71bbc994 JB |
8267 | switch (wdev->iftype) { |
8268 | case NL80211_IFTYPE_STATION: | |
8269 | case NL80211_IFTYPE_ADHOC: | |
8270 | case NL80211_IFTYPE_P2P_CLIENT: | |
8271 | case NL80211_IFTYPE_AP: | |
8272 | case NL80211_IFTYPE_AP_VLAN: | |
8273 | case NL80211_IFTYPE_MESH_POINT: | |
8274 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8275 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8276 | break; |
8277 | default: | |
4c476991 | 8278 | return -EOPNOTSUPP; |
71bbc994 | 8279 | } |
026331c4 JM |
8280 | |
8281 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
8282 | if (!rdev->ops->mgmt_tx) |
8283 | return -EOPNOTSUPP; | |
026331c4 | 8284 | |
15e47304 | 8285 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
8286 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
8287 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
8288 | } |
8289 | ||
2e161f78 | 8290 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8291 | { |
4c476991 | 8292 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8293 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 8294 | struct cfg80211_chan_def chandef; |
026331c4 | 8295 | int err; |
d64d373f | 8296 | void *hdr = NULL; |
026331c4 | 8297 | u64 cookie; |
e247bd90 | 8298 | struct sk_buff *msg = NULL; |
b176e629 AO |
8299 | struct cfg80211_mgmt_tx_params params = { |
8300 | .dont_wait_for_ack = | |
8301 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
8302 | }; | |
026331c4 | 8303 | |
683b6d3b | 8304 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
8305 | return -EINVAL; |
8306 | ||
4c476991 JB |
8307 | if (!rdev->ops->mgmt_tx) |
8308 | return -EOPNOTSUPP; | |
026331c4 | 8309 | |
71bbc994 | 8310 | switch (wdev->iftype) { |
ea141b75 AQ |
8311 | case NL80211_IFTYPE_P2P_DEVICE: |
8312 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
8313 | return -EINVAL; | |
71bbc994 JB |
8314 | case NL80211_IFTYPE_STATION: |
8315 | case NL80211_IFTYPE_ADHOC: | |
8316 | case NL80211_IFTYPE_P2P_CLIENT: | |
8317 | case NL80211_IFTYPE_AP: | |
8318 | case NL80211_IFTYPE_AP_VLAN: | |
8319 | case NL80211_IFTYPE_MESH_POINT: | |
8320 | case NL80211_IFTYPE_P2P_GO: | |
8321 | break; | |
8322 | default: | |
4c476991 | 8323 | return -EOPNOTSUPP; |
71bbc994 | 8324 | } |
026331c4 | 8325 | |
f7ca38df | 8326 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 8327 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 8328 | return -EINVAL; |
b176e629 | 8329 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
8330 | |
8331 | /* | |
8332 | * We should wait on the channel for at least a minimum amount | |
8333 | * of time (10ms) but no longer than the driver supports. | |
8334 | */ | |
b176e629 AO |
8335 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
8336 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc JB |
8337 | return -EINVAL; |
8338 | ||
f7ca38df JB |
8339 | } |
8340 | ||
b176e629 | 8341 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 8342 | |
b176e629 | 8343 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
8344 | return -EINVAL; |
8345 | ||
b176e629 | 8346 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 8347 | |
ea141b75 AQ |
8348 | /* get the channel if any has been specified, otherwise pass NULL to |
8349 | * the driver. The latter will use the current one | |
8350 | */ | |
8351 | chandef.chan = NULL; | |
8352 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
8353 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
8354 | if (err) | |
8355 | return err; | |
8356 | } | |
8357 | ||
b176e629 | 8358 | if (!chandef.chan && params.offchan) |
ea141b75 | 8359 | return -EINVAL; |
026331c4 | 8360 | |
34d22ce2 AO |
8361 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
8362 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
8363 | ||
8364 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
8365 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8366 | int i; | |
8367 | ||
8368 | if (len % sizeof(u16)) | |
8369 | return -EINVAL; | |
8370 | ||
8371 | params.n_csa_offsets = len / sizeof(u16); | |
8372 | params.csa_offsets = | |
8373 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8374 | ||
8375 | /* check that all the offsets fit the frame */ | |
8376 | for (i = 0; i < params.n_csa_offsets; i++) { | |
8377 | if (params.csa_offsets[i] >= params.len) | |
8378 | return -EINVAL; | |
8379 | } | |
8380 | } | |
8381 | ||
b176e629 | 8382 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
8383 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
8384 | if (!msg) | |
8385 | return -ENOMEM; | |
026331c4 | 8386 | |
15e47304 | 8387 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 8388 | NL80211_CMD_FRAME); |
cb35fba3 DC |
8389 | if (!hdr) { |
8390 | err = -ENOBUFS; | |
e247bd90 JB |
8391 | goto free_msg; |
8392 | } | |
026331c4 | 8393 | } |
e247bd90 | 8394 | |
b176e629 AO |
8395 | params.chan = chandef.chan; |
8396 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
8397 | if (err) |
8398 | goto free_msg; | |
8399 | ||
e247bd90 | 8400 | if (msg) { |
9360ffd1 DM |
8401 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8402 | goto nla_put_failure; | |
026331c4 | 8403 | |
e247bd90 JB |
8404 | genlmsg_end(msg, hdr); |
8405 | return genlmsg_reply(msg, info); | |
8406 | } | |
8407 | ||
8408 | return 0; | |
026331c4 JM |
8409 | |
8410 | nla_put_failure: | |
8411 | err = -ENOBUFS; | |
8412 | free_msg: | |
8413 | nlmsg_free(msg); | |
026331c4 JM |
8414 | return err; |
8415 | } | |
8416 | ||
f7ca38df JB |
8417 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
8418 | { | |
8419 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 8420 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
8421 | u64 cookie; |
8422 | ||
8423 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8424 | return -EINVAL; | |
8425 | ||
8426 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
8427 | return -EOPNOTSUPP; | |
8428 | ||
71bbc994 JB |
8429 | switch (wdev->iftype) { |
8430 | case NL80211_IFTYPE_STATION: | |
8431 | case NL80211_IFTYPE_ADHOC: | |
8432 | case NL80211_IFTYPE_P2P_CLIENT: | |
8433 | case NL80211_IFTYPE_AP: | |
8434 | case NL80211_IFTYPE_AP_VLAN: | |
8435 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8436 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8437 | break; |
8438 | default: | |
f7ca38df | 8439 | return -EOPNOTSUPP; |
71bbc994 | 8440 | } |
f7ca38df JB |
8441 | |
8442 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
8443 | ||
e35e4d28 | 8444 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
8445 | } |
8446 | ||
ffb9eb3d KV |
8447 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
8448 | { | |
4c476991 | 8449 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 8450 | struct wireless_dev *wdev; |
4c476991 | 8451 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8452 | u8 ps_state; |
8453 | bool state; | |
8454 | int err; | |
8455 | ||
4c476991 JB |
8456 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
8457 | return -EINVAL; | |
ffb9eb3d KV |
8458 | |
8459 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
8460 | ||
4c476991 JB |
8461 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
8462 | return -EINVAL; | |
ffb9eb3d KV |
8463 | |
8464 | wdev = dev->ieee80211_ptr; | |
8465 | ||
4c476991 JB |
8466 | if (!rdev->ops->set_power_mgmt) |
8467 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8468 | |
8469 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
8470 | ||
8471 | if (state == wdev->ps) | |
4c476991 | 8472 | return 0; |
ffb9eb3d | 8473 | |
e35e4d28 | 8474 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
8475 | if (!err) |
8476 | wdev->ps = state; | |
ffb9eb3d KV |
8477 | return err; |
8478 | } | |
8479 | ||
8480 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
8481 | { | |
4c476991 | 8482 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
8483 | enum nl80211_ps_state ps_state; |
8484 | struct wireless_dev *wdev; | |
4c476991 | 8485 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8486 | struct sk_buff *msg; |
8487 | void *hdr; | |
8488 | int err; | |
8489 | ||
ffb9eb3d KV |
8490 | wdev = dev->ieee80211_ptr; |
8491 | ||
4c476991 JB |
8492 | if (!rdev->ops->set_power_mgmt) |
8493 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8494 | |
8495 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
8496 | if (!msg) |
8497 | return -ENOMEM; | |
ffb9eb3d | 8498 | |
15e47304 | 8499 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
8500 | NL80211_CMD_GET_POWER_SAVE); |
8501 | if (!hdr) { | |
4c476991 | 8502 | err = -ENOBUFS; |
ffb9eb3d KV |
8503 | goto free_msg; |
8504 | } | |
8505 | ||
8506 | if (wdev->ps) | |
8507 | ps_state = NL80211_PS_ENABLED; | |
8508 | else | |
8509 | ps_state = NL80211_PS_DISABLED; | |
8510 | ||
9360ffd1 DM |
8511 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
8512 | goto nla_put_failure; | |
ffb9eb3d KV |
8513 | |
8514 | genlmsg_end(msg, hdr); | |
4c476991 | 8515 | return genlmsg_reply(msg, info); |
ffb9eb3d | 8516 | |
4c476991 | 8517 | nla_put_failure: |
ffb9eb3d | 8518 | err = -ENOBUFS; |
4c476991 | 8519 | free_msg: |
ffb9eb3d | 8520 | nlmsg_free(msg); |
ffb9eb3d KV |
8521 | return err; |
8522 | } | |
8523 | ||
94e860f1 JB |
8524 | static const struct nla_policy |
8525 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
8526 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
8527 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
8528 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
8529 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
8530 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
8531 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
8532 | }; |
8533 | ||
84f10708 | 8534 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 8535 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
8536 | { |
8537 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 8538 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8539 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 8540 | |
d9d8b019 | 8541 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
8542 | return -EINVAL; |
8543 | ||
84f10708 TP |
8544 | if (!rdev->ops->set_cqm_txe_config) |
8545 | return -EOPNOTSUPP; | |
8546 | ||
8547 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
8548 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
8549 | return -EOPNOTSUPP; | |
8550 | ||
e35e4d28 | 8551 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
8552 | } |
8553 | ||
d6dc1a38 JO |
8554 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
8555 | s32 threshold, u32 hysteresis) | |
8556 | { | |
4c476991 | 8557 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 8558 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8559 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
8560 | |
8561 | if (threshold > 0) | |
8562 | return -EINVAL; | |
8563 | ||
1da5fcc8 JB |
8564 | /* disabling - hysteresis should also be zero then */ |
8565 | if (threshold == 0) | |
8566 | hysteresis = 0; | |
d6dc1a38 | 8567 | |
4c476991 JB |
8568 | if (!rdev->ops->set_cqm_rssi_config) |
8569 | return -EOPNOTSUPP; | |
d6dc1a38 | 8570 | |
074ac8df | 8571 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8572 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8573 | return -EOPNOTSUPP; | |
d6dc1a38 | 8574 | |
e35e4d28 | 8575 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
8576 | } |
8577 | ||
8578 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
8579 | { | |
8580 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
8581 | struct nlattr *cqm; | |
8582 | int err; | |
8583 | ||
8584 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
8585 | if (!cqm) |
8586 | return -EINVAL; | |
d6dc1a38 JO |
8587 | |
8588 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
8589 | nl80211_attr_cqm_policy); | |
8590 | if (err) | |
1da5fcc8 | 8591 | return err; |
d6dc1a38 JO |
8592 | |
8593 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
8594 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
8595 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
8596 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 8597 | |
1da5fcc8 JB |
8598 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
8599 | } | |
8600 | ||
8601 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
8602 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
8603 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
8604 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
8605 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
8606 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
8607 | ||
8608 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
8609 | } | |
8610 | ||
8611 | return -EINVAL; | |
d6dc1a38 JO |
8612 | } |
8613 | ||
6e0bd6c3 RL |
8614 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
8615 | { | |
8616 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8617 | struct net_device *dev = info->user_ptr[1]; | |
8618 | struct ocb_setup setup = {}; | |
8619 | int err; | |
8620 | ||
8621 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | |
8622 | if (err) | |
8623 | return err; | |
8624 | ||
8625 | return cfg80211_join_ocb(rdev, dev, &setup); | |
8626 | } | |
8627 | ||
8628 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | |
8629 | { | |
8630 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8631 | struct net_device *dev = info->user_ptr[1]; | |
8632 | ||
8633 | return cfg80211_leave_ocb(rdev, dev); | |
8634 | } | |
8635 | ||
29cbe68c JB |
8636 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
8637 | { | |
8638 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8639 | struct net_device *dev = info->user_ptr[1]; | |
8640 | struct mesh_config cfg; | |
c80d545d | 8641 | struct mesh_setup setup; |
29cbe68c JB |
8642 | int err; |
8643 | ||
8644 | /* start with default */ | |
8645 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 8646 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 8647 | |
24bdd9f4 | 8648 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 8649 | /* and parse parameters if given */ |
24bdd9f4 | 8650 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
8651 | if (err) |
8652 | return err; | |
8653 | } | |
8654 | ||
8655 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
8656 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
8657 | return -EINVAL; | |
8658 | ||
c80d545d JC |
8659 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
8660 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
8661 | ||
4bb62344 CYY |
8662 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8663 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
8664 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8665 | return -EINVAL; | |
8666 | ||
9bdbf04d MP |
8667 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
8668 | setup.beacon_interval = | |
8669 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
8670 | if (setup.beacon_interval < 10 || | |
8671 | setup.beacon_interval > 10000) | |
8672 | return -EINVAL; | |
8673 | } | |
8674 | ||
8675 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
8676 | setup.dtim_period = | |
8677 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
8678 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
8679 | return -EINVAL; | |
8680 | } | |
8681 | ||
c80d545d JC |
8682 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
8683 | /* parse additional setup parameters if given */ | |
8684 | err = nl80211_parse_mesh_setup(info, &setup); | |
8685 | if (err) | |
8686 | return err; | |
8687 | } | |
8688 | ||
d37bb18a TP |
8689 | if (setup.user_mpm) |
8690 | cfg.auto_open_plinks = false; | |
8691 | ||
cc1d2806 | 8692 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
8693 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
8694 | if (err) | |
8695 | return err; | |
cc1d2806 JB |
8696 | } else { |
8697 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 8698 | setup.chandef.chan = NULL; |
cc1d2806 JB |
8699 | } |
8700 | ||
ffb3cf30 AN |
8701 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8702 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8703 | int n_rates = | |
8704 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8705 | struct ieee80211_supported_band *sband; | |
8706 | ||
8707 | if (!setup.chandef.chan) | |
8708 | return -EINVAL; | |
8709 | ||
8710 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
8711 | ||
8712 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
8713 | &setup.basic_rates); | |
8714 | if (err) | |
8715 | return err; | |
8716 | } | |
8717 | ||
c80d545d | 8718 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
8719 | } |
8720 | ||
8721 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
8722 | { | |
8723 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8724 | struct net_device *dev = info->user_ptr[1]; | |
8725 | ||
8726 | return cfg80211_leave_mesh(rdev, dev); | |
8727 | } | |
8728 | ||
dfb89c56 | 8729 | #ifdef CONFIG_PM |
bb92d199 AK |
8730 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
8731 | struct cfg80211_registered_device *rdev) | |
8732 | { | |
6abb9cb9 | 8733 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
8734 | struct nlattr *nl_pats, *nl_pat; |
8735 | int i, pat_len; | |
8736 | ||
6abb9cb9 | 8737 | if (!wowlan->n_patterns) |
bb92d199 AK |
8738 | return 0; |
8739 | ||
8740 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
8741 | if (!nl_pats) | |
8742 | return -ENOBUFS; | |
8743 | ||
6abb9cb9 | 8744 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
8745 | nl_pat = nla_nest_start(msg, i + 1); |
8746 | if (!nl_pat) | |
8747 | return -ENOBUFS; | |
6abb9cb9 | 8748 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 8749 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 8750 | wowlan->patterns[i].mask) || |
50ac6607 AK |
8751 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
8752 | wowlan->patterns[i].pattern) || | |
8753 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 8754 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
8755 | return -ENOBUFS; |
8756 | nla_nest_end(msg, nl_pat); | |
8757 | } | |
8758 | nla_nest_end(msg, nl_pats); | |
8759 | ||
8760 | return 0; | |
8761 | } | |
8762 | ||
2a0e047e JB |
8763 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
8764 | struct cfg80211_wowlan_tcp *tcp) | |
8765 | { | |
8766 | struct nlattr *nl_tcp; | |
8767 | ||
8768 | if (!tcp) | |
8769 | return 0; | |
8770 | ||
8771 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
8772 | if (!nl_tcp) | |
8773 | return -ENOBUFS; | |
8774 | ||
8775 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
8776 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
8777 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
8778 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
8779 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
8780 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
8781 | tcp->payload_len, tcp->payload) || | |
8782 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
8783 | tcp->data_interval) || | |
8784 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
8785 | tcp->wake_len, tcp->wake_data) || | |
8786 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
8787 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
8788 | return -ENOBUFS; | |
8789 | ||
8790 | if (tcp->payload_seq.len && | |
8791 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
8792 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
8793 | return -ENOBUFS; | |
8794 | ||
8795 | if (tcp->payload_tok.len && | |
8796 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
8797 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
8798 | &tcp->payload_tok)) | |
8799 | return -ENOBUFS; | |
8800 | ||
e248ad30 JB |
8801 | nla_nest_end(msg, nl_tcp); |
8802 | ||
2a0e047e JB |
8803 | return 0; |
8804 | } | |
8805 | ||
75453ccb LC |
8806 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
8807 | struct cfg80211_sched_scan_request *req) | |
8808 | { | |
8809 | struct nlattr *nd, *freqs, *matches, *match; | |
8810 | int i; | |
8811 | ||
8812 | if (!req) | |
8813 | return 0; | |
8814 | ||
8815 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); | |
8816 | if (!nd) | |
8817 | return -ENOBUFS; | |
8818 | ||
8819 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, req->interval)) | |
8820 | return -ENOBUFS; | |
8821 | ||
8822 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
8823 | if (!freqs) | |
8824 | return -ENOBUFS; | |
8825 | ||
8826 | for (i = 0; i < req->n_channels; i++) | |
8827 | nla_put_u32(msg, i, req->channels[i]->center_freq); | |
8828 | ||
8829 | nla_nest_end(msg, freqs); | |
8830 | ||
8831 | if (req->n_match_sets) { | |
8832 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); | |
8833 | for (i = 0; i < req->n_match_sets; i++) { | |
8834 | match = nla_nest_start(msg, i); | |
8835 | nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, | |
8836 | req->match_sets[i].ssid.ssid_len, | |
8837 | req->match_sets[i].ssid.ssid); | |
8838 | nla_nest_end(msg, match); | |
8839 | } | |
8840 | nla_nest_end(msg, matches); | |
8841 | } | |
8842 | ||
8843 | nla_nest_end(msg, nd); | |
8844 | ||
8845 | return 0; | |
8846 | } | |
8847 | ||
ff1b6e69 JB |
8848 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
8849 | { | |
8850 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8851 | struct sk_buff *msg; | |
8852 | void *hdr; | |
2a0e047e | 8853 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 8854 | |
964dc9e2 | 8855 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
8856 | return -EOPNOTSUPP; |
8857 | ||
6abb9cb9 | 8858 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 8859 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
8860 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
8861 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
8862 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
8863 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
8864 | } |
8865 | ||
8866 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
8867 | if (!msg) |
8868 | return -ENOMEM; | |
8869 | ||
15e47304 | 8870 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
8871 | NL80211_CMD_GET_WOWLAN); |
8872 | if (!hdr) | |
8873 | goto nla_put_failure; | |
8874 | ||
6abb9cb9 | 8875 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
8876 | struct nlattr *nl_wowlan; |
8877 | ||
8878 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
8879 | if (!nl_wowlan) | |
8880 | goto nla_put_failure; | |
8881 | ||
6abb9cb9 | 8882 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 8883 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 8884 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 8885 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 8886 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 8887 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 8888 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 8889 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 8890 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 8891 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 8892 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 8893 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 8894 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
8895 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
8896 | goto nla_put_failure; | |
2a0e047e | 8897 | |
bb92d199 AK |
8898 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
8899 | goto nla_put_failure; | |
2a0e047e | 8900 | |
6abb9cb9 JB |
8901 | if (nl80211_send_wowlan_tcp(msg, |
8902 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e | 8903 | goto nla_put_failure; |
75453ccb LC |
8904 | |
8905 | if (nl80211_send_wowlan_nd( | |
8906 | msg, | |
8907 | rdev->wiphy.wowlan_config->nd_config)) | |
8908 | goto nla_put_failure; | |
2a0e047e | 8909 | |
ff1b6e69 JB |
8910 | nla_nest_end(msg, nl_wowlan); |
8911 | } | |
8912 | ||
8913 | genlmsg_end(msg, hdr); | |
8914 | return genlmsg_reply(msg, info); | |
8915 | ||
8916 | nla_put_failure: | |
8917 | nlmsg_free(msg); | |
8918 | return -ENOBUFS; | |
8919 | } | |
8920 | ||
2a0e047e JB |
8921 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
8922 | struct nlattr *attr, | |
8923 | struct cfg80211_wowlan *trig) | |
8924 | { | |
8925 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
8926 | struct cfg80211_wowlan_tcp *cfg; | |
8927 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
8928 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
8929 | u32 size; | |
8930 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
8931 | int err, port; | |
8932 | ||
964dc9e2 | 8933 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
8934 | return -EINVAL; |
8935 | ||
8936 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
8937 | nla_data(attr), nla_len(attr), | |
8938 | nl80211_wowlan_tcp_policy); | |
8939 | if (err) | |
8940 | return err; | |
8941 | ||
8942 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
8943 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
8944 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
8945 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
8946 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
8947 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
8948 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
8949 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
8950 | return -EINVAL; | |
8951 | ||
8952 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 8953 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
8954 | return -EINVAL; |
8955 | ||
8956 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 8957 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 8958 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
8959 | return -EINVAL; |
8960 | ||
8961 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 8962 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
8963 | return -EINVAL; |
8964 | ||
8965 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
8966 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
8967 | return -EINVAL; | |
8968 | ||
8969 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
8970 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8971 | ||
8972 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8973 | tokens_size = tokln - sizeof(*tok); | |
8974 | ||
8975 | if (!tok->len || tokens_size % tok->len) | |
8976 | return -EINVAL; | |
964dc9e2 | 8977 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 8978 | return -EINVAL; |
964dc9e2 | 8979 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 8980 | return -EINVAL; |
964dc9e2 | 8981 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 8982 | return -EINVAL; |
964dc9e2 | 8983 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
8984 | return -EINVAL; |
8985 | if (tok->offset + tok->len > data_size) | |
8986 | return -EINVAL; | |
8987 | } | |
8988 | ||
8989 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
8990 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 8991 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
8992 | return -EINVAL; |
8993 | if (seq->len == 0 || seq->len > 4) | |
8994 | return -EINVAL; | |
8995 | if (seq->len + seq->offset > data_size) | |
8996 | return -EINVAL; | |
8997 | } | |
8998 | ||
8999 | size = sizeof(*cfg); | |
9000 | size += data_size; | |
9001 | size += wake_size + wake_mask_size; | |
9002 | size += tokens_size; | |
9003 | ||
9004 | cfg = kzalloc(size, GFP_KERNEL); | |
9005 | if (!cfg) | |
9006 | return -ENOMEM; | |
9007 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
9008 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
9009 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
9010 | ETH_ALEN); | |
9011 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
9012 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
9013 | else | |
9014 | port = 0; | |
9015 | #ifdef CONFIG_INET | |
9016 | /* allocate a socket and port for it and use it */ | |
9017 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
9018 | IPPROTO_TCP, &cfg->sock, 1); | |
9019 | if (err) { | |
9020 | kfree(cfg); | |
9021 | return err; | |
9022 | } | |
9023 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
9024 | sock_release(cfg->sock); | |
9025 | kfree(cfg); | |
9026 | return -EADDRINUSE; | |
9027 | } | |
9028 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
9029 | #else | |
9030 | if (!port) { | |
9031 | kfree(cfg); | |
9032 | return -EINVAL; | |
9033 | } | |
9034 | cfg->src_port = port; | |
9035 | #endif | |
9036 | ||
9037 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
9038 | cfg->payload_len = data_size; | |
9039 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
9040 | memcpy((void *)cfg->payload, | |
9041 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
9042 | data_size); | |
9043 | if (seq) | |
9044 | cfg->payload_seq = *seq; | |
9045 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
9046 | cfg->wake_len = wake_size; | |
9047 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
9048 | memcpy((void *)cfg->wake_data, | |
9049 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
9050 | wake_size); | |
9051 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
9052 | data_size + wake_size; | |
9053 | memcpy((void *)cfg->wake_mask, | |
9054 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
9055 | wake_mask_size); | |
9056 | if (tok) { | |
9057 | cfg->tokens_size = tokens_size; | |
9058 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
9059 | } | |
9060 | ||
9061 | trig->tcp = cfg; | |
9062 | ||
9063 | return 0; | |
9064 | } | |
9065 | ||
8cd4d456 LC |
9066 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
9067 | const struct wiphy_wowlan_support *wowlan, | |
9068 | struct nlattr *attr, | |
9069 | struct cfg80211_wowlan *trig) | |
9070 | { | |
9071 | struct nlattr **tb; | |
9072 | int err; | |
9073 | ||
9074 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); | |
9075 | if (!tb) | |
9076 | return -ENOMEM; | |
9077 | ||
9078 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | |
9079 | err = -EOPNOTSUPP; | |
9080 | goto out; | |
9081 | } | |
9082 | ||
9083 | err = nla_parse(tb, NL80211_ATTR_MAX, | |
9084 | nla_data(attr), nla_len(attr), | |
9085 | nl80211_policy); | |
9086 | if (err) | |
9087 | goto out; | |
9088 | ||
ad2b26ab | 9089 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
8cd4d456 LC |
9090 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
9091 | if (err) | |
9092 | trig->nd_config = NULL; | |
9093 | ||
9094 | out: | |
9095 | kfree(tb); | |
9096 | return err; | |
9097 | } | |
9098 | ||
ff1b6e69 JB |
9099 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
9100 | { | |
9101 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9102 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 9103 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 9104 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 9105 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 9106 | int err, i; |
6abb9cb9 | 9107 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 9108 | |
964dc9e2 | 9109 | if (!wowlan) |
ff1b6e69 JB |
9110 | return -EOPNOTSUPP; |
9111 | ||
ae33bd81 JB |
9112 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
9113 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 9114 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
9115 | goto set_wakeup; |
9116 | } | |
ff1b6e69 JB |
9117 | |
9118 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
9119 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9120 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9121 | nl80211_wowlan_policy); | |
9122 | if (err) | |
9123 | return err; | |
9124 | ||
9125 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
9126 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
9127 | return -EINVAL; | |
9128 | new_triggers.any = true; | |
9129 | } | |
9130 | ||
9131 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
9132 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
9133 | return -EINVAL; | |
9134 | new_triggers.disconnect = true; | |
9135 | } | |
9136 | ||
9137 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
9138 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
9139 | return -EINVAL; | |
9140 | new_triggers.magic_pkt = true; | |
9141 | } | |
9142 | ||
77dbbb13 JB |
9143 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
9144 | return -EINVAL; | |
9145 | ||
9146 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
9147 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
9148 | return -EINVAL; | |
9149 | new_triggers.gtk_rekey_failure = true; | |
9150 | } | |
9151 | ||
9152 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
9153 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
9154 | return -EINVAL; | |
9155 | new_triggers.eap_identity_req = true; | |
9156 | } | |
9157 | ||
9158 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
9159 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
9160 | return -EINVAL; | |
9161 | new_triggers.four_way_handshake = true; | |
9162 | } | |
9163 | ||
9164 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
9165 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
9166 | return -EINVAL; | |
9167 | new_triggers.rfkill_release = true; | |
9168 | } | |
9169 | ||
ff1b6e69 JB |
9170 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
9171 | struct nlattr *pat; | |
9172 | int n_patterns = 0; | |
bb92d199 | 9173 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 9174 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 JB |
9175 | |
9176 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9177 | rem) | |
9178 | n_patterns++; | |
9179 | if (n_patterns > wowlan->n_patterns) | |
9180 | return -EINVAL; | |
9181 | ||
9182 | new_triggers.patterns = kcalloc(n_patterns, | |
9183 | sizeof(new_triggers.patterns[0]), | |
9184 | GFP_KERNEL); | |
9185 | if (!new_triggers.patterns) | |
9186 | return -ENOMEM; | |
9187 | ||
9188 | new_triggers.n_patterns = n_patterns; | |
9189 | i = 0; | |
9190 | ||
9191 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9192 | rem) { | |
922bd80f JB |
9193 | u8 *mask_pat; |
9194 | ||
50ac6607 AK |
9195 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9196 | nla_len(pat), NULL); | |
ff1b6e69 | 9197 | err = -EINVAL; |
50ac6607 AK |
9198 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
9199 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 9200 | goto error; |
50ac6607 | 9201 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 9202 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 9203 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
9204 | goto error; |
9205 | if (pat_len > wowlan->pattern_max_len || | |
9206 | pat_len < wowlan->pattern_min_len) | |
9207 | goto error; | |
9208 | ||
50ac6607 | 9209 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
9210 | pkt_offset = 0; |
9211 | else | |
9212 | pkt_offset = nla_get_u32( | |
50ac6607 | 9213 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
9214 | if (pkt_offset > wowlan->max_pkt_offset) |
9215 | goto error; | |
9216 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
9217 | ||
922bd80f JB |
9218 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9219 | if (!mask_pat) { | |
ff1b6e69 JB |
9220 | err = -ENOMEM; |
9221 | goto error; | |
9222 | } | |
922bd80f JB |
9223 | new_triggers.patterns[i].mask = mask_pat; |
9224 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 9225 | mask_len); |
922bd80f JB |
9226 | mask_pat += mask_len; |
9227 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 9228 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 9229 | memcpy(mask_pat, |
50ac6607 | 9230 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
9231 | pat_len); |
9232 | i++; | |
9233 | } | |
9234 | } | |
9235 | ||
2a0e047e JB |
9236 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
9237 | err = nl80211_parse_wowlan_tcp( | |
9238 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
9239 | &new_triggers); | |
9240 | if (err) | |
9241 | goto error; | |
9242 | } | |
9243 | ||
8cd4d456 LC |
9244 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
9245 | err = nl80211_parse_wowlan_nd( | |
9246 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | |
9247 | &new_triggers); | |
9248 | if (err) | |
9249 | goto error; | |
9250 | } | |
9251 | ||
ae33bd81 JB |
9252 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
9253 | if (!ntrig) { | |
9254 | err = -ENOMEM; | |
9255 | goto error; | |
ff1b6e69 | 9256 | } |
ae33bd81 | 9257 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 9258 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 9259 | |
ae33bd81 | 9260 | set_wakeup: |
6abb9cb9 JB |
9261 | if (rdev->ops->set_wakeup && |
9262 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
9263 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 9264 | |
ff1b6e69 JB |
9265 | return 0; |
9266 | error: | |
9267 | for (i = 0; i < new_triggers.n_patterns; i++) | |
9268 | kfree(new_triggers.patterns[i].mask); | |
9269 | kfree(new_triggers.patterns); | |
2a0e047e JB |
9270 | if (new_triggers.tcp && new_triggers.tcp->sock) |
9271 | sock_release(new_triggers.tcp->sock); | |
9272 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
9273 | return err; |
9274 | } | |
dfb89c56 | 9275 | #endif |
ff1b6e69 | 9276 | |
be29b99a AK |
9277 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
9278 | struct cfg80211_registered_device *rdev) | |
9279 | { | |
9280 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
9281 | int i, j, pat_len; | |
9282 | struct cfg80211_coalesce_rules *rule; | |
9283 | ||
9284 | if (!rdev->coalesce->n_rules) | |
9285 | return 0; | |
9286 | ||
9287 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
9288 | if (!nl_rules) | |
9289 | return -ENOBUFS; | |
9290 | ||
9291 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
9292 | nl_rule = nla_nest_start(msg, i + 1); | |
9293 | if (!nl_rule) | |
9294 | return -ENOBUFS; | |
9295 | ||
9296 | rule = &rdev->coalesce->rules[i]; | |
9297 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
9298 | rule->delay)) | |
9299 | return -ENOBUFS; | |
9300 | ||
9301 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
9302 | rule->condition)) | |
9303 | return -ENOBUFS; | |
9304 | ||
9305 | nl_pats = nla_nest_start(msg, | |
9306 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
9307 | if (!nl_pats) | |
9308 | return -ENOBUFS; | |
9309 | ||
9310 | for (j = 0; j < rule->n_patterns; j++) { | |
9311 | nl_pat = nla_nest_start(msg, j + 1); | |
9312 | if (!nl_pat) | |
9313 | return -ENOBUFS; | |
9314 | pat_len = rule->patterns[j].pattern_len; | |
9315 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
9316 | DIV_ROUND_UP(pat_len, 8), | |
9317 | rule->patterns[j].mask) || | |
9318 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
9319 | rule->patterns[j].pattern) || | |
9320 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
9321 | rule->patterns[j].pkt_offset)) | |
9322 | return -ENOBUFS; | |
9323 | nla_nest_end(msg, nl_pat); | |
9324 | } | |
9325 | nla_nest_end(msg, nl_pats); | |
9326 | nla_nest_end(msg, nl_rule); | |
9327 | } | |
9328 | nla_nest_end(msg, nl_rules); | |
9329 | ||
9330 | return 0; | |
9331 | } | |
9332 | ||
9333 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9334 | { | |
9335 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9336 | struct sk_buff *msg; | |
9337 | void *hdr; | |
9338 | ||
9339 | if (!rdev->wiphy.coalesce) | |
9340 | return -EOPNOTSUPP; | |
9341 | ||
9342 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9343 | if (!msg) | |
9344 | return -ENOMEM; | |
9345 | ||
9346 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9347 | NL80211_CMD_GET_COALESCE); | |
9348 | if (!hdr) | |
9349 | goto nla_put_failure; | |
9350 | ||
9351 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
9352 | goto nla_put_failure; | |
9353 | ||
9354 | genlmsg_end(msg, hdr); | |
9355 | return genlmsg_reply(msg, info); | |
9356 | ||
9357 | nla_put_failure: | |
9358 | nlmsg_free(msg); | |
9359 | return -ENOBUFS; | |
9360 | } | |
9361 | ||
9362 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
9363 | { | |
9364 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
9365 | int i, j; | |
9366 | struct cfg80211_coalesce_rules *rule; | |
9367 | ||
9368 | if (!coalesce) | |
9369 | return; | |
9370 | ||
9371 | for (i = 0; i < coalesce->n_rules; i++) { | |
9372 | rule = &coalesce->rules[i]; | |
9373 | for (j = 0; j < rule->n_patterns; j++) | |
9374 | kfree(rule->patterns[j].mask); | |
9375 | kfree(rule->patterns); | |
9376 | } | |
9377 | kfree(coalesce->rules); | |
9378 | kfree(coalesce); | |
9379 | rdev->coalesce = NULL; | |
9380 | } | |
9381 | ||
9382 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
9383 | struct nlattr *rule, | |
9384 | struct cfg80211_coalesce_rules *new_rule) | |
9385 | { | |
9386 | int err, i; | |
9387 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9388 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
9389 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
9390 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
9391 | ||
9392 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
9393 | nla_len(rule), nl80211_coalesce_policy); | |
9394 | if (err) | |
9395 | return err; | |
9396 | ||
9397 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
9398 | new_rule->delay = | |
9399 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
9400 | if (new_rule->delay > coalesce->max_delay) | |
9401 | return -EINVAL; | |
9402 | ||
9403 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
9404 | new_rule->condition = | |
9405 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
9406 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
9407 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
9408 | return -EINVAL; | |
9409 | ||
9410 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
9411 | return -EINVAL; | |
9412 | ||
9413 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9414 | rem) | |
9415 | n_patterns++; | |
9416 | if (n_patterns > coalesce->n_patterns) | |
9417 | return -EINVAL; | |
9418 | ||
9419 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
9420 | GFP_KERNEL); | |
9421 | if (!new_rule->patterns) | |
9422 | return -ENOMEM; | |
9423 | ||
9424 | new_rule->n_patterns = n_patterns; | |
9425 | i = 0; | |
9426 | ||
9427 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9428 | rem) { | |
922bd80f JB |
9429 | u8 *mask_pat; |
9430 | ||
be29b99a AK |
9431 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9432 | nla_len(pat), NULL); | |
9433 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
9434 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
9435 | return -EINVAL; | |
9436 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
9437 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
9438 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
9439 | return -EINVAL; | |
9440 | if (pat_len > coalesce->pattern_max_len || | |
9441 | pat_len < coalesce->pattern_min_len) | |
9442 | return -EINVAL; | |
9443 | ||
9444 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
9445 | pkt_offset = 0; | |
9446 | else | |
9447 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
9448 | if (pkt_offset > coalesce->max_pkt_offset) | |
9449 | return -EINVAL; | |
9450 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
9451 | ||
922bd80f JB |
9452 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9453 | if (!mask_pat) | |
be29b99a | 9454 | return -ENOMEM; |
922bd80f JB |
9455 | |
9456 | new_rule->patterns[i].mask = mask_pat; | |
9457 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
9458 | mask_len); | |
9459 | ||
9460 | mask_pat += mask_len; | |
9461 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 9462 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
9463 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
9464 | pat_len); | |
be29b99a AK |
9465 | i++; |
9466 | } | |
9467 | ||
9468 | return 0; | |
9469 | } | |
9470 | ||
9471 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9472 | { | |
9473 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9474 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9475 | struct cfg80211_coalesce new_coalesce = {}; | |
9476 | struct cfg80211_coalesce *n_coalesce; | |
9477 | int err, rem_rule, n_rules = 0, i, j; | |
9478 | struct nlattr *rule; | |
9479 | struct cfg80211_coalesce_rules *tmp_rule; | |
9480 | ||
9481 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
9482 | return -EOPNOTSUPP; | |
9483 | ||
9484 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
9485 | cfg80211_rdev_free_coalesce(rdev); | |
9486 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
9487 | return 0; | |
9488 | } | |
9489 | ||
9490 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9491 | rem_rule) | |
9492 | n_rules++; | |
9493 | if (n_rules > coalesce->n_rules) | |
9494 | return -EINVAL; | |
9495 | ||
9496 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
9497 | GFP_KERNEL); | |
9498 | if (!new_coalesce.rules) | |
9499 | return -ENOMEM; | |
9500 | ||
9501 | new_coalesce.n_rules = n_rules; | |
9502 | i = 0; | |
9503 | ||
9504 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9505 | rem_rule) { | |
9506 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
9507 | &new_coalesce.rules[i]); | |
9508 | if (err) | |
9509 | goto error; | |
9510 | ||
9511 | i++; | |
9512 | } | |
9513 | ||
9514 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
9515 | if (err) | |
9516 | goto error; | |
9517 | ||
9518 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
9519 | if (!n_coalesce) { | |
9520 | err = -ENOMEM; | |
9521 | goto error; | |
9522 | } | |
9523 | cfg80211_rdev_free_coalesce(rdev); | |
9524 | rdev->coalesce = n_coalesce; | |
9525 | ||
9526 | return 0; | |
9527 | error: | |
9528 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
9529 | tmp_rule = &new_coalesce.rules[i]; | |
9530 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
9531 | kfree(tmp_rule->patterns[j].mask); | |
9532 | kfree(tmp_rule->patterns); | |
9533 | } | |
9534 | kfree(new_coalesce.rules); | |
9535 | ||
9536 | return err; | |
9537 | } | |
9538 | ||
e5497d76 JB |
9539 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
9540 | { | |
9541 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9542 | struct net_device *dev = info->user_ptr[1]; | |
9543 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9544 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
9545 | struct cfg80211_gtk_rekey_data rekey_data; | |
9546 | int err; | |
9547 | ||
9548 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
9549 | return -EINVAL; | |
9550 | ||
9551 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
9552 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9553 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9554 | nl80211_rekey_policy); | |
9555 | if (err) | |
9556 | return err; | |
9557 | ||
9558 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
9559 | return -ERANGE; | |
9560 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
9561 | return -ERANGE; | |
9562 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
9563 | return -ERANGE; | |
9564 | ||
78f686ca JB |
9565 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
9566 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | |
9567 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | |
e5497d76 JB |
9568 | |
9569 | wdev_lock(wdev); | |
9570 | if (!wdev->current_bss) { | |
9571 | err = -ENOTCONN; | |
9572 | goto out; | |
9573 | } | |
9574 | ||
9575 | if (!rdev->ops->set_rekey_data) { | |
9576 | err = -EOPNOTSUPP; | |
9577 | goto out; | |
9578 | } | |
9579 | ||
e35e4d28 | 9580 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
9581 | out: |
9582 | wdev_unlock(wdev); | |
9583 | return err; | |
9584 | } | |
9585 | ||
28946da7 JB |
9586 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
9587 | struct genl_info *info) | |
9588 | { | |
9589 | struct net_device *dev = info->user_ptr[1]; | |
9590 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9591 | ||
9592 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9593 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9594 | return -EINVAL; | |
9595 | ||
15e47304 | 9596 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
9597 | return -EBUSY; |
9598 | ||
15e47304 | 9599 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
9600 | return 0; |
9601 | } | |
9602 | ||
7f6cf311 JB |
9603 | static int nl80211_probe_client(struct sk_buff *skb, |
9604 | struct genl_info *info) | |
9605 | { | |
9606 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9607 | struct net_device *dev = info->user_ptr[1]; | |
9608 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9609 | struct sk_buff *msg; | |
9610 | void *hdr; | |
9611 | const u8 *addr; | |
9612 | u64 cookie; | |
9613 | int err; | |
9614 | ||
9615 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9616 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9617 | return -EOPNOTSUPP; | |
9618 | ||
9619 | if (!info->attrs[NL80211_ATTR_MAC]) | |
9620 | return -EINVAL; | |
9621 | ||
9622 | if (!rdev->ops->probe_client) | |
9623 | return -EOPNOTSUPP; | |
9624 | ||
9625 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9626 | if (!msg) | |
9627 | return -ENOMEM; | |
9628 | ||
15e47304 | 9629 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 9630 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
9631 | if (!hdr) { |
9632 | err = -ENOBUFS; | |
7f6cf311 JB |
9633 | goto free_msg; |
9634 | } | |
9635 | ||
9636 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9637 | ||
e35e4d28 | 9638 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
9639 | if (err) |
9640 | goto free_msg; | |
9641 | ||
9360ffd1 DM |
9642 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9643 | goto nla_put_failure; | |
7f6cf311 JB |
9644 | |
9645 | genlmsg_end(msg, hdr); | |
9646 | ||
9647 | return genlmsg_reply(msg, info); | |
9648 | ||
9649 | nla_put_failure: | |
9650 | err = -ENOBUFS; | |
9651 | free_msg: | |
9652 | nlmsg_free(msg); | |
9653 | return err; | |
9654 | } | |
9655 | ||
5e760230 JB |
9656 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
9657 | { | |
9658 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
9659 | struct cfg80211_beacon_registration *reg, *nreg; |
9660 | int rv; | |
5e760230 JB |
9661 | |
9662 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
9663 | return -EOPNOTSUPP; | |
9664 | ||
37c73b5f BG |
9665 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
9666 | if (!nreg) | |
9667 | return -ENOMEM; | |
9668 | ||
9669 | /* First, check if already registered. */ | |
9670 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
9671 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
9672 | if (reg->nlportid == info->snd_portid) { | |
9673 | rv = -EALREADY; | |
9674 | goto out_err; | |
9675 | } | |
9676 | } | |
9677 | /* Add it to the list */ | |
9678 | nreg->nlportid = info->snd_portid; | |
9679 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 9680 | |
37c73b5f | 9681 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
9682 | |
9683 | return 0; | |
37c73b5f BG |
9684 | out_err: |
9685 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
9686 | kfree(nreg); | |
9687 | return rv; | |
5e760230 JB |
9688 | } |
9689 | ||
98104fde JB |
9690 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
9691 | { | |
9692 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9693 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9694 | int err; | |
9695 | ||
9696 | if (!rdev->ops->start_p2p_device) | |
9697 | return -EOPNOTSUPP; | |
9698 | ||
9699 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9700 | return -EOPNOTSUPP; | |
9701 | ||
9702 | if (wdev->p2p_started) | |
9703 | return 0; | |
9704 | ||
b6a55015 LC |
9705 | if (rfkill_blocked(rdev->rfkill)) |
9706 | return -ERFKILL; | |
98104fde | 9707 | |
eeb126e9 | 9708 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
9709 | if (err) |
9710 | return err; | |
9711 | ||
9712 | wdev->p2p_started = true; | |
98104fde | 9713 | rdev->opencount++; |
98104fde JB |
9714 | |
9715 | return 0; | |
9716 | } | |
9717 | ||
9718 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
9719 | { | |
9720 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9721 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9722 | ||
9723 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9724 | return -EOPNOTSUPP; | |
9725 | ||
9726 | if (!rdev->ops->stop_p2p_device) | |
9727 | return -EOPNOTSUPP; | |
9728 | ||
f9f47529 | 9729 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
9730 | |
9731 | return 0; | |
9732 | } | |
9733 | ||
3713b4e3 JB |
9734 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
9735 | struct genl_info *info) | |
9736 | { | |
9737 | void *hdr; | |
9738 | struct sk_buff *msg; | |
9739 | ||
9740 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9741 | if (!msg) | |
9742 | return -ENOMEM; | |
9743 | ||
9744 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9745 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
9746 | if (!hdr) | |
9747 | goto nla_put_failure; | |
9748 | ||
9749 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
9750 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
9751 | goto nla_put_failure; | |
9752 | ||
9753 | genlmsg_end(msg, hdr); | |
9754 | return genlmsg_reply(msg, info); | |
9755 | ||
9756 | nla_put_failure: | |
9757 | kfree_skb(msg); | |
9758 | return -ENOBUFS; | |
9759 | } | |
9760 | ||
355199e0 JM |
9761 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
9762 | { | |
9763 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9764 | struct cfg80211_update_ft_ies_params ft_params; | |
9765 | struct net_device *dev = info->user_ptr[1]; | |
9766 | ||
9767 | if (!rdev->ops->update_ft_ies) | |
9768 | return -EOPNOTSUPP; | |
9769 | ||
9770 | if (!info->attrs[NL80211_ATTR_MDID] || | |
9771 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
9772 | return -EINVAL; | |
9773 | ||
9774 | memset(&ft_params, 0, sizeof(ft_params)); | |
9775 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
9776 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
9777 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9778 | ||
9779 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
9780 | } | |
9781 | ||
5de17984 AS |
9782 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
9783 | struct genl_info *info) | |
9784 | { | |
9785 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9786 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9787 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
9788 | u16 duration; | |
9789 | int ret; | |
9790 | ||
9791 | if (!rdev->ops->crit_proto_start) | |
9792 | return -EOPNOTSUPP; | |
9793 | ||
9794 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
9795 | return -EINVAL; | |
9796 | ||
9797 | if (rdev->crit_proto_nlportid) | |
9798 | return -EBUSY; | |
9799 | ||
9800 | /* determine protocol if provided */ | |
9801 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
9802 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
9803 | ||
9804 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
9805 | return -EINVAL; | |
9806 | ||
9807 | /* timeout must be provided */ | |
9808 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
9809 | return -EINVAL; | |
9810 | ||
9811 | duration = | |
9812 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
9813 | ||
9814 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
9815 | return -ERANGE; | |
9816 | ||
9817 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
9818 | if (!ret) | |
9819 | rdev->crit_proto_nlportid = info->snd_portid; | |
9820 | ||
9821 | return ret; | |
9822 | } | |
9823 | ||
9824 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
9825 | struct genl_info *info) | |
9826 | { | |
9827 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9828 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9829 | ||
9830 | if (!rdev->ops->crit_proto_stop) | |
9831 | return -EOPNOTSUPP; | |
9832 | ||
9833 | if (rdev->crit_proto_nlportid) { | |
9834 | rdev->crit_proto_nlportid = 0; | |
9835 | rdev_crit_proto_stop(rdev, wdev); | |
9836 | } | |
9837 | return 0; | |
9838 | } | |
9839 | ||
ad7e718c JB |
9840 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
9841 | { | |
9842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9843 | struct wireless_dev *wdev = | |
9844 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
9845 | int i, err; | |
9846 | u32 vid, subcmd; | |
9847 | ||
9848 | if (!rdev->wiphy.vendor_commands) | |
9849 | return -EOPNOTSUPP; | |
9850 | ||
9851 | if (IS_ERR(wdev)) { | |
9852 | err = PTR_ERR(wdev); | |
9853 | if (err != -EINVAL) | |
9854 | return err; | |
9855 | wdev = NULL; | |
9856 | } else if (wdev->wiphy != &rdev->wiphy) { | |
9857 | return -EINVAL; | |
9858 | } | |
9859 | ||
9860 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
9861 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
9862 | return -EINVAL; | |
9863 | ||
9864 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
9865 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
9866 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
9867 | const struct wiphy_vendor_command *vcmd; | |
9868 | void *data = NULL; | |
9869 | int len = 0; | |
9870 | ||
9871 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
9872 | ||
9873 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
9874 | continue; | |
9875 | ||
9876 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
9877 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
9878 | if (!wdev) | |
9879 | return -EINVAL; | |
9880 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
9881 | !wdev->netdev) | |
9882 | return -EINVAL; | |
9883 | ||
9884 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
9885 | if (wdev->netdev && | |
9886 | !netif_running(wdev->netdev)) | |
9887 | return -ENETDOWN; | |
9888 | if (!wdev->netdev && !wdev->p2p_started) | |
9889 | return -ENETDOWN; | |
9890 | } | |
9891 | } else { | |
9892 | wdev = NULL; | |
9893 | } | |
9894 | ||
9895 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
9896 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9897 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9898 | } | |
9899 | ||
9900 | rdev->cur_cmd_info = info; | |
9901 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
9902 | data, len); | |
9903 | rdev->cur_cmd_info = NULL; | |
9904 | return err; | |
9905 | } | |
9906 | ||
9907 | return -EOPNOTSUPP; | |
9908 | } | |
9909 | ||
9910 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | |
9911 | enum nl80211_commands cmd, | |
9912 | enum nl80211_attrs attr, | |
9913 | int approxlen) | |
9914 | { | |
f26cbf40 | 9915 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
9916 | |
9917 | if (WARN_ON(!rdev->cur_cmd_info)) | |
9918 | return NULL; | |
9919 | ||
6c09e791 | 9920 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
ad7e718c JB |
9921 | rdev->cur_cmd_info->snd_portid, |
9922 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 9923 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
9924 | } |
9925 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
9926 | ||
9927 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
9928 | { | |
9929 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
9930 | void *hdr = ((void **)skb->cb)[1]; | |
9931 | struct nlattr *data = ((void **)skb->cb)[2]; | |
9932 | ||
bd8c78e7 JB |
9933 | /* clear CB data for netlink core to own from now on */ |
9934 | memset(skb->cb, 0, sizeof(skb->cb)); | |
9935 | ||
ad7e718c JB |
9936 | if (WARN_ON(!rdev->cur_cmd_info)) { |
9937 | kfree_skb(skb); | |
9938 | return -EINVAL; | |
9939 | } | |
9940 | ||
9941 | nla_nest_end(skb, data); | |
9942 | genlmsg_end(skb, hdr); | |
9943 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
9944 | } | |
9945 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
9946 | ||
9947 | ||
fa9ffc74 KP |
9948 | static int nl80211_set_qos_map(struct sk_buff *skb, |
9949 | struct genl_info *info) | |
9950 | { | |
9951 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9952 | struct cfg80211_qos_map *qos_map = NULL; | |
9953 | struct net_device *dev = info->user_ptr[1]; | |
9954 | u8 *pos, len, num_des, des_len, des; | |
9955 | int ret; | |
9956 | ||
9957 | if (!rdev->ops->set_qos_map) | |
9958 | return -EOPNOTSUPP; | |
9959 | ||
9960 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
9961 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9962 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9963 | ||
9964 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
9965 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
9966 | return -EINVAL; | |
9967 | ||
9968 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
9969 | if (!qos_map) | |
9970 | return -ENOMEM; | |
9971 | ||
9972 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
9973 | if (num_des) { | |
9974 | des_len = num_des * | |
9975 | sizeof(struct cfg80211_dscp_exception); | |
9976 | memcpy(qos_map->dscp_exception, pos, des_len); | |
9977 | qos_map->num_des = num_des; | |
9978 | for (des = 0; des < num_des; des++) { | |
9979 | if (qos_map->dscp_exception[des].up > 7) { | |
9980 | kfree(qos_map); | |
9981 | return -EINVAL; | |
9982 | } | |
9983 | } | |
9984 | pos += des_len; | |
9985 | } | |
9986 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
9987 | } | |
9988 | ||
9989 | wdev_lock(dev->ieee80211_ptr); | |
9990 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
9991 | if (!ret) | |
9992 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
9993 | wdev_unlock(dev->ieee80211_ptr); | |
9994 | ||
9995 | kfree(qos_map); | |
9996 | return ret; | |
9997 | } | |
9998 | ||
960d01ac JB |
9999 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
10000 | { | |
10001 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10002 | struct net_device *dev = info->user_ptr[1]; | |
10003 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10004 | const u8 *peer; | |
10005 | u8 tsid, up; | |
10006 | u16 admitted_time = 0; | |
10007 | int err; | |
10008 | ||
723e73ac | 10009 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
960d01ac JB |
10010 | return -EOPNOTSUPP; |
10011 | ||
10012 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | |
10013 | !info->attrs[NL80211_ATTR_USER_PRIO]) | |
10014 | return -EINVAL; | |
10015 | ||
10016 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
10017 | if (tsid >= IEEE80211_NUM_TIDS) | |
10018 | return -EINVAL; | |
10019 | ||
10020 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); | |
10021 | if (up >= IEEE80211_NUM_UPS) | |
10022 | return -EINVAL; | |
10023 | ||
10024 | /* WMM uses TIDs 0-7 even for TSPEC */ | |
723e73ac | 10025 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
960d01ac | 10026 | /* TODO: handle 802.11 TSPEC/admission control |
723e73ac JB |
10027 | * need more attributes for that (e.g. BA session requirement); |
10028 | * change the WMM adminssion test above to allow both then | |
960d01ac JB |
10029 | */ |
10030 | return -EINVAL; | |
10031 | } | |
10032 | ||
10033 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10034 | ||
10035 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | |
10036 | admitted_time = | |
10037 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | |
10038 | if (!admitted_time) | |
10039 | return -EINVAL; | |
10040 | } | |
10041 | ||
10042 | wdev_lock(wdev); | |
10043 | switch (wdev->iftype) { | |
10044 | case NL80211_IFTYPE_STATION: | |
10045 | case NL80211_IFTYPE_P2P_CLIENT: | |
10046 | if (wdev->current_bss) | |
10047 | break; | |
10048 | err = -ENOTCONN; | |
10049 | goto out; | |
10050 | default: | |
10051 | err = -EOPNOTSUPP; | |
10052 | goto out; | |
10053 | } | |
10054 | ||
10055 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | |
10056 | ||
10057 | out: | |
10058 | wdev_unlock(wdev); | |
10059 | return err; | |
10060 | } | |
10061 | ||
10062 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | |
10063 | { | |
10064 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10065 | struct net_device *dev = info->user_ptr[1]; | |
10066 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10067 | const u8 *peer; | |
10068 | u8 tsid; | |
10069 | int err; | |
10070 | ||
10071 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | |
10072 | return -EINVAL; | |
10073 | ||
10074 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
10075 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10076 | ||
10077 | wdev_lock(wdev); | |
10078 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | |
10079 | wdev_unlock(wdev); | |
10080 | ||
10081 | return err; | |
10082 | } | |
10083 | ||
1057d35e AN |
10084 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
10085 | struct genl_info *info) | |
10086 | { | |
10087 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10088 | struct net_device *dev = info->user_ptr[1]; | |
10089 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10090 | struct cfg80211_chan_def chandef = {}; | |
10091 | const u8 *addr; | |
10092 | u8 oper_class; | |
10093 | int err; | |
10094 | ||
10095 | if (!rdev->ops->tdls_channel_switch || | |
10096 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
10097 | return -EOPNOTSUPP; | |
10098 | ||
10099 | switch (dev->ieee80211_ptr->iftype) { | |
10100 | case NL80211_IFTYPE_STATION: | |
10101 | case NL80211_IFTYPE_P2P_CLIENT: | |
10102 | break; | |
10103 | default: | |
10104 | return -EOPNOTSUPP; | |
10105 | } | |
10106 | ||
10107 | if (!info->attrs[NL80211_ATTR_MAC] || | |
10108 | !info->attrs[NL80211_ATTR_OPER_CLASS]) | |
10109 | return -EINVAL; | |
10110 | ||
10111 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
10112 | if (err) | |
10113 | return err; | |
10114 | ||
10115 | /* | |
10116 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | |
10117 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | |
10118 | * specification is not defined for them. | |
10119 | */ | |
10120 | if (chandef.chan->band == IEEE80211_BAND_2GHZ && | |
10121 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | |
10122 | chandef.width != NL80211_CHAN_WIDTH_20) | |
10123 | return -EINVAL; | |
10124 | ||
10125 | /* we will be active on the TDLS link */ | |
10126 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype)) | |
10127 | return -EINVAL; | |
10128 | ||
10129 | /* don't allow switching to DFS channels */ | |
10130 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | |
10131 | return -EINVAL; | |
10132 | ||
10133 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10134 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | |
10135 | ||
10136 | wdev_lock(wdev); | |
10137 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | |
10138 | wdev_unlock(wdev); | |
10139 | ||
10140 | return err; | |
10141 | } | |
10142 | ||
10143 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | |
10144 | struct genl_info *info) | |
10145 | { | |
10146 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10147 | struct net_device *dev = info->user_ptr[1]; | |
10148 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10149 | const u8 *addr; | |
10150 | ||
10151 | if (!rdev->ops->tdls_channel_switch || | |
10152 | !rdev->ops->tdls_cancel_channel_switch || | |
10153 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
10154 | return -EOPNOTSUPP; | |
10155 | ||
10156 | switch (dev->ieee80211_ptr->iftype) { | |
10157 | case NL80211_IFTYPE_STATION: | |
10158 | case NL80211_IFTYPE_P2P_CLIENT: | |
10159 | break; | |
10160 | default: | |
10161 | return -EOPNOTSUPP; | |
10162 | } | |
10163 | ||
10164 | if (!info->attrs[NL80211_ATTR_MAC]) | |
10165 | return -EINVAL; | |
10166 | ||
10167 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10168 | ||
10169 | wdev_lock(wdev); | |
10170 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); | |
10171 | wdev_unlock(wdev); | |
10172 | ||
10173 | return 0; | |
10174 | } | |
10175 | ||
4c476991 JB |
10176 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
10177 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
10178 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
10179 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
10180 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
10181 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 10182 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 10183 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
10184 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
10185 | NL80211_FLAG_CHECK_NETDEV_UP) | |
5393b917 | 10186 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
4c476991 | 10187 | |
f84f771d | 10188 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10189 | struct genl_info *info) |
10190 | { | |
10191 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 10192 | struct wireless_dev *wdev; |
4c476991 | 10193 | struct net_device *dev; |
4c476991 JB |
10194 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
10195 | ||
10196 | if (rtnl) | |
10197 | rtnl_lock(); | |
10198 | ||
10199 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 10200 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
10201 | if (IS_ERR(rdev)) { |
10202 | if (rtnl) | |
10203 | rtnl_unlock(); | |
10204 | return PTR_ERR(rdev); | |
10205 | } | |
10206 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
10207 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
10208 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
10209 | ASSERT_RTNL(); |
10210 | ||
89a54e48 JB |
10211 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
10212 | info->attrs); | |
10213 | if (IS_ERR(wdev)) { | |
4c476991 JB |
10214 | if (rtnl) |
10215 | rtnl_unlock(); | |
89a54e48 | 10216 | return PTR_ERR(wdev); |
4c476991 | 10217 | } |
89a54e48 | 10218 | |
89a54e48 | 10219 | dev = wdev->netdev; |
f26cbf40 | 10220 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 10221 | |
1bf614ef JB |
10222 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
10223 | if (!dev) { | |
1bf614ef JB |
10224 | if (rtnl) |
10225 | rtnl_unlock(); | |
10226 | return -EINVAL; | |
10227 | } | |
10228 | ||
10229 | info->user_ptr[1] = dev; | |
10230 | } else { | |
10231 | info->user_ptr[1] = wdev; | |
41265714 | 10232 | } |
1bf614ef JB |
10233 | |
10234 | if (dev) { | |
10235 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
10236 | !netif_running(dev)) { | |
1bf614ef JB |
10237 | if (rtnl) |
10238 | rtnl_unlock(); | |
10239 | return -ENETDOWN; | |
10240 | } | |
10241 | ||
10242 | dev_hold(dev); | |
98104fde JB |
10243 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
10244 | if (!wdev->p2p_started) { | |
98104fde JB |
10245 | if (rtnl) |
10246 | rtnl_unlock(); | |
10247 | return -ENETDOWN; | |
10248 | } | |
41265714 | 10249 | } |
89a54e48 | 10250 | |
4c476991 | 10251 | info->user_ptr[0] = rdev; |
4c476991 JB |
10252 | } |
10253 | ||
10254 | return 0; | |
10255 | } | |
10256 | ||
f84f771d | 10257 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10258 | struct genl_info *info) |
10259 | { | |
1bf614ef JB |
10260 | if (info->user_ptr[1]) { |
10261 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
10262 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10263 | ||
10264 | if (wdev->netdev) | |
10265 | dev_put(wdev->netdev); | |
10266 | } else { | |
10267 | dev_put(info->user_ptr[1]); | |
10268 | } | |
10269 | } | |
5393b917 | 10270 | |
4c476991 JB |
10271 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
10272 | rtnl_unlock(); | |
5393b917 JB |
10273 | |
10274 | /* If needed, clear the netlink message payload from the SKB | |
10275 | * as it might contain key data that shouldn't stick around on | |
10276 | * the heap after the SKB is freed. The netlink message header | |
10277 | * is still needed for further processing, so leave it intact. | |
10278 | */ | |
10279 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | |
10280 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | |
10281 | ||
10282 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | |
10283 | } | |
4c476991 JB |
10284 | } |
10285 | ||
4534de83 | 10286 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
10287 | { |
10288 | .cmd = NL80211_CMD_GET_WIPHY, | |
10289 | .doit = nl80211_get_wiphy, | |
10290 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 10291 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
10292 | .policy = nl80211_policy, |
10293 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10294 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10295 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10296 | }, |
10297 | { | |
10298 | .cmd = NL80211_CMD_SET_WIPHY, | |
10299 | .doit = nl80211_set_wiphy, | |
10300 | .policy = nl80211_policy, | |
10301 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 10302 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
10303 | }, |
10304 | { | |
10305 | .cmd = NL80211_CMD_GET_INTERFACE, | |
10306 | .doit = nl80211_get_interface, | |
10307 | .dumpit = nl80211_dump_interface, | |
10308 | .policy = nl80211_policy, | |
10309 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10310 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
10311 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10312 | }, |
10313 | { | |
10314 | .cmd = NL80211_CMD_SET_INTERFACE, | |
10315 | .doit = nl80211_set_interface, | |
10316 | .policy = nl80211_policy, | |
10317 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10318 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10319 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10320 | }, |
10321 | { | |
10322 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
10323 | .doit = nl80211_new_interface, | |
10324 | .policy = nl80211_policy, | |
10325 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10326 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10327 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10328 | }, |
10329 | { | |
10330 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
10331 | .doit = nl80211_del_interface, | |
10332 | .policy = nl80211_policy, | |
41ade00f | 10333 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 10334 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10335 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10336 | }, |
10337 | { | |
10338 | .cmd = NL80211_CMD_GET_KEY, | |
10339 | .doit = nl80211_get_key, | |
10340 | .policy = nl80211_policy, | |
10341 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10342 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10343 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10344 | }, |
10345 | { | |
10346 | .cmd = NL80211_CMD_SET_KEY, | |
10347 | .doit = nl80211_set_key, | |
10348 | .policy = nl80211_policy, | |
10349 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10350 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10351 | NL80211_FLAG_NEED_RTNL | |
10352 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10353 | }, |
10354 | { | |
10355 | .cmd = NL80211_CMD_NEW_KEY, | |
10356 | .doit = nl80211_new_key, | |
10357 | .policy = nl80211_policy, | |
10358 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10359 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10360 | NL80211_FLAG_NEED_RTNL | |
10361 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10362 | }, |
10363 | { | |
10364 | .cmd = NL80211_CMD_DEL_KEY, | |
10365 | .doit = nl80211_del_key, | |
10366 | .policy = nl80211_policy, | |
55682965 | 10367 | .flags = GENL_ADMIN_PERM, |
41265714 | 10368 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10369 | NL80211_FLAG_NEED_RTNL, |
55682965 | 10370 | }, |
ed1b6cc7 JB |
10371 | { |
10372 | .cmd = NL80211_CMD_SET_BEACON, | |
10373 | .policy = nl80211_policy, | |
10374 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10375 | .doit = nl80211_set_beacon, |
2b5f8b0b | 10376 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10377 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10378 | }, |
10379 | { | |
8860020e | 10380 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
10381 | .policy = nl80211_policy, |
10382 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10383 | .doit = nl80211_start_ap, |
2b5f8b0b | 10384 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10385 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10386 | }, |
10387 | { | |
8860020e | 10388 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
10389 | .policy = nl80211_policy, |
10390 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10391 | .doit = nl80211_stop_ap, |
2b5f8b0b | 10392 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10393 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 10394 | }, |
5727ef1b JB |
10395 | { |
10396 | .cmd = NL80211_CMD_GET_STATION, | |
10397 | .doit = nl80211_get_station, | |
2ec600d6 | 10398 | .dumpit = nl80211_dump_station, |
5727ef1b | 10399 | .policy = nl80211_policy, |
4c476991 JB |
10400 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10401 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
10402 | }, |
10403 | { | |
10404 | .cmd = NL80211_CMD_SET_STATION, | |
10405 | .doit = nl80211_set_station, | |
10406 | .policy = nl80211_policy, | |
10407 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10408 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10409 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10410 | }, |
10411 | { | |
10412 | .cmd = NL80211_CMD_NEW_STATION, | |
10413 | .doit = nl80211_new_station, | |
10414 | .policy = nl80211_policy, | |
10415 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10416 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10417 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10418 | }, |
10419 | { | |
10420 | .cmd = NL80211_CMD_DEL_STATION, | |
10421 | .doit = nl80211_del_station, | |
10422 | .policy = nl80211_policy, | |
2ec600d6 | 10423 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10424 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10425 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10426 | }, |
10427 | { | |
10428 | .cmd = NL80211_CMD_GET_MPATH, | |
10429 | .doit = nl80211_get_mpath, | |
10430 | .dumpit = nl80211_dump_mpath, | |
10431 | .policy = nl80211_policy, | |
10432 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10433 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10434 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 | 10435 | }, |
66be7d2b HR |
10436 | { |
10437 | .cmd = NL80211_CMD_GET_MPP, | |
10438 | .doit = nl80211_get_mpp, | |
10439 | .dumpit = nl80211_dump_mpp, | |
10440 | .policy = nl80211_policy, | |
10441 | .flags = GENL_ADMIN_PERM, | |
10442 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10443 | NL80211_FLAG_NEED_RTNL, | |
10444 | }, | |
2ec600d6 LCC |
10445 | { |
10446 | .cmd = NL80211_CMD_SET_MPATH, | |
10447 | .doit = nl80211_set_mpath, | |
10448 | .policy = nl80211_policy, | |
10449 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10450 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10451 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10452 | }, |
10453 | { | |
10454 | .cmd = NL80211_CMD_NEW_MPATH, | |
10455 | .doit = nl80211_new_mpath, | |
10456 | .policy = nl80211_policy, | |
10457 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10458 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10459 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10460 | }, |
10461 | { | |
10462 | .cmd = NL80211_CMD_DEL_MPATH, | |
10463 | .doit = nl80211_del_mpath, | |
10464 | .policy = nl80211_policy, | |
9f1ba906 | 10465 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10466 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10467 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
10468 | }, |
10469 | { | |
10470 | .cmd = NL80211_CMD_SET_BSS, | |
10471 | .doit = nl80211_set_bss, | |
10472 | .policy = nl80211_policy, | |
b2e1b302 | 10473 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10474 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10475 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 10476 | }, |
f130347c LR |
10477 | { |
10478 | .cmd = NL80211_CMD_GET_REG, | |
ad30ca2c AN |
10479 | .doit = nl80211_get_reg_do, |
10480 | .dumpit = nl80211_get_reg_dump, | |
f130347c | 10481 | .policy = nl80211_policy, |
5fe231e8 | 10482 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
10483 | /* can be retrieved by unprivileged users */ |
10484 | }, | |
b2e1b302 LR |
10485 | { |
10486 | .cmd = NL80211_CMD_SET_REG, | |
10487 | .doit = nl80211_set_reg, | |
10488 | .policy = nl80211_policy, | |
10489 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 10490 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
10491 | }, |
10492 | { | |
10493 | .cmd = NL80211_CMD_REQ_SET_REG, | |
10494 | .doit = nl80211_req_set_reg, | |
10495 | .policy = nl80211_policy, | |
93da9cc1 | 10496 | .flags = GENL_ADMIN_PERM, |
10497 | }, | |
10498 | { | |
24bdd9f4 JC |
10499 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
10500 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 10501 | .policy = nl80211_policy, |
10502 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 10503 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10504 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 10505 | }, |
10506 | { | |
24bdd9f4 JC |
10507 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
10508 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 10509 | .policy = nl80211_policy, |
9aed3cc1 | 10510 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 10511 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10512 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 10513 | }, |
2a519311 JB |
10514 | { |
10515 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
10516 | .doit = nl80211_trigger_scan, | |
10517 | .policy = nl80211_policy, | |
10518 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 10519 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10520 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
10521 | }, |
10522 | { | |
10523 | .cmd = NL80211_CMD_GET_SCAN, | |
10524 | .policy = nl80211_policy, | |
10525 | .dumpit = nl80211_dump_scan, | |
10526 | }, | |
807f8a8c LC |
10527 | { |
10528 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
10529 | .doit = nl80211_start_sched_scan, | |
10530 | .policy = nl80211_policy, | |
10531 | .flags = GENL_ADMIN_PERM, | |
10532 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10533 | NL80211_FLAG_NEED_RTNL, | |
10534 | }, | |
10535 | { | |
10536 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
10537 | .doit = nl80211_stop_sched_scan, | |
10538 | .policy = nl80211_policy, | |
10539 | .flags = GENL_ADMIN_PERM, | |
10540 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10541 | NL80211_FLAG_NEED_RTNL, | |
10542 | }, | |
636a5d36 JM |
10543 | { |
10544 | .cmd = NL80211_CMD_AUTHENTICATE, | |
10545 | .doit = nl80211_authenticate, | |
10546 | .policy = nl80211_policy, | |
10547 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10548 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10549 | NL80211_FLAG_NEED_RTNL | |
10550 | NL80211_FLAG_CLEAR_SKB, | |
636a5d36 JM |
10551 | }, |
10552 | { | |
10553 | .cmd = NL80211_CMD_ASSOCIATE, | |
10554 | .doit = nl80211_associate, | |
10555 | .policy = nl80211_policy, | |
10556 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10557 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10558 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10559 | }, |
10560 | { | |
10561 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
10562 | .doit = nl80211_deauthenticate, | |
10563 | .policy = nl80211_policy, | |
10564 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10565 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10566 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10567 | }, |
10568 | { | |
10569 | .cmd = NL80211_CMD_DISASSOCIATE, | |
10570 | .doit = nl80211_disassociate, | |
10571 | .policy = nl80211_policy, | |
10572 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10573 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10574 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 10575 | }, |
04a773ad JB |
10576 | { |
10577 | .cmd = NL80211_CMD_JOIN_IBSS, | |
10578 | .doit = nl80211_join_ibss, | |
10579 | .policy = nl80211_policy, | |
10580 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10581 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10582 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
10583 | }, |
10584 | { | |
10585 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
10586 | .doit = nl80211_leave_ibss, | |
10587 | .policy = nl80211_policy, | |
10588 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10589 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10590 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 10591 | }, |
aff89a9b JB |
10592 | #ifdef CONFIG_NL80211_TESTMODE |
10593 | { | |
10594 | .cmd = NL80211_CMD_TESTMODE, | |
10595 | .doit = nl80211_testmode_do, | |
71063f0e | 10596 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
10597 | .policy = nl80211_policy, |
10598 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10599 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10600 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
10601 | }, |
10602 | #endif | |
b23aa676 SO |
10603 | { |
10604 | .cmd = NL80211_CMD_CONNECT, | |
10605 | .doit = nl80211_connect, | |
10606 | .policy = nl80211_policy, | |
10607 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10608 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10609 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
10610 | }, |
10611 | { | |
10612 | .cmd = NL80211_CMD_DISCONNECT, | |
10613 | .doit = nl80211_disconnect, | |
10614 | .policy = nl80211_policy, | |
10615 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10616 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10617 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 10618 | }, |
463d0183 JB |
10619 | { |
10620 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
10621 | .doit = nl80211_wiphy_netns, | |
10622 | .policy = nl80211_policy, | |
10623 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10624 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10625 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 10626 | }, |
61fa713c HS |
10627 | { |
10628 | .cmd = NL80211_CMD_GET_SURVEY, | |
10629 | .policy = nl80211_policy, | |
10630 | .dumpit = nl80211_dump_survey, | |
10631 | }, | |
67fbb16b SO |
10632 | { |
10633 | .cmd = NL80211_CMD_SET_PMKSA, | |
10634 | .doit = nl80211_setdel_pmksa, | |
10635 | .policy = nl80211_policy, | |
10636 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10637 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10638 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10639 | }, |
10640 | { | |
10641 | .cmd = NL80211_CMD_DEL_PMKSA, | |
10642 | .doit = nl80211_setdel_pmksa, | |
10643 | .policy = nl80211_policy, | |
10644 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10645 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10646 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10647 | }, |
10648 | { | |
10649 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
10650 | .doit = nl80211_flush_pmksa, | |
10651 | .policy = nl80211_policy, | |
10652 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10653 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10654 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 10655 | }, |
9588bbd5 JM |
10656 | { |
10657 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
10658 | .doit = nl80211_remain_on_channel, | |
10659 | .policy = nl80211_policy, | |
10660 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10661 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10662 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
10663 | }, |
10664 | { | |
10665 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
10666 | .doit = nl80211_cancel_remain_on_channel, | |
10667 | .policy = nl80211_policy, | |
10668 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10669 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10670 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 10671 | }, |
13ae75b1 JM |
10672 | { |
10673 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
10674 | .doit = nl80211_set_tx_bitrate_mask, | |
10675 | .policy = nl80211_policy, | |
10676 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10677 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10678 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 10679 | }, |
026331c4 | 10680 | { |
2e161f78 JB |
10681 | .cmd = NL80211_CMD_REGISTER_FRAME, |
10682 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
10683 | .policy = nl80211_policy, |
10684 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10685 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10686 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
10687 | }, |
10688 | { | |
2e161f78 JB |
10689 | .cmd = NL80211_CMD_FRAME, |
10690 | .doit = nl80211_tx_mgmt, | |
026331c4 | 10691 | .policy = nl80211_policy, |
f7ca38df | 10692 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10693 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
10694 | NL80211_FLAG_NEED_RTNL, |
10695 | }, | |
10696 | { | |
10697 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
10698 | .doit = nl80211_tx_mgmt_cancel_wait, | |
10699 | .policy = nl80211_policy, | |
026331c4 | 10700 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10701 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10702 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 10703 | }, |
ffb9eb3d KV |
10704 | { |
10705 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
10706 | .doit = nl80211_set_power_save, | |
10707 | .policy = nl80211_policy, | |
10708 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10709 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10710 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
10711 | }, |
10712 | { | |
10713 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
10714 | .doit = nl80211_get_power_save, | |
10715 | .policy = nl80211_policy, | |
10716 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
10717 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10718 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 10719 | }, |
d6dc1a38 JO |
10720 | { |
10721 | .cmd = NL80211_CMD_SET_CQM, | |
10722 | .doit = nl80211_set_cqm, | |
10723 | .policy = nl80211_policy, | |
10724 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10725 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10726 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 10727 | }, |
f444de05 JB |
10728 | { |
10729 | .cmd = NL80211_CMD_SET_CHANNEL, | |
10730 | .doit = nl80211_set_channel, | |
10731 | .policy = nl80211_policy, | |
10732 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10733 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10734 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 10735 | }, |
e8347eba BJ |
10736 | { |
10737 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
10738 | .doit = nl80211_set_wds_peer, | |
10739 | .policy = nl80211_policy, | |
10740 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
10741 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10742 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 10743 | }, |
29cbe68c JB |
10744 | { |
10745 | .cmd = NL80211_CMD_JOIN_MESH, | |
10746 | .doit = nl80211_join_mesh, | |
10747 | .policy = nl80211_policy, | |
10748 | .flags = GENL_ADMIN_PERM, | |
10749 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10750 | NL80211_FLAG_NEED_RTNL, | |
10751 | }, | |
10752 | { | |
10753 | .cmd = NL80211_CMD_LEAVE_MESH, | |
10754 | .doit = nl80211_leave_mesh, | |
10755 | .policy = nl80211_policy, | |
10756 | .flags = GENL_ADMIN_PERM, | |
10757 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10758 | NL80211_FLAG_NEED_RTNL, | |
10759 | }, | |
6e0bd6c3 RL |
10760 | { |
10761 | .cmd = NL80211_CMD_JOIN_OCB, | |
10762 | .doit = nl80211_join_ocb, | |
10763 | .policy = nl80211_policy, | |
10764 | .flags = GENL_ADMIN_PERM, | |
10765 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10766 | NL80211_FLAG_NEED_RTNL, | |
10767 | }, | |
10768 | { | |
10769 | .cmd = NL80211_CMD_LEAVE_OCB, | |
10770 | .doit = nl80211_leave_ocb, | |
10771 | .policy = nl80211_policy, | |
10772 | .flags = GENL_ADMIN_PERM, | |
10773 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10774 | NL80211_FLAG_NEED_RTNL, | |
10775 | }, | |
dfb89c56 | 10776 | #ifdef CONFIG_PM |
ff1b6e69 JB |
10777 | { |
10778 | .cmd = NL80211_CMD_GET_WOWLAN, | |
10779 | .doit = nl80211_get_wowlan, | |
10780 | .policy = nl80211_policy, | |
10781 | /* can be retrieved by unprivileged users */ | |
10782 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10783 | NL80211_FLAG_NEED_RTNL, | |
10784 | }, | |
10785 | { | |
10786 | .cmd = NL80211_CMD_SET_WOWLAN, | |
10787 | .doit = nl80211_set_wowlan, | |
10788 | .policy = nl80211_policy, | |
10789 | .flags = GENL_ADMIN_PERM, | |
10790 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10791 | NL80211_FLAG_NEED_RTNL, | |
10792 | }, | |
dfb89c56 | 10793 | #endif |
e5497d76 JB |
10794 | { |
10795 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
10796 | .doit = nl80211_set_rekey_data, | |
10797 | .policy = nl80211_policy, | |
10798 | .flags = GENL_ADMIN_PERM, | |
10799 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
5393b917 JB |
10800 | NL80211_FLAG_NEED_RTNL | |
10801 | NL80211_FLAG_CLEAR_SKB, | |
e5497d76 | 10802 | }, |
109086ce AN |
10803 | { |
10804 | .cmd = NL80211_CMD_TDLS_MGMT, | |
10805 | .doit = nl80211_tdls_mgmt, | |
10806 | .policy = nl80211_policy, | |
10807 | .flags = GENL_ADMIN_PERM, | |
10808 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10809 | NL80211_FLAG_NEED_RTNL, | |
10810 | }, | |
10811 | { | |
10812 | .cmd = NL80211_CMD_TDLS_OPER, | |
10813 | .doit = nl80211_tdls_oper, | |
10814 | .policy = nl80211_policy, | |
10815 | .flags = GENL_ADMIN_PERM, | |
10816 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10817 | NL80211_FLAG_NEED_RTNL, | |
10818 | }, | |
28946da7 JB |
10819 | { |
10820 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
10821 | .doit = nl80211_register_unexpected_frame, | |
10822 | .policy = nl80211_policy, | |
10823 | .flags = GENL_ADMIN_PERM, | |
10824 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10825 | NL80211_FLAG_NEED_RTNL, | |
10826 | }, | |
7f6cf311 JB |
10827 | { |
10828 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
10829 | .doit = nl80211_probe_client, | |
10830 | .policy = nl80211_policy, | |
10831 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10832 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
10833 | NL80211_FLAG_NEED_RTNL, |
10834 | }, | |
5e760230 JB |
10835 | { |
10836 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
10837 | .doit = nl80211_register_beacons, | |
10838 | .policy = nl80211_policy, | |
10839 | .flags = GENL_ADMIN_PERM, | |
10840 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10841 | NL80211_FLAG_NEED_RTNL, | |
10842 | }, | |
1d9d9213 SW |
10843 | { |
10844 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
10845 | .doit = nl80211_set_noack_map, | |
10846 | .policy = nl80211_policy, | |
10847 | .flags = GENL_ADMIN_PERM, | |
10848 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10849 | NL80211_FLAG_NEED_RTNL, | |
10850 | }, | |
98104fde JB |
10851 | { |
10852 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
10853 | .doit = nl80211_start_p2p_device, | |
10854 | .policy = nl80211_policy, | |
10855 | .flags = GENL_ADMIN_PERM, | |
10856 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
10857 | NL80211_FLAG_NEED_RTNL, | |
10858 | }, | |
10859 | { | |
10860 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
10861 | .doit = nl80211_stop_p2p_device, | |
10862 | .policy = nl80211_policy, | |
10863 | .flags = GENL_ADMIN_PERM, | |
10864 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10865 | NL80211_FLAG_NEED_RTNL, | |
10866 | }, | |
f4e583c8 AQ |
10867 | { |
10868 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
10869 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
10870 | .policy = nl80211_policy, |
10871 | .flags = GENL_ADMIN_PERM, | |
10872 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10873 | NL80211_FLAG_NEED_RTNL, | |
10874 | }, | |
10875 | { | |
10876 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
10877 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
10878 | .policy = nl80211_policy, |
10879 | .flags = GENL_ADMIN_PERM, | |
10880 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10881 | NL80211_FLAG_NEED_RTNL, | |
10882 | }, | |
04f39047 SW |
10883 | { |
10884 | .cmd = NL80211_CMD_RADAR_DETECT, | |
10885 | .doit = nl80211_start_radar_detection, | |
10886 | .policy = nl80211_policy, | |
10887 | .flags = GENL_ADMIN_PERM, | |
10888 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10889 | NL80211_FLAG_NEED_RTNL, | |
10890 | }, | |
3713b4e3 JB |
10891 | { |
10892 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
10893 | .doit = nl80211_get_protocol_features, | |
10894 | .policy = nl80211_policy, | |
10895 | }, | |
355199e0 JM |
10896 | { |
10897 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
10898 | .doit = nl80211_update_ft_ies, | |
10899 | .policy = nl80211_policy, | |
10900 | .flags = GENL_ADMIN_PERM, | |
10901 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10902 | NL80211_FLAG_NEED_RTNL, | |
10903 | }, | |
5de17984 AS |
10904 | { |
10905 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
10906 | .doit = nl80211_crit_protocol_start, | |
10907 | .policy = nl80211_policy, | |
10908 | .flags = GENL_ADMIN_PERM, | |
10909 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10910 | NL80211_FLAG_NEED_RTNL, | |
10911 | }, | |
10912 | { | |
10913 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
10914 | .doit = nl80211_crit_protocol_stop, | |
10915 | .policy = nl80211_policy, | |
10916 | .flags = GENL_ADMIN_PERM, | |
10917 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10918 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
10919 | }, |
10920 | { | |
10921 | .cmd = NL80211_CMD_GET_COALESCE, | |
10922 | .doit = nl80211_get_coalesce, | |
10923 | .policy = nl80211_policy, | |
10924 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10925 | NL80211_FLAG_NEED_RTNL, | |
10926 | }, | |
10927 | { | |
10928 | .cmd = NL80211_CMD_SET_COALESCE, | |
10929 | .doit = nl80211_set_coalesce, | |
10930 | .policy = nl80211_policy, | |
10931 | .flags = GENL_ADMIN_PERM, | |
10932 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10933 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
10934 | }, |
10935 | { | |
10936 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
10937 | .doit = nl80211_channel_switch, | |
10938 | .policy = nl80211_policy, | |
10939 | .flags = GENL_ADMIN_PERM, | |
10940 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10941 | NL80211_FLAG_NEED_RTNL, | |
10942 | }, | |
ad7e718c JB |
10943 | { |
10944 | .cmd = NL80211_CMD_VENDOR, | |
10945 | .doit = nl80211_vendor_cmd, | |
10946 | .policy = nl80211_policy, | |
10947 | .flags = GENL_ADMIN_PERM, | |
10948 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10949 | NL80211_FLAG_NEED_RTNL, | |
10950 | }, | |
fa9ffc74 KP |
10951 | { |
10952 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
10953 | .doit = nl80211_set_qos_map, | |
10954 | .policy = nl80211_policy, | |
10955 | .flags = GENL_ADMIN_PERM, | |
10956 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10957 | NL80211_FLAG_NEED_RTNL, | |
10958 | }, | |
960d01ac JB |
10959 | { |
10960 | .cmd = NL80211_CMD_ADD_TX_TS, | |
10961 | .doit = nl80211_add_tx_ts, | |
10962 | .policy = nl80211_policy, | |
10963 | .flags = GENL_ADMIN_PERM, | |
10964 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10965 | NL80211_FLAG_NEED_RTNL, | |
10966 | }, | |
10967 | { | |
10968 | .cmd = NL80211_CMD_DEL_TX_TS, | |
10969 | .doit = nl80211_del_tx_ts, | |
10970 | .policy = nl80211_policy, | |
10971 | .flags = GENL_ADMIN_PERM, | |
10972 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10973 | NL80211_FLAG_NEED_RTNL, | |
10974 | }, | |
1057d35e AN |
10975 | { |
10976 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | |
10977 | .doit = nl80211_tdls_channel_switch, | |
10978 | .policy = nl80211_policy, | |
10979 | .flags = GENL_ADMIN_PERM, | |
10980 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10981 | NL80211_FLAG_NEED_RTNL, | |
10982 | }, | |
10983 | { | |
10984 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | |
10985 | .doit = nl80211_tdls_cancel_channel_switch, | |
10986 | .policy = nl80211_policy, | |
10987 | .flags = GENL_ADMIN_PERM, | |
10988 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10989 | NL80211_FLAG_NEED_RTNL, | |
10990 | }, | |
55682965 | 10991 | }; |
9588bbd5 | 10992 | |
55682965 JB |
10993 | /* notification functions */ |
10994 | ||
3bb20556 JB |
10995 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
10996 | enum nl80211_commands cmd) | |
55682965 JB |
10997 | { |
10998 | struct sk_buff *msg; | |
86e8cf98 | 10999 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 11000 | |
3bb20556 JB |
11001 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
11002 | cmd != NL80211_CMD_DEL_WIPHY); | |
11003 | ||
fd2120ca | 11004 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
11005 | if (!msg) |
11006 | return; | |
11007 | ||
3bb20556 | 11008 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
11009 | nlmsg_free(msg); |
11010 | return; | |
11011 | } | |
11012 | ||
68eb5503 | 11013 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11014 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
11015 | } |
11016 | ||
362a415d JB |
11017 | static int nl80211_add_scan_req(struct sk_buff *msg, |
11018 | struct cfg80211_registered_device *rdev) | |
11019 | { | |
11020 | struct cfg80211_scan_request *req = rdev->scan_req; | |
11021 | struct nlattr *nest; | |
11022 | int i; | |
11023 | ||
11024 | if (WARN_ON(!req)) | |
11025 | return 0; | |
11026 | ||
11027 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
11028 | if (!nest) | |
11029 | goto nla_put_failure; | |
9360ffd1 DM |
11030 | for (i = 0; i < req->n_ssids; i++) { |
11031 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
11032 | goto nla_put_failure; | |
11033 | } | |
362a415d JB |
11034 | nla_nest_end(msg, nest); |
11035 | ||
11036 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
11037 | if (!nest) | |
11038 | goto nla_put_failure; | |
9360ffd1 DM |
11039 | for (i = 0; i < req->n_channels; i++) { |
11040 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
11041 | goto nla_put_failure; | |
11042 | } | |
362a415d JB |
11043 | nla_nest_end(msg, nest); |
11044 | ||
9360ffd1 DM |
11045 | if (req->ie && |
11046 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
11047 | goto nla_put_failure; | |
362a415d | 11048 | |
ae917c9f JB |
11049 | if (req->flags && |
11050 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
11051 | goto nla_put_failure; | |
ed473771 | 11052 | |
362a415d JB |
11053 | return 0; |
11054 | nla_put_failure: | |
11055 | return -ENOBUFS; | |
11056 | } | |
11057 | ||
a538e2d5 JB |
11058 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
11059 | struct cfg80211_registered_device *rdev, | |
fd014284 | 11060 | struct wireless_dev *wdev, |
15e47304 | 11061 | u32 portid, u32 seq, int flags, |
a538e2d5 | 11062 | u32 cmd) |
2a519311 JB |
11063 | { |
11064 | void *hdr; | |
11065 | ||
15e47304 | 11066 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
11067 | if (!hdr) |
11068 | return -1; | |
11069 | ||
9360ffd1 | 11070 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
11071 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11072 | wdev->netdev->ifindex)) || | |
11073 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 11074 | goto nla_put_failure; |
2a519311 | 11075 | |
362a415d JB |
11076 | /* ignore errors and send incomplete event anyway */ |
11077 | nl80211_add_scan_req(msg, rdev); | |
2a519311 | 11078 | |
053c095a JB |
11079 | genlmsg_end(msg, hdr); |
11080 | return 0; | |
2a519311 JB |
11081 | |
11082 | nla_put_failure: | |
11083 | genlmsg_cancel(msg, hdr); | |
11084 | return -EMSGSIZE; | |
11085 | } | |
11086 | ||
807f8a8c LC |
11087 | static int |
11088 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
11089 | struct cfg80211_registered_device *rdev, | |
11090 | struct net_device *netdev, | |
15e47304 | 11091 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
11092 | { |
11093 | void *hdr; | |
11094 | ||
15e47304 | 11095 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
11096 | if (!hdr) |
11097 | return -1; | |
11098 | ||
9360ffd1 DM |
11099 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11100 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
11101 | goto nla_put_failure; | |
807f8a8c | 11102 | |
053c095a JB |
11103 | genlmsg_end(msg, hdr); |
11104 | return 0; | |
807f8a8c LC |
11105 | |
11106 | nla_put_failure: | |
11107 | genlmsg_cancel(msg, hdr); | |
11108 | return -EMSGSIZE; | |
11109 | } | |
11110 | ||
a538e2d5 | 11111 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 11112 | struct wireless_dev *wdev) |
a538e2d5 JB |
11113 | { |
11114 | struct sk_buff *msg; | |
11115 | ||
58050fce | 11116 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
11117 | if (!msg) |
11118 | return; | |
11119 | ||
fd014284 | 11120 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
11121 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
11122 | nlmsg_free(msg); | |
11123 | return; | |
11124 | } | |
11125 | ||
68eb5503 | 11126 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11127 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
11128 | } |
11129 | ||
f9d15d16 JB |
11130 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
11131 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
11132 | { |
11133 | struct sk_buff *msg; | |
11134 | ||
fd2120ca | 11135 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 11136 | if (!msg) |
f9d15d16 | 11137 | return NULL; |
2a519311 | 11138 | |
fd014284 | 11139 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
11140 | aborted ? NL80211_CMD_SCAN_ABORTED : |
11141 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 11142 | nlmsg_free(msg); |
f9d15d16 | 11143 | return NULL; |
2a519311 JB |
11144 | } |
11145 | ||
f9d15d16 | 11146 | return msg; |
2a519311 JB |
11147 | } |
11148 | ||
f9d15d16 JB |
11149 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
11150 | struct sk_buff *msg) | |
2a519311 | 11151 | { |
2a519311 JB |
11152 | if (!msg) |
11153 | return; | |
11154 | ||
68eb5503 | 11155 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11156 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
11157 | } |
11158 | ||
807f8a8c LC |
11159 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
11160 | struct net_device *netdev) | |
11161 | { | |
11162 | struct sk_buff *msg; | |
11163 | ||
11164 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11165 | if (!msg) | |
11166 | return; | |
11167 | ||
11168 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
11169 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
11170 | nlmsg_free(msg); | |
11171 | return; | |
11172 | } | |
11173 | ||
68eb5503 | 11174 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11175 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11176 | } |
11177 | ||
11178 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
11179 | struct net_device *netdev, u32 cmd) | |
11180 | { | |
11181 | struct sk_buff *msg; | |
11182 | ||
58050fce | 11183 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
11184 | if (!msg) |
11185 | return; | |
11186 | ||
11187 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
11188 | nlmsg_free(msg); | |
11189 | return; | |
11190 | } | |
11191 | ||
68eb5503 | 11192 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11193 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11194 | } |
11195 | ||
b0d7aa59 JD |
11196 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
11197 | struct regulatory_request *request) | |
73d54c9e | 11198 | { |
73d54c9e | 11199 | /* Userspace can always count this one always being set */ |
9360ffd1 DM |
11200 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
11201 | goto nla_put_failure; | |
11202 | ||
11203 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
11204 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11205 | NL80211_REGDOM_TYPE_WORLD)) | |
11206 | goto nla_put_failure; | |
11207 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
11208 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11209 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
11210 | goto nla_put_failure; | |
11211 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
11212 | request->intersect) { | |
11213 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11214 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
11215 | goto nla_put_failure; | |
11216 | } else { | |
11217 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11218 | NL80211_REGDOM_TYPE_COUNTRY) || | |
11219 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
11220 | request->alpha2)) | |
11221 | goto nla_put_failure; | |
11222 | } | |
11223 | ||
ad30ca2c AN |
11224 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
11225 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); | |
11226 | ||
11227 | if (wiphy && | |
11228 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | |
11229 | goto nla_put_failure; | |
1bdd716c AN |
11230 | |
11231 | if (wiphy && | |
11232 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | |
11233 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
11234 | goto nla_put_failure; | |
ad30ca2c | 11235 | } |
73d54c9e | 11236 | |
b0d7aa59 JD |
11237 | return true; |
11238 | ||
11239 | nla_put_failure: | |
11240 | return false; | |
11241 | } | |
11242 | ||
11243 | /* | |
11244 | * This can happen on global regulatory changes or device specific settings | |
11245 | * based on custom regulatory domains. | |
11246 | */ | |
11247 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, | |
11248 | struct regulatory_request *request) | |
11249 | { | |
11250 | struct sk_buff *msg; | |
11251 | void *hdr; | |
11252 | ||
11253 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11254 | if (!msg) | |
11255 | return; | |
11256 | ||
11257 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); | |
11258 | if (!hdr) { | |
11259 | nlmsg_free(msg); | |
11260 | return; | |
11261 | } | |
11262 | ||
11263 | if (nl80211_reg_change_event_fill(msg, request) == false) | |
11264 | goto nla_put_failure; | |
11265 | ||
3b7b72ee | 11266 | genlmsg_end(msg, hdr); |
73d54c9e | 11267 | |
bc43b28c | 11268 | rcu_read_lock(); |
68eb5503 | 11269 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11270 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 11271 | rcu_read_unlock(); |
73d54c9e LR |
11272 | |
11273 | return; | |
11274 | ||
11275 | nla_put_failure: | |
11276 | genlmsg_cancel(msg, hdr); | |
11277 | nlmsg_free(msg); | |
11278 | } | |
11279 | ||
6039f6d2 JM |
11280 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
11281 | struct net_device *netdev, | |
11282 | const u8 *buf, size_t len, | |
b0b6aa2c EP |
11283 | enum nl80211_commands cmd, gfp_t gfp, |
11284 | int uapsd_queues) | |
6039f6d2 JM |
11285 | { |
11286 | struct sk_buff *msg; | |
11287 | void *hdr; | |
11288 | ||
e6d6e342 | 11289 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
11290 | if (!msg) |
11291 | return; | |
11292 | ||
11293 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11294 | if (!hdr) { | |
11295 | nlmsg_free(msg); | |
11296 | return; | |
11297 | } | |
11298 | ||
9360ffd1 DM |
11299 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11300 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11301 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
11302 | goto nla_put_failure; | |
6039f6d2 | 11303 | |
b0b6aa2c EP |
11304 | if (uapsd_queues >= 0) { |
11305 | struct nlattr *nla_wmm = | |
11306 | nla_nest_start(msg, NL80211_ATTR_STA_WME); | |
11307 | if (!nla_wmm) | |
11308 | goto nla_put_failure; | |
11309 | ||
11310 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
11311 | uapsd_queues)) | |
11312 | goto nla_put_failure; | |
11313 | ||
11314 | nla_nest_end(msg, nla_wmm); | |
11315 | } | |
11316 | ||
3b7b72ee | 11317 | genlmsg_end(msg, hdr); |
6039f6d2 | 11318 | |
68eb5503 | 11319 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11320 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
11321 | return; |
11322 | ||
11323 | nla_put_failure: | |
11324 | genlmsg_cancel(msg, hdr); | |
11325 | nlmsg_free(msg); | |
11326 | } | |
11327 | ||
11328 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11329 | struct net_device *netdev, const u8 *buf, |
11330 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11331 | { |
11332 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11333 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11334 | } |
11335 | ||
11336 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
11337 | struct net_device *netdev, const u8 *buf, | |
b0b6aa2c | 11338 | size_t len, gfp_t gfp, int uapsd_queues) |
6039f6d2 | 11339 | { |
e6d6e342 | 11340 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
b0b6aa2c | 11341 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
6039f6d2 JM |
11342 | } |
11343 | ||
53b46b84 | 11344 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
11345 | struct net_device *netdev, const u8 *buf, |
11346 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11347 | { |
11348 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11349 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11350 | } |
11351 | ||
53b46b84 JM |
11352 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
11353 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 11354 | size_t len, gfp_t gfp) |
6039f6d2 JM |
11355 | { |
11356 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11357 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
6039f6d2 JM |
11358 | } |
11359 | ||
6ff57cf8 JB |
11360 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
11361 | size_t len) | |
cf4e594e | 11362 | { |
947add36 JB |
11363 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11364 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11365 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
11366 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
11367 | u32 cmd; | |
947add36 | 11368 | |
6ff57cf8 JB |
11369 | if (WARN_ON(len < 2)) |
11370 | return; | |
cf4e594e | 11371 | |
6ff57cf8 JB |
11372 | if (ieee80211_is_deauth(mgmt->frame_control)) |
11373 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
11374 | else | |
11375 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 11376 | |
6ff57cf8 | 11377 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
b0b6aa2c | 11378 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
cf4e594e | 11379 | } |
6ff57cf8 | 11380 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 11381 | |
1b06bb40 LR |
11382 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
11383 | struct net_device *netdev, int cmd, | |
e6d6e342 | 11384 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
11385 | { |
11386 | struct sk_buff *msg; | |
11387 | void *hdr; | |
11388 | ||
e6d6e342 | 11389 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
11390 | if (!msg) |
11391 | return; | |
11392 | ||
11393 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11394 | if (!hdr) { | |
11395 | nlmsg_free(msg); | |
11396 | return; | |
11397 | } | |
11398 | ||
9360ffd1 DM |
11399 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11400 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11401 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
11402 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11403 | goto nla_put_failure; | |
1965c853 | 11404 | |
3b7b72ee | 11405 | genlmsg_end(msg, hdr); |
1965c853 | 11406 | |
68eb5503 | 11407 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11408 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
11409 | return; |
11410 | ||
11411 | nla_put_failure: | |
11412 | genlmsg_cancel(msg, hdr); | |
11413 | nlmsg_free(msg); | |
11414 | } | |
11415 | ||
11416 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11417 | struct net_device *netdev, const u8 *addr, |
11418 | gfp_t gfp) | |
1965c853 JM |
11419 | { |
11420 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 11421 | addr, gfp); |
1965c853 JM |
11422 | } |
11423 | ||
11424 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11425 | struct net_device *netdev, const u8 *addr, |
11426 | gfp_t gfp) | |
1965c853 | 11427 | { |
e6d6e342 JB |
11428 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
11429 | addr, gfp); | |
1965c853 JM |
11430 | } |
11431 | ||
b23aa676 SO |
11432 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
11433 | struct net_device *netdev, const u8 *bssid, | |
11434 | const u8 *req_ie, size_t req_ie_len, | |
11435 | const u8 *resp_ie, size_t resp_ie_len, | |
11436 | u16 status, 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_CONNECT); | |
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 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
11454 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
11455 | (req_ie && | |
11456 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11457 | (resp_ie && | |
11458 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11459 | goto nla_put_failure; | |
b23aa676 | 11460 | |
3b7b72ee | 11461 | genlmsg_end(msg, hdr); |
b23aa676 | 11462 | |
68eb5503 | 11463 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11464 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11465 | return; |
11466 | ||
11467 | nla_put_failure: | |
11468 | genlmsg_cancel(msg, hdr); | |
11469 | nlmsg_free(msg); | |
11470 | ||
11471 | } | |
11472 | ||
11473 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
11474 | struct net_device *netdev, const u8 *bssid, | |
11475 | const u8 *req_ie, size_t req_ie_len, | |
11476 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
11477 | { | |
11478 | struct sk_buff *msg; | |
11479 | void *hdr; | |
11480 | ||
58050fce | 11481 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
11482 | if (!msg) |
11483 | return; | |
11484 | ||
11485 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
11486 | if (!hdr) { | |
11487 | nlmsg_free(msg); | |
11488 | return; | |
11489 | } | |
11490 | ||
9360ffd1 DM |
11491 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11492 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11493 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
11494 | (req_ie && | |
11495 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11496 | (resp_ie && | |
11497 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11498 | goto nla_put_failure; | |
b23aa676 | 11499 | |
3b7b72ee | 11500 | genlmsg_end(msg, hdr); |
b23aa676 | 11501 | |
68eb5503 | 11502 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11503 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11504 | return; |
11505 | ||
11506 | nla_put_failure: | |
11507 | genlmsg_cancel(msg, hdr); | |
11508 | nlmsg_free(msg); | |
11509 | ||
11510 | } | |
11511 | ||
11512 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
11513 | struct net_device *netdev, u16 reason, | |
667503dd | 11514 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
11515 | { |
11516 | struct sk_buff *msg; | |
11517 | void *hdr; | |
11518 | ||
58050fce | 11519 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
11520 | if (!msg) |
11521 | return; | |
11522 | ||
11523 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
11524 | if (!hdr) { | |
11525 | nlmsg_free(msg); | |
11526 | return; | |
11527 | } | |
11528 | ||
9360ffd1 DM |
11529 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11530 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11531 | (from_ap && reason && | |
11532 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
11533 | (from_ap && | |
11534 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
11535 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
11536 | goto nla_put_failure; | |
b23aa676 | 11537 | |
3b7b72ee | 11538 | genlmsg_end(msg, hdr); |
b23aa676 | 11539 | |
68eb5503 | 11540 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11541 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
11542 | return; |
11543 | ||
11544 | nla_put_failure: | |
11545 | genlmsg_cancel(msg, hdr); | |
11546 | nlmsg_free(msg); | |
11547 | ||
11548 | } | |
11549 | ||
04a773ad JB |
11550 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
11551 | struct net_device *netdev, const u8 *bssid, | |
11552 | gfp_t gfp) | |
11553 | { | |
11554 | struct sk_buff *msg; | |
11555 | void *hdr; | |
11556 | ||
fd2120ca | 11557 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
11558 | if (!msg) |
11559 | return; | |
11560 | ||
11561 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
11562 | if (!hdr) { | |
11563 | nlmsg_free(msg); | |
11564 | return; | |
11565 | } | |
11566 | ||
9360ffd1 DM |
11567 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11568 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11569 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
11570 | goto nla_put_failure; | |
04a773ad | 11571 | |
3b7b72ee | 11572 | genlmsg_end(msg, hdr); |
04a773ad | 11573 | |
68eb5503 | 11574 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11575 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
11576 | return; |
11577 | ||
11578 | nla_put_failure: | |
11579 | genlmsg_cancel(msg, hdr); | |
11580 | nlmsg_free(msg); | |
11581 | } | |
11582 | ||
947add36 JB |
11583 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
11584 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 11585 | { |
947add36 | 11586 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 11587 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
11588 | struct sk_buff *msg; |
11589 | void *hdr; | |
11590 | ||
947add36 JB |
11591 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
11592 | return; | |
11593 | ||
11594 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
11595 | ||
c93b5e71 JC |
11596 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11597 | if (!msg) | |
11598 | return; | |
11599 | ||
11600 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
11601 | if (!hdr) { | |
11602 | nlmsg_free(msg); | |
11603 | return; | |
11604 | } | |
11605 | ||
9360ffd1 | 11606 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
11607 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
11608 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
11609 | (ie_len && ie && |
11610 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
11611 | goto nla_put_failure; | |
c93b5e71 | 11612 | |
3b7b72ee | 11613 | genlmsg_end(msg, hdr); |
c93b5e71 | 11614 | |
68eb5503 | 11615 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11616 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
11617 | return; |
11618 | ||
11619 | nla_put_failure: | |
11620 | genlmsg_cancel(msg, hdr); | |
11621 | nlmsg_free(msg); | |
11622 | } | |
947add36 | 11623 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 11624 | |
a3b8b056 JM |
11625 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
11626 | struct net_device *netdev, const u8 *addr, | |
11627 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 11628 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
11629 | { |
11630 | struct sk_buff *msg; | |
11631 | void *hdr; | |
11632 | ||
e6d6e342 | 11633 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
11634 | if (!msg) |
11635 | return; | |
11636 | ||
11637 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
11638 | if (!hdr) { | |
11639 | nlmsg_free(msg); | |
11640 | return; | |
11641 | } | |
11642 | ||
9360ffd1 DM |
11643 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11644 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11645 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
11646 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
11647 | (key_id != -1 && | |
11648 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
11649 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
11650 | goto nla_put_failure; | |
a3b8b056 | 11651 | |
3b7b72ee | 11652 | genlmsg_end(msg, hdr); |
a3b8b056 | 11653 | |
68eb5503 | 11654 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11655 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
11656 | return; |
11657 | ||
11658 | nla_put_failure: | |
11659 | genlmsg_cancel(msg, hdr); | |
11660 | nlmsg_free(msg); | |
11661 | } | |
11662 | ||
6bad8766 LR |
11663 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
11664 | struct ieee80211_channel *channel_before, | |
11665 | struct ieee80211_channel *channel_after) | |
11666 | { | |
11667 | struct sk_buff *msg; | |
11668 | void *hdr; | |
11669 | struct nlattr *nl_freq; | |
11670 | ||
fd2120ca | 11671 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
11672 | if (!msg) |
11673 | return; | |
11674 | ||
11675 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
11676 | if (!hdr) { | |
11677 | nlmsg_free(msg); | |
11678 | return; | |
11679 | } | |
11680 | ||
11681 | /* | |
11682 | * Since we are applying the beacon hint to a wiphy we know its | |
11683 | * wiphy_idx is valid | |
11684 | */ | |
9360ffd1 DM |
11685 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
11686 | goto nla_put_failure; | |
6bad8766 LR |
11687 | |
11688 | /* Before */ | |
11689 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
11690 | if (!nl_freq) | |
11691 | goto nla_put_failure; | |
cdc89b97 | 11692 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
11693 | goto nla_put_failure; |
11694 | nla_nest_end(msg, nl_freq); | |
11695 | ||
11696 | /* After */ | |
11697 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
11698 | if (!nl_freq) | |
11699 | goto nla_put_failure; | |
cdc89b97 | 11700 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
11701 | goto nla_put_failure; |
11702 | nla_nest_end(msg, nl_freq); | |
11703 | ||
3b7b72ee | 11704 | genlmsg_end(msg, hdr); |
6bad8766 | 11705 | |
463d0183 | 11706 | rcu_read_lock(); |
68eb5503 | 11707 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11708 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 11709 | rcu_read_unlock(); |
6bad8766 LR |
11710 | |
11711 | return; | |
11712 | ||
11713 | nla_put_failure: | |
11714 | genlmsg_cancel(msg, hdr); | |
11715 | nlmsg_free(msg); | |
11716 | } | |
11717 | ||
9588bbd5 JM |
11718 | static void nl80211_send_remain_on_chan_event( |
11719 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 11720 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 11721 | struct ieee80211_channel *chan, |
9588bbd5 JM |
11722 | unsigned int duration, gfp_t gfp) |
11723 | { | |
11724 | struct sk_buff *msg; | |
11725 | void *hdr; | |
11726 | ||
11727 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11728 | if (!msg) | |
11729 | return; | |
11730 | ||
11731 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11732 | if (!hdr) { | |
11733 | nlmsg_free(msg); | |
11734 | return; | |
11735 | } | |
11736 | ||
9360ffd1 | 11737 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11738 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11739 | wdev->netdev->ifindex)) || | |
00f53350 | 11740 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 11741 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
11742 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
11743 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
11744 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
11745 | goto nla_put_failure; | |
9588bbd5 | 11746 | |
9360ffd1 DM |
11747 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
11748 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
11749 | goto nla_put_failure; | |
9588bbd5 | 11750 | |
3b7b72ee | 11751 | genlmsg_end(msg, hdr); |
9588bbd5 | 11752 | |
68eb5503 | 11753 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11754 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
11755 | return; |
11756 | ||
11757 | nla_put_failure: | |
11758 | genlmsg_cancel(msg, hdr); | |
11759 | nlmsg_free(msg); | |
11760 | } | |
11761 | ||
947add36 JB |
11762 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
11763 | struct ieee80211_channel *chan, | |
11764 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 11765 | { |
947add36 | 11766 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11767 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11768 | |
11769 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 11770 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 11771 | rdev, wdev, cookie, chan, |
42d97a59 | 11772 | duration, gfp); |
9588bbd5 | 11773 | } |
947add36 | 11774 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 11775 | |
947add36 JB |
11776 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
11777 | struct ieee80211_channel *chan, | |
11778 | gfp_t gfp) | |
9588bbd5 | 11779 | { |
947add36 | 11780 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11781 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11782 | |
11783 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 11784 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 11785 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 11786 | } |
947add36 | 11787 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 11788 | |
947add36 JB |
11789 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
11790 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 11791 | { |
947add36 | 11792 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11793 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
11794 | struct sk_buff *msg; |
11795 | ||
947add36 JB |
11796 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
11797 | ||
58050fce | 11798 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
11799 | if (!msg) |
11800 | return; | |
11801 | ||
cf5ead82 | 11802 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
66266b3a | 11803 | rdev, dev, mac_addr, sinfo) < 0) { |
98b62183 JB |
11804 | nlmsg_free(msg); |
11805 | return; | |
11806 | } | |
11807 | ||
68eb5503 | 11808 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11809 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 11810 | } |
947add36 | 11811 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 11812 | |
cf5ead82 JB |
11813 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
11814 | struct station_info *sinfo, gfp_t gfp) | |
ec15e68b | 11815 | { |
947add36 | 11816 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11817 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b | 11818 | struct sk_buff *msg; |
cf5ead82 JB |
11819 | struct station_info empty_sinfo = {}; |
11820 | ||
11821 | if (!sinfo) | |
11822 | sinfo = &empty_sinfo; | |
ec15e68b | 11823 | |
947add36 JB |
11824 | trace_cfg80211_del_sta(dev, mac_addr); |
11825 | ||
58050fce | 11826 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
11827 | if (!msg) |
11828 | return; | |
11829 | ||
cf5ead82 | 11830 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
57007121 | 11831 | rdev, dev, mac_addr, sinfo) < 0) { |
ec15e68b JM |
11832 | nlmsg_free(msg); |
11833 | return; | |
11834 | } | |
11835 | ||
68eb5503 | 11836 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11837 | NL80211_MCGRP_MLME, gfp); |
ec15e68b | 11838 | } |
cf5ead82 | 11839 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
ec15e68b | 11840 | |
947add36 JB |
11841 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
11842 | enum nl80211_connect_failed_reason reason, | |
11843 | gfp_t gfp) | |
ed44a951 | 11844 | { |
947add36 | 11845 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11846 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
11847 | struct sk_buff *msg; |
11848 | void *hdr; | |
11849 | ||
11850 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
11851 | if (!msg) | |
11852 | return; | |
11853 | ||
11854 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
11855 | if (!hdr) { | |
11856 | nlmsg_free(msg); | |
11857 | return; | |
11858 | } | |
11859 | ||
11860 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11861 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
11862 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
11863 | goto nla_put_failure; | |
11864 | ||
11865 | genlmsg_end(msg, hdr); | |
11866 | ||
68eb5503 | 11867 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11868 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
11869 | return; |
11870 | ||
11871 | nla_put_failure: | |
11872 | genlmsg_cancel(msg, hdr); | |
11873 | nlmsg_free(msg); | |
11874 | } | |
947add36 | 11875 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 11876 | |
b92ab5d8 JB |
11877 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
11878 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
11879 | { |
11880 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 11881 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
11882 | struct sk_buff *msg; |
11883 | void *hdr; | |
15e47304 | 11884 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 11885 | |
15e47304 | 11886 | if (!nlportid) |
28946da7 JB |
11887 | return false; |
11888 | ||
11889 | msg = nlmsg_new(100, gfp); | |
11890 | if (!msg) | |
11891 | return true; | |
11892 | ||
b92ab5d8 | 11893 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
11894 | if (!hdr) { |
11895 | nlmsg_free(msg); | |
11896 | return true; | |
11897 | } | |
11898 | ||
9360ffd1 DM |
11899 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11900 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11901 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11902 | goto nla_put_failure; | |
28946da7 | 11903 | |
9c90a9f6 | 11904 | genlmsg_end(msg, hdr); |
15e47304 | 11905 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
11906 | return true; |
11907 | ||
11908 | nla_put_failure: | |
11909 | genlmsg_cancel(msg, hdr); | |
11910 | nlmsg_free(msg); | |
11911 | return true; | |
11912 | } | |
11913 | ||
947add36 JB |
11914 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
11915 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11916 | { |
947add36 JB |
11917 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11918 | bool ret; | |
11919 | ||
11920 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
11921 | ||
11922 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11923 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
11924 | trace_cfg80211_return_bool(false); | |
11925 | return false; | |
11926 | } | |
11927 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
11928 | addr, gfp); | |
11929 | trace_cfg80211_return_bool(ret); | |
11930 | return ret; | |
b92ab5d8 | 11931 | } |
947add36 | 11932 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 11933 | |
947add36 JB |
11934 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
11935 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11936 | { |
947add36 JB |
11937 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11938 | bool ret; | |
11939 | ||
11940 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
11941 | ||
11942 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11943 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
11944 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
11945 | trace_cfg80211_return_bool(false); | |
11946 | return false; | |
11947 | } | |
11948 | ret = __nl80211_unexpected_frame(dev, | |
11949 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
11950 | addr, gfp); | |
11951 | trace_cfg80211_return_bool(ret); | |
11952 | return ret; | |
b92ab5d8 | 11953 | } |
947add36 | 11954 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 11955 | |
2e161f78 | 11956 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 11957 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 11958 | int freq, int sig_dbm, |
19504cf5 | 11959 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 11960 | { |
71bbc994 | 11961 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11962 | struct sk_buff *msg; |
11963 | void *hdr; | |
026331c4 JM |
11964 | |
11965 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11966 | if (!msg) | |
11967 | return -ENOMEM; | |
11968 | ||
2e161f78 | 11969 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
11970 | if (!hdr) { |
11971 | nlmsg_free(msg); | |
11972 | return -ENOMEM; | |
11973 | } | |
11974 | ||
9360ffd1 | 11975 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11976 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11977 | netdev->ifindex)) || | |
a838490b | 11978 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11979 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
11980 | (sig_dbm && | |
11981 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
11982 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11983 | (flags && | |
11984 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 11985 | goto nla_put_failure; |
026331c4 | 11986 | |
3b7b72ee | 11987 | genlmsg_end(msg, hdr); |
026331c4 | 11988 | |
15e47304 | 11989 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
11990 | |
11991 | nla_put_failure: | |
11992 | genlmsg_cancel(msg, hdr); | |
11993 | nlmsg_free(msg); | |
11994 | return -ENOBUFS; | |
11995 | } | |
11996 | ||
947add36 JB |
11997 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
11998 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 11999 | { |
947add36 | 12000 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 12001 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 12002 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
12003 | struct sk_buff *msg; |
12004 | void *hdr; | |
12005 | ||
947add36 JB |
12006 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
12007 | ||
026331c4 JM |
12008 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
12009 | if (!msg) | |
12010 | return; | |
12011 | ||
2e161f78 | 12012 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
12013 | if (!hdr) { |
12014 | nlmsg_free(msg); | |
12015 | return; | |
12016 | } | |
12017 | ||
9360ffd1 | 12018 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
12019 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
12020 | netdev->ifindex)) || | |
a838490b | 12021 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
12022 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
12023 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
12024 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
12025 | goto nla_put_failure; | |
026331c4 | 12026 | |
3b7b72ee | 12027 | genlmsg_end(msg, hdr); |
026331c4 | 12028 | |
68eb5503 | 12029 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12030 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
12031 | return; |
12032 | ||
12033 | nla_put_failure: | |
12034 | genlmsg_cancel(msg, hdr); | |
12035 | nlmsg_free(msg); | |
12036 | } | |
947add36 | 12037 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 12038 | |
5b97f49d JB |
12039 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
12040 | const char *mac, gfp_t gfp) | |
d6dc1a38 | 12041 | { |
947add36 | 12042 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5b97f49d JB |
12043 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
12044 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12045 | void **cb; | |
947add36 | 12046 | |
d6dc1a38 | 12047 | if (!msg) |
5b97f49d | 12048 | return NULL; |
d6dc1a38 | 12049 | |
5b97f49d JB |
12050 | cb = (void **)msg->cb; |
12051 | ||
12052 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
12053 | if (!cb[0]) { | |
d6dc1a38 | 12054 | nlmsg_free(msg); |
5b97f49d | 12055 | return NULL; |
d6dc1a38 JO |
12056 | } |
12057 | ||
9360ffd1 | 12058 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 12059 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 12060 | goto nla_put_failure; |
d6dc1a38 | 12061 | |
5b97f49d | 12062 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
d6dc1a38 JO |
12063 | goto nla_put_failure; |
12064 | ||
5b97f49d JB |
12065 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
12066 | if (!cb[1]) | |
9360ffd1 | 12067 | goto nla_put_failure; |
d6dc1a38 | 12068 | |
5b97f49d | 12069 | cb[2] = rdev; |
d6dc1a38 | 12070 | |
5b97f49d JB |
12071 | return msg; |
12072 | nla_put_failure: | |
12073 | nlmsg_free(msg); | |
12074 | return NULL; | |
12075 | } | |
12076 | ||
12077 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) | |
12078 | { | |
12079 | void **cb = (void **)msg->cb; | |
12080 | struct cfg80211_registered_device *rdev = cb[2]; | |
12081 | ||
12082 | nla_nest_end(msg, cb[1]); | |
12083 | genlmsg_end(msg, cb[0]); | |
12084 | ||
12085 | memset(msg->cb, 0, sizeof(msg->cb)); | |
d6dc1a38 | 12086 | |
68eb5503 | 12087 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12088 | NL80211_MCGRP_MLME, gfp); |
5b97f49d JB |
12089 | } |
12090 | ||
12091 | void cfg80211_cqm_rssi_notify(struct net_device *dev, | |
12092 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
12093 | gfp_t gfp) | |
12094 | { | |
12095 | struct sk_buff *msg; | |
12096 | ||
12097 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); | |
12098 | ||
98f03342 JB |
12099 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
12100 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) | |
12101 | return; | |
12102 | ||
5b97f49d JB |
12103 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
12104 | if (!msg) | |
12105 | return; | |
12106 | ||
12107 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
12108 | rssi_event)) | |
12109 | goto nla_put_failure; | |
12110 | ||
12111 | cfg80211_send_cqm(msg, gfp); | |
12112 | ||
d6dc1a38 JO |
12113 | return; |
12114 | ||
12115 | nla_put_failure: | |
d6dc1a38 JO |
12116 | nlmsg_free(msg); |
12117 | } | |
947add36 | 12118 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 12119 | |
5b97f49d JB |
12120 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
12121 | const u8 *peer, u32 num_packets, | |
12122 | u32 rate, u32 intvl, gfp_t gfp) | |
12123 | { | |
12124 | struct sk_buff *msg; | |
12125 | ||
12126 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12127 | if (!msg) | |
12128 | return; | |
12129 | ||
12130 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
12131 | goto nla_put_failure; | |
12132 | ||
12133 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
12134 | goto nla_put_failure; | |
12135 | ||
12136 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
12137 | goto nla_put_failure; | |
12138 | ||
12139 | cfg80211_send_cqm(msg, gfp); | |
12140 | return; | |
12141 | ||
12142 | nla_put_failure: | |
12143 | nlmsg_free(msg); | |
12144 | } | |
12145 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); | |
12146 | ||
12147 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, | |
12148 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
12149 | { | |
12150 | struct sk_buff *msg; | |
12151 | ||
12152 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); | |
12153 | ||
12154 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12155 | if (!msg) | |
12156 | return; | |
12157 | ||
12158 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) | |
12159 | goto nla_put_failure; | |
12160 | ||
12161 | cfg80211_send_cqm(msg, gfp); | |
12162 | return; | |
12163 | ||
12164 | nla_put_failure: | |
12165 | nlmsg_free(msg); | |
12166 | } | |
12167 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); | |
12168 | ||
98f03342 JB |
12169 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
12170 | { | |
12171 | struct sk_buff *msg; | |
12172 | ||
12173 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); | |
12174 | if (!msg) | |
12175 | return; | |
12176 | ||
12177 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) | |
12178 | goto nla_put_failure; | |
12179 | ||
12180 | cfg80211_send_cqm(msg, gfp); | |
12181 | return; | |
12182 | ||
12183 | nla_put_failure: | |
12184 | nlmsg_free(msg); | |
12185 | } | |
12186 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); | |
12187 | ||
947add36 JB |
12188 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
12189 | struct net_device *netdev, const u8 *bssid, | |
12190 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
12191 | { |
12192 | struct sk_buff *msg; | |
12193 | struct nlattr *rekey_attr; | |
12194 | void *hdr; | |
12195 | ||
58050fce | 12196 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
12197 | if (!msg) |
12198 | return; | |
12199 | ||
12200 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
12201 | if (!hdr) { | |
12202 | nlmsg_free(msg); | |
12203 | return; | |
12204 | } | |
12205 | ||
9360ffd1 DM |
12206 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12207 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12208 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
12209 | goto nla_put_failure; | |
e5497d76 JB |
12210 | |
12211 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
12212 | if (!rekey_attr) | |
12213 | goto nla_put_failure; | |
12214 | ||
9360ffd1 DM |
12215 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
12216 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
12217 | goto nla_put_failure; | |
e5497d76 JB |
12218 | |
12219 | nla_nest_end(msg, rekey_attr); | |
12220 | ||
3b7b72ee | 12221 | genlmsg_end(msg, hdr); |
e5497d76 | 12222 | |
68eb5503 | 12223 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12224 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
12225 | return; |
12226 | ||
12227 | nla_put_failure: | |
12228 | genlmsg_cancel(msg, hdr); | |
12229 | nlmsg_free(msg); | |
12230 | } | |
12231 | ||
947add36 JB |
12232 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
12233 | const u8 *replay_ctr, gfp_t gfp) | |
12234 | { | |
12235 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12236 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12237 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12238 | |
12239 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
12240 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
12241 | } | |
12242 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
12243 | ||
12244 | static void | |
12245 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
12246 | struct net_device *netdev, int index, | |
12247 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
12248 | { |
12249 | struct sk_buff *msg; | |
12250 | struct nlattr *attr; | |
12251 | void *hdr; | |
12252 | ||
58050fce | 12253 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
12254 | if (!msg) |
12255 | return; | |
12256 | ||
12257 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
12258 | if (!hdr) { | |
12259 | nlmsg_free(msg); | |
12260 | return; | |
12261 | } | |
12262 | ||
9360ffd1 DM |
12263 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12264 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
12265 | goto nla_put_failure; | |
c9df56b4 JM |
12266 | |
12267 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
12268 | if (!attr) | |
12269 | goto nla_put_failure; | |
12270 | ||
9360ffd1 DM |
12271 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
12272 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
12273 | (preauth && | |
12274 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
12275 | goto nla_put_failure; | |
c9df56b4 JM |
12276 | |
12277 | nla_nest_end(msg, attr); | |
12278 | ||
3b7b72ee | 12279 | genlmsg_end(msg, hdr); |
c9df56b4 | 12280 | |
68eb5503 | 12281 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12282 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
12283 | return; |
12284 | ||
12285 | nla_put_failure: | |
12286 | genlmsg_cancel(msg, hdr); | |
12287 | nlmsg_free(msg); | |
12288 | } | |
12289 | ||
947add36 JB |
12290 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
12291 | const u8 *bssid, bool preauth, gfp_t gfp) | |
12292 | { | |
12293 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12294 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12295 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12296 | |
12297 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
12298 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
12299 | } | |
12300 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
12301 | ||
12302 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
12303 | struct net_device *netdev, | |
12304 | struct cfg80211_chan_def *chandef, | |
f8d7552e LC |
12305 | gfp_t gfp, |
12306 | enum nl80211_commands notif, | |
12307 | u8 count) | |
5314526b TP |
12308 | { |
12309 | struct sk_buff *msg; | |
12310 | void *hdr; | |
12311 | ||
58050fce | 12312 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
12313 | if (!msg) |
12314 | return; | |
12315 | ||
f8d7552e | 12316 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
5314526b TP |
12317 | if (!hdr) { |
12318 | nlmsg_free(msg); | |
12319 | return; | |
12320 | } | |
12321 | ||
683b6d3b JB |
12322 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
12323 | goto nla_put_failure; | |
12324 | ||
12325 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 12326 | goto nla_put_failure; |
5314526b | 12327 | |
f8d7552e LC |
12328 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
12329 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) | |
12330 | goto nla_put_failure; | |
12331 | ||
5314526b TP |
12332 | genlmsg_end(msg, hdr); |
12333 | ||
68eb5503 | 12334 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12335 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
12336 | return; |
12337 | ||
12338 | nla_put_failure: | |
12339 | genlmsg_cancel(msg, hdr); | |
12340 | nlmsg_free(msg); | |
12341 | } | |
12342 | ||
947add36 JB |
12343 | void cfg80211_ch_switch_notify(struct net_device *dev, |
12344 | struct cfg80211_chan_def *chandef) | |
84f10708 | 12345 | { |
947add36 JB |
12346 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
12347 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12348 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 12349 | |
e487eaeb | 12350 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 12351 | |
e487eaeb | 12352 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 | 12353 | |
9e0e2961 | 12354 | wdev->chandef = *chandef; |
96f55f12 | 12355 | wdev->preset_chandef = *chandef; |
f8d7552e LC |
12356 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
12357 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); | |
947add36 JB |
12358 | } |
12359 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
12360 | ||
f8d7552e LC |
12361 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
12362 | struct cfg80211_chan_def *chandef, | |
12363 | u8 count) | |
12364 | { | |
12365 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12366 | struct wiphy *wiphy = wdev->wiphy; | |
12367 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
12368 | ||
12369 | trace_cfg80211_ch_switch_started_notify(dev, chandef); | |
12370 | ||
12371 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | |
12372 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); | |
12373 | } | |
12374 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | |
12375 | ||
04f39047 SW |
12376 | void |
12377 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 12378 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
12379 | enum nl80211_radar_event event, |
12380 | struct net_device *netdev, gfp_t gfp) | |
12381 | { | |
12382 | struct sk_buff *msg; | |
12383 | void *hdr; | |
12384 | ||
12385 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12386 | if (!msg) | |
12387 | return; | |
12388 | ||
12389 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
12390 | if (!hdr) { | |
12391 | nlmsg_free(msg); | |
12392 | return; | |
12393 | } | |
12394 | ||
12395 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
12396 | goto nla_put_failure; | |
12397 | ||
12398 | /* NOP and radar events don't need a netdev parameter */ | |
12399 | if (netdev) { | |
12400 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
12401 | ||
12402 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12403 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12404 | goto nla_put_failure; | |
12405 | } | |
12406 | ||
12407 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
12408 | goto nla_put_failure; | |
12409 | ||
12410 | if (nl80211_send_chandef(msg, chandef)) | |
12411 | goto nla_put_failure; | |
12412 | ||
9c90a9f6 | 12413 | genlmsg_end(msg, hdr); |
04f39047 | 12414 | |
68eb5503 | 12415 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12416 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
12417 | return; |
12418 | ||
12419 | nla_put_failure: | |
12420 | genlmsg_cancel(msg, hdr); | |
12421 | nlmsg_free(msg); | |
12422 | } | |
12423 | ||
7f6cf311 JB |
12424 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
12425 | u64 cookie, bool acked, gfp_t gfp) | |
12426 | { | |
12427 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12428 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
12429 | struct sk_buff *msg; |
12430 | void *hdr; | |
7f6cf311 | 12431 | |
4ee3e063 BL |
12432 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
12433 | ||
58050fce | 12434 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 12435 | |
7f6cf311 JB |
12436 | if (!msg) |
12437 | return; | |
12438 | ||
12439 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
12440 | if (!hdr) { | |
12441 | nlmsg_free(msg); | |
12442 | return; | |
12443 | } | |
12444 | ||
9360ffd1 DM |
12445 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12446 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12447 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
12448 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
12449 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
12450 | goto nla_put_failure; | |
7f6cf311 | 12451 | |
9c90a9f6 | 12452 | genlmsg_end(msg, hdr); |
7f6cf311 | 12453 | |
68eb5503 | 12454 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12455 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
12456 | return; |
12457 | ||
12458 | nla_put_failure: | |
12459 | genlmsg_cancel(msg, hdr); | |
12460 | nlmsg_free(msg); | |
12461 | } | |
12462 | EXPORT_SYMBOL(cfg80211_probe_status); | |
12463 | ||
5e760230 JB |
12464 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
12465 | const u8 *frame, size_t len, | |
37c73b5f | 12466 | int freq, int sig_dbm) |
5e760230 | 12467 | { |
f26cbf40 | 12468 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
12469 | struct sk_buff *msg; |
12470 | void *hdr; | |
37c73b5f | 12471 | struct cfg80211_beacon_registration *reg; |
5e760230 | 12472 | |
4ee3e063 BL |
12473 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
12474 | ||
37c73b5f BG |
12475 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12476 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
12477 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
12478 | if (!msg) { | |
12479 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
12480 | return; | |
12481 | } | |
5e760230 | 12482 | |
37c73b5f BG |
12483 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
12484 | if (!hdr) | |
12485 | goto nla_put_failure; | |
5e760230 | 12486 | |
37c73b5f BG |
12487 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12488 | (freq && | |
12489 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
12490 | (sig_dbm && | |
12491 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
12492 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
12493 | goto nla_put_failure; | |
5e760230 | 12494 | |
37c73b5f | 12495 | genlmsg_end(msg, hdr); |
5e760230 | 12496 | |
37c73b5f BG |
12497 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
12498 | } | |
12499 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
12500 | return; |
12501 | ||
12502 | nla_put_failure: | |
37c73b5f BG |
12503 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
12504 | if (hdr) | |
12505 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
12506 | nlmsg_free(msg); |
12507 | } | |
12508 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
12509 | ||
cd8f7cb4 | 12510 | #ifdef CONFIG_PM |
8cd4d456 LC |
12511 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
12512 | struct cfg80211_wowlan_wakeup *wakeup) | |
12513 | { | |
12514 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | |
12515 | struct nlattr *nl_results, *nl_match, *nl_freqs; | |
12516 | int i, j; | |
12517 | ||
12518 | nl_results = nla_nest_start( | |
12519 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | |
12520 | if (!nl_results) | |
12521 | return -EMSGSIZE; | |
12522 | ||
12523 | for (i = 0; i < nd->n_matches; i++) { | |
12524 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | |
12525 | ||
12526 | nl_match = nla_nest_start(msg, i); | |
12527 | if (!nl_match) | |
12528 | break; | |
12529 | ||
12530 | /* The SSID attribute is optional in nl80211, but for | |
12531 | * simplicity reasons it's always present in the | |
12532 | * cfg80211 structure. If a driver can't pass the | |
12533 | * SSID, that needs to be changed. A zero length SSID | |
12534 | * is still a valid SSID (wildcard), so it cannot be | |
12535 | * used for this purpose. | |
12536 | */ | |
12537 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | |
12538 | match->ssid.ssid)) { | |
12539 | nla_nest_cancel(msg, nl_match); | |
12540 | goto out; | |
12541 | } | |
12542 | ||
12543 | if (match->n_channels) { | |
12544 | nl_freqs = nla_nest_start( | |
12545 | msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
12546 | if (!nl_freqs) { | |
12547 | nla_nest_cancel(msg, nl_match); | |
12548 | goto out; | |
12549 | } | |
12550 | ||
12551 | for (j = 0; j < match->n_channels; j++) { | |
12552 | if (nla_put_u32(msg, | |
12553 | NL80211_ATTR_WIPHY_FREQ, | |
12554 | match->channels[j])) { | |
12555 | nla_nest_cancel(msg, nl_freqs); | |
12556 | nla_nest_cancel(msg, nl_match); | |
12557 | goto out; | |
12558 | } | |
12559 | } | |
12560 | ||
12561 | nla_nest_end(msg, nl_freqs); | |
12562 | } | |
12563 | ||
12564 | nla_nest_end(msg, nl_match); | |
12565 | } | |
12566 | ||
12567 | out: | |
12568 | nla_nest_end(msg, nl_results); | |
12569 | return 0; | |
12570 | } | |
12571 | ||
cd8f7cb4 JB |
12572 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
12573 | struct cfg80211_wowlan_wakeup *wakeup, | |
12574 | gfp_t gfp) | |
12575 | { | |
f26cbf40 | 12576 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
12577 | struct sk_buff *msg; |
12578 | void *hdr; | |
9c90a9f6 | 12579 | int size = 200; |
cd8f7cb4 JB |
12580 | |
12581 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
12582 | ||
12583 | if (wakeup) | |
12584 | size += wakeup->packet_present_len; | |
12585 | ||
12586 | msg = nlmsg_new(size, gfp); | |
12587 | if (!msg) | |
12588 | return; | |
12589 | ||
12590 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
12591 | if (!hdr) | |
12592 | goto free_msg; | |
12593 | ||
12594 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12595 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12596 | goto free_msg; | |
12597 | ||
12598 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
12599 | wdev->netdev->ifindex)) | |
12600 | goto free_msg; | |
12601 | ||
12602 | if (wakeup) { | |
12603 | struct nlattr *reasons; | |
12604 | ||
12605 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
12606 | if (!reasons) |
12607 | goto free_msg; | |
cd8f7cb4 JB |
12608 | |
12609 | if (wakeup->disconnect && | |
12610 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
12611 | goto free_msg; | |
12612 | if (wakeup->magic_pkt && | |
12613 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
12614 | goto free_msg; | |
12615 | if (wakeup->gtk_rekey_failure && | |
12616 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
12617 | goto free_msg; | |
12618 | if (wakeup->eap_identity_req && | |
12619 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
12620 | goto free_msg; | |
12621 | if (wakeup->four_way_handshake && | |
12622 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
12623 | goto free_msg; | |
12624 | if (wakeup->rfkill_release && | |
12625 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
12626 | goto free_msg; | |
12627 | ||
12628 | if (wakeup->pattern_idx >= 0 && | |
12629 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
12630 | wakeup->pattern_idx)) | |
12631 | goto free_msg; | |
12632 | ||
ae917c9f JB |
12633 | if (wakeup->tcp_match && |
12634 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
12635 | goto free_msg; | |
2a0e047e | 12636 | |
ae917c9f JB |
12637 | if (wakeup->tcp_connlost && |
12638 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
12639 | goto free_msg; | |
2a0e047e | 12640 | |
ae917c9f JB |
12641 | if (wakeup->tcp_nomoretokens && |
12642 | nla_put_flag(msg, | |
12643 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
12644 | goto free_msg; | |
2a0e047e | 12645 | |
cd8f7cb4 JB |
12646 | if (wakeup->packet) { |
12647 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
12648 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
12649 | ||
12650 | if (!wakeup->packet_80211) { | |
12651 | pkt_attr = | |
12652 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
12653 | len_attr = | |
12654 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
12655 | } | |
12656 | ||
12657 | if (wakeup->packet_len && | |
12658 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
12659 | goto free_msg; | |
12660 | ||
12661 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
12662 | wakeup->packet)) | |
12663 | goto free_msg; | |
12664 | } | |
12665 | ||
8cd4d456 LC |
12666 | if (wakeup->net_detect && |
12667 | cfg80211_net_detect_results(msg, wakeup)) | |
12668 | goto free_msg; | |
12669 | ||
cd8f7cb4 JB |
12670 | nla_nest_end(msg, reasons); |
12671 | } | |
12672 | ||
9c90a9f6 | 12673 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 12674 | |
68eb5503 | 12675 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12676 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
12677 | return; |
12678 | ||
12679 | free_msg: | |
12680 | nlmsg_free(msg); | |
12681 | } | |
12682 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
12683 | #endif | |
12684 | ||
3475b094 JM |
12685 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
12686 | enum nl80211_tdls_operation oper, | |
12687 | u16 reason_code, gfp_t gfp) | |
12688 | { | |
12689 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12690 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
12691 | struct sk_buff *msg; |
12692 | void *hdr; | |
3475b094 JM |
12693 | |
12694 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
12695 | reason_code); | |
12696 | ||
12697 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12698 | if (!msg) | |
12699 | return; | |
12700 | ||
12701 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
12702 | if (!hdr) { | |
12703 | nlmsg_free(msg); | |
12704 | return; | |
12705 | } | |
12706 | ||
12707 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12708 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12709 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
12710 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
12711 | (reason_code > 0 && | |
12712 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
12713 | goto nla_put_failure; | |
12714 | ||
9c90a9f6 | 12715 | genlmsg_end(msg, hdr); |
3475b094 | 12716 | |
68eb5503 | 12717 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12718 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
12719 | return; |
12720 | ||
12721 | nla_put_failure: | |
12722 | genlmsg_cancel(msg, hdr); | |
12723 | nlmsg_free(msg); | |
12724 | } | |
12725 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
12726 | ||
026331c4 JM |
12727 | static int nl80211_netlink_notify(struct notifier_block * nb, |
12728 | unsigned long state, | |
12729 | void *_notify) | |
12730 | { | |
12731 | struct netlink_notify *notify = _notify; | |
12732 | struct cfg80211_registered_device *rdev; | |
12733 | struct wireless_dev *wdev; | |
37c73b5f | 12734 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
12735 | |
12736 | if (state != NETLINK_URELEASE) | |
12737 | return NOTIFY_DONE; | |
12738 | ||
12739 | rcu_read_lock(); | |
12740 | ||
5e760230 | 12741 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
78f22b6a | 12742 | bool schedule_destroy_work = false; |
93a1e86c JR |
12743 | bool schedule_scan_stop = false; |
12744 | struct cfg80211_sched_scan_request *sched_scan_req = | |
12745 | rcu_dereference(rdev->sched_scan_req); | |
12746 | ||
12747 | if (sched_scan_req && notify->portid && | |
12748 | sched_scan_req->owner_nlportid == notify->portid) | |
12749 | schedule_scan_stop = true; | |
78f22b6a JB |
12750 | |
12751 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { | |
15e47304 | 12752 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 12753 | |
78f22b6a JB |
12754 | if (wdev->owner_nlportid == notify->portid) |
12755 | schedule_destroy_work = true; | |
12756 | } | |
12757 | ||
37c73b5f BG |
12758 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12759 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
12760 | list) { | |
12761 | if (reg->nlportid == notify->portid) { | |
12762 | list_del(®->list); | |
12763 | kfree(reg); | |
12764 | break; | |
12765 | } | |
12766 | } | |
12767 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
78f22b6a JB |
12768 | |
12769 | if (schedule_destroy_work) { | |
12770 | struct cfg80211_iface_destroy *destroy; | |
12771 | ||
12772 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | |
12773 | if (destroy) { | |
12774 | destroy->nlportid = notify->portid; | |
12775 | spin_lock(&rdev->destroy_list_lock); | |
12776 | list_add(&destroy->list, &rdev->destroy_list); | |
12777 | spin_unlock(&rdev->destroy_list_lock); | |
12778 | schedule_work(&rdev->destroy_work); | |
12779 | } | |
93a1e86c JR |
12780 | } else if (schedule_scan_stop) { |
12781 | sched_scan_req->owner_nlportid = 0; | |
12782 | ||
12783 | if (rdev->ops->sched_scan_stop && | |
12784 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
12785 | schedule_work(&rdev->sched_scan_stop_wk); | |
78f22b6a | 12786 | } |
5e760230 | 12787 | } |
026331c4 JM |
12788 | |
12789 | rcu_read_unlock(); | |
12790 | ||
6784c7db | 12791 | return NOTIFY_OK; |
026331c4 JM |
12792 | } |
12793 | ||
12794 | static struct notifier_block nl80211_netlink_notifier = { | |
12795 | .notifier_call = nl80211_netlink_notify, | |
12796 | }; | |
12797 | ||
355199e0 JM |
12798 | void cfg80211_ft_event(struct net_device *netdev, |
12799 | struct cfg80211_ft_event_params *ft_event) | |
12800 | { | |
12801 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 12802 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
12803 | struct sk_buff *msg; |
12804 | void *hdr; | |
355199e0 JM |
12805 | |
12806 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
12807 | ||
12808 | if (!ft_event->target_ap) | |
12809 | return; | |
12810 | ||
12811 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12812 | if (!msg) | |
12813 | return; | |
12814 | ||
12815 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
12816 | if (!hdr) |
12817 | goto out; | |
355199e0 | 12818 | |
ae917c9f JB |
12819 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12820 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12821 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
12822 | goto out; | |
355199e0 | 12823 | |
ae917c9f JB |
12824 | if (ft_event->ies && |
12825 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
12826 | goto out; | |
12827 | if (ft_event->ric_ies && | |
12828 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
12829 | ft_event->ric_ies)) | |
12830 | goto out; | |
355199e0 | 12831 | |
9c90a9f6 | 12832 | genlmsg_end(msg, hdr); |
355199e0 | 12833 | |
68eb5503 | 12834 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12835 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
12836 | return; |
12837 | out: | |
12838 | nlmsg_free(msg); | |
355199e0 JM |
12839 | } |
12840 | EXPORT_SYMBOL(cfg80211_ft_event); | |
12841 | ||
5de17984 AS |
12842 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
12843 | { | |
12844 | struct cfg80211_registered_device *rdev; | |
12845 | struct sk_buff *msg; | |
12846 | void *hdr; | |
12847 | u32 nlportid; | |
12848 | ||
f26cbf40 | 12849 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
12850 | if (!rdev->crit_proto_nlportid) |
12851 | return; | |
12852 | ||
12853 | nlportid = rdev->crit_proto_nlportid; | |
12854 | rdev->crit_proto_nlportid = 0; | |
12855 | ||
12856 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12857 | if (!msg) | |
12858 | return; | |
12859 | ||
12860 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
12861 | if (!hdr) | |
12862 | goto nla_put_failure; | |
12863 | ||
12864 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12865 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12866 | goto nla_put_failure; | |
12867 | ||
12868 | genlmsg_end(msg, hdr); | |
12869 | ||
12870 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
12871 | return; | |
12872 | ||
12873 | nla_put_failure: | |
12874 | if (hdr) | |
12875 | genlmsg_cancel(msg, hdr); | |
12876 | nlmsg_free(msg); | |
12877 | ||
12878 | } | |
12879 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
12880 | ||
348baf0e JB |
12881 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
12882 | { | |
12883 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12884 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
12885 | struct sk_buff *msg; |
12886 | void *hdr; | |
12887 | ||
12888 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12889 | if (!msg) | |
12890 | return; | |
12891 | ||
12892 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
12893 | if (!hdr) | |
12894 | goto out; | |
12895 | ||
12896 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12897 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
12898 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12899 | goto out; | |
12900 | ||
12901 | genlmsg_end(msg, hdr); | |
12902 | ||
12903 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
12904 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
12905 | return; | |
12906 | out: | |
12907 | nlmsg_free(msg); | |
12908 | } | |
12909 | ||
55682965 JB |
12910 | /* initialisation/exit functions */ |
12911 | ||
12912 | int nl80211_init(void) | |
12913 | { | |
0d63cbb5 | 12914 | int err; |
55682965 | 12915 | |
2a94fe48 JB |
12916 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
12917 | nl80211_mcgrps); | |
55682965 JB |
12918 | if (err) |
12919 | return err; | |
12920 | ||
026331c4 JM |
12921 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
12922 | if (err) | |
12923 | goto err_out; | |
12924 | ||
55682965 JB |
12925 | return 0; |
12926 | err_out: | |
12927 | genl_unregister_family(&nl80211_fam); | |
12928 | return err; | |
12929 | } | |
12930 | ||
12931 | void nl80211_exit(void) | |
12932 | { | |
026331c4 | 12933 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
12934 | genl_unregister_family(&nl80211_fam); |
12935 | } |