]>
Commit | Line | Data |
---|---|---|
55682965 JB |
1 | /* |
2 | * This is the new netlink-based wireless configuration interface. | |
3 | * | |
026331c4 | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
2740f0cf | 5 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
55682965 JB |
6 | */ |
7 | ||
8 | #include <linux/if.h> | |
9 | #include <linux/module.h> | |
10 | #include <linux/err.h> | |
5a0e3ad6 | 11 | #include <linux/slab.h> |
55682965 JB |
12 | #include <linux/list.h> |
13 | #include <linux/if_ether.h> | |
14 | #include <linux/ieee80211.h> | |
15 | #include <linux/nl80211.h> | |
16 | #include <linux/rtnetlink.h> | |
17 | #include <linux/netlink.h> | |
2a519311 | 18 | #include <linux/etherdevice.h> |
463d0183 | 19 | #include <net/net_namespace.h> |
55682965 JB |
20 | #include <net/genetlink.h> |
21 | #include <net/cfg80211.h> | |
463d0183 | 22 | #include <net/sock.h> |
2a0e047e | 23 | #include <net/inet_connection_sock.h> |
55682965 JB |
24 | #include "core.h" |
25 | #include "nl80211.h" | |
b2e1b302 | 26 | #include "reg.h" |
e35e4d28 | 27 | #include "rdev-ops.h" |
55682965 | 28 | |
5fb628e9 JM |
29 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
30 | struct genl_info *info, | |
31 | struct cfg80211_crypto_settings *settings, | |
32 | int cipher_limit); | |
33 | ||
f84f771d | 34 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 | 35 | struct genl_info *info); |
f84f771d | 36 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
37 | struct genl_info *info); |
38 | ||
55682965 JB |
39 | /* the netlink family */ |
40 | static struct genl_family nl80211_fam = { | |
fb4e1568 MH |
41 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
42 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ | |
43 | .hdrsize = 0, /* no private header */ | |
44 | .version = 1, /* no particular meaning now */ | |
55682965 | 45 | .maxattr = NL80211_ATTR_MAX, |
463d0183 | 46 | .netnsok = true, |
4c476991 JB |
47 | .pre_doit = nl80211_pre_doit, |
48 | .post_doit = nl80211_post_doit, | |
55682965 JB |
49 | }; |
50 | ||
2a94fe48 JB |
51 | /* multicast groups */ |
52 | enum nl80211_multicast_groups { | |
53 | NL80211_MCGRP_CONFIG, | |
54 | NL80211_MCGRP_SCAN, | |
55 | NL80211_MCGRP_REGULATORY, | |
56 | NL80211_MCGRP_MLME, | |
567ffc35 | 57 | NL80211_MCGRP_VENDOR, |
2a94fe48 JB |
58 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
59 | }; | |
60 | ||
61 | static const struct genl_multicast_group nl80211_mcgrps[] = { | |
71b836ec JB |
62 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
63 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, | |
64 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, | |
65 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, | |
66 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, | |
2a94fe48 | 67 | #ifdef CONFIG_NL80211_TESTMODE |
71b836ec | 68 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
2a94fe48 JB |
69 | #endif |
70 | }; | |
71 | ||
89a54e48 JB |
72 | /* returns ERR_PTR values */ |
73 | static struct wireless_dev * | |
74 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 75 | { |
89a54e48 JB |
76 | struct cfg80211_registered_device *rdev; |
77 | struct wireless_dev *result = NULL; | |
78 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
79 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
80 | u64 wdev_id; | |
81 | int wiphy_idx = -1; | |
82 | int ifidx = -1; | |
55682965 | 83 | |
5fe231e8 | 84 | ASSERT_RTNL(); |
55682965 | 85 | |
89a54e48 JB |
86 | if (!have_ifidx && !have_wdev_id) |
87 | return ERR_PTR(-EINVAL); | |
55682965 | 88 | |
89a54e48 JB |
89 | if (have_ifidx) |
90 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
91 | if (have_wdev_id) { | |
92 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
93 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
94 | } |
95 | ||
89a54e48 JB |
96 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
97 | struct wireless_dev *wdev; | |
98 | ||
99 | if (wiphy_net(&rdev->wiphy) != netns) | |
100 | continue; | |
101 | ||
102 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
103 | continue; | |
104 | ||
89a54e48 JB |
105 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
106 | if (have_ifidx && wdev->netdev && | |
107 | wdev->netdev->ifindex == ifidx) { | |
108 | result = wdev; | |
109 | break; | |
110 | } | |
111 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
112 | result = wdev; | |
113 | break; | |
114 | } | |
115 | } | |
89a54e48 JB |
116 | |
117 | if (result) | |
118 | break; | |
119 | } | |
120 | ||
121 | if (result) | |
122 | return result; | |
123 | return ERR_PTR(-ENODEV); | |
55682965 JB |
124 | } |
125 | ||
a9455408 | 126 | static struct cfg80211_registered_device * |
878d9ec7 | 127 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 128 | { |
7fee4778 JB |
129 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
130 | struct net_device *netdev; | |
a9455408 | 131 | |
5fe231e8 | 132 | ASSERT_RTNL(); |
a9455408 | 133 | |
878d9ec7 | 134 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
135 | !attrs[NL80211_ATTR_IFINDEX] && |
136 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
137 | return ERR_PTR(-EINVAL); |
138 | ||
878d9ec7 | 139 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 140 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 141 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 142 | |
89a54e48 JB |
143 | if (attrs[NL80211_ATTR_WDEV]) { |
144 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
145 | struct wireless_dev *wdev; | |
146 | bool found = false; | |
147 | ||
148 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
149 | if (tmp) { | |
150 | /* make sure wdev exists */ | |
89a54e48 JB |
151 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
152 | if (wdev->identifier != (u32)wdev_id) | |
153 | continue; | |
154 | found = true; | |
155 | break; | |
156 | } | |
89a54e48 JB |
157 | |
158 | if (!found) | |
159 | tmp = NULL; | |
160 | ||
161 | if (rdev && tmp != rdev) | |
162 | return ERR_PTR(-EINVAL); | |
163 | rdev = tmp; | |
164 | } | |
165 | } | |
166 | ||
878d9ec7 JB |
167 | if (attrs[NL80211_ATTR_IFINDEX]) { |
168 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
7f2b8562 | 169 | netdev = __dev_get_by_index(netns, ifindex); |
7fee4778 JB |
170 | if (netdev) { |
171 | if (netdev->ieee80211_ptr) | |
f26cbf40 ZG |
172 | tmp = wiphy_to_rdev( |
173 | netdev->ieee80211_ptr->wiphy); | |
7fee4778 JB |
174 | else |
175 | tmp = NULL; | |
176 | ||
7fee4778 JB |
177 | /* not wireless device -- return error */ |
178 | if (!tmp) | |
179 | return ERR_PTR(-EINVAL); | |
180 | ||
181 | /* mismatch -- return error */ | |
182 | if (rdev && tmp != rdev) | |
183 | return ERR_PTR(-EINVAL); | |
184 | ||
185 | rdev = tmp; | |
a9455408 | 186 | } |
a9455408 | 187 | } |
a9455408 | 188 | |
4f7eff10 JB |
189 | if (!rdev) |
190 | return ERR_PTR(-ENODEV); | |
a9455408 | 191 | |
4f7eff10 JB |
192 | if (netns != wiphy_net(&rdev->wiphy)) |
193 | return ERR_PTR(-ENODEV); | |
194 | ||
195 | return rdev; | |
a9455408 JB |
196 | } |
197 | ||
198 | /* | |
199 | * This function returns a pointer to the driver | |
200 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
201 | * |
202 | * The result of this can be a PTR_ERR and hence must | |
203 | * be checked with IS_ERR() for errors. | |
204 | */ | |
205 | static struct cfg80211_registered_device * | |
4f7eff10 | 206 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 207 | { |
5fe231e8 | 208 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
209 | } |
210 | ||
55682965 | 211 | /* policy for the attributes */ |
8cd4d456 | 212 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
55682965 JB |
213 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
214 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 215 | .len = 20-1 }, |
31888487 | 216 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 217 | |
72bdcf34 | 218 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 219 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
220 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
221 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
222 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
223 | ||
b9a5f8ca JM |
224 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
225 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
226 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
227 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 228 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
3057dbfd | 229 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
55682965 JB |
230 | |
231 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
232 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
233 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 234 | |
e007b857 EP |
235 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
236 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 237 | |
b9454e83 | 238 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
239 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
240 | .len = WLAN_MAX_KEY_LEN }, | |
241 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
242 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
243 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 244 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 245 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
246 | |
247 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
248 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
249 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
250 | .len = IEEE80211_MAX_DATA_LEN }, | |
251 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
252 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
253 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
254 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
255 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
256 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
257 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 258 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 259 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 260 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 261 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 262 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 263 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 264 | |
b2e1b302 LR |
265 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
266 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
267 | ||
9f1ba906 JM |
268 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
269 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
270 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
271 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
272 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 273 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 274 | |
24bdd9f4 | 275 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 276 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 277 | |
6c739419 | 278 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
279 | |
280 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
281 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
282 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
283 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
284 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
285 | |
286 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
287 | .len = IEEE80211_MAX_SSID_LEN }, | |
288 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
289 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 290 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 291 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 292 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
293 | [NL80211_ATTR_STA_FLAGS2] = { |
294 | .len = sizeof(struct nl80211_sta_flag_update), | |
295 | }, | |
3f77316c | 296 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
297 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
298 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
299 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
300 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
301 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 302 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 303 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
304 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
305 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
306 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
307 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 308 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
309 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
310 | .len = IEEE80211_MAX_DATA_LEN }, | |
311 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 312 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 313 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 314 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 315 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
316 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
317 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 318 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
319 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
320 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 321 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 322 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 323 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 324 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 325 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 326 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 327 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 328 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 329 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
330 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
331 | .len = IEEE80211_MAX_DATA_LEN }, | |
332 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
333 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 334 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 335 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 336 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
337 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
338 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
339 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
340 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
341 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
31fa97c5 | 342 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
e247bd90 | 343 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
344 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
345 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 346 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
347 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
348 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
349 | .len = NL80211_HT_CAPABILITY_LEN | |
350 | }, | |
1d9d9213 | 351 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 352 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 353 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 354 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 355 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
e39e5b5e | 356 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
f461be3e | 357 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
ed473771 | 358 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
53cabad7 JB |
359 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
360 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | |
77765eaf VT |
361 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
362 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
363 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
364 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 365 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
366 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
367 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
368 | .len = NL80211_VHT_CAPABILITY_LEN, | |
369 | }, | |
355199e0 JM |
370 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
371 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
372 | .len = IEEE80211_MAX_DATA_LEN }, | |
5e4b6f56 | 373 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
16ef1fe2 SW |
374 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
375 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | |
376 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | |
9a774c78 AO |
377 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
378 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, | |
c01fc9ad SD |
379 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
380 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, | |
5336fa88 | 381 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
60f4a7b1 | 382 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
ad7e718c JB |
383 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
384 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, | |
385 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, | |
fa9ffc74 KP |
386 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
387 | .len = IEEE80211_QOS_MAP_LEN_MAX }, | |
1df4a510 JM |
388 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
389 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, | |
df942e7b | 390 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
18e5ca65 | 391 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
34d22ce2 | 392 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
bab5ab7d | 393 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
960d01ac JB |
394 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
395 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, | |
396 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, | |
18998c38 | 397 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
ad2b26ab | 398 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
1bdd716c | 399 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
4b681c82 | 400 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
9c748934 | 401 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
05050753 | 402 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
55682965 JB |
403 | }; |
404 | ||
e31b8213 | 405 | /* policy for the key attributes */ |
b54452b0 | 406 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 407 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
408 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
409 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 410 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
411 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
412 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 413 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
414 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
415 | }; | |
416 | ||
417 | /* policy for the key default flags */ | |
418 | static const struct nla_policy | |
419 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
420 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
421 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
422 | }; |
423 | ||
ff1b6e69 JB |
424 | /* policy for WoWLAN attributes */ |
425 | static const struct nla_policy | |
426 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
427 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
428 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
429 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
430 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
431 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
432 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
433 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
434 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e | 435 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
8cd4d456 | 436 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
2a0e047e JB |
437 | }; |
438 | ||
439 | static const struct nla_policy | |
440 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
441 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
442 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
443 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
444 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
445 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
446 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
447 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
448 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
449 | }, | |
450 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
451 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
452 | }, | |
453 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
454 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
455 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
456 | }; |
457 | ||
be29b99a AK |
458 | /* policy for coalesce rule attributes */ |
459 | static const struct nla_policy | |
460 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
461 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
462 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
463 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
464 | }; | |
465 | ||
e5497d76 JB |
466 | /* policy for GTK rekey offload attributes */ |
467 | static const struct nla_policy | |
468 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
469 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
470 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
471 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
472 | }; | |
473 | ||
a1f1c21c LC |
474 | static const struct nla_policy |
475 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 476 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 477 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 478 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
479 | }; |
480 | ||
97990a06 JB |
481 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
482 | struct netlink_callback *cb, | |
483 | struct cfg80211_registered_device **rdev, | |
484 | struct wireless_dev **wdev) | |
a043897a | 485 | { |
97990a06 | 486 | int err; |
a043897a | 487 | |
97990a06 | 488 | rtnl_lock(); |
a043897a | 489 | |
97990a06 JB |
490 | if (!cb->args[0]) { |
491 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
492 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
493 | nl80211_policy); | |
494 | if (err) | |
495 | goto out_unlock; | |
67748893 | 496 | |
97990a06 JB |
497 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
498 | nl80211_fam.attrbuf); | |
499 | if (IS_ERR(*wdev)) { | |
500 | err = PTR_ERR(*wdev); | |
501 | goto out_unlock; | |
502 | } | |
f26cbf40 | 503 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
504 | /* 0 is the first index - add 1 to parse only once */ |
505 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
506 | cb->args[1] = (*wdev)->identifier; |
507 | } else { | |
c319d50b JB |
508 | /* subtract the 1 again here */ |
509 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 510 | struct wireless_dev *tmp; |
67748893 | 511 | |
97990a06 JB |
512 | if (!wiphy) { |
513 | err = -ENODEV; | |
514 | goto out_unlock; | |
515 | } | |
f26cbf40 | 516 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 517 | *wdev = NULL; |
67748893 | 518 | |
97990a06 JB |
519 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
520 | if (tmp->identifier == cb->args[1]) { | |
521 | *wdev = tmp; | |
522 | break; | |
523 | } | |
524 | } | |
67748893 | 525 | |
97990a06 JB |
526 | if (!*wdev) { |
527 | err = -ENODEV; | |
528 | goto out_unlock; | |
529 | } | |
67748893 JB |
530 | } |
531 | ||
67748893 | 532 | return 0; |
97990a06 | 533 | out_unlock: |
67748893 JB |
534 | rtnl_unlock(); |
535 | return err; | |
536 | } | |
537 | ||
97990a06 | 538 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 539 | { |
67748893 JB |
540 | rtnl_unlock(); |
541 | } | |
542 | ||
f4a11bb0 JB |
543 | /* IE validation */ |
544 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
545 | { | |
546 | const u8 *pos; | |
547 | int len; | |
548 | ||
549 | if (!attr) | |
550 | return true; | |
551 | ||
552 | pos = nla_data(attr); | |
553 | len = nla_len(attr); | |
554 | ||
555 | while (len) { | |
556 | u8 elemlen; | |
557 | ||
558 | if (len < 2) | |
559 | return false; | |
560 | len -= 2; | |
561 | ||
562 | elemlen = pos[1]; | |
563 | if (elemlen > len) | |
564 | return false; | |
565 | ||
566 | len -= elemlen; | |
567 | pos += 2 + elemlen; | |
568 | } | |
569 | ||
570 | return true; | |
571 | } | |
572 | ||
55682965 | 573 | /* message building helper */ |
15e47304 | 574 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
575 | int flags, u8 cmd) |
576 | { | |
577 | /* since there is no private header just add the generic one */ | |
15e47304 | 578 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
579 | } |
580 | ||
5dab3b8a | 581 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
582 | struct ieee80211_channel *chan, |
583 | bool large) | |
5dab3b8a | 584 | { |
ea077c1c RL |
585 | /* Some channels must be completely excluded from the |
586 | * list to protect old user-space tools from breaking | |
587 | */ | |
588 | if (!large && chan->flags & | |
589 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
590 | return 0; | |
591 | ||
9360ffd1 DM |
592 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
593 | chan->center_freq)) | |
594 | goto nla_put_failure; | |
5dab3b8a | 595 | |
9360ffd1 DM |
596 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
597 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
598 | goto nla_put_failure; | |
8fe02e16 LR |
599 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
600 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
601 | goto nla_put_failure; | |
602 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
603 | goto nla_put_failure; | |
604 | } | |
cdc89b97 JB |
605 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
606 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
607 | goto nla_put_failure; | |
608 | if (large) { | |
609 | u32 time; | |
610 | ||
611 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
612 | ||
613 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
614 | chan->dfs_state)) | |
615 | goto nla_put_failure; | |
616 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
617 | time)) | |
618 | goto nla_put_failure; | |
089027e5 JD |
619 | if (nla_put_u32(msg, |
620 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
621 | chan->dfs_cac_ms)) | |
622 | goto nla_put_failure; | |
cdc89b97 JB |
623 | } |
624 | } | |
5dab3b8a | 625 | |
fe1abafd JB |
626 | if (large) { |
627 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
628 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
629 | goto nla_put_failure; | |
630 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
631 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
632 | goto nla_put_failure; | |
633 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
634 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
635 | goto nla_put_failure; | |
636 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
637 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
638 | goto nla_put_failure; | |
570dbde1 DS |
639 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
640 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
641 | goto nla_put_failure; | |
642 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && | |
643 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) | |
644 | goto nla_put_failure; | |
ea077c1c RL |
645 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
646 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
647 | goto nla_put_failure; | |
648 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
649 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
650 | goto nla_put_failure; | |
fe1abafd JB |
651 | } |
652 | ||
9360ffd1 DM |
653 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
654 | DBM_TO_MBM(chan->max_power))) | |
655 | goto nla_put_failure; | |
5dab3b8a LR |
656 | |
657 | return 0; | |
658 | ||
659 | nla_put_failure: | |
660 | return -ENOBUFS; | |
661 | } | |
662 | ||
55682965 JB |
663 | /* netlink command implementations */ |
664 | ||
b9454e83 JB |
665 | struct key_parse { |
666 | struct key_params p; | |
667 | int idx; | |
e31b8213 | 668 | int type; |
b9454e83 | 669 | bool def, defmgmt; |
dbd2fd65 | 670 | bool def_uni, def_multi; |
b9454e83 JB |
671 | }; |
672 | ||
673 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
674 | { | |
675 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
676 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
677 | nl80211_key_policy); | |
678 | if (err) | |
679 | return err; | |
680 | ||
681 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
682 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
683 | ||
dbd2fd65 JB |
684 | if (k->def) { |
685 | k->def_uni = true; | |
686 | k->def_multi = true; | |
687 | } | |
688 | if (k->defmgmt) | |
689 | k->def_multi = true; | |
690 | ||
b9454e83 JB |
691 | if (tb[NL80211_KEY_IDX]) |
692 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
693 | ||
694 | if (tb[NL80211_KEY_DATA]) { | |
695 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
696 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
697 | } | |
698 | ||
699 | if (tb[NL80211_KEY_SEQ]) { | |
700 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
701 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
702 | } | |
703 | ||
704 | if (tb[NL80211_KEY_CIPHER]) | |
705 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
706 | ||
e31b8213 JB |
707 | if (tb[NL80211_KEY_TYPE]) { |
708 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
709 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
710 | return -EINVAL; | |
711 | } | |
712 | ||
dbd2fd65 JB |
713 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
714 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
715 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
716 | tb[NL80211_KEY_DEFAULT_TYPES], | |
717 | nl80211_key_default_policy); | |
dbd2fd65 JB |
718 | if (err) |
719 | return err; | |
720 | ||
721 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
722 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
723 | } | |
724 | ||
b9454e83 JB |
725 | return 0; |
726 | } | |
727 | ||
728 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
729 | { | |
730 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
731 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
732 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
733 | } | |
734 | ||
735 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
736 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
737 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
738 | } | |
739 | ||
740 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
741 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
742 | ||
743 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
744 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
745 | ||
746 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
747 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
748 | ||
dbd2fd65 JB |
749 | if (k->def) { |
750 | k->def_uni = true; | |
751 | k->def_multi = true; | |
752 | } | |
753 | if (k->defmgmt) | |
754 | k->def_multi = true; | |
755 | ||
e31b8213 JB |
756 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
757 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
758 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
759 | return -EINVAL; | |
760 | } | |
761 | ||
dbd2fd65 JB |
762 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
763 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
764 | int err = nla_parse_nested( | |
765 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
766 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
767 | nl80211_key_default_policy); | |
768 | if (err) | |
769 | return err; | |
770 | ||
771 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
772 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
773 | } | |
774 | ||
b9454e83 JB |
775 | return 0; |
776 | } | |
777 | ||
778 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
779 | { | |
780 | int err; | |
781 | ||
782 | memset(k, 0, sizeof(*k)); | |
783 | k->idx = -1; | |
e31b8213 | 784 | k->type = -1; |
b9454e83 JB |
785 | |
786 | if (info->attrs[NL80211_ATTR_KEY]) | |
787 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
788 | else | |
789 | err = nl80211_parse_key_old(info, k); | |
790 | ||
791 | if (err) | |
792 | return err; | |
793 | ||
794 | if (k->def && k->defmgmt) | |
795 | return -EINVAL; | |
796 | ||
dbd2fd65 JB |
797 | if (k->defmgmt) { |
798 | if (k->def_uni || !k->def_multi) | |
799 | return -EINVAL; | |
800 | } | |
801 | ||
b9454e83 JB |
802 | if (k->idx != -1) { |
803 | if (k->defmgmt) { | |
804 | if (k->idx < 4 || k->idx > 5) | |
805 | return -EINVAL; | |
806 | } else if (k->def) { | |
807 | if (k->idx < 0 || k->idx > 3) | |
808 | return -EINVAL; | |
809 | } else { | |
810 | if (k->idx < 0 || k->idx > 5) | |
811 | return -EINVAL; | |
812 | } | |
813 | } | |
814 | ||
815 | return 0; | |
816 | } | |
817 | ||
fffd0934 JB |
818 | static struct cfg80211_cached_keys * |
819 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 820 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
821 | { |
822 | struct key_parse parse; | |
823 | struct nlattr *key; | |
824 | struct cfg80211_cached_keys *result; | |
825 | int rem, err, def = 0; | |
826 | ||
827 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
828 | if (!result) | |
829 | return ERR_PTR(-ENOMEM); | |
830 | ||
831 | result->def = -1; | |
832 | result->defmgmt = -1; | |
833 | ||
834 | nla_for_each_nested(key, keys, rem) { | |
835 | memset(&parse, 0, sizeof(parse)); | |
836 | parse.idx = -1; | |
837 | ||
838 | err = nl80211_parse_key_new(key, &parse); | |
839 | if (err) | |
840 | goto error; | |
841 | err = -EINVAL; | |
842 | if (!parse.p.key) | |
843 | goto error; | |
844 | if (parse.idx < 0 || parse.idx > 4) | |
845 | goto error; | |
846 | if (parse.def) { | |
847 | if (def) | |
848 | goto error; | |
849 | def = 1; | |
850 | result->def = parse.idx; | |
dbd2fd65 JB |
851 | if (!parse.def_uni || !parse.def_multi) |
852 | goto error; | |
fffd0934 JB |
853 | } else if (parse.defmgmt) |
854 | goto error; | |
855 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 856 | parse.idx, false, NULL); |
fffd0934 JB |
857 | if (err) |
858 | goto error; | |
859 | result->params[parse.idx].cipher = parse.p.cipher; | |
860 | result->params[parse.idx].key_len = parse.p.key_len; | |
861 | result->params[parse.idx].key = result->data[parse.idx]; | |
862 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
863 | |
864 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
865 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
866 | if (no_ht) | |
867 | *no_ht = true; | |
868 | } | |
fffd0934 JB |
869 | } |
870 | ||
871 | return result; | |
872 | error: | |
873 | kfree(result); | |
874 | return ERR_PTR(err); | |
875 | } | |
876 | ||
877 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
878 | { | |
879 | ASSERT_WDEV_LOCK(wdev); | |
880 | ||
fffd0934 JB |
881 | switch (wdev->iftype) { |
882 | case NL80211_IFTYPE_AP: | |
883 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 884 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 885 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
886 | break; |
887 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 888 | case NL80211_IFTYPE_STATION: |
074ac8df | 889 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 890 | if (!wdev->current_bss) |
fffd0934 JB |
891 | return -ENOLINK; |
892 | break; | |
de4fcbad | 893 | case NL80211_IFTYPE_UNSPECIFIED: |
6e0bd6c3 | 894 | case NL80211_IFTYPE_OCB: |
de4fcbad JB |
895 | case NL80211_IFTYPE_MONITOR: |
896 | case NL80211_IFTYPE_P2P_DEVICE: | |
897 | case NL80211_IFTYPE_WDS: | |
898 | case NUM_NL80211_IFTYPES: | |
fffd0934 JB |
899 | return -EINVAL; |
900 | } | |
901 | ||
902 | return 0; | |
903 | } | |
904 | ||
664834de JM |
905 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
906 | struct nlattr *tb) | |
907 | { | |
908 | struct ieee80211_channel *chan; | |
909 | ||
910 | if (tb == NULL) | |
911 | return NULL; | |
912 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
913 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
914 | return NULL; | |
915 | return chan; | |
916 | } | |
917 | ||
7527a782 JB |
918 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
919 | { | |
920 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
921 | int i; | |
922 | ||
923 | if (!nl_modes) | |
924 | goto nla_put_failure; | |
925 | ||
926 | i = 0; | |
927 | while (ifmodes) { | |
9360ffd1 DM |
928 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
929 | goto nla_put_failure; | |
7527a782 JB |
930 | ifmodes >>= 1; |
931 | i++; | |
932 | } | |
933 | ||
934 | nla_nest_end(msg, nl_modes); | |
935 | return 0; | |
936 | ||
937 | nla_put_failure: | |
938 | return -ENOBUFS; | |
939 | } | |
940 | ||
941 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
942 | struct sk_buff *msg, |
943 | bool large) | |
7527a782 JB |
944 | { |
945 | struct nlattr *nl_combis; | |
946 | int i, j; | |
947 | ||
948 | nl_combis = nla_nest_start(msg, | |
949 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
950 | if (!nl_combis) | |
951 | goto nla_put_failure; | |
952 | ||
953 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
954 | const struct ieee80211_iface_combination *c; | |
955 | struct nlattr *nl_combi, *nl_limits; | |
956 | ||
957 | c = &wiphy->iface_combinations[i]; | |
958 | ||
959 | nl_combi = nla_nest_start(msg, i + 1); | |
960 | if (!nl_combi) | |
961 | goto nla_put_failure; | |
962 | ||
963 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
964 | if (!nl_limits) | |
965 | goto nla_put_failure; | |
966 | ||
967 | for (j = 0; j < c->n_limits; j++) { | |
968 | struct nlattr *nl_limit; | |
969 | ||
970 | nl_limit = nla_nest_start(msg, j + 1); | |
971 | if (!nl_limit) | |
972 | goto nla_put_failure; | |
9360ffd1 DM |
973 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
974 | c->limits[j].max)) | |
975 | goto nla_put_failure; | |
7527a782 JB |
976 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
977 | c->limits[j].types)) | |
978 | goto nla_put_failure; | |
979 | nla_nest_end(msg, nl_limit); | |
980 | } | |
981 | ||
982 | nla_nest_end(msg, nl_limits); | |
983 | ||
9360ffd1 DM |
984 | if (c->beacon_int_infra_match && |
985 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
986 | goto nla_put_failure; | |
987 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
988 | c->num_different_channels) || | |
989 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
990 | c->max_interfaces)) | |
991 | goto nla_put_failure; | |
cdc89b97 | 992 | if (large && |
8c48b50a FF |
993 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
994 | c->radar_detect_widths) || | |
995 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
996 | c->radar_detect_regions))) | |
cdc89b97 | 997 | goto nla_put_failure; |
7527a782 JB |
998 | |
999 | nla_nest_end(msg, nl_combi); | |
1000 | } | |
1001 | ||
1002 | nla_nest_end(msg, nl_combis); | |
1003 | ||
1004 | return 0; | |
1005 | nla_put_failure: | |
1006 | return -ENOBUFS; | |
1007 | } | |
1008 | ||
3713b4e3 | 1009 | #ifdef CONFIG_PM |
b56cf720 JB |
1010 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
1011 | struct sk_buff *msg) | |
1012 | { | |
964dc9e2 | 1013 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
1014 | struct nlattr *nl_tcp; |
1015 | ||
1016 | if (!tcp) | |
1017 | return 0; | |
1018 | ||
1019 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
1020 | if (!nl_tcp) | |
1021 | return -ENOBUFS; | |
1022 | ||
1023 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1024 | tcp->data_payload_max)) | |
1025 | return -ENOBUFS; | |
1026 | ||
1027 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1028 | tcp->data_payload_max)) | |
1029 | return -ENOBUFS; | |
1030 | ||
1031 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1032 | return -ENOBUFS; | |
1033 | ||
1034 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1035 | sizeof(*tcp->tok), tcp->tok)) | |
1036 | return -ENOBUFS; | |
1037 | ||
1038 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1039 | tcp->data_interval_max)) | |
1040 | return -ENOBUFS; | |
1041 | ||
1042 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1043 | tcp->wake_payload_max)) | |
1044 | return -ENOBUFS; | |
1045 | ||
1046 | nla_nest_end(msg, nl_tcp); | |
1047 | return 0; | |
1048 | } | |
1049 | ||
3713b4e3 | 1050 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1051 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1052 | bool large) |
55682965 | 1053 | { |
3713b4e3 | 1054 | struct nlattr *nl_wowlan; |
55682965 | 1055 | |
1b8ec87a | 1056 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1057 | return 0; |
55682965 | 1058 | |
3713b4e3 JB |
1059 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1060 | if (!nl_wowlan) | |
1061 | return -ENOBUFS; | |
9360ffd1 | 1062 | |
1b8ec87a | 1063 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1064 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1065 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1066 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1067 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1068 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1069 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1070 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1071 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1072 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1073 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1074 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1075 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1076 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1077 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1078 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1079 | return -ENOBUFS; | |
9360ffd1 | 1080 | |
1b8ec87a | 1081 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1082 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1083 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1084 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1085 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1086 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1087 | }; |
9360ffd1 | 1088 | |
3713b4e3 JB |
1089 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1090 | sizeof(pat), &pat)) | |
1091 | return -ENOBUFS; | |
1092 | } | |
9360ffd1 | 1093 | |
75453ccb LC |
1094 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
1095 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, | |
1096 | rdev->wiphy.wowlan->max_nd_match_sets)) | |
1097 | return -ENOBUFS; | |
1098 | ||
1b8ec87a | 1099 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1100 | return -ENOBUFS; |
1101 | ||
3713b4e3 | 1102 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1103 | |
3713b4e3 JB |
1104 | return 0; |
1105 | } | |
1106 | #endif | |
9360ffd1 | 1107 | |
be29b99a | 1108 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1109 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1110 | { |
1111 | struct nl80211_coalesce_rule_support rule; | |
1112 | ||
1b8ec87a | 1113 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1114 | return 0; |
1115 | ||
1b8ec87a ZG |
1116 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1117 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1118 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1119 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1120 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1121 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1122 | |
1123 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1124 | return -ENOBUFS; | |
1125 | ||
1126 | return 0; | |
1127 | } | |
1128 | ||
3713b4e3 JB |
1129 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1130 | struct ieee80211_supported_band *sband) | |
1131 | { | |
1132 | struct nlattr *nl_rates, *nl_rate; | |
1133 | struct ieee80211_rate *rate; | |
1134 | int i; | |
87bbbe22 | 1135 | |
3713b4e3 JB |
1136 | /* add HT info */ |
1137 | if (sband->ht_cap.ht_supported && | |
1138 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1139 | sizeof(sband->ht_cap.mcs), | |
1140 | &sband->ht_cap.mcs) || | |
1141 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1142 | sband->ht_cap.cap) || | |
1143 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1144 | sband->ht_cap.ampdu_factor) || | |
1145 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1146 | sband->ht_cap.ampdu_density))) | |
1147 | return -ENOBUFS; | |
afe0cbf8 | 1148 | |
3713b4e3 JB |
1149 | /* add VHT info */ |
1150 | if (sband->vht_cap.vht_supported && | |
1151 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1152 | sizeof(sband->vht_cap.vht_mcs), | |
1153 | &sband->vht_cap.vht_mcs) || | |
1154 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1155 | sband->vht_cap.cap))) | |
1156 | return -ENOBUFS; | |
f59ac048 | 1157 | |
3713b4e3 JB |
1158 | /* add bitrates */ |
1159 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1160 | if (!nl_rates) | |
1161 | return -ENOBUFS; | |
ee688b00 | 1162 | |
3713b4e3 JB |
1163 | for (i = 0; i < sband->n_bitrates; i++) { |
1164 | nl_rate = nla_nest_start(msg, i); | |
1165 | if (!nl_rate) | |
1166 | return -ENOBUFS; | |
ee688b00 | 1167 | |
3713b4e3 JB |
1168 | rate = &sband->bitrates[i]; |
1169 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1170 | rate->bitrate)) | |
1171 | return -ENOBUFS; | |
1172 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1173 | nla_put_flag(msg, | |
1174 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1175 | return -ENOBUFS; | |
ee688b00 | 1176 | |
3713b4e3 JB |
1177 | nla_nest_end(msg, nl_rate); |
1178 | } | |
d51626df | 1179 | |
3713b4e3 | 1180 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1181 | |
3713b4e3 JB |
1182 | return 0; |
1183 | } | |
ee688b00 | 1184 | |
3713b4e3 JB |
1185 | static int |
1186 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1187 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1188 | { | |
1189 | u16 stypes; | |
1190 | struct nlattr *nl_ftypes, *nl_ifs; | |
1191 | enum nl80211_iftype ift; | |
1192 | int i; | |
ee688b00 | 1193 | |
3713b4e3 JB |
1194 | if (!mgmt_stypes) |
1195 | return 0; | |
5dab3b8a | 1196 | |
3713b4e3 JB |
1197 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1198 | if (!nl_ifs) | |
1199 | return -ENOBUFS; | |
e2f367f2 | 1200 | |
3713b4e3 JB |
1201 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1202 | nl_ftypes = nla_nest_start(msg, ift); | |
1203 | if (!nl_ftypes) | |
1204 | return -ENOBUFS; | |
1205 | i = 0; | |
1206 | stypes = mgmt_stypes[ift].tx; | |
1207 | while (stypes) { | |
1208 | if ((stypes & 1) && | |
1209 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1210 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1211 | return -ENOBUFS; | |
1212 | stypes >>= 1; | |
1213 | i++; | |
ee688b00 | 1214 | } |
3713b4e3 JB |
1215 | nla_nest_end(msg, nl_ftypes); |
1216 | } | |
ee688b00 | 1217 | |
3713b4e3 | 1218 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1219 | |
3713b4e3 JB |
1220 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1221 | if (!nl_ifs) | |
1222 | return -ENOBUFS; | |
ee688b00 | 1223 | |
3713b4e3 JB |
1224 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1225 | nl_ftypes = nla_nest_start(msg, ift); | |
1226 | if (!nl_ftypes) | |
1227 | return -ENOBUFS; | |
1228 | i = 0; | |
1229 | stypes = mgmt_stypes[ift].rx; | |
1230 | while (stypes) { | |
1231 | if ((stypes & 1) && | |
1232 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1233 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1234 | return -ENOBUFS; | |
1235 | stypes >>= 1; | |
1236 | i++; | |
1237 | } | |
1238 | nla_nest_end(msg, nl_ftypes); | |
1239 | } | |
1240 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1241 | |
3713b4e3 JB |
1242 | return 0; |
1243 | } | |
ee688b00 | 1244 | |
86e8cf98 JB |
1245 | struct nl80211_dump_wiphy_state { |
1246 | s64 filter_wiphy; | |
1247 | long start; | |
1248 | long split_start, band_start, chan_start; | |
1249 | bool split; | |
1250 | }; | |
1251 | ||
1b8ec87a | 1252 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 1253 | enum nl80211_commands cmd, |
3713b4e3 | 1254 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1255 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1256 | { |
1257 | void *hdr; | |
1258 | struct nlattr *nl_bands, *nl_band; | |
1259 | struct nlattr *nl_freqs, *nl_freq; | |
1260 | struct nlattr *nl_cmds; | |
1261 | enum ieee80211_band band; | |
1262 | struct ieee80211_channel *chan; | |
1263 | int i; | |
1264 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1265 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1266 | u32 features; |
ee688b00 | 1267 | |
3bb20556 | 1268 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
1269 | if (!hdr) |
1270 | return -ENOBUFS; | |
ee688b00 | 1271 | |
86e8cf98 JB |
1272 | if (WARN_ON(!state)) |
1273 | return -EINVAL; | |
ee688b00 | 1274 | |
1b8ec87a | 1275 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1276 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1277 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1278 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1279 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1280 | goto nla_put_failure; |
1281 | ||
3bb20556 JB |
1282 | if (cmd != NL80211_CMD_NEW_WIPHY) |
1283 | goto finish; | |
1284 | ||
86e8cf98 | 1285 | switch (state->split_start) { |
3713b4e3 JB |
1286 | case 0: |
1287 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1288 | rdev->wiphy.retry_short) || |
3713b4e3 | 1289 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1290 | rdev->wiphy.retry_long) || |
3713b4e3 | 1291 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1292 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1293 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1294 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1295 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1296 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1297 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1298 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1299 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1300 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1301 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1302 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1303 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1304 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1305 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
1b8ec87a | 1306 | rdev->wiphy.max_match_sets)) |
9360ffd1 | 1307 | goto nla_put_failure; |
3713b4e3 | 1308 | |
1b8ec87a | 1309 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1310 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1311 | goto nla_put_failure; |
1b8ec87a | 1312 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1313 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1314 | goto nla_put_failure; | |
1b8ec87a | 1315 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1316 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1317 | goto nla_put_failure; | |
1b8ec87a | 1318 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1319 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1320 | goto nla_put_failure; | |
1b8ec87a | 1321 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1322 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1323 | goto nla_put_failure; | |
1b8ec87a | 1324 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1325 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1326 | goto nla_put_failure; |
86e8cf98 JB |
1327 | state->split_start++; |
1328 | if (state->split) | |
3713b4e3 JB |
1329 | break; |
1330 | case 1: | |
1331 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1332 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1333 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1334 | goto nla_put_failure; |
4745fc09 | 1335 | |
3713b4e3 | 1336 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1337 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1338 | goto nla_put_failure; |
b23aa676 | 1339 | |
1b8ec87a | 1340 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1341 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1342 | goto nla_put_failure; |
b23aa676 | 1343 | |
3713b4e3 | 1344 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1345 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1346 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1347 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1348 | goto nla_put_failure; |
b23aa676 | 1349 | |
1b8ec87a | 1350 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1351 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1352 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1353 | goto nla_put_failure; |
8fdc621d | 1354 | |
1b8ec87a ZG |
1355 | if ((rdev->wiphy.available_antennas_tx || |
1356 | rdev->wiphy.available_antennas_rx) && | |
1357 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1358 | u32 tx_ant = 0, rx_ant = 0; |
1359 | int res; | |
1b8ec87a | 1360 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1361 | if (!res) { |
1362 | if (nla_put_u32(msg, | |
1363 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1364 | tx_ant) || | |
1365 | nla_put_u32(msg, | |
1366 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1367 | rx_ant)) | |
1368 | goto nla_put_failure; | |
1369 | } | |
1370 | } | |
a293911d | 1371 | |
86e8cf98 JB |
1372 | state->split_start++; |
1373 | if (state->split) | |
3713b4e3 JB |
1374 | break; |
1375 | case 2: | |
1376 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1377 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1378 | goto nla_put_failure; |
86e8cf98 JB |
1379 | state->split_start++; |
1380 | if (state->split) | |
3713b4e3 JB |
1381 | break; |
1382 | case 3: | |
1383 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1384 | if (!nl_bands) | |
1385 | goto nla_put_failure; | |
f7ca38df | 1386 | |
86e8cf98 JB |
1387 | for (band = state->band_start; |
1388 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1389 | struct ieee80211_supported_band *sband; |
2e161f78 | 1390 | |
1b8ec87a | 1391 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1392 | |
3713b4e3 JB |
1393 | if (!sband) |
1394 | continue; | |
1395 | ||
1396 | nl_band = nla_nest_start(msg, band); | |
1397 | if (!nl_band) | |
2e161f78 | 1398 | goto nla_put_failure; |
3713b4e3 | 1399 | |
86e8cf98 | 1400 | switch (state->chan_start) { |
3713b4e3 JB |
1401 | case 0: |
1402 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1403 | goto nla_put_failure; |
86e8cf98 JB |
1404 | state->chan_start++; |
1405 | if (state->split) | |
3713b4e3 JB |
1406 | break; |
1407 | default: | |
1408 | /* add frequencies */ | |
1409 | nl_freqs = nla_nest_start( | |
1410 | msg, NL80211_BAND_ATTR_FREQS); | |
1411 | if (!nl_freqs) | |
1412 | goto nla_put_failure; | |
1413 | ||
86e8cf98 | 1414 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1415 | i < sband->n_channels; |
1416 | i++) { | |
1417 | nl_freq = nla_nest_start(msg, i); | |
1418 | if (!nl_freq) | |
1419 | goto nla_put_failure; | |
1420 | ||
1421 | chan = &sband->channels[i]; | |
1422 | ||
86e8cf98 JB |
1423 | if (nl80211_msg_put_channel( |
1424 | msg, chan, | |
1425 | state->split)) | |
3713b4e3 JB |
1426 | goto nla_put_failure; |
1427 | ||
1428 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1429 | if (state->split) |
3713b4e3 JB |
1430 | break; |
1431 | } | |
1432 | if (i < sband->n_channels) | |
86e8cf98 | 1433 | state->chan_start = i + 2; |
3713b4e3 | 1434 | else |
86e8cf98 | 1435 | state->chan_start = 0; |
3713b4e3 JB |
1436 | nla_nest_end(msg, nl_freqs); |
1437 | } | |
1438 | ||
1439 | nla_nest_end(msg, nl_band); | |
1440 | ||
86e8cf98 | 1441 | if (state->split) { |
3713b4e3 | 1442 | /* start again here */ |
86e8cf98 | 1443 | if (state->chan_start) |
3713b4e3 JB |
1444 | band--; |
1445 | break; | |
2e161f78 | 1446 | } |
2e161f78 | 1447 | } |
3713b4e3 | 1448 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1449 | |
3713b4e3 | 1450 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1451 | state->band_start = band + 1; |
3713b4e3 | 1452 | else |
86e8cf98 | 1453 | state->band_start = 0; |
74b70a4e | 1454 | |
3713b4e3 | 1455 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1456 | if (state->band_start == 0 && state->chan_start == 0) |
1457 | state->split_start++; | |
1458 | if (state->split) | |
3713b4e3 JB |
1459 | break; |
1460 | case 4: | |
1461 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1462 | if (!nl_cmds) | |
2e161f78 JB |
1463 | goto nla_put_failure; |
1464 | ||
3713b4e3 JB |
1465 | i = 0; |
1466 | #define CMD(op, n) \ | |
1467 | do { \ | |
1b8ec87a | 1468 | if (rdev->ops->op) { \ |
3713b4e3 JB |
1469 | i++; \ |
1470 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1471 | goto nla_put_failure; \ | |
1472 | } \ | |
1473 | } while (0) | |
1474 | ||
1475 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1476 | CMD(change_virtual_intf, SET_INTERFACE); | |
1477 | CMD(add_key, NEW_KEY); | |
1478 | CMD(start_ap, START_AP); | |
1479 | CMD(add_station, NEW_STATION); | |
1480 | CMD(add_mpath, NEW_MPATH); | |
1481 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1482 | CMD(change_bss, SET_BSS); | |
1483 | CMD(auth, AUTHENTICATE); | |
1484 | CMD(assoc, ASSOCIATE); | |
1485 | CMD(deauth, DEAUTHENTICATE); | |
1486 | CMD(disassoc, DISASSOCIATE); | |
1487 | CMD(join_ibss, JOIN_IBSS); | |
1488 | CMD(join_mesh, JOIN_MESH); | |
1489 | CMD(set_pmksa, SET_PMKSA); | |
1490 | CMD(del_pmksa, DEL_PMKSA); | |
1491 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1b8ec87a | 1492 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
3713b4e3 JB |
1493 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
1494 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1495 | CMD(mgmt_tx, FRAME); | |
1496 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1b8ec87a | 1497 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
3713b4e3 JB |
1498 | i++; |
1499 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1500 | goto nla_put_failure; |
2e161f78 | 1501 | } |
1b8ec87a ZG |
1502 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
1503 | rdev->ops->join_mesh) { | |
3713b4e3 JB |
1504 | i++; |
1505 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1506 | goto nla_put_failure; | |
1507 | } | |
1508 | CMD(set_wds_peer, SET_WDS_PEER); | |
1b8ec87a | 1509 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
3713b4e3 JB |
1510 | CMD(tdls_mgmt, TDLS_MGMT); |
1511 | CMD(tdls_oper, TDLS_OPER); | |
1512 | } | |
1b8ec87a | 1513 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
3713b4e3 JB |
1514 | CMD(sched_scan_start, START_SCHED_SCAN); |
1515 | CMD(probe_client, PROBE_CLIENT); | |
1516 | CMD(set_noack_map, SET_NOACK_MAP); | |
1b8ec87a | 1517 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
3713b4e3 JB |
1518 | i++; |
1519 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1520 | goto nla_put_failure; | |
1521 | } | |
1522 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1523 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
02df00eb JB |
1524 | #ifdef CONFIG_NL80211_TESTMODE |
1525 | CMD(testmode_cmd, TESTMODE); | |
1526 | #endif | |
86e8cf98 | 1527 | if (state->split) { |
5de17984 AS |
1528 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1529 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 1530 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 1531 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 1532 | CMD(set_qos_map, SET_QOS_MAP); |
723e73ac JB |
1533 | if (rdev->wiphy.features & |
1534 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | |
960d01ac | 1535 | CMD(add_tx_ts, ADD_TX_TS); |
5de17984 | 1536 | } |
02df00eb | 1537 | /* add into the if now */ |
3713b4e3 | 1538 | #undef CMD |
ff1b6e69 | 1539 | |
1b8ec87a | 1540 | if (rdev->ops->connect || rdev->ops->auth) { |
3713b4e3 JB |
1541 | i++; |
1542 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1543 | goto nla_put_failure; |
ff1b6e69 JB |
1544 | } |
1545 | ||
1b8ec87a | 1546 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
3713b4e3 JB |
1547 | i++; |
1548 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1549 | goto nla_put_failure; | |
1550 | } | |
1551 | ||
1552 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1553 | state->split_start++; |
1554 | if (state->split) | |
3713b4e3 JB |
1555 | break; |
1556 | case 5: | |
1b8ec87a ZG |
1557 | if (rdev->ops->remain_on_channel && |
1558 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
1559 | nla_put_u32(msg, |
1560 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 1561 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
1562 | goto nla_put_failure; |
1563 | ||
1b8ec87a | 1564 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
1565 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
1566 | goto nla_put_failure; | |
1567 | ||
1568 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1569 | goto nla_put_failure; | |
86e8cf98 JB |
1570 | state->split_start++; |
1571 | if (state->split) | |
3713b4e3 JB |
1572 | break; |
1573 | case 6: | |
1574 | #ifdef CONFIG_PM | |
1b8ec87a | 1575 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 1576 | goto nla_put_failure; |
86e8cf98 JB |
1577 | state->split_start++; |
1578 | if (state->split) | |
3713b4e3 JB |
1579 | break; |
1580 | #else | |
86e8cf98 | 1581 | state->split_start++; |
dfb89c56 | 1582 | #endif |
3713b4e3 JB |
1583 | case 7: |
1584 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 1585 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 1586 | goto nla_put_failure; |
ff1b6e69 | 1587 | |
1b8ec87a | 1588 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 1589 | state->split)) |
3713b4e3 | 1590 | goto nla_put_failure; |
7527a782 | 1591 | |
86e8cf98 JB |
1592 | state->split_start++; |
1593 | if (state->split) | |
3713b4e3 JB |
1594 | break; |
1595 | case 8: | |
1b8ec87a | 1596 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 1597 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 1598 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 1599 | goto nla_put_failure; |
7527a782 | 1600 | |
1b8ec87a | 1601 | features = rdev->wiphy.features; |
fe1abafd JB |
1602 | /* |
1603 | * We can only add the per-channel limit information if the | |
1604 | * dump is split, otherwise it makes it too big. Therefore | |
1605 | * only advertise it in that case. | |
1606 | */ | |
86e8cf98 | 1607 | if (state->split) |
fe1abafd JB |
1608 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1609 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1610 | goto nla_put_failure; |
562a7480 | 1611 | |
1b8ec87a | 1612 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 1613 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
1614 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
1615 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 1616 | goto nla_put_failure; |
1f074bd8 | 1617 | |
1b8ec87a ZG |
1618 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1619 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 1620 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 1621 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 1622 | goto nla_put_failure; |
7e7c8926 | 1623 | |
3713b4e3 JB |
1624 | /* |
1625 | * Any information below this point is only available to | |
1626 | * applications that can deal with it being split. This | |
1627 | * helps ensure that newly added capabilities don't break | |
1628 | * older tools by overrunning their buffers. | |
1629 | * | |
1630 | * We still increment split_start so that in the split | |
1631 | * case we'll continue with more data in the next round, | |
1632 | * but break unconditionally so unsplit data stops here. | |
1633 | */ | |
86e8cf98 | 1634 | state->split_start++; |
3713b4e3 JB |
1635 | break; |
1636 | case 9: | |
1b8ec87a | 1637 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 1638 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
1639 | rdev->wiphy.extended_capabilities_len, |
1640 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 1641 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
1642 | rdev->wiphy.extended_capabilities_len, |
1643 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 1644 | goto nla_put_failure; |
a50df0c4 | 1645 | |
1b8ec87a | 1646 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 1647 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
1648 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
1649 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
1650 | goto nla_put_failure; |
1651 | ||
be29b99a AK |
1652 | state->split_start++; |
1653 | break; | |
1654 | case 10: | |
1b8ec87a | 1655 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
1656 | goto nla_put_failure; |
1657 | ||
1b8ec87a | 1658 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
1659 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
1660 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1661 | goto nla_put_failure; | |
b43504cf | 1662 | |
1b8ec87a | 1663 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 1664 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 1665 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
1666 | goto nla_put_failure; |
1667 | ||
ad7e718c JB |
1668 | state->split_start++; |
1669 | break; | |
1670 | case 11: | |
1b8ec87a | 1671 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
1672 | const struct nl80211_vendor_cmd_info *info; |
1673 | struct nlattr *nested; | |
1674 | ||
1675 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1676 | if (!nested) | |
1677 | goto nla_put_failure; | |
1678 | ||
1b8ec87a ZG |
1679 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
1680 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
1681 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1682 | goto nla_put_failure; | |
1683 | } | |
1684 | nla_nest_end(msg, nested); | |
1685 | } | |
1686 | ||
1b8ec87a | 1687 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
1688 | const struct nl80211_vendor_cmd_info *info; |
1689 | struct nlattr *nested; | |
ad7e718c | 1690 | |
567ffc35 JB |
1691 | nested = nla_nest_start(msg, |
1692 | NL80211_ATTR_VENDOR_EVENTS); | |
1693 | if (!nested) | |
ad7e718c | 1694 | goto nla_put_failure; |
567ffc35 | 1695 | |
1b8ec87a ZG |
1696 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
1697 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
1698 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1699 | goto nla_put_failure; | |
1700 | } | |
1701 | nla_nest_end(msg, nested); | |
1702 | } | |
9a774c78 AO |
1703 | state->split_start++; |
1704 | break; | |
1705 | case 12: | |
1706 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
1707 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
1708 | rdev->wiphy.max_num_csa_counters)) | |
1709 | goto nla_put_failure; | |
01e0daa4 | 1710 | |
1bdd716c AN |
1711 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
1712 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
1713 | goto nla_put_failure; | |
1714 | ||
d75bb06b GKS |
1715 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
1716 | sizeof(rdev->wiphy.ext_features), | |
1717 | rdev->wiphy.ext_features)) | |
1718 | goto nla_put_failure; | |
1719 | ||
3713b4e3 | 1720 | /* done */ |
86e8cf98 | 1721 | state->split_start = 0; |
3713b4e3 JB |
1722 | break; |
1723 | } | |
3bb20556 | 1724 | finish: |
053c095a JB |
1725 | genlmsg_end(msg, hdr); |
1726 | return 0; | |
55682965 JB |
1727 | |
1728 | nla_put_failure: | |
bc3ed28c TG |
1729 | genlmsg_cancel(msg, hdr); |
1730 | return -EMSGSIZE; | |
55682965 JB |
1731 | } |
1732 | ||
86e8cf98 JB |
1733 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1734 | struct netlink_callback *cb, | |
1735 | struct nl80211_dump_wiphy_state *state) | |
1736 | { | |
1737 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1738 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1739 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1740 | /* ignore parse errors for backward compatibility */ | |
1741 | if (ret) | |
1742 | return 0; | |
1743 | ||
1744 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1745 | if (tb[NL80211_ATTR_WIPHY]) | |
1746 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1747 | if (tb[NL80211_ATTR_WDEV]) | |
1748 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1749 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1750 | struct net_device *netdev; | |
1751 | struct cfg80211_registered_device *rdev; | |
1752 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1753 | ||
7f2b8562 | 1754 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1755 | if (!netdev) |
1756 | return -ENODEV; | |
1757 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1758 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1759 | netdev->ieee80211_ptr->wiphy); |
1760 | state->filter_wiphy = rdev->wiphy_idx; | |
1761 | } | |
86e8cf98 JB |
1762 | } |
1763 | ||
1764 | return 0; | |
1765 | } | |
1766 | ||
55682965 JB |
1767 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1768 | { | |
645e77de | 1769 | int idx = 0, ret; |
86e8cf98 | 1770 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1771 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1772 | |
5fe231e8 | 1773 | rtnl_lock(); |
86e8cf98 JB |
1774 | if (!state) { |
1775 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1776 | if (!state) { |
1777 | rtnl_unlock(); | |
86e8cf98 | 1778 | return -ENOMEM; |
3713b4e3 | 1779 | } |
86e8cf98 JB |
1780 | state->filter_wiphy = -1; |
1781 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1782 | if (ret) { | |
1783 | kfree(state); | |
1784 | rtnl_unlock(); | |
1785 | return ret; | |
3713b4e3 | 1786 | } |
86e8cf98 | 1787 | cb->args[0] = (long)state; |
3713b4e3 JB |
1788 | } |
1789 | ||
1b8ec87a ZG |
1790 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1791 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1792 | continue; |
86e8cf98 | 1793 | if (++idx <= state->start) |
55682965 | 1794 | continue; |
86e8cf98 | 1795 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1796 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1797 | continue; |
1798 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1799 | do { | |
3bb20556 JB |
1800 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
1801 | skb, | |
3713b4e3 JB |
1802 | NETLINK_CB(cb->skb).portid, |
1803 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1804 | NLM_F_MULTI, state); |
3713b4e3 JB |
1805 | if (ret < 0) { |
1806 | /* | |
1807 | * If sending the wiphy data didn't fit (ENOBUFS | |
1808 | * or EMSGSIZE returned), this SKB is still | |
1809 | * empty (so it's not too big because another | |
1810 | * wiphy dataset is already in the skb) and | |
1811 | * we've not tried to adjust the dump allocation | |
1812 | * yet ... then adjust the alloc size to be | |
1813 | * bigger, and return 1 but with the empty skb. | |
1814 | * This results in an empty message being RX'ed | |
1815 | * in userspace, but that is ignored. | |
1816 | * | |
1817 | * We can then retry with the larger buffer. | |
1818 | */ | |
1819 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1820 | !skb->len && !state->split && |
3713b4e3 JB |
1821 | cb->min_dump_alloc < 4096) { |
1822 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1823 | state->split_start = 0; |
d98cae64 | 1824 | rtnl_unlock(); |
3713b4e3 JB |
1825 | return 1; |
1826 | } | |
1827 | idx--; | |
1828 | break; | |
645e77de | 1829 | } |
86e8cf98 | 1830 | } while (state->split_start > 0); |
3713b4e3 | 1831 | break; |
55682965 | 1832 | } |
5fe231e8 | 1833 | rtnl_unlock(); |
55682965 | 1834 | |
86e8cf98 | 1835 | state->start = idx; |
55682965 JB |
1836 | |
1837 | return skb->len; | |
1838 | } | |
1839 | ||
86e8cf98 JB |
1840 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1841 | { | |
1842 | kfree((void *)cb->args[0]); | |
1843 | return 0; | |
1844 | } | |
1845 | ||
55682965 JB |
1846 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1847 | { | |
1848 | struct sk_buff *msg; | |
1b8ec87a | 1849 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 1850 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1851 | |
645e77de | 1852 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1853 | if (!msg) |
4c476991 | 1854 | return -ENOMEM; |
55682965 | 1855 | |
3bb20556 JB |
1856 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
1857 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 1858 | &state) < 0) { |
4c476991 JB |
1859 | nlmsg_free(msg); |
1860 | return -ENOBUFS; | |
1861 | } | |
55682965 | 1862 | |
134e6375 | 1863 | return genlmsg_reply(msg, info); |
55682965 JB |
1864 | } |
1865 | ||
31888487 JM |
1866 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1867 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1868 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1869 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1870 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1871 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1872 | }; | |
1873 | ||
1874 | static int parse_txq_params(struct nlattr *tb[], | |
1875 | struct ieee80211_txq_params *txq_params) | |
1876 | { | |
a3304b0a | 1877 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1878 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1879 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1880 | return -EINVAL; | |
1881 | ||
a3304b0a | 1882 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1883 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1884 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1885 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1886 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1887 | ||
a3304b0a JB |
1888 | if (txq_params->ac >= NL80211_NUM_ACS) |
1889 | return -EINVAL; | |
1890 | ||
31888487 JM |
1891 | return 0; |
1892 | } | |
1893 | ||
f444de05 JB |
1894 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1895 | { | |
1896 | /* | |
cc1d2806 JB |
1897 | * You can only set the channel explicitly for WDS interfaces, |
1898 | * all others have their channel managed via their respective | |
1899 | * "establish a connection" command (connect, join, ...) | |
1900 | * | |
1901 | * For AP/GO and mesh mode, the channel can be set with the | |
1902 | * channel userspace API, but is only stored and passed to the | |
1903 | * low-level driver when the AP starts or the mesh is joined. | |
1904 | * This is for backward compatibility, userspace can also give | |
1905 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1906 | * |
1907 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1908 | * whatever else is going on, so they have their own special |
1909 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1910 | */ |
1911 | return !wdev || | |
1912 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1913 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1914 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1915 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1916 | } |
1917 | ||
683b6d3b JB |
1918 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1919 | struct genl_info *info, | |
1920 | struct cfg80211_chan_def *chandef) | |
1921 | { | |
dbeca2ea | 1922 | u32 control_freq; |
683b6d3b JB |
1923 | |
1924 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1925 | return -EINVAL; | |
1926 | ||
1927 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1928 | ||
1929 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1930 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1931 | chandef->center_freq1 = control_freq; | |
1932 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1933 | |
1934 | /* Primary channel not allowed */ | |
1935 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1936 | return -EINVAL; | |
1937 | ||
3d9d1d66 JB |
1938 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1939 | enum nl80211_channel_type chantype; | |
1940 | ||
1941 | chantype = nla_get_u32( | |
1942 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1943 | ||
1944 | switch (chantype) { | |
1945 | case NL80211_CHAN_NO_HT: | |
1946 | case NL80211_CHAN_HT20: | |
1947 | case NL80211_CHAN_HT40PLUS: | |
1948 | case NL80211_CHAN_HT40MINUS: | |
1949 | cfg80211_chandef_create(chandef, chandef->chan, | |
1950 | chantype); | |
1951 | break; | |
1952 | default: | |
1953 | return -EINVAL; | |
1954 | } | |
1955 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1956 | chandef->width = | |
1957 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1958 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1959 | chandef->center_freq1 = | |
1960 | nla_get_u32( | |
1961 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1962 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1963 | chandef->center_freq2 = | |
1964 | nla_get_u32( | |
1965 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1966 | } | |
1967 | ||
9f5e8f6e | 1968 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1969 | return -EINVAL; |
1970 | ||
9f5e8f6e JB |
1971 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1972 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1973 | return -EINVAL; |
1974 | ||
2f301ab2 SW |
1975 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1976 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1977 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1978 | return -EINVAL; | |
1979 | ||
683b6d3b JB |
1980 | return 0; |
1981 | } | |
1982 | ||
f444de05 | 1983 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 1984 | struct net_device *dev, |
f444de05 JB |
1985 | struct genl_info *info) |
1986 | { | |
683b6d3b | 1987 | struct cfg80211_chan_def chandef; |
f444de05 | 1988 | int result; |
e8c9bd5b | 1989 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 1990 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 1991 | |
e16821bc JM |
1992 | if (dev) |
1993 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
1994 | if (!nl80211_can_set_dev_channel(wdev)) |
1995 | return -EOPNOTSUPP; | |
e16821bc JM |
1996 | if (wdev) |
1997 | iftype = wdev->iftype; | |
f444de05 | 1998 | |
683b6d3b JB |
1999 | result = nl80211_parse_chandef(rdev, info, &chandef); |
2000 | if (result) | |
2001 | return result; | |
f444de05 | 2002 | |
e8c9bd5b | 2003 | switch (iftype) { |
aa430da4 JB |
2004 | case NL80211_IFTYPE_AP: |
2005 | case NL80211_IFTYPE_P2P_GO: | |
174e0cd2 | 2006 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
aa430da4 JB |
2007 | result = -EINVAL; |
2008 | break; | |
2009 | } | |
e16821bc JM |
2010 | if (wdev->beacon_interval) { |
2011 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
2012 | !(rdev->wiphy.features & | |
2013 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
2014 | result = -EBUSY; | |
2015 | break; | |
2016 | } | |
2017 | ||
2018 | /* Only allow dynamic channel width changes */ | |
2019 | if (chandef.chan != wdev->preset_chandef.chan) { | |
2020 | result = -EBUSY; | |
2021 | break; | |
2022 | } | |
2023 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
2024 | if (result) | |
2025 | break; | |
2026 | } | |
683b6d3b | 2027 | wdev->preset_chandef = chandef; |
aa430da4 JB |
2028 | result = 0; |
2029 | break; | |
cc1d2806 | 2030 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 2031 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 2032 | break; |
e8c9bd5b | 2033 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 2034 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 2035 | break; |
aa430da4 | 2036 | default: |
e8c9bd5b | 2037 | result = -EINVAL; |
f444de05 | 2038 | } |
f444de05 JB |
2039 | |
2040 | return result; | |
2041 | } | |
2042 | ||
2043 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2044 | { | |
4c476991 JB |
2045 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2046 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2047 | |
e16821bc | 2048 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2049 | } |
2050 | ||
e8347eba BJ |
2051 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2052 | { | |
43b19952 JB |
2053 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2054 | struct net_device *dev = info->user_ptr[1]; | |
2055 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2056 | const u8 *bssid; |
e8347eba BJ |
2057 | |
2058 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2059 | return -EINVAL; | |
2060 | ||
43b19952 JB |
2061 | if (netif_running(dev)) |
2062 | return -EBUSY; | |
e8347eba | 2063 | |
43b19952 JB |
2064 | if (!rdev->ops->set_wds_peer) |
2065 | return -EOPNOTSUPP; | |
e8347eba | 2066 | |
43b19952 JB |
2067 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2068 | return -EOPNOTSUPP; | |
e8347eba BJ |
2069 | |
2070 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2071 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2072 | } |
2073 | ||
2074 | ||
55682965 JB |
2075 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2076 | { | |
2077 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2078 | struct net_device *netdev = NULL; |
2079 | struct wireless_dev *wdev; | |
a1e567c8 | 2080 | int result = 0, rem_txq_params = 0; |
31888487 | 2081 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2082 | u32 changed; |
2083 | u8 retry_short = 0, retry_long = 0; | |
2084 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2085 | u8 coverage_class = 0; |
55682965 | 2086 | |
5fe231e8 JB |
2087 | ASSERT_RTNL(); |
2088 | ||
f444de05 JB |
2089 | /* |
2090 | * Try to find the wiphy and netdev. Normally this | |
2091 | * function shouldn't need the netdev, but this is | |
2092 | * done for backward compatibility -- previously | |
2093 | * setting the channel was done per wiphy, but now | |
2094 | * it is per netdev. Previous userland like hostapd | |
2095 | * also passed a netdev to set_wiphy, so that it is | |
2096 | * possible to let that go to the right netdev! | |
2097 | */ | |
4bbf4d56 | 2098 | |
f444de05 JB |
2099 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2100 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2101 | ||
7f2b8562 | 2102 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2103 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2104 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2105 | else |
f444de05 | 2106 | netdev = NULL; |
4bbf4d56 JB |
2107 | } |
2108 | ||
f444de05 | 2109 | if (!netdev) { |
878d9ec7 JB |
2110 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2111 | info->attrs); | |
5fe231e8 | 2112 | if (IS_ERR(rdev)) |
4c476991 | 2113 | return PTR_ERR(rdev); |
f444de05 JB |
2114 | wdev = NULL; |
2115 | netdev = NULL; | |
2116 | result = 0; | |
71fe96bf | 2117 | } else |
f444de05 | 2118 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2119 | |
2120 | /* | |
2121 | * end workaround code, by now the rdev is available | |
2122 | * and locked, and wdev may or may not be NULL. | |
2123 | */ | |
4bbf4d56 JB |
2124 | |
2125 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2126 | result = cfg80211_dev_rename( |
2127 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2128 | |
4bbf4d56 | 2129 | if (result) |
7f2b8562 | 2130 | return result; |
31888487 JM |
2131 | |
2132 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2133 | struct ieee80211_txq_params txq_params; | |
2134 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2135 | ||
7f2b8562 YX |
2136 | if (!rdev->ops->set_txq_params) |
2137 | return -EOPNOTSUPP; | |
31888487 | 2138 | |
7f2b8562 YX |
2139 | if (!netdev) |
2140 | return -EINVAL; | |
f70f01c2 | 2141 | |
133a3ff2 | 2142 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2143 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2144 | return -EINVAL; | |
133a3ff2 | 2145 | |
7f2b8562 YX |
2146 | if (!netif_running(netdev)) |
2147 | return -ENETDOWN; | |
2b5f8b0b | 2148 | |
31888487 JM |
2149 | nla_for_each_nested(nl_txq_params, |
2150 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2151 | rem_txq_params) { | |
ae811e21 JB |
2152 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2153 | nla_data(nl_txq_params), | |
2154 | nla_len(nl_txq_params), | |
2155 | txq_params_policy); | |
2156 | if (result) | |
2157 | return result; | |
31888487 JM |
2158 | result = parse_txq_params(tb, &txq_params); |
2159 | if (result) | |
7f2b8562 | 2160 | return result; |
31888487 | 2161 | |
e35e4d28 HG |
2162 | result = rdev_set_txq_params(rdev, netdev, |
2163 | &txq_params); | |
31888487 | 2164 | if (result) |
7f2b8562 | 2165 | return result; |
31888487 JM |
2166 | } |
2167 | } | |
55682965 | 2168 | |
72bdcf34 | 2169 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2170 | result = __nl80211_set_channel( |
2171 | rdev, | |
2172 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2173 | info); | |
72bdcf34 | 2174 | if (result) |
7f2b8562 | 2175 | return result; |
72bdcf34 JM |
2176 | } |
2177 | ||
98d2ff8b | 2178 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2179 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2180 | enum nl80211_tx_power_setting type; |
2181 | int idx, mbm = 0; | |
2182 | ||
c8442118 JB |
2183 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2184 | txp_wdev = NULL; | |
2185 | ||
7f2b8562 YX |
2186 | if (!rdev->ops->set_tx_power) |
2187 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2188 | |
2189 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2190 | type = nla_get_u32(info->attrs[idx]); | |
2191 | ||
2192 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2193 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2194 | return -EINVAL; | |
98d2ff8b JO |
2195 | |
2196 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2197 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2198 | mbm = nla_get_u32(info->attrs[idx]); | |
2199 | } | |
2200 | ||
c8442118 | 2201 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2202 | if (result) |
7f2b8562 | 2203 | return result; |
98d2ff8b JO |
2204 | } |
2205 | ||
afe0cbf8 BR |
2206 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2207 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2208 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2209 | if ((!rdev->wiphy.available_antennas_tx && |
2210 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2211 | !rdev->ops->set_antenna) |
2212 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2213 | |
2214 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2215 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2216 | ||
a7ffac95 | 2217 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2218 | * available antenna masks, except for the "all" mask */ |
2219 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2220 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2221 | return -EINVAL; | |
a7ffac95 | 2222 | |
7f531e03 BR |
2223 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2224 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2225 | |
e35e4d28 | 2226 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2227 | if (result) |
7f2b8562 | 2228 | return result; |
afe0cbf8 BR |
2229 | } |
2230 | ||
b9a5f8ca JM |
2231 | changed = 0; |
2232 | ||
2233 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2234 | retry_short = nla_get_u8( | |
2235 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2236 | if (retry_short == 0) |
2237 | return -EINVAL; | |
2238 | ||
b9a5f8ca JM |
2239 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2240 | } | |
2241 | ||
2242 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2243 | retry_long = nla_get_u8( | |
2244 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2245 | if (retry_long == 0) |
2246 | return -EINVAL; | |
2247 | ||
b9a5f8ca JM |
2248 | changed |= WIPHY_PARAM_RETRY_LONG; |
2249 | } | |
2250 | ||
2251 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2252 | frag_threshold = nla_get_u32( | |
2253 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2254 | if (frag_threshold < 256) |
2255 | return -EINVAL; | |
2256 | ||
b9a5f8ca JM |
2257 | if (frag_threshold != (u32) -1) { |
2258 | /* | |
2259 | * Fragments (apart from the last one) are required to | |
2260 | * have even length. Make the fragmentation code | |
2261 | * simpler by stripping LSB should someone try to use | |
2262 | * odd threshold value. | |
2263 | */ | |
2264 | frag_threshold &= ~0x1; | |
2265 | } | |
2266 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2267 | } | |
2268 | ||
2269 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2270 | rts_threshold = nla_get_u32( | |
2271 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2272 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2273 | } | |
2274 | ||
81077e82 | 2275 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
3057dbfd LB |
2276 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
2277 | return -EINVAL; | |
2278 | ||
81077e82 LT |
2279 | coverage_class = nla_get_u8( |
2280 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2281 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2282 | } | |
2283 | ||
3057dbfd LB |
2284 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
2285 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | |
2286 | return -EOPNOTSUPP; | |
2287 | ||
2288 | changed |= WIPHY_PARAM_DYN_ACK; | |
81077e82 LT |
2289 | } |
2290 | ||
b9a5f8ca JM |
2291 | if (changed) { |
2292 | u8 old_retry_short, old_retry_long; | |
2293 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2294 | u8 old_coverage_class; |
b9a5f8ca | 2295 | |
7f2b8562 YX |
2296 | if (!rdev->ops->set_wiphy_params) |
2297 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2298 | |
2299 | old_retry_short = rdev->wiphy.retry_short; | |
2300 | old_retry_long = rdev->wiphy.retry_long; | |
2301 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2302 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2303 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2304 | |
2305 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2306 | rdev->wiphy.retry_short = retry_short; | |
2307 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2308 | rdev->wiphy.retry_long = retry_long; | |
2309 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2310 | rdev->wiphy.frag_threshold = frag_threshold; | |
2311 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2312 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2313 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2314 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2315 | |
e35e4d28 | 2316 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2317 | if (result) { |
2318 | rdev->wiphy.retry_short = old_retry_short; | |
2319 | rdev->wiphy.retry_long = old_retry_long; | |
2320 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2321 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2322 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2323 | } |
2324 | } | |
7f2b8562 | 2325 | return 0; |
55682965 JB |
2326 | } |
2327 | ||
71bbc994 JB |
2328 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2329 | { | |
2330 | return (u64)wdev->identifier | | |
f26cbf40 | 2331 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2332 | } |
55682965 | 2333 | |
683b6d3b | 2334 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2335 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2336 | { |
601555cd JB |
2337 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
2338 | return -EINVAL; | |
3d9d1d66 | 2339 | |
683b6d3b JB |
2340 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2341 | chandef->chan->center_freq)) | |
2342 | return -ENOBUFS; | |
3d9d1d66 JB |
2343 | switch (chandef->width) { |
2344 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2345 | case NL80211_CHAN_WIDTH_20: | |
2346 | case NL80211_CHAN_WIDTH_40: | |
2347 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2348 | cfg80211_get_chandef_type(chandef))) | |
2349 | return -ENOBUFS; | |
2350 | break; | |
2351 | default: | |
2352 | break; | |
2353 | } | |
2354 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2355 | return -ENOBUFS; | |
2356 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2357 | return -ENOBUFS; | |
2358 | if (chandef->center_freq2 && | |
2359 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2360 | return -ENOBUFS; |
2361 | return 0; | |
2362 | } | |
2363 | ||
15e47304 | 2364 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2365 | struct cfg80211_registered_device *rdev, |
8f894be2 | 2366 | struct wireless_dev *wdev, bool removal) |
55682965 | 2367 | { |
72fb2abc | 2368 | struct net_device *dev = wdev->netdev; |
8f894be2 | 2369 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
55682965 JB |
2370 | void *hdr; |
2371 | ||
8f894be2 TB |
2372 | if (removal) |
2373 | cmd = NL80211_CMD_DEL_INTERFACE; | |
2374 | ||
2375 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | |
55682965 JB |
2376 | if (!hdr) |
2377 | return -1; | |
2378 | ||
72fb2abc JB |
2379 | if (dev && |
2380 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2381 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2382 | goto nla_put_failure; |
2383 | ||
2384 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2385 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2386 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2387 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2388 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2389 | rdev->devlist_generation ^ | |
2390 | (cfg80211_rdev_list_generation << 2))) | |
2391 | goto nla_put_failure; | |
f5ea9120 | 2392 | |
5b7ccaf3 | 2393 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2394 | int ret; |
2395 | struct cfg80211_chan_def chandef; | |
2396 | ||
2397 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2398 | if (ret == 0) { | |
2399 | if (nl80211_send_chandef(msg, &chandef)) | |
2400 | goto nla_put_failure; | |
2401 | } | |
d91df0e3 PF |
2402 | } |
2403 | ||
b84e7a05 AQ |
2404 | if (wdev->ssid_len) { |
2405 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2406 | goto nla_put_failure; | |
2407 | } | |
2408 | ||
053c095a JB |
2409 | genlmsg_end(msg, hdr); |
2410 | return 0; | |
55682965 JB |
2411 | |
2412 | nla_put_failure: | |
bc3ed28c TG |
2413 | genlmsg_cancel(msg, hdr); |
2414 | return -EMSGSIZE; | |
55682965 JB |
2415 | } |
2416 | ||
2417 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2418 | { | |
2419 | int wp_idx = 0; | |
2420 | int if_idx = 0; | |
2421 | int wp_start = cb->args[0]; | |
2422 | int if_start = cb->args[1]; | |
f5ea9120 | 2423 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2424 | struct wireless_dev *wdev; |
2425 | ||
5fe231e8 | 2426 | rtnl_lock(); |
f5ea9120 JB |
2427 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2428 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2429 | continue; |
bba95fef JB |
2430 | if (wp_idx < wp_start) { |
2431 | wp_idx++; | |
55682965 | 2432 | continue; |
bba95fef | 2433 | } |
55682965 JB |
2434 | if_idx = 0; |
2435 | ||
89a54e48 | 2436 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2437 | if (if_idx < if_start) { |
2438 | if_idx++; | |
55682965 | 2439 | continue; |
bba95fef | 2440 | } |
15e47304 | 2441 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2442 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
8f894be2 | 2443 | rdev, wdev, false) < 0) { |
bba95fef JB |
2444 | goto out; |
2445 | } | |
2446 | if_idx++; | |
55682965 | 2447 | } |
bba95fef JB |
2448 | |
2449 | wp_idx++; | |
55682965 | 2450 | } |
bba95fef | 2451 | out: |
5fe231e8 | 2452 | rtnl_unlock(); |
55682965 JB |
2453 | |
2454 | cb->args[0] = wp_idx; | |
2455 | cb->args[1] = if_idx; | |
2456 | ||
2457 | return skb->len; | |
2458 | } | |
2459 | ||
2460 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2461 | { | |
2462 | struct sk_buff *msg; | |
1b8ec87a | 2463 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2464 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2465 | |
fd2120ca | 2466 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2467 | if (!msg) |
4c476991 | 2468 | return -ENOMEM; |
55682965 | 2469 | |
15e47304 | 2470 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2471 | rdev, wdev, false) < 0) { |
4c476991 JB |
2472 | nlmsg_free(msg); |
2473 | return -ENOBUFS; | |
2474 | } | |
55682965 | 2475 | |
134e6375 | 2476 | return genlmsg_reply(msg, info); |
55682965 JB |
2477 | } |
2478 | ||
66f7ac50 MW |
2479 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2480 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2481 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2482 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2483 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2484 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2485 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2486 | }; |
2487 | ||
2488 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2489 | { | |
2490 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2491 | int flag; | |
2492 | ||
2493 | *mntrflags = 0; | |
2494 | ||
2495 | if (!nla) | |
2496 | return -EINVAL; | |
2497 | ||
2498 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2499 | nla, mntr_flags_policy)) | |
2500 | return -EINVAL; | |
2501 | ||
2502 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2503 | if (flags[flag]) | |
2504 | *mntrflags |= (1<<flag); | |
2505 | ||
2506 | return 0; | |
2507 | } | |
2508 | ||
9bc383de | 2509 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2510 | struct net_device *netdev, u8 use_4addr, |
2511 | enum nl80211_iftype iftype) | |
9bc383de | 2512 | { |
ad4bb6f8 | 2513 | if (!use_4addr) { |
f350a0a8 | 2514 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2515 | return -EBUSY; |
9bc383de | 2516 | return 0; |
ad4bb6f8 | 2517 | } |
9bc383de JB |
2518 | |
2519 | switch (iftype) { | |
2520 | case NL80211_IFTYPE_AP_VLAN: | |
2521 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2522 | return 0; | |
2523 | break; | |
2524 | case NL80211_IFTYPE_STATION: | |
2525 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2526 | return 0; | |
2527 | break; | |
2528 | default: | |
2529 | break; | |
2530 | } | |
2531 | ||
2532 | return -EOPNOTSUPP; | |
2533 | } | |
2534 | ||
55682965 JB |
2535 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2536 | { | |
4c476991 | 2537 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2538 | struct vif_params params; |
e36d56b6 | 2539 | int err; |
04a773ad | 2540 | enum nl80211_iftype otype, ntype; |
4c476991 | 2541 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2542 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2543 | bool change = false; |
55682965 | 2544 | |
2ec600d6 LCC |
2545 | memset(¶ms, 0, sizeof(params)); |
2546 | ||
04a773ad | 2547 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2548 | |
723b038d | 2549 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2550 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2551 | if (otype != ntype) |
ac7f9cfa | 2552 | change = true; |
4c476991 JB |
2553 | if (ntype > NL80211_IFTYPE_MAX) |
2554 | return -EINVAL; | |
723b038d JB |
2555 | } |
2556 | ||
92ffe055 | 2557 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2558 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2559 | ||
4c476991 JB |
2560 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2561 | return -EINVAL; | |
29cbe68c JB |
2562 | if (netif_running(dev)) |
2563 | return -EBUSY; | |
2564 | ||
2565 | wdev_lock(wdev); | |
2566 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2567 | IEEE80211_MAX_MESH_ID_LEN); | |
2568 | wdev->mesh_id_up_len = | |
2569 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2570 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2571 | wdev->mesh_id_up_len); | |
2572 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2573 | } |
2574 | ||
8b787643 FF |
2575 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2576 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2577 | change = true; | |
ad4bb6f8 | 2578 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2579 | if (err) |
4c476991 | 2580 | return err; |
8b787643 FF |
2581 | } else { |
2582 | params.use_4addr = -1; | |
2583 | } | |
2584 | ||
92ffe055 | 2585 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2586 | if (ntype != NL80211_IFTYPE_MONITOR) |
2587 | return -EINVAL; | |
92ffe055 JB |
2588 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2589 | &_flags); | |
ac7f9cfa | 2590 | if (err) |
4c476991 | 2591 | return err; |
ac7f9cfa JB |
2592 | |
2593 | flags = &_flags; | |
2594 | change = true; | |
92ffe055 | 2595 | } |
3b85875a | 2596 | |
18003297 | 2597 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2598 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2599 | return -EOPNOTSUPP; | |
2600 | ||
ac7f9cfa | 2601 | if (change) |
3d54d255 | 2602 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2603 | else |
2604 | err = 0; | |
60719ffd | 2605 | |
9bc383de JB |
2606 | if (!err && params.use_4addr != -1) |
2607 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2608 | ||
55682965 JB |
2609 | return err; |
2610 | } | |
2611 | ||
2612 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2613 | { | |
4c476991 | 2614 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2615 | struct vif_params params; |
84efbb84 | 2616 | struct wireless_dev *wdev; |
8f894be2 | 2617 | struct sk_buff *msg, *event; |
55682965 JB |
2618 | int err; |
2619 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2620 | u32 flags; |
55682965 | 2621 | |
78f22b6a JB |
2622 | /* to avoid failing a new interface creation due to pending removal */ |
2623 | cfg80211_destroy_ifaces(rdev); | |
2624 | ||
2ec600d6 LCC |
2625 | memset(¶ms, 0, sizeof(params)); |
2626 | ||
55682965 JB |
2627 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2628 | return -EINVAL; | |
2629 | ||
2630 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2631 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2632 | if (type > NL80211_IFTYPE_MAX) | |
2633 | return -EINVAL; | |
2634 | } | |
2635 | ||
79c97e97 | 2636 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2637 | !(rdev->wiphy.interface_modes & (1 << type))) |
2638 | return -EOPNOTSUPP; | |
55682965 | 2639 | |
e8f479b1 BG |
2640 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
2641 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && | |
2642 | info->attrs[NL80211_ATTR_MAC]) { | |
1c18f145 AS |
2643 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
2644 | ETH_ALEN); | |
2645 | if (!is_valid_ether_addr(params.macaddr)) | |
2646 | return -EADDRNOTAVAIL; | |
2647 | } | |
2648 | ||
9bc383de | 2649 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2650 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2651 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2652 | if (err) |
4c476991 | 2653 | return err; |
9bc383de | 2654 | } |
8b787643 | 2655 | |
66f7ac50 MW |
2656 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2657 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2658 | &flags); | |
e057d3c3 | 2659 | |
18003297 | 2660 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2661 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2662 | return -EOPNOTSUPP; | |
2663 | ||
a18c7192 JB |
2664 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2665 | if (!msg) | |
2666 | return -ENOMEM; | |
2667 | ||
e35e4d28 HG |
2668 | wdev = rdev_add_virtual_intf(rdev, |
2669 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
6bab2e19 TG |
2670 | NET_NAME_USER, type, err ? NULL : &flags, |
2671 | ¶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: |
42925040 CYY |
4064 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
4065 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) | |
77ee7c89 JB |
4066 | return -EINVAL; |
4067 | break; | |
4068 | } | |
4069 | ||
4070 | return 0; | |
4071 | } | |
4072 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
4073 | ||
5727ef1b | 4074 | /* |
c258d2de | 4075 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 4076 | */ |
80b99899 JB |
4077 | static struct net_device *get_vlan(struct genl_info *info, |
4078 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 4079 | { |
463d0183 | 4080 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
4081 | struct net_device *v; |
4082 | int ret; | |
4083 | ||
4084 | if (!vlanattr) | |
4085 | return NULL; | |
4086 | ||
4087 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
4088 | if (!v) | |
4089 | return ERR_PTR(-ENODEV); | |
4090 | ||
4091 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
4092 | ret = -EINVAL; | |
4093 | goto error; | |
5727ef1b | 4094 | } |
80b99899 | 4095 | |
77ee7c89 JB |
4096 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
4097 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4098 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
4099 | ret = -EINVAL; | |
4100 | goto error; | |
4101 | } | |
4102 | ||
80b99899 JB |
4103 | if (!netif_running(v)) { |
4104 | ret = -ENETDOWN; | |
4105 | goto error; | |
4106 | } | |
4107 | ||
4108 | return v; | |
4109 | error: | |
4110 | dev_put(v); | |
4111 | return ERR_PTR(ret); | |
5727ef1b JB |
4112 | } |
4113 | ||
94e860f1 JB |
4114 | static const struct nla_policy |
4115 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
4116 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
4117 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
4118 | }; | |
4119 | ||
ff276691 JB |
4120 | static int nl80211_parse_sta_wme(struct genl_info *info, |
4121 | struct station_parameters *params) | |
df881293 | 4122 | { |
df881293 JM |
4123 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
4124 | struct nlattr *nla; | |
4125 | int err; | |
4126 | ||
df881293 JM |
4127 | /* parse WME attributes if present */ |
4128 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
4129 | return 0; | |
4130 | ||
4131 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
4132 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
4133 | nl80211_sta_wme_policy); | |
4134 | if (err) | |
4135 | return err; | |
4136 | ||
4137 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
4138 | params->uapsd_queues = nla_get_u8( | |
4139 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4140 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
4141 | return -EINVAL; | |
4142 | ||
4143 | if (tb[NL80211_STA_WME_MAX_SP]) | |
4144 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4145 | ||
4146 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
4147 | return -EINVAL; | |
4148 | ||
4149 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
4150 | ||
4151 | return 0; | |
4152 | } | |
4153 | ||
c01fc9ad SD |
4154 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4155 | struct station_parameters *params) | |
4156 | { | |
4157 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4158 | params->supported_channels = | |
4159 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4160 | params->supported_channels_len = | |
4161 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4162 | /* | |
4163 | * Need to include at least one (first channel, number of | |
4164 | * channels) tuple for each subband, and must have proper | |
4165 | * tuples for the rest of the data as well. | |
4166 | */ | |
4167 | if (params->supported_channels_len < 2) | |
4168 | return -EINVAL; | |
4169 | if (params->supported_channels_len % 2) | |
4170 | return -EINVAL; | |
4171 | } | |
4172 | ||
4173 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4174 | params->supported_oper_classes = | |
4175 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4176 | params->supported_oper_classes_len = | |
4177 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4178 | /* | |
4179 | * The value of the Length field of the Supported Operating | |
4180 | * Classes element is between 2 and 253. | |
4181 | */ | |
4182 | if (params->supported_oper_classes_len < 2 || | |
4183 | params->supported_oper_classes_len > 253) | |
4184 | return -EINVAL; | |
4185 | } | |
4186 | return 0; | |
4187 | } | |
4188 | ||
ff276691 JB |
4189 | static int nl80211_set_station_tdls(struct genl_info *info, |
4190 | struct station_parameters *params) | |
4191 | { | |
c01fc9ad | 4192 | int err; |
ff276691 | 4193 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4194 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4195 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4196 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4197 | params->ht_capa = | |
4198 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4199 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4200 | params->vht_capa = | |
4201 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4202 | ||
c01fc9ad SD |
4203 | err = nl80211_parse_sta_channel_info(info, params); |
4204 | if (err) | |
4205 | return err; | |
4206 | ||
ff276691 JB |
4207 | return nl80211_parse_sta_wme(info, params); |
4208 | } | |
4209 | ||
5727ef1b JB |
4210 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4211 | { | |
4c476991 | 4212 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4213 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4214 | struct station_parameters params; |
77ee7c89 JB |
4215 | u8 *mac_addr; |
4216 | int err; | |
5727ef1b JB |
4217 | |
4218 | memset(¶ms, 0, sizeof(params)); | |
4219 | ||
4220 | params.listen_interval = -1; | |
4221 | ||
77ee7c89 JB |
4222 | if (!rdev->ops->change_station) |
4223 | return -EOPNOTSUPP; | |
4224 | ||
5727ef1b JB |
4225 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4226 | return -EINVAL; | |
4227 | ||
4228 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4229 | return -EINVAL; | |
4230 | ||
4231 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4232 | ||
4233 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4234 | params.supported_rates = | |
4235 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4236 | params.supported_rates_len = | |
4237 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4238 | } | |
4239 | ||
9d62a986 JM |
4240 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4241 | params.capability = | |
4242 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4243 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4244 | } | |
4245 | ||
4246 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4247 | params.ext_capab = | |
4248 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4249 | params.ext_capab_len = | |
4250 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4251 | } | |
4252 | ||
df881293 | 4253 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 4254 | return -EINVAL; |
36aedc90 | 4255 | |
bdd3ae3d | 4256 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4257 | return -EINVAL; |
4258 | ||
f8bacc21 | 4259 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4260 | params.plink_action = |
f8bacc21 JB |
4261 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4262 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4263 | return -EINVAL; | |
4264 | } | |
2ec600d6 | 4265 | |
f8bacc21 | 4266 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4267 | params.plink_state = |
f8bacc21 JB |
4268 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4269 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4270 | return -EINVAL; | |
4271 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
4272 | } | |
9c3990aa | 4273 | |
3b1c5a53 MP |
4274 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4275 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4276 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4277 | ||
4278 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4279 | pm > NL80211_MESH_POWER_MAX) | |
4280 | return -EINVAL; | |
4281 | ||
4282 | params.local_pm = pm; | |
4283 | } | |
4284 | ||
77ee7c89 JB |
4285 | /* Include parameters for TDLS peer (will check later) */ |
4286 | err = nl80211_set_station_tdls(info, ¶ms); | |
4287 | if (err) | |
4288 | return err; | |
4289 | ||
4290 | params.vlan = get_vlan(info, rdev); | |
4291 | if (IS_ERR(params.vlan)) | |
4292 | return PTR_ERR(params.vlan); | |
4293 | ||
a97f4424 JB |
4294 | switch (dev->ieee80211_ptr->iftype) { |
4295 | case NL80211_IFTYPE_AP: | |
4296 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4297 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4298 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4299 | case NL80211_IFTYPE_STATION: |
267335d6 | 4300 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4301 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4302 | break; |
4303 | default: | |
77ee7c89 JB |
4304 | err = -EOPNOTSUPP; |
4305 | goto out_put_vlan; | |
034d655e JB |
4306 | } |
4307 | ||
77ee7c89 | 4308 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4309 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4310 | |
77ee7c89 | 4311 | out_put_vlan: |
5727ef1b JB |
4312 | if (params.vlan) |
4313 | dev_put(params.vlan); | |
3b85875a | 4314 | |
5727ef1b JB |
4315 | return err; |
4316 | } | |
4317 | ||
4318 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4319 | { | |
4c476991 | 4320 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4321 | int err; |
4c476991 | 4322 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4323 | struct station_parameters params; |
4324 | u8 *mac_addr = NULL; | |
4325 | ||
4326 | memset(¶ms, 0, sizeof(params)); | |
4327 | ||
984c311b JB |
4328 | if (!rdev->ops->add_station) |
4329 | return -EOPNOTSUPP; | |
4330 | ||
5727ef1b JB |
4331 | if (!info->attrs[NL80211_ATTR_MAC]) |
4332 | return -EINVAL; | |
4333 | ||
5727ef1b JB |
4334 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4335 | return -EINVAL; | |
4336 | ||
4337 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4338 | return -EINVAL; | |
4339 | ||
5e4b6f56 JM |
4340 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4341 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4342 | return -EINVAL; |
4343 | ||
5727ef1b JB |
4344 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4345 | params.supported_rates = | |
4346 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4347 | params.supported_rates_len = | |
4348 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4349 | params.listen_interval = | |
4350 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4351 | |
3d124ea2 | 4352 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4353 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4354 | else |
4355 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4356 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4357 | return -EINVAL; | |
51b50fbe | 4358 | |
9d62a986 JM |
4359 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4360 | params.capability = | |
4361 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4362 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4363 | } | |
4364 | ||
4365 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4366 | params.ext_capab = | |
4367 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4368 | params.ext_capab_len = | |
4369 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4370 | } | |
4371 | ||
36aedc90 JM |
4372 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4373 | params.ht_capa = | |
4374 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4375 | |
f461be3e MP |
4376 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4377 | params.vht_capa = | |
4378 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4379 | ||
60f4a7b1 MK |
4380 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4381 | params.opmode_notif_used = true; | |
4382 | params.opmode_notif = | |
4383 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4384 | } | |
4385 | ||
f8bacc21 | 4386 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4387 | params.plink_action = |
f8bacc21 JB |
4388 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4389 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4390 | return -EINVAL; | |
4391 | } | |
96b78dff | 4392 | |
c01fc9ad SD |
4393 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4394 | if (err) | |
4395 | return err; | |
4396 | ||
ff276691 JB |
4397 | err = nl80211_parse_sta_wme(info, ¶ms); |
4398 | if (err) | |
4399 | return err; | |
bdd90d5e | 4400 | |
bdd3ae3d | 4401 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4402 | return -EINVAL; |
4403 | ||
496fcc29 JB |
4404 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
4405 | * as userspace might just pass through the capabilities from the IEs | |
4406 | * directly, rather than enforcing this restriction and returning an | |
4407 | * error in this case. | |
4408 | */ | |
4409 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { | |
4410 | params.ht_capa = NULL; | |
4411 | params.vht_capa = NULL; | |
4412 | } | |
4413 | ||
77ee7c89 JB |
4414 | /* When you run into this, adjust the code below for the new flag */ |
4415 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4416 | ||
bdd90d5e JB |
4417 | switch (dev->ieee80211_ptr->iftype) { |
4418 | case NL80211_IFTYPE_AP: | |
4419 | case NL80211_IFTYPE_AP_VLAN: | |
4420 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4421 | /* ignore WME attributes if iface/sta is not capable */ |
4422 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4423 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4424 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4425 | |
bdd90d5e | 4426 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4427 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4428 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4429 | return -EINVAL; |
bdd90d5e JB |
4430 | /* but don't bother the driver with it */ |
4431 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4432 | |
d582cffb JB |
4433 | /* allow authenticated/associated only if driver handles it */ |
4434 | if (!(rdev->wiphy.features & | |
4435 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4436 | params.sta_flags_mask & | |
4437 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4438 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4439 | return -EINVAL; | |
4440 | ||
bdd90d5e JB |
4441 | /* must be last in here for error handling */ |
4442 | params.vlan = get_vlan(info, rdev); | |
4443 | if (IS_ERR(params.vlan)) | |
4444 | return PTR_ERR(params.vlan); | |
4445 | break; | |
4446 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4447 | /* ignore uAPSD data */ |
4448 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4449 | ||
d582cffb JB |
4450 | /* associated is disallowed */ |
4451 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4452 | return -EINVAL; | |
bdd90d5e | 4453 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4454 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4455 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4456 | return -EINVAL; |
4457 | break; | |
4458 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4459 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4460 | /* ignore uAPSD data */ |
4461 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4462 | ||
77ee7c89 JB |
4463 | /* these are disallowed */ |
4464 | if (params.sta_flags_mask & | |
4465 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4466 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4467 | return -EINVAL; |
bdd90d5e JB |
4468 | /* Only TDLS peers can be added */ |
4469 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4470 | return -EINVAL; | |
4471 | /* Can only add if TDLS ... */ | |
4472 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4473 | return -EOPNOTSUPP; | |
4474 | /* ... with external setup is supported */ | |
4475 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4476 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4477 | /* |
4478 | * Older wpa_supplicant versions always mark the TDLS peer | |
4479 | * as authorized, but it shouldn't yet be. | |
4480 | */ | |
4481 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4482 | break; |
4483 | default: | |
4484 | return -EOPNOTSUPP; | |
c75786c9 EP |
4485 | } |
4486 | ||
bdd90d5e | 4487 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4488 | |
e35e4d28 | 4489 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4490 | |
5727ef1b JB |
4491 | if (params.vlan) |
4492 | dev_put(params.vlan); | |
5727ef1b JB |
4493 | return err; |
4494 | } | |
4495 | ||
4496 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4497 | { | |
4c476991 JB |
4498 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4499 | struct net_device *dev = info->user_ptr[1]; | |
89c771e5 JM |
4500 | struct station_del_parameters params; |
4501 | ||
4502 | memset(¶ms, 0, sizeof(params)); | |
5727ef1b JB |
4503 | |
4504 | if (info->attrs[NL80211_ATTR_MAC]) | |
89c771e5 | 4505 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5727ef1b | 4506 | |
e80cf853 | 4507 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4508 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4509 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4510 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4511 | return -EINVAL; | |
5727ef1b | 4512 | |
4c476991 JB |
4513 | if (!rdev->ops->del_station) |
4514 | return -EOPNOTSUPP; | |
3b85875a | 4515 | |
98856866 JM |
4516 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
4517 | params.subtype = | |
4518 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | |
4519 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | |
4520 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | |
4521 | return -EINVAL; | |
4522 | } else { | |
4523 | /* Default to Deauthentication frame */ | |
4524 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | |
4525 | } | |
4526 | ||
4527 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | |
4528 | params.reason_code = | |
4529 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
4530 | if (params.reason_code == 0) | |
4531 | return -EINVAL; /* 0 is reserved */ | |
4532 | } else { | |
4533 | /* Default to reason code 2 */ | |
4534 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | |
4535 | } | |
4536 | ||
89c771e5 | 4537 | return rdev_del_station(rdev, dev, ¶ms); |
5727ef1b JB |
4538 | } |
4539 | ||
15e47304 | 4540 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4541 | int flags, struct net_device *dev, |
4542 | u8 *dst, u8 *next_hop, | |
4543 | struct mpath_info *pinfo) | |
4544 | { | |
4545 | void *hdr; | |
4546 | struct nlattr *pinfoattr; | |
4547 | ||
1ef4c850 | 4548 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
2ec600d6 LCC |
4549 | if (!hdr) |
4550 | return -1; | |
4551 | ||
9360ffd1 DM |
4552 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4553 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4554 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4555 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4556 | goto nla_put_failure; | |
f5ea9120 | 4557 | |
2ec600d6 LCC |
4558 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4559 | if (!pinfoattr) | |
4560 | goto nla_put_failure; | |
9360ffd1 DM |
4561 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4562 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4563 | pinfo->frame_qlen)) | |
4564 | goto nla_put_failure; | |
4565 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4566 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4567 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4568 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4569 | pinfo->metric)) || | |
4570 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4571 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4572 | pinfo->exptime)) || | |
4573 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4574 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4575 | pinfo->flags)) || | |
4576 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4577 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4578 | pinfo->discovery_timeout)) || | |
4579 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4580 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4581 | pinfo->discovery_retries))) | |
4582 | goto nla_put_failure; | |
2ec600d6 LCC |
4583 | |
4584 | nla_nest_end(msg, pinfoattr); | |
4585 | ||
053c095a JB |
4586 | genlmsg_end(msg, hdr); |
4587 | return 0; | |
2ec600d6 LCC |
4588 | |
4589 | nla_put_failure: | |
bc3ed28c TG |
4590 | genlmsg_cancel(msg, hdr); |
4591 | return -EMSGSIZE; | |
2ec600d6 LCC |
4592 | } |
4593 | ||
4594 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4595 | struct netlink_callback *cb) |
2ec600d6 | 4596 | { |
2ec600d6 | 4597 | struct mpath_info pinfo; |
1b8ec87a | 4598 | struct cfg80211_registered_device *rdev; |
97990a06 | 4599 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4600 | u8 dst[ETH_ALEN]; |
4601 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4602 | int path_idx = cb->args[2]; |
2ec600d6 | 4603 | int err; |
2ec600d6 | 4604 | |
1b8ec87a | 4605 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
4606 | if (err) |
4607 | return err; | |
bba95fef | 4608 | |
1b8ec87a | 4609 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 4610 | err = -EOPNOTSUPP; |
bba95fef JB |
4611 | goto out_err; |
4612 | } | |
4613 | ||
97990a06 | 4614 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4615 | err = -EOPNOTSUPP; |
0448b5fc | 4616 | goto out_err; |
eec60b03 JM |
4617 | } |
4618 | ||
bba95fef | 4619 | while (1) { |
1b8ec87a | 4620 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 4621 | next_hop, &pinfo); |
bba95fef | 4622 | if (err == -ENOENT) |
2ec600d6 | 4623 | break; |
bba95fef | 4624 | if (err) |
3b85875a | 4625 | goto out_err; |
2ec600d6 | 4626 | |
15e47304 | 4627 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4628 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4629 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4630 | &pinfo) < 0) |
4631 | goto out; | |
2ec600d6 | 4632 | |
bba95fef | 4633 | path_idx++; |
2ec600d6 | 4634 | } |
2ec600d6 | 4635 | |
2ec600d6 | 4636 | |
bba95fef | 4637 | out: |
97990a06 | 4638 | cb->args[2] = path_idx; |
bba95fef | 4639 | err = skb->len; |
bba95fef | 4640 | out_err: |
1b8ec87a | 4641 | nl80211_finish_wdev_dump(rdev); |
bba95fef | 4642 | return err; |
2ec600d6 LCC |
4643 | } |
4644 | ||
4645 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4646 | { | |
4c476991 | 4647 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4648 | int err; |
4c476991 | 4649 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4650 | struct mpath_info pinfo; |
4651 | struct sk_buff *msg; | |
4652 | u8 *dst = NULL; | |
4653 | u8 next_hop[ETH_ALEN]; | |
4654 | ||
4655 | memset(&pinfo, 0, sizeof(pinfo)); | |
4656 | ||
4657 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4658 | return -EINVAL; | |
4659 | ||
4660 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4661 | ||
4c476991 JB |
4662 | if (!rdev->ops->get_mpath) |
4663 | return -EOPNOTSUPP; | |
2ec600d6 | 4664 | |
4c476991 JB |
4665 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4666 | return -EOPNOTSUPP; | |
eec60b03 | 4667 | |
e35e4d28 | 4668 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4669 | if (err) |
4c476991 | 4670 | return err; |
2ec600d6 | 4671 | |
fd2120ca | 4672 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4673 | if (!msg) |
4c476991 | 4674 | return -ENOMEM; |
2ec600d6 | 4675 | |
15e47304 | 4676 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4677 | dev, dst, next_hop, &pinfo) < 0) { |
4678 | nlmsg_free(msg); | |
4679 | return -ENOBUFS; | |
4680 | } | |
3b85875a | 4681 | |
4c476991 | 4682 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4683 | } |
4684 | ||
4685 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4686 | { | |
4c476991 JB |
4687 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4688 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4689 | u8 *dst = NULL; |
4690 | u8 *next_hop = NULL; | |
4691 | ||
4692 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4693 | return -EINVAL; | |
4694 | ||
4695 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4696 | return -EINVAL; | |
4697 | ||
4698 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4699 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4700 | ||
4c476991 JB |
4701 | if (!rdev->ops->change_mpath) |
4702 | return -EOPNOTSUPP; | |
35a8efe1 | 4703 | |
4c476991 JB |
4704 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4705 | return -EOPNOTSUPP; | |
2ec600d6 | 4706 | |
e35e4d28 | 4707 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4708 | } |
4c476991 | 4709 | |
2ec600d6 LCC |
4710 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4711 | { | |
4c476991 JB |
4712 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4713 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4714 | u8 *dst = NULL; |
4715 | u8 *next_hop = NULL; | |
4716 | ||
4717 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4718 | return -EINVAL; | |
4719 | ||
4720 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4721 | return -EINVAL; | |
4722 | ||
4723 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4724 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4725 | ||
4c476991 JB |
4726 | if (!rdev->ops->add_mpath) |
4727 | return -EOPNOTSUPP; | |
35a8efe1 | 4728 | |
4c476991 JB |
4729 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4730 | return -EOPNOTSUPP; | |
2ec600d6 | 4731 | |
e35e4d28 | 4732 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4733 | } |
4734 | ||
4735 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4736 | { | |
4c476991 JB |
4737 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4738 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4739 | u8 *dst = NULL; |
4740 | ||
4741 | if (info->attrs[NL80211_ATTR_MAC]) | |
4742 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4743 | ||
4c476991 JB |
4744 | if (!rdev->ops->del_mpath) |
4745 | return -EOPNOTSUPP; | |
3b85875a | 4746 | |
e35e4d28 | 4747 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4748 | } |
4749 | ||
66be7d2b HR |
4750 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
4751 | { | |
4752 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4753 | int err; | |
4754 | struct net_device *dev = info->user_ptr[1]; | |
4755 | struct mpath_info pinfo; | |
4756 | struct sk_buff *msg; | |
4757 | u8 *dst = NULL; | |
4758 | u8 mpp[ETH_ALEN]; | |
4759 | ||
4760 | memset(&pinfo, 0, sizeof(pinfo)); | |
4761 | ||
4762 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4763 | return -EINVAL; | |
4764 | ||
4765 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4766 | ||
4767 | if (!rdev->ops->get_mpp) | |
4768 | return -EOPNOTSUPP; | |
4769 | ||
4770 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
4771 | return -EOPNOTSUPP; | |
4772 | ||
4773 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | |
4774 | if (err) | |
4775 | return err; | |
4776 | ||
4777 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4778 | if (!msg) | |
4779 | return -ENOMEM; | |
4780 | ||
4781 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | |
4782 | dev, dst, mpp, &pinfo) < 0) { | |
4783 | nlmsg_free(msg); | |
4784 | return -ENOBUFS; | |
4785 | } | |
4786 | ||
4787 | return genlmsg_reply(msg, info); | |
4788 | } | |
4789 | ||
4790 | static int nl80211_dump_mpp(struct sk_buff *skb, | |
4791 | struct netlink_callback *cb) | |
4792 | { | |
4793 | struct mpath_info pinfo; | |
4794 | struct cfg80211_registered_device *rdev; | |
4795 | struct wireless_dev *wdev; | |
4796 | u8 dst[ETH_ALEN]; | |
4797 | u8 mpp[ETH_ALEN]; | |
4798 | int path_idx = cb->args[2]; | |
4799 | int err; | |
4800 | ||
4801 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | |
4802 | if (err) | |
4803 | return err; | |
4804 | ||
4805 | if (!rdev->ops->dump_mpp) { | |
4806 | err = -EOPNOTSUPP; | |
4807 | goto out_err; | |
4808 | } | |
4809 | ||
4810 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | |
4811 | err = -EOPNOTSUPP; | |
4812 | goto out_err; | |
4813 | } | |
4814 | ||
4815 | while (1) { | |
4816 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | |
4817 | mpp, &pinfo); | |
4818 | if (err == -ENOENT) | |
4819 | break; | |
4820 | if (err) | |
4821 | goto out_err; | |
4822 | ||
4823 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | |
4824 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
4825 | wdev->netdev, dst, mpp, | |
4826 | &pinfo) < 0) | |
4827 | goto out; | |
4828 | ||
4829 | path_idx++; | |
4830 | } | |
4831 | ||
4832 | out: | |
4833 | cb->args[2] = path_idx; | |
4834 | err = skb->len; | |
4835 | out_err: | |
4836 | nl80211_finish_wdev_dump(rdev); | |
4837 | return err; | |
4838 | } | |
4839 | ||
9f1ba906 JM |
4840 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4841 | { | |
4c476991 JB |
4842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4843 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 4844 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 4845 | struct bss_parameters params; |
c56589ed | 4846 | int err; |
9f1ba906 JM |
4847 | |
4848 | memset(¶ms, 0, sizeof(params)); | |
4849 | /* default to not changing parameters */ | |
4850 | params.use_cts_prot = -1; | |
4851 | params.use_short_preamble = -1; | |
4852 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4853 | params.ap_isolate = -1; |
50b12f59 | 4854 | params.ht_opmode = -1; |
53cabad7 JB |
4855 | params.p2p_ctwindow = -1; |
4856 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4857 | |
4858 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4859 | params.use_cts_prot = | |
4860 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4861 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4862 | params.use_short_preamble = | |
4863 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4864 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4865 | params.use_short_slot_time = | |
4866 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4867 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4868 | params.basic_rates = | |
4869 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4870 | params.basic_rates_len = | |
4871 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4872 | } | |
fd8aaaf3 FF |
4873 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4874 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4875 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4876 | params.ht_opmode = | |
4877 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4878 | |
53cabad7 JB |
4879 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4880 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4881 | return -EINVAL; | |
4882 | params.p2p_ctwindow = | |
4883 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4884 | if (params.p2p_ctwindow < 0) | |
4885 | return -EINVAL; | |
4886 | if (params.p2p_ctwindow != 0 && | |
4887 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4888 | return -EINVAL; | |
4889 | } | |
4890 | ||
4891 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4892 | u8 tmp; | |
4893 | ||
4894 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4895 | return -EINVAL; | |
4896 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4897 | if (tmp > 1) | |
4898 | return -EINVAL; | |
4899 | params.p2p_opp_ps = tmp; | |
4900 | if (params.p2p_opp_ps && | |
4901 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4902 | return -EINVAL; | |
4903 | } | |
4904 | ||
4c476991 JB |
4905 | if (!rdev->ops->change_bss) |
4906 | return -EOPNOTSUPP; | |
9f1ba906 | 4907 | |
074ac8df | 4908 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4909 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4910 | return -EOPNOTSUPP; | |
3b85875a | 4911 | |
c56589ed SW |
4912 | wdev_lock(wdev); |
4913 | err = rdev_change_bss(rdev, dev, ¶ms); | |
4914 | wdev_unlock(wdev); | |
4915 | ||
4916 | return err; | |
9f1ba906 JM |
4917 | } |
4918 | ||
b54452b0 | 4919 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4920 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4921 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4922 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4923 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4924 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4925 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
089027e5 | 4926 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
b2e1b302 LR |
4927 | }; |
4928 | ||
4929 | static int parse_reg_rule(struct nlattr *tb[], | |
4930 | struct ieee80211_reg_rule *reg_rule) | |
4931 | { | |
4932 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4933 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4934 | ||
4935 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4936 | return -EINVAL; | |
4937 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4938 | return -EINVAL; | |
4939 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4940 | return -EINVAL; | |
b0dfd2ea JD |
4941 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
4942 | return -EINVAL; | |
b2e1b302 LR |
4943 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
4944 | return -EINVAL; | |
4945 | ||
4946 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4947 | ||
4948 | freq_range->start_freq_khz = | |
4949 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4950 | freq_range->end_freq_khz = | |
4951 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
b0dfd2ea JD |
4952 | freq_range->max_bandwidth_khz = |
4953 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
b2e1b302 LR |
4954 | |
4955 | power_rule->max_eirp = | |
4956 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4957 | ||
4958 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4959 | power_rule->max_antenna_gain = | |
4960 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4961 | ||
089027e5 JD |
4962 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
4963 | reg_rule->dfs_cac_ms = | |
4964 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
4965 | ||
b2e1b302 LR |
4966 | return 0; |
4967 | } | |
4968 | ||
4969 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4970 | { | |
b2e1b302 | 4971 | char *data = NULL; |
05050753 | 4972 | bool is_indoor; |
57b5ce07 | 4973 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
05050753 I |
4974 | u32 owner_nlportid; |
4975 | ||
b2e1b302 | 4976 | |
80778f18 LR |
4977 | /* |
4978 | * You should only get this when cfg80211 hasn't yet initialized | |
4979 | * completely when built-in to the kernel right between the time | |
4980 | * window between nl80211_init() and regulatory_init(), if that is | |
4981 | * even possible. | |
4982 | */ | |
458f4f9e | 4983 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4984 | return -EINPROGRESS; |
80778f18 | 4985 | |
57b5ce07 LR |
4986 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4987 | user_reg_hint_type = | |
4988 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4989 | else | |
4990 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4991 | ||
4992 | switch (user_reg_hint_type) { | |
4993 | case NL80211_USER_REG_HINT_USER: | |
4994 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
4995 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4996 | return -EINVAL; | |
4997 | ||
4998 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4999 | return regulatory_hint_user(data, user_reg_hint_type); | |
5000 | case NL80211_USER_REG_HINT_INDOOR: | |
05050753 I |
5001 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
5002 | owner_nlportid = info->snd_portid; | |
5003 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; | |
5004 | } else { | |
5005 | owner_nlportid = 0; | |
5006 | is_indoor = true; | |
5007 | } | |
5008 | ||
5009 | return regulatory_hint_indoor(is_indoor, owner_nlportid); | |
57b5ce07 LR |
5010 | default: |
5011 | return -EINVAL; | |
5012 | } | |
b2e1b302 LR |
5013 | } |
5014 | ||
24bdd9f4 | 5015 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 5016 | struct genl_info *info) |
93da9cc1 | 5017 | { |
4c476991 | 5018 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 5019 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
5020 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5021 | struct mesh_config cur_params; | |
5022 | int err = 0; | |
93da9cc1 | 5023 | void *hdr; |
5024 | struct nlattr *pinfoattr; | |
5025 | struct sk_buff *msg; | |
5026 | ||
29cbe68c JB |
5027 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5028 | return -EOPNOTSUPP; | |
5029 | ||
24bdd9f4 | 5030 | if (!rdev->ops->get_mesh_config) |
4c476991 | 5031 | return -EOPNOTSUPP; |
f3f92586 | 5032 | |
29cbe68c JB |
5033 | wdev_lock(wdev); |
5034 | /* If not connected, get default parameters */ | |
5035 | if (!wdev->mesh_id_len) | |
5036 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
5037 | else | |
e35e4d28 | 5038 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
5039 | wdev_unlock(wdev); |
5040 | ||
93da9cc1 | 5041 | if (err) |
4c476991 | 5042 | return err; |
93da9cc1 | 5043 | |
5044 | /* Draw up a netlink message to send back */ | |
fd2120ca | 5045 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
5046 | if (!msg) |
5047 | return -ENOMEM; | |
15e47304 | 5048 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 5049 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 5050 | if (!hdr) |
efe1cf0c | 5051 | goto out; |
24bdd9f4 | 5052 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 5053 | if (!pinfoattr) |
5054 | goto nla_put_failure; | |
9360ffd1 DM |
5055 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5056 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
5057 | cur_params.dot11MeshRetryTimeout) || | |
5058 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
5059 | cur_params.dot11MeshConfirmTimeout) || | |
5060 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
5061 | cur_params.dot11MeshHoldingTimeout) || | |
5062 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
5063 | cur_params.dot11MeshMaxPeerLinks) || | |
5064 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
5065 | cur_params.dot11MeshMaxRetries) || | |
5066 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
5067 | cur_params.dot11MeshTTL) || | |
5068 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
5069 | cur_params.element_ttl) || | |
5070 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
5071 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
5072 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5073 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
5074 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5075 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
5076 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
5077 | cur_params.path_refresh_time) || | |
5078 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
5079 | cur_params.min_discovery_timeout) || | |
5080 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
5081 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
5082 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
5083 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
5084 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
5085 | cur_params.dot11MeshHWMPperrMinInterval) || | |
5086 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
5087 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
5088 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5089 | cur_params.dot11MeshHWMPRootMode) || | |
5090 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
5091 | cur_params.dot11MeshHWMPRannInterval) || | |
5092 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
5093 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
5094 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
5095 | cur_params.dot11MeshForwarding) || | |
5096 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
5097 | cur_params.rssi_threshold) || |
5098 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
5099 | cur_params.ht_opmode) || |
5100 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
5101 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
5102 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
5103 | cur_params.dot11MeshHWMProotInterval) || |
5104 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
5105 | cur_params.dot11MeshHWMPconfirmationInterval) || |
5106 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
5107 | cur_params.power_mode) || | |
5108 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
5109 | cur_params.dot11MeshAwakeWindowDuration) || |
5110 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5111 | cur_params.plink_timeout)) | |
9360ffd1 | 5112 | goto nla_put_failure; |
93da9cc1 | 5113 | nla_nest_end(msg, pinfoattr); |
5114 | genlmsg_end(msg, hdr); | |
4c476991 | 5115 | return genlmsg_reply(msg, info); |
93da9cc1 | 5116 | |
3b85875a | 5117 | nla_put_failure: |
93da9cc1 | 5118 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 5119 | out: |
d080e275 | 5120 | nlmsg_free(msg); |
4c476991 | 5121 | return -ENOBUFS; |
93da9cc1 | 5122 | } |
5123 | ||
b54452b0 | 5124 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 5125 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
5126 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
5127 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
5128 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
5129 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
5130 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 5131 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 5132 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 5133 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 5134 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
5135 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
5136 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
5137 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
5138 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 5139 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 5140 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 5141 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 5142 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 5143 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 5144 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
5145 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
5146 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
5147 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
5148 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 5149 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
5150 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
5151 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 5152 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 5153 | }; |
5154 | ||
c80d545d JC |
5155 | static const struct nla_policy |
5156 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 5157 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
5158 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
5159 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 5160 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 5161 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 5162 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 5163 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 5164 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 5165 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
5166 | }; |
5167 | ||
24bdd9f4 | 5168 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
5169 | struct mesh_config *cfg, |
5170 | u32 *mask_out) | |
93da9cc1 | 5171 | { |
93da9cc1 | 5172 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 5173 | u32 mask = 0; |
93da9cc1 | 5174 | |
ea54fba2 MP |
5175 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
5176 | do { \ | |
5177 | if (tb[attr]) { \ | |
5178 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
5179 | return -EINVAL; \ | |
5180 | cfg->param = fn(tb[attr]); \ | |
5181 | mask |= (1 << (attr - 1)); \ | |
5182 | } \ | |
5183 | } while (0) | |
bd90fdcc JB |
5184 | |
5185 | ||
24bdd9f4 | 5186 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 5187 | return -EINVAL; |
5188 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 5189 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 5190 | nl80211_meshconf_params_policy)) |
93da9cc1 | 5191 | return -EINVAL; |
5192 | ||
93da9cc1 | 5193 | /* This makes sure that there aren't more than 32 mesh config |
5194 | * parameters (otherwise our bitfield scheme would not work.) */ | |
5195 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
5196 | ||
5197 | /* Fill in the params struct */ | |
ea54fba2 | 5198 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
5199 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
5200 | nla_get_u16); | |
ea54fba2 | 5201 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
5202 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
5203 | nla_get_u16); | |
ea54fba2 | 5204 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
5205 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
5206 | nla_get_u16); | |
ea54fba2 | 5207 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
5208 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
5209 | nla_get_u16); | |
ea54fba2 | 5210 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
5211 | mask, NL80211_MESHCONF_MAX_RETRIES, |
5212 | nla_get_u8); | |
ea54fba2 | 5213 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 5214 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 5215 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
5216 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
5217 | nla_get_u8); | |
ea54fba2 | 5218 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
5219 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
5220 | nla_get_u8); | |
ea54fba2 MP |
5221 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
5222 | 1, 255, mask, | |
a4f606ea CYY |
5223 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5224 | nla_get_u32); | |
ea54fba2 | 5225 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
5226 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5227 | nla_get_u8); | |
ea54fba2 | 5228 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
5229 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
5230 | nla_get_u32); | |
ea54fba2 | 5231 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
5232 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
5233 | nla_get_u16); | |
ea54fba2 MP |
5234 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
5235 | 1, 65535, mask, | |
a4f606ea CYY |
5236 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
5237 | nla_get_u32); | |
93da9cc1 | 5238 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
5239 | 1, 65535, mask, |
5240 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 5241 | nla_get_u16); |
dca7e943 | 5242 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
5243 | 1, 65535, mask, |
5244 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 5245 | nla_get_u16); |
93da9cc1 | 5246 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5247 | dot11MeshHWMPnetDiameterTraversalTime, |
5248 | 1, 65535, mask, | |
a4f606ea CYY |
5249 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
5250 | nla_get_u16); | |
ea54fba2 MP |
5251 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
5252 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5253 | nla_get_u8); | |
5254 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
5255 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 5256 | nla_get_u16); |
63c5723b | 5257 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5258 | dot11MeshGateAnnouncementProtocol, 0, 1, |
5259 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 5260 | nla_get_u8); |
ea54fba2 | 5261 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
5262 | mask, NL80211_MESHCONF_FORWARDING, |
5263 | nla_get_u8); | |
83374fe9 | 5264 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 5265 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
83374fe9 | 5266 | nla_get_s32); |
ea54fba2 | 5267 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 5268 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
5269 | nla_get_u16); |
5270 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 5271 | 1, 65535, mask, |
ac1073a6 CYY |
5272 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
5273 | nla_get_u32); | |
ea54fba2 | 5274 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 5275 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
5276 | nla_get_u16); |
5277 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
5278 | dot11MeshHWMPconfirmationInterval, |
5279 | 1, 65535, mask, | |
728b19e5 | 5280 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 5281 | nla_get_u16); |
3b1c5a53 MP |
5282 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
5283 | NL80211_MESH_POWER_ACTIVE, | |
5284 | NL80211_MESH_POWER_MAX, | |
5285 | mask, NL80211_MESHCONF_POWER_MODE, | |
5286 | nla_get_u32); | |
5287 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
5288 | 0, 65535, mask, | |
5289 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
31f909a2 | 5290 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
8e7c0538 CT |
5291 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
5292 | nla_get_u32); | |
bd90fdcc JB |
5293 | if (mask_out) |
5294 | *mask_out = mask; | |
c80d545d | 5295 | |
bd90fdcc JB |
5296 | return 0; |
5297 | ||
5298 | #undef FILL_IN_MESH_PARAM_IF_SET | |
5299 | } | |
5300 | ||
c80d545d JC |
5301 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
5302 | struct mesh_setup *setup) | |
5303 | { | |
bb2798d4 | 5304 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
5305 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
5306 | ||
5307 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
5308 | return -EINVAL; | |
5309 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
5310 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
5311 | nl80211_mesh_setup_params_policy)) | |
5312 | return -EINVAL; | |
5313 | ||
d299a1f2 JC |
5314 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
5315 | setup->sync_method = | |
5316 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
5317 | IEEE80211_SYNC_METHOD_VENDOR : | |
5318 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
5319 | ||
c80d545d JC |
5320 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
5321 | setup->path_sel_proto = | |
5322 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5323 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5324 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5325 | ||
5326 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5327 | setup->path_metric = | |
5328 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5329 | IEEE80211_PATH_METRIC_VENDOR : | |
5330 | IEEE80211_PATH_METRIC_AIRTIME; | |
5331 | ||
581a8b0f JC |
5332 | |
5333 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 5334 | struct nlattr *ieattr = |
581a8b0f | 5335 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5336 | if (!is_valid_ie_attr(ieattr)) |
5337 | return -EINVAL; | |
581a8b0f JC |
5338 | setup->ie = nla_data(ieattr); |
5339 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5340 | } |
bb2798d4 TP |
5341 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5342 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5343 | return -EINVAL; | |
5344 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5345 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5346 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5347 | if (setup->is_secure) |
5348 | setup->user_mpm = true; | |
c80d545d | 5349 | |
6e16d90b CT |
5350 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5351 | if (!setup->user_mpm) | |
5352 | return -EINVAL; | |
5353 | setup->auth_id = | |
5354 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5355 | } | |
5356 | ||
c80d545d JC |
5357 | return 0; |
5358 | } | |
5359 | ||
24bdd9f4 | 5360 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5361 | struct genl_info *info) |
bd90fdcc JB |
5362 | { |
5363 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5364 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5365 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5366 | struct mesh_config cfg; |
5367 | u32 mask; | |
5368 | int err; | |
5369 | ||
29cbe68c JB |
5370 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5371 | return -EOPNOTSUPP; | |
5372 | ||
24bdd9f4 | 5373 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5374 | return -EOPNOTSUPP; |
5375 | ||
24bdd9f4 | 5376 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5377 | if (err) |
5378 | return err; | |
5379 | ||
29cbe68c JB |
5380 | wdev_lock(wdev); |
5381 | if (!wdev->mesh_id_len) | |
5382 | err = -ENOLINK; | |
5383 | ||
5384 | if (!err) | |
e35e4d28 | 5385 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5386 | |
5387 | wdev_unlock(wdev); | |
5388 | ||
5389 | return err; | |
93da9cc1 | 5390 | } |
5391 | ||
ad30ca2c AN |
5392 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
5393 | struct sk_buff *msg) | |
f130347c | 5394 | { |
f130347c LR |
5395 | struct nlattr *nl_reg_rules; |
5396 | unsigned int i; | |
f130347c | 5397 | |
458f4f9e JB |
5398 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
5399 | (regdom->dfs_region && | |
5400 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
ad30ca2c | 5401 | goto nla_put_failure; |
458f4f9e | 5402 | |
f130347c LR |
5403 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5404 | if (!nl_reg_rules) | |
ad30ca2c | 5405 | goto nla_put_failure; |
f130347c | 5406 | |
458f4f9e | 5407 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5408 | struct nlattr *nl_reg_rule; |
5409 | const struct ieee80211_reg_rule *reg_rule; | |
5410 | const struct ieee80211_freq_range *freq_range; | |
5411 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 5412 | unsigned int max_bandwidth_khz; |
f130347c | 5413 | |
458f4f9e | 5414 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5415 | freq_range = ®_rule->freq_range; |
5416 | power_rule = ®_rule->power_rule; | |
5417 | ||
5418 | nl_reg_rule = nla_nest_start(msg, i); | |
5419 | if (!nl_reg_rule) | |
ad30ca2c | 5420 | goto nla_put_failure; |
f130347c | 5421 | |
97524820 JD |
5422 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
5423 | if (!max_bandwidth_khz) | |
5424 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
5425 | reg_rule); | |
5426 | ||
9360ffd1 DM |
5427 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5428 | reg_rule->flags) || | |
5429 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5430 | freq_range->start_freq_khz) || | |
5431 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5432 | freq_range->end_freq_khz) || | |
5433 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 5434 | max_bandwidth_khz) || |
9360ffd1 DM |
5435 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
5436 | power_rule->max_antenna_gain) || | |
5437 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
5438 | power_rule->max_eirp) || |
5439 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
5440 | reg_rule->dfs_cac_ms)) | |
ad30ca2c | 5441 | goto nla_put_failure; |
f130347c LR |
5442 | |
5443 | nla_nest_end(msg, nl_reg_rule); | |
5444 | } | |
5445 | ||
5446 | nla_nest_end(msg, nl_reg_rules); | |
ad30ca2c AN |
5447 | return 0; |
5448 | ||
5449 | nla_put_failure: | |
5450 | return -EMSGSIZE; | |
5451 | } | |
5452 | ||
5453 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) | |
5454 | { | |
5455 | const struct ieee80211_regdomain *regdom = NULL; | |
5456 | struct cfg80211_registered_device *rdev; | |
5457 | struct wiphy *wiphy = NULL; | |
5458 | struct sk_buff *msg; | |
5459 | void *hdr; | |
5460 | ||
5461 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5462 | if (!msg) | |
5463 | return -ENOBUFS; | |
5464 | ||
5465 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
5466 | NL80211_CMD_GET_REG); | |
5467 | if (!hdr) | |
5468 | goto put_failure; | |
5469 | ||
5470 | if (info->attrs[NL80211_ATTR_WIPHY]) { | |
1bdd716c AN |
5471 | bool self_managed; |
5472 | ||
ad30ca2c AN |
5473 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
5474 | if (IS_ERR(rdev)) { | |
5475 | nlmsg_free(msg); | |
5476 | return PTR_ERR(rdev); | |
5477 | } | |
5478 | ||
5479 | wiphy = &rdev->wiphy; | |
1bdd716c AN |
5480 | self_managed = wiphy->regulatory_flags & |
5481 | REGULATORY_WIPHY_SELF_MANAGED; | |
ad30ca2c AN |
5482 | regdom = get_wiphy_regdom(wiphy); |
5483 | ||
1bdd716c AN |
5484 | /* a self-managed-reg device must have a private regdom */ |
5485 | if (WARN_ON(!regdom && self_managed)) { | |
5486 | nlmsg_free(msg); | |
5487 | return -EINVAL; | |
5488 | } | |
5489 | ||
ad30ca2c AN |
5490 | if (regdom && |
5491 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5492 | goto nla_put_failure; | |
5493 | } | |
5494 | ||
5495 | if (!wiphy && reg_last_request_cell_base() && | |
5496 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5497 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5498 | goto nla_put_failure; | |
5499 | ||
5500 | rcu_read_lock(); | |
5501 | ||
5502 | if (!regdom) | |
5503 | regdom = rcu_dereference(cfg80211_regdomain); | |
5504 | ||
5505 | if (nl80211_put_regdom(regdom, msg)) | |
5506 | goto nla_put_failure_rcu; | |
5507 | ||
5508 | rcu_read_unlock(); | |
f130347c LR |
5509 | |
5510 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5511 | return genlmsg_reply(msg, info); |
f130347c | 5512 | |
458f4f9e JB |
5513 | nla_put_failure_rcu: |
5514 | rcu_read_unlock(); | |
f130347c LR |
5515 | nla_put_failure: |
5516 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5517 | put_failure: |
d080e275 | 5518 | nlmsg_free(msg); |
5fe231e8 | 5519 | return -EMSGSIZE; |
f130347c LR |
5520 | } |
5521 | ||
ad30ca2c AN |
5522 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
5523 | u32 seq, int flags, struct wiphy *wiphy, | |
5524 | const struct ieee80211_regdomain *regdom) | |
5525 | { | |
5526 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | |
5527 | NL80211_CMD_GET_REG); | |
5528 | ||
5529 | if (!hdr) | |
5530 | return -1; | |
5531 | ||
5532 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); | |
5533 | ||
5534 | if (nl80211_put_regdom(regdom, msg)) | |
5535 | goto nla_put_failure; | |
5536 | ||
5537 | if (!wiphy && reg_last_request_cell_base() && | |
5538 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5539 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5540 | goto nla_put_failure; | |
5541 | ||
5542 | if (wiphy && | |
5543 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5544 | goto nla_put_failure; | |
5545 | ||
1bdd716c AN |
5546 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
5547 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
5548 | goto nla_put_failure; | |
5549 | ||
053c095a JB |
5550 | genlmsg_end(msg, hdr); |
5551 | return 0; | |
ad30ca2c AN |
5552 | |
5553 | nla_put_failure: | |
5554 | genlmsg_cancel(msg, hdr); | |
5555 | return -EMSGSIZE; | |
5556 | } | |
5557 | ||
5558 | static int nl80211_get_reg_dump(struct sk_buff *skb, | |
5559 | struct netlink_callback *cb) | |
5560 | { | |
5561 | const struct ieee80211_regdomain *regdom = NULL; | |
5562 | struct cfg80211_registered_device *rdev; | |
5563 | int err, reg_idx, start = cb->args[2]; | |
5564 | ||
5565 | rtnl_lock(); | |
5566 | ||
5567 | if (cfg80211_regdomain && start == 0) { | |
5568 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5569 | NLM_F_MULTI, NULL, | |
5570 | rtnl_dereference(cfg80211_regdomain)); | |
5571 | if (err < 0) | |
5572 | goto out_err; | |
5573 | } | |
5574 | ||
5575 | /* the global regdom is idx 0 */ | |
5576 | reg_idx = 1; | |
5577 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | |
5578 | regdom = get_wiphy_regdom(&rdev->wiphy); | |
5579 | if (!regdom) | |
5580 | continue; | |
5581 | ||
5582 | if (++reg_idx <= start) | |
5583 | continue; | |
5584 | ||
5585 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5586 | NLM_F_MULTI, &rdev->wiphy, regdom); | |
5587 | if (err < 0) { | |
5588 | reg_idx--; | |
5589 | break; | |
5590 | } | |
5591 | } | |
5592 | ||
5593 | cb->args[2] = reg_idx; | |
5594 | err = skb->len; | |
5595 | out_err: | |
5596 | rtnl_unlock(); | |
5597 | return err; | |
5598 | } | |
5599 | ||
b2e1b302 LR |
5600 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5601 | { | |
5602 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5603 | struct nlattr *nl_reg_rule; | |
ea372c54 JB |
5604 | char *alpha2; |
5605 | int rem_reg_rules, r; | |
b2e1b302 | 5606 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
4c7d3982 | 5607 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
ea372c54 | 5608 | struct ieee80211_regdomain *rd; |
b2e1b302 LR |
5609 | |
5610 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5611 | return -EINVAL; | |
5612 | ||
5613 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5614 | return -EINVAL; | |
5615 | ||
5616 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5617 | ||
8b60b078 LR |
5618 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5619 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5620 | ||
b2e1b302 | 5621 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5622 | rem_reg_rules) { |
b2e1b302 LR |
5623 | num_rules++; |
5624 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5625 | return -EINVAL; |
b2e1b302 LR |
5626 | } |
5627 | ||
e438768f LR |
5628 | if (!reg_is_valid_request(alpha2)) |
5629 | return -EINVAL; | |
5630 | ||
b2e1b302 | 5631 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5632 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5633 | |
5634 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5635 | if (!rd) |
5636 | return -ENOMEM; | |
b2e1b302 LR |
5637 | |
5638 | rd->n_reg_rules = num_rules; | |
5639 | rd->alpha2[0] = alpha2[0]; | |
5640 | rd->alpha2[1] = alpha2[1]; | |
5641 | ||
8b60b078 LR |
5642 | /* |
5643 | * Disable DFS master mode if the DFS region was | |
5644 | * not supported or known on this kernel. | |
5645 | */ | |
5646 | if (reg_supported_dfs_region(dfs_region)) | |
5647 | rd->dfs_region = dfs_region; | |
5648 | ||
b2e1b302 | 5649 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5650 | rem_reg_rules) { |
ae811e21 JB |
5651 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
5652 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
5653 | reg_rule_policy); | |
5654 | if (r) | |
5655 | goto bad_reg; | |
b2e1b302 LR |
5656 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5657 | if (r) | |
5658 | goto bad_reg; | |
5659 | ||
5660 | rule_idx++; | |
5661 | ||
d0e18f83 LR |
5662 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5663 | r = -EINVAL; | |
b2e1b302 | 5664 | goto bad_reg; |
d0e18f83 | 5665 | } |
b2e1b302 LR |
5666 | } |
5667 | ||
c37722bd | 5668 | r = set_regdom(rd, REGD_SOURCE_CRDA); |
6913b49a | 5669 | /* set_regdom took ownership */ |
1a919318 | 5670 | rd = NULL; |
b2e1b302 | 5671 | |
d2372b31 | 5672 | bad_reg: |
b2e1b302 | 5673 | kfree(rd); |
d0e18f83 | 5674 | return r; |
b2e1b302 LR |
5675 | } |
5676 | ||
83f5e2cf JB |
5677 | static int validate_scan_freqs(struct nlattr *freqs) |
5678 | { | |
5679 | struct nlattr *attr1, *attr2; | |
5680 | int n_channels = 0, tmp1, tmp2; | |
5681 | ||
5682 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5683 | n_channels++; | |
5684 | /* | |
5685 | * Some hardware has a limited channel list for | |
5686 | * scanning, and it is pretty much nonsensical | |
5687 | * to scan for a channel twice, so disallow that | |
5688 | * and don't require drivers to check that the | |
5689 | * channel list they get isn't longer than what | |
5690 | * they can scan, as long as they can scan all | |
5691 | * the channels they registered at once. | |
5692 | */ | |
5693 | nla_for_each_nested(attr2, freqs, tmp2) | |
5694 | if (attr1 != attr2 && | |
5695 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5696 | return 0; | |
5697 | } | |
5698 | ||
5699 | return n_channels; | |
5700 | } | |
5701 | ||
ad2b26ab JB |
5702 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
5703 | u8 *mac_addr, u8 *mac_addr_mask) | |
5704 | { | |
5705 | int i; | |
5706 | ||
5707 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { | |
d2beae10 JP |
5708 | eth_zero_addr(mac_addr); |
5709 | eth_zero_addr(mac_addr_mask); | |
ad2b26ab JB |
5710 | mac_addr[0] = 0x2; |
5711 | mac_addr_mask[0] = 0x3; | |
5712 | ||
5713 | return 0; | |
5714 | } | |
5715 | ||
5716 | /* need both or none */ | |
5717 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) | |
5718 | return -EINVAL; | |
5719 | ||
5720 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); | |
5721 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); | |
5722 | ||
5723 | /* don't allow or configure an mcast address */ | |
5724 | if (!is_multicast_ether_addr(mac_addr_mask) || | |
5725 | is_multicast_ether_addr(mac_addr)) | |
5726 | return -EINVAL; | |
5727 | ||
5728 | /* | |
5729 | * allow users to pass a MAC address that has bits set outside | |
5730 | * of the mask, but don't bother drivers with having to deal | |
5731 | * with such bits | |
5732 | */ | |
5733 | for (i = 0; i < ETH_ALEN; i++) | |
5734 | mac_addr[i] &= mac_addr_mask[i]; | |
5735 | ||
5736 | return 0; | |
5737 | } | |
5738 | ||
2a519311 JB |
5739 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5740 | { | |
4c476991 | 5741 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5742 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5743 | struct cfg80211_scan_request *request; |
2a519311 JB |
5744 | struct nlattr *attr; |
5745 | struct wiphy *wiphy; | |
83f5e2cf | 5746 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5747 | size_t ie_len; |
2a519311 | 5748 | |
f4a11bb0 JB |
5749 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5750 | return -EINVAL; | |
5751 | ||
79c97e97 | 5752 | wiphy = &rdev->wiphy; |
2a519311 | 5753 | |
4c476991 JB |
5754 | if (!rdev->ops->scan) |
5755 | return -EOPNOTSUPP; | |
2a519311 | 5756 | |
f9d15d16 | 5757 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
5758 | err = -EBUSY; |
5759 | goto unlock; | |
5760 | } | |
2a519311 JB |
5761 | |
5762 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5763 | n_channels = validate_scan_freqs( |
5764 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5765 | if (!n_channels) { |
5766 | err = -EINVAL; | |
5767 | goto unlock; | |
5768 | } | |
2a519311 | 5769 | } else { |
bdfbec2d | 5770 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
5771 | } |
5772 | ||
5773 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5774 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5775 | n_ssids++; | |
5776 | ||
f9f47529 JB |
5777 | if (n_ssids > wiphy->max_scan_ssids) { |
5778 | err = -EINVAL; | |
5779 | goto unlock; | |
5780 | } | |
2a519311 | 5781 | |
70692ad2 JM |
5782 | if (info->attrs[NL80211_ATTR_IE]) |
5783 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5784 | else | |
5785 | ie_len = 0; | |
5786 | ||
f9f47529 JB |
5787 | if (ie_len > wiphy->max_scan_ie_len) { |
5788 | err = -EINVAL; | |
5789 | goto unlock; | |
5790 | } | |
18a83659 | 5791 | |
2a519311 | 5792 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5793 | + sizeof(*request->ssids) * n_ssids |
5794 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5795 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5796 | if (!request) { |
5797 | err = -ENOMEM; | |
5798 | goto unlock; | |
5799 | } | |
2a519311 | 5800 | |
2a519311 | 5801 | if (n_ssids) |
5ba63533 | 5802 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5803 | request->n_ssids = n_ssids; |
70692ad2 | 5804 | if (ie_len) { |
13874e4b | 5805 | if (n_ssids) |
70692ad2 JM |
5806 | request->ie = (void *)(request->ssids + n_ssids); |
5807 | else | |
5808 | request->ie = (void *)(request->channels + n_channels); | |
5809 | } | |
2a519311 | 5810 | |
584991dc | 5811 | i = 0; |
2a519311 JB |
5812 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5813 | /* user specified, bail out if channel not found */ | |
2a519311 | 5814 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5815 | struct ieee80211_channel *chan; |
5816 | ||
5817 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5818 | ||
5819 | if (!chan) { | |
2a519311 JB |
5820 | err = -EINVAL; |
5821 | goto out_free; | |
5822 | } | |
584991dc JB |
5823 | |
5824 | /* ignore disabled channels */ | |
5825 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5826 | continue; | |
5827 | ||
5828 | request->channels[i] = chan; | |
2a519311 JB |
5829 | i++; |
5830 | } | |
5831 | } else { | |
34850ab2 JB |
5832 | enum ieee80211_band band; |
5833 | ||
2a519311 | 5834 | /* all channels */ |
2a519311 JB |
5835 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5836 | int j; | |
5837 | if (!wiphy->bands[band]) | |
5838 | continue; | |
5839 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5840 | struct ieee80211_channel *chan; |
5841 | ||
5842 | chan = &wiphy->bands[band]->channels[j]; | |
5843 | ||
5844 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5845 | continue; | |
5846 | ||
5847 | request->channels[i] = chan; | |
2a519311 JB |
5848 | i++; |
5849 | } | |
5850 | } | |
5851 | } | |
5852 | ||
584991dc JB |
5853 | if (!i) { |
5854 | err = -EINVAL; | |
5855 | goto out_free; | |
5856 | } | |
5857 | ||
5858 | request->n_channels = i; | |
5859 | ||
2a519311 | 5860 | i = 0; |
13874e4b | 5861 | if (n_ssids) { |
2a519311 | 5862 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
57a27e1d | 5863 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5864 | err = -EINVAL; |
5865 | goto out_free; | |
5866 | } | |
57a27e1d | 5867 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5868 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5869 | i++; |
5870 | } | |
5871 | } | |
5872 | ||
70692ad2 JM |
5873 | if (info->attrs[NL80211_ATTR_IE]) { |
5874 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5875 | memcpy((void *)request->ie, |
5876 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5877 | request->ie_len); |
5878 | } | |
5879 | ||
34850ab2 | 5880 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5881 | if (wiphy->bands[i]) |
5882 | request->rates[i] = | |
5883 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5884 | |
5885 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5886 | nla_for_each_nested(attr, | |
5887 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5888 | tmp) { | |
5889 | enum ieee80211_band band = nla_type(attr); | |
5890 | ||
84404623 | 5891 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5892 | err = -EINVAL; |
5893 | goto out_free; | |
5894 | } | |
1b09cd82 FF |
5895 | |
5896 | if (!wiphy->bands[band]) | |
5897 | continue; | |
5898 | ||
34850ab2 JB |
5899 | err = ieee80211_get_ratemask(wiphy->bands[band], |
5900 | nla_data(attr), | |
5901 | nla_len(attr), | |
5902 | &request->rates[band]); | |
5903 | if (err) | |
5904 | goto out_free; | |
5905 | } | |
5906 | } | |
5907 | ||
46856bbf | 5908 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5909 | request->flags = nla_get_u32( |
5910 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5911 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5912 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5913 | err = -EOPNOTSUPP; |
5914 | goto out_free; | |
5915 | } | |
ad2b26ab JB |
5916 | |
5917 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
5918 | if (!(wiphy->features & | |
5919 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { | |
5920 | err = -EOPNOTSUPP; | |
5921 | goto out_free; | |
5922 | } | |
5923 | ||
5924 | if (wdev->current_bss) { | |
5925 | err = -EOPNOTSUPP; | |
5926 | goto out_free; | |
5927 | } | |
5928 | ||
5929 | err = nl80211_parse_random_mac(info->attrs, | |
5930 | request->mac_addr, | |
5931 | request->mac_addr_mask); | |
5932 | if (err) | |
5933 | goto out_free; | |
5934 | } | |
46856bbf | 5935 | } |
ed473771 | 5936 | |
e9f935e3 RM |
5937 | request->no_cck = |
5938 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5939 | ||
fd014284 | 5940 | request->wdev = wdev; |
79c97e97 | 5941 | request->wiphy = &rdev->wiphy; |
15d6030b | 5942 | request->scan_start = jiffies; |
2a519311 | 5943 | |
79c97e97 | 5944 | rdev->scan_req = request; |
e35e4d28 | 5945 | err = rdev_scan(rdev, request); |
2a519311 | 5946 | |
463d0183 | 5947 | if (!err) { |
fd014284 JB |
5948 | nl80211_send_scan_start(rdev, wdev); |
5949 | if (wdev->netdev) | |
5950 | dev_hold(wdev->netdev); | |
4c476991 | 5951 | } else { |
2a519311 | 5952 | out_free: |
79c97e97 | 5953 | rdev->scan_req = NULL; |
2a519311 JB |
5954 | kfree(request); |
5955 | } | |
3b85875a | 5956 | |
f9f47529 | 5957 | unlock: |
2a519311 JB |
5958 | return err; |
5959 | } | |
5960 | ||
256da02d | 5961 | static struct cfg80211_sched_scan_request * |
ad2b26ab | 5962 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
256da02d | 5963 | struct nlattr **attrs) |
807f8a8c LC |
5964 | { |
5965 | struct cfg80211_sched_scan_request *request; | |
807f8a8c | 5966 | struct nlattr *attr; |
a1f1c21c | 5967 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5968 | u32 interval; |
807f8a8c LC |
5969 | enum ieee80211_band band; |
5970 | size_t ie_len; | |
a1f1c21c | 5971 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 5972 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c | 5973 | |
256da02d LC |
5974 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
5975 | return ERR_PTR(-EINVAL); | |
807f8a8c | 5976 | |
256da02d LC |
5977 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5978 | return ERR_PTR(-EINVAL); | |
bbe6ad6d | 5979 | |
256da02d | 5980 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
bbe6ad6d | 5981 | if (interval == 0) |
256da02d | 5982 | return ERR_PTR(-EINVAL); |
807f8a8c | 5983 | |
256da02d | 5984 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c | 5985 | n_channels = validate_scan_freqs( |
256da02d | 5986 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
807f8a8c | 5987 | if (!n_channels) |
256da02d | 5988 | return ERR_PTR(-EINVAL); |
807f8a8c | 5989 | } else { |
bdfbec2d | 5990 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
5991 | } |
5992 | ||
256da02d LC |
5993 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
5994 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c LC |
5995 | tmp) |
5996 | n_ssids++; | |
5997 | ||
93b6aa69 | 5998 | if (n_ssids > wiphy->max_sched_scan_ssids) |
256da02d | 5999 | return ERR_PTR(-EINVAL); |
807f8a8c | 6000 | |
ea73cbce JB |
6001 | /* |
6002 | * First, count the number of 'real' matchsets. Due to an issue with | |
6003 | * the old implementation, matchsets containing only the RSSI attribute | |
6004 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
6005 | * RSSI for all matchsets, rather than their own matchset for reporting | |
6006 | * all APs with a strong RSSI. This is needed to be compatible with | |
6007 | * older userspace that treated a matchset with only the RSSI as the | |
6008 | * global RSSI for all other matchsets - if there are other matchsets. | |
6009 | */ | |
256da02d | 6010 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 6011 | nla_for_each_nested(attr, |
256da02d | 6012 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
ea73cbce JB |
6013 | tmp) { |
6014 | struct nlattr *rssi; | |
6015 | ||
6016 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
6017 | nla_data(attr), nla_len(attr), | |
6018 | nl80211_match_policy); | |
6019 | if (err) | |
256da02d | 6020 | return ERR_PTR(err); |
ea73cbce JB |
6021 | /* add other standalone attributes here */ |
6022 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | |
6023 | n_match_sets++; | |
6024 | continue; | |
6025 | } | |
6026 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6027 | if (rssi) | |
6028 | default_match_rssi = nla_get_s32(rssi); | |
6029 | } | |
6030 | } | |
6031 | ||
6032 | /* However, if there's no other matchset, add the RSSI one */ | |
6033 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
6034 | n_match_sets = 1; | |
a1f1c21c LC |
6035 | |
6036 | if (n_match_sets > wiphy->max_match_sets) | |
256da02d | 6037 | return ERR_PTR(-EINVAL); |
a1f1c21c | 6038 | |
256da02d LC |
6039 | if (attrs[NL80211_ATTR_IE]) |
6040 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); | |
807f8a8c LC |
6041 | else |
6042 | ie_len = 0; | |
6043 | ||
5a865bad | 6044 | if (ie_len > wiphy->max_sched_scan_ie_len) |
256da02d | 6045 | return ERR_PTR(-EINVAL); |
c10841ca | 6046 | |
807f8a8c | 6047 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 6048 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 6049 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 6050 | + sizeof(*request->channels) * n_channels |
807f8a8c | 6051 | + ie_len, GFP_KERNEL); |
256da02d LC |
6052 | if (!request) |
6053 | return ERR_PTR(-ENOMEM); | |
807f8a8c LC |
6054 | |
6055 | if (n_ssids) | |
6056 | request->ssids = (void *)&request->channels[n_channels]; | |
6057 | request->n_ssids = n_ssids; | |
6058 | if (ie_len) { | |
13874e4b | 6059 | if (n_ssids) |
807f8a8c LC |
6060 | request->ie = (void *)(request->ssids + n_ssids); |
6061 | else | |
6062 | request->ie = (void *)(request->channels + n_channels); | |
6063 | } | |
6064 | ||
a1f1c21c LC |
6065 | if (n_match_sets) { |
6066 | if (request->ie) | |
6067 | request->match_sets = (void *)(request->ie + ie_len); | |
13874e4b | 6068 | else if (n_ssids) |
a1f1c21c LC |
6069 | request->match_sets = |
6070 | (void *)(request->ssids + n_ssids); | |
6071 | else | |
6072 | request->match_sets = | |
6073 | (void *)(request->channels + n_channels); | |
6074 | } | |
6075 | request->n_match_sets = n_match_sets; | |
6076 | ||
807f8a8c | 6077 | i = 0; |
256da02d | 6078 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c LC |
6079 | /* user specified, bail out if channel not found */ |
6080 | nla_for_each_nested(attr, | |
256da02d | 6081 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
807f8a8c LC |
6082 | tmp) { |
6083 | struct ieee80211_channel *chan; | |
6084 | ||
6085 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
6086 | ||
6087 | if (!chan) { | |
6088 | err = -EINVAL; | |
6089 | goto out_free; | |
6090 | } | |
6091 | ||
6092 | /* ignore disabled channels */ | |
6093 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6094 | continue; | |
6095 | ||
6096 | request->channels[i] = chan; | |
6097 | i++; | |
6098 | } | |
6099 | } else { | |
6100 | /* all channels */ | |
6101 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6102 | int j; | |
6103 | if (!wiphy->bands[band]) | |
6104 | continue; | |
6105 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
6106 | struct ieee80211_channel *chan; | |
6107 | ||
6108 | chan = &wiphy->bands[band]->channels[j]; | |
6109 | ||
6110 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6111 | continue; | |
6112 | ||
6113 | request->channels[i] = chan; | |
6114 | i++; | |
6115 | } | |
6116 | } | |
6117 | } | |
6118 | ||
6119 | if (!i) { | |
6120 | err = -EINVAL; | |
6121 | goto out_free; | |
6122 | } | |
6123 | ||
6124 | request->n_channels = i; | |
6125 | ||
6126 | i = 0; | |
13874e4b | 6127 | if (n_ssids) { |
256da02d | 6128 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
807f8a8c | 6129 | tmp) { |
57a27e1d | 6130 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
6131 | err = -EINVAL; |
6132 | goto out_free; | |
6133 | } | |
57a27e1d | 6134 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
6135 | memcpy(request->ssids[i].ssid, nla_data(attr), |
6136 | nla_len(attr)); | |
807f8a8c LC |
6137 | i++; |
6138 | } | |
6139 | } | |
6140 | ||
a1f1c21c | 6141 | i = 0; |
256da02d | 6142 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 6143 | nla_for_each_nested(attr, |
256da02d | 6144 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
a1f1c21c | 6145 | tmp) { |
88e920b4 | 6146 | struct nlattr *ssid, *rssi; |
a1f1c21c | 6147 | |
ae811e21 JB |
6148 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
6149 | nla_data(attr), nla_len(attr), | |
6150 | nl80211_match_policy); | |
6151 | if (err) | |
6152 | goto out_free; | |
4a4ab0d7 | 6153 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 6154 | if (ssid) { |
ea73cbce JB |
6155 | if (WARN_ON(i >= n_match_sets)) { |
6156 | /* this indicates a programming error, | |
6157 | * the loop above should have verified | |
6158 | * things properly | |
6159 | */ | |
6160 | err = -EINVAL; | |
6161 | goto out_free; | |
6162 | } | |
6163 | ||
a1f1c21c LC |
6164 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
6165 | err = -EINVAL; | |
6166 | goto out_free; | |
6167 | } | |
6168 | memcpy(request->match_sets[i].ssid.ssid, | |
6169 | nla_data(ssid), nla_len(ssid)); | |
6170 | request->match_sets[i].ssid.ssid_len = | |
6171 | nla_len(ssid); | |
ea73cbce JB |
6172 | /* special attribute - old implemenation w/a */ |
6173 | request->match_sets[i].rssi_thold = | |
6174 | default_match_rssi; | |
6175 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6176 | if (rssi) | |
6177 | request->match_sets[i].rssi_thold = | |
6178 | nla_get_s32(rssi); | |
a1f1c21c LC |
6179 | } |
6180 | i++; | |
6181 | } | |
ea73cbce JB |
6182 | |
6183 | /* there was no other matchset, so the RSSI one is alone */ | |
f89f46cf | 6184 | if (i == 0 && n_match_sets) |
ea73cbce JB |
6185 | request->match_sets[0].rssi_thold = default_match_rssi; |
6186 | ||
6187 | request->min_rssi_thold = INT_MAX; | |
6188 | for (i = 0; i < n_match_sets; i++) | |
6189 | request->min_rssi_thold = | |
6190 | min(request->match_sets[i].rssi_thold, | |
6191 | request->min_rssi_thold); | |
6192 | } else { | |
6193 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
6194 | } |
6195 | ||
9900e484 JB |
6196 | if (ie_len) { |
6197 | request->ie_len = ie_len; | |
807f8a8c | 6198 | memcpy((void *)request->ie, |
256da02d | 6199 | nla_data(attrs[NL80211_ATTR_IE]), |
807f8a8c LC |
6200 | request->ie_len); |
6201 | } | |
6202 | ||
256da02d | 6203 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 | 6204 | request->flags = nla_get_u32( |
256da02d | 6205 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
00c3a6ed JB |
6206 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
6207 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
6208 | err = -EOPNOTSUPP; |
6209 | goto out_free; | |
6210 | } | |
ad2b26ab JB |
6211 | |
6212 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
6213 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; | |
6214 | ||
6215 | if (!wdev) /* must be net-detect */ | |
6216 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
6217 | ||
6218 | if (!(wiphy->features & flg)) { | |
6219 | err = -EOPNOTSUPP; | |
6220 | goto out_free; | |
6221 | } | |
6222 | ||
6223 | if (wdev && wdev->current_bss) { | |
6224 | err = -EOPNOTSUPP; | |
6225 | goto out_free; | |
6226 | } | |
6227 | ||
6228 | err = nl80211_parse_random_mac(attrs, request->mac_addr, | |
6229 | request->mac_addr_mask); | |
6230 | if (err) | |
6231 | goto out_free; | |
6232 | } | |
46856bbf | 6233 | } |
ed473771 | 6234 | |
9c748934 LC |
6235 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
6236 | request->delay = | |
6237 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); | |
6238 | ||
bbe6ad6d | 6239 | request->interval = interval; |
15d6030b | 6240 | request->scan_start = jiffies; |
807f8a8c | 6241 | |
256da02d | 6242 | return request; |
807f8a8c LC |
6243 | |
6244 | out_free: | |
6245 | kfree(request); | |
256da02d LC |
6246 | return ERR_PTR(err); |
6247 | } | |
6248 | ||
6249 | static int nl80211_start_sched_scan(struct sk_buff *skb, | |
6250 | struct genl_info *info) | |
6251 | { | |
6252 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6253 | struct net_device *dev = info->user_ptr[1]; | |
ad2b26ab | 6254 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
31a60ed1 | 6255 | struct cfg80211_sched_scan_request *sched_scan_req; |
256da02d LC |
6256 | int err; |
6257 | ||
6258 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6259 | !rdev->ops->sched_scan_start) | |
6260 | return -EOPNOTSUPP; | |
6261 | ||
6262 | if (rdev->sched_scan_req) | |
6263 | return -EINPROGRESS; | |
6264 | ||
31a60ed1 JR |
6265 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
6266 | info->attrs); | |
6267 | ||
6268 | err = PTR_ERR_OR_ZERO(sched_scan_req); | |
256da02d LC |
6269 | if (err) |
6270 | goto out_err; | |
6271 | ||
31a60ed1 | 6272 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
256da02d LC |
6273 | if (err) |
6274 | goto out_free; | |
6275 | ||
31a60ed1 JR |
6276 | sched_scan_req->dev = dev; |
6277 | sched_scan_req->wiphy = &rdev->wiphy; | |
6278 | ||
93a1e86c JR |
6279 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
6280 | sched_scan_req->owner_nlportid = info->snd_portid; | |
6281 | ||
31a60ed1 | 6282 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
256da02d LC |
6283 | |
6284 | nl80211_send_sched_scan(rdev, dev, | |
6285 | NL80211_CMD_START_SCHED_SCAN); | |
6286 | return 0; | |
6287 | ||
6288 | out_free: | |
31a60ed1 | 6289 | kfree(sched_scan_req); |
256da02d | 6290 | out_err: |
807f8a8c LC |
6291 | return err; |
6292 | } | |
6293 | ||
6294 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
6295 | struct genl_info *info) | |
6296 | { | |
6297 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6298 | ||
6299 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6300 | !rdev->ops->sched_scan_stop) | |
6301 | return -EOPNOTSUPP; | |
6302 | ||
5fe231e8 | 6303 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
6304 | } |
6305 | ||
04f39047 SW |
6306 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
6307 | struct genl_info *info) | |
6308 | { | |
6309 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6310 | struct net_device *dev = info->user_ptr[1]; | |
6311 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6312 | struct cfg80211_chan_def chandef; | |
55f7435c | 6313 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 6314 | unsigned int cac_time_ms; |
04f39047 SW |
6315 | int err; |
6316 | ||
55f7435c LR |
6317 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
6318 | if (dfs_region == NL80211_DFS_UNSET) | |
6319 | return -EINVAL; | |
6320 | ||
04f39047 SW |
6321 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6322 | if (err) | |
6323 | return err; | |
6324 | ||
ff311bc1 SW |
6325 | if (netif_carrier_ok(dev)) |
6326 | return -EBUSY; | |
6327 | ||
04f39047 SW |
6328 | if (wdev->cac_started) |
6329 | return -EBUSY; | |
6330 | ||
2beb6dab | 6331 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
00ec75fc | 6332 | wdev->iftype); |
04f39047 SW |
6333 | if (err < 0) |
6334 | return err; | |
6335 | ||
6336 | if (err == 0) | |
6337 | return -EINVAL; | |
6338 | ||
fe7c3a1f | 6339 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
6340 | return -EINVAL; |
6341 | ||
6342 | if (!rdev->ops->start_radar_detection) | |
6343 | return -EOPNOTSUPP; | |
6344 | ||
31559f35 JD |
6345 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
6346 | if (WARN_ON(!cac_time_ms)) | |
6347 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
6348 | ||
6349 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, | |
6350 | cac_time_ms); | |
04f39047 | 6351 | if (!err) { |
9e0e2961 | 6352 | wdev->chandef = chandef; |
04f39047 SW |
6353 | wdev->cac_started = true; |
6354 | wdev->cac_start_time = jiffies; | |
31559f35 | 6355 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 6356 | } |
04f39047 SW |
6357 | return err; |
6358 | } | |
6359 | ||
16ef1fe2 SW |
6360 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
6361 | { | |
6362 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6363 | struct net_device *dev = info->user_ptr[1]; | |
6364 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6365 | struct cfg80211_csa_settings params; | |
6366 | /* csa_attrs is defined static to avoid waste of stack size - this | |
6367 | * function is called under RTNL lock, so this should not be a problem. | |
6368 | */ | |
6369 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
16ef1fe2 | 6370 | int err; |
ee4bc9e7 | 6371 | bool need_new_beacon = false; |
9a774c78 | 6372 | int len, i; |
252e07ca | 6373 | u32 cs_count; |
16ef1fe2 SW |
6374 | |
6375 | if (!rdev->ops->channel_switch || | |
6376 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
6377 | return -EOPNOTSUPP; | |
6378 | ||
ee4bc9e7 SW |
6379 | switch (dev->ieee80211_ptr->iftype) { |
6380 | case NL80211_IFTYPE_AP: | |
6381 | case NL80211_IFTYPE_P2P_GO: | |
6382 | need_new_beacon = true; | |
6383 | ||
6384 | /* useless if AP is not running */ | |
6385 | if (!wdev->beacon_interval) | |
1ff79dfa | 6386 | return -ENOTCONN; |
ee4bc9e7 SW |
6387 | break; |
6388 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
6389 | if (!wdev->ssid_len) |
6390 | return -ENOTCONN; | |
6391 | break; | |
c6da674a | 6392 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
6393 | if (!wdev->mesh_id_len) |
6394 | return -ENOTCONN; | |
ee4bc9e7 SW |
6395 | break; |
6396 | default: | |
16ef1fe2 | 6397 | return -EOPNOTSUPP; |
ee4bc9e7 | 6398 | } |
16ef1fe2 SW |
6399 | |
6400 | memset(¶ms, 0, sizeof(params)); | |
6401 | ||
6402 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6403 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
6404 | return -EINVAL; | |
6405 | ||
6406 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 6407 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
6408 | return -EINVAL; |
6409 | ||
252e07ca LC |
6410 | /* Even though the attribute is u32, the specification says |
6411 | * u8, so let's make sure we don't overflow. | |
6412 | */ | |
6413 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
6414 | if (cs_count > 255) | |
6415 | return -EINVAL; | |
6416 | ||
6417 | params.count = cs_count; | |
16ef1fe2 | 6418 | |
ee4bc9e7 SW |
6419 | if (!need_new_beacon) |
6420 | goto skip_beacons; | |
6421 | ||
16ef1fe2 SW |
6422 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
6423 | if (err) | |
6424 | return err; | |
6425 | ||
6426 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
6427 | info->attrs[NL80211_ATTR_CSA_IES], | |
6428 | nl80211_policy); | |
6429 | if (err) | |
6430 | return err; | |
6431 | ||
6432 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
6433 | if (err) | |
6434 | return err; | |
6435 | ||
6436 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
6437 | return -EINVAL; | |
6438 | ||
9a774c78 AO |
6439 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
6440 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6441 | return -EINVAL; |
6442 | ||
9a774c78 AO |
6443 | params.n_counter_offsets_beacon = len / sizeof(u16); |
6444 | if (rdev->wiphy.max_num_csa_counters && | |
6445 | (params.n_counter_offsets_beacon > | |
6446 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
6447 | return -EINVAL; |
6448 | ||
9a774c78 AO |
6449 | params.counter_offsets_beacon = |
6450 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
6451 | ||
6452 | /* sanity checks - counters should fit and be the same */ | |
6453 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
6454 | u16 offset = params.counter_offsets_beacon[i]; | |
6455 | ||
6456 | if (offset >= params.beacon_csa.tail_len) | |
6457 | return -EINVAL; | |
6458 | ||
6459 | if (params.beacon_csa.tail[offset] != params.count) | |
6460 | return -EINVAL; | |
6461 | } | |
6462 | ||
16ef1fe2 | 6463 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
6464 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
6465 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6466 | return -EINVAL; |
6467 | ||
9a774c78 AO |
6468 | params.n_counter_offsets_presp = len / sizeof(u16); |
6469 | if (rdev->wiphy.max_num_csa_counters && | |
6470 | (params.n_counter_offsets_beacon > | |
6471 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 | 6472 | return -EINVAL; |
9a774c78 AO |
6473 | |
6474 | params.counter_offsets_presp = | |
6475 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
6476 | ||
6477 | /* sanity checks - counters should fit and be the same */ | |
6478 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
6479 | u16 offset = params.counter_offsets_presp[i]; | |
6480 | ||
6481 | if (offset >= params.beacon_csa.probe_resp_len) | |
6482 | return -EINVAL; | |
6483 | ||
6484 | if (params.beacon_csa.probe_resp[offset] != | |
6485 | params.count) | |
6486 | return -EINVAL; | |
6487 | } | |
16ef1fe2 SW |
6488 | } |
6489 | ||
ee4bc9e7 | 6490 | skip_beacons: |
16ef1fe2 SW |
6491 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
6492 | if (err) | |
6493 | return err; | |
6494 | ||
174e0cd2 IP |
6495 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
6496 | wdev->iftype)) | |
16ef1fe2 SW |
6497 | return -EINVAL; |
6498 | ||
2beb6dab LC |
6499 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
6500 | ¶ms.chandef, | |
6501 | wdev->iftype); | |
6502 | if (err < 0) | |
6503 | return err; | |
6504 | ||
dcc6c2f5 | 6505 | if (err > 0) |
2beb6dab | 6506 | params.radar_required = true; |
16ef1fe2 | 6507 | |
16ef1fe2 SW |
6508 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
6509 | params.block_tx = true; | |
6510 | ||
c56589ed SW |
6511 | wdev_lock(wdev); |
6512 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
6513 | wdev_unlock(wdev); | |
6514 | ||
6515 | return err; | |
16ef1fe2 SW |
6516 | } |
6517 | ||
9720bb3a JB |
6518 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
6519 | u32 seq, int flags, | |
2a519311 | 6520 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
6521 | struct wireless_dev *wdev, |
6522 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 6523 | { |
48ab905d | 6524 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 6525 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
6526 | void *hdr; |
6527 | struct nlattr *bss; | |
48ab905d JB |
6528 | |
6529 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 6530 | |
15e47304 | 6531 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
6532 | NL80211_CMD_NEW_SCAN_RESULTS); |
6533 | if (!hdr) | |
6534 | return -1; | |
6535 | ||
9720bb3a JB |
6536 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
6537 | ||
97990a06 JB |
6538 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
6539 | goto nla_put_failure; | |
6540 | if (wdev->netdev && | |
9360ffd1 DM |
6541 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
6542 | goto nla_put_failure; | |
97990a06 JB |
6543 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
6544 | goto nla_put_failure; | |
2a519311 JB |
6545 | |
6546 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
6547 | if (!bss) | |
6548 | goto nla_put_failure; | |
9360ffd1 | 6549 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 6550 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 6551 | goto nla_put_failure; |
9caf0364 JB |
6552 | |
6553 | rcu_read_lock(); | |
0e227084 JB |
6554 | /* indicate whether we have probe response data or not */ |
6555 | if (rcu_access_pointer(res->proberesp_ies) && | |
6556 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
6557 | goto fail_unlock_rcu; | |
6558 | ||
6559 | /* this pointer prefers to be pointed to probe response data | |
6560 | * but is always valid | |
6561 | */ | |
9caf0364 | 6562 | ies = rcu_dereference(res->ies); |
8cef2c9d JB |
6563 | if (ies) { |
6564 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
6565 | goto fail_unlock_rcu; | |
8cef2c9d JB |
6566 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
6567 | ies->len, ies->data)) | |
6568 | goto fail_unlock_rcu; | |
9caf0364 | 6569 | } |
0e227084 JB |
6570 | |
6571 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 6572 | ies = rcu_dereference(res->beacon_ies); |
0e227084 JB |
6573 | if (ies && ies->from_beacon) { |
6574 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) | |
8cef2c9d JB |
6575 | goto fail_unlock_rcu; |
6576 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
6577 | ies->len, ies->data)) | |
6578 | goto fail_unlock_rcu; | |
9caf0364 JB |
6579 | } |
6580 | rcu_read_unlock(); | |
6581 | ||
9360ffd1 DM |
6582 | if (res->beacon_interval && |
6583 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
6584 | goto nla_put_failure; | |
6585 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
6586 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 6587 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
6588 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
6589 | jiffies_to_msecs(jiffies - intbss->ts))) | |
6590 | goto nla_put_failure; | |
2a519311 | 6591 | |
77965c97 | 6592 | switch (rdev->wiphy.signal_type) { |
2a519311 | 6593 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
6594 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
6595 | goto nla_put_failure; | |
2a519311 JB |
6596 | break; |
6597 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
6598 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
6599 | goto nla_put_failure; | |
2a519311 JB |
6600 | break; |
6601 | default: | |
6602 | break; | |
6603 | } | |
6604 | ||
48ab905d | 6605 | switch (wdev->iftype) { |
074ac8df | 6606 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 6607 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
6608 | if (intbss == wdev->current_bss && |
6609 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6610 | NL80211_BSS_STATUS_ASSOCIATED)) | |
6611 | goto nla_put_failure; | |
48ab905d JB |
6612 | break; |
6613 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
6614 | if (intbss == wdev->current_bss && |
6615 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6616 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
6617 | goto nla_put_failure; | |
48ab905d JB |
6618 | break; |
6619 | default: | |
6620 | break; | |
6621 | } | |
6622 | ||
2a519311 JB |
6623 | nla_nest_end(msg, bss); |
6624 | ||
053c095a JB |
6625 | genlmsg_end(msg, hdr); |
6626 | return 0; | |
2a519311 | 6627 | |
8cef2c9d JB |
6628 | fail_unlock_rcu: |
6629 | rcu_read_unlock(); | |
2a519311 JB |
6630 | nla_put_failure: |
6631 | genlmsg_cancel(msg, hdr); | |
6632 | return -EMSGSIZE; | |
6633 | } | |
6634 | ||
97990a06 | 6635 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 6636 | { |
48ab905d | 6637 | struct cfg80211_registered_device *rdev; |
2a519311 | 6638 | struct cfg80211_internal_bss *scan; |
48ab905d | 6639 | struct wireless_dev *wdev; |
97990a06 | 6640 | int start = cb->args[2], idx = 0; |
2a519311 JB |
6641 | int err; |
6642 | ||
97990a06 | 6643 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6644 | if (err) |
6645 | return err; | |
2a519311 | 6646 | |
48ab905d JB |
6647 | wdev_lock(wdev); |
6648 | spin_lock_bh(&rdev->bss_lock); | |
6649 | cfg80211_bss_expire(rdev); | |
6650 | ||
9720bb3a JB |
6651 | cb->seq = rdev->bss_generation; |
6652 | ||
48ab905d | 6653 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
6654 | if (++idx <= start) |
6655 | continue; | |
9720bb3a | 6656 | if (nl80211_send_bss(skb, cb, |
2a519311 | 6657 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 6658 | rdev, wdev, scan) < 0) { |
2a519311 | 6659 | idx--; |
67748893 | 6660 | break; |
2a519311 JB |
6661 | } |
6662 | } | |
6663 | ||
48ab905d JB |
6664 | spin_unlock_bh(&rdev->bss_lock); |
6665 | wdev_unlock(wdev); | |
2a519311 | 6666 | |
97990a06 JB |
6667 | cb->args[2] = idx; |
6668 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 6669 | |
67748893 | 6670 | return skb->len; |
2a519311 JB |
6671 | } |
6672 | ||
15e47304 | 6673 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
11f78ac3 JB |
6674 | int flags, struct net_device *dev, |
6675 | bool allow_radio_stats, | |
6676 | struct survey_info *survey) | |
61fa713c HS |
6677 | { |
6678 | void *hdr; | |
6679 | struct nlattr *infoattr; | |
6680 | ||
11f78ac3 JB |
6681 | /* skip radio stats if userspace didn't request them */ |
6682 | if (!survey->channel && !allow_radio_stats) | |
6683 | return 0; | |
6684 | ||
15e47304 | 6685 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
6686 | NL80211_CMD_NEW_SURVEY_RESULTS); |
6687 | if (!hdr) | |
6688 | return -ENOMEM; | |
6689 | ||
9360ffd1 DM |
6690 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
6691 | goto nla_put_failure; | |
61fa713c HS |
6692 | |
6693 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
6694 | if (!infoattr) | |
6695 | goto nla_put_failure; | |
6696 | ||
11f78ac3 JB |
6697 | if (survey->channel && |
6698 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
9360ffd1 DM |
6699 | survey->channel->center_freq)) |
6700 | goto nla_put_failure; | |
6701 | ||
6702 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
6703 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
6704 | goto nla_put_failure; | |
6705 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
6706 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
6707 | goto nla_put_failure; | |
4ed20beb JB |
6708 | if ((survey->filled & SURVEY_INFO_TIME) && |
6709 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME, | |
6710 | survey->time)) | |
9360ffd1 | 6711 | goto nla_put_failure; |
4ed20beb JB |
6712 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
6713 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY, | |
6714 | survey->time_busy)) | |
9360ffd1 | 6715 | goto nla_put_failure; |
4ed20beb JB |
6716 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
6717 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, | |
6718 | survey->time_ext_busy)) | |
9360ffd1 | 6719 | goto nla_put_failure; |
4ed20beb JB |
6720 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
6721 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX, | |
6722 | survey->time_rx)) | |
9360ffd1 | 6723 | goto nla_put_failure; |
4ed20beb JB |
6724 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
6725 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX, | |
6726 | survey->time_tx)) | |
9360ffd1 | 6727 | goto nla_put_failure; |
052536ab JB |
6728 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
6729 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN, | |
6730 | survey->time_scan)) | |
6731 | goto nla_put_failure; | |
61fa713c HS |
6732 | |
6733 | nla_nest_end(msg, infoattr); | |
6734 | ||
053c095a JB |
6735 | genlmsg_end(msg, hdr); |
6736 | return 0; | |
61fa713c HS |
6737 | |
6738 | nla_put_failure: | |
6739 | genlmsg_cancel(msg, hdr); | |
6740 | return -EMSGSIZE; | |
6741 | } | |
6742 | ||
11f78ac3 | 6743 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
61fa713c HS |
6744 | { |
6745 | struct survey_info survey; | |
1b8ec87a | 6746 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
6747 | struct wireless_dev *wdev; |
6748 | int survey_idx = cb->args[2]; | |
61fa713c | 6749 | int res; |
11f78ac3 | 6750 | bool radio_stats; |
61fa713c | 6751 | |
1b8ec87a | 6752 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6753 | if (res) |
6754 | return res; | |
61fa713c | 6755 | |
11f78ac3 JB |
6756 | /* prepare_wdev_dump parsed the attributes */ |
6757 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; | |
6758 | ||
97990a06 JB |
6759 | if (!wdev->netdev) { |
6760 | res = -EINVAL; | |
6761 | goto out_err; | |
6762 | } | |
6763 | ||
1b8ec87a | 6764 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
6765 | res = -EOPNOTSUPP; |
6766 | goto out_err; | |
6767 | } | |
6768 | ||
6769 | while (1) { | |
1b8ec87a | 6770 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
6771 | if (res == -ENOENT) |
6772 | break; | |
6773 | if (res) | |
6774 | goto out_err; | |
6775 | ||
11f78ac3 JB |
6776 | /* don't send disabled channels, but do send non-channel data */ |
6777 | if (survey.channel && | |
6778 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { | |
180cdc79 LR |
6779 | survey_idx++; |
6780 | continue; | |
6781 | } | |
6782 | ||
61fa713c | 6783 | if (nl80211_send_survey(skb, |
15e47304 | 6784 | NETLINK_CB(cb->skb).portid, |
61fa713c | 6785 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
11f78ac3 | 6786 | wdev->netdev, radio_stats, &survey) < 0) |
61fa713c HS |
6787 | goto out; |
6788 | survey_idx++; | |
6789 | } | |
6790 | ||
6791 | out: | |
97990a06 | 6792 | cb->args[2] = survey_idx; |
61fa713c HS |
6793 | res = skb->len; |
6794 | out_err: | |
1b8ec87a | 6795 | nl80211_finish_wdev_dump(rdev); |
61fa713c HS |
6796 | return res; |
6797 | } | |
6798 | ||
b23aa676 SO |
6799 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
6800 | { | |
6801 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
6802 | NL80211_WPA_VERSION_2)); | |
6803 | } | |
6804 | ||
636a5d36 JM |
6805 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
6806 | { | |
4c476991 JB |
6807 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6808 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6809 | struct ieee80211_channel *chan; |
e39e5b5e JM |
6810 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
6811 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 6812 | enum nl80211_auth_type auth_type; |
fffd0934 | 6813 | struct key_parse key; |
d5cdfacb | 6814 | bool local_state_change; |
636a5d36 | 6815 | |
f4a11bb0 JB |
6816 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6817 | return -EINVAL; | |
6818 | ||
6819 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6820 | return -EINVAL; | |
6821 | ||
1778092e JM |
6822 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
6823 | return -EINVAL; | |
6824 | ||
19957bb3 JB |
6825 | if (!info->attrs[NL80211_ATTR_SSID]) |
6826 | return -EINVAL; | |
6827 | ||
6828 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
6829 | return -EINVAL; | |
6830 | ||
fffd0934 JB |
6831 | err = nl80211_parse_key(info, &key); |
6832 | if (err) | |
6833 | return err; | |
6834 | ||
6835 | if (key.idx >= 0) { | |
e31b8213 JB |
6836 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
6837 | return -EINVAL; | |
fffd0934 JB |
6838 | if (!key.p.key || !key.p.key_len) |
6839 | return -EINVAL; | |
6840 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
6841 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
6842 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
6843 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
6844 | return -EINVAL; | |
6845 | if (key.idx > 4) | |
6846 | return -EINVAL; | |
6847 | } else { | |
6848 | key.p.key_len = 0; | |
6849 | key.p.key = NULL; | |
6850 | } | |
6851 | ||
afea0b7a JB |
6852 | if (key.idx >= 0) { |
6853 | int i; | |
6854 | bool ok = false; | |
6855 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
6856 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
6857 | ok = true; | |
6858 | break; | |
6859 | } | |
6860 | } | |
4c476991 JB |
6861 | if (!ok) |
6862 | return -EINVAL; | |
afea0b7a JB |
6863 | } |
6864 | ||
4c476991 JB |
6865 | if (!rdev->ops->auth) |
6866 | return -EOPNOTSUPP; | |
636a5d36 | 6867 | |
074ac8df | 6868 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6869 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6870 | return -EOPNOTSUPP; | |
eec60b03 | 6871 | |
19957bb3 | 6872 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
6873 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6874 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6875 | if (!chan) | |
4c476991 | 6876 | return -EINVAL; |
636a5d36 | 6877 | |
19957bb3 JB |
6878 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6879 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6880 | |
6881 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6882 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6883 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6884 | } |
6885 | ||
19957bb3 | 6886 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 6887 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 6888 | return -EINVAL; |
636a5d36 | 6889 | |
e39e5b5e JM |
6890 | if (auth_type == NL80211_AUTHTYPE_SAE && |
6891 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
6892 | return -EINVAL; | |
6893 | ||
6894 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
6895 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
6896 | return -EINVAL; | |
6897 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6898 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6899 | /* need to include at least Auth Transaction and Status Code */ | |
6900 | if (sae_data_len < 4) | |
6901 | return -EINVAL; | |
6902 | } | |
6903 | ||
d5cdfacb JM |
6904 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6905 | ||
95de817b JB |
6906 | /* |
6907 | * Since we no longer track auth state, ignore | |
6908 | * requests to only change local state. | |
6909 | */ | |
6910 | if (local_state_change) | |
6911 | return 0; | |
6912 | ||
91bf9b26 JB |
6913 | wdev_lock(dev->ieee80211_ptr); |
6914 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
6915 | ssid, ssid_len, ie, ie_len, | |
6916 | key.p.key, key.p.key_len, key.idx, | |
6917 | sae_data, sae_data_len); | |
6918 | wdev_unlock(dev->ieee80211_ptr); | |
6919 | return err; | |
636a5d36 JM |
6920 | } |
6921 | ||
c0692b8f JB |
6922 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6923 | struct genl_info *info, | |
3dc27d25 JB |
6924 | struct cfg80211_crypto_settings *settings, |
6925 | int cipher_limit) | |
b23aa676 | 6926 | { |
c0b2bbd8 JB |
6927 | memset(settings, 0, sizeof(*settings)); |
6928 | ||
b23aa676 SO |
6929 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6930 | ||
c0692b8f JB |
6931 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6932 | u16 proto; | |
6933 | proto = nla_get_u16( | |
6934 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6935 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6936 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6937 | proto != ETH_P_PAE) | |
6938 | return -EINVAL; | |
6939 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6940 | settings->control_port_no_encrypt = true; | |
6941 | } else | |
6942 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6943 | ||
b23aa676 SO |
6944 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6945 | void *data; | |
6946 | int len, i; | |
6947 | ||
6948 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6949 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6950 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6951 | ||
6952 | if (len % sizeof(u32)) | |
6953 | return -EINVAL; | |
6954 | ||
3dc27d25 | 6955 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6956 | return -EINVAL; |
6957 | ||
6958 | memcpy(settings->ciphers_pairwise, data, len); | |
6959 | ||
6960 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6961 | if (!cfg80211_supported_cipher_suite( |
6962 | &rdev->wiphy, | |
b23aa676 SO |
6963 | settings->ciphers_pairwise[i])) |
6964 | return -EINVAL; | |
6965 | } | |
6966 | ||
6967 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6968 | settings->cipher_group = | |
6969 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6970 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6971 | settings->cipher_group)) | |
b23aa676 SO |
6972 | return -EINVAL; |
6973 | } | |
6974 | ||
6975 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6976 | settings->wpa_versions = | |
6977 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6978 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6979 | return -EINVAL; | |
6980 | } | |
6981 | ||
6982 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6983 | void *data; | |
6d30240e | 6984 | int len; |
b23aa676 SO |
6985 | |
6986 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6987 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6988 | settings->n_akm_suites = len / sizeof(u32); | |
6989 | ||
6990 | if (len % sizeof(u32)) | |
6991 | return -EINVAL; | |
6992 | ||
1b9ca027 JM |
6993 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6994 | return -EINVAL; | |
6995 | ||
b23aa676 | 6996 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6997 | } |
6998 | ||
6999 | return 0; | |
7000 | } | |
7001 | ||
636a5d36 JM |
7002 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
7003 | { | |
4c476991 JB |
7004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7005 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 7006 | struct ieee80211_channel *chan; |
f62fab73 JB |
7007 | struct cfg80211_assoc_request req = {}; |
7008 | const u8 *bssid, *ssid; | |
7009 | int err, ssid_len = 0; | |
636a5d36 | 7010 | |
f4a11bb0 JB |
7011 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7012 | return -EINVAL; | |
7013 | ||
7014 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
7015 | !info->attrs[NL80211_ATTR_SSID] || |
7016 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
7017 | return -EINVAL; |
7018 | ||
4c476991 JB |
7019 | if (!rdev->ops->assoc) |
7020 | return -EOPNOTSUPP; | |
636a5d36 | 7021 | |
074ac8df | 7022 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7023 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7024 | return -EOPNOTSUPP; | |
eec60b03 | 7025 | |
19957bb3 | 7026 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7027 | |
664834de JM |
7028 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
7029 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7030 | if (!chan) | |
4c476991 | 7031 | return -EINVAL; |
636a5d36 | 7032 | |
19957bb3 JB |
7033 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7034 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
7035 | |
7036 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
7037 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7038 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7039 | } |
7040 | ||
dc6382ce | 7041 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 7042 | enum nl80211_mfp mfp = |
dc6382ce | 7043 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 7044 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 7045 | req.use_mfp = true; |
4c476991 JB |
7046 | else if (mfp != NL80211_MFP_NO) |
7047 | return -EINVAL; | |
dc6382ce JM |
7048 | } |
7049 | ||
3e5d7649 | 7050 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 7051 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 7052 | |
7e7c8926 | 7053 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 7054 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
7055 | |
7056 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
7057 | memcpy(&req.ht_capa_mask, |
7058 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7059 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
7060 | |
7061 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 7062 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 7063 | return -EINVAL; |
f62fab73 JB |
7064 | memcpy(&req.ht_capa, |
7065 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7066 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
7067 | } |
7068 | ||
ee2aca34 | 7069 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 7070 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
7071 | |
7072 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
7073 | memcpy(&req.vht_capa_mask, |
7074 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7075 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
7076 | |
7077 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 7078 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 7079 | return -EINVAL; |
f62fab73 JB |
7080 | memcpy(&req.vht_capa, |
7081 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7082 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
7083 | } |
7084 | ||
bab5ab7d AK |
7085 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7086 | if (!(rdev->wiphy.features & | |
7087 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7088 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7089 | return -EINVAL; | |
7090 | req.flags |= ASSOC_REQ_USE_RRM; | |
7091 | } | |
7092 | ||
f62fab73 | 7093 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
7094 | if (!err) { |
7095 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
7096 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
7097 | ssid, ssid_len, &req); | |
91bf9b26 JB |
7098 | wdev_unlock(dev->ieee80211_ptr); |
7099 | } | |
636a5d36 | 7100 | |
636a5d36 JM |
7101 | return err; |
7102 | } | |
7103 | ||
7104 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
7105 | { | |
4c476991 JB |
7106 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7107 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7108 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7109 | int ie_len = 0, err; |
19957bb3 | 7110 | u16 reason_code; |
d5cdfacb | 7111 | bool local_state_change; |
636a5d36 | 7112 | |
f4a11bb0 JB |
7113 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7114 | return -EINVAL; | |
7115 | ||
7116 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7117 | return -EINVAL; | |
7118 | ||
7119 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7120 | return -EINVAL; | |
7121 | ||
4c476991 JB |
7122 | if (!rdev->ops->deauth) |
7123 | return -EOPNOTSUPP; | |
636a5d36 | 7124 | |
074ac8df | 7125 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7126 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7127 | return -EOPNOTSUPP; | |
eec60b03 | 7128 | |
19957bb3 | 7129 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7130 | |
19957bb3 JB |
7131 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7132 | if (reason_code == 0) { | |
f4a11bb0 | 7133 | /* Reason Code 0 is reserved */ |
4c476991 | 7134 | return -EINVAL; |
255e737e | 7135 | } |
636a5d36 JM |
7136 | |
7137 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7138 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7139 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7140 | } |
7141 | ||
d5cdfacb JM |
7142 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7143 | ||
91bf9b26 JB |
7144 | wdev_lock(dev->ieee80211_ptr); |
7145 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
7146 | local_state_change); | |
7147 | wdev_unlock(dev->ieee80211_ptr); | |
7148 | return err; | |
636a5d36 JM |
7149 | } |
7150 | ||
7151 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
7152 | { | |
4c476991 JB |
7153 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7154 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7155 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7156 | int ie_len = 0, err; |
19957bb3 | 7157 | u16 reason_code; |
d5cdfacb | 7158 | bool local_state_change; |
636a5d36 | 7159 | |
f4a11bb0 JB |
7160 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7161 | return -EINVAL; | |
7162 | ||
7163 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7164 | return -EINVAL; | |
7165 | ||
7166 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7167 | return -EINVAL; | |
7168 | ||
4c476991 JB |
7169 | if (!rdev->ops->disassoc) |
7170 | return -EOPNOTSUPP; | |
636a5d36 | 7171 | |
074ac8df | 7172 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7173 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7174 | return -EOPNOTSUPP; | |
eec60b03 | 7175 | |
19957bb3 | 7176 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7177 | |
19957bb3 JB |
7178 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7179 | if (reason_code == 0) { | |
f4a11bb0 | 7180 | /* Reason Code 0 is reserved */ |
4c476991 | 7181 | return -EINVAL; |
255e737e | 7182 | } |
636a5d36 JM |
7183 | |
7184 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7185 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7186 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7187 | } |
7188 | ||
d5cdfacb JM |
7189 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7190 | ||
91bf9b26 JB |
7191 | wdev_lock(dev->ieee80211_ptr); |
7192 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
7193 | local_state_change); | |
7194 | wdev_unlock(dev->ieee80211_ptr); | |
7195 | return err; | |
636a5d36 JM |
7196 | } |
7197 | ||
dd5b4cc7 FF |
7198 | static bool |
7199 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
7200 | int mcast_rate[IEEE80211_NUM_BANDS], | |
7201 | int rateval) | |
7202 | { | |
7203 | struct wiphy *wiphy = &rdev->wiphy; | |
7204 | bool found = false; | |
7205 | int band, i; | |
7206 | ||
7207 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
7208 | struct ieee80211_supported_band *sband; | |
7209 | ||
7210 | sband = wiphy->bands[band]; | |
7211 | if (!sband) | |
7212 | continue; | |
7213 | ||
7214 | for (i = 0; i < sband->n_bitrates; i++) { | |
7215 | if (sband->bitrates[i].bitrate == rateval) { | |
7216 | mcast_rate[band] = i + 1; | |
7217 | found = true; | |
7218 | break; | |
7219 | } | |
7220 | } | |
7221 | } | |
7222 | ||
7223 | return found; | |
7224 | } | |
7225 | ||
04a773ad JB |
7226 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
7227 | { | |
4c476991 JB |
7228 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7229 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
7230 | struct cfg80211_ibss_params ibss; |
7231 | struct wiphy *wiphy; | |
fffd0934 | 7232 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
7233 | int err; |
7234 | ||
8e30bc55 JB |
7235 | memset(&ibss, 0, sizeof(ibss)); |
7236 | ||
04a773ad JB |
7237 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7238 | return -EINVAL; | |
7239 | ||
683b6d3b | 7240 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
7241 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
7242 | return -EINVAL; | |
7243 | ||
8e30bc55 JB |
7244 | ibss.beacon_interval = 100; |
7245 | ||
7246 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
7247 | ibss.beacon_interval = | |
7248 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7249 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
7250 | return -EINVAL; | |
7251 | } | |
7252 | ||
4c476991 JB |
7253 | if (!rdev->ops->join_ibss) |
7254 | return -EOPNOTSUPP; | |
04a773ad | 7255 | |
4c476991 JB |
7256 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7257 | return -EOPNOTSUPP; | |
04a773ad | 7258 | |
79c97e97 | 7259 | wiphy = &rdev->wiphy; |
04a773ad | 7260 | |
39193498 | 7261 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 7262 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
7263 | |
7264 | if (!is_valid_ether_addr(ibss.bssid)) | |
7265 | return -EINVAL; | |
7266 | } | |
04a773ad JB |
7267 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7268 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7269 | ||
7270 | if (info->attrs[NL80211_ATTR_IE]) { | |
7271 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7272 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7273 | } | |
7274 | ||
683b6d3b JB |
7275 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
7276 | if (err) | |
7277 | return err; | |
04a773ad | 7278 | |
174e0cd2 IP |
7279 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
7280 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
7281 | return -EINVAL; |
7282 | ||
2f301ab2 | 7283 | switch (ibss.chandef.width) { |
bf372645 SW |
7284 | case NL80211_CHAN_WIDTH_5: |
7285 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
7286 | case NL80211_CHAN_WIDTH_20_NOHT: |
7287 | break; | |
7288 | case NL80211_CHAN_WIDTH_20: | |
7289 | case NL80211_CHAN_WIDTH_40: | |
ffc11991 JD |
7290 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
7291 | return -EINVAL; | |
7292 | break; | |
7293 | case NL80211_CHAN_WIDTH_80: | |
7294 | case NL80211_CHAN_WIDTH_80P80: | |
7295 | case NL80211_CHAN_WIDTH_160: | |
7296 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | |
7297 | return -EINVAL; | |
7298 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
7299 | NL80211_EXT_FEATURE_VHT_IBSS)) | |
7300 | return -EINVAL; | |
7301 | break; | |
2f301ab2 | 7302 | default: |
c04d6150 | 7303 | return -EINVAL; |
2f301ab2 | 7304 | } |
db9c64cf | 7305 | |
04a773ad | 7306 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
7307 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
7308 | ||
fbd2c8dc TP |
7309 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
7310 | u8 *rates = | |
7311 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7312 | int n_rates = | |
7313 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7314 | struct ieee80211_supported_band *sband = | |
683b6d3b | 7315 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 7316 | |
34850ab2 JB |
7317 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
7318 | &ibss.basic_rates); | |
7319 | if (err) | |
7320 | return err; | |
fbd2c8dc | 7321 | } |
dd5b4cc7 | 7322 | |
803768f5 SW |
7323 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7324 | memcpy(&ibss.ht_capa_mask, | |
7325 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7326 | sizeof(ibss.ht_capa_mask)); | |
7327 | ||
7328 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
7329 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7330 | return -EINVAL; | |
7331 | memcpy(&ibss.ht_capa, | |
7332 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7333 | sizeof(ibss.ht_capa)); | |
7334 | } | |
7335 | ||
dd5b4cc7 FF |
7336 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7337 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
7338 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7339 | return -EINVAL; | |
fbd2c8dc | 7340 | |
4c476991 | 7341 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
7342 | bool no_ht = false; |
7343 | ||
4c476991 | 7344 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
7345 | info->attrs[NL80211_ATTR_KEYS], |
7346 | &no_ht); | |
4c476991 JB |
7347 | if (IS_ERR(connkeys)) |
7348 | return PTR_ERR(connkeys); | |
de7044ee | 7349 | |
3d9d1d66 JB |
7350 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
7351 | no_ht) { | |
de7044ee SM |
7352 | kfree(connkeys); |
7353 | return -EINVAL; | |
7354 | } | |
4c476991 | 7355 | } |
04a773ad | 7356 | |
267335d6 AQ |
7357 | ibss.control_port = |
7358 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
7359 | ||
5336fa88 SW |
7360 | ibss.userspace_handles_dfs = |
7361 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
7362 | ||
4c476991 | 7363 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 | 7364 | if (err) |
b47f610b | 7365 | kzfree(connkeys); |
04a773ad JB |
7366 | return err; |
7367 | } | |
7368 | ||
7369 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
7370 | { | |
4c476991 JB |
7371 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7372 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 7373 | |
4c476991 JB |
7374 | if (!rdev->ops->leave_ibss) |
7375 | return -EOPNOTSUPP; | |
04a773ad | 7376 | |
4c476991 JB |
7377 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7378 | return -EOPNOTSUPP; | |
04a773ad | 7379 | |
4c476991 | 7380 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
7381 | } |
7382 | ||
f4e583c8 AQ |
7383 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
7384 | { | |
7385 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7386 | struct net_device *dev = info->user_ptr[1]; | |
7387 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
7388 | u32 nla_rate; | |
7389 | int err; | |
7390 | ||
7391 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
7392 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
7393 | return -EOPNOTSUPP; | |
7394 | ||
7395 | if (!rdev->ops->set_mcast_rate) | |
7396 | return -EOPNOTSUPP; | |
7397 | ||
7398 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
7399 | ||
7400 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
7401 | return -EINVAL; | |
7402 | ||
7403 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
7404 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
7405 | return -EINVAL; | |
7406 | ||
7407 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
7408 | ||
7409 | return err; | |
7410 | } | |
7411 | ||
ad7e718c JB |
7412 | static struct sk_buff * |
7413 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
6c09e791 AK |
7414 | struct wireless_dev *wdev, int approxlen, |
7415 | u32 portid, u32 seq, enum nl80211_commands cmd, | |
567ffc35 JB |
7416 | enum nl80211_attrs attr, |
7417 | const struct nl80211_vendor_cmd_info *info, | |
7418 | gfp_t gfp) | |
ad7e718c JB |
7419 | { |
7420 | struct sk_buff *skb; | |
7421 | void *hdr; | |
7422 | struct nlattr *data; | |
7423 | ||
7424 | skb = nlmsg_new(approxlen + 100, gfp); | |
7425 | if (!skb) | |
7426 | return NULL; | |
7427 | ||
7428 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
7429 | if (!hdr) { | |
7430 | kfree_skb(skb); | |
7431 | return NULL; | |
7432 | } | |
7433 | ||
7434 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
7435 | goto nla_put_failure; | |
567ffc35 JB |
7436 | |
7437 | if (info) { | |
7438 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
7439 | info->vendor_id)) | |
7440 | goto nla_put_failure; | |
7441 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
7442 | info->subcmd)) | |
7443 | goto nla_put_failure; | |
7444 | } | |
7445 | ||
6c09e791 AK |
7446 | if (wdev) { |
7447 | if (nla_put_u64(skb, NL80211_ATTR_WDEV, | |
7448 | wdev_id(wdev))) | |
7449 | goto nla_put_failure; | |
7450 | if (wdev->netdev && | |
7451 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, | |
7452 | wdev->netdev->ifindex)) | |
7453 | goto nla_put_failure; | |
7454 | } | |
7455 | ||
ad7e718c JB |
7456 | data = nla_nest_start(skb, attr); |
7457 | ||
7458 | ((void **)skb->cb)[0] = rdev; | |
7459 | ((void **)skb->cb)[1] = hdr; | |
7460 | ((void **)skb->cb)[2] = data; | |
7461 | ||
7462 | return skb; | |
7463 | ||
7464 | nla_put_failure: | |
7465 | kfree_skb(skb); | |
7466 | return NULL; | |
7467 | } | |
f4e583c8 | 7468 | |
e03ad6ea | 7469 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
6c09e791 | 7470 | struct wireless_dev *wdev, |
e03ad6ea JB |
7471 | enum nl80211_commands cmd, |
7472 | enum nl80211_attrs attr, | |
7473 | int vendor_event_idx, | |
7474 | int approxlen, gfp_t gfp) | |
7475 | { | |
f26cbf40 | 7476 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
7477 | const struct nl80211_vendor_cmd_info *info; |
7478 | ||
7479 | switch (cmd) { | |
7480 | case NL80211_CMD_TESTMODE: | |
7481 | if (WARN_ON(vendor_event_idx != -1)) | |
7482 | return NULL; | |
7483 | info = NULL; | |
7484 | break; | |
7485 | case NL80211_CMD_VENDOR: | |
7486 | if (WARN_ON(vendor_event_idx < 0 || | |
7487 | vendor_event_idx >= wiphy->n_vendor_events)) | |
7488 | return NULL; | |
7489 | info = &wiphy->vendor_events[vendor_event_idx]; | |
7490 | break; | |
7491 | default: | |
7492 | WARN_ON(1); | |
7493 | return NULL; | |
7494 | } | |
7495 | ||
6c09e791 | 7496 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
e03ad6ea JB |
7497 | cmd, attr, info, gfp); |
7498 | } | |
7499 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
7500 | ||
7501 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
7502 | { | |
7503 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
7504 | void *hdr = ((void **)skb->cb)[1]; | |
7505 | struct nlattr *data = ((void **)skb->cb)[2]; | |
7506 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
7507 | ||
bd8c78e7 JB |
7508 | /* clear CB data for netlink core to own from now on */ |
7509 | memset(skb->cb, 0, sizeof(skb->cb)); | |
7510 | ||
e03ad6ea JB |
7511 | nla_nest_end(skb, data); |
7512 | genlmsg_end(skb, hdr); | |
7513 | ||
7514 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
7515 | mcgrp = NL80211_MCGRP_VENDOR; | |
7516 | ||
7517 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
7518 | mcgrp, gfp); | |
7519 | } | |
7520 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
7521 | ||
aff89a9b | 7522 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
7523 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
7524 | { | |
4c476991 | 7525 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
7526 | struct wireless_dev *wdev = |
7527 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
7528 | int err; |
7529 | ||
fc73f11f DS |
7530 | if (!rdev->ops->testmode_cmd) |
7531 | return -EOPNOTSUPP; | |
7532 | ||
7533 | if (IS_ERR(wdev)) { | |
7534 | err = PTR_ERR(wdev); | |
7535 | if (err != -EINVAL) | |
7536 | return err; | |
7537 | wdev = NULL; | |
7538 | } else if (wdev->wiphy != &rdev->wiphy) { | |
7539 | return -EINVAL; | |
7540 | } | |
7541 | ||
aff89a9b JB |
7542 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
7543 | return -EINVAL; | |
7544 | ||
ad7e718c | 7545 | rdev->cur_cmd_info = info; |
fc73f11f | 7546 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
7547 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
7548 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 7549 | rdev->cur_cmd_info = NULL; |
aff89a9b | 7550 | |
aff89a9b JB |
7551 | return err; |
7552 | } | |
7553 | ||
71063f0e WYG |
7554 | static int nl80211_testmode_dump(struct sk_buff *skb, |
7555 | struct netlink_callback *cb) | |
7556 | { | |
00918d33 | 7557 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
7558 | int err; |
7559 | long phy_idx; | |
7560 | void *data = NULL; | |
7561 | int data_len = 0; | |
7562 | ||
5fe231e8 JB |
7563 | rtnl_lock(); |
7564 | ||
71063f0e WYG |
7565 | if (cb->args[0]) { |
7566 | /* | |
7567 | * 0 is a valid index, but not valid for args[0], | |
7568 | * so we need to offset by 1. | |
7569 | */ | |
7570 | phy_idx = cb->args[0] - 1; | |
7571 | } else { | |
7572 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
7573 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
7574 | nl80211_policy); | |
7575 | if (err) | |
5fe231e8 | 7576 | goto out_err; |
00918d33 | 7577 | |
2bd7e35d JB |
7578 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
7579 | nl80211_fam.attrbuf); | |
7580 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
7581 | err = PTR_ERR(rdev); |
7582 | goto out_err; | |
00918d33 | 7583 | } |
2bd7e35d JB |
7584 | phy_idx = rdev->wiphy_idx; |
7585 | rdev = NULL; | |
2bd7e35d | 7586 | |
71063f0e WYG |
7587 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
7588 | cb->args[1] = | |
7589 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
7590 | } | |
7591 | ||
7592 | if (cb->args[1]) { | |
7593 | data = nla_data((void *)cb->args[1]); | |
7594 | data_len = nla_len((void *)cb->args[1]); | |
7595 | } | |
7596 | ||
00918d33 JB |
7597 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
7598 | if (!rdev) { | |
5fe231e8 JB |
7599 | err = -ENOENT; |
7600 | goto out_err; | |
71063f0e | 7601 | } |
71063f0e | 7602 | |
00918d33 | 7603 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
7604 | err = -EOPNOTSUPP; |
7605 | goto out_err; | |
7606 | } | |
7607 | ||
7608 | while (1) { | |
15e47304 | 7609 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
7610 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
7611 | NL80211_CMD_TESTMODE); | |
7612 | struct nlattr *tmdata; | |
7613 | ||
cb35fba3 DC |
7614 | if (!hdr) |
7615 | break; | |
7616 | ||
9360ffd1 | 7617 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
7618 | genlmsg_cancel(skb, hdr); |
7619 | break; | |
7620 | } | |
7621 | ||
7622 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
7623 | if (!tmdata) { | |
7624 | genlmsg_cancel(skb, hdr); | |
7625 | break; | |
7626 | } | |
e35e4d28 | 7627 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
7628 | nla_nest_end(skb, tmdata); |
7629 | ||
7630 | if (err == -ENOBUFS || err == -ENOENT) { | |
7631 | genlmsg_cancel(skb, hdr); | |
7632 | break; | |
7633 | } else if (err) { | |
7634 | genlmsg_cancel(skb, hdr); | |
7635 | goto out_err; | |
7636 | } | |
7637 | ||
7638 | genlmsg_end(skb, hdr); | |
7639 | } | |
7640 | ||
7641 | err = skb->len; | |
7642 | /* see above */ | |
7643 | cb->args[0] = phy_idx + 1; | |
7644 | out_err: | |
5fe231e8 | 7645 | rtnl_unlock(); |
71063f0e WYG |
7646 | return err; |
7647 | } | |
aff89a9b JB |
7648 | #endif |
7649 | ||
b23aa676 SO |
7650 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
7651 | { | |
4c476991 JB |
7652 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7653 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
7654 | struct cfg80211_connect_params connect; |
7655 | struct wiphy *wiphy; | |
fffd0934 | 7656 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
7657 | int err; |
7658 | ||
7659 | memset(&connect, 0, sizeof(connect)); | |
7660 | ||
7661 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
7662 | return -EINVAL; | |
7663 | ||
7664 | if (!info->attrs[NL80211_ATTR_SSID] || | |
7665 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
7666 | return -EINVAL; | |
7667 | ||
7668 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
7669 | connect.auth_type = | |
7670 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
7671 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
7672 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
7673 | return -EINVAL; |
7674 | } else | |
7675 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
7676 | ||
7677 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
7678 | ||
c0692b8f | 7679 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 7680 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
7681 | if (err) |
7682 | return err; | |
b23aa676 | 7683 | |
074ac8df | 7684 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7685 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7686 | return -EOPNOTSUPP; | |
b23aa676 | 7687 | |
79c97e97 | 7688 | wiphy = &rdev->wiphy; |
b23aa676 | 7689 | |
4486ea98 BS |
7690 | connect.bg_scan_period = -1; |
7691 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
7692 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
7693 | connect.bg_scan_period = | |
7694 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
7695 | } | |
7696 | ||
b23aa676 SO |
7697 | if (info->attrs[NL80211_ATTR_MAC]) |
7698 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
7699 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
7700 | connect.bssid_hint = | |
7701 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
7702 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7703 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7704 | ||
7705 | if (info->attrs[NL80211_ATTR_IE]) { | |
7706 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7707 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7708 | } | |
7709 | ||
cee00a95 JM |
7710 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
7711 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
7712 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
7713 | connect.mfp != NL80211_MFP_NO) | |
7714 | return -EINVAL; | |
7715 | } else { | |
7716 | connect.mfp = NL80211_MFP_NO; | |
7717 | } | |
7718 | ||
b23aa676 | 7719 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
7720 | connect.channel = nl80211_get_valid_chan( |
7721 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7722 | if (!connect.channel) | |
1df4a510 JM |
7723 | return -EINVAL; |
7724 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
7725 | connect.channel_hint = nl80211_get_valid_chan( |
7726 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
7727 | if (!connect.channel_hint) | |
4c476991 | 7728 | return -EINVAL; |
b23aa676 SO |
7729 | } |
7730 | ||
fffd0934 JB |
7731 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
7732 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 7733 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
7734 | if (IS_ERR(connkeys)) |
7735 | return PTR_ERR(connkeys); | |
fffd0934 JB |
7736 | } |
7737 | ||
7e7c8926 BG |
7738 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
7739 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
7740 | ||
7741 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7742 | memcpy(&connect.ht_capa_mask, | |
7743 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7744 | sizeof(connect.ht_capa_mask)); | |
7745 | ||
7746 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e | 7747 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
b47f610b | 7748 | kzfree(connkeys); |
7e7c8926 | 7749 | return -EINVAL; |
b4e4f47e | 7750 | } |
7e7c8926 BG |
7751 | memcpy(&connect.ht_capa, |
7752 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7753 | sizeof(connect.ht_capa)); | |
7754 | } | |
7755 | ||
ee2aca34 JB |
7756 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
7757 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
7758 | ||
7759 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
7760 | memcpy(&connect.vht_capa_mask, | |
7761 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7762 | sizeof(connect.vht_capa_mask)); | |
7763 | ||
7764 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
7765 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
b47f610b | 7766 | kzfree(connkeys); |
ee2aca34 JB |
7767 | return -EINVAL; |
7768 | } | |
7769 | memcpy(&connect.vht_capa, | |
7770 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7771 | sizeof(connect.vht_capa)); | |
7772 | } | |
7773 | ||
bab5ab7d AK |
7774 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7775 | if (!(rdev->wiphy.features & | |
7776 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7777 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7778 | return -EINVAL; | |
7779 | connect.flags |= ASSOC_REQ_USE_RRM; | |
7780 | } | |
7781 | ||
83739b03 JB |
7782 | wdev_lock(dev->ieee80211_ptr); |
7783 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
7784 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 | 7785 | if (err) |
b47f610b | 7786 | kzfree(connkeys); |
b23aa676 SO |
7787 | return err; |
7788 | } | |
7789 | ||
7790 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
7791 | { | |
4c476991 JB |
7792 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7793 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 7794 | u16 reason; |
83739b03 | 7795 | int ret; |
b23aa676 SO |
7796 | |
7797 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7798 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
7799 | else | |
7800 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
7801 | ||
7802 | if (reason == 0) | |
7803 | return -EINVAL; | |
7804 | ||
074ac8df | 7805 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7806 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7807 | return -EOPNOTSUPP; | |
b23aa676 | 7808 | |
83739b03 JB |
7809 | wdev_lock(dev->ieee80211_ptr); |
7810 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
7811 | wdev_unlock(dev->ieee80211_ptr); | |
7812 | return ret; | |
b23aa676 SO |
7813 | } |
7814 | ||
463d0183 JB |
7815 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
7816 | { | |
4c476991 | 7817 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
7818 | struct net *net; |
7819 | int err; | |
463d0183 | 7820 | |
4b681c82 VK |
7821 | if (info->attrs[NL80211_ATTR_PID]) { |
7822 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
7823 | ||
7824 | net = get_net_ns_by_pid(pid); | |
7825 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { | |
7826 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); | |
463d0183 | 7827 | |
4b681c82 VK |
7828 | net = get_net_ns_by_fd(fd); |
7829 | } else { | |
7830 | return -EINVAL; | |
7831 | } | |
463d0183 | 7832 | |
4c476991 JB |
7833 | if (IS_ERR(net)) |
7834 | return PTR_ERR(net); | |
463d0183 JB |
7835 | |
7836 | err = 0; | |
7837 | ||
7838 | /* check if anything to do */ | |
4c476991 JB |
7839 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
7840 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 7841 | |
463d0183 | 7842 | put_net(net); |
463d0183 JB |
7843 | return err; |
7844 | } | |
7845 | ||
67fbb16b SO |
7846 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
7847 | { | |
4c476991 | 7848 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
7849 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
7850 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 7851 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
7852 | struct cfg80211_pmksa pmksa; |
7853 | ||
7854 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
7855 | ||
7856 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7857 | return -EINVAL; | |
7858 | ||
7859 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
7860 | return -EINVAL; | |
7861 | ||
67fbb16b SO |
7862 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
7863 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7864 | ||
074ac8df | 7865 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7866 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7867 | return -EOPNOTSUPP; | |
67fbb16b SO |
7868 | |
7869 | switch (info->genlhdr->cmd) { | |
7870 | case NL80211_CMD_SET_PMKSA: | |
7871 | rdev_ops = rdev->ops->set_pmksa; | |
7872 | break; | |
7873 | case NL80211_CMD_DEL_PMKSA: | |
7874 | rdev_ops = rdev->ops->del_pmksa; | |
7875 | break; | |
7876 | default: | |
7877 | WARN_ON(1); | |
7878 | break; | |
7879 | } | |
7880 | ||
4c476991 JB |
7881 | if (!rdev_ops) |
7882 | return -EOPNOTSUPP; | |
67fbb16b | 7883 | |
4c476991 | 7884 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
7885 | } |
7886 | ||
7887 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
7888 | { | |
4c476991 JB |
7889 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7890 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 7891 | |
074ac8df | 7892 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7893 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7894 | return -EOPNOTSUPP; | |
67fbb16b | 7895 | |
4c476991 JB |
7896 | if (!rdev->ops->flush_pmksa) |
7897 | return -EOPNOTSUPP; | |
67fbb16b | 7898 | |
e35e4d28 | 7899 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
7900 | } |
7901 | ||
109086ce AN |
7902 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
7903 | { | |
7904 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7905 | struct net_device *dev = info->user_ptr[1]; | |
7906 | u8 action_code, dialog_token; | |
df942e7b | 7907 | u32 peer_capability = 0; |
109086ce AN |
7908 | u16 status_code; |
7909 | u8 *peer; | |
31fa97c5 | 7910 | bool initiator; |
109086ce AN |
7911 | |
7912 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7913 | !rdev->ops->tdls_mgmt) | |
7914 | return -EOPNOTSUPP; | |
7915 | ||
7916 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
7917 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
7918 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
7919 | !info->attrs[NL80211_ATTR_IE] || | |
7920 | !info->attrs[NL80211_ATTR_MAC]) | |
7921 | return -EINVAL; | |
7922 | ||
7923 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7924 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
7925 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
7926 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 7927 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
7928 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
7929 | peer_capability = | |
7930 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 7931 | |
e35e4d28 | 7932 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 7933 | dialog_token, status_code, peer_capability, |
31fa97c5 | 7934 | initiator, |
e35e4d28 HG |
7935 | nla_data(info->attrs[NL80211_ATTR_IE]), |
7936 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
7937 | } |
7938 | ||
7939 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
7940 | { | |
7941 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7942 | struct net_device *dev = info->user_ptr[1]; | |
7943 | enum nl80211_tdls_operation operation; | |
7944 | u8 *peer; | |
7945 | ||
7946 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7947 | !rdev->ops->tdls_oper) | |
7948 | return -EOPNOTSUPP; | |
7949 | ||
7950 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
7951 | !info->attrs[NL80211_ATTR_MAC]) | |
7952 | return -EINVAL; | |
7953 | ||
7954 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
7955 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7956 | ||
e35e4d28 | 7957 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
7958 | } |
7959 | ||
9588bbd5 JM |
7960 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
7961 | struct genl_info *info) | |
7962 | { | |
4c476991 | 7963 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7964 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7965 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
7966 | struct sk_buff *msg; |
7967 | void *hdr; | |
7968 | u64 cookie; | |
683b6d3b | 7969 | u32 duration; |
9588bbd5 JM |
7970 | int err; |
7971 | ||
7972 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7973 | !info->attrs[NL80211_ATTR_DURATION]) | |
7974 | return -EINVAL; | |
7975 | ||
7976 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
7977 | ||
ebf348fc JB |
7978 | if (!rdev->ops->remain_on_channel || |
7979 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
7980 | return -EOPNOTSUPP; | |
7981 | ||
9588bbd5 | 7982 | /* |
ebf348fc JB |
7983 | * We should be on that channel for at least a minimum amount of |
7984 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 7985 | */ |
ebf348fc | 7986 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 7987 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
7988 | return -EINVAL; |
7989 | ||
683b6d3b JB |
7990 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7991 | if (err) | |
7992 | return err; | |
9588bbd5 JM |
7993 | |
7994 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7995 | if (!msg) |
7996 | return -ENOMEM; | |
9588bbd5 | 7997 | |
15e47304 | 7998 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 7999 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
8000 | if (!hdr) { |
8001 | err = -ENOBUFS; | |
9588bbd5 JM |
8002 | goto free_msg; |
8003 | } | |
8004 | ||
683b6d3b JB |
8005 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
8006 | duration, &cookie); | |
9588bbd5 JM |
8007 | |
8008 | if (err) | |
8009 | goto free_msg; | |
8010 | ||
9360ffd1 DM |
8011 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8012 | goto nla_put_failure; | |
9588bbd5 JM |
8013 | |
8014 | genlmsg_end(msg, hdr); | |
4c476991 JB |
8015 | |
8016 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
8017 | |
8018 | nla_put_failure: | |
8019 | err = -ENOBUFS; | |
8020 | free_msg: | |
8021 | nlmsg_free(msg); | |
9588bbd5 JM |
8022 | return err; |
8023 | } | |
8024 | ||
8025 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
8026 | struct genl_info *info) | |
8027 | { | |
4c476991 | 8028 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8029 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 8030 | u64 cookie; |
9588bbd5 JM |
8031 | |
8032 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8033 | return -EINVAL; | |
8034 | ||
4c476991 JB |
8035 | if (!rdev->ops->cancel_remain_on_channel) |
8036 | return -EOPNOTSUPP; | |
9588bbd5 | 8037 | |
9588bbd5 JM |
8038 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
8039 | ||
e35e4d28 | 8040 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
8041 | } |
8042 | ||
13ae75b1 JM |
8043 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
8044 | u8 *rates, u8 rates_len) | |
8045 | { | |
8046 | u8 i; | |
8047 | u32 mask = 0; | |
8048 | ||
8049 | for (i = 0; i < rates_len; i++) { | |
8050 | int rate = (rates[i] & 0x7f) * 5; | |
8051 | int ridx; | |
8052 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
8053 | struct ieee80211_rate *srate = | |
8054 | &sband->bitrates[ridx]; | |
8055 | if (rate == srate->bitrate) { | |
8056 | mask |= 1 << ridx; | |
8057 | break; | |
8058 | } | |
8059 | } | |
8060 | if (ridx == sband->n_bitrates) | |
8061 | return 0; /* rate not found */ | |
8062 | } | |
8063 | ||
8064 | return mask; | |
8065 | } | |
8066 | ||
24db78c0 SW |
8067 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
8068 | u8 *rates, u8 rates_len, | |
8069 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
8070 | { | |
8071 | u8 i; | |
8072 | ||
8073 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
8074 | ||
8075 | for (i = 0; i < rates_len; i++) { | |
8076 | int ridx, rbit; | |
8077 | ||
8078 | ridx = rates[i] / 8; | |
8079 | rbit = BIT(rates[i] % 8); | |
8080 | ||
8081 | /* check validity */ | |
910570b5 | 8082 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
8083 | return false; |
8084 | ||
8085 | /* check availability */ | |
8086 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
8087 | mcs[ridx] |= rbit; | |
8088 | else | |
8089 | return false; | |
8090 | } | |
8091 | ||
8092 | return true; | |
8093 | } | |
8094 | ||
204e35a9 JD |
8095 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
8096 | { | |
8097 | u16 mcs_mask = 0; | |
8098 | ||
8099 | switch (vht_mcs_map) { | |
8100 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
8101 | break; | |
8102 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
8103 | mcs_mask = 0x00FF; | |
8104 | break; | |
8105 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
8106 | mcs_mask = 0x01FF; | |
8107 | break; | |
8108 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
8109 | mcs_mask = 0x03FF; | |
8110 | break; | |
8111 | default: | |
8112 | break; | |
8113 | } | |
8114 | ||
8115 | return mcs_mask; | |
8116 | } | |
8117 | ||
8118 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
8119 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
8120 | { | |
8121 | u8 nss; | |
8122 | ||
8123 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
8124 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
8125 | vht_mcs_map >>= 2; | |
8126 | } | |
8127 | } | |
8128 | ||
8129 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
8130 | struct nl80211_txrate_vht *txrate, | |
8131 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
8132 | { | |
8133 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8134 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
8135 | u8 i; | |
8136 | ||
8137 | if (!sband->vht_cap.vht_supported) | |
8138 | return false; | |
8139 | ||
8140 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
8141 | ||
8142 | /* Build vht_mcs_mask from VHT capabilities */ | |
8143 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
8144 | ||
8145 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
8146 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
8147 | mcs[i] = txrate->mcs[i]; | |
8148 | else | |
8149 | return false; | |
8150 | } | |
8151 | ||
8152 | return true; | |
8153 | } | |
8154 | ||
b54452b0 | 8155 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
8156 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
8157 | .len = NL80211_MAX_SUPP_RATES }, | |
d1e33e65 JD |
8158 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
8159 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
204e35a9 | 8160 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
0b9323f6 | 8161 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
13ae75b1 JM |
8162 | }; |
8163 | ||
8164 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
8165 | struct genl_info *info) | |
8166 | { | |
8167 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 8168 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 8169 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
8170 | int rem, i; |
8171 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
8172 | struct nlattr *tx_rates; |
8173 | struct ieee80211_supported_band *sband; | |
204e35a9 | 8174 | u16 vht_tx_mcs_map; |
13ae75b1 | 8175 | |
4c476991 JB |
8176 | if (!rdev->ops->set_bitrate_mask) |
8177 | return -EOPNOTSUPP; | |
13ae75b1 JM |
8178 | |
8179 | memset(&mask, 0, sizeof(mask)); | |
8180 | /* Default to all rates enabled */ | |
8181 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
8182 | sband = rdev->wiphy.bands[i]; | |
7869303b JD |
8183 | |
8184 | if (!sband) | |
8185 | continue; | |
8186 | ||
8187 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; | |
d1e33e65 | 8188 | memcpy(mask.control[i].ht_mcs, |
7869303b | 8189 | sband->ht_cap.mcs.rx_mask, |
d1e33e65 | 8190 | sizeof(mask.control[i].ht_mcs)); |
204e35a9 JD |
8191 | |
8192 | if (!sband->vht_cap.vht_supported) | |
8193 | continue; | |
8194 | ||
8195 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8196 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); | |
13ae75b1 JM |
8197 | } |
8198 | ||
b9243ab0 JD |
8199 | /* if no rates are given set it back to the defaults */ |
8200 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
8201 | goto out; | |
8202 | ||
13ae75b1 JM |
8203 | /* |
8204 | * The nested attribute uses enum nl80211_band as the index. This maps | |
8205 | * directly to the enum ieee80211_band values used in cfg80211. | |
8206 | */ | |
24db78c0 | 8207 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
ae811e21 | 8208 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
13ae75b1 | 8209 | enum ieee80211_band band = nla_type(tx_rates); |
ae811e21 JB |
8210 | int err; |
8211 | ||
4c476991 JB |
8212 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
8213 | return -EINVAL; | |
13ae75b1 | 8214 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
8215 | if (sband == NULL) |
8216 | return -EINVAL; | |
ae811e21 JB |
8217 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
8218 | nla_len(tx_rates), nl80211_txattr_policy); | |
8219 | if (err) | |
8220 | return err; | |
13ae75b1 JM |
8221 | if (tb[NL80211_TXRATE_LEGACY]) { |
8222 | mask.control[band].legacy = rateset_to_mask( | |
8223 | sband, | |
8224 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
8225 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
8226 | if ((mask.control[band].legacy == 0) && |
8227 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
8228 | return -EINVAL; | |
24db78c0 | 8229 | } |
d1e33e65 | 8230 | if (tb[NL80211_TXRATE_HT]) { |
24db78c0 SW |
8231 | if (!ht_rateset_to_mask( |
8232 | sband, | |
d1e33e65 JD |
8233 | nla_data(tb[NL80211_TXRATE_HT]), |
8234 | nla_len(tb[NL80211_TXRATE_HT]), | |
8235 | mask.control[band].ht_mcs)) | |
24db78c0 SW |
8236 | return -EINVAL; |
8237 | } | |
204e35a9 JD |
8238 | if (tb[NL80211_TXRATE_VHT]) { |
8239 | if (!vht_set_mcs_mask( | |
8240 | sband, | |
8241 | nla_data(tb[NL80211_TXRATE_VHT]), | |
8242 | mask.control[band].vht_mcs)) | |
8243 | return -EINVAL; | |
8244 | } | |
0b9323f6 JD |
8245 | if (tb[NL80211_TXRATE_GI]) { |
8246 | mask.control[band].gi = | |
8247 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
8248 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
8249 | return -EINVAL; | |
8250 | } | |
24db78c0 SW |
8251 | |
8252 | if (mask.control[band].legacy == 0) { | |
204e35a9 JD |
8253 | /* don't allow empty legacy rates if HT or VHT |
8254 | * are not even supported. | |
8255 | */ | |
8256 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
8257 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
24db78c0 SW |
8258 | return -EINVAL; |
8259 | ||
8260 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
d1e33e65 | 8261 | if (mask.control[band].ht_mcs[i]) |
204e35a9 JD |
8262 | goto out; |
8263 | ||
8264 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
8265 | if (mask.control[band].vht_mcs[i]) | |
8266 | goto out; | |
24db78c0 SW |
8267 | |
8268 | /* legacy and mcs rates may not be both empty */ | |
204e35a9 | 8269 | return -EINVAL; |
13ae75b1 JM |
8270 | } |
8271 | } | |
8272 | ||
b9243ab0 | 8273 | out: |
e35e4d28 | 8274 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
8275 | } |
8276 | ||
2e161f78 | 8277 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8278 | { |
4c476991 | 8279 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8280 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 8281 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
8282 | |
8283 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
8284 | return -EINVAL; | |
8285 | ||
2e161f78 JB |
8286 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
8287 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 8288 | |
71bbc994 JB |
8289 | switch (wdev->iftype) { |
8290 | case NL80211_IFTYPE_STATION: | |
8291 | case NL80211_IFTYPE_ADHOC: | |
8292 | case NL80211_IFTYPE_P2P_CLIENT: | |
8293 | case NL80211_IFTYPE_AP: | |
8294 | case NL80211_IFTYPE_AP_VLAN: | |
8295 | case NL80211_IFTYPE_MESH_POINT: | |
8296 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8297 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8298 | break; |
8299 | default: | |
4c476991 | 8300 | return -EOPNOTSUPP; |
71bbc994 | 8301 | } |
026331c4 JM |
8302 | |
8303 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
8304 | if (!rdev->ops->mgmt_tx) |
8305 | return -EOPNOTSUPP; | |
026331c4 | 8306 | |
15e47304 | 8307 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
8308 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
8309 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
8310 | } |
8311 | ||
2e161f78 | 8312 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8313 | { |
4c476991 | 8314 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8315 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 8316 | struct cfg80211_chan_def chandef; |
026331c4 | 8317 | int err; |
d64d373f | 8318 | void *hdr = NULL; |
026331c4 | 8319 | u64 cookie; |
e247bd90 | 8320 | struct sk_buff *msg = NULL; |
b176e629 AO |
8321 | struct cfg80211_mgmt_tx_params params = { |
8322 | .dont_wait_for_ack = | |
8323 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
8324 | }; | |
026331c4 | 8325 | |
683b6d3b | 8326 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
8327 | return -EINVAL; |
8328 | ||
4c476991 JB |
8329 | if (!rdev->ops->mgmt_tx) |
8330 | return -EOPNOTSUPP; | |
026331c4 | 8331 | |
71bbc994 | 8332 | switch (wdev->iftype) { |
ea141b75 AQ |
8333 | case NL80211_IFTYPE_P2P_DEVICE: |
8334 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
8335 | return -EINVAL; | |
71bbc994 JB |
8336 | case NL80211_IFTYPE_STATION: |
8337 | case NL80211_IFTYPE_ADHOC: | |
8338 | case NL80211_IFTYPE_P2P_CLIENT: | |
8339 | case NL80211_IFTYPE_AP: | |
8340 | case NL80211_IFTYPE_AP_VLAN: | |
8341 | case NL80211_IFTYPE_MESH_POINT: | |
8342 | case NL80211_IFTYPE_P2P_GO: | |
8343 | break; | |
8344 | default: | |
4c476991 | 8345 | return -EOPNOTSUPP; |
71bbc994 | 8346 | } |
026331c4 | 8347 | |
f7ca38df | 8348 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 8349 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 8350 | return -EINVAL; |
b176e629 | 8351 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
8352 | |
8353 | /* | |
8354 | * We should wait on the channel for at least a minimum amount | |
8355 | * of time (10ms) but no longer than the driver supports. | |
8356 | */ | |
b176e629 AO |
8357 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
8358 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc JB |
8359 | return -EINVAL; |
8360 | ||
f7ca38df JB |
8361 | } |
8362 | ||
b176e629 | 8363 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 8364 | |
b176e629 | 8365 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
8366 | return -EINVAL; |
8367 | ||
b176e629 | 8368 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 8369 | |
ea141b75 AQ |
8370 | /* get the channel if any has been specified, otherwise pass NULL to |
8371 | * the driver. The latter will use the current one | |
8372 | */ | |
8373 | chandef.chan = NULL; | |
8374 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
8375 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
8376 | if (err) | |
8377 | return err; | |
8378 | } | |
8379 | ||
b176e629 | 8380 | if (!chandef.chan && params.offchan) |
ea141b75 | 8381 | return -EINVAL; |
026331c4 | 8382 | |
34d22ce2 AO |
8383 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
8384 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
8385 | ||
8386 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
8387 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8388 | int i; | |
8389 | ||
8390 | if (len % sizeof(u16)) | |
8391 | return -EINVAL; | |
8392 | ||
8393 | params.n_csa_offsets = len / sizeof(u16); | |
8394 | params.csa_offsets = | |
8395 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8396 | ||
8397 | /* check that all the offsets fit the frame */ | |
8398 | for (i = 0; i < params.n_csa_offsets; i++) { | |
8399 | if (params.csa_offsets[i] >= params.len) | |
8400 | return -EINVAL; | |
8401 | } | |
8402 | } | |
8403 | ||
b176e629 | 8404 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
8405 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
8406 | if (!msg) | |
8407 | return -ENOMEM; | |
026331c4 | 8408 | |
15e47304 | 8409 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 8410 | NL80211_CMD_FRAME); |
cb35fba3 DC |
8411 | if (!hdr) { |
8412 | err = -ENOBUFS; | |
e247bd90 JB |
8413 | goto free_msg; |
8414 | } | |
026331c4 | 8415 | } |
e247bd90 | 8416 | |
b176e629 AO |
8417 | params.chan = chandef.chan; |
8418 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
8419 | if (err) |
8420 | goto free_msg; | |
8421 | ||
e247bd90 | 8422 | if (msg) { |
9360ffd1 DM |
8423 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8424 | goto nla_put_failure; | |
026331c4 | 8425 | |
e247bd90 JB |
8426 | genlmsg_end(msg, hdr); |
8427 | return genlmsg_reply(msg, info); | |
8428 | } | |
8429 | ||
8430 | return 0; | |
026331c4 JM |
8431 | |
8432 | nla_put_failure: | |
8433 | err = -ENOBUFS; | |
8434 | free_msg: | |
8435 | nlmsg_free(msg); | |
026331c4 JM |
8436 | return err; |
8437 | } | |
8438 | ||
f7ca38df JB |
8439 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
8440 | { | |
8441 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 8442 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
8443 | u64 cookie; |
8444 | ||
8445 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8446 | return -EINVAL; | |
8447 | ||
8448 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
8449 | return -EOPNOTSUPP; | |
8450 | ||
71bbc994 JB |
8451 | switch (wdev->iftype) { |
8452 | case NL80211_IFTYPE_STATION: | |
8453 | case NL80211_IFTYPE_ADHOC: | |
8454 | case NL80211_IFTYPE_P2P_CLIENT: | |
8455 | case NL80211_IFTYPE_AP: | |
8456 | case NL80211_IFTYPE_AP_VLAN: | |
8457 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8458 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8459 | break; |
8460 | default: | |
f7ca38df | 8461 | return -EOPNOTSUPP; |
71bbc994 | 8462 | } |
f7ca38df JB |
8463 | |
8464 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
8465 | ||
e35e4d28 | 8466 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
8467 | } |
8468 | ||
ffb9eb3d KV |
8469 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
8470 | { | |
4c476991 | 8471 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 8472 | struct wireless_dev *wdev; |
4c476991 | 8473 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8474 | u8 ps_state; |
8475 | bool state; | |
8476 | int err; | |
8477 | ||
4c476991 JB |
8478 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
8479 | return -EINVAL; | |
ffb9eb3d KV |
8480 | |
8481 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
8482 | ||
4c476991 JB |
8483 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
8484 | return -EINVAL; | |
ffb9eb3d KV |
8485 | |
8486 | wdev = dev->ieee80211_ptr; | |
8487 | ||
4c476991 JB |
8488 | if (!rdev->ops->set_power_mgmt) |
8489 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8490 | |
8491 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
8492 | ||
8493 | if (state == wdev->ps) | |
4c476991 | 8494 | return 0; |
ffb9eb3d | 8495 | |
e35e4d28 | 8496 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
8497 | if (!err) |
8498 | wdev->ps = state; | |
ffb9eb3d KV |
8499 | return err; |
8500 | } | |
8501 | ||
8502 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
8503 | { | |
4c476991 | 8504 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
8505 | enum nl80211_ps_state ps_state; |
8506 | struct wireless_dev *wdev; | |
4c476991 | 8507 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8508 | struct sk_buff *msg; |
8509 | void *hdr; | |
8510 | int err; | |
8511 | ||
ffb9eb3d KV |
8512 | wdev = dev->ieee80211_ptr; |
8513 | ||
4c476991 JB |
8514 | if (!rdev->ops->set_power_mgmt) |
8515 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8516 | |
8517 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
8518 | if (!msg) |
8519 | return -ENOMEM; | |
ffb9eb3d | 8520 | |
15e47304 | 8521 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
8522 | NL80211_CMD_GET_POWER_SAVE); |
8523 | if (!hdr) { | |
4c476991 | 8524 | err = -ENOBUFS; |
ffb9eb3d KV |
8525 | goto free_msg; |
8526 | } | |
8527 | ||
8528 | if (wdev->ps) | |
8529 | ps_state = NL80211_PS_ENABLED; | |
8530 | else | |
8531 | ps_state = NL80211_PS_DISABLED; | |
8532 | ||
9360ffd1 DM |
8533 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
8534 | goto nla_put_failure; | |
ffb9eb3d KV |
8535 | |
8536 | genlmsg_end(msg, hdr); | |
4c476991 | 8537 | return genlmsg_reply(msg, info); |
ffb9eb3d | 8538 | |
4c476991 | 8539 | nla_put_failure: |
ffb9eb3d | 8540 | err = -ENOBUFS; |
4c476991 | 8541 | free_msg: |
ffb9eb3d | 8542 | nlmsg_free(msg); |
ffb9eb3d KV |
8543 | return err; |
8544 | } | |
8545 | ||
94e860f1 JB |
8546 | static const struct nla_policy |
8547 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
8548 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
8549 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
8550 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
8551 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
8552 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
8553 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
8554 | }; |
8555 | ||
84f10708 | 8556 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 8557 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
8558 | { |
8559 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 8560 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8561 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 8562 | |
d9d8b019 | 8563 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
8564 | return -EINVAL; |
8565 | ||
84f10708 TP |
8566 | if (!rdev->ops->set_cqm_txe_config) |
8567 | return -EOPNOTSUPP; | |
8568 | ||
8569 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
8570 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
8571 | return -EOPNOTSUPP; | |
8572 | ||
e35e4d28 | 8573 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
8574 | } |
8575 | ||
d6dc1a38 JO |
8576 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
8577 | s32 threshold, u32 hysteresis) | |
8578 | { | |
4c476991 | 8579 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 8580 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8581 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
8582 | |
8583 | if (threshold > 0) | |
8584 | return -EINVAL; | |
8585 | ||
1da5fcc8 JB |
8586 | /* disabling - hysteresis should also be zero then */ |
8587 | if (threshold == 0) | |
8588 | hysteresis = 0; | |
d6dc1a38 | 8589 | |
4c476991 JB |
8590 | if (!rdev->ops->set_cqm_rssi_config) |
8591 | return -EOPNOTSUPP; | |
d6dc1a38 | 8592 | |
074ac8df | 8593 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8594 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8595 | return -EOPNOTSUPP; | |
d6dc1a38 | 8596 | |
e35e4d28 | 8597 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
8598 | } |
8599 | ||
8600 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
8601 | { | |
8602 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
8603 | struct nlattr *cqm; | |
8604 | int err; | |
8605 | ||
8606 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
8607 | if (!cqm) |
8608 | return -EINVAL; | |
d6dc1a38 JO |
8609 | |
8610 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
8611 | nl80211_attr_cqm_policy); | |
8612 | if (err) | |
1da5fcc8 | 8613 | return err; |
d6dc1a38 JO |
8614 | |
8615 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
8616 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
8617 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
8618 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 8619 | |
1da5fcc8 JB |
8620 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
8621 | } | |
8622 | ||
8623 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
8624 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
8625 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
8626 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
8627 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
8628 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
8629 | ||
8630 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
8631 | } | |
8632 | ||
8633 | return -EINVAL; | |
d6dc1a38 JO |
8634 | } |
8635 | ||
6e0bd6c3 RL |
8636 | static int nl80211_join_ocb(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 ocb_setup setup = {}; | |
8641 | int err; | |
8642 | ||
8643 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | |
8644 | if (err) | |
8645 | return err; | |
8646 | ||
8647 | return cfg80211_join_ocb(rdev, dev, &setup); | |
8648 | } | |
8649 | ||
8650 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | |
8651 | { | |
8652 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8653 | struct net_device *dev = info->user_ptr[1]; | |
8654 | ||
8655 | return cfg80211_leave_ocb(rdev, dev); | |
8656 | } | |
8657 | ||
29cbe68c JB |
8658 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
8659 | { | |
8660 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8661 | struct net_device *dev = info->user_ptr[1]; | |
8662 | struct mesh_config cfg; | |
c80d545d | 8663 | struct mesh_setup setup; |
29cbe68c JB |
8664 | int err; |
8665 | ||
8666 | /* start with default */ | |
8667 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 8668 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 8669 | |
24bdd9f4 | 8670 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 8671 | /* and parse parameters if given */ |
24bdd9f4 | 8672 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
8673 | if (err) |
8674 | return err; | |
8675 | } | |
8676 | ||
8677 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
8678 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
8679 | return -EINVAL; | |
8680 | ||
c80d545d JC |
8681 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
8682 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
8683 | ||
4bb62344 CYY |
8684 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8685 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
8686 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8687 | return -EINVAL; | |
8688 | ||
9bdbf04d MP |
8689 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
8690 | setup.beacon_interval = | |
8691 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
8692 | if (setup.beacon_interval < 10 || | |
8693 | setup.beacon_interval > 10000) | |
8694 | return -EINVAL; | |
8695 | } | |
8696 | ||
8697 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
8698 | setup.dtim_period = | |
8699 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
8700 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
8701 | return -EINVAL; | |
8702 | } | |
8703 | ||
c80d545d JC |
8704 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
8705 | /* parse additional setup parameters if given */ | |
8706 | err = nl80211_parse_mesh_setup(info, &setup); | |
8707 | if (err) | |
8708 | return err; | |
8709 | } | |
8710 | ||
d37bb18a TP |
8711 | if (setup.user_mpm) |
8712 | cfg.auto_open_plinks = false; | |
8713 | ||
cc1d2806 | 8714 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
8715 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
8716 | if (err) | |
8717 | return err; | |
cc1d2806 JB |
8718 | } else { |
8719 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 8720 | setup.chandef.chan = NULL; |
cc1d2806 JB |
8721 | } |
8722 | ||
ffb3cf30 AN |
8723 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8724 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8725 | int n_rates = | |
8726 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8727 | struct ieee80211_supported_band *sband; | |
8728 | ||
8729 | if (!setup.chandef.chan) | |
8730 | return -EINVAL; | |
8731 | ||
8732 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
8733 | ||
8734 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
8735 | &setup.basic_rates); | |
8736 | if (err) | |
8737 | return err; | |
8738 | } | |
8739 | ||
c80d545d | 8740 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
8741 | } |
8742 | ||
8743 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
8744 | { | |
8745 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8746 | struct net_device *dev = info->user_ptr[1]; | |
8747 | ||
8748 | return cfg80211_leave_mesh(rdev, dev); | |
8749 | } | |
8750 | ||
dfb89c56 | 8751 | #ifdef CONFIG_PM |
bb92d199 AK |
8752 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
8753 | struct cfg80211_registered_device *rdev) | |
8754 | { | |
6abb9cb9 | 8755 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
8756 | struct nlattr *nl_pats, *nl_pat; |
8757 | int i, pat_len; | |
8758 | ||
6abb9cb9 | 8759 | if (!wowlan->n_patterns) |
bb92d199 AK |
8760 | return 0; |
8761 | ||
8762 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
8763 | if (!nl_pats) | |
8764 | return -ENOBUFS; | |
8765 | ||
6abb9cb9 | 8766 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
8767 | nl_pat = nla_nest_start(msg, i + 1); |
8768 | if (!nl_pat) | |
8769 | return -ENOBUFS; | |
6abb9cb9 | 8770 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 8771 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 8772 | wowlan->patterns[i].mask) || |
50ac6607 AK |
8773 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
8774 | wowlan->patterns[i].pattern) || | |
8775 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 8776 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
8777 | return -ENOBUFS; |
8778 | nla_nest_end(msg, nl_pat); | |
8779 | } | |
8780 | nla_nest_end(msg, nl_pats); | |
8781 | ||
8782 | return 0; | |
8783 | } | |
8784 | ||
2a0e047e JB |
8785 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
8786 | struct cfg80211_wowlan_tcp *tcp) | |
8787 | { | |
8788 | struct nlattr *nl_tcp; | |
8789 | ||
8790 | if (!tcp) | |
8791 | return 0; | |
8792 | ||
8793 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
8794 | if (!nl_tcp) | |
8795 | return -ENOBUFS; | |
8796 | ||
930345ea JB |
8797 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
8798 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
2a0e047e JB |
8799 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
8800 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
8801 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
8802 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
8803 | tcp->payload_len, tcp->payload) || | |
8804 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
8805 | tcp->data_interval) || | |
8806 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
8807 | tcp->wake_len, tcp->wake_data) || | |
8808 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
8809 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
8810 | return -ENOBUFS; | |
8811 | ||
8812 | if (tcp->payload_seq.len && | |
8813 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
8814 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
8815 | return -ENOBUFS; | |
8816 | ||
8817 | if (tcp->payload_tok.len && | |
8818 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
8819 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
8820 | &tcp->payload_tok)) | |
8821 | return -ENOBUFS; | |
8822 | ||
e248ad30 JB |
8823 | nla_nest_end(msg, nl_tcp); |
8824 | ||
2a0e047e JB |
8825 | return 0; |
8826 | } | |
8827 | ||
75453ccb LC |
8828 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
8829 | struct cfg80211_sched_scan_request *req) | |
8830 | { | |
8831 | struct nlattr *nd, *freqs, *matches, *match; | |
8832 | int i; | |
8833 | ||
8834 | if (!req) | |
8835 | return 0; | |
8836 | ||
8837 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); | |
8838 | if (!nd) | |
8839 | return -ENOBUFS; | |
8840 | ||
8841 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, req->interval)) | |
8842 | return -ENOBUFS; | |
8843 | ||
21fea567 LC |
8844 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
8845 | return -ENOBUFS; | |
8846 | ||
75453ccb LC |
8847 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
8848 | if (!freqs) | |
8849 | return -ENOBUFS; | |
8850 | ||
8851 | for (i = 0; i < req->n_channels; i++) | |
8852 | nla_put_u32(msg, i, req->channels[i]->center_freq); | |
8853 | ||
8854 | nla_nest_end(msg, freqs); | |
8855 | ||
8856 | if (req->n_match_sets) { | |
8857 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); | |
8858 | for (i = 0; i < req->n_match_sets; i++) { | |
8859 | match = nla_nest_start(msg, i); | |
8860 | nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, | |
8861 | req->match_sets[i].ssid.ssid_len, | |
8862 | req->match_sets[i].ssid.ssid); | |
8863 | nla_nest_end(msg, match); | |
8864 | } | |
8865 | nla_nest_end(msg, matches); | |
8866 | } | |
8867 | ||
8868 | nla_nest_end(msg, nd); | |
8869 | ||
8870 | return 0; | |
8871 | } | |
8872 | ||
ff1b6e69 JB |
8873 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
8874 | { | |
8875 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8876 | struct sk_buff *msg; | |
8877 | void *hdr; | |
2a0e047e | 8878 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 8879 | |
964dc9e2 | 8880 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
8881 | return -EOPNOTSUPP; |
8882 | ||
6abb9cb9 | 8883 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 8884 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
8885 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
8886 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
8887 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
8888 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
8889 | } |
8890 | ||
8891 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
8892 | if (!msg) |
8893 | return -ENOMEM; | |
8894 | ||
15e47304 | 8895 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
8896 | NL80211_CMD_GET_WOWLAN); |
8897 | if (!hdr) | |
8898 | goto nla_put_failure; | |
8899 | ||
6abb9cb9 | 8900 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
8901 | struct nlattr *nl_wowlan; |
8902 | ||
8903 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
8904 | if (!nl_wowlan) | |
8905 | goto nla_put_failure; | |
8906 | ||
6abb9cb9 | 8907 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 8908 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 8909 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 8910 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 8911 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 8912 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 8913 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 8914 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 8915 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 8916 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 8917 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 8918 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 8919 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
8920 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
8921 | goto nla_put_failure; | |
2a0e047e | 8922 | |
bb92d199 AK |
8923 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
8924 | goto nla_put_failure; | |
2a0e047e | 8925 | |
6abb9cb9 JB |
8926 | if (nl80211_send_wowlan_tcp(msg, |
8927 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e | 8928 | goto nla_put_failure; |
75453ccb LC |
8929 | |
8930 | if (nl80211_send_wowlan_nd( | |
8931 | msg, | |
8932 | rdev->wiphy.wowlan_config->nd_config)) | |
8933 | goto nla_put_failure; | |
2a0e047e | 8934 | |
ff1b6e69 JB |
8935 | nla_nest_end(msg, nl_wowlan); |
8936 | } | |
8937 | ||
8938 | genlmsg_end(msg, hdr); | |
8939 | return genlmsg_reply(msg, info); | |
8940 | ||
8941 | nla_put_failure: | |
8942 | nlmsg_free(msg); | |
8943 | return -ENOBUFS; | |
8944 | } | |
8945 | ||
2a0e047e JB |
8946 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
8947 | struct nlattr *attr, | |
8948 | struct cfg80211_wowlan *trig) | |
8949 | { | |
8950 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
8951 | struct cfg80211_wowlan_tcp *cfg; | |
8952 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
8953 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
8954 | u32 size; | |
8955 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
8956 | int err, port; | |
8957 | ||
964dc9e2 | 8958 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
8959 | return -EINVAL; |
8960 | ||
8961 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
8962 | nla_data(attr), nla_len(attr), | |
8963 | nl80211_wowlan_tcp_policy); | |
8964 | if (err) | |
8965 | return err; | |
8966 | ||
8967 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
8968 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
8969 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
8970 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
8971 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
8972 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
8973 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
8974 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
8975 | return -EINVAL; | |
8976 | ||
8977 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 8978 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
8979 | return -EINVAL; |
8980 | ||
8981 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 8982 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 8983 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
8984 | return -EINVAL; |
8985 | ||
8986 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 8987 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
8988 | return -EINVAL; |
8989 | ||
8990 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
8991 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
8992 | return -EINVAL; | |
8993 | ||
8994 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
8995 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8996 | ||
8997 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8998 | tokens_size = tokln - sizeof(*tok); | |
8999 | ||
9000 | if (!tok->len || tokens_size % tok->len) | |
9001 | return -EINVAL; | |
964dc9e2 | 9002 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 9003 | return -EINVAL; |
964dc9e2 | 9004 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 9005 | return -EINVAL; |
964dc9e2 | 9006 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 9007 | return -EINVAL; |
964dc9e2 | 9008 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
9009 | return -EINVAL; |
9010 | if (tok->offset + tok->len > data_size) | |
9011 | return -EINVAL; | |
9012 | } | |
9013 | ||
9014 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
9015 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 9016 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
9017 | return -EINVAL; |
9018 | if (seq->len == 0 || seq->len > 4) | |
9019 | return -EINVAL; | |
9020 | if (seq->len + seq->offset > data_size) | |
9021 | return -EINVAL; | |
9022 | } | |
9023 | ||
9024 | size = sizeof(*cfg); | |
9025 | size += data_size; | |
9026 | size += wake_size + wake_mask_size; | |
9027 | size += tokens_size; | |
9028 | ||
9029 | cfg = kzalloc(size, GFP_KERNEL); | |
9030 | if (!cfg) | |
9031 | return -ENOMEM; | |
67b61f6c JB |
9032 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
9033 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
2a0e047e JB |
9034 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
9035 | ETH_ALEN); | |
9036 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
9037 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
9038 | else | |
9039 | port = 0; | |
9040 | #ifdef CONFIG_INET | |
9041 | /* allocate a socket and port for it and use it */ | |
9042 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
9043 | IPPROTO_TCP, &cfg->sock, 1); | |
9044 | if (err) { | |
9045 | kfree(cfg); | |
9046 | return err; | |
9047 | } | |
9048 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
9049 | sock_release(cfg->sock); | |
9050 | kfree(cfg); | |
9051 | return -EADDRINUSE; | |
9052 | } | |
9053 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
9054 | #else | |
9055 | if (!port) { | |
9056 | kfree(cfg); | |
9057 | return -EINVAL; | |
9058 | } | |
9059 | cfg->src_port = port; | |
9060 | #endif | |
9061 | ||
9062 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
9063 | cfg->payload_len = data_size; | |
9064 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
9065 | memcpy((void *)cfg->payload, | |
9066 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
9067 | data_size); | |
9068 | if (seq) | |
9069 | cfg->payload_seq = *seq; | |
9070 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
9071 | cfg->wake_len = wake_size; | |
9072 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
9073 | memcpy((void *)cfg->wake_data, | |
9074 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
9075 | wake_size); | |
9076 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
9077 | data_size + wake_size; | |
9078 | memcpy((void *)cfg->wake_mask, | |
9079 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
9080 | wake_mask_size); | |
9081 | if (tok) { | |
9082 | cfg->tokens_size = tokens_size; | |
9083 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
9084 | } | |
9085 | ||
9086 | trig->tcp = cfg; | |
9087 | ||
9088 | return 0; | |
9089 | } | |
9090 | ||
8cd4d456 LC |
9091 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
9092 | const struct wiphy_wowlan_support *wowlan, | |
9093 | struct nlattr *attr, | |
9094 | struct cfg80211_wowlan *trig) | |
9095 | { | |
9096 | struct nlattr **tb; | |
9097 | int err; | |
9098 | ||
9099 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); | |
9100 | if (!tb) | |
9101 | return -ENOMEM; | |
9102 | ||
9103 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | |
9104 | err = -EOPNOTSUPP; | |
9105 | goto out; | |
9106 | } | |
9107 | ||
9108 | err = nla_parse(tb, NL80211_ATTR_MAX, | |
9109 | nla_data(attr), nla_len(attr), | |
9110 | nl80211_policy); | |
9111 | if (err) | |
9112 | goto out; | |
9113 | ||
ad2b26ab | 9114 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
8cd4d456 LC |
9115 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
9116 | if (err) | |
9117 | trig->nd_config = NULL; | |
9118 | ||
9119 | out: | |
9120 | kfree(tb); | |
9121 | return err; | |
9122 | } | |
9123 | ||
ff1b6e69 JB |
9124 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
9125 | { | |
9126 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9127 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 9128 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 9129 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 9130 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 9131 | int err, i; |
6abb9cb9 | 9132 | bool prev_enabled = rdev->wiphy.wowlan_config; |
98fc4386 | 9133 | bool regular = false; |
ff1b6e69 | 9134 | |
964dc9e2 | 9135 | if (!wowlan) |
ff1b6e69 JB |
9136 | return -EOPNOTSUPP; |
9137 | ||
ae33bd81 JB |
9138 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
9139 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 9140 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
9141 | goto set_wakeup; |
9142 | } | |
ff1b6e69 JB |
9143 | |
9144 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
9145 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9146 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9147 | nl80211_wowlan_policy); | |
9148 | if (err) | |
9149 | return err; | |
9150 | ||
9151 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
9152 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
9153 | return -EINVAL; | |
9154 | new_triggers.any = true; | |
9155 | } | |
9156 | ||
9157 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
9158 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
9159 | return -EINVAL; | |
9160 | new_triggers.disconnect = true; | |
98fc4386 | 9161 | regular = true; |
ff1b6e69 JB |
9162 | } |
9163 | ||
9164 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
9165 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
9166 | return -EINVAL; | |
9167 | new_triggers.magic_pkt = true; | |
98fc4386 | 9168 | regular = true; |
ff1b6e69 JB |
9169 | } |
9170 | ||
77dbbb13 JB |
9171 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
9172 | return -EINVAL; | |
9173 | ||
9174 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
9175 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
9176 | return -EINVAL; | |
9177 | new_triggers.gtk_rekey_failure = true; | |
98fc4386 | 9178 | regular = true; |
77dbbb13 JB |
9179 | } |
9180 | ||
9181 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
9182 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
9183 | return -EINVAL; | |
9184 | new_triggers.eap_identity_req = true; | |
98fc4386 | 9185 | regular = true; |
77dbbb13 JB |
9186 | } |
9187 | ||
9188 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
9189 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
9190 | return -EINVAL; | |
9191 | new_triggers.four_way_handshake = true; | |
98fc4386 | 9192 | regular = true; |
77dbbb13 JB |
9193 | } |
9194 | ||
9195 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
9196 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
9197 | return -EINVAL; | |
9198 | new_triggers.rfkill_release = true; | |
98fc4386 | 9199 | regular = true; |
77dbbb13 JB |
9200 | } |
9201 | ||
ff1b6e69 JB |
9202 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
9203 | struct nlattr *pat; | |
9204 | int n_patterns = 0; | |
bb92d199 | 9205 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 9206 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 | 9207 | |
98fc4386 JB |
9208 | regular = true; |
9209 | ||
ff1b6e69 JB |
9210 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
9211 | rem) | |
9212 | n_patterns++; | |
9213 | if (n_patterns > wowlan->n_patterns) | |
9214 | return -EINVAL; | |
9215 | ||
9216 | new_triggers.patterns = kcalloc(n_patterns, | |
9217 | sizeof(new_triggers.patterns[0]), | |
9218 | GFP_KERNEL); | |
9219 | if (!new_triggers.patterns) | |
9220 | return -ENOMEM; | |
9221 | ||
9222 | new_triggers.n_patterns = n_patterns; | |
9223 | i = 0; | |
9224 | ||
9225 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9226 | rem) { | |
922bd80f JB |
9227 | u8 *mask_pat; |
9228 | ||
50ac6607 AK |
9229 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9230 | nla_len(pat), NULL); | |
ff1b6e69 | 9231 | err = -EINVAL; |
50ac6607 AK |
9232 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
9233 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 9234 | goto error; |
50ac6607 | 9235 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 9236 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 9237 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
9238 | goto error; |
9239 | if (pat_len > wowlan->pattern_max_len || | |
9240 | pat_len < wowlan->pattern_min_len) | |
9241 | goto error; | |
9242 | ||
50ac6607 | 9243 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
9244 | pkt_offset = 0; |
9245 | else | |
9246 | pkt_offset = nla_get_u32( | |
50ac6607 | 9247 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
9248 | if (pkt_offset > wowlan->max_pkt_offset) |
9249 | goto error; | |
9250 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
9251 | ||
922bd80f JB |
9252 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9253 | if (!mask_pat) { | |
ff1b6e69 JB |
9254 | err = -ENOMEM; |
9255 | goto error; | |
9256 | } | |
922bd80f JB |
9257 | new_triggers.patterns[i].mask = mask_pat; |
9258 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 9259 | mask_len); |
922bd80f JB |
9260 | mask_pat += mask_len; |
9261 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 9262 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 9263 | memcpy(mask_pat, |
50ac6607 | 9264 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
9265 | pat_len); |
9266 | i++; | |
9267 | } | |
9268 | } | |
9269 | ||
2a0e047e | 9270 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
98fc4386 | 9271 | regular = true; |
2a0e047e JB |
9272 | err = nl80211_parse_wowlan_tcp( |
9273 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
9274 | &new_triggers); | |
9275 | if (err) | |
9276 | goto error; | |
9277 | } | |
9278 | ||
8cd4d456 | 9279 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
98fc4386 | 9280 | regular = true; |
8cd4d456 LC |
9281 | err = nl80211_parse_wowlan_nd( |
9282 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | |
9283 | &new_triggers); | |
9284 | if (err) | |
9285 | goto error; | |
9286 | } | |
9287 | ||
98fc4386 JB |
9288 | /* The 'any' trigger means the device continues operating more or less |
9289 | * as in its normal operation mode and wakes up the host on most of the | |
9290 | * normal interrupts (like packet RX, ...) | |
9291 | * It therefore makes little sense to combine with the more constrained | |
9292 | * wakeup trigger modes. | |
9293 | */ | |
9294 | if (new_triggers.any && regular) { | |
9295 | err = -EINVAL; | |
9296 | goto error; | |
9297 | } | |
9298 | ||
ae33bd81 JB |
9299 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
9300 | if (!ntrig) { | |
9301 | err = -ENOMEM; | |
9302 | goto error; | |
ff1b6e69 | 9303 | } |
ae33bd81 | 9304 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 9305 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 9306 | |
ae33bd81 | 9307 | set_wakeup: |
6abb9cb9 JB |
9308 | if (rdev->ops->set_wakeup && |
9309 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
9310 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 9311 | |
ff1b6e69 JB |
9312 | return 0; |
9313 | error: | |
9314 | for (i = 0; i < new_triggers.n_patterns; i++) | |
9315 | kfree(new_triggers.patterns[i].mask); | |
9316 | kfree(new_triggers.patterns); | |
2a0e047e JB |
9317 | if (new_triggers.tcp && new_triggers.tcp->sock) |
9318 | sock_release(new_triggers.tcp->sock); | |
9319 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
9320 | return err; |
9321 | } | |
dfb89c56 | 9322 | #endif |
ff1b6e69 | 9323 | |
be29b99a AK |
9324 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
9325 | struct cfg80211_registered_device *rdev) | |
9326 | { | |
9327 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
9328 | int i, j, pat_len; | |
9329 | struct cfg80211_coalesce_rules *rule; | |
9330 | ||
9331 | if (!rdev->coalesce->n_rules) | |
9332 | return 0; | |
9333 | ||
9334 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
9335 | if (!nl_rules) | |
9336 | return -ENOBUFS; | |
9337 | ||
9338 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
9339 | nl_rule = nla_nest_start(msg, i + 1); | |
9340 | if (!nl_rule) | |
9341 | return -ENOBUFS; | |
9342 | ||
9343 | rule = &rdev->coalesce->rules[i]; | |
9344 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
9345 | rule->delay)) | |
9346 | return -ENOBUFS; | |
9347 | ||
9348 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
9349 | rule->condition)) | |
9350 | return -ENOBUFS; | |
9351 | ||
9352 | nl_pats = nla_nest_start(msg, | |
9353 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
9354 | if (!nl_pats) | |
9355 | return -ENOBUFS; | |
9356 | ||
9357 | for (j = 0; j < rule->n_patterns; j++) { | |
9358 | nl_pat = nla_nest_start(msg, j + 1); | |
9359 | if (!nl_pat) | |
9360 | return -ENOBUFS; | |
9361 | pat_len = rule->patterns[j].pattern_len; | |
9362 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
9363 | DIV_ROUND_UP(pat_len, 8), | |
9364 | rule->patterns[j].mask) || | |
9365 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
9366 | rule->patterns[j].pattern) || | |
9367 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
9368 | rule->patterns[j].pkt_offset)) | |
9369 | return -ENOBUFS; | |
9370 | nla_nest_end(msg, nl_pat); | |
9371 | } | |
9372 | nla_nest_end(msg, nl_pats); | |
9373 | nla_nest_end(msg, nl_rule); | |
9374 | } | |
9375 | nla_nest_end(msg, nl_rules); | |
9376 | ||
9377 | return 0; | |
9378 | } | |
9379 | ||
9380 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9381 | { | |
9382 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9383 | struct sk_buff *msg; | |
9384 | void *hdr; | |
9385 | ||
9386 | if (!rdev->wiphy.coalesce) | |
9387 | return -EOPNOTSUPP; | |
9388 | ||
9389 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9390 | if (!msg) | |
9391 | return -ENOMEM; | |
9392 | ||
9393 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9394 | NL80211_CMD_GET_COALESCE); | |
9395 | if (!hdr) | |
9396 | goto nla_put_failure; | |
9397 | ||
9398 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
9399 | goto nla_put_failure; | |
9400 | ||
9401 | genlmsg_end(msg, hdr); | |
9402 | return genlmsg_reply(msg, info); | |
9403 | ||
9404 | nla_put_failure: | |
9405 | nlmsg_free(msg); | |
9406 | return -ENOBUFS; | |
9407 | } | |
9408 | ||
9409 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
9410 | { | |
9411 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
9412 | int i, j; | |
9413 | struct cfg80211_coalesce_rules *rule; | |
9414 | ||
9415 | if (!coalesce) | |
9416 | return; | |
9417 | ||
9418 | for (i = 0; i < coalesce->n_rules; i++) { | |
9419 | rule = &coalesce->rules[i]; | |
9420 | for (j = 0; j < rule->n_patterns; j++) | |
9421 | kfree(rule->patterns[j].mask); | |
9422 | kfree(rule->patterns); | |
9423 | } | |
9424 | kfree(coalesce->rules); | |
9425 | kfree(coalesce); | |
9426 | rdev->coalesce = NULL; | |
9427 | } | |
9428 | ||
9429 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
9430 | struct nlattr *rule, | |
9431 | struct cfg80211_coalesce_rules *new_rule) | |
9432 | { | |
9433 | int err, i; | |
9434 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9435 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
9436 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
9437 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
9438 | ||
9439 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
9440 | nla_len(rule), nl80211_coalesce_policy); | |
9441 | if (err) | |
9442 | return err; | |
9443 | ||
9444 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
9445 | new_rule->delay = | |
9446 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
9447 | if (new_rule->delay > coalesce->max_delay) | |
9448 | return -EINVAL; | |
9449 | ||
9450 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
9451 | new_rule->condition = | |
9452 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
9453 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
9454 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
9455 | return -EINVAL; | |
9456 | ||
9457 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
9458 | return -EINVAL; | |
9459 | ||
9460 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9461 | rem) | |
9462 | n_patterns++; | |
9463 | if (n_patterns > coalesce->n_patterns) | |
9464 | return -EINVAL; | |
9465 | ||
9466 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
9467 | GFP_KERNEL); | |
9468 | if (!new_rule->patterns) | |
9469 | return -ENOMEM; | |
9470 | ||
9471 | new_rule->n_patterns = n_patterns; | |
9472 | i = 0; | |
9473 | ||
9474 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9475 | rem) { | |
922bd80f JB |
9476 | u8 *mask_pat; |
9477 | ||
be29b99a AK |
9478 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9479 | nla_len(pat), NULL); | |
9480 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
9481 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
9482 | return -EINVAL; | |
9483 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
9484 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
9485 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
9486 | return -EINVAL; | |
9487 | if (pat_len > coalesce->pattern_max_len || | |
9488 | pat_len < coalesce->pattern_min_len) | |
9489 | return -EINVAL; | |
9490 | ||
9491 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
9492 | pkt_offset = 0; | |
9493 | else | |
9494 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
9495 | if (pkt_offset > coalesce->max_pkt_offset) | |
9496 | return -EINVAL; | |
9497 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
9498 | ||
922bd80f JB |
9499 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9500 | if (!mask_pat) | |
be29b99a | 9501 | return -ENOMEM; |
922bd80f JB |
9502 | |
9503 | new_rule->patterns[i].mask = mask_pat; | |
9504 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
9505 | mask_len); | |
9506 | ||
9507 | mask_pat += mask_len; | |
9508 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 9509 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
9510 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
9511 | pat_len); | |
be29b99a AK |
9512 | i++; |
9513 | } | |
9514 | ||
9515 | return 0; | |
9516 | } | |
9517 | ||
9518 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9519 | { | |
9520 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9521 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9522 | struct cfg80211_coalesce new_coalesce = {}; | |
9523 | struct cfg80211_coalesce *n_coalesce; | |
9524 | int err, rem_rule, n_rules = 0, i, j; | |
9525 | struct nlattr *rule; | |
9526 | struct cfg80211_coalesce_rules *tmp_rule; | |
9527 | ||
9528 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
9529 | return -EOPNOTSUPP; | |
9530 | ||
9531 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
9532 | cfg80211_rdev_free_coalesce(rdev); | |
9533 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
9534 | return 0; | |
9535 | } | |
9536 | ||
9537 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9538 | rem_rule) | |
9539 | n_rules++; | |
9540 | if (n_rules > coalesce->n_rules) | |
9541 | return -EINVAL; | |
9542 | ||
9543 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
9544 | GFP_KERNEL); | |
9545 | if (!new_coalesce.rules) | |
9546 | return -ENOMEM; | |
9547 | ||
9548 | new_coalesce.n_rules = n_rules; | |
9549 | i = 0; | |
9550 | ||
9551 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9552 | rem_rule) { | |
9553 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
9554 | &new_coalesce.rules[i]); | |
9555 | if (err) | |
9556 | goto error; | |
9557 | ||
9558 | i++; | |
9559 | } | |
9560 | ||
9561 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
9562 | if (err) | |
9563 | goto error; | |
9564 | ||
9565 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
9566 | if (!n_coalesce) { | |
9567 | err = -ENOMEM; | |
9568 | goto error; | |
9569 | } | |
9570 | cfg80211_rdev_free_coalesce(rdev); | |
9571 | rdev->coalesce = n_coalesce; | |
9572 | ||
9573 | return 0; | |
9574 | error: | |
9575 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
9576 | tmp_rule = &new_coalesce.rules[i]; | |
9577 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
9578 | kfree(tmp_rule->patterns[j].mask); | |
9579 | kfree(tmp_rule->patterns); | |
9580 | } | |
9581 | kfree(new_coalesce.rules); | |
9582 | ||
9583 | return err; | |
9584 | } | |
9585 | ||
e5497d76 JB |
9586 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
9587 | { | |
9588 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9589 | struct net_device *dev = info->user_ptr[1]; | |
9590 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9591 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
9592 | struct cfg80211_gtk_rekey_data rekey_data; | |
9593 | int err; | |
9594 | ||
9595 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
9596 | return -EINVAL; | |
9597 | ||
9598 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
9599 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9600 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9601 | nl80211_rekey_policy); | |
9602 | if (err) | |
9603 | return err; | |
9604 | ||
9605 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
9606 | return -ERANGE; | |
9607 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
9608 | return -ERANGE; | |
9609 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
9610 | return -ERANGE; | |
9611 | ||
78f686ca JB |
9612 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
9613 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | |
9614 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | |
e5497d76 JB |
9615 | |
9616 | wdev_lock(wdev); | |
9617 | if (!wdev->current_bss) { | |
9618 | err = -ENOTCONN; | |
9619 | goto out; | |
9620 | } | |
9621 | ||
9622 | if (!rdev->ops->set_rekey_data) { | |
9623 | err = -EOPNOTSUPP; | |
9624 | goto out; | |
9625 | } | |
9626 | ||
e35e4d28 | 9627 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
9628 | out: |
9629 | wdev_unlock(wdev); | |
9630 | return err; | |
9631 | } | |
9632 | ||
28946da7 JB |
9633 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
9634 | struct genl_info *info) | |
9635 | { | |
9636 | struct net_device *dev = info->user_ptr[1]; | |
9637 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9638 | ||
9639 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9640 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9641 | return -EINVAL; | |
9642 | ||
15e47304 | 9643 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
9644 | return -EBUSY; |
9645 | ||
15e47304 | 9646 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
9647 | return 0; |
9648 | } | |
9649 | ||
7f6cf311 JB |
9650 | static int nl80211_probe_client(struct sk_buff *skb, |
9651 | struct genl_info *info) | |
9652 | { | |
9653 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9654 | struct net_device *dev = info->user_ptr[1]; | |
9655 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9656 | struct sk_buff *msg; | |
9657 | void *hdr; | |
9658 | const u8 *addr; | |
9659 | u64 cookie; | |
9660 | int err; | |
9661 | ||
9662 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9663 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9664 | return -EOPNOTSUPP; | |
9665 | ||
9666 | if (!info->attrs[NL80211_ATTR_MAC]) | |
9667 | return -EINVAL; | |
9668 | ||
9669 | if (!rdev->ops->probe_client) | |
9670 | return -EOPNOTSUPP; | |
9671 | ||
9672 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9673 | if (!msg) | |
9674 | return -ENOMEM; | |
9675 | ||
15e47304 | 9676 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 9677 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
9678 | if (!hdr) { |
9679 | err = -ENOBUFS; | |
7f6cf311 JB |
9680 | goto free_msg; |
9681 | } | |
9682 | ||
9683 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9684 | ||
e35e4d28 | 9685 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
9686 | if (err) |
9687 | goto free_msg; | |
9688 | ||
9360ffd1 DM |
9689 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9690 | goto nla_put_failure; | |
7f6cf311 JB |
9691 | |
9692 | genlmsg_end(msg, hdr); | |
9693 | ||
9694 | return genlmsg_reply(msg, info); | |
9695 | ||
9696 | nla_put_failure: | |
9697 | err = -ENOBUFS; | |
9698 | free_msg: | |
9699 | nlmsg_free(msg); | |
9700 | return err; | |
9701 | } | |
9702 | ||
5e760230 JB |
9703 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
9704 | { | |
9705 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
9706 | struct cfg80211_beacon_registration *reg, *nreg; |
9707 | int rv; | |
5e760230 JB |
9708 | |
9709 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
9710 | return -EOPNOTSUPP; | |
9711 | ||
37c73b5f BG |
9712 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
9713 | if (!nreg) | |
9714 | return -ENOMEM; | |
9715 | ||
9716 | /* First, check if already registered. */ | |
9717 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
9718 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
9719 | if (reg->nlportid == info->snd_portid) { | |
9720 | rv = -EALREADY; | |
9721 | goto out_err; | |
9722 | } | |
9723 | } | |
9724 | /* Add it to the list */ | |
9725 | nreg->nlportid = info->snd_portid; | |
9726 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 9727 | |
37c73b5f | 9728 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
9729 | |
9730 | return 0; | |
37c73b5f BG |
9731 | out_err: |
9732 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
9733 | kfree(nreg); | |
9734 | return rv; | |
5e760230 JB |
9735 | } |
9736 | ||
98104fde JB |
9737 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
9738 | { | |
9739 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9740 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9741 | int err; | |
9742 | ||
9743 | if (!rdev->ops->start_p2p_device) | |
9744 | return -EOPNOTSUPP; | |
9745 | ||
9746 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9747 | return -EOPNOTSUPP; | |
9748 | ||
9749 | if (wdev->p2p_started) | |
9750 | return 0; | |
9751 | ||
b6a55015 LC |
9752 | if (rfkill_blocked(rdev->rfkill)) |
9753 | return -ERFKILL; | |
98104fde | 9754 | |
eeb126e9 | 9755 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
9756 | if (err) |
9757 | return err; | |
9758 | ||
9759 | wdev->p2p_started = true; | |
98104fde | 9760 | rdev->opencount++; |
98104fde JB |
9761 | |
9762 | return 0; | |
9763 | } | |
9764 | ||
9765 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
9766 | { | |
9767 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9768 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9769 | ||
9770 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9771 | return -EOPNOTSUPP; | |
9772 | ||
9773 | if (!rdev->ops->stop_p2p_device) | |
9774 | return -EOPNOTSUPP; | |
9775 | ||
f9f47529 | 9776 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
9777 | |
9778 | return 0; | |
9779 | } | |
9780 | ||
3713b4e3 JB |
9781 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
9782 | struct genl_info *info) | |
9783 | { | |
9784 | void *hdr; | |
9785 | struct sk_buff *msg; | |
9786 | ||
9787 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9788 | if (!msg) | |
9789 | return -ENOMEM; | |
9790 | ||
9791 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9792 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
9793 | if (!hdr) | |
9794 | goto nla_put_failure; | |
9795 | ||
9796 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
9797 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
9798 | goto nla_put_failure; | |
9799 | ||
9800 | genlmsg_end(msg, hdr); | |
9801 | return genlmsg_reply(msg, info); | |
9802 | ||
9803 | nla_put_failure: | |
9804 | kfree_skb(msg); | |
9805 | return -ENOBUFS; | |
9806 | } | |
9807 | ||
355199e0 JM |
9808 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
9809 | { | |
9810 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9811 | struct cfg80211_update_ft_ies_params ft_params; | |
9812 | struct net_device *dev = info->user_ptr[1]; | |
9813 | ||
9814 | if (!rdev->ops->update_ft_ies) | |
9815 | return -EOPNOTSUPP; | |
9816 | ||
9817 | if (!info->attrs[NL80211_ATTR_MDID] || | |
9818 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
9819 | return -EINVAL; | |
9820 | ||
9821 | memset(&ft_params, 0, sizeof(ft_params)); | |
9822 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
9823 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
9824 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9825 | ||
9826 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
9827 | } | |
9828 | ||
5de17984 AS |
9829 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
9830 | struct genl_info *info) | |
9831 | { | |
9832 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9833 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9834 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
9835 | u16 duration; | |
9836 | int ret; | |
9837 | ||
9838 | if (!rdev->ops->crit_proto_start) | |
9839 | return -EOPNOTSUPP; | |
9840 | ||
9841 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
9842 | return -EINVAL; | |
9843 | ||
9844 | if (rdev->crit_proto_nlportid) | |
9845 | return -EBUSY; | |
9846 | ||
9847 | /* determine protocol if provided */ | |
9848 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
9849 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
9850 | ||
9851 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
9852 | return -EINVAL; | |
9853 | ||
9854 | /* timeout must be provided */ | |
9855 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
9856 | return -EINVAL; | |
9857 | ||
9858 | duration = | |
9859 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
9860 | ||
9861 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
9862 | return -ERANGE; | |
9863 | ||
9864 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
9865 | if (!ret) | |
9866 | rdev->crit_proto_nlportid = info->snd_portid; | |
9867 | ||
9868 | return ret; | |
9869 | } | |
9870 | ||
9871 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
9872 | struct genl_info *info) | |
9873 | { | |
9874 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9875 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9876 | ||
9877 | if (!rdev->ops->crit_proto_stop) | |
9878 | return -EOPNOTSUPP; | |
9879 | ||
9880 | if (rdev->crit_proto_nlportid) { | |
9881 | rdev->crit_proto_nlportid = 0; | |
9882 | rdev_crit_proto_stop(rdev, wdev); | |
9883 | } | |
9884 | return 0; | |
9885 | } | |
9886 | ||
ad7e718c JB |
9887 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
9888 | { | |
9889 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9890 | struct wireless_dev *wdev = | |
9891 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
9892 | int i, err; | |
9893 | u32 vid, subcmd; | |
9894 | ||
9895 | if (!rdev->wiphy.vendor_commands) | |
9896 | return -EOPNOTSUPP; | |
9897 | ||
9898 | if (IS_ERR(wdev)) { | |
9899 | err = PTR_ERR(wdev); | |
9900 | if (err != -EINVAL) | |
9901 | return err; | |
9902 | wdev = NULL; | |
9903 | } else if (wdev->wiphy != &rdev->wiphy) { | |
9904 | return -EINVAL; | |
9905 | } | |
9906 | ||
9907 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
9908 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
9909 | return -EINVAL; | |
9910 | ||
9911 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
9912 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
9913 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
9914 | const struct wiphy_vendor_command *vcmd; | |
9915 | void *data = NULL; | |
9916 | int len = 0; | |
9917 | ||
9918 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
9919 | ||
9920 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
9921 | continue; | |
9922 | ||
9923 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
9924 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
9925 | if (!wdev) | |
9926 | return -EINVAL; | |
9927 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
9928 | !wdev->netdev) | |
9929 | return -EINVAL; | |
9930 | ||
9931 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
9932 | if (wdev->netdev && | |
9933 | !netif_running(wdev->netdev)) | |
9934 | return -ENETDOWN; | |
9935 | if (!wdev->netdev && !wdev->p2p_started) | |
9936 | return -ENETDOWN; | |
9937 | } | |
9938 | } else { | |
9939 | wdev = NULL; | |
9940 | } | |
9941 | ||
9942 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
9943 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9944 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9945 | } | |
9946 | ||
9947 | rdev->cur_cmd_info = info; | |
9948 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
9949 | data, len); | |
9950 | rdev->cur_cmd_info = NULL; | |
9951 | return err; | |
9952 | } | |
9953 | ||
9954 | return -EOPNOTSUPP; | |
9955 | } | |
9956 | ||
9957 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | |
9958 | enum nl80211_commands cmd, | |
9959 | enum nl80211_attrs attr, | |
9960 | int approxlen) | |
9961 | { | |
f26cbf40 | 9962 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
9963 | |
9964 | if (WARN_ON(!rdev->cur_cmd_info)) | |
9965 | return NULL; | |
9966 | ||
6c09e791 | 9967 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
ad7e718c JB |
9968 | rdev->cur_cmd_info->snd_portid, |
9969 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 9970 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
9971 | } |
9972 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
9973 | ||
9974 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
9975 | { | |
9976 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
9977 | void *hdr = ((void **)skb->cb)[1]; | |
9978 | struct nlattr *data = ((void **)skb->cb)[2]; | |
9979 | ||
bd8c78e7 JB |
9980 | /* clear CB data for netlink core to own from now on */ |
9981 | memset(skb->cb, 0, sizeof(skb->cb)); | |
9982 | ||
ad7e718c JB |
9983 | if (WARN_ON(!rdev->cur_cmd_info)) { |
9984 | kfree_skb(skb); | |
9985 | return -EINVAL; | |
9986 | } | |
9987 | ||
9988 | nla_nest_end(skb, data); | |
9989 | genlmsg_end(skb, hdr); | |
9990 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
9991 | } | |
9992 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
9993 | ||
9994 | ||
fa9ffc74 KP |
9995 | static int nl80211_set_qos_map(struct sk_buff *skb, |
9996 | struct genl_info *info) | |
9997 | { | |
9998 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9999 | struct cfg80211_qos_map *qos_map = NULL; | |
10000 | struct net_device *dev = info->user_ptr[1]; | |
10001 | u8 *pos, len, num_des, des_len, des; | |
10002 | int ret; | |
10003 | ||
10004 | if (!rdev->ops->set_qos_map) | |
10005 | return -EOPNOTSUPP; | |
10006 | ||
10007 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
10008 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
10009 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
10010 | ||
10011 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
10012 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
10013 | return -EINVAL; | |
10014 | ||
10015 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
10016 | if (!qos_map) | |
10017 | return -ENOMEM; | |
10018 | ||
10019 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
10020 | if (num_des) { | |
10021 | des_len = num_des * | |
10022 | sizeof(struct cfg80211_dscp_exception); | |
10023 | memcpy(qos_map->dscp_exception, pos, des_len); | |
10024 | qos_map->num_des = num_des; | |
10025 | for (des = 0; des < num_des; des++) { | |
10026 | if (qos_map->dscp_exception[des].up > 7) { | |
10027 | kfree(qos_map); | |
10028 | return -EINVAL; | |
10029 | } | |
10030 | } | |
10031 | pos += des_len; | |
10032 | } | |
10033 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
10034 | } | |
10035 | ||
10036 | wdev_lock(dev->ieee80211_ptr); | |
10037 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
10038 | if (!ret) | |
10039 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
10040 | wdev_unlock(dev->ieee80211_ptr); | |
10041 | ||
10042 | kfree(qos_map); | |
10043 | return ret; | |
10044 | } | |
10045 | ||
960d01ac JB |
10046 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
10047 | { | |
10048 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10049 | struct net_device *dev = info->user_ptr[1]; | |
10050 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10051 | const u8 *peer; | |
10052 | u8 tsid, up; | |
10053 | u16 admitted_time = 0; | |
10054 | int err; | |
10055 | ||
723e73ac | 10056 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
960d01ac JB |
10057 | return -EOPNOTSUPP; |
10058 | ||
10059 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | |
10060 | !info->attrs[NL80211_ATTR_USER_PRIO]) | |
10061 | return -EINVAL; | |
10062 | ||
10063 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
10064 | if (tsid >= IEEE80211_NUM_TIDS) | |
10065 | return -EINVAL; | |
10066 | ||
10067 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); | |
10068 | if (up >= IEEE80211_NUM_UPS) | |
10069 | return -EINVAL; | |
10070 | ||
10071 | /* WMM uses TIDs 0-7 even for TSPEC */ | |
723e73ac | 10072 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
960d01ac | 10073 | /* TODO: handle 802.11 TSPEC/admission control |
723e73ac JB |
10074 | * need more attributes for that (e.g. BA session requirement); |
10075 | * change the WMM adminssion test above to allow both then | |
960d01ac JB |
10076 | */ |
10077 | return -EINVAL; | |
10078 | } | |
10079 | ||
10080 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10081 | ||
10082 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | |
10083 | admitted_time = | |
10084 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | |
10085 | if (!admitted_time) | |
10086 | return -EINVAL; | |
10087 | } | |
10088 | ||
10089 | wdev_lock(wdev); | |
10090 | switch (wdev->iftype) { | |
10091 | case NL80211_IFTYPE_STATION: | |
10092 | case NL80211_IFTYPE_P2P_CLIENT: | |
10093 | if (wdev->current_bss) | |
10094 | break; | |
10095 | err = -ENOTCONN; | |
10096 | goto out; | |
10097 | default: | |
10098 | err = -EOPNOTSUPP; | |
10099 | goto out; | |
10100 | } | |
10101 | ||
10102 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | |
10103 | ||
10104 | out: | |
10105 | wdev_unlock(wdev); | |
10106 | return err; | |
10107 | } | |
10108 | ||
10109 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | |
10110 | { | |
10111 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10112 | struct net_device *dev = info->user_ptr[1]; | |
10113 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10114 | const u8 *peer; | |
10115 | u8 tsid; | |
10116 | int err; | |
10117 | ||
10118 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | |
10119 | return -EINVAL; | |
10120 | ||
10121 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
10122 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10123 | ||
10124 | wdev_lock(wdev); | |
10125 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | |
10126 | wdev_unlock(wdev); | |
10127 | ||
10128 | return err; | |
10129 | } | |
10130 | ||
1057d35e AN |
10131 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
10132 | struct genl_info *info) | |
10133 | { | |
10134 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10135 | struct net_device *dev = info->user_ptr[1]; | |
10136 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10137 | struct cfg80211_chan_def chandef = {}; | |
10138 | const u8 *addr; | |
10139 | u8 oper_class; | |
10140 | int err; | |
10141 | ||
10142 | if (!rdev->ops->tdls_channel_switch || | |
10143 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
10144 | return -EOPNOTSUPP; | |
10145 | ||
10146 | switch (dev->ieee80211_ptr->iftype) { | |
10147 | case NL80211_IFTYPE_STATION: | |
10148 | case NL80211_IFTYPE_P2P_CLIENT: | |
10149 | break; | |
10150 | default: | |
10151 | return -EOPNOTSUPP; | |
10152 | } | |
10153 | ||
10154 | if (!info->attrs[NL80211_ATTR_MAC] || | |
10155 | !info->attrs[NL80211_ATTR_OPER_CLASS]) | |
10156 | return -EINVAL; | |
10157 | ||
10158 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
10159 | if (err) | |
10160 | return err; | |
10161 | ||
10162 | /* | |
10163 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | |
10164 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | |
10165 | * specification is not defined for them. | |
10166 | */ | |
10167 | if (chandef.chan->band == IEEE80211_BAND_2GHZ && | |
10168 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | |
10169 | chandef.width != NL80211_CHAN_WIDTH_20) | |
10170 | return -EINVAL; | |
10171 | ||
10172 | /* we will be active on the TDLS link */ | |
10173 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype)) | |
10174 | return -EINVAL; | |
10175 | ||
10176 | /* don't allow switching to DFS channels */ | |
10177 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | |
10178 | return -EINVAL; | |
10179 | ||
10180 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10181 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | |
10182 | ||
10183 | wdev_lock(wdev); | |
10184 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | |
10185 | wdev_unlock(wdev); | |
10186 | ||
10187 | return err; | |
10188 | } | |
10189 | ||
10190 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | |
10191 | struct genl_info *info) | |
10192 | { | |
10193 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10194 | struct net_device *dev = info->user_ptr[1]; | |
10195 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10196 | const u8 *addr; | |
10197 | ||
10198 | if (!rdev->ops->tdls_channel_switch || | |
10199 | !rdev->ops->tdls_cancel_channel_switch || | |
10200 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
10201 | return -EOPNOTSUPP; | |
10202 | ||
10203 | switch (dev->ieee80211_ptr->iftype) { | |
10204 | case NL80211_IFTYPE_STATION: | |
10205 | case NL80211_IFTYPE_P2P_CLIENT: | |
10206 | break; | |
10207 | default: | |
10208 | return -EOPNOTSUPP; | |
10209 | } | |
10210 | ||
10211 | if (!info->attrs[NL80211_ATTR_MAC]) | |
10212 | return -EINVAL; | |
10213 | ||
10214 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10215 | ||
10216 | wdev_lock(wdev); | |
10217 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); | |
10218 | wdev_unlock(wdev); | |
10219 | ||
10220 | return 0; | |
10221 | } | |
10222 | ||
4c476991 JB |
10223 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
10224 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
10225 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
10226 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
10227 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
10228 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 10229 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 10230 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
10231 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
10232 | NL80211_FLAG_CHECK_NETDEV_UP) | |
5393b917 | 10233 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
4c476991 | 10234 | |
f84f771d | 10235 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10236 | struct genl_info *info) |
10237 | { | |
10238 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 10239 | struct wireless_dev *wdev; |
4c476991 | 10240 | struct net_device *dev; |
4c476991 JB |
10241 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
10242 | ||
10243 | if (rtnl) | |
10244 | rtnl_lock(); | |
10245 | ||
10246 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 10247 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
10248 | if (IS_ERR(rdev)) { |
10249 | if (rtnl) | |
10250 | rtnl_unlock(); | |
10251 | return PTR_ERR(rdev); | |
10252 | } | |
10253 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
10254 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
10255 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
10256 | ASSERT_RTNL(); |
10257 | ||
89a54e48 JB |
10258 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
10259 | info->attrs); | |
10260 | if (IS_ERR(wdev)) { | |
4c476991 JB |
10261 | if (rtnl) |
10262 | rtnl_unlock(); | |
89a54e48 | 10263 | return PTR_ERR(wdev); |
4c476991 | 10264 | } |
89a54e48 | 10265 | |
89a54e48 | 10266 | dev = wdev->netdev; |
f26cbf40 | 10267 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 10268 | |
1bf614ef JB |
10269 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
10270 | if (!dev) { | |
1bf614ef JB |
10271 | if (rtnl) |
10272 | rtnl_unlock(); | |
10273 | return -EINVAL; | |
10274 | } | |
10275 | ||
10276 | info->user_ptr[1] = dev; | |
10277 | } else { | |
10278 | info->user_ptr[1] = wdev; | |
41265714 | 10279 | } |
1bf614ef JB |
10280 | |
10281 | if (dev) { | |
10282 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
10283 | !netif_running(dev)) { | |
1bf614ef JB |
10284 | if (rtnl) |
10285 | rtnl_unlock(); | |
10286 | return -ENETDOWN; | |
10287 | } | |
10288 | ||
10289 | dev_hold(dev); | |
98104fde JB |
10290 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
10291 | if (!wdev->p2p_started) { | |
98104fde JB |
10292 | if (rtnl) |
10293 | rtnl_unlock(); | |
10294 | return -ENETDOWN; | |
10295 | } | |
41265714 | 10296 | } |
89a54e48 | 10297 | |
4c476991 | 10298 | info->user_ptr[0] = rdev; |
4c476991 JB |
10299 | } |
10300 | ||
10301 | return 0; | |
10302 | } | |
10303 | ||
f84f771d | 10304 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10305 | struct genl_info *info) |
10306 | { | |
1bf614ef JB |
10307 | if (info->user_ptr[1]) { |
10308 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
10309 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10310 | ||
10311 | if (wdev->netdev) | |
10312 | dev_put(wdev->netdev); | |
10313 | } else { | |
10314 | dev_put(info->user_ptr[1]); | |
10315 | } | |
10316 | } | |
5393b917 | 10317 | |
4c476991 JB |
10318 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
10319 | rtnl_unlock(); | |
5393b917 JB |
10320 | |
10321 | /* If needed, clear the netlink message payload from the SKB | |
10322 | * as it might contain key data that shouldn't stick around on | |
10323 | * the heap after the SKB is freed. The netlink message header | |
10324 | * is still needed for further processing, so leave it intact. | |
10325 | */ | |
10326 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | |
10327 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | |
10328 | ||
10329 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | |
10330 | } | |
4c476991 JB |
10331 | } |
10332 | ||
4534de83 | 10333 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
10334 | { |
10335 | .cmd = NL80211_CMD_GET_WIPHY, | |
10336 | .doit = nl80211_get_wiphy, | |
10337 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 10338 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
10339 | .policy = nl80211_policy, |
10340 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10341 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10342 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10343 | }, |
10344 | { | |
10345 | .cmd = NL80211_CMD_SET_WIPHY, | |
10346 | .doit = nl80211_set_wiphy, | |
10347 | .policy = nl80211_policy, | |
10348 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 10349 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
10350 | }, |
10351 | { | |
10352 | .cmd = NL80211_CMD_GET_INTERFACE, | |
10353 | .doit = nl80211_get_interface, | |
10354 | .dumpit = nl80211_dump_interface, | |
10355 | .policy = nl80211_policy, | |
10356 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10357 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
10358 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10359 | }, |
10360 | { | |
10361 | .cmd = NL80211_CMD_SET_INTERFACE, | |
10362 | .doit = nl80211_set_interface, | |
10363 | .policy = nl80211_policy, | |
10364 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10365 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10366 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10367 | }, |
10368 | { | |
10369 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
10370 | .doit = nl80211_new_interface, | |
10371 | .policy = nl80211_policy, | |
10372 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10373 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10374 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10375 | }, |
10376 | { | |
10377 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
10378 | .doit = nl80211_del_interface, | |
10379 | .policy = nl80211_policy, | |
41ade00f | 10380 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 10381 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10382 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10383 | }, |
10384 | { | |
10385 | .cmd = NL80211_CMD_GET_KEY, | |
10386 | .doit = nl80211_get_key, | |
10387 | .policy = nl80211_policy, | |
10388 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10389 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10390 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10391 | }, |
10392 | { | |
10393 | .cmd = NL80211_CMD_SET_KEY, | |
10394 | .doit = nl80211_set_key, | |
10395 | .policy = nl80211_policy, | |
10396 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10397 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10398 | NL80211_FLAG_NEED_RTNL | |
10399 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10400 | }, |
10401 | { | |
10402 | .cmd = NL80211_CMD_NEW_KEY, | |
10403 | .doit = nl80211_new_key, | |
10404 | .policy = nl80211_policy, | |
10405 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10406 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10407 | NL80211_FLAG_NEED_RTNL | |
10408 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10409 | }, |
10410 | { | |
10411 | .cmd = NL80211_CMD_DEL_KEY, | |
10412 | .doit = nl80211_del_key, | |
10413 | .policy = nl80211_policy, | |
55682965 | 10414 | .flags = GENL_ADMIN_PERM, |
41265714 | 10415 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10416 | NL80211_FLAG_NEED_RTNL, |
55682965 | 10417 | }, |
ed1b6cc7 JB |
10418 | { |
10419 | .cmd = NL80211_CMD_SET_BEACON, | |
10420 | .policy = nl80211_policy, | |
10421 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10422 | .doit = nl80211_set_beacon, |
2b5f8b0b | 10423 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10424 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10425 | }, |
10426 | { | |
8860020e | 10427 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
10428 | .policy = nl80211_policy, |
10429 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10430 | .doit = nl80211_start_ap, |
2b5f8b0b | 10431 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10432 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10433 | }, |
10434 | { | |
8860020e | 10435 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
10436 | .policy = nl80211_policy, |
10437 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10438 | .doit = nl80211_stop_ap, |
2b5f8b0b | 10439 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10440 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 10441 | }, |
5727ef1b JB |
10442 | { |
10443 | .cmd = NL80211_CMD_GET_STATION, | |
10444 | .doit = nl80211_get_station, | |
2ec600d6 | 10445 | .dumpit = nl80211_dump_station, |
5727ef1b | 10446 | .policy = nl80211_policy, |
4c476991 JB |
10447 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10448 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
10449 | }, |
10450 | { | |
10451 | .cmd = NL80211_CMD_SET_STATION, | |
10452 | .doit = nl80211_set_station, | |
10453 | .policy = nl80211_policy, | |
10454 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10455 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10456 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10457 | }, |
10458 | { | |
10459 | .cmd = NL80211_CMD_NEW_STATION, | |
10460 | .doit = nl80211_new_station, | |
10461 | .policy = nl80211_policy, | |
10462 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10463 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10464 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10465 | }, |
10466 | { | |
10467 | .cmd = NL80211_CMD_DEL_STATION, | |
10468 | .doit = nl80211_del_station, | |
10469 | .policy = nl80211_policy, | |
2ec600d6 | 10470 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10471 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10472 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10473 | }, |
10474 | { | |
10475 | .cmd = NL80211_CMD_GET_MPATH, | |
10476 | .doit = nl80211_get_mpath, | |
10477 | .dumpit = nl80211_dump_mpath, | |
10478 | .policy = nl80211_policy, | |
10479 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10480 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10481 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 | 10482 | }, |
66be7d2b HR |
10483 | { |
10484 | .cmd = NL80211_CMD_GET_MPP, | |
10485 | .doit = nl80211_get_mpp, | |
10486 | .dumpit = nl80211_dump_mpp, | |
10487 | .policy = nl80211_policy, | |
10488 | .flags = GENL_ADMIN_PERM, | |
10489 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10490 | NL80211_FLAG_NEED_RTNL, | |
10491 | }, | |
2ec600d6 LCC |
10492 | { |
10493 | .cmd = NL80211_CMD_SET_MPATH, | |
10494 | .doit = nl80211_set_mpath, | |
10495 | .policy = nl80211_policy, | |
10496 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10497 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10498 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10499 | }, |
10500 | { | |
10501 | .cmd = NL80211_CMD_NEW_MPATH, | |
10502 | .doit = nl80211_new_mpath, | |
10503 | .policy = nl80211_policy, | |
10504 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10505 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10506 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10507 | }, |
10508 | { | |
10509 | .cmd = NL80211_CMD_DEL_MPATH, | |
10510 | .doit = nl80211_del_mpath, | |
10511 | .policy = nl80211_policy, | |
9f1ba906 | 10512 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10513 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10514 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
10515 | }, |
10516 | { | |
10517 | .cmd = NL80211_CMD_SET_BSS, | |
10518 | .doit = nl80211_set_bss, | |
10519 | .policy = nl80211_policy, | |
b2e1b302 | 10520 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10521 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10522 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 10523 | }, |
f130347c LR |
10524 | { |
10525 | .cmd = NL80211_CMD_GET_REG, | |
ad30ca2c AN |
10526 | .doit = nl80211_get_reg_do, |
10527 | .dumpit = nl80211_get_reg_dump, | |
f130347c | 10528 | .policy = nl80211_policy, |
5fe231e8 | 10529 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
10530 | /* can be retrieved by unprivileged users */ |
10531 | }, | |
b2e1b302 LR |
10532 | { |
10533 | .cmd = NL80211_CMD_SET_REG, | |
10534 | .doit = nl80211_set_reg, | |
10535 | .policy = nl80211_policy, | |
10536 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 10537 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
10538 | }, |
10539 | { | |
10540 | .cmd = NL80211_CMD_REQ_SET_REG, | |
10541 | .doit = nl80211_req_set_reg, | |
10542 | .policy = nl80211_policy, | |
93da9cc1 | 10543 | .flags = GENL_ADMIN_PERM, |
10544 | }, | |
10545 | { | |
24bdd9f4 JC |
10546 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
10547 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 10548 | .policy = nl80211_policy, |
10549 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 10550 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10551 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 10552 | }, |
10553 | { | |
24bdd9f4 JC |
10554 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
10555 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 10556 | .policy = nl80211_policy, |
9aed3cc1 | 10557 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 10558 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10559 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 10560 | }, |
2a519311 JB |
10561 | { |
10562 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
10563 | .doit = nl80211_trigger_scan, | |
10564 | .policy = nl80211_policy, | |
10565 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 10566 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10567 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
10568 | }, |
10569 | { | |
10570 | .cmd = NL80211_CMD_GET_SCAN, | |
10571 | .policy = nl80211_policy, | |
10572 | .dumpit = nl80211_dump_scan, | |
10573 | }, | |
807f8a8c LC |
10574 | { |
10575 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
10576 | .doit = nl80211_start_sched_scan, | |
10577 | .policy = nl80211_policy, | |
10578 | .flags = GENL_ADMIN_PERM, | |
10579 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10580 | NL80211_FLAG_NEED_RTNL, | |
10581 | }, | |
10582 | { | |
10583 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
10584 | .doit = nl80211_stop_sched_scan, | |
10585 | .policy = nl80211_policy, | |
10586 | .flags = GENL_ADMIN_PERM, | |
10587 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10588 | NL80211_FLAG_NEED_RTNL, | |
10589 | }, | |
636a5d36 JM |
10590 | { |
10591 | .cmd = NL80211_CMD_AUTHENTICATE, | |
10592 | .doit = nl80211_authenticate, | |
10593 | .policy = nl80211_policy, | |
10594 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10595 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10596 | NL80211_FLAG_NEED_RTNL | |
10597 | NL80211_FLAG_CLEAR_SKB, | |
636a5d36 JM |
10598 | }, |
10599 | { | |
10600 | .cmd = NL80211_CMD_ASSOCIATE, | |
10601 | .doit = nl80211_associate, | |
10602 | .policy = nl80211_policy, | |
10603 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10604 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10605 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10606 | }, |
10607 | { | |
10608 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
10609 | .doit = nl80211_deauthenticate, | |
10610 | .policy = nl80211_policy, | |
10611 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10612 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10613 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10614 | }, |
10615 | { | |
10616 | .cmd = NL80211_CMD_DISASSOCIATE, | |
10617 | .doit = nl80211_disassociate, | |
10618 | .policy = nl80211_policy, | |
10619 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10620 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10621 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 10622 | }, |
04a773ad JB |
10623 | { |
10624 | .cmd = NL80211_CMD_JOIN_IBSS, | |
10625 | .doit = nl80211_join_ibss, | |
10626 | .policy = nl80211_policy, | |
10627 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10628 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10629 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
10630 | }, |
10631 | { | |
10632 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
10633 | .doit = nl80211_leave_ibss, | |
10634 | .policy = nl80211_policy, | |
10635 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10636 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10637 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 10638 | }, |
aff89a9b JB |
10639 | #ifdef CONFIG_NL80211_TESTMODE |
10640 | { | |
10641 | .cmd = NL80211_CMD_TESTMODE, | |
10642 | .doit = nl80211_testmode_do, | |
71063f0e | 10643 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
10644 | .policy = nl80211_policy, |
10645 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10646 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10647 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
10648 | }, |
10649 | #endif | |
b23aa676 SO |
10650 | { |
10651 | .cmd = NL80211_CMD_CONNECT, | |
10652 | .doit = nl80211_connect, | |
10653 | .policy = nl80211_policy, | |
10654 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10655 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10656 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
10657 | }, |
10658 | { | |
10659 | .cmd = NL80211_CMD_DISCONNECT, | |
10660 | .doit = nl80211_disconnect, | |
10661 | .policy = nl80211_policy, | |
10662 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10663 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10664 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 10665 | }, |
463d0183 JB |
10666 | { |
10667 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
10668 | .doit = nl80211_wiphy_netns, | |
10669 | .policy = nl80211_policy, | |
10670 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10671 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10672 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 10673 | }, |
61fa713c HS |
10674 | { |
10675 | .cmd = NL80211_CMD_GET_SURVEY, | |
10676 | .policy = nl80211_policy, | |
10677 | .dumpit = nl80211_dump_survey, | |
10678 | }, | |
67fbb16b SO |
10679 | { |
10680 | .cmd = NL80211_CMD_SET_PMKSA, | |
10681 | .doit = nl80211_setdel_pmksa, | |
10682 | .policy = nl80211_policy, | |
10683 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10684 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10685 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10686 | }, |
10687 | { | |
10688 | .cmd = NL80211_CMD_DEL_PMKSA, | |
10689 | .doit = nl80211_setdel_pmksa, | |
10690 | .policy = nl80211_policy, | |
10691 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10692 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10693 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10694 | }, |
10695 | { | |
10696 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
10697 | .doit = nl80211_flush_pmksa, | |
10698 | .policy = nl80211_policy, | |
10699 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10700 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10701 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 10702 | }, |
9588bbd5 JM |
10703 | { |
10704 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
10705 | .doit = nl80211_remain_on_channel, | |
10706 | .policy = nl80211_policy, | |
10707 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10708 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10709 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
10710 | }, |
10711 | { | |
10712 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
10713 | .doit = nl80211_cancel_remain_on_channel, | |
10714 | .policy = nl80211_policy, | |
10715 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10716 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10717 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 10718 | }, |
13ae75b1 JM |
10719 | { |
10720 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
10721 | .doit = nl80211_set_tx_bitrate_mask, | |
10722 | .policy = nl80211_policy, | |
10723 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10724 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10725 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 10726 | }, |
026331c4 | 10727 | { |
2e161f78 JB |
10728 | .cmd = NL80211_CMD_REGISTER_FRAME, |
10729 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
10730 | .policy = nl80211_policy, |
10731 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10732 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10733 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
10734 | }, |
10735 | { | |
2e161f78 JB |
10736 | .cmd = NL80211_CMD_FRAME, |
10737 | .doit = nl80211_tx_mgmt, | |
026331c4 | 10738 | .policy = nl80211_policy, |
f7ca38df | 10739 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10740 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
10741 | NL80211_FLAG_NEED_RTNL, |
10742 | }, | |
10743 | { | |
10744 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
10745 | .doit = nl80211_tx_mgmt_cancel_wait, | |
10746 | .policy = nl80211_policy, | |
026331c4 | 10747 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10748 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10749 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 10750 | }, |
ffb9eb3d KV |
10751 | { |
10752 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
10753 | .doit = nl80211_set_power_save, | |
10754 | .policy = nl80211_policy, | |
10755 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10756 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10757 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
10758 | }, |
10759 | { | |
10760 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
10761 | .doit = nl80211_get_power_save, | |
10762 | .policy = nl80211_policy, | |
10763 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
10764 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10765 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 10766 | }, |
d6dc1a38 JO |
10767 | { |
10768 | .cmd = NL80211_CMD_SET_CQM, | |
10769 | .doit = nl80211_set_cqm, | |
10770 | .policy = nl80211_policy, | |
10771 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10772 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10773 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 10774 | }, |
f444de05 JB |
10775 | { |
10776 | .cmd = NL80211_CMD_SET_CHANNEL, | |
10777 | .doit = nl80211_set_channel, | |
10778 | .policy = nl80211_policy, | |
10779 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10780 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10781 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 10782 | }, |
e8347eba BJ |
10783 | { |
10784 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
10785 | .doit = nl80211_set_wds_peer, | |
10786 | .policy = nl80211_policy, | |
10787 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
10788 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10789 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 10790 | }, |
29cbe68c JB |
10791 | { |
10792 | .cmd = NL80211_CMD_JOIN_MESH, | |
10793 | .doit = nl80211_join_mesh, | |
10794 | .policy = nl80211_policy, | |
10795 | .flags = GENL_ADMIN_PERM, | |
10796 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10797 | NL80211_FLAG_NEED_RTNL, | |
10798 | }, | |
10799 | { | |
10800 | .cmd = NL80211_CMD_LEAVE_MESH, | |
10801 | .doit = nl80211_leave_mesh, | |
10802 | .policy = nl80211_policy, | |
10803 | .flags = GENL_ADMIN_PERM, | |
10804 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10805 | NL80211_FLAG_NEED_RTNL, | |
10806 | }, | |
6e0bd6c3 RL |
10807 | { |
10808 | .cmd = NL80211_CMD_JOIN_OCB, | |
10809 | .doit = nl80211_join_ocb, | |
10810 | .policy = nl80211_policy, | |
10811 | .flags = GENL_ADMIN_PERM, | |
10812 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10813 | NL80211_FLAG_NEED_RTNL, | |
10814 | }, | |
10815 | { | |
10816 | .cmd = NL80211_CMD_LEAVE_OCB, | |
10817 | .doit = nl80211_leave_ocb, | |
10818 | .policy = nl80211_policy, | |
10819 | .flags = GENL_ADMIN_PERM, | |
10820 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10821 | NL80211_FLAG_NEED_RTNL, | |
10822 | }, | |
dfb89c56 | 10823 | #ifdef CONFIG_PM |
ff1b6e69 JB |
10824 | { |
10825 | .cmd = NL80211_CMD_GET_WOWLAN, | |
10826 | .doit = nl80211_get_wowlan, | |
10827 | .policy = nl80211_policy, | |
10828 | /* can be retrieved by unprivileged users */ | |
10829 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10830 | NL80211_FLAG_NEED_RTNL, | |
10831 | }, | |
10832 | { | |
10833 | .cmd = NL80211_CMD_SET_WOWLAN, | |
10834 | .doit = nl80211_set_wowlan, | |
10835 | .policy = nl80211_policy, | |
10836 | .flags = GENL_ADMIN_PERM, | |
10837 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10838 | NL80211_FLAG_NEED_RTNL, | |
10839 | }, | |
dfb89c56 | 10840 | #endif |
e5497d76 JB |
10841 | { |
10842 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
10843 | .doit = nl80211_set_rekey_data, | |
10844 | .policy = nl80211_policy, | |
10845 | .flags = GENL_ADMIN_PERM, | |
10846 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
5393b917 JB |
10847 | NL80211_FLAG_NEED_RTNL | |
10848 | NL80211_FLAG_CLEAR_SKB, | |
e5497d76 | 10849 | }, |
109086ce AN |
10850 | { |
10851 | .cmd = NL80211_CMD_TDLS_MGMT, | |
10852 | .doit = nl80211_tdls_mgmt, | |
10853 | .policy = nl80211_policy, | |
10854 | .flags = GENL_ADMIN_PERM, | |
10855 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10856 | NL80211_FLAG_NEED_RTNL, | |
10857 | }, | |
10858 | { | |
10859 | .cmd = NL80211_CMD_TDLS_OPER, | |
10860 | .doit = nl80211_tdls_oper, | |
10861 | .policy = nl80211_policy, | |
10862 | .flags = GENL_ADMIN_PERM, | |
10863 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10864 | NL80211_FLAG_NEED_RTNL, | |
10865 | }, | |
28946da7 JB |
10866 | { |
10867 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
10868 | .doit = nl80211_register_unexpected_frame, | |
10869 | .policy = nl80211_policy, | |
10870 | .flags = GENL_ADMIN_PERM, | |
10871 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10872 | NL80211_FLAG_NEED_RTNL, | |
10873 | }, | |
7f6cf311 JB |
10874 | { |
10875 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
10876 | .doit = nl80211_probe_client, | |
10877 | .policy = nl80211_policy, | |
10878 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10879 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
10880 | NL80211_FLAG_NEED_RTNL, |
10881 | }, | |
5e760230 JB |
10882 | { |
10883 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
10884 | .doit = nl80211_register_beacons, | |
10885 | .policy = nl80211_policy, | |
10886 | .flags = GENL_ADMIN_PERM, | |
10887 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10888 | NL80211_FLAG_NEED_RTNL, | |
10889 | }, | |
1d9d9213 SW |
10890 | { |
10891 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
10892 | .doit = nl80211_set_noack_map, | |
10893 | .policy = nl80211_policy, | |
10894 | .flags = GENL_ADMIN_PERM, | |
10895 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10896 | NL80211_FLAG_NEED_RTNL, | |
10897 | }, | |
98104fde JB |
10898 | { |
10899 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
10900 | .doit = nl80211_start_p2p_device, | |
10901 | .policy = nl80211_policy, | |
10902 | .flags = GENL_ADMIN_PERM, | |
10903 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
10904 | NL80211_FLAG_NEED_RTNL, | |
10905 | }, | |
10906 | { | |
10907 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
10908 | .doit = nl80211_stop_p2p_device, | |
10909 | .policy = nl80211_policy, | |
10910 | .flags = GENL_ADMIN_PERM, | |
10911 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10912 | NL80211_FLAG_NEED_RTNL, | |
10913 | }, | |
f4e583c8 AQ |
10914 | { |
10915 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
10916 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
10917 | .policy = nl80211_policy, |
10918 | .flags = GENL_ADMIN_PERM, | |
10919 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10920 | NL80211_FLAG_NEED_RTNL, | |
10921 | }, | |
10922 | { | |
10923 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
10924 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
10925 | .policy = nl80211_policy, |
10926 | .flags = GENL_ADMIN_PERM, | |
10927 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10928 | NL80211_FLAG_NEED_RTNL, | |
10929 | }, | |
04f39047 SW |
10930 | { |
10931 | .cmd = NL80211_CMD_RADAR_DETECT, | |
10932 | .doit = nl80211_start_radar_detection, | |
10933 | .policy = nl80211_policy, | |
10934 | .flags = GENL_ADMIN_PERM, | |
10935 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10936 | NL80211_FLAG_NEED_RTNL, | |
10937 | }, | |
3713b4e3 JB |
10938 | { |
10939 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
10940 | .doit = nl80211_get_protocol_features, | |
10941 | .policy = nl80211_policy, | |
10942 | }, | |
355199e0 JM |
10943 | { |
10944 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
10945 | .doit = nl80211_update_ft_ies, | |
10946 | .policy = nl80211_policy, | |
10947 | .flags = GENL_ADMIN_PERM, | |
10948 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10949 | NL80211_FLAG_NEED_RTNL, | |
10950 | }, | |
5de17984 AS |
10951 | { |
10952 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
10953 | .doit = nl80211_crit_protocol_start, | |
10954 | .policy = nl80211_policy, | |
10955 | .flags = GENL_ADMIN_PERM, | |
10956 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10957 | NL80211_FLAG_NEED_RTNL, | |
10958 | }, | |
10959 | { | |
10960 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
10961 | .doit = nl80211_crit_protocol_stop, | |
10962 | .policy = nl80211_policy, | |
10963 | .flags = GENL_ADMIN_PERM, | |
10964 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10965 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
10966 | }, |
10967 | { | |
10968 | .cmd = NL80211_CMD_GET_COALESCE, | |
10969 | .doit = nl80211_get_coalesce, | |
10970 | .policy = nl80211_policy, | |
10971 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10972 | NL80211_FLAG_NEED_RTNL, | |
10973 | }, | |
10974 | { | |
10975 | .cmd = NL80211_CMD_SET_COALESCE, | |
10976 | .doit = nl80211_set_coalesce, | |
10977 | .policy = nl80211_policy, | |
10978 | .flags = GENL_ADMIN_PERM, | |
10979 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10980 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
10981 | }, |
10982 | { | |
10983 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
10984 | .doit = nl80211_channel_switch, | |
10985 | .policy = nl80211_policy, | |
10986 | .flags = GENL_ADMIN_PERM, | |
10987 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10988 | NL80211_FLAG_NEED_RTNL, | |
10989 | }, | |
ad7e718c JB |
10990 | { |
10991 | .cmd = NL80211_CMD_VENDOR, | |
10992 | .doit = nl80211_vendor_cmd, | |
10993 | .policy = nl80211_policy, | |
10994 | .flags = GENL_ADMIN_PERM, | |
10995 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10996 | NL80211_FLAG_NEED_RTNL, | |
10997 | }, | |
fa9ffc74 KP |
10998 | { |
10999 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
11000 | .doit = nl80211_set_qos_map, | |
11001 | .policy = nl80211_policy, | |
11002 | .flags = GENL_ADMIN_PERM, | |
11003 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11004 | NL80211_FLAG_NEED_RTNL, | |
11005 | }, | |
960d01ac JB |
11006 | { |
11007 | .cmd = NL80211_CMD_ADD_TX_TS, | |
11008 | .doit = nl80211_add_tx_ts, | |
11009 | .policy = nl80211_policy, | |
11010 | .flags = GENL_ADMIN_PERM, | |
11011 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11012 | NL80211_FLAG_NEED_RTNL, | |
11013 | }, | |
11014 | { | |
11015 | .cmd = NL80211_CMD_DEL_TX_TS, | |
11016 | .doit = nl80211_del_tx_ts, | |
11017 | .policy = nl80211_policy, | |
11018 | .flags = GENL_ADMIN_PERM, | |
11019 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11020 | NL80211_FLAG_NEED_RTNL, | |
11021 | }, | |
1057d35e AN |
11022 | { |
11023 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | |
11024 | .doit = nl80211_tdls_channel_switch, | |
11025 | .policy = nl80211_policy, | |
11026 | .flags = GENL_ADMIN_PERM, | |
11027 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11028 | NL80211_FLAG_NEED_RTNL, | |
11029 | }, | |
11030 | { | |
11031 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | |
11032 | .doit = nl80211_tdls_cancel_channel_switch, | |
11033 | .policy = nl80211_policy, | |
11034 | .flags = GENL_ADMIN_PERM, | |
11035 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11036 | NL80211_FLAG_NEED_RTNL, | |
11037 | }, | |
55682965 | 11038 | }; |
9588bbd5 | 11039 | |
55682965 JB |
11040 | /* notification functions */ |
11041 | ||
3bb20556 JB |
11042 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
11043 | enum nl80211_commands cmd) | |
55682965 JB |
11044 | { |
11045 | struct sk_buff *msg; | |
86e8cf98 | 11046 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 11047 | |
3bb20556 JB |
11048 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
11049 | cmd != NL80211_CMD_DEL_WIPHY); | |
11050 | ||
fd2120ca | 11051 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
11052 | if (!msg) |
11053 | return; | |
11054 | ||
3bb20556 | 11055 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
11056 | nlmsg_free(msg); |
11057 | return; | |
11058 | } | |
11059 | ||
68eb5503 | 11060 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11061 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
11062 | } |
11063 | ||
362a415d JB |
11064 | static int nl80211_add_scan_req(struct sk_buff *msg, |
11065 | struct cfg80211_registered_device *rdev) | |
11066 | { | |
11067 | struct cfg80211_scan_request *req = rdev->scan_req; | |
11068 | struct nlattr *nest; | |
11069 | int i; | |
11070 | ||
11071 | if (WARN_ON(!req)) | |
11072 | return 0; | |
11073 | ||
11074 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
11075 | if (!nest) | |
11076 | goto nla_put_failure; | |
9360ffd1 DM |
11077 | for (i = 0; i < req->n_ssids; i++) { |
11078 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
11079 | goto nla_put_failure; | |
11080 | } | |
362a415d JB |
11081 | nla_nest_end(msg, nest); |
11082 | ||
11083 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
11084 | if (!nest) | |
11085 | goto nla_put_failure; | |
9360ffd1 DM |
11086 | for (i = 0; i < req->n_channels; i++) { |
11087 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
11088 | goto nla_put_failure; | |
11089 | } | |
362a415d JB |
11090 | nla_nest_end(msg, nest); |
11091 | ||
9360ffd1 DM |
11092 | if (req->ie && |
11093 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
11094 | goto nla_put_failure; | |
362a415d | 11095 | |
ae917c9f JB |
11096 | if (req->flags && |
11097 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
11098 | goto nla_put_failure; | |
ed473771 | 11099 | |
362a415d JB |
11100 | return 0; |
11101 | nla_put_failure: | |
11102 | return -ENOBUFS; | |
11103 | } | |
11104 | ||
a538e2d5 JB |
11105 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
11106 | struct cfg80211_registered_device *rdev, | |
fd014284 | 11107 | struct wireless_dev *wdev, |
15e47304 | 11108 | u32 portid, u32 seq, int flags, |
a538e2d5 | 11109 | u32 cmd) |
2a519311 JB |
11110 | { |
11111 | void *hdr; | |
11112 | ||
15e47304 | 11113 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
11114 | if (!hdr) |
11115 | return -1; | |
11116 | ||
9360ffd1 | 11117 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
11118 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11119 | wdev->netdev->ifindex)) || | |
11120 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 11121 | goto nla_put_failure; |
2a519311 | 11122 | |
362a415d JB |
11123 | /* ignore errors and send incomplete event anyway */ |
11124 | nl80211_add_scan_req(msg, rdev); | |
2a519311 | 11125 | |
053c095a JB |
11126 | genlmsg_end(msg, hdr); |
11127 | return 0; | |
2a519311 JB |
11128 | |
11129 | nla_put_failure: | |
11130 | genlmsg_cancel(msg, hdr); | |
11131 | return -EMSGSIZE; | |
11132 | } | |
11133 | ||
807f8a8c LC |
11134 | static int |
11135 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
11136 | struct cfg80211_registered_device *rdev, | |
11137 | struct net_device *netdev, | |
15e47304 | 11138 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
11139 | { |
11140 | void *hdr; | |
11141 | ||
15e47304 | 11142 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
11143 | if (!hdr) |
11144 | return -1; | |
11145 | ||
9360ffd1 DM |
11146 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11147 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
11148 | goto nla_put_failure; | |
807f8a8c | 11149 | |
053c095a JB |
11150 | genlmsg_end(msg, hdr); |
11151 | return 0; | |
807f8a8c LC |
11152 | |
11153 | nla_put_failure: | |
11154 | genlmsg_cancel(msg, hdr); | |
11155 | return -EMSGSIZE; | |
11156 | } | |
11157 | ||
a538e2d5 | 11158 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 11159 | struct wireless_dev *wdev) |
a538e2d5 JB |
11160 | { |
11161 | struct sk_buff *msg; | |
11162 | ||
58050fce | 11163 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
11164 | if (!msg) |
11165 | return; | |
11166 | ||
fd014284 | 11167 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
11168 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
11169 | nlmsg_free(msg); | |
11170 | return; | |
11171 | } | |
11172 | ||
68eb5503 | 11173 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11174 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
11175 | } |
11176 | ||
f9d15d16 JB |
11177 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
11178 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
11179 | { |
11180 | struct sk_buff *msg; | |
11181 | ||
fd2120ca | 11182 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 11183 | if (!msg) |
f9d15d16 | 11184 | return NULL; |
2a519311 | 11185 | |
fd014284 | 11186 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
11187 | aborted ? NL80211_CMD_SCAN_ABORTED : |
11188 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 11189 | nlmsg_free(msg); |
f9d15d16 | 11190 | return NULL; |
2a519311 JB |
11191 | } |
11192 | ||
f9d15d16 | 11193 | return msg; |
2a519311 JB |
11194 | } |
11195 | ||
f9d15d16 JB |
11196 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
11197 | struct sk_buff *msg) | |
2a519311 | 11198 | { |
2a519311 JB |
11199 | if (!msg) |
11200 | return; | |
11201 | ||
68eb5503 | 11202 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11203 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
11204 | } |
11205 | ||
807f8a8c LC |
11206 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
11207 | struct net_device *netdev) | |
11208 | { | |
11209 | struct sk_buff *msg; | |
11210 | ||
11211 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11212 | if (!msg) | |
11213 | return; | |
11214 | ||
11215 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
11216 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
11217 | nlmsg_free(msg); | |
11218 | return; | |
11219 | } | |
11220 | ||
68eb5503 | 11221 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11222 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11223 | } |
11224 | ||
11225 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
11226 | struct net_device *netdev, u32 cmd) | |
11227 | { | |
11228 | struct sk_buff *msg; | |
11229 | ||
58050fce | 11230 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
11231 | if (!msg) |
11232 | return; | |
11233 | ||
11234 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
11235 | nlmsg_free(msg); | |
11236 | return; | |
11237 | } | |
11238 | ||
68eb5503 | 11239 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11240 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11241 | } |
11242 | ||
b0d7aa59 JD |
11243 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
11244 | struct regulatory_request *request) | |
73d54c9e | 11245 | { |
73d54c9e | 11246 | /* Userspace can always count this one always being set */ |
9360ffd1 DM |
11247 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
11248 | goto nla_put_failure; | |
11249 | ||
11250 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
11251 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11252 | NL80211_REGDOM_TYPE_WORLD)) | |
11253 | goto nla_put_failure; | |
11254 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
11255 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11256 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
11257 | goto nla_put_failure; | |
11258 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
11259 | request->intersect) { | |
11260 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11261 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
11262 | goto nla_put_failure; | |
11263 | } else { | |
11264 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11265 | NL80211_REGDOM_TYPE_COUNTRY) || | |
11266 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
11267 | request->alpha2)) | |
11268 | goto nla_put_failure; | |
11269 | } | |
11270 | ||
ad30ca2c AN |
11271 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
11272 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); | |
11273 | ||
11274 | if (wiphy && | |
11275 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | |
11276 | goto nla_put_failure; | |
1bdd716c AN |
11277 | |
11278 | if (wiphy && | |
11279 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | |
11280 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
11281 | goto nla_put_failure; | |
ad30ca2c | 11282 | } |
73d54c9e | 11283 | |
b0d7aa59 JD |
11284 | return true; |
11285 | ||
11286 | nla_put_failure: | |
11287 | return false; | |
11288 | } | |
11289 | ||
11290 | /* | |
11291 | * This can happen on global regulatory changes or device specific settings | |
11292 | * based on custom regulatory domains. | |
11293 | */ | |
11294 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, | |
11295 | struct regulatory_request *request) | |
11296 | { | |
11297 | struct sk_buff *msg; | |
11298 | void *hdr; | |
11299 | ||
11300 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11301 | if (!msg) | |
11302 | return; | |
11303 | ||
11304 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); | |
11305 | if (!hdr) { | |
11306 | nlmsg_free(msg); | |
11307 | return; | |
11308 | } | |
11309 | ||
11310 | if (nl80211_reg_change_event_fill(msg, request) == false) | |
11311 | goto nla_put_failure; | |
11312 | ||
3b7b72ee | 11313 | genlmsg_end(msg, hdr); |
73d54c9e | 11314 | |
bc43b28c | 11315 | rcu_read_lock(); |
68eb5503 | 11316 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11317 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 11318 | rcu_read_unlock(); |
73d54c9e LR |
11319 | |
11320 | return; | |
11321 | ||
11322 | nla_put_failure: | |
11323 | genlmsg_cancel(msg, hdr); | |
11324 | nlmsg_free(msg); | |
11325 | } | |
11326 | ||
6039f6d2 JM |
11327 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
11328 | struct net_device *netdev, | |
11329 | const u8 *buf, size_t len, | |
b0b6aa2c EP |
11330 | enum nl80211_commands cmd, gfp_t gfp, |
11331 | int uapsd_queues) | |
6039f6d2 JM |
11332 | { |
11333 | struct sk_buff *msg; | |
11334 | void *hdr; | |
11335 | ||
e6d6e342 | 11336 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
11337 | if (!msg) |
11338 | return; | |
11339 | ||
11340 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11341 | if (!hdr) { | |
11342 | nlmsg_free(msg); | |
11343 | return; | |
11344 | } | |
11345 | ||
9360ffd1 DM |
11346 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11347 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11348 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
11349 | goto nla_put_failure; | |
6039f6d2 | 11350 | |
b0b6aa2c EP |
11351 | if (uapsd_queues >= 0) { |
11352 | struct nlattr *nla_wmm = | |
11353 | nla_nest_start(msg, NL80211_ATTR_STA_WME); | |
11354 | if (!nla_wmm) | |
11355 | goto nla_put_failure; | |
11356 | ||
11357 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
11358 | uapsd_queues)) | |
11359 | goto nla_put_failure; | |
11360 | ||
11361 | nla_nest_end(msg, nla_wmm); | |
11362 | } | |
11363 | ||
3b7b72ee | 11364 | genlmsg_end(msg, hdr); |
6039f6d2 | 11365 | |
68eb5503 | 11366 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11367 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
11368 | return; |
11369 | ||
11370 | nla_put_failure: | |
11371 | genlmsg_cancel(msg, hdr); | |
11372 | nlmsg_free(msg); | |
11373 | } | |
11374 | ||
11375 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11376 | struct net_device *netdev, const u8 *buf, |
11377 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11378 | { |
11379 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11380 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11381 | } |
11382 | ||
11383 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
11384 | struct net_device *netdev, const u8 *buf, | |
b0b6aa2c | 11385 | size_t len, gfp_t gfp, int uapsd_queues) |
6039f6d2 | 11386 | { |
e6d6e342 | 11387 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
b0b6aa2c | 11388 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
6039f6d2 JM |
11389 | } |
11390 | ||
53b46b84 | 11391 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
11392 | struct net_device *netdev, const u8 *buf, |
11393 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11394 | { |
11395 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11396 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11397 | } |
11398 | ||
53b46b84 JM |
11399 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
11400 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 11401 | size_t len, gfp_t gfp) |
6039f6d2 JM |
11402 | { |
11403 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11404 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
6039f6d2 JM |
11405 | } |
11406 | ||
6ff57cf8 JB |
11407 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
11408 | size_t len) | |
cf4e594e | 11409 | { |
947add36 JB |
11410 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11411 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11412 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
11413 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
11414 | u32 cmd; | |
947add36 | 11415 | |
6ff57cf8 JB |
11416 | if (WARN_ON(len < 2)) |
11417 | return; | |
cf4e594e | 11418 | |
6ff57cf8 JB |
11419 | if (ieee80211_is_deauth(mgmt->frame_control)) |
11420 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
11421 | else | |
11422 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 11423 | |
6ff57cf8 | 11424 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
b0b6aa2c | 11425 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
cf4e594e | 11426 | } |
6ff57cf8 | 11427 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 11428 | |
1b06bb40 LR |
11429 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
11430 | struct net_device *netdev, int cmd, | |
e6d6e342 | 11431 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
11432 | { |
11433 | struct sk_buff *msg; | |
11434 | void *hdr; | |
11435 | ||
e6d6e342 | 11436 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
11437 | if (!msg) |
11438 | return; | |
11439 | ||
11440 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11441 | if (!hdr) { | |
11442 | nlmsg_free(msg); | |
11443 | return; | |
11444 | } | |
11445 | ||
9360ffd1 DM |
11446 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11447 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11448 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
11449 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11450 | goto nla_put_failure; | |
1965c853 | 11451 | |
3b7b72ee | 11452 | genlmsg_end(msg, hdr); |
1965c853 | 11453 | |
68eb5503 | 11454 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11455 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
11456 | return; |
11457 | ||
11458 | nla_put_failure: | |
11459 | genlmsg_cancel(msg, hdr); | |
11460 | nlmsg_free(msg); | |
11461 | } | |
11462 | ||
11463 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11464 | struct net_device *netdev, const u8 *addr, |
11465 | gfp_t gfp) | |
1965c853 JM |
11466 | { |
11467 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 11468 | addr, gfp); |
1965c853 JM |
11469 | } |
11470 | ||
11471 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11472 | struct net_device *netdev, const u8 *addr, |
11473 | gfp_t gfp) | |
1965c853 | 11474 | { |
e6d6e342 JB |
11475 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
11476 | addr, gfp); | |
1965c853 JM |
11477 | } |
11478 | ||
b23aa676 SO |
11479 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
11480 | struct net_device *netdev, const u8 *bssid, | |
11481 | const u8 *req_ie, size_t req_ie_len, | |
11482 | const u8 *resp_ie, size_t resp_ie_len, | |
11483 | u16 status, gfp_t gfp) | |
11484 | { | |
11485 | struct sk_buff *msg; | |
11486 | void *hdr; | |
11487 | ||
58050fce | 11488 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
11489 | if (!msg) |
11490 | return; | |
11491 | ||
11492 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
11493 | if (!hdr) { | |
11494 | nlmsg_free(msg); | |
11495 | return; | |
11496 | } | |
11497 | ||
9360ffd1 DM |
11498 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11499 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11500 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
11501 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
11502 | (req_ie && | |
11503 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11504 | (resp_ie && | |
11505 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11506 | goto nla_put_failure; | |
b23aa676 | 11507 | |
3b7b72ee | 11508 | genlmsg_end(msg, hdr); |
b23aa676 | 11509 | |
68eb5503 | 11510 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11511 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11512 | return; |
11513 | ||
11514 | nla_put_failure: | |
11515 | genlmsg_cancel(msg, hdr); | |
11516 | nlmsg_free(msg); | |
11517 | ||
11518 | } | |
11519 | ||
11520 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
11521 | struct net_device *netdev, const u8 *bssid, | |
11522 | const u8 *req_ie, size_t req_ie_len, | |
11523 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
11524 | { | |
11525 | struct sk_buff *msg; | |
11526 | void *hdr; | |
11527 | ||
58050fce | 11528 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
11529 | if (!msg) |
11530 | return; | |
11531 | ||
11532 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
11533 | if (!hdr) { | |
11534 | nlmsg_free(msg); | |
11535 | return; | |
11536 | } | |
11537 | ||
9360ffd1 DM |
11538 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11539 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11540 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
11541 | (req_ie && | |
11542 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11543 | (resp_ie && | |
11544 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11545 | goto nla_put_failure; | |
b23aa676 | 11546 | |
3b7b72ee | 11547 | genlmsg_end(msg, hdr); |
b23aa676 | 11548 | |
68eb5503 | 11549 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11550 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11551 | return; |
11552 | ||
11553 | nla_put_failure: | |
11554 | genlmsg_cancel(msg, hdr); | |
11555 | nlmsg_free(msg); | |
11556 | ||
11557 | } | |
11558 | ||
11559 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
11560 | struct net_device *netdev, u16 reason, | |
667503dd | 11561 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
11562 | { |
11563 | struct sk_buff *msg; | |
11564 | void *hdr; | |
11565 | ||
58050fce | 11566 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
11567 | if (!msg) |
11568 | return; | |
11569 | ||
11570 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
11571 | if (!hdr) { | |
11572 | nlmsg_free(msg); | |
11573 | return; | |
11574 | } | |
11575 | ||
9360ffd1 DM |
11576 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11577 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11578 | (from_ap && reason && | |
11579 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
11580 | (from_ap && | |
11581 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
11582 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
11583 | goto nla_put_failure; | |
b23aa676 | 11584 | |
3b7b72ee | 11585 | genlmsg_end(msg, hdr); |
b23aa676 | 11586 | |
68eb5503 | 11587 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11588 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
11589 | return; |
11590 | ||
11591 | nla_put_failure: | |
11592 | genlmsg_cancel(msg, hdr); | |
11593 | nlmsg_free(msg); | |
11594 | ||
11595 | } | |
11596 | ||
04a773ad JB |
11597 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
11598 | struct net_device *netdev, const u8 *bssid, | |
11599 | gfp_t gfp) | |
11600 | { | |
11601 | struct sk_buff *msg; | |
11602 | void *hdr; | |
11603 | ||
fd2120ca | 11604 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
11605 | if (!msg) |
11606 | return; | |
11607 | ||
11608 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
11609 | if (!hdr) { | |
11610 | nlmsg_free(msg); | |
11611 | return; | |
11612 | } | |
11613 | ||
9360ffd1 DM |
11614 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11615 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11616 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
11617 | goto nla_put_failure; | |
04a773ad | 11618 | |
3b7b72ee | 11619 | genlmsg_end(msg, hdr); |
04a773ad | 11620 | |
68eb5503 | 11621 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11622 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
11623 | return; |
11624 | ||
11625 | nla_put_failure: | |
11626 | genlmsg_cancel(msg, hdr); | |
11627 | nlmsg_free(msg); | |
11628 | } | |
11629 | ||
947add36 JB |
11630 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
11631 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 11632 | { |
947add36 | 11633 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 11634 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
11635 | struct sk_buff *msg; |
11636 | void *hdr; | |
11637 | ||
947add36 JB |
11638 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
11639 | return; | |
11640 | ||
11641 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
11642 | ||
c93b5e71 JC |
11643 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11644 | if (!msg) | |
11645 | return; | |
11646 | ||
11647 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
11648 | if (!hdr) { | |
11649 | nlmsg_free(msg); | |
11650 | return; | |
11651 | } | |
11652 | ||
9360ffd1 | 11653 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
11654 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
11655 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
11656 | (ie_len && ie && |
11657 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
11658 | goto nla_put_failure; | |
c93b5e71 | 11659 | |
3b7b72ee | 11660 | genlmsg_end(msg, hdr); |
c93b5e71 | 11661 | |
68eb5503 | 11662 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11663 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
11664 | return; |
11665 | ||
11666 | nla_put_failure: | |
11667 | genlmsg_cancel(msg, hdr); | |
11668 | nlmsg_free(msg); | |
11669 | } | |
947add36 | 11670 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 11671 | |
a3b8b056 JM |
11672 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
11673 | struct net_device *netdev, const u8 *addr, | |
11674 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 11675 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
11676 | { |
11677 | struct sk_buff *msg; | |
11678 | void *hdr; | |
11679 | ||
e6d6e342 | 11680 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
11681 | if (!msg) |
11682 | return; | |
11683 | ||
11684 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
11685 | if (!hdr) { | |
11686 | nlmsg_free(msg); | |
11687 | return; | |
11688 | } | |
11689 | ||
9360ffd1 DM |
11690 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11691 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11692 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
11693 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
11694 | (key_id != -1 && | |
11695 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
11696 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
11697 | goto nla_put_failure; | |
a3b8b056 | 11698 | |
3b7b72ee | 11699 | genlmsg_end(msg, hdr); |
a3b8b056 | 11700 | |
68eb5503 | 11701 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11702 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
11703 | return; |
11704 | ||
11705 | nla_put_failure: | |
11706 | genlmsg_cancel(msg, hdr); | |
11707 | nlmsg_free(msg); | |
11708 | } | |
11709 | ||
6bad8766 LR |
11710 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
11711 | struct ieee80211_channel *channel_before, | |
11712 | struct ieee80211_channel *channel_after) | |
11713 | { | |
11714 | struct sk_buff *msg; | |
11715 | void *hdr; | |
11716 | struct nlattr *nl_freq; | |
11717 | ||
fd2120ca | 11718 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
11719 | if (!msg) |
11720 | return; | |
11721 | ||
11722 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
11723 | if (!hdr) { | |
11724 | nlmsg_free(msg); | |
11725 | return; | |
11726 | } | |
11727 | ||
11728 | /* | |
11729 | * Since we are applying the beacon hint to a wiphy we know its | |
11730 | * wiphy_idx is valid | |
11731 | */ | |
9360ffd1 DM |
11732 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
11733 | goto nla_put_failure; | |
6bad8766 LR |
11734 | |
11735 | /* Before */ | |
11736 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
11737 | if (!nl_freq) | |
11738 | goto nla_put_failure; | |
cdc89b97 | 11739 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
11740 | goto nla_put_failure; |
11741 | nla_nest_end(msg, nl_freq); | |
11742 | ||
11743 | /* After */ | |
11744 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
11745 | if (!nl_freq) | |
11746 | goto nla_put_failure; | |
cdc89b97 | 11747 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
11748 | goto nla_put_failure; |
11749 | nla_nest_end(msg, nl_freq); | |
11750 | ||
3b7b72ee | 11751 | genlmsg_end(msg, hdr); |
6bad8766 | 11752 | |
463d0183 | 11753 | rcu_read_lock(); |
68eb5503 | 11754 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11755 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 11756 | rcu_read_unlock(); |
6bad8766 LR |
11757 | |
11758 | return; | |
11759 | ||
11760 | nla_put_failure: | |
11761 | genlmsg_cancel(msg, hdr); | |
11762 | nlmsg_free(msg); | |
11763 | } | |
11764 | ||
9588bbd5 JM |
11765 | static void nl80211_send_remain_on_chan_event( |
11766 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 11767 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 11768 | struct ieee80211_channel *chan, |
9588bbd5 JM |
11769 | unsigned int duration, gfp_t gfp) |
11770 | { | |
11771 | struct sk_buff *msg; | |
11772 | void *hdr; | |
11773 | ||
11774 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11775 | if (!msg) | |
11776 | return; | |
11777 | ||
11778 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11779 | if (!hdr) { | |
11780 | nlmsg_free(msg); | |
11781 | return; | |
11782 | } | |
11783 | ||
9360ffd1 | 11784 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11785 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11786 | wdev->netdev->ifindex)) || | |
00f53350 | 11787 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 11788 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
11789 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
11790 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
11791 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
11792 | goto nla_put_failure; | |
9588bbd5 | 11793 | |
9360ffd1 DM |
11794 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
11795 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
11796 | goto nla_put_failure; | |
9588bbd5 | 11797 | |
3b7b72ee | 11798 | genlmsg_end(msg, hdr); |
9588bbd5 | 11799 | |
68eb5503 | 11800 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11801 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
11802 | return; |
11803 | ||
11804 | nla_put_failure: | |
11805 | genlmsg_cancel(msg, hdr); | |
11806 | nlmsg_free(msg); | |
11807 | } | |
11808 | ||
947add36 JB |
11809 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
11810 | struct ieee80211_channel *chan, | |
11811 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 11812 | { |
947add36 | 11813 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11814 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11815 | |
11816 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 11817 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 11818 | rdev, wdev, cookie, chan, |
42d97a59 | 11819 | duration, gfp); |
9588bbd5 | 11820 | } |
947add36 | 11821 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 11822 | |
947add36 JB |
11823 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
11824 | struct ieee80211_channel *chan, | |
11825 | gfp_t gfp) | |
9588bbd5 | 11826 | { |
947add36 | 11827 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11828 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11829 | |
11830 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 11831 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 11832 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 11833 | } |
947add36 | 11834 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 11835 | |
947add36 JB |
11836 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
11837 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 11838 | { |
947add36 | 11839 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11840 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
11841 | struct sk_buff *msg; |
11842 | ||
947add36 JB |
11843 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
11844 | ||
58050fce | 11845 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
11846 | if (!msg) |
11847 | return; | |
11848 | ||
cf5ead82 | 11849 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
66266b3a | 11850 | rdev, dev, mac_addr, sinfo) < 0) { |
98b62183 JB |
11851 | nlmsg_free(msg); |
11852 | return; | |
11853 | } | |
11854 | ||
68eb5503 | 11855 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11856 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 11857 | } |
947add36 | 11858 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 11859 | |
cf5ead82 JB |
11860 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
11861 | struct station_info *sinfo, gfp_t gfp) | |
ec15e68b | 11862 | { |
947add36 | 11863 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11864 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b | 11865 | struct sk_buff *msg; |
cf5ead82 JB |
11866 | struct station_info empty_sinfo = {}; |
11867 | ||
11868 | if (!sinfo) | |
11869 | sinfo = &empty_sinfo; | |
ec15e68b | 11870 | |
947add36 JB |
11871 | trace_cfg80211_del_sta(dev, mac_addr); |
11872 | ||
58050fce | 11873 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
11874 | if (!msg) |
11875 | return; | |
11876 | ||
cf5ead82 | 11877 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
57007121 | 11878 | rdev, dev, mac_addr, sinfo) < 0) { |
ec15e68b JM |
11879 | nlmsg_free(msg); |
11880 | return; | |
11881 | } | |
11882 | ||
68eb5503 | 11883 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11884 | NL80211_MCGRP_MLME, gfp); |
ec15e68b | 11885 | } |
cf5ead82 | 11886 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
ec15e68b | 11887 | |
947add36 JB |
11888 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
11889 | enum nl80211_connect_failed_reason reason, | |
11890 | gfp_t gfp) | |
ed44a951 | 11891 | { |
947add36 | 11892 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11893 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
11894 | struct sk_buff *msg; |
11895 | void *hdr; | |
11896 | ||
11897 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
11898 | if (!msg) | |
11899 | return; | |
11900 | ||
11901 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
11902 | if (!hdr) { | |
11903 | nlmsg_free(msg); | |
11904 | return; | |
11905 | } | |
11906 | ||
11907 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11908 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
11909 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
11910 | goto nla_put_failure; | |
11911 | ||
11912 | genlmsg_end(msg, hdr); | |
11913 | ||
68eb5503 | 11914 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11915 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
11916 | return; |
11917 | ||
11918 | nla_put_failure: | |
11919 | genlmsg_cancel(msg, hdr); | |
11920 | nlmsg_free(msg); | |
11921 | } | |
947add36 | 11922 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 11923 | |
b92ab5d8 JB |
11924 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
11925 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
11926 | { |
11927 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 11928 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
11929 | struct sk_buff *msg; |
11930 | void *hdr; | |
15e47304 | 11931 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 11932 | |
15e47304 | 11933 | if (!nlportid) |
28946da7 JB |
11934 | return false; |
11935 | ||
11936 | msg = nlmsg_new(100, gfp); | |
11937 | if (!msg) | |
11938 | return true; | |
11939 | ||
b92ab5d8 | 11940 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
11941 | if (!hdr) { |
11942 | nlmsg_free(msg); | |
11943 | return true; | |
11944 | } | |
11945 | ||
9360ffd1 DM |
11946 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11947 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11948 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11949 | goto nla_put_failure; | |
28946da7 | 11950 | |
9c90a9f6 | 11951 | genlmsg_end(msg, hdr); |
15e47304 | 11952 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
11953 | return true; |
11954 | ||
11955 | nla_put_failure: | |
11956 | genlmsg_cancel(msg, hdr); | |
11957 | nlmsg_free(msg); | |
11958 | return true; | |
11959 | } | |
11960 | ||
947add36 JB |
11961 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
11962 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11963 | { |
947add36 JB |
11964 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11965 | bool ret; | |
11966 | ||
11967 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
11968 | ||
11969 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11970 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
11971 | trace_cfg80211_return_bool(false); | |
11972 | return false; | |
11973 | } | |
11974 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
11975 | addr, gfp); | |
11976 | trace_cfg80211_return_bool(ret); | |
11977 | return ret; | |
b92ab5d8 | 11978 | } |
947add36 | 11979 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 11980 | |
947add36 JB |
11981 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
11982 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11983 | { |
947add36 JB |
11984 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11985 | bool ret; | |
11986 | ||
11987 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
11988 | ||
11989 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11990 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
11991 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
11992 | trace_cfg80211_return_bool(false); | |
11993 | return false; | |
11994 | } | |
11995 | ret = __nl80211_unexpected_frame(dev, | |
11996 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
11997 | addr, gfp); | |
11998 | trace_cfg80211_return_bool(ret); | |
11999 | return ret; | |
b92ab5d8 | 12000 | } |
947add36 | 12001 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 12002 | |
2e161f78 | 12003 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 12004 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 12005 | int freq, int sig_dbm, |
19504cf5 | 12006 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 12007 | { |
71bbc994 | 12008 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
12009 | struct sk_buff *msg; |
12010 | void *hdr; | |
026331c4 JM |
12011 | |
12012 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12013 | if (!msg) | |
12014 | return -ENOMEM; | |
12015 | ||
2e161f78 | 12016 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
12017 | if (!hdr) { |
12018 | nlmsg_free(msg); | |
12019 | return -ENOMEM; | |
12020 | } | |
12021 | ||
9360ffd1 | 12022 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
12023 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
12024 | netdev->ifindex)) || | |
a838490b | 12025 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
12026 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
12027 | (sig_dbm && | |
12028 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
12029 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
12030 | (flags && | |
12031 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 12032 | goto nla_put_failure; |
026331c4 | 12033 | |
3b7b72ee | 12034 | genlmsg_end(msg, hdr); |
026331c4 | 12035 | |
15e47304 | 12036 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
12037 | |
12038 | nla_put_failure: | |
12039 | genlmsg_cancel(msg, hdr); | |
12040 | nlmsg_free(msg); | |
12041 | return -ENOBUFS; | |
12042 | } | |
12043 | ||
947add36 JB |
12044 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
12045 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 12046 | { |
947add36 | 12047 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 12048 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 12049 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
12050 | struct sk_buff *msg; |
12051 | void *hdr; | |
12052 | ||
947add36 JB |
12053 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
12054 | ||
026331c4 JM |
12055 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
12056 | if (!msg) | |
12057 | return; | |
12058 | ||
2e161f78 | 12059 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
12060 | if (!hdr) { |
12061 | nlmsg_free(msg); | |
12062 | return; | |
12063 | } | |
12064 | ||
9360ffd1 | 12065 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
12066 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
12067 | netdev->ifindex)) || | |
a838490b | 12068 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
12069 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
12070 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
12071 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
12072 | goto nla_put_failure; | |
026331c4 | 12073 | |
3b7b72ee | 12074 | genlmsg_end(msg, hdr); |
026331c4 | 12075 | |
68eb5503 | 12076 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12077 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
12078 | return; |
12079 | ||
12080 | nla_put_failure: | |
12081 | genlmsg_cancel(msg, hdr); | |
12082 | nlmsg_free(msg); | |
12083 | } | |
947add36 | 12084 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 12085 | |
5b97f49d JB |
12086 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
12087 | const char *mac, gfp_t gfp) | |
d6dc1a38 | 12088 | { |
947add36 | 12089 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5b97f49d JB |
12090 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
12091 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12092 | void **cb; | |
947add36 | 12093 | |
d6dc1a38 | 12094 | if (!msg) |
5b97f49d | 12095 | return NULL; |
d6dc1a38 | 12096 | |
5b97f49d JB |
12097 | cb = (void **)msg->cb; |
12098 | ||
12099 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
12100 | if (!cb[0]) { | |
d6dc1a38 | 12101 | nlmsg_free(msg); |
5b97f49d | 12102 | return NULL; |
d6dc1a38 JO |
12103 | } |
12104 | ||
9360ffd1 | 12105 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 12106 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 12107 | goto nla_put_failure; |
d6dc1a38 | 12108 | |
5b97f49d | 12109 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
d6dc1a38 JO |
12110 | goto nla_put_failure; |
12111 | ||
5b97f49d JB |
12112 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
12113 | if (!cb[1]) | |
9360ffd1 | 12114 | goto nla_put_failure; |
d6dc1a38 | 12115 | |
5b97f49d | 12116 | cb[2] = rdev; |
d6dc1a38 | 12117 | |
5b97f49d JB |
12118 | return msg; |
12119 | nla_put_failure: | |
12120 | nlmsg_free(msg); | |
12121 | return NULL; | |
12122 | } | |
12123 | ||
12124 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) | |
12125 | { | |
12126 | void **cb = (void **)msg->cb; | |
12127 | struct cfg80211_registered_device *rdev = cb[2]; | |
12128 | ||
12129 | nla_nest_end(msg, cb[1]); | |
12130 | genlmsg_end(msg, cb[0]); | |
12131 | ||
12132 | memset(msg->cb, 0, sizeof(msg->cb)); | |
d6dc1a38 | 12133 | |
68eb5503 | 12134 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12135 | NL80211_MCGRP_MLME, gfp); |
5b97f49d JB |
12136 | } |
12137 | ||
12138 | void cfg80211_cqm_rssi_notify(struct net_device *dev, | |
12139 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
12140 | gfp_t gfp) | |
12141 | { | |
12142 | struct sk_buff *msg; | |
12143 | ||
12144 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); | |
12145 | ||
98f03342 JB |
12146 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
12147 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) | |
12148 | return; | |
12149 | ||
5b97f49d JB |
12150 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
12151 | if (!msg) | |
12152 | return; | |
12153 | ||
12154 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
12155 | rssi_event)) | |
12156 | goto nla_put_failure; | |
12157 | ||
12158 | cfg80211_send_cqm(msg, gfp); | |
12159 | ||
d6dc1a38 JO |
12160 | return; |
12161 | ||
12162 | nla_put_failure: | |
d6dc1a38 JO |
12163 | nlmsg_free(msg); |
12164 | } | |
947add36 | 12165 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 12166 | |
5b97f49d JB |
12167 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
12168 | const u8 *peer, u32 num_packets, | |
12169 | u32 rate, u32 intvl, gfp_t gfp) | |
12170 | { | |
12171 | struct sk_buff *msg; | |
12172 | ||
12173 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12174 | if (!msg) | |
12175 | return; | |
12176 | ||
12177 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
12178 | goto nla_put_failure; | |
12179 | ||
12180 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
12181 | goto nla_put_failure; | |
12182 | ||
12183 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
12184 | goto nla_put_failure; | |
12185 | ||
12186 | cfg80211_send_cqm(msg, gfp); | |
12187 | return; | |
12188 | ||
12189 | nla_put_failure: | |
12190 | nlmsg_free(msg); | |
12191 | } | |
12192 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); | |
12193 | ||
12194 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, | |
12195 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
12196 | { | |
12197 | struct sk_buff *msg; | |
12198 | ||
12199 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); | |
12200 | ||
12201 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12202 | if (!msg) | |
12203 | return; | |
12204 | ||
12205 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) | |
12206 | goto nla_put_failure; | |
12207 | ||
12208 | cfg80211_send_cqm(msg, gfp); | |
12209 | return; | |
12210 | ||
12211 | nla_put_failure: | |
12212 | nlmsg_free(msg); | |
12213 | } | |
12214 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); | |
12215 | ||
98f03342 JB |
12216 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
12217 | { | |
12218 | struct sk_buff *msg; | |
12219 | ||
12220 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); | |
12221 | if (!msg) | |
12222 | return; | |
12223 | ||
12224 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) | |
12225 | goto nla_put_failure; | |
12226 | ||
12227 | cfg80211_send_cqm(msg, gfp); | |
12228 | return; | |
12229 | ||
12230 | nla_put_failure: | |
12231 | nlmsg_free(msg); | |
12232 | } | |
12233 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); | |
12234 | ||
947add36 JB |
12235 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
12236 | struct net_device *netdev, const u8 *bssid, | |
12237 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
12238 | { |
12239 | struct sk_buff *msg; | |
12240 | struct nlattr *rekey_attr; | |
12241 | void *hdr; | |
12242 | ||
58050fce | 12243 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
12244 | if (!msg) |
12245 | return; | |
12246 | ||
12247 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
12248 | if (!hdr) { | |
12249 | nlmsg_free(msg); | |
12250 | return; | |
12251 | } | |
12252 | ||
9360ffd1 DM |
12253 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12254 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12255 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
12256 | goto nla_put_failure; | |
e5497d76 JB |
12257 | |
12258 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
12259 | if (!rekey_attr) | |
12260 | goto nla_put_failure; | |
12261 | ||
9360ffd1 DM |
12262 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
12263 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
12264 | goto nla_put_failure; | |
e5497d76 JB |
12265 | |
12266 | nla_nest_end(msg, rekey_attr); | |
12267 | ||
3b7b72ee | 12268 | genlmsg_end(msg, hdr); |
e5497d76 | 12269 | |
68eb5503 | 12270 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12271 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
12272 | return; |
12273 | ||
12274 | nla_put_failure: | |
12275 | genlmsg_cancel(msg, hdr); | |
12276 | nlmsg_free(msg); | |
12277 | } | |
12278 | ||
947add36 JB |
12279 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
12280 | const u8 *replay_ctr, gfp_t gfp) | |
12281 | { | |
12282 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12283 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12284 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12285 | |
12286 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
12287 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
12288 | } | |
12289 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
12290 | ||
12291 | static void | |
12292 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
12293 | struct net_device *netdev, int index, | |
12294 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
12295 | { |
12296 | struct sk_buff *msg; | |
12297 | struct nlattr *attr; | |
12298 | void *hdr; | |
12299 | ||
58050fce | 12300 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
12301 | if (!msg) |
12302 | return; | |
12303 | ||
12304 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
12305 | if (!hdr) { | |
12306 | nlmsg_free(msg); | |
12307 | return; | |
12308 | } | |
12309 | ||
9360ffd1 DM |
12310 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12311 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
12312 | goto nla_put_failure; | |
c9df56b4 JM |
12313 | |
12314 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
12315 | if (!attr) | |
12316 | goto nla_put_failure; | |
12317 | ||
9360ffd1 DM |
12318 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
12319 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
12320 | (preauth && | |
12321 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
12322 | goto nla_put_failure; | |
c9df56b4 JM |
12323 | |
12324 | nla_nest_end(msg, attr); | |
12325 | ||
3b7b72ee | 12326 | genlmsg_end(msg, hdr); |
c9df56b4 | 12327 | |
68eb5503 | 12328 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12329 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
12330 | return; |
12331 | ||
12332 | nla_put_failure: | |
12333 | genlmsg_cancel(msg, hdr); | |
12334 | nlmsg_free(msg); | |
12335 | } | |
12336 | ||
947add36 JB |
12337 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
12338 | const u8 *bssid, bool preauth, gfp_t gfp) | |
12339 | { | |
12340 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12341 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12342 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12343 | |
12344 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
12345 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
12346 | } | |
12347 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
12348 | ||
12349 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
12350 | struct net_device *netdev, | |
12351 | struct cfg80211_chan_def *chandef, | |
f8d7552e LC |
12352 | gfp_t gfp, |
12353 | enum nl80211_commands notif, | |
12354 | u8 count) | |
5314526b TP |
12355 | { |
12356 | struct sk_buff *msg; | |
12357 | void *hdr; | |
12358 | ||
58050fce | 12359 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
12360 | if (!msg) |
12361 | return; | |
12362 | ||
f8d7552e | 12363 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
5314526b TP |
12364 | if (!hdr) { |
12365 | nlmsg_free(msg); | |
12366 | return; | |
12367 | } | |
12368 | ||
683b6d3b JB |
12369 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
12370 | goto nla_put_failure; | |
12371 | ||
12372 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 12373 | goto nla_put_failure; |
5314526b | 12374 | |
f8d7552e LC |
12375 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
12376 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) | |
12377 | goto nla_put_failure; | |
12378 | ||
5314526b TP |
12379 | genlmsg_end(msg, hdr); |
12380 | ||
68eb5503 | 12381 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12382 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
12383 | return; |
12384 | ||
12385 | nla_put_failure: | |
12386 | genlmsg_cancel(msg, hdr); | |
12387 | nlmsg_free(msg); | |
12388 | } | |
12389 | ||
947add36 JB |
12390 | void cfg80211_ch_switch_notify(struct net_device *dev, |
12391 | struct cfg80211_chan_def *chandef) | |
84f10708 | 12392 | { |
947add36 JB |
12393 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
12394 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12395 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 12396 | |
e487eaeb | 12397 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 12398 | |
e487eaeb | 12399 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 | 12400 | |
9e0e2961 | 12401 | wdev->chandef = *chandef; |
96f55f12 | 12402 | wdev->preset_chandef = *chandef; |
f8d7552e LC |
12403 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
12404 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); | |
947add36 JB |
12405 | } |
12406 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
12407 | ||
f8d7552e LC |
12408 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
12409 | struct cfg80211_chan_def *chandef, | |
12410 | u8 count) | |
12411 | { | |
12412 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12413 | struct wiphy *wiphy = wdev->wiphy; | |
12414 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
12415 | ||
12416 | trace_cfg80211_ch_switch_started_notify(dev, chandef); | |
12417 | ||
12418 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | |
12419 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); | |
12420 | } | |
12421 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | |
12422 | ||
04f39047 SW |
12423 | void |
12424 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 12425 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
12426 | enum nl80211_radar_event event, |
12427 | struct net_device *netdev, gfp_t gfp) | |
12428 | { | |
12429 | struct sk_buff *msg; | |
12430 | void *hdr; | |
12431 | ||
12432 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12433 | if (!msg) | |
12434 | return; | |
12435 | ||
12436 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
12437 | if (!hdr) { | |
12438 | nlmsg_free(msg); | |
12439 | return; | |
12440 | } | |
12441 | ||
12442 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
12443 | goto nla_put_failure; | |
12444 | ||
12445 | /* NOP and radar events don't need a netdev parameter */ | |
12446 | if (netdev) { | |
12447 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
12448 | ||
12449 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12450 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12451 | goto nla_put_failure; | |
12452 | } | |
12453 | ||
12454 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
12455 | goto nla_put_failure; | |
12456 | ||
12457 | if (nl80211_send_chandef(msg, chandef)) | |
12458 | goto nla_put_failure; | |
12459 | ||
9c90a9f6 | 12460 | genlmsg_end(msg, hdr); |
04f39047 | 12461 | |
68eb5503 | 12462 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12463 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
12464 | return; |
12465 | ||
12466 | nla_put_failure: | |
12467 | genlmsg_cancel(msg, hdr); | |
12468 | nlmsg_free(msg); | |
12469 | } | |
12470 | ||
7f6cf311 JB |
12471 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
12472 | u64 cookie, bool acked, gfp_t gfp) | |
12473 | { | |
12474 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12475 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
12476 | struct sk_buff *msg; |
12477 | void *hdr; | |
7f6cf311 | 12478 | |
4ee3e063 BL |
12479 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
12480 | ||
58050fce | 12481 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 12482 | |
7f6cf311 JB |
12483 | if (!msg) |
12484 | return; | |
12485 | ||
12486 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
12487 | if (!hdr) { | |
12488 | nlmsg_free(msg); | |
12489 | return; | |
12490 | } | |
12491 | ||
9360ffd1 DM |
12492 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12493 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12494 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
12495 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
12496 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
12497 | goto nla_put_failure; | |
7f6cf311 | 12498 | |
9c90a9f6 | 12499 | genlmsg_end(msg, hdr); |
7f6cf311 | 12500 | |
68eb5503 | 12501 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12502 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
12503 | return; |
12504 | ||
12505 | nla_put_failure: | |
12506 | genlmsg_cancel(msg, hdr); | |
12507 | nlmsg_free(msg); | |
12508 | } | |
12509 | EXPORT_SYMBOL(cfg80211_probe_status); | |
12510 | ||
5e760230 JB |
12511 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
12512 | const u8 *frame, size_t len, | |
37c73b5f | 12513 | int freq, int sig_dbm) |
5e760230 | 12514 | { |
f26cbf40 | 12515 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
12516 | struct sk_buff *msg; |
12517 | void *hdr; | |
37c73b5f | 12518 | struct cfg80211_beacon_registration *reg; |
5e760230 | 12519 | |
4ee3e063 BL |
12520 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
12521 | ||
37c73b5f BG |
12522 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12523 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
12524 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
12525 | if (!msg) { | |
12526 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
12527 | return; | |
12528 | } | |
5e760230 | 12529 | |
37c73b5f BG |
12530 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
12531 | if (!hdr) | |
12532 | goto nla_put_failure; | |
5e760230 | 12533 | |
37c73b5f BG |
12534 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12535 | (freq && | |
12536 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
12537 | (sig_dbm && | |
12538 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
12539 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
12540 | goto nla_put_failure; | |
5e760230 | 12541 | |
37c73b5f | 12542 | genlmsg_end(msg, hdr); |
5e760230 | 12543 | |
37c73b5f BG |
12544 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
12545 | } | |
12546 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
12547 | return; |
12548 | ||
12549 | nla_put_failure: | |
37c73b5f BG |
12550 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
12551 | if (hdr) | |
12552 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
12553 | nlmsg_free(msg); |
12554 | } | |
12555 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
12556 | ||
cd8f7cb4 | 12557 | #ifdef CONFIG_PM |
8cd4d456 LC |
12558 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
12559 | struct cfg80211_wowlan_wakeup *wakeup) | |
12560 | { | |
12561 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | |
12562 | struct nlattr *nl_results, *nl_match, *nl_freqs; | |
12563 | int i, j; | |
12564 | ||
12565 | nl_results = nla_nest_start( | |
12566 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | |
12567 | if (!nl_results) | |
12568 | return -EMSGSIZE; | |
12569 | ||
12570 | for (i = 0; i < nd->n_matches; i++) { | |
12571 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | |
12572 | ||
12573 | nl_match = nla_nest_start(msg, i); | |
12574 | if (!nl_match) | |
12575 | break; | |
12576 | ||
12577 | /* The SSID attribute is optional in nl80211, but for | |
12578 | * simplicity reasons it's always present in the | |
12579 | * cfg80211 structure. If a driver can't pass the | |
12580 | * SSID, that needs to be changed. A zero length SSID | |
12581 | * is still a valid SSID (wildcard), so it cannot be | |
12582 | * used for this purpose. | |
12583 | */ | |
12584 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | |
12585 | match->ssid.ssid)) { | |
12586 | nla_nest_cancel(msg, nl_match); | |
12587 | goto out; | |
12588 | } | |
12589 | ||
12590 | if (match->n_channels) { | |
12591 | nl_freqs = nla_nest_start( | |
12592 | msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
12593 | if (!nl_freqs) { | |
12594 | nla_nest_cancel(msg, nl_match); | |
12595 | goto out; | |
12596 | } | |
12597 | ||
12598 | for (j = 0; j < match->n_channels; j++) { | |
5528fae8 | 12599 | if (nla_put_u32(msg, j, match->channels[j])) { |
8cd4d456 LC |
12600 | nla_nest_cancel(msg, nl_freqs); |
12601 | nla_nest_cancel(msg, nl_match); | |
12602 | goto out; | |
12603 | } | |
12604 | } | |
12605 | ||
12606 | nla_nest_end(msg, nl_freqs); | |
12607 | } | |
12608 | ||
12609 | nla_nest_end(msg, nl_match); | |
12610 | } | |
12611 | ||
12612 | out: | |
12613 | nla_nest_end(msg, nl_results); | |
12614 | return 0; | |
12615 | } | |
12616 | ||
cd8f7cb4 JB |
12617 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
12618 | struct cfg80211_wowlan_wakeup *wakeup, | |
12619 | gfp_t gfp) | |
12620 | { | |
f26cbf40 | 12621 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
12622 | struct sk_buff *msg; |
12623 | void *hdr; | |
9c90a9f6 | 12624 | int size = 200; |
cd8f7cb4 JB |
12625 | |
12626 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
12627 | ||
12628 | if (wakeup) | |
12629 | size += wakeup->packet_present_len; | |
12630 | ||
12631 | msg = nlmsg_new(size, gfp); | |
12632 | if (!msg) | |
12633 | return; | |
12634 | ||
12635 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
12636 | if (!hdr) | |
12637 | goto free_msg; | |
12638 | ||
12639 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12640 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12641 | goto free_msg; | |
12642 | ||
12643 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
12644 | wdev->netdev->ifindex)) | |
12645 | goto free_msg; | |
12646 | ||
12647 | if (wakeup) { | |
12648 | struct nlattr *reasons; | |
12649 | ||
12650 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
12651 | if (!reasons) |
12652 | goto free_msg; | |
cd8f7cb4 JB |
12653 | |
12654 | if (wakeup->disconnect && | |
12655 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
12656 | goto free_msg; | |
12657 | if (wakeup->magic_pkt && | |
12658 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
12659 | goto free_msg; | |
12660 | if (wakeup->gtk_rekey_failure && | |
12661 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
12662 | goto free_msg; | |
12663 | if (wakeup->eap_identity_req && | |
12664 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
12665 | goto free_msg; | |
12666 | if (wakeup->four_way_handshake && | |
12667 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
12668 | goto free_msg; | |
12669 | if (wakeup->rfkill_release && | |
12670 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
12671 | goto free_msg; | |
12672 | ||
12673 | if (wakeup->pattern_idx >= 0 && | |
12674 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
12675 | wakeup->pattern_idx)) | |
12676 | goto free_msg; | |
12677 | ||
ae917c9f JB |
12678 | if (wakeup->tcp_match && |
12679 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
12680 | goto free_msg; | |
2a0e047e | 12681 | |
ae917c9f JB |
12682 | if (wakeup->tcp_connlost && |
12683 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
12684 | goto free_msg; | |
2a0e047e | 12685 | |
ae917c9f JB |
12686 | if (wakeup->tcp_nomoretokens && |
12687 | nla_put_flag(msg, | |
12688 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
12689 | goto free_msg; | |
2a0e047e | 12690 | |
cd8f7cb4 JB |
12691 | if (wakeup->packet) { |
12692 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
12693 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
12694 | ||
12695 | if (!wakeup->packet_80211) { | |
12696 | pkt_attr = | |
12697 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
12698 | len_attr = | |
12699 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
12700 | } | |
12701 | ||
12702 | if (wakeup->packet_len && | |
12703 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
12704 | goto free_msg; | |
12705 | ||
12706 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
12707 | wakeup->packet)) | |
12708 | goto free_msg; | |
12709 | } | |
12710 | ||
8cd4d456 LC |
12711 | if (wakeup->net_detect && |
12712 | cfg80211_net_detect_results(msg, wakeup)) | |
12713 | goto free_msg; | |
12714 | ||
cd8f7cb4 JB |
12715 | nla_nest_end(msg, reasons); |
12716 | } | |
12717 | ||
9c90a9f6 | 12718 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 12719 | |
68eb5503 | 12720 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12721 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
12722 | return; |
12723 | ||
12724 | free_msg: | |
12725 | nlmsg_free(msg); | |
12726 | } | |
12727 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
12728 | #endif | |
12729 | ||
3475b094 JM |
12730 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
12731 | enum nl80211_tdls_operation oper, | |
12732 | u16 reason_code, gfp_t gfp) | |
12733 | { | |
12734 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12735 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
12736 | struct sk_buff *msg; |
12737 | void *hdr; | |
3475b094 JM |
12738 | |
12739 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
12740 | reason_code); | |
12741 | ||
12742 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12743 | if (!msg) | |
12744 | return; | |
12745 | ||
12746 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
12747 | if (!hdr) { | |
12748 | nlmsg_free(msg); | |
12749 | return; | |
12750 | } | |
12751 | ||
12752 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12753 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12754 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
12755 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
12756 | (reason_code > 0 && | |
12757 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
12758 | goto nla_put_failure; | |
12759 | ||
9c90a9f6 | 12760 | genlmsg_end(msg, hdr); |
3475b094 | 12761 | |
68eb5503 | 12762 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12763 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
12764 | return; |
12765 | ||
12766 | nla_put_failure: | |
12767 | genlmsg_cancel(msg, hdr); | |
12768 | nlmsg_free(msg); | |
12769 | } | |
12770 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
12771 | ||
026331c4 JM |
12772 | static int nl80211_netlink_notify(struct notifier_block * nb, |
12773 | unsigned long state, | |
12774 | void *_notify) | |
12775 | { | |
12776 | struct netlink_notify *notify = _notify; | |
12777 | struct cfg80211_registered_device *rdev; | |
12778 | struct wireless_dev *wdev; | |
37c73b5f | 12779 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
12780 | |
12781 | if (state != NETLINK_URELEASE) | |
12782 | return NOTIFY_DONE; | |
12783 | ||
12784 | rcu_read_lock(); | |
12785 | ||
5e760230 | 12786 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
78f22b6a | 12787 | bool schedule_destroy_work = false; |
93a1e86c JR |
12788 | bool schedule_scan_stop = false; |
12789 | struct cfg80211_sched_scan_request *sched_scan_req = | |
12790 | rcu_dereference(rdev->sched_scan_req); | |
12791 | ||
12792 | if (sched_scan_req && notify->portid && | |
12793 | sched_scan_req->owner_nlportid == notify->portid) | |
12794 | schedule_scan_stop = true; | |
78f22b6a JB |
12795 | |
12796 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { | |
15e47304 | 12797 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 12798 | |
78f22b6a JB |
12799 | if (wdev->owner_nlportid == notify->portid) |
12800 | schedule_destroy_work = true; | |
12801 | } | |
12802 | ||
37c73b5f BG |
12803 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12804 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
12805 | list) { | |
12806 | if (reg->nlportid == notify->portid) { | |
12807 | list_del(®->list); | |
12808 | kfree(reg); | |
12809 | break; | |
12810 | } | |
12811 | } | |
12812 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
78f22b6a JB |
12813 | |
12814 | if (schedule_destroy_work) { | |
12815 | struct cfg80211_iface_destroy *destroy; | |
12816 | ||
12817 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | |
12818 | if (destroy) { | |
12819 | destroy->nlportid = notify->portid; | |
12820 | spin_lock(&rdev->destroy_list_lock); | |
12821 | list_add(&destroy->list, &rdev->destroy_list); | |
12822 | spin_unlock(&rdev->destroy_list_lock); | |
12823 | schedule_work(&rdev->destroy_work); | |
12824 | } | |
93a1e86c JR |
12825 | } else if (schedule_scan_stop) { |
12826 | sched_scan_req->owner_nlportid = 0; | |
12827 | ||
12828 | if (rdev->ops->sched_scan_stop && | |
12829 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
12830 | schedule_work(&rdev->sched_scan_stop_wk); | |
78f22b6a | 12831 | } |
5e760230 | 12832 | } |
026331c4 JM |
12833 | |
12834 | rcu_read_unlock(); | |
12835 | ||
05050753 I |
12836 | /* |
12837 | * It is possible that the user space process that is controlling the | |
12838 | * indoor setting disappeared, so notify the regulatory core. | |
12839 | */ | |
12840 | regulatory_netlink_notify(notify->portid); | |
6784c7db | 12841 | return NOTIFY_OK; |
026331c4 JM |
12842 | } |
12843 | ||
12844 | static struct notifier_block nl80211_netlink_notifier = { | |
12845 | .notifier_call = nl80211_netlink_notify, | |
12846 | }; | |
12847 | ||
355199e0 JM |
12848 | void cfg80211_ft_event(struct net_device *netdev, |
12849 | struct cfg80211_ft_event_params *ft_event) | |
12850 | { | |
12851 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 12852 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
12853 | struct sk_buff *msg; |
12854 | void *hdr; | |
355199e0 JM |
12855 | |
12856 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
12857 | ||
12858 | if (!ft_event->target_ap) | |
12859 | return; | |
12860 | ||
12861 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12862 | if (!msg) | |
12863 | return; | |
12864 | ||
12865 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
12866 | if (!hdr) |
12867 | goto out; | |
355199e0 | 12868 | |
ae917c9f JB |
12869 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12870 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12871 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
12872 | goto out; | |
355199e0 | 12873 | |
ae917c9f JB |
12874 | if (ft_event->ies && |
12875 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
12876 | goto out; | |
12877 | if (ft_event->ric_ies && | |
12878 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
12879 | ft_event->ric_ies)) | |
12880 | goto out; | |
355199e0 | 12881 | |
9c90a9f6 | 12882 | genlmsg_end(msg, hdr); |
355199e0 | 12883 | |
68eb5503 | 12884 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12885 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
12886 | return; |
12887 | out: | |
12888 | nlmsg_free(msg); | |
355199e0 JM |
12889 | } |
12890 | EXPORT_SYMBOL(cfg80211_ft_event); | |
12891 | ||
5de17984 AS |
12892 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
12893 | { | |
12894 | struct cfg80211_registered_device *rdev; | |
12895 | struct sk_buff *msg; | |
12896 | void *hdr; | |
12897 | u32 nlportid; | |
12898 | ||
f26cbf40 | 12899 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
12900 | if (!rdev->crit_proto_nlportid) |
12901 | return; | |
12902 | ||
12903 | nlportid = rdev->crit_proto_nlportid; | |
12904 | rdev->crit_proto_nlportid = 0; | |
12905 | ||
12906 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12907 | if (!msg) | |
12908 | return; | |
12909 | ||
12910 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
12911 | if (!hdr) | |
12912 | goto nla_put_failure; | |
12913 | ||
12914 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12915 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12916 | goto nla_put_failure; | |
12917 | ||
12918 | genlmsg_end(msg, hdr); | |
12919 | ||
12920 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
12921 | return; | |
12922 | ||
12923 | nla_put_failure: | |
12924 | if (hdr) | |
12925 | genlmsg_cancel(msg, hdr); | |
12926 | nlmsg_free(msg); | |
12927 | ||
12928 | } | |
12929 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
12930 | ||
348baf0e JB |
12931 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
12932 | { | |
12933 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12934 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
12935 | struct sk_buff *msg; |
12936 | void *hdr; | |
12937 | ||
12938 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12939 | if (!msg) | |
12940 | return; | |
12941 | ||
12942 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
12943 | if (!hdr) | |
12944 | goto out; | |
12945 | ||
12946 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12947 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
12948 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12949 | goto out; | |
12950 | ||
12951 | genlmsg_end(msg, hdr); | |
12952 | ||
12953 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
12954 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
12955 | return; | |
12956 | out: | |
12957 | nlmsg_free(msg); | |
12958 | } | |
12959 | ||
55682965 JB |
12960 | /* initialisation/exit functions */ |
12961 | ||
12962 | int nl80211_init(void) | |
12963 | { | |
0d63cbb5 | 12964 | int err; |
55682965 | 12965 | |
2a94fe48 JB |
12966 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
12967 | nl80211_mcgrps); | |
55682965 JB |
12968 | if (err) |
12969 | return err; | |
12970 | ||
026331c4 JM |
12971 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
12972 | if (err) | |
12973 | goto err_out; | |
12974 | ||
55682965 JB |
12975 | return 0; |
12976 | err_out: | |
12977 | genl_unregister_family(&nl80211_fam); | |
12978 | return err; | |
12979 | } | |
12980 | ||
12981 | void nl80211_exit(void) | |
12982 | { | |
026331c4 | 12983 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
12984 | genl_unregister_family(&nl80211_fam); |
12985 | } |