]>
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 }, |
55682965 JB |
401 | }; |
402 | ||
e31b8213 | 403 | /* policy for the key attributes */ |
b54452b0 | 404 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 405 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
406 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
407 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 408 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
409 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
410 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 411 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
412 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
413 | }; | |
414 | ||
415 | /* policy for the key default flags */ | |
416 | static const struct nla_policy | |
417 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
418 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
419 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
420 | }; |
421 | ||
ff1b6e69 JB |
422 | /* policy for WoWLAN attributes */ |
423 | static const struct nla_policy | |
424 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
425 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
426 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
427 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
428 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
429 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
430 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
431 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
432 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e | 433 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
8cd4d456 | 434 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
2a0e047e JB |
435 | }; |
436 | ||
437 | static const struct nla_policy | |
438 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
439 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
440 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
441 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
442 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
443 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
444 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
445 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
446 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
447 | }, | |
448 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
449 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
450 | }, | |
451 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
452 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
453 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
454 | }; |
455 | ||
be29b99a AK |
456 | /* policy for coalesce rule attributes */ |
457 | static const struct nla_policy | |
458 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
459 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
460 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
461 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
462 | }; | |
463 | ||
e5497d76 JB |
464 | /* policy for GTK rekey offload attributes */ |
465 | static const struct nla_policy | |
466 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
467 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
468 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
469 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
470 | }; | |
471 | ||
a1f1c21c LC |
472 | static const struct nla_policy |
473 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 474 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 475 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 476 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
477 | }; |
478 | ||
97990a06 JB |
479 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
480 | struct netlink_callback *cb, | |
481 | struct cfg80211_registered_device **rdev, | |
482 | struct wireless_dev **wdev) | |
a043897a | 483 | { |
97990a06 | 484 | int err; |
a043897a | 485 | |
97990a06 | 486 | rtnl_lock(); |
a043897a | 487 | |
97990a06 JB |
488 | if (!cb->args[0]) { |
489 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
490 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
491 | nl80211_policy); | |
492 | if (err) | |
493 | goto out_unlock; | |
67748893 | 494 | |
97990a06 JB |
495 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
496 | nl80211_fam.attrbuf); | |
497 | if (IS_ERR(*wdev)) { | |
498 | err = PTR_ERR(*wdev); | |
499 | goto out_unlock; | |
500 | } | |
f26cbf40 | 501 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
502 | /* 0 is the first index - add 1 to parse only once */ |
503 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
504 | cb->args[1] = (*wdev)->identifier; |
505 | } else { | |
c319d50b JB |
506 | /* subtract the 1 again here */ |
507 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 508 | struct wireless_dev *tmp; |
67748893 | 509 | |
97990a06 JB |
510 | if (!wiphy) { |
511 | err = -ENODEV; | |
512 | goto out_unlock; | |
513 | } | |
f26cbf40 | 514 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 515 | *wdev = NULL; |
67748893 | 516 | |
97990a06 JB |
517 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
518 | if (tmp->identifier == cb->args[1]) { | |
519 | *wdev = tmp; | |
520 | break; | |
521 | } | |
522 | } | |
67748893 | 523 | |
97990a06 JB |
524 | if (!*wdev) { |
525 | err = -ENODEV; | |
526 | goto out_unlock; | |
527 | } | |
67748893 JB |
528 | } |
529 | ||
67748893 | 530 | return 0; |
97990a06 | 531 | out_unlock: |
67748893 JB |
532 | rtnl_unlock(); |
533 | return err; | |
534 | } | |
535 | ||
97990a06 | 536 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 537 | { |
67748893 JB |
538 | rtnl_unlock(); |
539 | } | |
540 | ||
f4a11bb0 JB |
541 | /* IE validation */ |
542 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
543 | { | |
544 | const u8 *pos; | |
545 | int len; | |
546 | ||
547 | if (!attr) | |
548 | return true; | |
549 | ||
550 | pos = nla_data(attr); | |
551 | len = nla_len(attr); | |
552 | ||
553 | while (len) { | |
554 | u8 elemlen; | |
555 | ||
556 | if (len < 2) | |
557 | return false; | |
558 | len -= 2; | |
559 | ||
560 | elemlen = pos[1]; | |
561 | if (elemlen > len) | |
562 | return false; | |
563 | ||
564 | len -= elemlen; | |
565 | pos += 2 + elemlen; | |
566 | } | |
567 | ||
568 | return true; | |
569 | } | |
570 | ||
55682965 | 571 | /* message building helper */ |
15e47304 | 572 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
573 | int flags, u8 cmd) |
574 | { | |
575 | /* since there is no private header just add the generic one */ | |
15e47304 | 576 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
577 | } |
578 | ||
5dab3b8a | 579 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
580 | struct ieee80211_channel *chan, |
581 | bool large) | |
5dab3b8a | 582 | { |
ea077c1c RL |
583 | /* Some channels must be completely excluded from the |
584 | * list to protect old user-space tools from breaking | |
585 | */ | |
586 | if (!large && chan->flags & | |
587 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
588 | return 0; | |
589 | ||
9360ffd1 DM |
590 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
591 | chan->center_freq)) | |
592 | goto nla_put_failure; | |
5dab3b8a | 593 | |
9360ffd1 DM |
594 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
595 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
596 | goto nla_put_failure; | |
8fe02e16 LR |
597 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
598 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
599 | goto nla_put_failure; | |
600 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
601 | goto nla_put_failure; | |
602 | } | |
cdc89b97 JB |
603 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
604 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
605 | goto nla_put_failure; | |
606 | if (large) { | |
607 | u32 time; | |
608 | ||
609 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
610 | ||
611 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
612 | chan->dfs_state)) | |
613 | goto nla_put_failure; | |
614 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
615 | time)) | |
616 | goto nla_put_failure; | |
089027e5 JD |
617 | if (nla_put_u32(msg, |
618 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
619 | chan->dfs_cac_ms)) | |
620 | goto nla_put_failure; | |
cdc89b97 JB |
621 | } |
622 | } | |
5dab3b8a | 623 | |
fe1abafd JB |
624 | if (large) { |
625 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
626 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
627 | goto nla_put_failure; | |
628 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
629 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
630 | goto nla_put_failure; | |
631 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
632 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
633 | goto nla_put_failure; | |
634 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
635 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
636 | goto nla_put_failure; | |
570dbde1 DS |
637 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
638 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
639 | goto nla_put_failure; | |
640 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && | |
641 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) | |
642 | goto nla_put_failure; | |
ea077c1c RL |
643 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
644 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
645 | goto nla_put_failure; | |
646 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
647 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
648 | goto nla_put_failure; | |
fe1abafd JB |
649 | } |
650 | ||
9360ffd1 DM |
651 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
652 | DBM_TO_MBM(chan->max_power))) | |
653 | goto nla_put_failure; | |
5dab3b8a LR |
654 | |
655 | return 0; | |
656 | ||
657 | nla_put_failure: | |
658 | return -ENOBUFS; | |
659 | } | |
660 | ||
55682965 JB |
661 | /* netlink command implementations */ |
662 | ||
b9454e83 JB |
663 | struct key_parse { |
664 | struct key_params p; | |
665 | int idx; | |
e31b8213 | 666 | int type; |
b9454e83 | 667 | bool def, defmgmt; |
dbd2fd65 | 668 | bool def_uni, def_multi; |
b9454e83 JB |
669 | }; |
670 | ||
671 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
672 | { | |
673 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
674 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
675 | nl80211_key_policy); | |
676 | if (err) | |
677 | return err; | |
678 | ||
679 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
680 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
681 | ||
dbd2fd65 JB |
682 | if (k->def) { |
683 | k->def_uni = true; | |
684 | k->def_multi = true; | |
685 | } | |
686 | if (k->defmgmt) | |
687 | k->def_multi = true; | |
688 | ||
b9454e83 JB |
689 | if (tb[NL80211_KEY_IDX]) |
690 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
691 | ||
692 | if (tb[NL80211_KEY_DATA]) { | |
693 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
694 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
695 | } | |
696 | ||
697 | if (tb[NL80211_KEY_SEQ]) { | |
698 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
699 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
700 | } | |
701 | ||
702 | if (tb[NL80211_KEY_CIPHER]) | |
703 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
704 | ||
e31b8213 JB |
705 | if (tb[NL80211_KEY_TYPE]) { |
706 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
707 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
708 | return -EINVAL; | |
709 | } | |
710 | ||
dbd2fd65 JB |
711 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
712 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
713 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
714 | tb[NL80211_KEY_DEFAULT_TYPES], | |
715 | nl80211_key_default_policy); | |
dbd2fd65 JB |
716 | if (err) |
717 | return err; | |
718 | ||
719 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
720 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
721 | } | |
722 | ||
b9454e83 JB |
723 | return 0; |
724 | } | |
725 | ||
726 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
727 | { | |
728 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
729 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
730 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
731 | } | |
732 | ||
733 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
734 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
735 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
736 | } | |
737 | ||
738 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
739 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
740 | ||
741 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
742 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
743 | ||
744 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
745 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
746 | ||
dbd2fd65 JB |
747 | if (k->def) { |
748 | k->def_uni = true; | |
749 | k->def_multi = true; | |
750 | } | |
751 | if (k->defmgmt) | |
752 | k->def_multi = true; | |
753 | ||
e31b8213 JB |
754 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
755 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
756 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
757 | return -EINVAL; | |
758 | } | |
759 | ||
dbd2fd65 JB |
760 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
761 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
762 | int err = nla_parse_nested( | |
763 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
764 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
765 | nl80211_key_default_policy); | |
766 | if (err) | |
767 | return err; | |
768 | ||
769 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
770 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
771 | } | |
772 | ||
b9454e83 JB |
773 | return 0; |
774 | } | |
775 | ||
776 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
777 | { | |
778 | int err; | |
779 | ||
780 | memset(k, 0, sizeof(*k)); | |
781 | k->idx = -1; | |
e31b8213 | 782 | k->type = -1; |
b9454e83 JB |
783 | |
784 | if (info->attrs[NL80211_ATTR_KEY]) | |
785 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
786 | else | |
787 | err = nl80211_parse_key_old(info, k); | |
788 | ||
789 | if (err) | |
790 | return err; | |
791 | ||
792 | if (k->def && k->defmgmt) | |
793 | return -EINVAL; | |
794 | ||
dbd2fd65 JB |
795 | if (k->defmgmt) { |
796 | if (k->def_uni || !k->def_multi) | |
797 | return -EINVAL; | |
798 | } | |
799 | ||
b9454e83 JB |
800 | if (k->idx != -1) { |
801 | if (k->defmgmt) { | |
802 | if (k->idx < 4 || k->idx > 5) | |
803 | return -EINVAL; | |
804 | } else if (k->def) { | |
805 | if (k->idx < 0 || k->idx > 3) | |
806 | return -EINVAL; | |
807 | } else { | |
808 | if (k->idx < 0 || k->idx > 5) | |
809 | return -EINVAL; | |
810 | } | |
811 | } | |
812 | ||
813 | return 0; | |
814 | } | |
815 | ||
fffd0934 JB |
816 | static struct cfg80211_cached_keys * |
817 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 818 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
819 | { |
820 | struct key_parse parse; | |
821 | struct nlattr *key; | |
822 | struct cfg80211_cached_keys *result; | |
823 | int rem, err, def = 0; | |
824 | ||
825 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
826 | if (!result) | |
827 | return ERR_PTR(-ENOMEM); | |
828 | ||
829 | result->def = -1; | |
830 | result->defmgmt = -1; | |
831 | ||
832 | nla_for_each_nested(key, keys, rem) { | |
833 | memset(&parse, 0, sizeof(parse)); | |
834 | parse.idx = -1; | |
835 | ||
836 | err = nl80211_parse_key_new(key, &parse); | |
837 | if (err) | |
838 | goto error; | |
839 | err = -EINVAL; | |
840 | if (!parse.p.key) | |
841 | goto error; | |
842 | if (parse.idx < 0 || parse.idx > 4) | |
843 | goto error; | |
844 | if (parse.def) { | |
845 | if (def) | |
846 | goto error; | |
847 | def = 1; | |
848 | result->def = parse.idx; | |
dbd2fd65 JB |
849 | if (!parse.def_uni || !parse.def_multi) |
850 | goto error; | |
fffd0934 JB |
851 | } else if (parse.defmgmt) |
852 | goto error; | |
853 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 854 | parse.idx, false, NULL); |
fffd0934 JB |
855 | if (err) |
856 | goto error; | |
857 | result->params[parse.idx].cipher = parse.p.cipher; | |
858 | result->params[parse.idx].key_len = parse.p.key_len; | |
859 | result->params[parse.idx].key = result->data[parse.idx]; | |
860 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
861 | |
862 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
863 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
864 | if (no_ht) | |
865 | *no_ht = true; | |
866 | } | |
fffd0934 JB |
867 | } |
868 | ||
869 | return result; | |
870 | error: | |
871 | kfree(result); | |
872 | return ERR_PTR(err); | |
873 | } | |
874 | ||
875 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
876 | { | |
877 | ASSERT_WDEV_LOCK(wdev); | |
878 | ||
fffd0934 JB |
879 | switch (wdev->iftype) { |
880 | case NL80211_IFTYPE_AP: | |
881 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 882 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 883 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
884 | break; |
885 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 886 | case NL80211_IFTYPE_STATION: |
074ac8df | 887 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 888 | if (!wdev->current_bss) |
fffd0934 JB |
889 | return -ENOLINK; |
890 | break; | |
de4fcbad | 891 | case NL80211_IFTYPE_UNSPECIFIED: |
6e0bd6c3 | 892 | case NL80211_IFTYPE_OCB: |
de4fcbad JB |
893 | case NL80211_IFTYPE_MONITOR: |
894 | case NL80211_IFTYPE_P2P_DEVICE: | |
895 | case NL80211_IFTYPE_WDS: | |
896 | case NUM_NL80211_IFTYPES: | |
fffd0934 JB |
897 | return -EINVAL; |
898 | } | |
899 | ||
900 | return 0; | |
901 | } | |
902 | ||
664834de JM |
903 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
904 | struct nlattr *tb) | |
905 | { | |
906 | struct ieee80211_channel *chan; | |
907 | ||
908 | if (tb == NULL) | |
909 | return NULL; | |
910 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
911 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
912 | return NULL; | |
913 | return chan; | |
914 | } | |
915 | ||
7527a782 JB |
916 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
917 | { | |
918 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
919 | int i; | |
920 | ||
921 | if (!nl_modes) | |
922 | goto nla_put_failure; | |
923 | ||
924 | i = 0; | |
925 | while (ifmodes) { | |
9360ffd1 DM |
926 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
927 | goto nla_put_failure; | |
7527a782 JB |
928 | ifmodes >>= 1; |
929 | i++; | |
930 | } | |
931 | ||
932 | nla_nest_end(msg, nl_modes); | |
933 | return 0; | |
934 | ||
935 | nla_put_failure: | |
936 | return -ENOBUFS; | |
937 | } | |
938 | ||
939 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
940 | struct sk_buff *msg, |
941 | bool large) | |
7527a782 JB |
942 | { |
943 | struct nlattr *nl_combis; | |
944 | int i, j; | |
945 | ||
946 | nl_combis = nla_nest_start(msg, | |
947 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
948 | if (!nl_combis) | |
949 | goto nla_put_failure; | |
950 | ||
951 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
952 | const struct ieee80211_iface_combination *c; | |
953 | struct nlattr *nl_combi, *nl_limits; | |
954 | ||
955 | c = &wiphy->iface_combinations[i]; | |
956 | ||
957 | nl_combi = nla_nest_start(msg, i + 1); | |
958 | if (!nl_combi) | |
959 | goto nla_put_failure; | |
960 | ||
961 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
962 | if (!nl_limits) | |
963 | goto nla_put_failure; | |
964 | ||
965 | for (j = 0; j < c->n_limits; j++) { | |
966 | struct nlattr *nl_limit; | |
967 | ||
968 | nl_limit = nla_nest_start(msg, j + 1); | |
969 | if (!nl_limit) | |
970 | goto nla_put_failure; | |
9360ffd1 DM |
971 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
972 | c->limits[j].max)) | |
973 | goto nla_put_failure; | |
7527a782 JB |
974 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
975 | c->limits[j].types)) | |
976 | goto nla_put_failure; | |
977 | nla_nest_end(msg, nl_limit); | |
978 | } | |
979 | ||
980 | nla_nest_end(msg, nl_limits); | |
981 | ||
9360ffd1 DM |
982 | if (c->beacon_int_infra_match && |
983 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
984 | goto nla_put_failure; | |
985 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
986 | c->num_different_channels) || | |
987 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
988 | c->max_interfaces)) | |
989 | goto nla_put_failure; | |
cdc89b97 | 990 | if (large && |
8c48b50a FF |
991 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
992 | c->radar_detect_widths) || | |
993 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
994 | c->radar_detect_regions))) | |
cdc89b97 | 995 | goto nla_put_failure; |
7527a782 JB |
996 | |
997 | nla_nest_end(msg, nl_combi); | |
998 | } | |
999 | ||
1000 | nla_nest_end(msg, nl_combis); | |
1001 | ||
1002 | return 0; | |
1003 | nla_put_failure: | |
1004 | return -ENOBUFS; | |
1005 | } | |
1006 | ||
3713b4e3 | 1007 | #ifdef CONFIG_PM |
b56cf720 JB |
1008 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
1009 | struct sk_buff *msg) | |
1010 | { | |
964dc9e2 | 1011 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
1012 | struct nlattr *nl_tcp; |
1013 | ||
1014 | if (!tcp) | |
1015 | return 0; | |
1016 | ||
1017 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
1018 | if (!nl_tcp) | |
1019 | return -ENOBUFS; | |
1020 | ||
1021 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1022 | tcp->data_payload_max)) | |
1023 | return -ENOBUFS; | |
1024 | ||
1025 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1026 | tcp->data_payload_max)) | |
1027 | return -ENOBUFS; | |
1028 | ||
1029 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1030 | return -ENOBUFS; | |
1031 | ||
1032 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1033 | sizeof(*tcp->tok), tcp->tok)) | |
1034 | return -ENOBUFS; | |
1035 | ||
1036 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1037 | tcp->data_interval_max)) | |
1038 | return -ENOBUFS; | |
1039 | ||
1040 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1041 | tcp->wake_payload_max)) | |
1042 | return -ENOBUFS; | |
1043 | ||
1044 | nla_nest_end(msg, nl_tcp); | |
1045 | return 0; | |
1046 | } | |
1047 | ||
3713b4e3 | 1048 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1049 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1050 | bool large) |
55682965 | 1051 | { |
3713b4e3 | 1052 | struct nlattr *nl_wowlan; |
55682965 | 1053 | |
1b8ec87a | 1054 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1055 | return 0; |
55682965 | 1056 | |
3713b4e3 JB |
1057 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1058 | if (!nl_wowlan) | |
1059 | return -ENOBUFS; | |
9360ffd1 | 1060 | |
1b8ec87a | 1061 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1062 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1063 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1064 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1065 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1066 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1067 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1068 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1069 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1070 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1071 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1072 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1073 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1074 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1075 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1076 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1077 | return -ENOBUFS; | |
9360ffd1 | 1078 | |
1b8ec87a | 1079 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1080 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1081 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1082 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1083 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1084 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1085 | }; |
9360ffd1 | 1086 | |
3713b4e3 JB |
1087 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1088 | sizeof(pat), &pat)) | |
1089 | return -ENOBUFS; | |
1090 | } | |
9360ffd1 | 1091 | |
75453ccb LC |
1092 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
1093 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, | |
1094 | rdev->wiphy.wowlan->max_nd_match_sets)) | |
1095 | return -ENOBUFS; | |
1096 | ||
1b8ec87a | 1097 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1098 | return -ENOBUFS; |
1099 | ||
8cd4d456 LC |
1100 | /* TODO: send wowlan net detect */ |
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: |
55682965 JB |
1725 | return genlmsg_end(msg, hdr); |
1726 | ||
1727 | nla_put_failure: | |
bc3ed28c TG |
1728 | genlmsg_cancel(msg, hdr); |
1729 | return -EMSGSIZE; | |
55682965 JB |
1730 | } |
1731 | ||
86e8cf98 JB |
1732 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1733 | struct netlink_callback *cb, | |
1734 | struct nl80211_dump_wiphy_state *state) | |
1735 | { | |
1736 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1737 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1738 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1739 | /* ignore parse errors for backward compatibility */ | |
1740 | if (ret) | |
1741 | return 0; | |
1742 | ||
1743 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1744 | if (tb[NL80211_ATTR_WIPHY]) | |
1745 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1746 | if (tb[NL80211_ATTR_WDEV]) | |
1747 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1748 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1749 | struct net_device *netdev; | |
1750 | struct cfg80211_registered_device *rdev; | |
1751 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1752 | ||
7f2b8562 | 1753 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1754 | if (!netdev) |
1755 | return -ENODEV; | |
1756 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1757 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1758 | netdev->ieee80211_ptr->wiphy); |
1759 | state->filter_wiphy = rdev->wiphy_idx; | |
1760 | } | |
86e8cf98 JB |
1761 | } |
1762 | ||
1763 | return 0; | |
1764 | } | |
1765 | ||
55682965 JB |
1766 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1767 | { | |
645e77de | 1768 | int idx = 0, ret; |
86e8cf98 | 1769 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1770 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1771 | |
5fe231e8 | 1772 | rtnl_lock(); |
86e8cf98 JB |
1773 | if (!state) { |
1774 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1775 | if (!state) { |
1776 | rtnl_unlock(); | |
86e8cf98 | 1777 | return -ENOMEM; |
3713b4e3 | 1778 | } |
86e8cf98 JB |
1779 | state->filter_wiphy = -1; |
1780 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1781 | if (ret) { | |
1782 | kfree(state); | |
1783 | rtnl_unlock(); | |
1784 | return ret; | |
3713b4e3 | 1785 | } |
86e8cf98 | 1786 | cb->args[0] = (long)state; |
3713b4e3 JB |
1787 | } |
1788 | ||
1b8ec87a ZG |
1789 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1790 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1791 | continue; |
86e8cf98 | 1792 | if (++idx <= state->start) |
55682965 | 1793 | continue; |
86e8cf98 | 1794 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1795 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1796 | continue; |
1797 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1798 | do { | |
3bb20556 JB |
1799 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
1800 | skb, | |
3713b4e3 JB |
1801 | NETLINK_CB(cb->skb).portid, |
1802 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1803 | NLM_F_MULTI, state); |
3713b4e3 JB |
1804 | if (ret < 0) { |
1805 | /* | |
1806 | * If sending the wiphy data didn't fit (ENOBUFS | |
1807 | * or EMSGSIZE returned), this SKB is still | |
1808 | * empty (so it's not too big because another | |
1809 | * wiphy dataset is already in the skb) and | |
1810 | * we've not tried to adjust the dump allocation | |
1811 | * yet ... then adjust the alloc size to be | |
1812 | * bigger, and return 1 but with the empty skb. | |
1813 | * This results in an empty message being RX'ed | |
1814 | * in userspace, but that is ignored. | |
1815 | * | |
1816 | * We can then retry with the larger buffer. | |
1817 | */ | |
1818 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1819 | !skb->len && !state->split && |
3713b4e3 JB |
1820 | cb->min_dump_alloc < 4096) { |
1821 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1822 | state->split_start = 0; |
d98cae64 | 1823 | rtnl_unlock(); |
3713b4e3 JB |
1824 | return 1; |
1825 | } | |
1826 | idx--; | |
1827 | break; | |
645e77de | 1828 | } |
86e8cf98 | 1829 | } while (state->split_start > 0); |
3713b4e3 | 1830 | break; |
55682965 | 1831 | } |
5fe231e8 | 1832 | rtnl_unlock(); |
55682965 | 1833 | |
86e8cf98 | 1834 | state->start = idx; |
55682965 JB |
1835 | |
1836 | return skb->len; | |
1837 | } | |
1838 | ||
86e8cf98 JB |
1839 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1840 | { | |
1841 | kfree((void *)cb->args[0]); | |
1842 | return 0; | |
1843 | } | |
1844 | ||
55682965 JB |
1845 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1846 | { | |
1847 | struct sk_buff *msg; | |
1b8ec87a | 1848 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 1849 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1850 | |
645e77de | 1851 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1852 | if (!msg) |
4c476991 | 1853 | return -ENOMEM; |
55682965 | 1854 | |
3bb20556 JB |
1855 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
1856 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 1857 | &state) < 0) { |
4c476991 JB |
1858 | nlmsg_free(msg); |
1859 | return -ENOBUFS; | |
1860 | } | |
55682965 | 1861 | |
134e6375 | 1862 | return genlmsg_reply(msg, info); |
55682965 JB |
1863 | } |
1864 | ||
31888487 JM |
1865 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1866 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1867 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1868 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1869 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1870 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1871 | }; | |
1872 | ||
1873 | static int parse_txq_params(struct nlattr *tb[], | |
1874 | struct ieee80211_txq_params *txq_params) | |
1875 | { | |
a3304b0a | 1876 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1877 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1878 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1879 | return -EINVAL; | |
1880 | ||
a3304b0a | 1881 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1882 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1883 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1884 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1885 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1886 | ||
a3304b0a JB |
1887 | if (txq_params->ac >= NL80211_NUM_ACS) |
1888 | return -EINVAL; | |
1889 | ||
31888487 JM |
1890 | return 0; |
1891 | } | |
1892 | ||
f444de05 JB |
1893 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1894 | { | |
1895 | /* | |
cc1d2806 JB |
1896 | * You can only set the channel explicitly for WDS interfaces, |
1897 | * all others have their channel managed via their respective | |
1898 | * "establish a connection" command (connect, join, ...) | |
1899 | * | |
1900 | * For AP/GO and mesh mode, the channel can be set with the | |
1901 | * channel userspace API, but is only stored and passed to the | |
1902 | * low-level driver when the AP starts or the mesh is joined. | |
1903 | * This is for backward compatibility, userspace can also give | |
1904 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1905 | * |
1906 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1907 | * whatever else is going on, so they have their own special |
1908 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1909 | */ |
1910 | return !wdev || | |
1911 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1912 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1913 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1914 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1915 | } |
1916 | ||
683b6d3b JB |
1917 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1918 | struct genl_info *info, | |
1919 | struct cfg80211_chan_def *chandef) | |
1920 | { | |
dbeca2ea | 1921 | u32 control_freq; |
683b6d3b JB |
1922 | |
1923 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1924 | return -EINVAL; | |
1925 | ||
1926 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1927 | ||
1928 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1929 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1930 | chandef->center_freq1 = control_freq; | |
1931 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1932 | |
1933 | /* Primary channel not allowed */ | |
1934 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1935 | return -EINVAL; | |
1936 | ||
3d9d1d66 JB |
1937 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1938 | enum nl80211_channel_type chantype; | |
1939 | ||
1940 | chantype = nla_get_u32( | |
1941 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1942 | ||
1943 | switch (chantype) { | |
1944 | case NL80211_CHAN_NO_HT: | |
1945 | case NL80211_CHAN_HT20: | |
1946 | case NL80211_CHAN_HT40PLUS: | |
1947 | case NL80211_CHAN_HT40MINUS: | |
1948 | cfg80211_chandef_create(chandef, chandef->chan, | |
1949 | chantype); | |
1950 | break; | |
1951 | default: | |
1952 | return -EINVAL; | |
1953 | } | |
1954 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1955 | chandef->width = | |
1956 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1957 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1958 | chandef->center_freq1 = | |
1959 | nla_get_u32( | |
1960 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1961 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1962 | chandef->center_freq2 = | |
1963 | nla_get_u32( | |
1964 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1965 | } | |
1966 | ||
9f5e8f6e | 1967 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1968 | return -EINVAL; |
1969 | ||
9f5e8f6e JB |
1970 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1971 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1972 | return -EINVAL; |
1973 | ||
2f301ab2 SW |
1974 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1975 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1976 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1977 | return -EINVAL; | |
1978 | ||
683b6d3b JB |
1979 | return 0; |
1980 | } | |
1981 | ||
f444de05 | 1982 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 1983 | struct net_device *dev, |
f444de05 JB |
1984 | struct genl_info *info) |
1985 | { | |
683b6d3b | 1986 | struct cfg80211_chan_def chandef; |
f444de05 | 1987 | int result; |
e8c9bd5b | 1988 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 1989 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 1990 | |
e16821bc JM |
1991 | if (dev) |
1992 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
1993 | if (!nl80211_can_set_dev_channel(wdev)) |
1994 | return -EOPNOTSUPP; | |
e16821bc JM |
1995 | if (wdev) |
1996 | iftype = wdev->iftype; | |
f444de05 | 1997 | |
683b6d3b JB |
1998 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1999 | if (result) | |
2000 | return result; | |
f444de05 | 2001 | |
e8c9bd5b | 2002 | switch (iftype) { |
aa430da4 JB |
2003 | case NL80211_IFTYPE_AP: |
2004 | case NL80211_IFTYPE_P2P_GO: | |
174e0cd2 | 2005 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
aa430da4 JB |
2006 | result = -EINVAL; |
2007 | break; | |
2008 | } | |
e16821bc JM |
2009 | if (wdev->beacon_interval) { |
2010 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
2011 | !(rdev->wiphy.features & | |
2012 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
2013 | result = -EBUSY; | |
2014 | break; | |
2015 | } | |
2016 | ||
2017 | /* Only allow dynamic channel width changes */ | |
2018 | if (chandef.chan != wdev->preset_chandef.chan) { | |
2019 | result = -EBUSY; | |
2020 | break; | |
2021 | } | |
2022 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
2023 | if (result) | |
2024 | break; | |
2025 | } | |
683b6d3b | 2026 | wdev->preset_chandef = chandef; |
aa430da4 JB |
2027 | result = 0; |
2028 | break; | |
cc1d2806 | 2029 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 2030 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 2031 | break; |
e8c9bd5b | 2032 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 2033 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 2034 | break; |
aa430da4 | 2035 | default: |
e8c9bd5b | 2036 | result = -EINVAL; |
f444de05 | 2037 | } |
f444de05 JB |
2038 | |
2039 | return result; | |
2040 | } | |
2041 | ||
2042 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2043 | { | |
4c476991 JB |
2044 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2045 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2046 | |
e16821bc | 2047 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2048 | } |
2049 | ||
e8347eba BJ |
2050 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2051 | { | |
43b19952 JB |
2052 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2053 | struct net_device *dev = info->user_ptr[1]; | |
2054 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2055 | const u8 *bssid; |
e8347eba BJ |
2056 | |
2057 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2058 | return -EINVAL; | |
2059 | ||
43b19952 JB |
2060 | if (netif_running(dev)) |
2061 | return -EBUSY; | |
e8347eba | 2062 | |
43b19952 JB |
2063 | if (!rdev->ops->set_wds_peer) |
2064 | return -EOPNOTSUPP; | |
e8347eba | 2065 | |
43b19952 JB |
2066 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2067 | return -EOPNOTSUPP; | |
e8347eba BJ |
2068 | |
2069 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2070 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2071 | } |
2072 | ||
2073 | ||
55682965 JB |
2074 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2075 | { | |
2076 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2077 | struct net_device *netdev = NULL; |
2078 | struct wireless_dev *wdev; | |
a1e567c8 | 2079 | int result = 0, rem_txq_params = 0; |
31888487 | 2080 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2081 | u32 changed; |
2082 | u8 retry_short = 0, retry_long = 0; | |
2083 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2084 | u8 coverage_class = 0; |
55682965 | 2085 | |
5fe231e8 JB |
2086 | ASSERT_RTNL(); |
2087 | ||
f444de05 JB |
2088 | /* |
2089 | * Try to find the wiphy and netdev. Normally this | |
2090 | * function shouldn't need the netdev, but this is | |
2091 | * done for backward compatibility -- previously | |
2092 | * setting the channel was done per wiphy, but now | |
2093 | * it is per netdev. Previous userland like hostapd | |
2094 | * also passed a netdev to set_wiphy, so that it is | |
2095 | * possible to let that go to the right netdev! | |
2096 | */ | |
4bbf4d56 | 2097 | |
f444de05 JB |
2098 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2099 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2100 | ||
7f2b8562 | 2101 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2102 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2103 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2104 | else |
f444de05 | 2105 | netdev = NULL; |
4bbf4d56 JB |
2106 | } |
2107 | ||
f444de05 | 2108 | if (!netdev) { |
878d9ec7 JB |
2109 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2110 | info->attrs); | |
5fe231e8 | 2111 | if (IS_ERR(rdev)) |
4c476991 | 2112 | return PTR_ERR(rdev); |
f444de05 JB |
2113 | wdev = NULL; |
2114 | netdev = NULL; | |
2115 | result = 0; | |
71fe96bf | 2116 | } else |
f444de05 | 2117 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2118 | |
2119 | /* | |
2120 | * end workaround code, by now the rdev is available | |
2121 | * and locked, and wdev may or may not be NULL. | |
2122 | */ | |
4bbf4d56 JB |
2123 | |
2124 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2125 | result = cfg80211_dev_rename( |
2126 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2127 | |
4bbf4d56 | 2128 | if (result) |
7f2b8562 | 2129 | return result; |
31888487 JM |
2130 | |
2131 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2132 | struct ieee80211_txq_params txq_params; | |
2133 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2134 | ||
7f2b8562 YX |
2135 | if (!rdev->ops->set_txq_params) |
2136 | return -EOPNOTSUPP; | |
31888487 | 2137 | |
7f2b8562 YX |
2138 | if (!netdev) |
2139 | return -EINVAL; | |
f70f01c2 | 2140 | |
133a3ff2 | 2141 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2142 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2143 | return -EINVAL; | |
133a3ff2 | 2144 | |
7f2b8562 YX |
2145 | if (!netif_running(netdev)) |
2146 | return -ENETDOWN; | |
2b5f8b0b | 2147 | |
31888487 JM |
2148 | nla_for_each_nested(nl_txq_params, |
2149 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2150 | rem_txq_params) { | |
ae811e21 JB |
2151 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2152 | nla_data(nl_txq_params), | |
2153 | nla_len(nl_txq_params), | |
2154 | txq_params_policy); | |
2155 | if (result) | |
2156 | return result; | |
31888487 JM |
2157 | result = parse_txq_params(tb, &txq_params); |
2158 | if (result) | |
7f2b8562 | 2159 | return result; |
31888487 | 2160 | |
e35e4d28 HG |
2161 | result = rdev_set_txq_params(rdev, netdev, |
2162 | &txq_params); | |
31888487 | 2163 | if (result) |
7f2b8562 | 2164 | return result; |
31888487 JM |
2165 | } |
2166 | } | |
55682965 | 2167 | |
72bdcf34 | 2168 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2169 | result = __nl80211_set_channel( |
2170 | rdev, | |
2171 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2172 | info); | |
72bdcf34 | 2173 | if (result) |
7f2b8562 | 2174 | return result; |
72bdcf34 JM |
2175 | } |
2176 | ||
98d2ff8b | 2177 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2178 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2179 | enum nl80211_tx_power_setting type; |
2180 | int idx, mbm = 0; | |
2181 | ||
c8442118 JB |
2182 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2183 | txp_wdev = NULL; | |
2184 | ||
7f2b8562 YX |
2185 | if (!rdev->ops->set_tx_power) |
2186 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2187 | |
2188 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2189 | type = nla_get_u32(info->attrs[idx]); | |
2190 | ||
2191 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2192 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2193 | return -EINVAL; | |
98d2ff8b JO |
2194 | |
2195 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2196 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2197 | mbm = nla_get_u32(info->attrs[idx]); | |
2198 | } | |
2199 | ||
c8442118 | 2200 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2201 | if (result) |
7f2b8562 | 2202 | return result; |
98d2ff8b JO |
2203 | } |
2204 | ||
afe0cbf8 BR |
2205 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2206 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2207 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2208 | if ((!rdev->wiphy.available_antennas_tx && |
2209 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2210 | !rdev->ops->set_antenna) |
2211 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2212 | |
2213 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2214 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2215 | ||
a7ffac95 | 2216 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2217 | * available antenna masks, except for the "all" mask */ |
2218 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2219 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2220 | return -EINVAL; | |
a7ffac95 | 2221 | |
7f531e03 BR |
2222 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2223 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2224 | |
e35e4d28 | 2225 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2226 | if (result) |
7f2b8562 | 2227 | return result; |
afe0cbf8 BR |
2228 | } |
2229 | ||
b9a5f8ca JM |
2230 | changed = 0; |
2231 | ||
2232 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2233 | retry_short = nla_get_u8( | |
2234 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2235 | if (retry_short == 0) |
2236 | return -EINVAL; | |
2237 | ||
b9a5f8ca JM |
2238 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2239 | } | |
2240 | ||
2241 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2242 | retry_long = nla_get_u8( | |
2243 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2244 | if (retry_long == 0) |
2245 | return -EINVAL; | |
2246 | ||
b9a5f8ca JM |
2247 | changed |= WIPHY_PARAM_RETRY_LONG; |
2248 | } | |
2249 | ||
2250 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2251 | frag_threshold = nla_get_u32( | |
2252 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2253 | if (frag_threshold < 256) |
2254 | return -EINVAL; | |
2255 | ||
b9a5f8ca JM |
2256 | if (frag_threshold != (u32) -1) { |
2257 | /* | |
2258 | * Fragments (apart from the last one) are required to | |
2259 | * have even length. Make the fragmentation code | |
2260 | * simpler by stripping LSB should someone try to use | |
2261 | * odd threshold value. | |
2262 | */ | |
2263 | frag_threshold &= ~0x1; | |
2264 | } | |
2265 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2266 | } | |
2267 | ||
2268 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2269 | rts_threshold = nla_get_u32( | |
2270 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2271 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2272 | } | |
2273 | ||
81077e82 | 2274 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
3057dbfd LB |
2275 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
2276 | return -EINVAL; | |
2277 | ||
81077e82 LT |
2278 | coverage_class = nla_get_u8( |
2279 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2280 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2281 | } | |
2282 | ||
3057dbfd LB |
2283 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
2284 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | |
2285 | return -EOPNOTSUPP; | |
2286 | ||
2287 | changed |= WIPHY_PARAM_DYN_ACK; | |
81077e82 LT |
2288 | } |
2289 | ||
b9a5f8ca JM |
2290 | if (changed) { |
2291 | u8 old_retry_short, old_retry_long; | |
2292 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2293 | u8 old_coverage_class; |
b9a5f8ca | 2294 | |
7f2b8562 YX |
2295 | if (!rdev->ops->set_wiphy_params) |
2296 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2297 | |
2298 | old_retry_short = rdev->wiphy.retry_short; | |
2299 | old_retry_long = rdev->wiphy.retry_long; | |
2300 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2301 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2302 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2303 | |
2304 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2305 | rdev->wiphy.retry_short = retry_short; | |
2306 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2307 | rdev->wiphy.retry_long = retry_long; | |
2308 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2309 | rdev->wiphy.frag_threshold = frag_threshold; | |
2310 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2311 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2312 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2313 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2314 | |
e35e4d28 | 2315 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2316 | if (result) { |
2317 | rdev->wiphy.retry_short = old_retry_short; | |
2318 | rdev->wiphy.retry_long = old_retry_long; | |
2319 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2320 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2321 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2322 | } |
2323 | } | |
7f2b8562 | 2324 | return 0; |
55682965 JB |
2325 | } |
2326 | ||
71bbc994 JB |
2327 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2328 | { | |
2329 | return (u64)wdev->identifier | | |
f26cbf40 | 2330 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2331 | } |
55682965 | 2332 | |
683b6d3b | 2333 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2334 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2335 | { |
601555cd JB |
2336 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
2337 | return -EINVAL; | |
3d9d1d66 | 2338 | |
683b6d3b JB |
2339 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2340 | chandef->chan->center_freq)) | |
2341 | return -ENOBUFS; | |
3d9d1d66 JB |
2342 | switch (chandef->width) { |
2343 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2344 | case NL80211_CHAN_WIDTH_20: | |
2345 | case NL80211_CHAN_WIDTH_40: | |
2346 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2347 | cfg80211_get_chandef_type(chandef))) | |
2348 | return -ENOBUFS; | |
2349 | break; | |
2350 | default: | |
2351 | break; | |
2352 | } | |
2353 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2354 | return -ENOBUFS; | |
2355 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2356 | return -ENOBUFS; | |
2357 | if (chandef->center_freq2 && | |
2358 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2359 | return -ENOBUFS; |
2360 | return 0; | |
2361 | } | |
2362 | ||
15e47304 | 2363 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2364 | struct cfg80211_registered_device *rdev, |
8f894be2 | 2365 | struct wireless_dev *wdev, bool removal) |
55682965 | 2366 | { |
72fb2abc | 2367 | struct net_device *dev = wdev->netdev; |
8f894be2 | 2368 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
55682965 JB |
2369 | void *hdr; |
2370 | ||
8f894be2 TB |
2371 | if (removal) |
2372 | cmd = NL80211_CMD_DEL_INTERFACE; | |
2373 | ||
2374 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | |
55682965 JB |
2375 | if (!hdr) |
2376 | return -1; | |
2377 | ||
72fb2abc JB |
2378 | if (dev && |
2379 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2380 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2381 | goto nla_put_failure; |
2382 | ||
2383 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2384 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2385 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2386 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2387 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2388 | rdev->devlist_generation ^ | |
2389 | (cfg80211_rdev_list_generation << 2))) | |
2390 | goto nla_put_failure; | |
f5ea9120 | 2391 | |
5b7ccaf3 | 2392 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2393 | int ret; |
2394 | struct cfg80211_chan_def chandef; | |
2395 | ||
2396 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2397 | if (ret == 0) { | |
2398 | if (nl80211_send_chandef(msg, &chandef)) | |
2399 | goto nla_put_failure; | |
2400 | } | |
d91df0e3 PF |
2401 | } |
2402 | ||
b84e7a05 AQ |
2403 | if (wdev->ssid_len) { |
2404 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2405 | goto nla_put_failure; | |
2406 | } | |
2407 | ||
55682965 JB |
2408 | return genlmsg_end(msg, hdr); |
2409 | ||
2410 | nla_put_failure: | |
bc3ed28c TG |
2411 | genlmsg_cancel(msg, hdr); |
2412 | return -EMSGSIZE; | |
55682965 JB |
2413 | } |
2414 | ||
2415 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2416 | { | |
2417 | int wp_idx = 0; | |
2418 | int if_idx = 0; | |
2419 | int wp_start = cb->args[0]; | |
2420 | int if_start = cb->args[1]; | |
f5ea9120 | 2421 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2422 | struct wireless_dev *wdev; |
2423 | ||
5fe231e8 | 2424 | rtnl_lock(); |
f5ea9120 JB |
2425 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2426 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2427 | continue; |
bba95fef JB |
2428 | if (wp_idx < wp_start) { |
2429 | wp_idx++; | |
55682965 | 2430 | continue; |
bba95fef | 2431 | } |
55682965 JB |
2432 | if_idx = 0; |
2433 | ||
89a54e48 | 2434 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2435 | if (if_idx < if_start) { |
2436 | if_idx++; | |
55682965 | 2437 | continue; |
bba95fef | 2438 | } |
15e47304 | 2439 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2440 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
8f894be2 | 2441 | rdev, wdev, false) < 0) { |
bba95fef JB |
2442 | goto out; |
2443 | } | |
2444 | if_idx++; | |
55682965 | 2445 | } |
bba95fef JB |
2446 | |
2447 | wp_idx++; | |
55682965 | 2448 | } |
bba95fef | 2449 | out: |
5fe231e8 | 2450 | rtnl_unlock(); |
55682965 JB |
2451 | |
2452 | cb->args[0] = wp_idx; | |
2453 | cb->args[1] = if_idx; | |
2454 | ||
2455 | return skb->len; | |
2456 | } | |
2457 | ||
2458 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2459 | { | |
2460 | struct sk_buff *msg; | |
1b8ec87a | 2461 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2462 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2463 | |
fd2120ca | 2464 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2465 | if (!msg) |
4c476991 | 2466 | return -ENOMEM; |
55682965 | 2467 | |
15e47304 | 2468 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2469 | rdev, wdev, false) < 0) { |
4c476991 JB |
2470 | nlmsg_free(msg); |
2471 | return -ENOBUFS; | |
2472 | } | |
55682965 | 2473 | |
134e6375 | 2474 | return genlmsg_reply(msg, info); |
55682965 JB |
2475 | } |
2476 | ||
66f7ac50 MW |
2477 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2478 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2479 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2480 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2481 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2482 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2483 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2484 | }; |
2485 | ||
2486 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2487 | { | |
2488 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2489 | int flag; | |
2490 | ||
2491 | *mntrflags = 0; | |
2492 | ||
2493 | if (!nla) | |
2494 | return -EINVAL; | |
2495 | ||
2496 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2497 | nla, mntr_flags_policy)) | |
2498 | return -EINVAL; | |
2499 | ||
2500 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2501 | if (flags[flag]) | |
2502 | *mntrflags |= (1<<flag); | |
2503 | ||
2504 | return 0; | |
2505 | } | |
2506 | ||
9bc383de | 2507 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2508 | struct net_device *netdev, u8 use_4addr, |
2509 | enum nl80211_iftype iftype) | |
9bc383de | 2510 | { |
ad4bb6f8 | 2511 | if (!use_4addr) { |
f350a0a8 | 2512 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2513 | return -EBUSY; |
9bc383de | 2514 | return 0; |
ad4bb6f8 | 2515 | } |
9bc383de JB |
2516 | |
2517 | switch (iftype) { | |
2518 | case NL80211_IFTYPE_AP_VLAN: | |
2519 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2520 | return 0; | |
2521 | break; | |
2522 | case NL80211_IFTYPE_STATION: | |
2523 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2524 | return 0; | |
2525 | break; | |
2526 | default: | |
2527 | break; | |
2528 | } | |
2529 | ||
2530 | return -EOPNOTSUPP; | |
2531 | } | |
2532 | ||
55682965 JB |
2533 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2534 | { | |
4c476991 | 2535 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2536 | struct vif_params params; |
e36d56b6 | 2537 | int err; |
04a773ad | 2538 | enum nl80211_iftype otype, ntype; |
4c476991 | 2539 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2540 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2541 | bool change = false; |
55682965 | 2542 | |
2ec600d6 LCC |
2543 | memset(¶ms, 0, sizeof(params)); |
2544 | ||
04a773ad | 2545 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2546 | |
723b038d | 2547 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2548 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2549 | if (otype != ntype) |
ac7f9cfa | 2550 | change = true; |
4c476991 JB |
2551 | if (ntype > NL80211_IFTYPE_MAX) |
2552 | return -EINVAL; | |
723b038d JB |
2553 | } |
2554 | ||
92ffe055 | 2555 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2556 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2557 | ||
4c476991 JB |
2558 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2559 | return -EINVAL; | |
29cbe68c JB |
2560 | if (netif_running(dev)) |
2561 | return -EBUSY; | |
2562 | ||
2563 | wdev_lock(wdev); | |
2564 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2565 | IEEE80211_MAX_MESH_ID_LEN); | |
2566 | wdev->mesh_id_up_len = | |
2567 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2568 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2569 | wdev->mesh_id_up_len); | |
2570 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2571 | } |
2572 | ||
8b787643 FF |
2573 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2574 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2575 | change = true; | |
ad4bb6f8 | 2576 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2577 | if (err) |
4c476991 | 2578 | return err; |
8b787643 FF |
2579 | } else { |
2580 | params.use_4addr = -1; | |
2581 | } | |
2582 | ||
92ffe055 | 2583 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2584 | if (ntype != NL80211_IFTYPE_MONITOR) |
2585 | return -EINVAL; | |
92ffe055 JB |
2586 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2587 | &_flags); | |
ac7f9cfa | 2588 | if (err) |
4c476991 | 2589 | return err; |
ac7f9cfa JB |
2590 | |
2591 | flags = &_flags; | |
2592 | change = true; | |
92ffe055 | 2593 | } |
3b85875a | 2594 | |
18003297 | 2595 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2596 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2597 | return -EOPNOTSUPP; | |
2598 | ||
ac7f9cfa | 2599 | if (change) |
3d54d255 | 2600 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2601 | else |
2602 | err = 0; | |
60719ffd | 2603 | |
9bc383de JB |
2604 | if (!err && params.use_4addr != -1) |
2605 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2606 | ||
55682965 JB |
2607 | return err; |
2608 | } | |
2609 | ||
2610 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2611 | { | |
4c476991 | 2612 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2613 | struct vif_params params; |
84efbb84 | 2614 | struct wireless_dev *wdev; |
8f894be2 | 2615 | struct sk_buff *msg, *event; |
55682965 JB |
2616 | int err; |
2617 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2618 | u32 flags; |
55682965 | 2619 | |
78f22b6a JB |
2620 | /* to avoid failing a new interface creation due to pending removal */ |
2621 | cfg80211_destroy_ifaces(rdev); | |
2622 | ||
2ec600d6 LCC |
2623 | memset(¶ms, 0, sizeof(params)); |
2624 | ||
55682965 JB |
2625 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2626 | return -EINVAL; | |
2627 | ||
2628 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2629 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2630 | if (type > NL80211_IFTYPE_MAX) | |
2631 | return -EINVAL; | |
2632 | } | |
2633 | ||
79c97e97 | 2634 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2635 | !(rdev->wiphy.interface_modes & (1 << type))) |
2636 | return -EOPNOTSUPP; | |
55682965 | 2637 | |
e8f479b1 BG |
2638 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
2639 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && | |
2640 | info->attrs[NL80211_ATTR_MAC]) { | |
1c18f145 AS |
2641 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
2642 | ETH_ALEN); | |
2643 | if (!is_valid_ether_addr(params.macaddr)) | |
2644 | return -EADDRNOTAVAIL; | |
2645 | } | |
2646 | ||
9bc383de | 2647 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2648 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2649 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2650 | if (err) |
4c476991 | 2651 | return err; |
9bc383de | 2652 | } |
8b787643 | 2653 | |
1c90f9d4 JB |
2654 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2655 | if (!msg) | |
2656 | return -ENOMEM; | |
2657 | ||
66f7ac50 MW |
2658 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2659 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2660 | &flags); | |
e057d3c3 | 2661 | |
18003297 | 2662 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2663 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2664 | return -EOPNOTSUPP; | |
2665 | ||
e35e4d28 HG |
2666 | wdev = rdev_add_virtual_intf(rdev, |
2667 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2668 | type, err ? NULL : &flags, ¶ms); | |
d687cbb7 RM |
2669 | if (WARN_ON(!wdev)) { |
2670 | nlmsg_free(msg); | |
2671 | return -EPROTO; | |
2672 | } else if (IS_ERR(wdev)) { | |
1c90f9d4 | 2673 | nlmsg_free(msg); |
84efbb84 | 2674 | return PTR_ERR(wdev); |
1c90f9d4 | 2675 | } |
2ec600d6 | 2676 | |
18e5ca65 | 2677 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
78f22b6a JB |
2678 | wdev->owner_nlportid = info->snd_portid; |
2679 | ||
98104fde JB |
2680 | switch (type) { |
2681 | case NL80211_IFTYPE_MESH_POINT: | |
2682 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2683 | break; | |
29cbe68c JB |
2684 | wdev_lock(wdev); |
2685 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2686 | IEEE80211_MAX_MESH_ID_LEN); | |
2687 | wdev->mesh_id_up_len = | |
2688 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2689 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2690 | wdev->mesh_id_up_len); | |
2691 | wdev_unlock(wdev); | |
98104fde JB |
2692 | break; |
2693 | case NL80211_IFTYPE_P2P_DEVICE: | |
2694 | /* | |
2695 | * P2P Device doesn't have a netdev, so doesn't go | |
2696 | * through the netdev notifier and must be added here | |
2697 | */ | |
2698 | mutex_init(&wdev->mtx); | |
2699 | INIT_LIST_HEAD(&wdev->event_list); | |
2700 | spin_lock_init(&wdev->event_lock); | |
2701 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2702 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2703 | ||
98104fde JB |
2704 | wdev->identifier = ++rdev->wdev_id; |
2705 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2706 | rdev->devlist_generation++; | |
98104fde JB |
2707 | break; |
2708 | default: | |
2709 | break; | |
29cbe68c JB |
2710 | } |
2711 | ||
15e47304 | 2712 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2713 | rdev, wdev, false) < 0) { |
1c90f9d4 JB |
2714 | nlmsg_free(msg); |
2715 | return -ENOBUFS; | |
2716 | } | |
2717 | ||
8f894be2 TB |
2718 | event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2719 | if (event) { | |
2720 | if (nl80211_send_iface(event, 0, 0, 0, | |
2721 | rdev, wdev, false) < 0) { | |
2722 | nlmsg_free(event); | |
2723 | goto out; | |
2724 | } | |
2725 | ||
2726 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
2727 | event, 0, NL80211_MCGRP_CONFIG, | |
2728 | GFP_KERNEL); | |
2729 | } | |
2730 | ||
2731 | out: | |
1c90f9d4 | 2732 | return genlmsg_reply(msg, info); |
55682965 JB |
2733 | } |
2734 | ||
2735 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2736 | { | |
4c476991 | 2737 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2738 | struct wireless_dev *wdev = info->user_ptr[1]; |
8f894be2 TB |
2739 | struct sk_buff *msg; |
2740 | int status; | |
55682965 | 2741 | |
4c476991 JB |
2742 | if (!rdev->ops->del_virtual_intf) |
2743 | return -EOPNOTSUPP; | |
55682965 | 2744 | |
8f894be2 TB |
2745 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2746 | if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) { | |
2747 | nlmsg_free(msg); | |
2748 | msg = NULL; | |
2749 | } | |
2750 | ||
84efbb84 JB |
2751 | /* |
2752 | * If we remove a wireless device without a netdev then clear | |
2753 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2754 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2755 | * since the wdev has been freed, unlike with a netdev where | |
2756 | * we need the dev_put() for the netdev to really be freed. | |
2757 | */ | |
2758 | if (!wdev->netdev) | |
2759 | info->user_ptr[1] = NULL; | |
2760 | ||
8f894be2 TB |
2761 | status = rdev_del_virtual_intf(rdev, wdev); |
2762 | if (status >= 0 && msg) | |
2763 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
2764 | msg, 0, NL80211_MCGRP_CONFIG, | |
2765 | GFP_KERNEL); | |
2766 | else | |
2767 | nlmsg_free(msg); | |
2768 | ||
2769 | return status; | |
55682965 JB |
2770 | } |
2771 | ||
1d9d9213 SW |
2772 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2773 | { | |
2774 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2775 | struct net_device *dev = info->user_ptr[1]; | |
2776 | u16 noack_map; | |
2777 | ||
2778 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2779 | return -EINVAL; | |
2780 | ||
2781 | if (!rdev->ops->set_noack_map) | |
2782 | return -EOPNOTSUPP; | |
2783 | ||
2784 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2785 | ||
e35e4d28 | 2786 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2787 | } |
2788 | ||
41ade00f JB |
2789 | struct get_key_cookie { |
2790 | struct sk_buff *msg; | |
2791 | int error; | |
b9454e83 | 2792 | int idx; |
41ade00f JB |
2793 | }; |
2794 | ||
2795 | static void get_key_callback(void *c, struct key_params *params) | |
2796 | { | |
b9454e83 | 2797 | struct nlattr *key; |
41ade00f JB |
2798 | struct get_key_cookie *cookie = c; |
2799 | ||
9360ffd1 DM |
2800 | if ((params->key && |
2801 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2802 | params->key_len, params->key)) || | |
2803 | (params->seq && | |
2804 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2805 | params->seq_len, params->seq)) || | |
2806 | (params->cipher && | |
2807 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2808 | params->cipher))) | |
2809 | goto nla_put_failure; | |
41ade00f | 2810 | |
b9454e83 JB |
2811 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2812 | if (!key) | |
2813 | goto nla_put_failure; | |
2814 | ||
9360ffd1 DM |
2815 | if ((params->key && |
2816 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2817 | params->key_len, params->key)) || | |
2818 | (params->seq && | |
2819 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2820 | params->seq_len, params->seq)) || | |
2821 | (params->cipher && | |
2822 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2823 | params->cipher))) | |
2824 | goto nla_put_failure; | |
b9454e83 | 2825 | |
9360ffd1 DM |
2826 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2827 | goto nla_put_failure; | |
b9454e83 JB |
2828 | |
2829 | nla_nest_end(cookie->msg, key); | |
2830 | ||
41ade00f JB |
2831 | return; |
2832 | nla_put_failure: | |
2833 | cookie->error = 1; | |
2834 | } | |
2835 | ||
2836 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2837 | { | |
4c476991 | 2838 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2839 | int err; |
4c476991 | 2840 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2841 | u8 key_idx = 0; |
e31b8213 JB |
2842 | const u8 *mac_addr = NULL; |
2843 | bool pairwise; | |
41ade00f JB |
2844 | struct get_key_cookie cookie = { |
2845 | .error = 0, | |
2846 | }; | |
2847 | void *hdr; | |
2848 | struct sk_buff *msg; | |
2849 | ||
2850 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2851 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2852 | ||
3cfcf6ac | 2853 | if (key_idx > 5) |
41ade00f JB |
2854 | return -EINVAL; |
2855 | ||
2856 | if (info->attrs[NL80211_ATTR_MAC]) | |
2857 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2858 | ||
e31b8213 JB |
2859 | pairwise = !!mac_addr; |
2860 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2861 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2862 | if (kt >= NUM_NL80211_KEYTYPES) | |
2863 | return -EINVAL; | |
2864 | if (kt != NL80211_KEYTYPE_GROUP && | |
2865 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2866 | return -EINVAL; | |
2867 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2868 | } | |
2869 | ||
4c476991 JB |
2870 | if (!rdev->ops->get_key) |
2871 | return -EOPNOTSUPP; | |
41ade00f | 2872 | |
fd2120ca | 2873 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2874 | if (!msg) |
2875 | return -ENOMEM; | |
41ade00f | 2876 | |
15e47304 | 2877 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2878 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 2879 | if (!hdr) |
9fe271af | 2880 | goto nla_put_failure; |
41ade00f JB |
2881 | |
2882 | cookie.msg = msg; | |
b9454e83 | 2883 | cookie.idx = key_idx; |
41ade00f | 2884 | |
9360ffd1 DM |
2885 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2886 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2887 | goto nla_put_failure; | |
2888 | if (mac_addr && | |
2889 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2890 | goto nla_put_failure; | |
41ade00f | 2891 | |
e31b8213 JB |
2892 | if (pairwise && mac_addr && |
2893 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2894 | return -ENOENT; | |
2895 | ||
e35e4d28 HG |
2896 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2897 | get_key_callback); | |
41ade00f JB |
2898 | |
2899 | if (err) | |
6c95e2a2 | 2900 | goto free_msg; |
41ade00f JB |
2901 | |
2902 | if (cookie.error) | |
2903 | goto nla_put_failure; | |
2904 | ||
2905 | genlmsg_end(msg, hdr); | |
4c476991 | 2906 | return genlmsg_reply(msg, info); |
41ade00f JB |
2907 | |
2908 | nla_put_failure: | |
2909 | err = -ENOBUFS; | |
6c95e2a2 | 2910 | free_msg: |
41ade00f | 2911 | nlmsg_free(msg); |
41ade00f JB |
2912 | return err; |
2913 | } | |
2914 | ||
2915 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2916 | { | |
4c476991 | 2917 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2918 | struct key_parse key; |
41ade00f | 2919 | int err; |
4c476991 | 2920 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2921 | |
b9454e83 JB |
2922 | err = nl80211_parse_key(info, &key); |
2923 | if (err) | |
2924 | return err; | |
41ade00f | 2925 | |
b9454e83 | 2926 | if (key.idx < 0) |
41ade00f JB |
2927 | return -EINVAL; |
2928 | ||
b9454e83 JB |
2929 | /* only support setting default key */ |
2930 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2931 | return -EINVAL; |
2932 | ||
dbd2fd65 | 2933 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2934 | |
dbd2fd65 JB |
2935 | if (key.def) { |
2936 | if (!rdev->ops->set_default_key) { | |
2937 | err = -EOPNOTSUPP; | |
2938 | goto out; | |
2939 | } | |
41ade00f | 2940 | |
dbd2fd65 JB |
2941 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2942 | if (err) | |
2943 | goto out; | |
2944 | ||
e35e4d28 | 2945 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2946 | key.def_uni, key.def_multi); |
2947 | ||
2948 | if (err) | |
2949 | goto out; | |
fffd0934 | 2950 | |
3d23e349 | 2951 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2952 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2953 | #endif | |
2954 | } else { | |
2955 | if (key.def_uni || !key.def_multi) { | |
2956 | err = -EINVAL; | |
2957 | goto out; | |
2958 | } | |
2959 | ||
2960 | if (!rdev->ops->set_default_mgmt_key) { | |
2961 | err = -EOPNOTSUPP; | |
2962 | goto out; | |
2963 | } | |
2964 | ||
2965 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2966 | if (err) | |
2967 | goto out; | |
2968 | ||
e35e4d28 | 2969 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2970 | if (err) |
2971 | goto out; | |
2972 | ||
2973 | #ifdef CONFIG_CFG80211_WEXT | |
2974 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2975 | #endif |
dbd2fd65 JB |
2976 | } |
2977 | ||
2978 | out: | |
fffd0934 | 2979 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2980 | |
41ade00f JB |
2981 | return err; |
2982 | } | |
2983 | ||
2984 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2985 | { | |
4c476991 | 2986 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2987 | int err; |
4c476991 | 2988 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2989 | struct key_parse key; |
e31b8213 | 2990 | const u8 *mac_addr = NULL; |
41ade00f | 2991 | |
b9454e83 JB |
2992 | err = nl80211_parse_key(info, &key); |
2993 | if (err) | |
2994 | return err; | |
41ade00f | 2995 | |
b9454e83 | 2996 | if (!key.p.key) |
41ade00f JB |
2997 | return -EINVAL; |
2998 | ||
41ade00f JB |
2999 | if (info->attrs[NL80211_ATTR_MAC]) |
3000 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3001 | ||
e31b8213 JB |
3002 | if (key.type == -1) { |
3003 | if (mac_addr) | |
3004 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3005 | else | |
3006 | key.type = NL80211_KEYTYPE_GROUP; | |
3007 | } | |
3008 | ||
3009 | /* for now */ | |
3010 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3011 | key.type != NL80211_KEYTYPE_GROUP) | |
3012 | return -EINVAL; | |
3013 | ||
4c476991 JB |
3014 | if (!rdev->ops->add_key) |
3015 | return -EOPNOTSUPP; | |
25e47c18 | 3016 | |
e31b8213 JB |
3017 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
3018 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3019 | mac_addr)) | |
4c476991 | 3020 | return -EINVAL; |
41ade00f | 3021 | |
fffd0934 JB |
3022 | wdev_lock(dev->ieee80211_ptr); |
3023 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3024 | if (!err) | |
e35e4d28 HG |
3025 | err = rdev_add_key(rdev, dev, key.idx, |
3026 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3027 | mac_addr, &key.p); | |
fffd0934 | 3028 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3029 | |
41ade00f JB |
3030 | return err; |
3031 | } | |
3032 | ||
3033 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
3034 | { | |
4c476991 | 3035 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3036 | int err; |
4c476991 | 3037 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3038 | u8 *mac_addr = NULL; |
b9454e83 | 3039 | struct key_parse key; |
41ade00f | 3040 | |
b9454e83 JB |
3041 | err = nl80211_parse_key(info, &key); |
3042 | if (err) | |
3043 | return err; | |
41ade00f JB |
3044 | |
3045 | if (info->attrs[NL80211_ATTR_MAC]) | |
3046 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3047 | ||
e31b8213 JB |
3048 | if (key.type == -1) { |
3049 | if (mac_addr) | |
3050 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3051 | else | |
3052 | key.type = NL80211_KEYTYPE_GROUP; | |
3053 | } | |
3054 | ||
3055 | /* for now */ | |
3056 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3057 | key.type != NL80211_KEYTYPE_GROUP) | |
3058 | return -EINVAL; | |
3059 | ||
4c476991 JB |
3060 | if (!rdev->ops->del_key) |
3061 | return -EOPNOTSUPP; | |
41ade00f | 3062 | |
fffd0934 JB |
3063 | wdev_lock(dev->ieee80211_ptr); |
3064 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
3065 | |
3066 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
3067 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
3068 | err = -ENOENT; | |
3069 | ||
fffd0934 | 3070 | if (!err) |
e35e4d28 HG |
3071 | err = rdev_del_key(rdev, dev, key.idx, |
3072 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3073 | mac_addr); | |
41ade00f | 3074 | |
3d23e349 | 3075 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 3076 | if (!err) { |
b9454e83 | 3077 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 3078 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 3079 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
3080 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
3081 | } | |
3082 | #endif | |
fffd0934 | 3083 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 3084 | |
41ade00f JB |
3085 | return err; |
3086 | } | |
3087 | ||
77765eaf VT |
3088 | /* This function returns an error or the number of nested attributes */ |
3089 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
3090 | { | |
3091 | struct nlattr *attr; | |
3092 | int n_entries = 0, tmp; | |
3093 | ||
3094 | nla_for_each_nested(attr, nl_attr, tmp) { | |
3095 | if (nla_len(attr) != ETH_ALEN) | |
3096 | return -EINVAL; | |
3097 | ||
3098 | n_entries++; | |
3099 | } | |
3100 | ||
3101 | return n_entries; | |
3102 | } | |
3103 | ||
3104 | /* | |
3105 | * This function parses ACL information and allocates memory for ACL data. | |
3106 | * On successful return, the calling function is responsible to free the | |
3107 | * ACL buffer returned by this function. | |
3108 | */ | |
3109 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3110 | struct genl_info *info) | |
3111 | { | |
3112 | enum nl80211_acl_policy acl_policy; | |
3113 | struct nlattr *attr; | |
3114 | struct cfg80211_acl_data *acl; | |
3115 | int i = 0, n_entries, tmp; | |
3116 | ||
3117 | if (!wiphy->max_acl_mac_addrs) | |
3118 | return ERR_PTR(-EOPNOTSUPP); | |
3119 | ||
3120 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3121 | return ERR_PTR(-EINVAL); | |
3122 | ||
3123 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3124 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3125 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3126 | return ERR_PTR(-EINVAL); | |
3127 | ||
3128 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3129 | return ERR_PTR(-EINVAL); | |
3130 | ||
3131 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3132 | if (n_entries < 0) | |
3133 | return ERR_PTR(n_entries); | |
3134 | ||
3135 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3136 | return ERR_PTR(-ENOTSUPP); | |
3137 | ||
3138 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
3139 | GFP_KERNEL); | |
3140 | if (!acl) | |
3141 | return ERR_PTR(-ENOMEM); | |
3142 | ||
3143 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3144 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3145 | i++; | |
3146 | } | |
3147 | ||
3148 | acl->n_acl_entries = n_entries; | |
3149 | acl->acl_policy = acl_policy; | |
3150 | ||
3151 | return acl; | |
3152 | } | |
3153 | ||
3154 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3155 | { | |
3156 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3157 | struct net_device *dev = info->user_ptr[1]; | |
3158 | struct cfg80211_acl_data *acl; | |
3159 | int err; | |
3160 | ||
3161 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3162 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3163 | return -EOPNOTSUPP; | |
3164 | ||
3165 | if (!dev->ieee80211_ptr->beacon_interval) | |
3166 | return -EINVAL; | |
3167 | ||
3168 | acl = parse_acl_data(&rdev->wiphy, info); | |
3169 | if (IS_ERR(acl)) | |
3170 | return PTR_ERR(acl); | |
3171 | ||
3172 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3173 | ||
3174 | kfree(acl); | |
3175 | ||
3176 | return err; | |
3177 | } | |
3178 | ||
a1193be8 | 3179 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3180 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3181 | { |
8860020e | 3182 | bool haveinfo = false; |
ed1b6cc7 | 3183 | |
a1193be8 SW |
3184 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3185 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3186 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3187 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3188 | return -EINVAL; |
3189 | ||
8860020e | 3190 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3191 | |
a1193be8 SW |
3192 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3193 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3194 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3195 | if (!bcn->head_len) |
3196 | return -EINVAL; | |
3197 | haveinfo = true; | |
ed1b6cc7 JB |
3198 | } |
3199 | ||
a1193be8 SW |
3200 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3201 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3202 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3203 | haveinfo = true; |
ed1b6cc7 JB |
3204 | } |
3205 | ||
4c476991 JB |
3206 | if (!haveinfo) |
3207 | return -EINVAL; | |
3b85875a | 3208 | |
a1193be8 SW |
3209 | if (attrs[NL80211_ATTR_IE]) { |
3210 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3211 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3212 | } |
3213 | ||
a1193be8 | 3214 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3215 | bcn->proberesp_ies = |
a1193be8 | 3216 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3217 | bcn->proberesp_ies_len = |
a1193be8 | 3218 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3219 | } |
3220 | ||
a1193be8 | 3221 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3222 | bcn->assocresp_ies = |
a1193be8 | 3223 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3224 | bcn->assocresp_ies_len = |
a1193be8 | 3225 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3226 | } |
3227 | ||
a1193be8 SW |
3228 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3229 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3230 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3231 | } |
3232 | ||
8860020e JB |
3233 | return 0; |
3234 | } | |
3235 | ||
46c1dd0c FF |
3236 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3237 | struct cfg80211_ap_settings *params) | |
3238 | { | |
3239 | struct wireless_dev *wdev; | |
3240 | bool ret = false; | |
3241 | ||
89a54e48 | 3242 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3243 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3244 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3245 | continue; | |
3246 | ||
683b6d3b | 3247 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3248 | continue; |
3249 | ||
683b6d3b | 3250 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3251 | ret = true; |
3252 | break; | |
3253 | } | |
3254 | ||
46c1dd0c FF |
3255 | return ret; |
3256 | } | |
3257 | ||
e39e5b5e JM |
3258 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3259 | enum nl80211_auth_type auth_type, | |
3260 | enum nl80211_commands cmd) | |
3261 | { | |
3262 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3263 | return false; | |
3264 | ||
3265 | switch (cmd) { | |
3266 | case NL80211_CMD_AUTHENTICATE: | |
3267 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3268 | auth_type == NL80211_AUTHTYPE_SAE) | |
3269 | return false; | |
3270 | return true; | |
3271 | case NL80211_CMD_CONNECT: | |
3272 | case NL80211_CMD_START_AP: | |
3273 | /* SAE not supported yet */ | |
3274 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3275 | return false; | |
3276 | return true; | |
3277 | default: | |
3278 | return false; | |
3279 | } | |
3280 | } | |
3281 | ||
8860020e JB |
3282 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3283 | { | |
3284 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3285 | struct net_device *dev = info->user_ptr[1]; | |
3286 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3287 | struct cfg80211_ap_settings params; | |
3288 | int err; | |
3289 | ||
3290 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3291 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3292 | return -EOPNOTSUPP; | |
3293 | ||
3294 | if (!rdev->ops->start_ap) | |
3295 | return -EOPNOTSUPP; | |
3296 | ||
3297 | if (wdev->beacon_interval) | |
3298 | return -EALREADY; | |
3299 | ||
3300 | memset(¶ms, 0, sizeof(params)); | |
3301 | ||
3302 | /* these are required for START_AP */ | |
3303 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3304 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3305 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3306 | return -EINVAL; | |
3307 | ||
a1193be8 | 3308 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3309 | if (err) |
3310 | return err; | |
3311 | ||
3312 | params.beacon_interval = | |
3313 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3314 | params.dtim_period = | |
3315 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3316 | ||
3317 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3318 | if (err) | |
3319 | return err; | |
3320 | ||
3321 | /* | |
3322 | * In theory, some of these attributes should be required here | |
3323 | * but since they were not used when the command was originally | |
3324 | * added, keep them optional for old user space programs to let | |
3325 | * them continue to work with drivers that do not need the | |
3326 | * additional information -- drivers must check! | |
3327 | */ | |
3328 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3329 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3330 | params.ssid_len = | |
3331 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3332 | if (params.ssid_len == 0 || | |
3333 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3334 | return -EINVAL; | |
3335 | } | |
3336 | ||
3337 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3338 | params.hidden_ssid = nla_get_u32( | |
3339 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3340 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3341 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3342 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3343 | return -EINVAL; | |
3344 | } | |
3345 | ||
3346 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3347 | ||
3348 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3349 | params.auth_type = nla_get_u32( | |
3350 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3351 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3352 | NL80211_CMD_START_AP)) | |
8860020e JB |
3353 | return -EINVAL; |
3354 | } else | |
3355 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3356 | ||
3357 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3358 | NL80211_MAX_NR_CIPHER_SUITES); | |
3359 | if (err) | |
3360 | return err; | |
3361 | ||
1b658f11 VT |
3362 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3363 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3364 | return -EOPNOTSUPP; | |
3365 | params.inactivity_timeout = nla_get_u16( | |
3366 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3367 | } | |
3368 | ||
53cabad7 JB |
3369 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3370 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3371 | return -EINVAL; | |
3372 | params.p2p_ctwindow = | |
3373 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3374 | if (params.p2p_ctwindow > 127) | |
3375 | return -EINVAL; | |
3376 | if (params.p2p_ctwindow != 0 && | |
3377 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3378 | return -EINVAL; | |
3379 | } | |
3380 | ||
3381 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3382 | u8 tmp; | |
3383 | ||
3384 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3385 | return -EINVAL; | |
3386 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3387 | if (tmp > 1) | |
3388 | return -EINVAL; | |
3389 | params.p2p_opp_ps = tmp; | |
3390 | if (params.p2p_opp_ps != 0 && | |
3391 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3392 | return -EINVAL; | |
3393 | } | |
3394 | ||
aa430da4 | 3395 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3396 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3397 | if (err) | |
3398 | return err; | |
3399 | } else if (wdev->preset_chandef.chan) { | |
3400 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3401 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3402 | return -EINVAL; |
3403 | ||
174e0cd2 IP |
3404 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
3405 | wdev->iftype)) | |
aa430da4 JB |
3406 | return -EINVAL; |
3407 | ||
77765eaf VT |
3408 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3409 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3410 | if (IS_ERR(params.acl)) | |
3411 | return PTR_ERR(params.acl); | |
3412 | } | |
3413 | ||
18998c38 EP |
3414 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
3415 | params.smps_mode = | |
3416 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); | |
3417 | switch (params.smps_mode) { | |
3418 | case NL80211_SMPS_OFF: | |
3419 | break; | |
3420 | case NL80211_SMPS_STATIC: | |
3421 | if (!(rdev->wiphy.features & | |
3422 | NL80211_FEATURE_STATIC_SMPS)) | |
3423 | return -EINVAL; | |
3424 | break; | |
3425 | case NL80211_SMPS_DYNAMIC: | |
3426 | if (!(rdev->wiphy.features & | |
3427 | NL80211_FEATURE_DYNAMIC_SMPS)) | |
3428 | return -EINVAL; | |
3429 | break; | |
3430 | default: | |
3431 | return -EINVAL; | |
3432 | } | |
3433 | } else { | |
3434 | params.smps_mode = NL80211_SMPS_OFF; | |
3435 | } | |
3436 | ||
c56589ed | 3437 | wdev_lock(wdev); |
e35e4d28 | 3438 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3439 | if (!err) { |
683b6d3b | 3440 | wdev->preset_chandef = params.chandef; |
8860020e | 3441 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 3442 | wdev->chandef = params.chandef; |
06e191e2 AQ |
3443 | wdev->ssid_len = params.ssid_len; |
3444 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3445 | } |
c56589ed | 3446 | wdev_unlock(wdev); |
77765eaf VT |
3447 | |
3448 | kfree(params.acl); | |
3449 | ||
56d1893d | 3450 | return err; |
ed1b6cc7 JB |
3451 | } |
3452 | ||
8860020e JB |
3453 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3454 | { | |
3455 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3456 | struct net_device *dev = info->user_ptr[1]; | |
3457 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3458 | struct cfg80211_beacon_data params; | |
3459 | int err; | |
3460 | ||
3461 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3462 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3463 | return -EOPNOTSUPP; | |
3464 | ||
3465 | if (!rdev->ops->change_beacon) | |
3466 | return -EOPNOTSUPP; | |
3467 | ||
3468 | if (!wdev->beacon_interval) | |
3469 | return -EINVAL; | |
3470 | ||
a1193be8 | 3471 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3472 | if (err) |
3473 | return err; | |
3474 | ||
c56589ed SW |
3475 | wdev_lock(wdev); |
3476 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3477 | wdev_unlock(wdev); | |
3478 | ||
3479 | return err; | |
8860020e JB |
3480 | } |
3481 | ||
3482 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3483 | { |
4c476991 JB |
3484 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3485 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3486 | |
7c8d5e03 | 3487 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
3488 | } |
3489 | ||
5727ef1b JB |
3490 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3491 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3492 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3493 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3494 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3495 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3496 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3497 | }; |
3498 | ||
eccb8e8f | 3499 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3500 | enum nl80211_iftype iftype, |
eccb8e8f | 3501 | struct station_parameters *params) |
5727ef1b JB |
3502 | { |
3503 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3504 | struct nlattr *nla; |
5727ef1b JB |
3505 | int flag; |
3506 | ||
eccb8e8f JB |
3507 | /* |
3508 | * Try parsing the new attribute first so userspace | |
3509 | * can specify both for older kernels. | |
3510 | */ | |
3511 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3512 | if (nla) { | |
3513 | struct nl80211_sta_flag_update *sta_flags; | |
3514 | ||
3515 | sta_flags = nla_data(nla); | |
3516 | params->sta_flags_mask = sta_flags->mask; | |
3517 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3518 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3519 | if ((params->sta_flags_mask | |
3520 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3521 | return -EINVAL; | |
3522 | return 0; | |
3523 | } | |
3524 | ||
3525 | /* if present, parse the old attribute */ | |
5727ef1b | 3526 | |
eccb8e8f | 3527 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3528 | if (!nla) |
3529 | return 0; | |
3530 | ||
3531 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3532 | nla, sta_flags_policy)) | |
3533 | return -EINVAL; | |
3534 | ||
bdd3ae3d JB |
3535 | /* |
3536 | * Only allow certain flags for interface types so that | |
3537 | * other attributes are silently ignored. Remember that | |
3538 | * this is backward compatibility code with old userspace | |
3539 | * and shouldn't be hit in other cases anyway. | |
3540 | */ | |
3541 | switch (iftype) { | |
3542 | case NL80211_IFTYPE_AP: | |
3543 | case NL80211_IFTYPE_AP_VLAN: | |
3544 | case NL80211_IFTYPE_P2P_GO: | |
3545 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3546 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3547 | BIT(NL80211_STA_FLAG_WME) | | |
3548 | BIT(NL80211_STA_FLAG_MFP); | |
3549 | break; | |
3550 | case NL80211_IFTYPE_P2P_CLIENT: | |
3551 | case NL80211_IFTYPE_STATION: | |
3552 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3553 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3554 | break; | |
3555 | case NL80211_IFTYPE_MESH_POINT: | |
3556 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3557 | BIT(NL80211_STA_FLAG_MFP) | | |
3558 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3559 | default: | |
3560 | return -EINVAL; | |
3561 | } | |
5727ef1b | 3562 | |
3383b5a6 JB |
3563 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3564 | if (flags[flag]) { | |
eccb8e8f | 3565 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3566 | |
3383b5a6 JB |
3567 | /* no longer support new API additions in old API */ |
3568 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3569 | return -EINVAL; | |
3570 | } | |
3571 | } | |
3572 | ||
5727ef1b JB |
3573 | return 0; |
3574 | } | |
3575 | ||
c8dcfd8a FF |
3576 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3577 | int attr) | |
3578 | { | |
3579 | struct nlattr *rate; | |
8eb41c8d VK |
3580 | u32 bitrate; |
3581 | u16 bitrate_compat; | |
b51f3bee | 3582 | enum nl80211_attrs rate_flg; |
c8dcfd8a FF |
3583 | |
3584 | rate = nla_nest_start(msg, attr); | |
3585 | if (!rate) | |
db9c64cf | 3586 | return false; |
c8dcfd8a FF |
3587 | |
3588 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3589 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3590 | /* report 16-bit bitrate only if we can */ |
3591 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3592 | if (bitrate > 0 && |
3593 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3594 | return false; | |
3595 | if (bitrate_compat > 0 && | |
3596 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3597 | return false; | |
3598 | ||
b51f3bee JB |
3599 | switch (info->bw) { |
3600 | case RATE_INFO_BW_5: | |
3601 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; | |
3602 | break; | |
3603 | case RATE_INFO_BW_10: | |
3604 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; | |
3605 | break; | |
3606 | default: | |
3607 | WARN_ON(1); | |
3608 | /* fall through */ | |
3609 | case RATE_INFO_BW_20: | |
3610 | rate_flg = 0; | |
3611 | break; | |
3612 | case RATE_INFO_BW_40: | |
3613 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; | |
3614 | break; | |
3615 | case RATE_INFO_BW_80: | |
3616 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; | |
3617 | break; | |
3618 | case RATE_INFO_BW_160: | |
3619 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; | |
3620 | break; | |
3621 | } | |
3622 | ||
3623 | if (rate_flg && nla_put_flag(msg, rate_flg)) | |
3624 | return false; | |
3625 | ||
db9c64cf JB |
3626 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
3627 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3628 | return false; | |
db9c64cf JB |
3629 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
3630 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3631 | return false; | |
3632 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3633 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3634 | return false; | |
3635 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3636 | return false; | |
db9c64cf JB |
3637 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
3638 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3639 | return false; | |
3640 | } | |
c8dcfd8a FF |
3641 | |
3642 | nla_nest_end(msg, rate); | |
3643 | return true; | |
c8dcfd8a FF |
3644 | } |
3645 | ||
119363c7 FF |
3646 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3647 | int id) | |
3648 | { | |
3649 | void *attr; | |
3650 | int i = 0; | |
3651 | ||
3652 | if (!mask) | |
3653 | return true; | |
3654 | ||
3655 | attr = nla_nest_start(msg, id); | |
3656 | if (!attr) | |
3657 | return false; | |
3658 | ||
3659 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3660 | if (!(mask & BIT(i))) | |
3661 | continue; | |
3662 | ||
3663 | if (nla_put_u8(msg, i, signal[i])) | |
3664 | return false; | |
3665 | } | |
3666 | ||
3667 | nla_nest_end(msg, attr); | |
3668 | ||
3669 | return true; | |
3670 | } | |
3671 | ||
cf5ead82 JB |
3672 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
3673 | u32 seq, int flags, | |
66266b3a JL |
3674 | struct cfg80211_registered_device *rdev, |
3675 | struct net_device *dev, | |
98b62183 | 3676 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3677 | { |
3678 | void *hdr; | |
f4263c98 | 3679 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3680 | |
cf5ead82 | 3681 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
fd5b74dc JB |
3682 | if (!hdr) |
3683 | return -1; | |
3684 | ||
9360ffd1 DM |
3685 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3686 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3687 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3688 | goto nla_put_failure; | |
f5ea9120 | 3689 | |
2ec600d6 LCC |
3690 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3691 | if (!sinfoattr) | |
fd5b74dc | 3692 | goto nla_put_failure; |
319090bf JB |
3693 | |
3694 | #define PUT_SINFO(attr, memb, type) do { \ | |
3695 | if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \ | |
3696 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ | |
3697 | sinfo->memb)) \ | |
3698 | goto nla_put_failure; \ | |
3699 | } while (0) | |
3700 | ||
3701 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); | |
3702 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); | |
3703 | ||
3704 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | | |
3705 | BIT(NL80211_STA_INFO_RX_BYTES64)) && | |
9360ffd1 | 3706 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3707 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3708 | goto nla_put_failure; |
319090bf JB |
3709 | |
3710 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | | |
3711 | BIT(NL80211_STA_INFO_TX_BYTES64)) && | |
9360ffd1 | 3712 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3713 | (u32)sinfo->tx_bytes)) |
3714 | goto nla_put_failure; | |
319090bf JB |
3715 | |
3716 | PUT_SINFO(RX_BYTES64, rx_bytes, u64); | |
3717 | PUT_SINFO(TX_BYTES64, tx_bytes, u64); | |
3718 | PUT_SINFO(LLID, llid, u16); | |
3719 | PUT_SINFO(PLID, plid, u16); | |
3720 | PUT_SINFO(PLINK_STATE, plink_state, u8); | |
3721 | ||
66266b3a JL |
3722 | switch (rdev->wiphy.signal_type) { |
3723 | case CFG80211_SIGNAL_TYPE_MBM: | |
319090bf JB |
3724 | PUT_SINFO(SIGNAL, signal, u8); |
3725 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); | |
66266b3a JL |
3726 | break; |
3727 | default: | |
3728 | break; | |
3729 | } | |
319090bf | 3730 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
119363c7 FF |
3731 | if (!nl80211_put_signal(msg, sinfo->chains, |
3732 | sinfo->chain_signal, | |
3733 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3734 | goto nla_put_failure; | |
3735 | } | |
319090bf | 3736 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
119363c7 FF |
3737 | if (!nl80211_put_signal(msg, sinfo->chains, |
3738 | sinfo->chain_signal_avg, | |
3739 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3740 | goto nla_put_failure; | |
3741 | } | |
319090bf | 3742 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
c8dcfd8a FF |
3743 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3744 | NL80211_STA_INFO_TX_BITRATE)) | |
3745 | goto nla_put_failure; | |
3746 | } | |
319090bf | 3747 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
c8dcfd8a FF |
3748 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
3749 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3750 | goto nla_put_failure; |
420e7fab | 3751 | } |
319090bf JB |
3752 | |
3753 | PUT_SINFO(RX_PACKETS, rx_packets, u32); | |
3754 | PUT_SINFO(TX_PACKETS, tx_packets, u32); | |
3755 | PUT_SINFO(TX_RETRIES, tx_retries, u32); | |
3756 | PUT_SINFO(TX_FAILED, tx_failed, u32); | |
3757 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); | |
3758 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); | |
3759 | PUT_SINFO(LOCAL_PM, local_pm, u32); | |
3760 | PUT_SINFO(PEER_PM, peer_pm, u32); | |
3761 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); | |
3762 | ||
3763 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { | |
f4263c98 PS |
3764 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
3765 | if (!bss_param) | |
3766 | goto nla_put_failure; | |
3767 | ||
9360ffd1 DM |
3768 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3769 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3770 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3771 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3772 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3773 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3774 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3775 | sinfo->bss_param.dtim_period) || | |
3776 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3777 | sinfo->bss_param.beacon_interval)) | |
3778 | goto nla_put_failure; | |
f4263c98 PS |
3779 | |
3780 | nla_nest_end(msg, bss_param); | |
3781 | } | |
319090bf | 3782 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
9360ffd1 DM |
3783 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
3784 | sizeof(struct nl80211_sta_flag_update), | |
3785 | &sinfo->sta_flags)) | |
3786 | goto nla_put_failure; | |
319090bf JB |
3787 | |
3788 | PUT_SINFO(T_OFFSET, t_offset, u64); | |
3789 | PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64); | |
a76b1942 JB |
3790 | PUT_SINFO(BEACON_RX, rx_beacon, u64); |
3791 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); | |
319090bf JB |
3792 | |
3793 | #undef PUT_SINFO | |
6de39808 JB |
3794 | |
3795 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { | |
3796 | struct nlattr *tidsattr; | |
3797 | int tid; | |
3798 | ||
3799 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); | |
3800 | if (!tidsattr) | |
3801 | goto nla_put_failure; | |
3802 | ||
3803 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { | |
3804 | struct cfg80211_tid_stats *tidstats; | |
3805 | struct nlattr *tidattr; | |
3806 | ||
3807 | tidstats = &sinfo->pertid[tid]; | |
3808 | ||
3809 | if (!tidstats->filled) | |
3810 | continue; | |
3811 | ||
3812 | tidattr = nla_nest_start(msg, tid + 1); | |
3813 | if (!tidattr) | |
3814 | goto nla_put_failure; | |
3815 | ||
3816 | #define PUT_TIDVAL(attr, memb, type) do { \ | |
3817 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ | |
3818 | nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \ | |
3819 | tidstats->memb)) \ | |
3820 | goto nla_put_failure; \ | |
3821 | } while (0) | |
3822 | ||
3823 | PUT_TIDVAL(RX_MSDU, rx_msdu, u64); | |
3824 | PUT_TIDVAL(TX_MSDU, tx_msdu, u64); | |
3825 | PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64); | |
3826 | PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64); | |
3827 | ||
3828 | #undef PUT_TIDVAL | |
3829 | nla_nest_end(msg, tidattr); | |
3830 | } | |
3831 | ||
3832 | nla_nest_end(msg, tidsattr); | |
3833 | } | |
3834 | ||
2ec600d6 | 3835 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3836 | |
319090bf | 3837 | if (sinfo->assoc_req_ies_len && |
9360ffd1 DM |
3838 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
3839 | sinfo->assoc_req_ies)) | |
3840 | goto nla_put_failure; | |
50d3dfb7 | 3841 | |
fd5b74dc JB |
3842 | return genlmsg_end(msg, hdr); |
3843 | ||
3844 | nla_put_failure: | |
bc3ed28c TG |
3845 | genlmsg_cancel(msg, hdr); |
3846 | return -EMSGSIZE; | |
fd5b74dc JB |
3847 | } |
3848 | ||
2ec600d6 | 3849 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3850 | struct netlink_callback *cb) |
2ec600d6 | 3851 | { |
2ec600d6 | 3852 | struct station_info sinfo; |
1b8ec87a | 3853 | struct cfg80211_registered_device *rdev; |
97990a06 | 3854 | struct wireless_dev *wdev; |
2ec600d6 | 3855 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3856 | int sta_idx = cb->args[2]; |
2ec600d6 | 3857 | int err; |
2ec600d6 | 3858 | |
1b8ec87a | 3859 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
3860 | if (err) |
3861 | return err; | |
bba95fef | 3862 | |
97990a06 JB |
3863 | if (!wdev->netdev) { |
3864 | err = -EINVAL; | |
3865 | goto out_err; | |
3866 | } | |
3867 | ||
1b8ec87a | 3868 | if (!rdev->ops->dump_station) { |
eec60b03 | 3869 | err = -EOPNOTSUPP; |
bba95fef JB |
3870 | goto out_err; |
3871 | } | |
3872 | ||
bba95fef | 3873 | while (1) { |
f612cedf | 3874 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 3875 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
e35e4d28 | 3876 | mac_addr, &sinfo); |
bba95fef JB |
3877 | if (err == -ENOENT) |
3878 | break; | |
3879 | if (err) | |
3b85875a | 3880 | goto out_err; |
bba95fef | 3881 | |
cf5ead82 | 3882 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
15e47304 | 3883 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3884 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 3885 | rdev, wdev->netdev, mac_addr, |
bba95fef JB |
3886 | &sinfo) < 0) |
3887 | goto out; | |
3888 | ||
3889 | sta_idx++; | |
3890 | } | |
3891 | ||
3892 | ||
3893 | out: | |
97990a06 | 3894 | cb->args[2] = sta_idx; |
bba95fef | 3895 | err = skb->len; |
bba95fef | 3896 | out_err: |
1b8ec87a | 3897 | nl80211_finish_wdev_dump(rdev); |
bba95fef JB |
3898 | |
3899 | return err; | |
2ec600d6 | 3900 | } |
fd5b74dc | 3901 | |
5727ef1b JB |
3902 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3903 | { | |
4c476991 JB |
3904 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3905 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3906 | struct station_info sinfo; |
fd5b74dc JB |
3907 | struct sk_buff *msg; |
3908 | u8 *mac_addr = NULL; | |
4c476991 | 3909 | int err; |
fd5b74dc | 3910 | |
2ec600d6 | 3911 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3912 | |
3913 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3914 | return -EINVAL; | |
3915 | ||
3916 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3917 | ||
4c476991 JB |
3918 | if (!rdev->ops->get_station) |
3919 | return -EOPNOTSUPP; | |
3b85875a | 3920 | |
e35e4d28 | 3921 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3922 | if (err) |
4c476991 | 3923 | return err; |
2ec600d6 | 3924 | |
fd2120ca | 3925 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3926 | if (!msg) |
4c476991 | 3927 | return -ENOMEM; |
fd5b74dc | 3928 | |
cf5ead82 JB |
3929 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
3930 | info->snd_portid, info->snd_seq, 0, | |
66266b3a | 3931 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3932 | nlmsg_free(msg); |
3933 | return -ENOBUFS; | |
3934 | } | |
3b85875a | 3935 | |
4c476991 | 3936 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3937 | } |
3938 | ||
77ee7c89 JB |
3939 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3940 | struct station_parameters *params, | |
3941 | enum cfg80211_station_type statype) | |
3942 | { | |
3943 | if (params->listen_interval != -1) | |
3944 | return -EINVAL; | |
c72e1140 AN |
3945 | if (params->aid && |
3946 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
77ee7c89 JB |
3947 | return -EINVAL; |
3948 | ||
3949 | /* When you run into this, adjust the code below for the new flag */ | |
3950 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3951 | ||
3952 | switch (statype) { | |
eef941e6 TP |
3953 | case CFG80211_STA_MESH_PEER_KERNEL: |
3954 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3955 | /* |
3956 | * No ignoring the TDLS flag here -- the userspace mesh | |
3957 | * code doesn't have the bug of including TDLS in the | |
3958 | * mask everywhere. | |
3959 | */ | |
3960 | if (params->sta_flags_mask & | |
3961 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3962 | BIT(NL80211_STA_FLAG_MFP) | | |
3963 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3964 | return -EINVAL; | |
3965 | break; | |
3966 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3967 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3968 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3969 | return -EINVAL; | |
3970 | /* ignore since it can't change */ | |
3971 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3972 | break; | |
3973 | default: | |
3974 | /* disallow mesh-specific things */ | |
3975 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3976 | return -EINVAL; | |
3977 | if (params->local_pm) | |
3978 | return -EINVAL; | |
3979 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3980 | return -EINVAL; | |
3981 | } | |
3982 | ||
3983 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3984 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3985 | /* TDLS can't be set, ... */ | |
3986 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3987 | return -EINVAL; | |
3988 | /* | |
3989 | * ... but don't bother the driver with it. This works around | |
3990 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3991 | * TLDS_PEER flag in the mask even for AP mode. | |
3992 | */ | |
3993 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3994 | } | |
3995 | ||
3996 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3997 | /* reject other things that can't change */ | |
3998 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3999 | return -EINVAL; | |
4000 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
4001 | return -EINVAL; | |
4002 | if (params->supported_rates) | |
4003 | return -EINVAL; | |
4004 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
4005 | return -EINVAL; | |
4006 | } | |
4007 | ||
4008 | if (statype != CFG80211_STA_AP_CLIENT) { | |
4009 | if (params->vlan) | |
4010 | return -EINVAL; | |
4011 | } | |
4012 | ||
4013 | switch (statype) { | |
4014 | case CFG80211_STA_AP_MLME_CLIENT: | |
4015 | /* Use this only for authorizing/unauthorizing a station */ | |
4016 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
4017 | return -EOPNOTSUPP; | |
4018 | break; | |
4019 | case CFG80211_STA_AP_CLIENT: | |
4020 | /* accept only the listed bits */ | |
4021 | if (params->sta_flags_mask & | |
4022 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4023 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4024 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4025 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
4026 | BIT(NL80211_STA_FLAG_WME) | | |
4027 | BIT(NL80211_STA_FLAG_MFP))) | |
4028 | return -EINVAL; | |
4029 | ||
4030 | /* but authenticated/associated only if driver handles it */ | |
4031 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4032 | params->sta_flags_mask & | |
4033 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4034 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4035 | return -EINVAL; | |
4036 | break; | |
4037 | case CFG80211_STA_IBSS: | |
4038 | case CFG80211_STA_AP_STA: | |
4039 | /* reject any changes other than AUTHORIZED */ | |
4040 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
4041 | return -EINVAL; | |
4042 | break; | |
4043 | case CFG80211_STA_TDLS_PEER_SETUP: | |
4044 | /* reject any changes other than AUTHORIZED or WME */ | |
4045 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4046 | BIT(NL80211_STA_FLAG_WME))) | |
4047 | return -EINVAL; | |
4048 | /* force (at least) rates when authorizing */ | |
4049 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
4050 | !params->supported_rates) | |
4051 | return -EINVAL; | |
4052 | break; | |
4053 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
4054 | /* reject any changes */ | |
4055 | return -EINVAL; | |
eef941e6 | 4056 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
4057 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
4058 | return -EINVAL; | |
4059 | break; | |
eef941e6 | 4060 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
4061 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
4062 | return -EINVAL; | |
4063 | break; | |
4064 | } | |
4065 | ||
4066 | return 0; | |
4067 | } | |
4068 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
4069 | ||
5727ef1b | 4070 | /* |
c258d2de | 4071 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 4072 | */ |
80b99899 JB |
4073 | static struct net_device *get_vlan(struct genl_info *info, |
4074 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 4075 | { |
463d0183 | 4076 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
4077 | struct net_device *v; |
4078 | int ret; | |
4079 | ||
4080 | if (!vlanattr) | |
4081 | return NULL; | |
4082 | ||
4083 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
4084 | if (!v) | |
4085 | return ERR_PTR(-ENODEV); | |
4086 | ||
4087 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
4088 | ret = -EINVAL; | |
4089 | goto error; | |
5727ef1b | 4090 | } |
80b99899 | 4091 | |
77ee7c89 JB |
4092 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
4093 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4094 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
4095 | ret = -EINVAL; | |
4096 | goto error; | |
4097 | } | |
4098 | ||
80b99899 JB |
4099 | if (!netif_running(v)) { |
4100 | ret = -ENETDOWN; | |
4101 | goto error; | |
4102 | } | |
4103 | ||
4104 | return v; | |
4105 | error: | |
4106 | dev_put(v); | |
4107 | return ERR_PTR(ret); | |
5727ef1b JB |
4108 | } |
4109 | ||
94e860f1 JB |
4110 | static const struct nla_policy |
4111 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
4112 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
4113 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
4114 | }; | |
4115 | ||
ff276691 JB |
4116 | static int nl80211_parse_sta_wme(struct genl_info *info, |
4117 | struct station_parameters *params) | |
df881293 | 4118 | { |
df881293 JM |
4119 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
4120 | struct nlattr *nla; | |
4121 | int err; | |
4122 | ||
df881293 JM |
4123 | /* parse WME attributes if present */ |
4124 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
4125 | return 0; | |
4126 | ||
4127 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
4128 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
4129 | nl80211_sta_wme_policy); | |
4130 | if (err) | |
4131 | return err; | |
4132 | ||
4133 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
4134 | params->uapsd_queues = nla_get_u8( | |
4135 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4136 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
4137 | return -EINVAL; | |
4138 | ||
4139 | if (tb[NL80211_STA_WME_MAX_SP]) | |
4140 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4141 | ||
4142 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
4143 | return -EINVAL; | |
4144 | ||
4145 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
4146 | ||
4147 | return 0; | |
4148 | } | |
4149 | ||
c01fc9ad SD |
4150 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4151 | struct station_parameters *params) | |
4152 | { | |
4153 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4154 | params->supported_channels = | |
4155 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4156 | params->supported_channels_len = | |
4157 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4158 | /* | |
4159 | * Need to include at least one (first channel, number of | |
4160 | * channels) tuple for each subband, and must have proper | |
4161 | * tuples for the rest of the data as well. | |
4162 | */ | |
4163 | if (params->supported_channels_len < 2) | |
4164 | return -EINVAL; | |
4165 | if (params->supported_channels_len % 2) | |
4166 | return -EINVAL; | |
4167 | } | |
4168 | ||
4169 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4170 | params->supported_oper_classes = | |
4171 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4172 | params->supported_oper_classes_len = | |
4173 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4174 | /* | |
4175 | * The value of the Length field of the Supported Operating | |
4176 | * Classes element is between 2 and 253. | |
4177 | */ | |
4178 | if (params->supported_oper_classes_len < 2 || | |
4179 | params->supported_oper_classes_len > 253) | |
4180 | return -EINVAL; | |
4181 | } | |
4182 | return 0; | |
4183 | } | |
4184 | ||
ff276691 JB |
4185 | static int nl80211_set_station_tdls(struct genl_info *info, |
4186 | struct station_parameters *params) | |
4187 | { | |
c01fc9ad | 4188 | int err; |
ff276691 | 4189 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4190 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4191 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4192 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4193 | params->ht_capa = | |
4194 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4195 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4196 | params->vht_capa = | |
4197 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4198 | ||
c01fc9ad SD |
4199 | err = nl80211_parse_sta_channel_info(info, params); |
4200 | if (err) | |
4201 | return err; | |
4202 | ||
ff276691 JB |
4203 | return nl80211_parse_sta_wme(info, params); |
4204 | } | |
4205 | ||
5727ef1b JB |
4206 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4207 | { | |
4c476991 | 4208 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4209 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4210 | struct station_parameters params; |
77ee7c89 JB |
4211 | u8 *mac_addr; |
4212 | int err; | |
5727ef1b JB |
4213 | |
4214 | memset(¶ms, 0, sizeof(params)); | |
4215 | ||
4216 | params.listen_interval = -1; | |
4217 | ||
77ee7c89 JB |
4218 | if (!rdev->ops->change_station) |
4219 | return -EOPNOTSUPP; | |
4220 | ||
5727ef1b JB |
4221 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4222 | return -EINVAL; | |
4223 | ||
4224 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4225 | return -EINVAL; | |
4226 | ||
4227 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4228 | ||
4229 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4230 | params.supported_rates = | |
4231 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4232 | params.supported_rates_len = | |
4233 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4234 | } | |
4235 | ||
9d62a986 JM |
4236 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4237 | params.capability = | |
4238 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4239 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4240 | } | |
4241 | ||
4242 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4243 | params.ext_capab = | |
4244 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4245 | params.ext_capab_len = | |
4246 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4247 | } | |
4248 | ||
df881293 | 4249 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 4250 | return -EINVAL; |
36aedc90 | 4251 | |
bdd3ae3d | 4252 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4253 | return -EINVAL; |
4254 | ||
f8bacc21 | 4255 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4256 | params.plink_action = |
f8bacc21 JB |
4257 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4258 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4259 | return -EINVAL; | |
4260 | } | |
2ec600d6 | 4261 | |
f8bacc21 | 4262 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4263 | params.plink_state = |
f8bacc21 JB |
4264 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4265 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4266 | return -EINVAL; | |
4267 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
4268 | } | |
9c3990aa | 4269 | |
3b1c5a53 MP |
4270 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4271 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4272 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4273 | ||
4274 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4275 | pm > NL80211_MESH_POWER_MAX) | |
4276 | return -EINVAL; | |
4277 | ||
4278 | params.local_pm = pm; | |
4279 | } | |
4280 | ||
77ee7c89 JB |
4281 | /* Include parameters for TDLS peer (will check later) */ |
4282 | err = nl80211_set_station_tdls(info, ¶ms); | |
4283 | if (err) | |
4284 | return err; | |
4285 | ||
4286 | params.vlan = get_vlan(info, rdev); | |
4287 | if (IS_ERR(params.vlan)) | |
4288 | return PTR_ERR(params.vlan); | |
4289 | ||
a97f4424 JB |
4290 | switch (dev->ieee80211_ptr->iftype) { |
4291 | case NL80211_IFTYPE_AP: | |
4292 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4293 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4294 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4295 | case NL80211_IFTYPE_STATION: |
267335d6 | 4296 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4297 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4298 | break; |
4299 | default: | |
77ee7c89 JB |
4300 | err = -EOPNOTSUPP; |
4301 | goto out_put_vlan; | |
034d655e JB |
4302 | } |
4303 | ||
77ee7c89 | 4304 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4305 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4306 | |
77ee7c89 | 4307 | out_put_vlan: |
5727ef1b JB |
4308 | if (params.vlan) |
4309 | dev_put(params.vlan); | |
3b85875a | 4310 | |
5727ef1b JB |
4311 | return err; |
4312 | } | |
4313 | ||
4314 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4315 | { | |
4c476991 | 4316 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4317 | int err; |
4c476991 | 4318 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4319 | struct station_parameters params; |
4320 | u8 *mac_addr = NULL; | |
4321 | ||
4322 | memset(¶ms, 0, sizeof(params)); | |
4323 | ||
984c311b JB |
4324 | if (!rdev->ops->add_station) |
4325 | return -EOPNOTSUPP; | |
4326 | ||
5727ef1b JB |
4327 | if (!info->attrs[NL80211_ATTR_MAC]) |
4328 | return -EINVAL; | |
4329 | ||
5727ef1b JB |
4330 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4331 | return -EINVAL; | |
4332 | ||
4333 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4334 | return -EINVAL; | |
4335 | ||
5e4b6f56 JM |
4336 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4337 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4338 | return -EINVAL; |
4339 | ||
5727ef1b JB |
4340 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4341 | params.supported_rates = | |
4342 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4343 | params.supported_rates_len = | |
4344 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4345 | params.listen_interval = | |
4346 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4347 | |
3d124ea2 | 4348 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4349 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4350 | else |
4351 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4352 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4353 | return -EINVAL; | |
51b50fbe | 4354 | |
9d62a986 JM |
4355 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4356 | params.capability = | |
4357 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4358 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4359 | } | |
4360 | ||
4361 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4362 | params.ext_capab = | |
4363 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4364 | params.ext_capab_len = | |
4365 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4366 | } | |
4367 | ||
36aedc90 JM |
4368 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4369 | params.ht_capa = | |
4370 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4371 | |
f461be3e MP |
4372 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4373 | params.vht_capa = | |
4374 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4375 | ||
60f4a7b1 MK |
4376 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4377 | params.opmode_notif_used = true; | |
4378 | params.opmode_notif = | |
4379 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4380 | } | |
4381 | ||
f8bacc21 | 4382 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4383 | params.plink_action = |
f8bacc21 JB |
4384 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4385 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4386 | return -EINVAL; | |
4387 | } | |
96b78dff | 4388 | |
c01fc9ad SD |
4389 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4390 | if (err) | |
4391 | return err; | |
4392 | ||
ff276691 JB |
4393 | err = nl80211_parse_sta_wme(info, ¶ms); |
4394 | if (err) | |
4395 | return err; | |
bdd90d5e | 4396 | |
bdd3ae3d | 4397 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4398 | return -EINVAL; |
4399 | ||
77ee7c89 JB |
4400 | /* When you run into this, adjust the code below for the new flag */ |
4401 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4402 | ||
bdd90d5e JB |
4403 | switch (dev->ieee80211_ptr->iftype) { |
4404 | case NL80211_IFTYPE_AP: | |
4405 | case NL80211_IFTYPE_AP_VLAN: | |
4406 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4407 | /* ignore WME attributes if iface/sta is not capable */ |
4408 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4409 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4410 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4411 | |
bdd90d5e | 4412 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4413 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4414 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4415 | return -EINVAL; |
bdd90d5e JB |
4416 | /* but don't bother the driver with it */ |
4417 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4418 | |
d582cffb JB |
4419 | /* allow authenticated/associated only if driver handles it */ |
4420 | if (!(rdev->wiphy.features & | |
4421 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4422 | params.sta_flags_mask & | |
4423 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4424 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4425 | return -EINVAL; | |
4426 | ||
bdd90d5e JB |
4427 | /* must be last in here for error handling */ |
4428 | params.vlan = get_vlan(info, rdev); | |
4429 | if (IS_ERR(params.vlan)) | |
4430 | return PTR_ERR(params.vlan); | |
4431 | break; | |
4432 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4433 | /* ignore uAPSD data */ |
4434 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4435 | ||
d582cffb JB |
4436 | /* associated is disallowed */ |
4437 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4438 | return -EINVAL; | |
bdd90d5e | 4439 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4440 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4441 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4442 | return -EINVAL; |
4443 | break; | |
4444 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4445 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4446 | /* ignore uAPSD data */ |
4447 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4448 | ||
77ee7c89 JB |
4449 | /* these are disallowed */ |
4450 | if (params.sta_flags_mask & | |
4451 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4452 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4453 | return -EINVAL; |
bdd90d5e JB |
4454 | /* Only TDLS peers can be added */ |
4455 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4456 | return -EINVAL; | |
4457 | /* Can only add if TDLS ... */ | |
4458 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4459 | return -EOPNOTSUPP; | |
4460 | /* ... with external setup is supported */ | |
4461 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4462 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4463 | /* |
4464 | * Older wpa_supplicant versions always mark the TDLS peer | |
4465 | * as authorized, but it shouldn't yet be. | |
4466 | */ | |
4467 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4468 | break; |
4469 | default: | |
4470 | return -EOPNOTSUPP; | |
c75786c9 EP |
4471 | } |
4472 | ||
bdd90d5e | 4473 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4474 | |
e35e4d28 | 4475 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4476 | |
5727ef1b JB |
4477 | if (params.vlan) |
4478 | dev_put(params.vlan); | |
5727ef1b JB |
4479 | return err; |
4480 | } | |
4481 | ||
4482 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4483 | { | |
4c476991 JB |
4484 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4485 | struct net_device *dev = info->user_ptr[1]; | |
89c771e5 JM |
4486 | struct station_del_parameters params; |
4487 | ||
4488 | memset(¶ms, 0, sizeof(params)); | |
5727ef1b JB |
4489 | |
4490 | if (info->attrs[NL80211_ATTR_MAC]) | |
89c771e5 | 4491 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5727ef1b | 4492 | |
e80cf853 | 4493 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4494 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4495 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4496 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4497 | return -EINVAL; | |
5727ef1b | 4498 | |
4c476991 JB |
4499 | if (!rdev->ops->del_station) |
4500 | return -EOPNOTSUPP; | |
3b85875a | 4501 | |
98856866 JM |
4502 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
4503 | params.subtype = | |
4504 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | |
4505 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | |
4506 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | |
4507 | return -EINVAL; | |
4508 | } else { | |
4509 | /* Default to Deauthentication frame */ | |
4510 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | |
4511 | } | |
4512 | ||
4513 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | |
4514 | params.reason_code = | |
4515 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
4516 | if (params.reason_code == 0) | |
4517 | return -EINVAL; /* 0 is reserved */ | |
4518 | } else { | |
4519 | /* Default to reason code 2 */ | |
4520 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | |
4521 | } | |
4522 | ||
89c771e5 | 4523 | return rdev_del_station(rdev, dev, ¶ms); |
5727ef1b JB |
4524 | } |
4525 | ||
15e47304 | 4526 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4527 | int flags, struct net_device *dev, |
4528 | u8 *dst, u8 *next_hop, | |
4529 | struct mpath_info *pinfo) | |
4530 | { | |
4531 | void *hdr; | |
4532 | struct nlattr *pinfoattr; | |
4533 | ||
1ef4c850 | 4534 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
2ec600d6 LCC |
4535 | if (!hdr) |
4536 | return -1; | |
4537 | ||
9360ffd1 DM |
4538 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4539 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4540 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4541 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4542 | goto nla_put_failure; | |
f5ea9120 | 4543 | |
2ec600d6 LCC |
4544 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4545 | if (!pinfoattr) | |
4546 | goto nla_put_failure; | |
9360ffd1 DM |
4547 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4548 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4549 | pinfo->frame_qlen)) | |
4550 | goto nla_put_failure; | |
4551 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4552 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4553 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4554 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4555 | pinfo->metric)) || | |
4556 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4557 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4558 | pinfo->exptime)) || | |
4559 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4560 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4561 | pinfo->flags)) || | |
4562 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4563 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4564 | pinfo->discovery_timeout)) || | |
4565 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4566 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4567 | pinfo->discovery_retries))) | |
4568 | goto nla_put_failure; | |
2ec600d6 LCC |
4569 | |
4570 | nla_nest_end(msg, pinfoattr); | |
4571 | ||
4572 | return genlmsg_end(msg, hdr); | |
4573 | ||
4574 | nla_put_failure: | |
bc3ed28c TG |
4575 | genlmsg_cancel(msg, hdr); |
4576 | return -EMSGSIZE; | |
2ec600d6 LCC |
4577 | } |
4578 | ||
4579 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4580 | struct netlink_callback *cb) |
2ec600d6 | 4581 | { |
2ec600d6 | 4582 | struct mpath_info pinfo; |
1b8ec87a | 4583 | struct cfg80211_registered_device *rdev; |
97990a06 | 4584 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4585 | u8 dst[ETH_ALEN]; |
4586 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4587 | int path_idx = cb->args[2]; |
2ec600d6 | 4588 | int err; |
2ec600d6 | 4589 | |
1b8ec87a | 4590 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
4591 | if (err) |
4592 | return err; | |
bba95fef | 4593 | |
1b8ec87a | 4594 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 4595 | err = -EOPNOTSUPP; |
bba95fef JB |
4596 | goto out_err; |
4597 | } | |
4598 | ||
97990a06 | 4599 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4600 | err = -EOPNOTSUPP; |
0448b5fc | 4601 | goto out_err; |
eec60b03 JM |
4602 | } |
4603 | ||
bba95fef | 4604 | while (1) { |
1b8ec87a | 4605 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 4606 | next_hop, &pinfo); |
bba95fef | 4607 | if (err == -ENOENT) |
2ec600d6 | 4608 | break; |
bba95fef | 4609 | if (err) |
3b85875a | 4610 | goto out_err; |
2ec600d6 | 4611 | |
15e47304 | 4612 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4613 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4614 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4615 | &pinfo) < 0) |
4616 | goto out; | |
2ec600d6 | 4617 | |
bba95fef | 4618 | path_idx++; |
2ec600d6 | 4619 | } |
2ec600d6 | 4620 | |
2ec600d6 | 4621 | |
bba95fef | 4622 | out: |
97990a06 | 4623 | cb->args[2] = path_idx; |
bba95fef | 4624 | err = skb->len; |
bba95fef | 4625 | out_err: |
1b8ec87a | 4626 | nl80211_finish_wdev_dump(rdev); |
bba95fef | 4627 | return err; |
2ec600d6 LCC |
4628 | } |
4629 | ||
4630 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4631 | { | |
4c476991 | 4632 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4633 | int err; |
4c476991 | 4634 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4635 | struct mpath_info pinfo; |
4636 | struct sk_buff *msg; | |
4637 | u8 *dst = NULL; | |
4638 | u8 next_hop[ETH_ALEN]; | |
4639 | ||
4640 | memset(&pinfo, 0, sizeof(pinfo)); | |
4641 | ||
4642 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4643 | return -EINVAL; | |
4644 | ||
4645 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4646 | ||
4c476991 JB |
4647 | if (!rdev->ops->get_mpath) |
4648 | return -EOPNOTSUPP; | |
2ec600d6 | 4649 | |
4c476991 JB |
4650 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4651 | return -EOPNOTSUPP; | |
eec60b03 | 4652 | |
e35e4d28 | 4653 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4654 | if (err) |
4c476991 | 4655 | return err; |
2ec600d6 | 4656 | |
fd2120ca | 4657 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4658 | if (!msg) |
4c476991 | 4659 | return -ENOMEM; |
2ec600d6 | 4660 | |
15e47304 | 4661 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4662 | dev, dst, next_hop, &pinfo) < 0) { |
4663 | nlmsg_free(msg); | |
4664 | return -ENOBUFS; | |
4665 | } | |
3b85875a | 4666 | |
4c476991 | 4667 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4668 | } |
4669 | ||
4670 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4671 | { | |
4c476991 JB |
4672 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4673 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4674 | u8 *dst = NULL; |
4675 | u8 *next_hop = NULL; | |
4676 | ||
4677 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4678 | return -EINVAL; | |
4679 | ||
4680 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4681 | return -EINVAL; | |
4682 | ||
4683 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4684 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4685 | ||
4c476991 JB |
4686 | if (!rdev->ops->change_mpath) |
4687 | return -EOPNOTSUPP; | |
35a8efe1 | 4688 | |
4c476991 JB |
4689 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4690 | return -EOPNOTSUPP; | |
2ec600d6 | 4691 | |
e35e4d28 | 4692 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4693 | } |
4c476991 | 4694 | |
2ec600d6 LCC |
4695 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4696 | { | |
4c476991 JB |
4697 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4698 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4699 | u8 *dst = NULL; |
4700 | u8 *next_hop = NULL; | |
4701 | ||
4702 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4703 | return -EINVAL; | |
4704 | ||
4705 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4706 | return -EINVAL; | |
4707 | ||
4708 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4709 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4710 | ||
4c476991 JB |
4711 | if (!rdev->ops->add_mpath) |
4712 | return -EOPNOTSUPP; | |
35a8efe1 | 4713 | |
4c476991 JB |
4714 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4715 | return -EOPNOTSUPP; | |
2ec600d6 | 4716 | |
e35e4d28 | 4717 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4718 | } |
4719 | ||
4720 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4721 | { | |
4c476991 JB |
4722 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4723 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4724 | u8 *dst = NULL; |
4725 | ||
4726 | if (info->attrs[NL80211_ATTR_MAC]) | |
4727 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4728 | ||
4c476991 JB |
4729 | if (!rdev->ops->del_mpath) |
4730 | return -EOPNOTSUPP; | |
3b85875a | 4731 | |
e35e4d28 | 4732 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4733 | } |
4734 | ||
66be7d2b HR |
4735 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
4736 | { | |
4737 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4738 | int err; | |
4739 | struct net_device *dev = info->user_ptr[1]; | |
4740 | struct mpath_info pinfo; | |
4741 | struct sk_buff *msg; | |
4742 | u8 *dst = NULL; | |
4743 | u8 mpp[ETH_ALEN]; | |
4744 | ||
4745 | memset(&pinfo, 0, sizeof(pinfo)); | |
4746 | ||
4747 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4748 | return -EINVAL; | |
4749 | ||
4750 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4751 | ||
4752 | if (!rdev->ops->get_mpp) | |
4753 | return -EOPNOTSUPP; | |
4754 | ||
4755 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
4756 | return -EOPNOTSUPP; | |
4757 | ||
4758 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | |
4759 | if (err) | |
4760 | return err; | |
4761 | ||
4762 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4763 | if (!msg) | |
4764 | return -ENOMEM; | |
4765 | ||
4766 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | |
4767 | dev, dst, mpp, &pinfo) < 0) { | |
4768 | nlmsg_free(msg); | |
4769 | return -ENOBUFS; | |
4770 | } | |
4771 | ||
4772 | return genlmsg_reply(msg, info); | |
4773 | } | |
4774 | ||
4775 | static int nl80211_dump_mpp(struct sk_buff *skb, | |
4776 | struct netlink_callback *cb) | |
4777 | { | |
4778 | struct mpath_info pinfo; | |
4779 | struct cfg80211_registered_device *rdev; | |
4780 | struct wireless_dev *wdev; | |
4781 | u8 dst[ETH_ALEN]; | |
4782 | u8 mpp[ETH_ALEN]; | |
4783 | int path_idx = cb->args[2]; | |
4784 | int err; | |
4785 | ||
4786 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | |
4787 | if (err) | |
4788 | return err; | |
4789 | ||
4790 | if (!rdev->ops->dump_mpp) { | |
4791 | err = -EOPNOTSUPP; | |
4792 | goto out_err; | |
4793 | } | |
4794 | ||
4795 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | |
4796 | err = -EOPNOTSUPP; | |
4797 | goto out_err; | |
4798 | } | |
4799 | ||
4800 | while (1) { | |
4801 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | |
4802 | mpp, &pinfo); | |
4803 | if (err == -ENOENT) | |
4804 | break; | |
4805 | if (err) | |
4806 | goto out_err; | |
4807 | ||
4808 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | |
4809 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
4810 | wdev->netdev, dst, mpp, | |
4811 | &pinfo) < 0) | |
4812 | goto out; | |
4813 | ||
4814 | path_idx++; | |
4815 | } | |
4816 | ||
4817 | out: | |
4818 | cb->args[2] = path_idx; | |
4819 | err = skb->len; | |
4820 | out_err: | |
4821 | nl80211_finish_wdev_dump(rdev); | |
4822 | return err; | |
4823 | } | |
4824 | ||
9f1ba906 JM |
4825 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4826 | { | |
4c476991 JB |
4827 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4828 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 4829 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 4830 | struct bss_parameters params; |
c56589ed | 4831 | int err; |
9f1ba906 JM |
4832 | |
4833 | memset(¶ms, 0, sizeof(params)); | |
4834 | /* default to not changing parameters */ | |
4835 | params.use_cts_prot = -1; | |
4836 | params.use_short_preamble = -1; | |
4837 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4838 | params.ap_isolate = -1; |
50b12f59 | 4839 | params.ht_opmode = -1; |
53cabad7 JB |
4840 | params.p2p_ctwindow = -1; |
4841 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4842 | |
4843 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4844 | params.use_cts_prot = | |
4845 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4846 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4847 | params.use_short_preamble = | |
4848 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4849 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4850 | params.use_short_slot_time = | |
4851 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4852 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4853 | params.basic_rates = | |
4854 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4855 | params.basic_rates_len = | |
4856 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4857 | } | |
fd8aaaf3 FF |
4858 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4859 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4860 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4861 | params.ht_opmode = | |
4862 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4863 | |
53cabad7 JB |
4864 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4865 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4866 | return -EINVAL; | |
4867 | params.p2p_ctwindow = | |
4868 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4869 | if (params.p2p_ctwindow < 0) | |
4870 | return -EINVAL; | |
4871 | if (params.p2p_ctwindow != 0 && | |
4872 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4873 | return -EINVAL; | |
4874 | } | |
4875 | ||
4876 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4877 | u8 tmp; | |
4878 | ||
4879 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4880 | return -EINVAL; | |
4881 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4882 | if (tmp > 1) | |
4883 | return -EINVAL; | |
4884 | params.p2p_opp_ps = tmp; | |
4885 | if (params.p2p_opp_ps && | |
4886 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4887 | return -EINVAL; | |
4888 | } | |
4889 | ||
4c476991 JB |
4890 | if (!rdev->ops->change_bss) |
4891 | return -EOPNOTSUPP; | |
9f1ba906 | 4892 | |
074ac8df | 4893 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4894 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4895 | return -EOPNOTSUPP; | |
3b85875a | 4896 | |
c56589ed SW |
4897 | wdev_lock(wdev); |
4898 | err = rdev_change_bss(rdev, dev, ¶ms); | |
4899 | wdev_unlock(wdev); | |
4900 | ||
4901 | return err; | |
9f1ba906 JM |
4902 | } |
4903 | ||
b54452b0 | 4904 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4905 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4906 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4907 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4908 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4909 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4910 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
089027e5 | 4911 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
b2e1b302 LR |
4912 | }; |
4913 | ||
4914 | static int parse_reg_rule(struct nlattr *tb[], | |
4915 | struct ieee80211_reg_rule *reg_rule) | |
4916 | { | |
4917 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4918 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4919 | ||
4920 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4921 | return -EINVAL; | |
4922 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4923 | return -EINVAL; | |
4924 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4925 | return -EINVAL; | |
b0dfd2ea JD |
4926 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
4927 | return -EINVAL; | |
b2e1b302 LR |
4928 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
4929 | return -EINVAL; | |
4930 | ||
4931 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4932 | ||
4933 | freq_range->start_freq_khz = | |
4934 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4935 | freq_range->end_freq_khz = | |
4936 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
b0dfd2ea JD |
4937 | freq_range->max_bandwidth_khz = |
4938 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
b2e1b302 LR |
4939 | |
4940 | power_rule->max_eirp = | |
4941 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4942 | ||
4943 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4944 | power_rule->max_antenna_gain = | |
4945 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4946 | ||
089027e5 JD |
4947 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
4948 | reg_rule->dfs_cac_ms = | |
4949 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
4950 | ||
b2e1b302 LR |
4951 | return 0; |
4952 | } | |
4953 | ||
4954 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4955 | { | |
b2e1b302 | 4956 | char *data = NULL; |
57b5ce07 | 4957 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4958 | |
80778f18 LR |
4959 | /* |
4960 | * You should only get this when cfg80211 hasn't yet initialized | |
4961 | * completely when built-in to the kernel right between the time | |
4962 | * window between nl80211_init() and regulatory_init(), if that is | |
4963 | * even possible. | |
4964 | */ | |
458f4f9e | 4965 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4966 | return -EINPROGRESS; |
80778f18 | 4967 | |
57b5ce07 LR |
4968 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4969 | user_reg_hint_type = | |
4970 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4971 | else | |
4972 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4973 | ||
4974 | switch (user_reg_hint_type) { | |
4975 | case NL80211_USER_REG_HINT_USER: | |
4976 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
4977 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4978 | return -EINVAL; | |
4979 | ||
4980 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4981 | return regulatory_hint_user(data, user_reg_hint_type); | |
4982 | case NL80211_USER_REG_HINT_INDOOR: | |
4983 | return regulatory_hint_indoor_user(); | |
57b5ce07 LR |
4984 | default: |
4985 | return -EINVAL; | |
4986 | } | |
b2e1b302 LR |
4987 | } |
4988 | ||
24bdd9f4 | 4989 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4990 | struct genl_info *info) |
93da9cc1 | 4991 | { |
4c476991 | 4992 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4993 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4994 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4995 | struct mesh_config cur_params; | |
4996 | int err = 0; | |
93da9cc1 | 4997 | void *hdr; |
4998 | struct nlattr *pinfoattr; | |
4999 | struct sk_buff *msg; | |
5000 | ||
29cbe68c JB |
5001 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5002 | return -EOPNOTSUPP; | |
5003 | ||
24bdd9f4 | 5004 | if (!rdev->ops->get_mesh_config) |
4c476991 | 5005 | return -EOPNOTSUPP; |
f3f92586 | 5006 | |
29cbe68c JB |
5007 | wdev_lock(wdev); |
5008 | /* If not connected, get default parameters */ | |
5009 | if (!wdev->mesh_id_len) | |
5010 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
5011 | else | |
e35e4d28 | 5012 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
5013 | wdev_unlock(wdev); |
5014 | ||
93da9cc1 | 5015 | if (err) |
4c476991 | 5016 | return err; |
93da9cc1 | 5017 | |
5018 | /* Draw up a netlink message to send back */ | |
fd2120ca | 5019 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
5020 | if (!msg) |
5021 | return -ENOMEM; | |
15e47304 | 5022 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 5023 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 5024 | if (!hdr) |
efe1cf0c | 5025 | goto out; |
24bdd9f4 | 5026 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 5027 | if (!pinfoattr) |
5028 | goto nla_put_failure; | |
9360ffd1 DM |
5029 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5030 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
5031 | cur_params.dot11MeshRetryTimeout) || | |
5032 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
5033 | cur_params.dot11MeshConfirmTimeout) || | |
5034 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
5035 | cur_params.dot11MeshHoldingTimeout) || | |
5036 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
5037 | cur_params.dot11MeshMaxPeerLinks) || | |
5038 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
5039 | cur_params.dot11MeshMaxRetries) || | |
5040 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
5041 | cur_params.dot11MeshTTL) || | |
5042 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
5043 | cur_params.element_ttl) || | |
5044 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
5045 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
5046 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5047 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
5048 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5049 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
5050 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
5051 | cur_params.path_refresh_time) || | |
5052 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
5053 | cur_params.min_discovery_timeout) || | |
5054 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
5055 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
5056 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
5057 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
5058 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
5059 | cur_params.dot11MeshHWMPperrMinInterval) || | |
5060 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
5061 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
5062 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5063 | cur_params.dot11MeshHWMPRootMode) || | |
5064 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
5065 | cur_params.dot11MeshHWMPRannInterval) || | |
5066 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
5067 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
5068 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
5069 | cur_params.dot11MeshForwarding) || | |
5070 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
5071 | cur_params.rssi_threshold) || |
5072 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
5073 | cur_params.ht_opmode) || |
5074 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
5075 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
5076 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
5077 | cur_params.dot11MeshHWMProotInterval) || |
5078 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
5079 | cur_params.dot11MeshHWMPconfirmationInterval) || |
5080 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
5081 | cur_params.power_mode) || | |
5082 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
5083 | cur_params.dot11MeshAwakeWindowDuration) || |
5084 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5085 | cur_params.plink_timeout)) | |
9360ffd1 | 5086 | goto nla_put_failure; |
93da9cc1 | 5087 | nla_nest_end(msg, pinfoattr); |
5088 | genlmsg_end(msg, hdr); | |
4c476991 | 5089 | return genlmsg_reply(msg, info); |
93da9cc1 | 5090 | |
3b85875a | 5091 | nla_put_failure: |
93da9cc1 | 5092 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 5093 | out: |
d080e275 | 5094 | nlmsg_free(msg); |
4c476991 | 5095 | return -ENOBUFS; |
93da9cc1 | 5096 | } |
5097 | ||
b54452b0 | 5098 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 5099 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
5100 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
5101 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
5102 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
5103 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
5104 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 5105 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 5106 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 5107 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 5108 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
5109 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
5110 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
5111 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
5112 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 5113 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 5114 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 5115 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 5116 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 5117 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 5118 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
5119 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
5120 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
5121 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
5122 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 5123 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
5124 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
5125 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 5126 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 5127 | }; |
5128 | ||
c80d545d JC |
5129 | static const struct nla_policy |
5130 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 5131 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
5132 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
5133 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 5134 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 5135 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 5136 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 5137 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 5138 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 5139 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
5140 | }; |
5141 | ||
24bdd9f4 | 5142 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
5143 | struct mesh_config *cfg, |
5144 | u32 *mask_out) | |
93da9cc1 | 5145 | { |
93da9cc1 | 5146 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 5147 | u32 mask = 0; |
93da9cc1 | 5148 | |
ea54fba2 MP |
5149 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
5150 | do { \ | |
5151 | if (tb[attr]) { \ | |
5152 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
5153 | return -EINVAL; \ | |
5154 | cfg->param = fn(tb[attr]); \ | |
5155 | mask |= (1 << (attr - 1)); \ | |
5156 | } \ | |
5157 | } while (0) | |
bd90fdcc JB |
5158 | |
5159 | ||
24bdd9f4 | 5160 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 5161 | return -EINVAL; |
5162 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 5163 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 5164 | nl80211_meshconf_params_policy)) |
93da9cc1 | 5165 | return -EINVAL; |
5166 | ||
93da9cc1 | 5167 | /* This makes sure that there aren't more than 32 mesh config |
5168 | * parameters (otherwise our bitfield scheme would not work.) */ | |
5169 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
5170 | ||
5171 | /* Fill in the params struct */ | |
ea54fba2 | 5172 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
5173 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
5174 | nla_get_u16); | |
ea54fba2 | 5175 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
5176 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
5177 | nla_get_u16); | |
ea54fba2 | 5178 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
5179 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
5180 | nla_get_u16); | |
ea54fba2 | 5181 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
5182 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
5183 | nla_get_u16); | |
ea54fba2 | 5184 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
5185 | mask, NL80211_MESHCONF_MAX_RETRIES, |
5186 | nla_get_u8); | |
ea54fba2 | 5187 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 5188 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 5189 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
5190 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
5191 | nla_get_u8); | |
ea54fba2 | 5192 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
5193 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
5194 | nla_get_u8); | |
ea54fba2 MP |
5195 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
5196 | 1, 255, mask, | |
a4f606ea CYY |
5197 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5198 | nla_get_u32); | |
ea54fba2 | 5199 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
5200 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5201 | nla_get_u8); | |
ea54fba2 | 5202 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
5203 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
5204 | nla_get_u32); | |
ea54fba2 | 5205 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
5206 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
5207 | nla_get_u16); | |
ea54fba2 MP |
5208 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
5209 | 1, 65535, mask, | |
a4f606ea CYY |
5210 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
5211 | nla_get_u32); | |
93da9cc1 | 5212 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
5213 | 1, 65535, mask, |
5214 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 5215 | nla_get_u16); |
dca7e943 | 5216 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
5217 | 1, 65535, mask, |
5218 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 5219 | nla_get_u16); |
93da9cc1 | 5220 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5221 | dot11MeshHWMPnetDiameterTraversalTime, |
5222 | 1, 65535, mask, | |
a4f606ea CYY |
5223 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
5224 | nla_get_u16); | |
ea54fba2 MP |
5225 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
5226 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5227 | nla_get_u8); | |
5228 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
5229 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 5230 | nla_get_u16); |
63c5723b | 5231 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5232 | dot11MeshGateAnnouncementProtocol, 0, 1, |
5233 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 5234 | nla_get_u8); |
ea54fba2 | 5235 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
5236 | mask, NL80211_MESHCONF_FORWARDING, |
5237 | nla_get_u8); | |
83374fe9 | 5238 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 5239 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
83374fe9 | 5240 | nla_get_s32); |
ea54fba2 | 5241 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 5242 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
5243 | nla_get_u16); |
5244 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 5245 | 1, 65535, mask, |
ac1073a6 CYY |
5246 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
5247 | nla_get_u32); | |
ea54fba2 | 5248 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 5249 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
5250 | nla_get_u16); |
5251 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
5252 | dot11MeshHWMPconfirmationInterval, |
5253 | 1, 65535, mask, | |
728b19e5 | 5254 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 5255 | nla_get_u16); |
3b1c5a53 MP |
5256 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
5257 | NL80211_MESH_POWER_ACTIVE, | |
5258 | NL80211_MESH_POWER_MAX, | |
5259 | mask, NL80211_MESHCONF_POWER_MODE, | |
5260 | nla_get_u32); | |
5261 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
5262 | 0, 65535, mask, | |
5263 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
8e7c0538 CT |
5264 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
5265 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5266 | nla_get_u32); | |
bd90fdcc JB |
5267 | if (mask_out) |
5268 | *mask_out = mask; | |
c80d545d | 5269 | |
bd90fdcc JB |
5270 | return 0; |
5271 | ||
5272 | #undef FILL_IN_MESH_PARAM_IF_SET | |
5273 | } | |
5274 | ||
c80d545d JC |
5275 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
5276 | struct mesh_setup *setup) | |
5277 | { | |
bb2798d4 | 5278 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
5279 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
5280 | ||
5281 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
5282 | return -EINVAL; | |
5283 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
5284 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
5285 | nl80211_mesh_setup_params_policy)) | |
5286 | return -EINVAL; | |
5287 | ||
d299a1f2 JC |
5288 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
5289 | setup->sync_method = | |
5290 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
5291 | IEEE80211_SYNC_METHOD_VENDOR : | |
5292 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
5293 | ||
c80d545d JC |
5294 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
5295 | setup->path_sel_proto = | |
5296 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5297 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5298 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5299 | ||
5300 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5301 | setup->path_metric = | |
5302 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5303 | IEEE80211_PATH_METRIC_VENDOR : | |
5304 | IEEE80211_PATH_METRIC_AIRTIME; | |
5305 | ||
581a8b0f JC |
5306 | |
5307 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 5308 | struct nlattr *ieattr = |
581a8b0f | 5309 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5310 | if (!is_valid_ie_attr(ieattr)) |
5311 | return -EINVAL; | |
581a8b0f JC |
5312 | setup->ie = nla_data(ieattr); |
5313 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5314 | } |
bb2798d4 TP |
5315 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5316 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5317 | return -EINVAL; | |
5318 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5319 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5320 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5321 | if (setup->is_secure) |
5322 | setup->user_mpm = true; | |
c80d545d | 5323 | |
6e16d90b CT |
5324 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5325 | if (!setup->user_mpm) | |
5326 | return -EINVAL; | |
5327 | setup->auth_id = | |
5328 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5329 | } | |
5330 | ||
c80d545d JC |
5331 | return 0; |
5332 | } | |
5333 | ||
24bdd9f4 | 5334 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5335 | struct genl_info *info) |
bd90fdcc JB |
5336 | { |
5337 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5338 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5339 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5340 | struct mesh_config cfg; |
5341 | u32 mask; | |
5342 | int err; | |
5343 | ||
29cbe68c JB |
5344 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5345 | return -EOPNOTSUPP; | |
5346 | ||
24bdd9f4 | 5347 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5348 | return -EOPNOTSUPP; |
5349 | ||
24bdd9f4 | 5350 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5351 | if (err) |
5352 | return err; | |
5353 | ||
29cbe68c JB |
5354 | wdev_lock(wdev); |
5355 | if (!wdev->mesh_id_len) | |
5356 | err = -ENOLINK; | |
5357 | ||
5358 | if (!err) | |
e35e4d28 | 5359 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5360 | |
5361 | wdev_unlock(wdev); | |
5362 | ||
5363 | return err; | |
93da9cc1 | 5364 | } |
5365 | ||
ad30ca2c AN |
5366 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
5367 | struct sk_buff *msg) | |
f130347c | 5368 | { |
f130347c LR |
5369 | struct nlattr *nl_reg_rules; |
5370 | unsigned int i; | |
f130347c | 5371 | |
458f4f9e JB |
5372 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
5373 | (regdom->dfs_region && | |
5374 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
ad30ca2c | 5375 | goto nla_put_failure; |
458f4f9e | 5376 | |
f130347c LR |
5377 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5378 | if (!nl_reg_rules) | |
ad30ca2c | 5379 | goto nla_put_failure; |
f130347c | 5380 | |
458f4f9e | 5381 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5382 | struct nlattr *nl_reg_rule; |
5383 | const struct ieee80211_reg_rule *reg_rule; | |
5384 | const struct ieee80211_freq_range *freq_range; | |
5385 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 5386 | unsigned int max_bandwidth_khz; |
f130347c | 5387 | |
458f4f9e | 5388 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5389 | freq_range = ®_rule->freq_range; |
5390 | power_rule = ®_rule->power_rule; | |
5391 | ||
5392 | nl_reg_rule = nla_nest_start(msg, i); | |
5393 | if (!nl_reg_rule) | |
ad30ca2c | 5394 | goto nla_put_failure; |
f130347c | 5395 | |
97524820 JD |
5396 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
5397 | if (!max_bandwidth_khz) | |
5398 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
5399 | reg_rule); | |
5400 | ||
9360ffd1 DM |
5401 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5402 | reg_rule->flags) || | |
5403 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5404 | freq_range->start_freq_khz) || | |
5405 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5406 | freq_range->end_freq_khz) || | |
5407 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 5408 | max_bandwidth_khz) || |
9360ffd1 DM |
5409 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
5410 | power_rule->max_antenna_gain) || | |
5411 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
5412 | power_rule->max_eirp) || |
5413 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
5414 | reg_rule->dfs_cac_ms)) | |
ad30ca2c | 5415 | goto nla_put_failure; |
f130347c LR |
5416 | |
5417 | nla_nest_end(msg, nl_reg_rule); | |
5418 | } | |
5419 | ||
5420 | nla_nest_end(msg, nl_reg_rules); | |
ad30ca2c AN |
5421 | return 0; |
5422 | ||
5423 | nla_put_failure: | |
5424 | return -EMSGSIZE; | |
5425 | } | |
5426 | ||
5427 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) | |
5428 | { | |
5429 | const struct ieee80211_regdomain *regdom = NULL; | |
5430 | struct cfg80211_registered_device *rdev; | |
5431 | struct wiphy *wiphy = NULL; | |
5432 | struct sk_buff *msg; | |
5433 | void *hdr; | |
5434 | ||
5435 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5436 | if (!msg) | |
5437 | return -ENOBUFS; | |
5438 | ||
5439 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
5440 | NL80211_CMD_GET_REG); | |
5441 | if (!hdr) | |
5442 | goto put_failure; | |
5443 | ||
5444 | if (info->attrs[NL80211_ATTR_WIPHY]) { | |
1bdd716c AN |
5445 | bool self_managed; |
5446 | ||
ad30ca2c AN |
5447 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
5448 | if (IS_ERR(rdev)) { | |
5449 | nlmsg_free(msg); | |
5450 | return PTR_ERR(rdev); | |
5451 | } | |
5452 | ||
5453 | wiphy = &rdev->wiphy; | |
1bdd716c AN |
5454 | self_managed = wiphy->regulatory_flags & |
5455 | REGULATORY_WIPHY_SELF_MANAGED; | |
ad30ca2c AN |
5456 | regdom = get_wiphy_regdom(wiphy); |
5457 | ||
1bdd716c AN |
5458 | /* a self-managed-reg device must have a private regdom */ |
5459 | if (WARN_ON(!regdom && self_managed)) { | |
5460 | nlmsg_free(msg); | |
5461 | return -EINVAL; | |
5462 | } | |
5463 | ||
ad30ca2c AN |
5464 | if (regdom && |
5465 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5466 | goto nla_put_failure; | |
5467 | } | |
5468 | ||
5469 | if (!wiphy && reg_last_request_cell_base() && | |
5470 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5471 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5472 | goto nla_put_failure; | |
5473 | ||
5474 | rcu_read_lock(); | |
5475 | ||
5476 | if (!regdom) | |
5477 | regdom = rcu_dereference(cfg80211_regdomain); | |
5478 | ||
5479 | if (nl80211_put_regdom(regdom, msg)) | |
5480 | goto nla_put_failure_rcu; | |
5481 | ||
5482 | rcu_read_unlock(); | |
f130347c LR |
5483 | |
5484 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5485 | return genlmsg_reply(msg, info); |
f130347c | 5486 | |
458f4f9e JB |
5487 | nla_put_failure_rcu: |
5488 | rcu_read_unlock(); | |
f130347c LR |
5489 | nla_put_failure: |
5490 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5491 | put_failure: |
d080e275 | 5492 | nlmsg_free(msg); |
5fe231e8 | 5493 | return -EMSGSIZE; |
f130347c LR |
5494 | } |
5495 | ||
ad30ca2c AN |
5496 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
5497 | u32 seq, int flags, struct wiphy *wiphy, | |
5498 | const struct ieee80211_regdomain *regdom) | |
5499 | { | |
5500 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | |
5501 | NL80211_CMD_GET_REG); | |
5502 | ||
5503 | if (!hdr) | |
5504 | return -1; | |
5505 | ||
5506 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); | |
5507 | ||
5508 | if (nl80211_put_regdom(regdom, msg)) | |
5509 | goto nla_put_failure; | |
5510 | ||
5511 | if (!wiphy && reg_last_request_cell_base() && | |
5512 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5513 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5514 | goto nla_put_failure; | |
5515 | ||
5516 | if (wiphy && | |
5517 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5518 | goto nla_put_failure; | |
5519 | ||
1bdd716c AN |
5520 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
5521 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
5522 | goto nla_put_failure; | |
5523 | ||
ad30ca2c AN |
5524 | return genlmsg_end(msg, hdr); |
5525 | ||
5526 | nla_put_failure: | |
5527 | genlmsg_cancel(msg, hdr); | |
5528 | return -EMSGSIZE; | |
5529 | } | |
5530 | ||
5531 | static int nl80211_get_reg_dump(struct sk_buff *skb, | |
5532 | struct netlink_callback *cb) | |
5533 | { | |
5534 | const struct ieee80211_regdomain *regdom = NULL; | |
5535 | struct cfg80211_registered_device *rdev; | |
5536 | int err, reg_idx, start = cb->args[2]; | |
5537 | ||
5538 | rtnl_lock(); | |
5539 | ||
5540 | if (cfg80211_regdomain && start == 0) { | |
5541 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5542 | NLM_F_MULTI, NULL, | |
5543 | rtnl_dereference(cfg80211_regdomain)); | |
5544 | if (err < 0) | |
5545 | goto out_err; | |
5546 | } | |
5547 | ||
5548 | /* the global regdom is idx 0 */ | |
5549 | reg_idx = 1; | |
5550 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | |
5551 | regdom = get_wiphy_regdom(&rdev->wiphy); | |
5552 | if (!regdom) | |
5553 | continue; | |
5554 | ||
5555 | if (++reg_idx <= start) | |
5556 | continue; | |
5557 | ||
5558 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5559 | NLM_F_MULTI, &rdev->wiphy, regdom); | |
5560 | if (err < 0) { | |
5561 | reg_idx--; | |
5562 | break; | |
5563 | } | |
5564 | } | |
5565 | ||
5566 | cb->args[2] = reg_idx; | |
5567 | err = skb->len; | |
5568 | out_err: | |
5569 | rtnl_unlock(); | |
5570 | return err; | |
5571 | } | |
5572 | ||
b2e1b302 LR |
5573 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5574 | { | |
5575 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5576 | struct nlattr *nl_reg_rule; | |
ea372c54 JB |
5577 | char *alpha2; |
5578 | int rem_reg_rules, r; | |
b2e1b302 | 5579 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
4c7d3982 | 5580 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
ea372c54 | 5581 | struct ieee80211_regdomain *rd; |
b2e1b302 LR |
5582 | |
5583 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5584 | return -EINVAL; | |
5585 | ||
5586 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5587 | return -EINVAL; | |
5588 | ||
5589 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5590 | ||
8b60b078 LR |
5591 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5592 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5593 | ||
b2e1b302 | 5594 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5595 | rem_reg_rules) { |
b2e1b302 LR |
5596 | num_rules++; |
5597 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5598 | return -EINVAL; |
b2e1b302 LR |
5599 | } |
5600 | ||
e438768f LR |
5601 | if (!reg_is_valid_request(alpha2)) |
5602 | return -EINVAL; | |
5603 | ||
b2e1b302 | 5604 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5605 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5606 | |
5607 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5608 | if (!rd) |
5609 | return -ENOMEM; | |
b2e1b302 LR |
5610 | |
5611 | rd->n_reg_rules = num_rules; | |
5612 | rd->alpha2[0] = alpha2[0]; | |
5613 | rd->alpha2[1] = alpha2[1]; | |
5614 | ||
8b60b078 LR |
5615 | /* |
5616 | * Disable DFS master mode if the DFS region was | |
5617 | * not supported or known on this kernel. | |
5618 | */ | |
5619 | if (reg_supported_dfs_region(dfs_region)) | |
5620 | rd->dfs_region = dfs_region; | |
5621 | ||
b2e1b302 | 5622 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5623 | rem_reg_rules) { |
ae811e21 JB |
5624 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
5625 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
5626 | reg_rule_policy); | |
5627 | if (r) | |
5628 | goto bad_reg; | |
b2e1b302 LR |
5629 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5630 | if (r) | |
5631 | goto bad_reg; | |
5632 | ||
5633 | rule_idx++; | |
5634 | ||
d0e18f83 LR |
5635 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5636 | r = -EINVAL; | |
b2e1b302 | 5637 | goto bad_reg; |
d0e18f83 | 5638 | } |
b2e1b302 LR |
5639 | } |
5640 | ||
b2e1b302 | 5641 | r = set_regdom(rd); |
6913b49a | 5642 | /* set_regdom took ownership */ |
1a919318 | 5643 | rd = NULL; |
b2e1b302 | 5644 | |
d2372b31 | 5645 | bad_reg: |
b2e1b302 | 5646 | kfree(rd); |
d0e18f83 | 5647 | return r; |
b2e1b302 LR |
5648 | } |
5649 | ||
83f5e2cf JB |
5650 | static int validate_scan_freqs(struct nlattr *freqs) |
5651 | { | |
5652 | struct nlattr *attr1, *attr2; | |
5653 | int n_channels = 0, tmp1, tmp2; | |
5654 | ||
5655 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5656 | n_channels++; | |
5657 | /* | |
5658 | * Some hardware has a limited channel list for | |
5659 | * scanning, and it is pretty much nonsensical | |
5660 | * to scan for a channel twice, so disallow that | |
5661 | * and don't require drivers to check that the | |
5662 | * channel list they get isn't longer than what | |
5663 | * they can scan, as long as they can scan all | |
5664 | * the channels they registered at once. | |
5665 | */ | |
5666 | nla_for_each_nested(attr2, freqs, tmp2) | |
5667 | if (attr1 != attr2 && | |
5668 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5669 | return 0; | |
5670 | } | |
5671 | ||
5672 | return n_channels; | |
5673 | } | |
5674 | ||
ad2b26ab JB |
5675 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
5676 | u8 *mac_addr, u8 *mac_addr_mask) | |
5677 | { | |
5678 | int i; | |
5679 | ||
5680 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { | |
5681 | memset(mac_addr, 0, ETH_ALEN); | |
5682 | memset(mac_addr_mask, 0, ETH_ALEN); | |
5683 | mac_addr[0] = 0x2; | |
5684 | mac_addr_mask[0] = 0x3; | |
5685 | ||
5686 | return 0; | |
5687 | } | |
5688 | ||
5689 | /* need both or none */ | |
5690 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) | |
5691 | return -EINVAL; | |
5692 | ||
5693 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); | |
5694 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); | |
5695 | ||
5696 | /* don't allow or configure an mcast address */ | |
5697 | if (!is_multicast_ether_addr(mac_addr_mask) || | |
5698 | is_multicast_ether_addr(mac_addr)) | |
5699 | return -EINVAL; | |
5700 | ||
5701 | /* | |
5702 | * allow users to pass a MAC address that has bits set outside | |
5703 | * of the mask, but don't bother drivers with having to deal | |
5704 | * with such bits | |
5705 | */ | |
5706 | for (i = 0; i < ETH_ALEN; i++) | |
5707 | mac_addr[i] &= mac_addr_mask[i]; | |
5708 | ||
5709 | return 0; | |
5710 | } | |
5711 | ||
2a519311 JB |
5712 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5713 | { | |
4c476991 | 5714 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5715 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5716 | struct cfg80211_scan_request *request; |
2a519311 JB |
5717 | struct nlattr *attr; |
5718 | struct wiphy *wiphy; | |
83f5e2cf | 5719 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5720 | size_t ie_len; |
2a519311 | 5721 | |
f4a11bb0 JB |
5722 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5723 | return -EINVAL; | |
5724 | ||
79c97e97 | 5725 | wiphy = &rdev->wiphy; |
2a519311 | 5726 | |
4c476991 JB |
5727 | if (!rdev->ops->scan) |
5728 | return -EOPNOTSUPP; | |
2a519311 | 5729 | |
f9d15d16 | 5730 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
5731 | err = -EBUSY; |
5732 | goto unlock; | |
5733 | } | |
2a519311 JB |
5734 | |
5735 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5736 | n_channels = validate_scan_freqs( |
5737 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5738 | if (!n_channels) { |
5739 | err = -EINVAL; | |
5740 | goto unlock; | |
5741 | } | |
2a519311 | 5742 | } else { |
bdfbec2d | 5743 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
5744 | } |
5745 | ||
5746 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5747 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5748 | n_ssids++; | |
5749 | ||
f9f47529 JB |
5750 | if (n_ssids > wiphy->max_scan_ssids) { |
5751 | err = -EINVAL; | |
5752 | goto unlock; | |
5753 | } | |
2a519311 | 5754 | |
70692ad2 JM |
5755 | if (info->attrs[NL80211_ATTR_IE]) |
5756 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5757 | else | |
5758 | ie_len = 0; | |
5759 | ||
f9f47529 JB |
5760 | if (ie_len > wiphy->max_scan_ie_len) { |
5761 | err = -EINVAL; | |
5762 | goto unlock; | |
5763 | } | |
18a83659 | 5764 | |
2a519311 | 5765 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5766 | + sizeof(*request->ssids) * n_ssids |
5767 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5768 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5769 | if (!request) { |
5770 | err = -ENOMEM; | |
5771 | goto unlock; | |
5772 | } | |
2a519311 | 5773 | |
2a519311 | 5774 | if (n_ssids) |
5ba63533 | 5775 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5776 | request->n_ssids = n_ssids; |
70692ad2 JM |
5777 | if (ie_len) { |
5778 | if (request->ssids) | |
5779 | request->ie = (void *)(request->ssids + n_ssids); | |
5780 | else | |
5781 | request->ie = (void *)(request->channels + n_channels); | |
5782 | } | |
2a519311 | 5783 | |
584991dc | 5784 | i = 0; |
2a519311 JB |
5785 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5786 | /* user specified, bail out if channel not found */ | |
2a519311 | 5787 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5788 | struct ieee80211_channel *chan; |
5789 | ||
5790 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5791 | ||
5792 | if (!chan) { | |
2a519311 JB |
5793 | err = -EINVAL; |
5794 | goto out_free; | |
5795 | } | |
584991dc JB |
5796 | |
5797 | /* ignore disabled channels */ | |
5798 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5799 | continue; | |
5800 | ||
5801 | request->channels[i] = chan; | |
2a519311 JB |
5802 | i++; |
5803 | } | |
5804 | } else { | |
34850ab2 JB |
5805 | enum ieee80211_band band; |
5806 | ||
2a519311 | 5807 | /* all channels */ |
2a519311 JB |
5808 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5809 | int j; | |
5810 | if (!wiphy->bands[band]) | |
5811 | continue; | |
5812 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5813 | struct ieee80211_channel *chan; |
5814 | ||
5815 | chan = &wiphy->bands[band]->channels[j]; | |
5816 | ||
5817 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5818 | continue; | |
5819 | ||
5820 | request->channels[i] = chan; | |
2a519311 JB |
5821 | i++; |
5822 | } | |
5823 | } | |
5824 | } | |
5825 | ||
584991dc JB |
5826 | if (!i) { |
5827 | err = -EINVAL; | |
5828 | goto out_free; | |
5829 | } | |
5830 | ||
5831 | request->n_channels = i; | |
5832 | ||
2a519311 JB |
5833 | i = 0; |
5834 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5835 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5836 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5837 | err = -EINVAL; |
5838 | goto out_free; | |
5839 | } | |
57a27e1d | 5840 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5841 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5842 | i++; |
5843 | } | |
5844 | } | |
5845 | ||
70692ad2 JM |
5846 | if (info->attrs[NL80211_ATTR_IE]) { |
5847 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5848 | memcpy((void *)request->ie, |
5849 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5850 | request->ie_len); |
5851 | } | |
5852 | ||
34850ab2 | 5853 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5854 | if (wiphy->bands[i]) |
5855 | request->rates[i] = | |
5856 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5857 | |
5858 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5859 | nla_for_each_nested(attr, | |
5860 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5861 | tmp) { | |
5862 | enum ieee80211_band band = nla_type(attr); | |
5863 | ||
84404623 | 5864 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5865 | err = -EINVAL; |
5866 | goto out_free; | |
5867 | } | |
1b09cd82 FF |
5868 | |
5869 | if (!wiphy->bands[band]) | |
5870 | continue; | |
5871 | ||
34850ab2 JB |
5872 | err = ieee80211_get_ratemask(wiphy->bands[band], |
5873 | nla_data(attr), | |
5874 | nla_len(attr), | |
5875 | &request->rates[band]); | |
5876 | if (err) | |
5877 | goto out_free; | |
5878 | } | |
5879 | } | |
5880 | ||
46856bbf | 5881 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5882 | request->flags = nla_get_u32( |
5883 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5884 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5885 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5886 | err = -EOPNOTSUPP; |
5887 | goto out_free; | |
5888 | } | |
ad2b26ab JB |
5889 | |
5890 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
5891 | if (!(wiphy->features & | |
5892 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { | |
5893 | err = -EOPNOTSUPP; | |
5894 | goto out_free; | |
5895 | } | |
5896 | ||
5897 | if (wdev->current_bss) { | |
5898 | err = -EOPNOTSUPP; | |
5899 | goto out_free; | |
5900 | } | |
5901 | ||
5902 | err = nl80211_parse_random_mac(info->attrs, | |
5903 | request->mac_addr, | |
5904 | request->mac_addr_mask); | |
5905 | if (err) | |
5906 | goto out_free; | |
5907 | } | |
46856bbf | 5908 | } |
ed473771 | 5909 | |
e9f935e3 RM |
5910 | request->no_cck = |
5911 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5912 | ||
fd014284 | 5913 | request->wdev = wdev; |
79c97e97 | 5914 | request->wiphy = &rdev->wiphy; |
15d6030b | 5915 | request->scan_start = jiffies; |
2a519311 | 5916 | |
79c97e97 | 5917 | rdev->scan_req = request; |
e35e4d28 | 5918 | err = rdev_scan(rdev, request); |
2a519311 | 5919 | |
463d0183 | 5920 | if (!err) { |
fd014284 JB |
5921 | nl80211_send_scan_start(rdev, wdev); |
5922 | if (wdev->netdev) | |
5923 | dev_hold(wdev->netdev); | |
4c476991 | 5924 | } else { |
2a519311 | 5925 | out_free: |
79c97e97 | 5926 | rdev->scan_req = NULL; |
2a519311 JB |
5927 | kfree(request); |
5928 | } | |
3b85875a | 5929 | |
f9f47529 | 5930 | unlock: |
2a519311 JB |
5931 | return err; |
5932 | } | |
5933 | ||
256da02d | 5934 | static struct cfg80211_sched_scan_request * |
ad2b26ab | 5935 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
256da02d | 5936 | struct nlattr **attrs) |
807f8a8c LC |
5937 | { |
5938 | struct cfg80211_sched_scan_request *request; | |
807f8a8c | 5939 | struct nlattr *attr; |
a1f1c21c | 5940 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5941 | u32 interval; |
807f8a8c LC |
5942 | enum ieee80211_band band; |
5943 | size_t ie_len; | |
a1f1c21c | 5944 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 5945 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c | 5946 | |
256da02d LC |
5947 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
5948 | return ERR_PTR(-EINVAL); | |
807f8a8c | 5949 | |
256da02d LC |
5950 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5951 | return ERR_PTR(-EINVAL); | |
bbe6ad6d | 5952 | |
256da02d | 5953 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
bbe6ad6d | 5954 | if (interval == 0) |
256da02d | 5955 | return ERR_PTR(-EINVAL); |
807f8a8c | 5956 | |
256da02d | 5957 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c | 5958 | n_channels = validate_scan_freqs( |
256da02d | 5959 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
807f8a8c | 5960 | if (!n_channels) |
256da02d | 5961 | return ERR_PTR(-EINVAL); |
807f8a8c | 5962 | } else { |
bdfbec2d | 5963 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
5964 | } |
5965 | ||
256da02d LC |
5966 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
5967 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c LC |
5968 | tmp) |
5969 | n_ssids++; | |
5970 | ||
93b6aa69 | 5971 | if (n_ssids > wiphy->max_sched_scan_ssids) |
256da02d | 5972 | return ERR_PTR(-EINVAL); |
807f8a8c | 5973 | |
ea73cbce JB |
5974 | /* |
5975 | * First, count the number of 'real' matchsets. Due to an issue with | |
5976 | * the old implementation, matchsets containing only the RSSI attribute | |
5977 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
5978 | * RSSI for all matchsets, rather than their own matchset for reporting | |
5979 | * all APs with a strong RSSI. This is needed to be compatible with | |
5980 | * older userspace that treated a matchset with only the RSSI as the | |
5981 | * global RSSI for all other matchsets - if there are other matchsets. | |
5982 | */ | |
256da02d | 5983 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 5984 | nla_for_each_nested(attr, |
256da02d | 5985 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
ea73cbce JB |
5986 | tmp) { |
5987 | struct nlattr *rssi; | |
5988 | ||
5989 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5990 | nla_data(attr), nla_len(attr), | |
5991 | nl80211_match_policy); | |
5992 | if (err) | |
256da02d | 5993 | return ERR_PTR(err); |
ea73cbce JB |
5994 | /* add other standalone attributes here */ |
5995 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | |
5996 | n_match_sets++; | |
5997 | continue; | |
5998 | } | |
5999 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6000 | if (rssi) | |
6001 | default_match_rssi = nla_get_s32(rssi); | |
6002 | } | |
6003 | } | |
6004 | ||
6005 | /* However, if there's no other matchset, add the RSSI one */ | |
6006 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
6007 | n_match_sets = 1; | |
a1f1c21c LC |
6008 | |
6009 | if (n_match_sets > wiphy->max_match_sets) | |
256da02d | 6010 | return ERR_PTR(-EINVAL); |
a1f1c21c | 6011 | |
256da02d LC |
6012 | if (attrs[NL80211_ATTR_IE]) |
6013 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); | |
807f8a8c LC |
6014 | else |
6015 | ie_len = 0; | |
6016 | ||
5a865bad | 6017 | if (ie_len > wiphy->max_sched_scan_ie_len) |
256da02d | 6018 | return ERR_PTR(-EINVAL); |
c10841ca | 6019 | |
807f8a8c | 6020 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 6021 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 6022 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 6023 | + sizeof(*request->channels) * n_channels |
807f8a8c | 6024 | + ie_len, GFP_KERNEL); |
256da02d LC |
6025 | if (!request) |
6026 | return ERR_PTR(-ENOMEM); | |
807f8a8c LC |
6027 | |
6028 | if (n_ssids) | |
6029 | request->ssids = (void *)&request->channels[n_channels]; | |
6030 | request->n_ssids = n_ssids; | |
6031 | if (ie_len) { | |
6032 | if (request->ssids) | |
6033 | request->ie = (void *)(request->ssids + n_ssids); | |
6034 | else | |
6035 | request->ie = (void *)(request->channels + n_channels); | |
6036 | } | |
6037 | ||
a1f1c21c LC |
6038 | if (n_match_sets) { |
6039 | if (request->ie) | |
6040 | request->match_sets = (void *)(request->ie + ie_len); | |
6041 | else if (request->ssids) | |
6042 | request->match_sets = | |
6043 | (void *)(request->ssids + n_ssids); | |
6044 | else | |
6045 | request->match_sets = | |
6046 | (void *)(request->channels + n_channels); | |
6047 | } | |
6048 | request->n_match_sets = n_match_sets; | |
6049 | ||
807f8a8c | 6050 | i = 0; |
256da02d | 6051 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c LC |
6052 | /* user specified, bail out if channel not found */ |
6053 | nla_for_each_nested(attr, | |
256da02d | 6054 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
807f8a8c LC |
6055 | tmp) { |
6056 | struct ieee80211_channel *chan; | |
6057 | ||
6058 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
6059 | ||
6060 | if (!chan) { | |
6061 | err = -EINVAL; | |
6062 | goto out_free; | |
6063 | } | |
6064 | ||
6065 | /* ignore disabled channels */ | |
6066 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6067 | continue; | |
6068 | ||
6069 | request->channels[i] = chan; | |
6070 | i++; | |
6071 | } | |
6072 | } else { | |
6073 | /* all channels */ | |
6074 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6075 | int j; | |
6076 | if (!wiphy->bands[band]) | |
6077 | continue; | |
6078 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
6079 | struct ieee80211_channel *chan; | |
6080 | ||
6081 | chan = &wiphy->bands[band]->channels[j]; | |
6082 | ||
6083 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6084 | continue; | |
6085 | ||
6086 | request->channels[i] = chan; | |
6087 | i++; | |
6088 | } | |
6089 | } | |
6090 | } | |
6091 | ||
6092 | if (!i) { | |
6093 | err = -EINVAL; | |
6094 | goto out_free; | |
6095 | } | |
6096 | ||
6097 | request->n_channels = i; | |
6098 | ||
6099 | i = 0; | |
256da02d LC |
6100 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) { |
6101 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c | 6102 | tmp) { |
57a27e1d | 6103 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
6104 | err = -EINVAL; |
6105 | goto out_free; | |
6106 | } | |
57a27e1d | 6107 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
6108 | memcpy(request->ssids[i].ssid, nla_data(attr), |
6109 | nla_len(attr)); | |
807f8a8c LC |
6110 | i++; |
6111 | } | |
6112 | } | |
6113 | ||
a1f1c21c | 6114 | i = 0; |
256da02d | 6115 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 6116 | nla_for_each_nested(attr, |
256da02d | 6117 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
a1f1c21c | 6118 | tmp) { |
88e920b4 | 6119 | struct nlattr *ssid, *rssi; |
a1f1c21c | 6120 | |
ae811e21 JB |
6121 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
6122 | nla_data(attr), nla_len(attr), | |
6123 | nl80211_match_policy); | |
6124 | if (err) | |
6125 | goto out_free; | |
4a4ab0d7 | 6126 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 6127 | if (ssid) { |
ea73cbce JB |
6128 | if (WARN_ON(i >= n_match_sets)) { |
6129 | /* this indicates a programming error, | |
6130 | * the loop above should have verified | |
6131 | * things properly | |
6132 | */ | |
6133 | err = -EINVAL; | |
6134 | goto out_free; | |
6135 | } | |
6136 | ||
a1f1c21c LC |
6137 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
6138 | err = -EINVAL; | |
6139 | goto out_free; | |
6140 | } | |
6141 | memcpy(request->match_sets[i].ssid.ssid, | |
6142 | nla_data(ssid), nla_len(ssid)); | |
6143 | request->match_sets[i].ssid.ssid_len = | |
6144 | nla_len(ssid); | |
ea73cbce JB |
6145 | /* special attribute - old implemenation w/a */ |
6146 | request->match_sets[i].rssi_thold = | |
6147 | default_match_rssi; | |
6148 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6149 | if (rssi) | |
6150 | request->match_sets[i].rssi_thold = | |
6151 | nla_get_s32(rssi); | |
a1f1c21c LC |
6152 | } |
6153 | i++; | |
6154 | } | |
ea73cbce JB |
6155 | |
6156 | /* there was no other matchset, so the RSSI one is alone */ | |
f89f46cf | 6157 | if (i == 0 && n_match_sets) |
ea73cbce JB |
6158 | request->match_sets[0].rssi_thold = default_match_rssi; |
6159 | ||
6160 | request->min_rssi_thold = INT_MAX; | |
6161 | for (i = 0; i < n_match_sets; i++) | |
6162 | request->min_rssi_thold = | |
6163 | min(request->match_sets[i].rssi_thold, | |
6164 | request->min_rssi_thold); | |
6165 | } else { | |
6166 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
6167 | } |
6168 | ||
9900e484 JB |
6169 | if (ie_len) { |
6170 | request->ie_len = ie_len; | |
807f8a8c | 6171 | memcpy((void *)request->ie, |
256da02d | 6172 | nla_data(attrs[NL80211_ATTR_IE]), |
807f8a8c LC |
6173 | request->ie_len); |
6174 | } | |
6175 | ||
256da02d | 6176 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 | 6177 | request->flags = nla_get_u32( |
256da02d | 6178 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
00c3a6ed JB |
6179 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
6180 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
6181 | err = -EOPNOTSUPP; |
6182 | goto out_free; | |
6183 | } | |
ad2b26ab JB |
6184 | |
6185 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
6186 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; | |
6187 | ||
6188 | if (!wdev) /* must be net-detect */ | |
6189 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
6190 | ||
6191 | if (!(wiphy->features & flg)) { | |
6192 | err = -EOPNOTSUPP; | |
6193 | goto out_free; | |
6194 | } | |
6195 | ||
6196 | if (wdev && wdev->current_bss) { | |
6197 | err = -EOPNOTSUPP; | |
6198 | goto out_free; | |
6199 | } | |
6200 | ||
6201 | err = nl80211_parse_random_mac(attrs, request->mac_addr, | |
6202 | request->mac_addr_mask); | |
6203 | if (err) | |
6204 | goto out_free; | |
6205 | } | |
46856bbf | 6206 | } |
ed473771 | 6207 | |
bbe6ad6d | 6208 | request->interval = interval; |
15d6030b | 6209 | request->scan_start = jiffies; |
807f8a8c | 6210 | |
256da02d | 6211 | return request; |
807f8a8c LC |
6212 | |
6213 | out_free: | |
6214 | kfree(request); | |
256da02d LC |
6215 | return ERR_PTR(err); |
6216 | } | |
6217 | ||
6218 | static int nl80211_start_sched_scan(struct sk_buff *skb, | |
6219 | struct genl_info *info) | |
6220 | { | |
6221 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6222 | struct net_device *dev = info->user_ptr[1]; | |
ad2b26ab | 6223 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
31a60ed1 | 6224 | struct cfg80211_sched_scan_request *sched_scan_req; |
256da02d LC |
6225 | int err; |
6226 | ||
6227 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6228 | !rdev->ops->sched_scan_start) | |
6229 | return -EOPNOTSUPP; | |
6230 | ||
6231 | if (rdev->sched_scan_req) | |
6232 | return -EINPROGRESS; | |
6233 | ||
31a60ed1 JR |
6234 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
6235 | info->attrs); | |
6236 | ||
6237 | err = PTR_ERR_OR_ZERO(sched_scan_req); | |
256da02d LC |
6238 | if (err) |
6239 | goto out_err; | |
6240 | ||
31a60ed1 | 6241 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
256da02d LC |
6242 | if (err) |
6243 | goto out_free; | |
6244 | ||
31a60ed1 JR |
6245 | sched_scan_req->dev = dev; |
6246 | sched_scan_req->wiphy = &rdev->wiphy; | |
6247 | ||
93a1e86c JR |
6248 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
6249 | sched_scan_req->owner_nlportid = info->snd_portid; | |
6250 | ||
31a60ed1 | 6251 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
256da02d LC |
6252 | |
6253 | nl80211_send_sched_scan(rdev, dev, | |
6254 | NL80211_CMD_START_SCHED_SCAN); | |
6255 | return 0; | |
6256 | ||
6257 | out_free: | |
31a60ed1 | 6258 | kfree(sched_scan_req); |
256da02d | 6259 | out_err: |
807f8a8c LC |
6260 | return err; |
6261 | } | |
6262 | ||
6263 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
6264 | struct genl_info *info) | |
6265 | { | |
6266 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6267 | ||
6268 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6269 | !rdev->ops->sched_scan_stop) | |
6270 | return -EOPNOTSUPP; | |
6271 | ||
5fe231e8 | 6272 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
6273 | } |
6274 | ||
04f39047 SW |
6275 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
6276 | struct genl_info *info) | |
6277 | { | |
6278 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6279 | struct net_device *dev = info->user_ptr[1]; | |
6280 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6281 | struct cfg80211_chan_def chandef; | |
55f7435c | 6282 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 6283 | unsigned int cac_time_ms; |
04f39047 SW |
6284 | int err; |
6285 | ||
55f7435c LR |
6286 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
6287 | if (dfs_region == NL80211_DFS_UNSET) | |
6288 | return -EINVAL; | |
6289 | ||
04f39047 SW |
6290 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6291 | if (err) | |
6292 | return err; | |
6293 | ||
ff311bc1 SW |
6294 | if (netif_carrier_ok(dev)) |
6295 | return -EBUSY; | |
6296 | ||
04f39047 SW |
6297 | if (wdev->cac_started) |
6298 | return -EBUSY; | |
6299 | ||
2beb6dab | 6300 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
00ec75fc | 6301 | wdev->iftype); |
04f39047 SW |
6302 | if (err < 0) |
6303 | return err; | |
6304 | ||
6305 | if (err == 0) | |
6306 | return -EINVAL; | |
6307 | ||
fe7c3a1f | 6308 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
6309 | return -EINVAL; |
6310 | ||
6311 | if (!rdev->ops->start_radar_detection) | |
6312 | return -EOPNOTSUPP; | |
6313 | ||
31559f35 JD |
6314 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
6315 | if (WARN_ON(!cac_time_ms)) | |
6316 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
6317 | ||
6318 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, | |
6319 | cac_time_ms); | |
04f39047 | 6320 | if (!err) { |
9e0e2961 | 6321 | wdev->chandef = chandef; |
04f39047 SW |
6322 | wdev->cac_started = true; |
6323 | wdev->cac_start_time = jiffies; | |
31559f35 | 6324 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 6325 | } |
04f39047 SW |
6326 | return err; |
6327 | } | |
6328 | ||
16ef1fe2 SW |
6329 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
6330 | { | |
6331 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6332 | struct net_device *dev = info->user_ptr[1]; | |
6333 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6334 | struct cfg80211_csa_settings params; | |
6335 | /* csa_attrs is defined static to avoid waste of stack size - this | |
6336 | * function is called under RTNL lock, so this should not be a problem. | |
6337 | */ | |
6338 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
16ef1fe2 | 6339 | int err; |
ee4bc9e7 | 6340 | bool need_new_beacon = false; |
9a774c78 | 6341 | int len, i; |
252e07ca | 6342 | u32 cs_count; |
16ef1fe2 SW |
6343 | |
6344 | if (!rdev->ops->channel_switch || | |
6345 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
6346 | return -EOPNOTSUPP; | |
6347 | ||
ee4bc9e7 SW |
6348 | switch (dev->ieee80211_ptr->iftype) { |
6349 | case NL80211_IFTYPE_AP: | |
6350 | case NL80211_IFTYPE_P2P_GO: | |
6351 | need_new_beacon = true; | |
6352 | ||
6353 | /* useless if AP is not running */ | |
6354 | if (!wdev->beacon_interval) | |
1ff79dfa | 6355 | return -ENOTCONN; |
ee4bc9e7 SW |
6356 | break; |
6357 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
6358 | if (!wdev->ssid_len) |
6359 | return -ENOTCONN; | |
6360 | break; | |
c6da674a | 6361 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
6362 | if (!wdev->mesh_id_len) |
6363 | return -ENOTCONN; | |
ee4bc9e7 SW |
6364 | break; |
6365 | default: | |
16ef1fe2 | 6366 | return -EOPNOTSUPP; |
ee4bc9e7 | 6367 | } |
16ef1fe2 SW |
6368 | |
6369 | memset(¶ms, 0, sizeof(params)); | |
6370 | ||
6371 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6372 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
6373 | return -EINVAL; | |
6374 | ||
6375 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 6376 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
6377 | return -EINVAL; |
6378 | ||
252e07ca LC |
6379 | /* Even though the attribute is u32, the specification says |
6380 | * u8, so let's make sure we don't overflow. | |
6381 | */ | |
6382 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
6383 | if (cs_count > 255) | |
6384 | return -EINVAL; | |
6385 | ||
6386 | params.count = cs_count; | |
16ef1fe2 | 6387 | |
ee4bc9e7 SW |
6388 | if (!need_new_beacon) |
6389 | goto skip_beacons; | |
6390 | ||
16ef1fe2 SW |
6391 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
6392 | if (err) | |
6393 | return err; | |
6394 | ||
6395 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
6396 | info->attrs[NL80211_ATTR_CSA_IES], | |
6397 | nl80211_policy); | |
6398 | if (err) | |
6399 | return err; | |
6400 | ||
6401 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
6402 | if (err) | |
6403 | return err; | |
6404 | ||
6405 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
6406 | return -EINVAL; | |
6407 | ||
9a774c78 AO |
6408 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
6409 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6410 | return -EINVAL; |
6411 | ||
9a774c78 AO |
6412 | params.n_counter_offsets_beacon = len / sizeof(u16); |
6413 | if (rdev->wiphy.max_num_csa_counters && | |
6414 | (params.n_counter_offsets_beacon > | |
6415 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
6416 | return -EINVAL; |
6417 | ||
9a774c78 AO |
6418 | params.counter_offsets_beacon = |
6419 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
6420 | ||
6421 | /* sanity checks - counters should fit and be the same */ | |
6422 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
6423 | u16 offset = params.counter_offsets_beacon[i]; | |
6424 | ||
6425 | if (offset >= params.beacon_csa.tail_len) | |
6426 | return -EINVAL; | |
6427 | ||
6428 | if (params.beacon_csa.tail[offset] != params.count) | |
6429 | return -EINVAL; | |
6430 | } | |
6431 | ||
16ef1fe2 | 6432 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
6433 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
6434 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6435 | return -EINVAL; |
6436 | ||
9a774c78 AO |
6437 | params.n_counter_offsets_presp = len / sizeof(u16); |
6438 | if (rdev->wiphy.max_num_csa_counters && | |
6439 | (params.n_counter_offsets_beacon > | |
6440 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 | 6441 | return -EINVAL; |
9a774c78 AO |
6442 | |
6443 | params.counter_offsets_presp = | |
6444 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
6445 | ||
6446 | /* sanity checks - counters should fit and be the same */ | |
6447 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
6448 | u16 offset = params.counter_offsets_presp[i]; | |
6449 | ||
6450 | if (offset >= params.beacon_csa.probe_resp_len) | |
6451 | return -EINVAL; | |
6452 | ||
6453 | if (params.beacon_csa.probe_resp[offset] != | |
6454 | params.count) | |
6455 | return -EINVAL; | |
6456 | } | |
16ef1fe2 SW |
6457 | } |
6458 | ||
ee4bc9e7 | 6459 | skip_beacons: |
16ef1fe2 SW |
6460 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
6461 | if (err) | |
6462 | return err; | |
6463 | ||
174e0cd2 IP |
6464 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
6465 | wdev->iftype)) | |
16ef1fe2 SW |
6466 | return -EINVAL; |
6467 | ||
2beb6dab LC |
6468 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
6469 | ¶ms.chandef, | |
6470 | wdev->iftype); | |
6471 | if (err < 0) | |
6472 | return err; | |
6473 | ||
dcc6c2f5 | 6474 | if (err > 0) |
2beb6dab | 6475 | params.radar_required = true; |
16ef1fe2 | 6476 | |
16ef1fe2 SW |
6477 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
6478 | params.block_tx = true; | |
6479 | ||
c56589ed SW |
6480 | wdev_lock(wdev); |
6481 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
6482 | wdev_unlock(wdev); | |
6483 | ||
6484 | return err; | |
16ef1fe2 SW |
6485 | } |
6486 | ||
9720bb3a JB |
6487 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
6488 | u32 seq, int flags, | |
2a519311 | 6489 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
6490 | struct wireless_dev *wdev, |
6491 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 6492 | { |
48ab905d | 6493 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 6494 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
6495 | void *hdr; |
6496 | struct nlattr *bss; | |
48ab905d JB |
6497 | |
6498 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 6499 | |
15e47304 | 6500 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
6501 | NL80211_CMD_NEW_SCAN_RESULTS); |
6502 | if (!hdr) | |
6503 | return -1; | |
6504 | ||
9720bb3a JB |
6505 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
6506 | ||
97990a06 JB |
6507 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
6508 | goto nla_put_failure; | |
6509 | if (wdev->netdev && | |
9360ffd1 DM |
6510 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
6511 | goto nla_put_failure; | |
97990a06 JB |
6512 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
6513 | goto nla_put_failure; | |
2a519311 JB |
6514 | |
6515 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
6516 | if (!bss) | |
6517 | goto nla_put_failure; | |
9360ffd1 | 6518 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 6519 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 6520 | goto nla_put_failure; |
9caf0364 JB |
6521 | |
6522 | rcu_read_lock(); | |
0e227084 JB |
6523 | /* indicate whether we have probe response data or not */ |
6524 | if (rcu_access_pointer(res->proberesp_ies) && | |
6525 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
6526 | goto fail_unlock_rcu; | |
6527 | ||
6528 | /* this pointer prefers to be pointed to probe response data | |
6529 | * but is always valid | |
6530 | */ | |
9caf0364 | 6531 | ies = rcu_dereference(res->ies); |
8cef2c9d JB |
6532 | if (ies) { |
6533 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
6534 | goto fail_unlock_rcu; | |
8cef2c9d JB |
6535 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
6536 | ies->len, ies->data)) | |
6537 | goto fail_unlock_rcu; | |
9caf0364 | 6538 | } |
0e227084 JB |
6539 | |
6540 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 6541 | ies = rcu_dereference(res->beacon_ies); |
0e227084 JB |
6542 | if (ies && ies->from_beacon) { |
6543 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) | |
8cef2c9d JB |
6544 | goto fail_unlock_rcu; |
6545 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
6546 | ies->len, ies->data)) | |
6547 | goto fail_unlock_rcu; | |
9caf0364 JB |
6548 | } |
6549 | rcu_read_unlock(); | |
6550 | ||
9360ffd1 DM |
6551 | if (res->beacon_interval && |
6552 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
6553 | goto nla_put_failure; | |
6554 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
6555 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 6556 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
6557 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
6558 | jiffies_to_msecs(jiffies - intbss->ts))) | |
6559 | goto nla_put_failure; | |
2a519311 | 6560 | |
77965c97 | 6561 | switch (rdev->wiphy.signal_type) { |
2a519311 | 6562 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
6563 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
6564 | goto nla_put_failure; | |
2a519311 JB |
6565 | break; |
6566 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
6567 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
6568 | goto nla_put_failure; | |
2a519311 JB |
6569 | break; |
6570 | default: | |
6571 | break; | |
6572 | } | |
6573 | ||
48ab905d | 6574 | switch (wdev->iftype) { |
074ac8df | 6575 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 6576 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
6577 | if (intbss == wdev->current_bss && |
6578 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6579 | NL80211_BSS_STATUS_ASSOCIATED)) | |
6580 | goto nla_put_failure; | |
48ab905d JB |
6581 | break; |
6582 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
6583 | if (intbss == wdev->current_bss && |
6584 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6585 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
6586 | goto nla_put_failure; | |
48ab905d JB |
6587 | break; |
6588 | default: | |
6589 | break; | |
6590 | } | |
6591 | ||
2a519311 JB |
6592 | nla_nest_end(msg, bss); |
6593 | ||
6594 | return genlmsg_end(msg, hdr); | |
6595 | ||
8cef2c9d JB |
6596 | fail_unlock_rcu: |
6597 | rcu_read_unlock(); | |
2a519311 JB |
6598 | nla_put_failure: |
6599 | genlmsg_cancel(msg, hdr); | |
6600 | return -EMSGSIZE; | |
6601 | } | |
6602 | ||
97990a06 | 6603 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 6604 | { |
48ab905d | 6605 | struct cfg80211_registered_device *rdev; |
2a519311 | 6606 | struct cfg80211_internal_bss *scan; |
48ab905d | 6607 | struct wireless_dev *wdev; |
97990a06 | 6608 | int start = cb->args[2], idx = 0; |
2a519311 JB |
6609 | int err; |
6610 | ||
97990a06 | 6611 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6612 | if (err) |
6613 | return err; | |
2a519311 | 6614 | |
48ab905d JB |
6615 | wdev_lock(wdev); |
6616 | spin_lock_bh(&rdev->bss_lock); | |
6617 | cfg80211_bss_expire(rdev); | |
6618 | ||
9720bb3a JB |
6619 | cb->seq = rdev->bss_generation; |
6620 | ||
48ab905d | 6621 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
6622 | if (++idx <= start) |
6623 | continue; | |
9720bb3a | 6624 | if (nl80211_send_bss(skb, cb, |
2a519311 | 6625 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 6626 | rdev, wdev, scan) < 0) { |
2a519311 | 6627 | idx--; |
67748893 | 6628 | break; |
2a519311 JB |
6629 | } |
6630 | } | |
6631 | ||
48ab905d JB |
6632 | spin_unlock_bh(&rdev->bss_lock); |
6633 | wdev_unlock(wdev); | |
2a519311 | 6634 | |
97990a06 JB |
6635 | cb->args[2] = idx; |
6636 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 6637 | |
67748893 | 6638 | return skb->len; |
2a519311 JB |
6639 | } |
6640 | ||
15e47304 | 6641 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
11f78ac3 JB |
6642 | int flags, struct net_device *dev, |
6643 | bool allow_radio_stats, | |
6644 | struct survey_info *survey) | |
61fa713c HS |
6645 | { |
6646 | void *hdr; | |
6647 | struct nlattr *infoattr; | |
6648 | ||
11f78ac3 JB |
6649 | /* skip radio stats if userspace didn't request them */ |
6650 | if (!survey->channel && !allow_radio_stats) | |
6651 | return 0; | |
6652 | ||
15e47304 | 6653 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
6654 | NL80211_CMD_NEW_SURVEY_RESULTS); |
6655 | if (!hdr) | |
6656 | return -ENOMEM; | |
6657 | ||
9360ffd1 DM |
6658 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
6659 | goto nla_put_failure; | |
61fa713c HS |
6660 | |
6661 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
6662 | if (!infoattr) | |
6663 | goto nla_put_failure; | |
6664 | ||
11f78ac3 JB |
6665 | if (survey->channel && |
6666 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
9360ffd1 DM |
6667 | survey->channel->center_freq)) |
6668 | goto nla_put_failure; | |
6669 | ||
6670 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
6671 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
6672 | goto nla_put_failure; | |
6673 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
6674 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
6675 | goto nla_put_failure; | |
4ed20beb JB |
6676 | if ((survey->filled & SURVEY_INFO_TIME) && |
6677 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME, | |
6678 | survey->time)) | |
9360ffd1 | 6679 | goto nla_put_failure; |
4ed20beb JB |
6680 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
6681 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY, | |
6682 | survey->time_busy)) | |
9360ffd1 | 6683 | goto nla_put_failure; |
4ed20beb JB |
6684 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
6685 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, | |
6686 | survey->time_ext_busy)) | |
9360ffd1 | 6687 | goto nla_put_failure; |
4ed20beb JB |
6688 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
6689 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX, | |
6690 | survey->time_rx)) | |
9360ffd1 | 6691 | goto nla_put_failure; |
4ed20beb JB |
6692 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
6693 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX, | |
6694 | survey->time_tx)) | |
9360ffd1 | 6695 | goto nla_put_failure; |
052536ab JB |
6696 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
6697 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN, | |
6698 | survey->time_scan)) | |
6699 | goto nla_put_failure; | |
61fa713c HS |
6700 | |
6701 | nla_nest_end(msg, infoattr); | |
6702 | ||
6703 | return genlmsg_end(msg, hdr); | |
6704 | ||
6705 | nla_put_failure: | |
6706 | genlmsg_cancel(msg, hdr); | |
6707 | return -EMSGSIZE; | |
6708 | } | |
6709 | ||
11f78ac3 | 6710 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
61fa713c HS |
6711 | { |
6712 | struct survey_info survey; | |
1b8ec87a | 6713 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
6714 | struct wireless_dev *wdev; |
6715 | int survey_idx = cb->args[2]; | |
61fa713c | 6716 | int res; |
11f78ac3 | 6717 | bool radio_stats; |
61fa713c | 6718 | |
1b8ec87a | 6719 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6720 | if (res) |
6721 | return res; | |
61fa713c | 6722 | |
11f78ac3 JB |
6723 | /* prepare_wdev_dump parsed the attributes */ |
6724 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; | |
6725 | ||
97990a06 JB |
6726 | if (!wdev->netdev) { |
6727 | res = -EINVAL; | |
6728 | goto out_err; | |
6729 | } | |
6730 | ||
1b8ec87a | 6731 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
6732 | res = -EOPNOTSUPP; |
6733 | goto out_err; | |
6734 | } | |
6735 | ||
6736 | while (1) { | |
1b8ec87a | 6737 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
6738 | if (res == -ENOENT) |
6739 | break; | |
6740 | if (res) | |
6741 | goto out_err; | |
6742 | ||
11f78ac3 JB |
6743 | /* don't send disabled channels, but do send non-channel data */ |
6744 | if (survey.channel && | |
6745 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { | |
180cdc79 LR |
6746 | survey_idx++; |
6747 | continue; | |
6748 | } | |
6749 | ||
61fa713c | 6750 | if (nl80211_send_survey(skb, |
15e47304 | 6751 | NETLINK_CB(cb->skb).portid, |
61fa713c | 6752 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
11f78ac3 | 6753 | wdev->netdev, radio_stats, &survey) < 0) |
61fa713c HS |
6754 | goto out; |
6755 | survey_idx++; | |
6756 | } | |
6757 | ||
6758 | out: | |
97990a06 | 6759 | cb->args[2] = survey_idx; |
61fa713c HS |
6760 | res = skb->len; |
6761 | out_err: | |
1b8ec87a | 6762 | nl80211_finish_wdev_dump(rdev); |
61fa713c HS |
6763 | return res; |
6764 | } | |
6765 | ||
b23aa676 SO |
6766 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
6767 | { | |
6768 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
6769 | NL80211_WPA_VERSION_2)); | |
6770 | } | |
6771 | ||
636a5d36 JM |
6772 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
6773 | { | |
4c476991 JB |
6774 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6775 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6776 | struct ieee80211_channel *chan; |
e39e5b5e JM |
6777 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
6778 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 6779 | enum nl80211_auth_type auth_type; |
fffd0934 | 6780 | struct key_parse key; |
d5cdfacb | 6781 | bool local_state_change; |
636a5d36 | 6782 | |
f4a11bb0 JB |
6783 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6784 | return -EINVAL; | |
6785 | ||
6786 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6787 | return -EINVAL; | |
6788 | ||
1778092e JM |
6789 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
6790 | return -EINVAL; | |
6791 | ||
19957bb3 JB |
6792 | if (!info->attrs[NL80211_ATTR_SSID]) |
6793 | return -EINVAL; | |
6794 | ||
6795 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
6796 | return -EINVAL; | |
6797 | ||
fffd0934 JB |
6798 | err = nl80211_parse_key(info, &key); |
6799 | if (err) | |
6800 | return err; | |
6801 | ||
6802 | if (key.idx >= 0) { | |
e31b8213 JB |
6803 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
6804 | return -EINVAL; | |
fffd0934 JB |
6805 | if (!key.p.key || !key.p.key_len) |
6806 | return -EINVAL; | |
6807 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
6808 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
6809 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
6810 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
6811 | return -EINVAL; | |
6812 | if (key.idx > 4) | |
6813 | return -EINVAL; | |
6814 | } else { | |
6815 | key.p.key_len = 0; | |
6816 | key.p.key = NULL; | |
6817 | } | |
6818 | ||
afea0b7a JB |
6819 | if (key.idx >= 0) { |
6820 | int i; | |
6821 | bool ok = false; | |
6822 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
6823 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
6824 | ok = true; | |
6825 | break; | |
6826 | } | |
6827 | } | |
4c476991 JB |
6828 | if (!ok) |
6829 | return -EINVAL; | |
afea0b7a JB |
6830 | } |
6831 | ||
4c476991 JB |
6832 | if (!rdev->ops->auth) |
6833 | return -EOPNOTSUPP; | |
636a5d36 | 6834 | |
074ac8df | 6835 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6836 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6837 | return -EOPNOTSUPP; | |
eec60b03 | 6838 | |
19957bb3 | 6839 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
6840 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6841 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6842 | if (!chan) | |
4c476991 | 6843 | return -EINVAL; |
636a5d36 | 6844 | |
19957bb3 JB |
6845 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6846 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6847 | |
6848 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6849 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6850 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6851 | } |
6852 | ||
19957bb3 | 6853 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 6854 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 6855 | return -EINVAL; |
636a5d36 | 6856 | |
e39e5b5e JM |
6857 | if (auth_type == NL80211_AUTHTYPE_SAE && |
6858 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
6859 | return -EINVAL; | |
6860 | ||
6861 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
6862 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
6863 | return -EINVAL; | |
6864 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6865 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6866 | /* need to include at least Auth Transaction and Status Code */ | |
6867 | if (sae_data_len < 4) | |
6868 | return -EINVAL; | |
6869 | } | |
6870 | ||
d5cdfacb JM |
6871 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6872 | ||
95de817b JB |
6873 | /* |
6874 | * Since we no longer track auth state, ignore | |
6875 | * requests to only change local state. | |
6876 | */ | |
6877 | if (local_state_change) | |
6878 | return 0; | |
6879 | ||
91bf9b26 JB |
6880 | wdev_lock(dev->ieee80211_ptr); |
6881 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
6882 | ssid, ssid_len, ie, ie_len, | |
6883 | key.p.key, key.p.key_len, key.idx, | |
6884 | sae_data, sae_data_len); | |
6885 | wdev_unlock(dev->ieee80211_ptr); | |
6886 | return err; | |
636a5d36 JM |
6887 | } |
6888 | ||
c0692b8f JB |
6889 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6890 | struct genl_info *info, | |
3dc27d25 JB |
6891 | struct cfg80211_crypto_settings *settings, |
6892 | int cipher_limit) | |
b23aa676 | 6893 | { |
c0b2bbd8 JB |
6894 | memset(settings, 0, sizeof(*settings)); |
6895 | ||
b23aa676 SO |
6896 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6897 | ||
c0692b8f JB |
6898 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6899 | u16 proto; | |
6900 | proto = nla_get_u16( | |
6901 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6902 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6903 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6904 | proto != ETH_P_PAE) | |
6905 | return -EINVAL; | |
6906 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6907 | settings->control_port_no_encrypt = true; | |
6908 | } else | |
6909 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6910 | ||
b23aa676 SO |
6911 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6912 | void *data; | |
6913 | int len, i; | |
6914 | ||
6915 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6916 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6917 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6918 | ||
6919 | if (len % sizeof(u32)) | |
6920 | return -EINVAL; | |
6921 | ||
3dc27d25 | 6922 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6923 | return -EINVAL; |
6924 | ||
6925 | memcpy(settings->ciphers_pairwise, data, len); | |
6926 | ||
6927 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6928 | if (!cfg80211_supported_cipher_suite( |
6929 | &rdev->wiphy, | |
b23aa676 SO |
6930 | settings->ciphers_pairwise[i])) |
6931 | return -EINVAL; | |
6932 | } | |
6933 | ||
6934 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6935 | settings->cipher_group = | |
6936 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6937 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6938 | settings->cipher_group)) | |
b23aa676 SO |
6939 | return -EINVAL; |
6940 | } | |
6941 | ||
6942 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6943 | settings->wpa_versions = | |
6944 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6945 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6946 | return -EINVAL; | |
6947 | } | |
6948 | ||
6949 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6950 | void *data; | |
6d30240e | 6951 | int len; |
b23aa676 SO |
6952 | |
6953 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6954 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6955 | settings->n_akm_suites = len / sizeof(u32); | |
6956 | ||
6957 | if (len % sizeof(u32)) | |
6958 | return -EINVAL; | |
6959 | ||
1b9ca027 JM |
6960 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6961 | return -EINVAL; | |
6962 | ||
b23aa676 | 6963 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6964 | } |
6965 | ||
6966 | return 0; | |
6967 | } | |
6968 | ||
636a5d36 JM |
6969 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6970 | { | |
4c476991 JB |
6971 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6972 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6973 | struct ieee80211_channel *chan; |
f62fab73 JB |
6974 | struct cfg80211_assoc_request req = {}; |
6975 | const u8 *bssid, *ssid; | |
6976 | int err, ssid_len = 0; | |
636a5d36 | 6977 | |
f4a11bb0 JB |
6978 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6979 | return -EINVAL; | |
6980 | ||
6981 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6982 | !info->attrs[NL80211_ATTR_SSID] || |
6983 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6984 | return -EINVAL; |
6985 | ||
4c476991 JB |
6986 | if (!rdev->ops->assoc) |
6987 | return -EOPNOTSUPP; | |
636a5d36 | 6988 | |
074ac8df | 6989 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6990 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6991 | return -EOPNOTSUPP; | |
eec60b03 | 6992 | |
19957bb3 | 6993 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6994 | |
664834de JM |
6995 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6996 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6997 | if (!chan) | |
4c476991 | 6998 | return -EINVAL; |
636a5d36 | 6999 | |
19957bb3 JB |
7000 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7001 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
7002 | |
7003 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
7004 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7005 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7006 | } |
7007 | ||
dc6382ce | 7008 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 7009 | enum nl80211_mfp mfp = |
dc6382ce | 7010 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 7011 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 7012 | req.use_mfp = true; |
4c476991 JB |
7013 | else if (mfp != NL80211_MFP_NO) |
7014 | return -EINVAL; | |
dc6382ce JM |
7015 | } |
7016 | ||
3e5d7649 | 7017 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 7018 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 7019 | |
7e7c8926 | 7020 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 7021 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
7022 | |
7023 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
7024 | memcpy(&req.ht_capa_mask, |
7025 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7026 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
7027 | |
7028 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 7029 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 7030 | return -EINVAL; |
f62fab73 JB |
7031 | memcpy(&req.ht_capa, |
7032 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7033 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
7034 | } |
7035 | ||
ee2aca34 | 7036 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 7037 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
7038 | |
7039 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
7040 | memcpy(&req.vht_capa_mask, |
7041 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7042 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
7043 | |
7044 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 7045 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 7046 | return -EINVAL; |
f62fab73 JB |
7047 | memcpy(&req.vht_capa, |
7048 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7049 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
7050 | } |
7051 | ||
bab5ab7d AK |
7052 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7053 | if (!(rdev->wiphy.features & | |
7054 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7055 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7056 | return -EINVAL; | |
7057 | req.flags |= ASSOC_REQ_USE_RRM; | |
7058 | } | |
7059 | ||
f62fab73 | 7060 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
7061 | if (!err) { |
7062 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
7063 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
7064 | ssid, ssid_len, &req); | |
91bf9b26 JB |
7065 | wdev_unlock(dev->ieee80211_ptr); |
7066 | } | |
636a5d36 | 7067 | |
636a5d36 JM |
7068 | return err; |
7069 | } | |
7070 | ||
7071 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
7072 | { | |
4c476991 JB |
7073 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7074 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7075 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7076 | int ie_len = 0, err; |
19957bb3 | 7077 | u16 reason_code; |
d5cdfacb | 7078 | bool local_state_change; |
636a5d36 | 7079 | |
f4a11bb0 JB |
7080 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7081 | return -EINVAL; | |
7082 | ||
7083 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7084 | return -EINVAL; | |
7085 | ||
7086 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7087 | return -EINVAL; | |
7088 | ||
4c476991 JB |
7089 | if (!rdev->ops->deauth) |
7090 | return -EOPNOTSUPP; | |
636a5d36 | 7091 | |
074ac8df | 7092 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7093 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7094 | return -EOPNOTSUPP; | |
eec60b03 | 7095 | |
19957bb3 | 7096 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7097 | |
19957bb3 JB |
7098 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7099 | if (reason_code == 0) { | |
f4a11bb0 | 7100 | /* Reason Code 0 is reserved */ |
4c476991 | 7101 | return -EINVAL; |
255e737e | 7102 | } |
636a5d36 JM |
7103 | |
7104 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7105 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7106 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7107 | } |
7108 | ||
d5cdfacb JM |
7109 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7110 | ||
91bf9b26 JB |
7111 | wdev_lock(dev->ieee80211_ptr); |
7112 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
7113 | local_state_change); | |
7114 | wdev_unlock(dev->ieee80211_ptr); | |
7115 | return err; | |
636a5d36 JM |
7116 | } |
7117 | ||
7118 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
7119 | { | |
4c476991 JB |
7120 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7121 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7122 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7123 | int ie_len = 0, err; |
19957bb3 | 7124 | u16 reason_code; |
d5cdfacb | 7125 | bool local_state_change; |
636a5d36 | 7126 | |
f4a11bb0 JB |
7127 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7128 | return -EINVAL; | |
7129 | ||
7130 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7131 | return -EINVAL; | |
7132 | ||
7133 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7134 | return -EINVAL; | |
7135 | ||
4c476991 JB |
7136 | if (!rdev->ops->disassoc) |
7137 | return -EOPNOTSUPP; | |
636a5d36 | 7138 | |
074ac8df | 7139 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7140 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7141 | return -EOPNOTSUPP; | |
eec60b03 | 7142 | |
19957bb3 | 7143 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7144 | |
19957bb3 JB |
7145 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7146 | if (reason_code == 0) { | |
f4a11bb0 | 7147 | /* Reason Code 0 is reserved */ |
4c476991 | 7148 | return -EINVAL; |
255e737e | 7149 | } |
636a5d36 JM |
7150 | |
7151 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7152 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7153 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7154 | } |
7155 | ||
d5cdfacb JM |
7156 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7157 | ||
91bf9b26 JB |
7158 | wdev_lock(dev->ieee80211_ptr); |
7159 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
7160 | local_state_change); | |
7161 | wdev_unlock(dev->ieee80211_ptr); | |
7162 | return err; | |
636a5d36 JM |
7163 | } |
7164 | ||
dd5b4cc7 FF |
7165 | static bool |
7166 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
7167 | int mcast_rate[IEEE80211_NUM_BANDS], | |
7168 | int rateval) | |
7169 | { | |
7170 | struct wiphy *wiphy = &rdev->wiphy; | |
7171 | bool found = false; | |
7172 | int band, i; | |
7173 | ||
7174 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
7175 | struct ieee80211_supported_band *sband; | |
7176 | ||
7177 | sband = wiphy->bands[band]; | |
7178 | if (!sband) | |
7179 | continue; | |
7180 | ||
7181 | for (i = 0; i < sband->n_bitrates; i++) { | |
7182 | if (sband->bitrates[i].bitrate == rateval) { | |
7183 | mcast_rate[band] = i + 1; | |
7184 | found = true; | |
7185 | break; | |
7186 | } | |
7187 | } | |
7188 | } | |
7189 | ||
7190 | return found; | |
7191 | } | |
7192 | ||
04a773ad JB |
7193 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
7194 | { | |
4c476991 JB |
7195 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7196 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
7197 | struct cfg80211_ibss_params ibss; |
7198 | struct wiphy *wiphy; | |
fffd0934 | 7199 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
7200 | int err; |
7201 | ||
8e30bc55 JB |
7202 | memset(&ibss, 0, sizeof(ibss)); |
7203 | ||
04a773ad JB |
7204 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7205 | return -EINVAL; | |
7206 | ||
683b6d3b | 7207 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
7208 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
7209 | return -EINVAL; | |
7210 | ||
8e30bc55 JB |
7211 | ibss.beacon_interval = 100; |
7212 | ||
7213 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
7214 | ibss.beacon_interval = | |
7215 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7216 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
7217 | return -EINVAL; | |
7218 | } | |
7219 | ||
4c476991 JB |
7220 | if (!rdev->ops->join_ibss) |
7221 | return -EOPNOTSUPP; | |
04a773ad | 7222 | |
4c476991 JB |
7223 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7224 | return -EOPNOTSUPP; | |
04a773ad | 7225 | |
79c97e97 | 7226 | wiphy = &rdev->wiphy; |
04a773ad | 7227 | |
39193498 | 7228 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 7229 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
7230 | |
7231 | if (!is_valid_ether_addr(ibss.bssid)) | |
7232 | return -EINVAL; | |
7233 | } | |
04a773ad JB |
7234 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7235 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7236 | ||
7237 | if (info->attrs[NL80211_ATTR_IE]) { | |
7238 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7239 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7240 | } | |
7241 | ||
683b6d3b JB |
7242 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
7243 | if (err) | |
7244 | return err; | |
04a773ad | 7245 | |
174e0cd2 IP |
7246 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
7247 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
7248 | return -EINVAL; |
7249 | ||
2f301ab2 | 7250 | switch (ibss.chandef.width) { |
bf372645 SW |
7251 | case NL80211_CHAN_WIDTH_5: |
7252 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
7253 | case NL80211_CHAN_WIDTH_20_NOHT: |
7254 | break; | |
7255 | case NL80211_CHAN_WIDTH_20: | |
7256 | case NL80211_CHAN_WIDTH_40: | |
7257 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | |
7258 | break; | |
7259 | default: | |
c04d6150 | 7260 | return -EINVAL; |
2f301ab2 | 7261 | } |
db9c64cf | 7262 | |
04a773ad | 7263 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
7264 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
7265 | ||
fbd2c8dc TP |
7266 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
7267 | u8 *rates = | |
7268 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7269 | int n_rates = | |
7270 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7271 | struct ieee80211_supported_band *sband = | |
683b6d3b | 7272 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 7273 | |
34850ab2 JB |
7274 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
7275 | &ibss.basic_rates); | |
7276 | if (err) | |
7277 | return err; | |
fbd2c8dc | 7278 | } |
dd5b4cc7 | 7279 | |
803768f5 SW |
7280 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7281 | memcpy(&ibss.ht_capa_mask, | |
7282 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7283 | sizeof(ibss.ht_capa_mask)); | |
7284 | ||
7285 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
7286 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7287 | return -EINVAL; | |
7288 | memcpy(&ibss.ht_capa, | |
7289 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7290 | sizeof(ibss.ht_capa)); | |
7291 | } | |
7292 | ||
dd5b4cc7 FF |
7293 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7294 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
7295 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7296 | return -EINVAL; | |
fbd2c8dc | 7297 | |
4c476991 | 7298 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
7299 | bool no_ht = false; |
7300 | ||
4c476991 | 7301 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
7302 | info->attrs[NL80211_ATTR_KEYS], |
7303 | &no_ht); | |
4c476991 JB |
7304 | if (IS_ERR(connkeys)) |
7305 | return PTR_ERR(connkeys); | |
de7044ee | 7306 | |
3d9d1d66 JB |
7307 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
7308 | no_ht) { | |
de7044ee SM |
7309 | kfree(connkeys); |
7310 | return -EINVAL; | |
7311 | } | |
4c476991 | 7312 | } |
04a773ad | 7313 | |
267335d6 AQ |
7314 | ibss.control_port = |
7315 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
7316 | ||
5336fa88 SW |
7317 | ibss.userspace_handles_dfs = |
7318 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
7319 | ||
4c476991 | 7320 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 | 7321 | if (err) |
b47f610b | 7322 | kzfree(connkeys); |
04a773ad JB |
7323 | return err; |
7324 | } | |
7325 | ||
7326 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
7327 | { | |
4c476991 JB |
7328 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7329 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 7330 | |
4c476991 JB |
7331 | if (!rdev->ops->leave_ibss) |
7332 | return -EOPNOTSUPP; | |
04a773ad | 7333 | |
4c476991 JB |
7334 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7335 | return -EOPNOTSUPP; | |
04a773ad | 7336 | |
4c476991 | 7337 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
7338 | } |
7339 | ||
f4e583c8 AQ |
7340 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
7341 | { | |
7342 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7343 | struct net_device *dev = info->user_ptr[1]; | |
7344 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
7345 | u32 nla_rate; | |
7346 | int err; | |
7347 | ||
7348 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
7349 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
7350 | return -EOPNOTSUPP; | |
7351 | ||
7352 | if (!rdev->ops->set_mcast_rate) | |
7353 | return -EOPNOTSUPP; | |
7354 | ||
7355 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
7356 | ||
7357 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
7358 | return -EINVAL; | |
7359 | ||
7360 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
7361 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
7362 | return -EINVAL; | |
7363 | ||
7364 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
7365 | ||
7366 | return err; | |
7367 | } | |
7368 | ||
ad7e718c JB |
7369 | static struct sk_buff * |
7370 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
7371 | int approxlen, u32 portid, u32 seq, | |
7372 | enum nl80211_commands cmd, | |
567ffc35 JB |
7373 | enum nl80211_attrs attr, |
7374 | const struct nl80211_vendor_cmd_info *info, | |
7375 | gfp_t gfp) | |
ad7e718c JB |
7376 | { |
7377 | struct sk_buff *skb; | |
7378 | void *hdr; | |
7379 | struct nlattr *data; | |
7380 | ||
7381 | skb = nlmsg_new(approxlen + 100, gfp); | |
7382 | if (!skb) | |
7383 | return NULL; | |
7384 | ||
7385 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
7386 | if (!hdr) { | |
7387 | kfree_skb(skb); | |
7388 | return NULL; | |
7389 | } | |
7390 | ||
7391 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
7392 | goto nla_put_failure; | |
567ffc35 JB |
7393 | |
7394 | if (info) { | |
7395 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
7396 | info->vendor_id)) | |
7397 | goto nla_put_failure; | |
7398 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
7399 | info->subcmd)) | |
7400 | goto nla_put_failure; | |
7401 | } | |
7402 | ||
ad7e718c JB |
7403 | data = nla_nest_start(skb, attr); |
7404 | ||
7405 | ((void **)skb->cb)[0] = rdev; | |
7406 | ((void **)skb->cb)[1] = hdr; | |
7407 | ((void **)skb->cb)[2] = data; | |
7408 | ||
7409 | return skb; | |
7410 | ||
7411 | nla_put_failure: | |
7412 | kfree_skb(skb); | |
7413 | return NULL; | |
7414 | } | |
f4e583c8 | 7415 | |
e03ad6ea JB |
7416 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
7417 | enum nl80211_commands cmd, | |
7418 | enum nl80211_attrs attr, | |
7419 | int vendor_event_idx, | |
7420 | int approxlen, gfp_t gfp) | |
7421 | { | |
f26cbf40 | 7422 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
7423 | const struct nl80211_vendor_cmd_info *info; |
7424 | ||
7425 | switch (cmd) { | |
7426 | case NL80211_CMD_TESTMODE: | |
7427 | if (WARN_ON(vendor_event_idx != -1)) | |
7428 | return NULL; | |
7429 | info = NULL; | |
7430 | break; | |
7431 | case NL80211_CMD_VENDOR: | |
7432 | if (WARN_ON(vendor_event_idx < 0 || | |
7433 | vendor_event_idx >= wiphy->n_vendor_events)) | |
7434 | return NULL; | |
7435 | info = &wiphy->vendor_events[vendor_event_idx]; | |
7436 | break; | |
7437 | default: | |
7438 | WARN_ON(1); | |
7439 | return NULL; | |
7440 | } | |
7441 | ||
7442 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, | |
7443 | cmd, attr, info, gfp); | |
7444 | } | |
7445 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
7446 | ||
7447 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
7448 | { | |
7449 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
7450 | void *hdr = ((void **)skb->cb)[1]; | |
7451 | struct nlattr *data = ((void **)skb->cb)[2]; | |
7452 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
7453 | ||
bd8c78e7 JB |
7454 | /* clear CB data for netlink core to own from now on */ |
7455 | memset(skb->cb, 0, sizeof(skb->cb)); | |
7456 | ||
e03ad6ea JB |
7457 | nla_nest_end(skb, data); |
7458 | genlmsg_end(skb, hdr); | |
7459 | ||
7460 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
7461 | mcgrp = NL80211_MCGRP_VENDOR; | |
7462 | ||
7463 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
7464 | mcgrp, gfp); | |
7465 | } | |
7466 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
7467 | ||
aff89a9b | 7468 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
7469 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
7470 | { | |
4c476991 | 7471 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
7472 | struct wireless_dev *wdev = |
7473 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
7474 | int err; |
7475 | ||
fc73f11f DS |
7476 | if (!rdev->ops->testmode_cmd) |
7477 | return -EOPNOTSUPP; | |
7478 | ||
7479 | if (IS_ERR(wdev)) { | |
7480 | err = PTR_ERR(wdev); | |
7481 | if (err != -EINVAL) | |
7482 | return err; | |
7483 | wdev = NULL; | |
7484 | } else if (wdev->wiphy != &rdev->wiphy) { | |
7485 | return -EINVAL; | |
7486 | } | |
7487 | ||
aff89a9b JB |
7488 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
7489 | return -EINVAL; | |
7490 | ||
ad7e718c | 7491 | rdev->cur_cmd_info = info; |
fc73f11f | 7492 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
7493 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
7494 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 7495 | rdev->cur_cmd_info = NULL; |
aff89a9b | 7496 | |
aff89a9b JB |
7497 | return err; |
7498 | } | |
7499 | ||
71063f0e WYG |
7500 | static int nl80211_testmode_dump(struct sk_buff *skb, |
7501 | struct netlink_callback *cb) | |
7502 | { | |
00918d33 | 7503 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
7504 | int err; |
7505 | long phy_idx; | |
7506 | void *data = NULL; | |
7507 | int data_len = 0; | |
7508 | ||
5fe231e8 JB |
7509 | rtnl_lock(); |
7510 | ||
71063f0e WYG |
7511 | if (cb->args[0]) { |
7512 | /* | |
7513 | * 0 is a valid index, but not valid for args[0], | |
7514 | * so we need to offset by 1. | |
7515 | */ | |
7516 | phy_idx = cb->args[0] - 1; | |
7517 | } else { | |
7518 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
7519 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
7520 | nl80211_policy); | |
7521 | if (err) | |
5fe231e8 | 7522 | goto out_err; |
00918d33 | 7523 | |
2bd7e35d JB |
7524 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
7525 | nl80211_fam.attrbuf); | |
7526 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
7527 | err = PTR_ERR(rdev); |
7528 | goto out_err; | |
00918d33 | 7529 | } |
2bd7e35d JB |
7530 | phy_idx = rdev->wiphy_idx; |
7531 | rdev = NULL; | |
2bd7e35d | 7532 | |
71063f0e WYG |
7533 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
7534 | cb->args[1] = | |
7535 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
7536 | } | |
7537 | ||
7538 | if (cb->args[1]) { | |
7539 | data = nla_data((void *)cb->args[1]); | |
7540 | data_len = nla_len((void *)cb->args[1]); | |
7541 | } | |
7542 | ||
00918d33 JB |
7543 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
7544 | if (!rdev) { | |
5fe231e8 JB |
7545 | err = -ENOENT; |
7546 | goto out_err; | |
71063f0e | 7547 | } |
71063f0e | 7548 | |
00918d33 | 7549 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
7550 | err = -EOPNOTSUPP; |
7551 | goto out_err; | |
7552 | } | |
7553 | ||
7554 | while (1) { | |
15e47304 | 7555 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
7556 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
7557 | NL80211_CMD_TESTMODE); | |
7558 | struct nlattr *tmdata; | |
7559 | ||
cb35fba3 DC |
7560 | if (!hdr) |
7561 | break; | |
7562 | ||
9360ffd1 | 7563 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
7564 | genlmsg_cancel(skb, hdr); |
7565 | break; | |
7566 | } | |
7567 | ||
7568 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
7569 | if (!tmdata) { | |
7570 | genlmsg_cancel(skb, hdr); | |
7571 | break; | |
7572 | } | |
e35e4d28 | 7573 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
7574 | nla_nest_end(skb, tmdata); |
7575 | ||
7576 | if (err == -ENOBUFS || err == -ENOENT) { | |
7577 | genlmsg_cancel(skb, hdr); | |
7578 | break; | |
7579 | } else if (err) { | |
7580 | genlmsg_cancel(skb, hdr); | |
7581 | goto out_err; | |
7582 | } | |
7583 | ||
7584 | genlmsg_end(skb, hdr); | |
7585 | } | |
7586 | ||
7587 | err = skb->len; | |
7588 | /* see above */ | |
7589 | cb->args[0] = phy_idx + 1; | |
7590 | out_err: | |
5fe231e8 | 7591 | rtnl_unlock(); |
71063f0e WYG |
7592 | return err; |
7593 | } | |
aff89a9b JB |
7594 | #endif |
7595 | ||
b23aa676 SO |
7596 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
7597 | { | |
4c476991 JB |
7598 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7599 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
7600 | struct cfg80211_connect_params connect; |
7601 | struct wiphy *wiphy; | |
fffd0934 | 7602 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
7603 | int err; |
7604 | ||
7605 | memset(&connect, 0, sizeof(connect)); | |
7606 | ||
7607 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
7608 | return -EINVAL; | |
7609 | ||
7610 | if (!info->attrs[NL80211_ATTR_SSID] || | |
7611 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
7612 | return -EINVAL; | |
7613 | ||
7614 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
7615 | connect.auth_type = | |
7616 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
7617 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
7618 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
7619 | return -EINVAL; |
7620 | } else | |
7621 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
7622 | ||
7623 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
7624 | ||
c0692b8f | 7625 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 7626 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
7627 | if (err) |
7628 | return err; | |
b23aa676 | 7629 | |
074ac8df | 7630 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7631 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7632 | return -EOPNOTSUPP; | |
b23aa676 | 7633 | |
79c97e97 | 7634 | wiphy = &rdev->wiphy; |
b23aa676 | 7635 | |
4486ea98 BS |
7636 | connect.bg_scan_period = -1; |
7637 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
7638 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
7639 | connect.bg_scan_period = | |
7640 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
7641 | } | |
7642 | ||
b23aa676 SO |
7643 | if (info->attrs[NL80211_ATTR_MAC]) |
7644 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
7645 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
7646 | connect.bssid_hint = | |
7647 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
7648 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7649 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7650 | ||
7651 | if (info->attrs[NL80211_ATTR_IE]) { | |
7652 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7653 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7654 | } | |
7655 | ||
cee00a95 JM |
7656 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
7657 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
7658 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
7659 | connect.mfp != NL80211_MFP_NO) | |
7660 | return -EINVAL; | |
7661 | } else { | |
7662 | connect.mfp = NL80211_MFP_NO; | |
7663 | } | |
7664 | ||
b23aa676 | 7665 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
7666 | connect.channel = nl80211_get_valid_chan( |
7667 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7668 | if (!connect.channel) | |
1df4a510 JM |
7669 | return -EINVAL; |
7670 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
7671 | connect.channel_hint = nl80211_get_valid_chan( |
7672 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
7673 | if (!connect.channel_hint) | |
4c476991 | 7674 | return -EINVAL; |
b23aa676 SO |
7675 | } |
7676 | ||
fffd0934 JB |
7677 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
7678 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 7679 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
7680 | if (IS_ERR(connkeys)) |
7681 | return PTR_ERR(connkeys); | |
fffd0934 JB |
7682 | } |
7683 | ||
7e7c8926 BG |
7684 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
7685 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
7686 | ||
7687 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7688 | memcpy(&connect.ht_capa_mask, | |
7689 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7690 | sizeof(connect.ht_capa_mask)); | |
7691 | ||
7692 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e | 7693 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
b47f610b | 7694 | kzfree(connkeys); |
7e7c8926 | 7695 | return -EINVAL; |
b4e4f47e | 7696 | } |
7e7c8926 BG |
7697 | memcpy(&connect.ht_capa, |
7698 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7699 | sizeof(connect.ht_capa)); | |
7700 | } | |
7701 | ||
ee2aca34 JB |
7702 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
7703 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
7704 | ||
7705 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
7706 | memcpy(&connect.vht_capa_mask, | |
7707 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7708 | sizeof(connect.vht_capa_mask)); | |
7709 | ||
7710 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
7711 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
b47f610b | 7712 | kzfree(connkeys); |
ee2aca34 JB |
7713 | return -EINVAL; |
7714 | } | |
7715 | memcpy(&connect.vht_capa, | |
7716 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7717 | sizeof(connect.vht_capa)); | |
7718 | } | |
7719 | ||
bab5ab7d AK |
7720 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7721 | if (!(rdev->wiphy.features & | |
7722 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7723 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7724 | return -EINVAL; | |
7725 | connect.flags |= ASSOC_REQ_USE_RRM; | |
7726 | } | |
7727 | ||
83739b03 JB |
7728 | wdev_lock(dev->ieee80211_ptr); |
7729 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
7730 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 | 7731 | if (err) |
b47f610b | 7732 | kzfree(connkeys); |
b23aa676 SO |
7733 | return err; |
7734 | } | |
7735 | ||
7736 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
7737 | { | |
4c476991 JB |
7738 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7739 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 7740 | u16 reason; |
83739b03 | 7741 | int ret; |
b23aa676 SO |
7742 | |
7743 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7744 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
7745 | else | |
7746 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
7747 | ||
7748 | if (reason == 0) | |
7749 | return -EINVAL; | |
7750 | ||
074ac8df | 7751 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7752 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7753 | return -EOPNOTSUPP; | |
b23aa676 | 7754 | |
83739b03 JB |
7755 | wdev_lock(dev->ieee80211_ptr); |
7756 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
7757 | wdev_unlock(dev->ieee80211_ptr); | |
7758 | return ret; | |
b23aa676 SO |
7759 | } |
7760 | ||
463d0183 JB |
7761 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
7762 | { | |
4c476991 | 7763 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
7764 | struct net *net; |
7765 | int err; | |
463d0183 | 7766 | |
4b681c82 VK |
7767 | if (info->attrs[NL80211_ATTR_PID]) { |
7768 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
7769 | ||
7770 | net = get_net_ns_by_pid(pid); | |
7771 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { | |
7772 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); | |
463d0183 | 7773 | |
4b681c82 VK |
7774 | net = get_net_ns_by_fd(fd); |
7775 | } else { | |
7776 | return -EINVAL; | |
7777 | } | |
463d0183 | 7778 | |
4c476991 JB |
7779 | if (IS_ERR(net)) |
7780 | return PTR_ERR(net); | |
463d0183 JB |
7781 | |
7782 | err = 0; | |
7783 | ||
7784 | /* check if anything to do */ | |
4c476991 JB |
7785 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
7786 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 7787 | |
463d0183 | 7788 | put_net(net); |
463d0183 JB |
7789 | return err; |
7790 | } | |
7791 | ||
67fbb16b SO |
7792 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
7793 | { | |
4c476991 | 7794 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
7795 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
7796 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 7797 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
7798 | struct cfg80211_pmksa pmksa; |
7799 | ||
7800 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
7801 | ||
7802 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7803 | return -EINVAL; | |
7804 | ||
7805 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
7806 | return -EINVAL; | |
7807 | ||
67fbb16b SO |
7808 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
7809 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7810 | ||
074ac8df | 7811 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7812 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7813 | return -EOPNOTSUPP; | |
67fbb16b SO |
7814 | |
7815 | switch (info->genlhdr->cmd) { | |
7816 | case NL80211_CMD_SET_PMKSA: | |
7817 | rdev_ops = rdev->ops->set_pmksa; | |
7818 | break; | |
7819 | case NL80211_CMD_DEL_PMKSA: | |
7820 | rdev_ops = rdev->ops->del_pmksa; | |
7821 | break; | |
7822 | default: | |
7823 | WARN_ON(1); | |
7824 | break; | |
7825 | } | |
7826 | ||
4c476991 JB |
7827 | if (!rdev_ops) |
7828 | return -EOPNOTSUPP; | |
67fbb16b | 7829 | |
4c476991 | 7830 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
7831 | } |
7832 | ||
7833 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
7834 | { | |
4c476991 JB |
7835 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7836 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 7837 | |
074ac8df | 7838 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7839 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7840 | return -EOPNOTSUPP; | |
67fbb16b | 7841 | |
4c476991 JB |
7842 | if (!rdev->ops->flush_pmksa) |
7843 | return -EOPNOTSUPP; | |
67fbb16b | 7844 | |
e35e4d28 | 7845 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
7846 | } |
7847 | ||
109086ce AN |
7848 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
7849 | { | |
7850 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7851 | struct net_device *dev = info->user_ptr[1]; | |
7852 | u8 action_code, dialog_token; | |
df942e7b | 7853 | u32 peer_capability = 0; |
109086ce AN |
7854 | u16 status_code; |
7855 | u8 *peer; | |
31fa97c5 | 7856 | bool initiator; |
109086ce AN |
7857 | |
7858 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7859 | !rdev->ops->tdls_mgmt) | |
7860 | return -EOPNOTSUPP; | |
7861 | ||
7862 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
7863 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
7864 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
7865 | !info->attrs[NL80211_ATTR_IE] || | |
7866 | !info->attrs[NL80211_ATTR_MAC]) | |
7867 | return -EINVAL; | |
7868 | ||
7869 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7870 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
7871 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
7872 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 7873 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
7874 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
7875 | peer_capability = | |
7876 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 7877 | |
e35e4d28 | 7878 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 7879 | dialog_token, status_code, peer_capability, |
31fa97c5 | 7880 | initiator, |
e35e4d28 HG |
7881 | nla_data(info->attrs[NL80211_ATTR_IE]), |
7882 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
7883 | } |
7884 | ||
7885 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
7886 | { | |
7887 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7888 | struct net_device *dev = info->user_ptr[1]; | |
7889 | enum nl80211_tdls_operation operation; | |
7890 | u8 *peer; | |
7891 | ||
7892 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7893 | !rdev->ops->tdls_oper) | |
7894 | return -EOPNOTSUPP; | |
7895 | ||
7896 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
7897 | !info->attrs[NL80211_ATTR_MAC]) | |
7898 | return -EINVAL; | |
7899 | ||
7900 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
7901 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7902 | ||
e35e4d28 | 7903 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
7904 | } |
7905 | ||
9588bbd5 JM |
7906 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
7907 | struct genl_info *info) | |
7908 | { | |
4c476991 | 7909 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7910 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7911 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
7912 | struct sk_buff *msg; |
7913 | void *hdr; | |
7914 | u64 cookie; | |
683b6d3b | 7915 | u32 duration; |
9588bbd5 JM |
7916 | int err; |
7917 | ||
7918 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7919 | !info->attrs[NL80211_ATTR_DURATION]) | |
7920 | return -EINVAL; | |
7921 | ||
7922 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
7923 | ||
ebf348fc JB |
7924 | if (!rdev->ops->remain_on_channel || |
7925 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
7926 | return -EOPNOTSUPP; | |
7927 | ||
9588bbd5 | 7928 | /* |
ebf348fc JB |
7929 | * We should be on that channel for at least a minimum amount of |
7930 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 7931 | */ |
ebf348fc | 7932 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 7933 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
7934 | return -EINVAL; |
7935 | ||
683b6d3b JB |
7936 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7937 | if (err) | |
7938 | return err; | |
9588bbd5 JM |
7939 | |
7940 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7941 | if (!msg) |
7942 | return -ENOMEM; | |
9588bbd5 | 7943 | |
15e47304 | 7944 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 7945 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
7946 | if (!hdr) { |
7947 | err = -ENOBUFS; | |
9588bbd5 JM |
7948 | goto free_msg; |
7949 | } | |
7950 | ||
683b6d3b JB |
7951 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7952 | duration, &cookie); | |
9588bbd5 JM |
7953 | |
7954 | if (err) | |
7955 | goto free_msg; | |
7956 | ||
9360ffd1 DM |
7957 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7958 | goto nla_put_failure; | |
9588bbd5 JM |
7959 | |
7960 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7961 | |
7962 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7963 | |
7964 | nla_put_failure: | |
7965 | err = -ENOBUFS; | |
7966 | free_msg: | |
7967 | nlmsg_free(msg); | |
9588bbd5 JM |
7968 | return err; |
7969 | } | |
7970 | ||
7971 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
7972 | struct genl_info *info) | |
7973 | { | |
4c476991 | 7974 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7975 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 7976 | u64 cookie; |
9588bbd5 JM |
7977 | |
7978 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7979 | return -EINVAL; | |
7980 | ||
4c476991 JB |
7981 | if (!rdev->ops->cancel_remain_on_channel) |
7982 | return -EOPNOTSUPP; | |
9588bbd5 | 7983 | |
9588bbd5 JM |
7984 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
7985 | ||
e35e4d28 | 7986 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
7987 | } |
7988 | ||
13ae75b1 JM |
7989 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
7990 | u8 *rates, u8 rates_len) | |
7991 | { | |
7992 | u8 i; | |
7993 | u32 mask = 0; | |
7994 | ||
7995 | for (i = 0; i < rates_len; i++) { | |
7996 | int rate = (rates[i] & 0x7f) * 5; | |
7997 | int ridx; | |
7998 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
7999 | struct ieee80211_rate *srate = | |
8000 | &sband->bitrates[ridx]; | |
8001 | if (rate == srate->bitrate) { | |
8002 | mask |= 1 << ridx; | |
8003 | break; | |
8004 | } | |
8005 | } | |
8006 | if (ridx == sband->n_bitrates) | |
8007 | return 0; /* rate not found */ | |
8008 | } | |
8009 | ||
8010 | return mask; | |
8011 | } | |
8012 | ||
24db78c0 SW |
8013 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
8014 | u8 *rates, u8 rates_len, | |
8015 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
8016 | { | |
8017 | u8 i; | |
8018 | ||
8019 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
8020 | ||
8021 | for (i = 0; i < rates_len; i++) { | |
8022 | int ridx, rbit; | |
8023 | ||
8024 | ridx = rates[i] / 8; | |
8025 | rbit = BIT(rates[i] % 8); | |
8026 | ||
8027 | /* check validity */ | |
910570b5 | 8028 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
8029 | return false; |
8030 | ||
8031 | /* check availability */ | |
8032 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
8033 | mcs[ridx] |= rbit; | |
8034 | else | |
8035 | return false; | |
8036 | } | |
8037 | ||
8038 | return true; | |
8039 | } | |
8040 | ||
204e35a9 JD |
8041 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
8042 | { | |
8043 | u16 mcs_mask = 0; | |
8044 | ||
8045 | switch (vht_mcs_map) { | |
8046 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
8047 | break; | |
8048 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
8049 | mcs_mask = 0x00FF; | |
8050 | break; | |
8051 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
8052 | mcs_mask = 0x01FF; | |
8053 | break; | |
8054 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
8055 | mcs_mask = 0x03FF; | |
8056 | break; | |
8057 | default: | |
8058 | break; | |
8059 | } | |
8060 | ||
8061 | return mcs_mask; | |
8062 | } | |
8063 | ||
8064 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
8065 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
8066 | { | |
8067 | u8 nss; | |
8068 | ||
8069 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
8070 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
8071 | vht_mcs_map >>= 2; | |
8072 | } | |
8073 | } | |
8074 | ||
8075 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
8076 | struct nl80211_txrate_vht *txrate, | |
8077 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
8078 | { | |
8079 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8080 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
8081 | u8 i; | |
8082 | ||
8083 | if (!sband->vht_cap.vht_supported) | |
8084 | return false; | |
8085 | ||
8086 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
8087 | ||
8088 | /* Build vht_mcs_mask from VHT capabilities */ | |
8089 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
8090 | ||
8091 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
8092 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
8093 | mcs[i] = txrate->mcs[i]; | |
8094 | else | |
8095 | return false; | |
8096 | } | |
8097 | ||
8098 | return true; | |
8099 | } | |
8100 | ||
b54452b0 | 8101 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
8102 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
8103 | .len = NL80211_MAX_SUPP_RATES }, | |
d1e33e65 JD |
8104 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
8105 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
204e35a9 | 8106 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
0b9323f6 | 8107 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
13ae75b1 JM |
8108 | }; |
8109 | ||
8110 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
8111 | struct genl_info *info) | |
8112 | { | |
8113 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 8114 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 8115 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
8116 | int rem, i; |
8117 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
8118 | struct nlattr *tx_rates; |
8119 | struct ieee80211_supported_band *sband; | |
204e35a9 | 8120 | u16 vht_tx_mcs_map; |
13ae75b1 | 8121 | |
4c476991 JB |
8122 | if (!rdev->ops->set_bitrate_mask) |
8123 | return -EOPNOTSUPP; | |
13ae75b1 JM |
8124 | |
8125 | memset(&mask, 0, sizeof(mask)); | |
8126 | /* Default to all rates enabled */ | |
8127 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
8128 | sband = rdev->wiphy.bands[i]; | |
7869303b JD |
8129 | |
8130 | if (!sband) | |
8131 | continue; | |
8132 | ||
8133 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; | |
d1e33e65 | 8134 | memcpy(mask.control[i].ht_mcs, |
7869303b | 8135 | sband->ht_cap.mcs.rx_mask, |
d1e33e65 | 8136 | sizeof(mask.control[i].ht_mcs)); |
204e35a9 JD |
8137 | |
8138 | if (!sband->vht_cap.vht_supported) | |
8139 | continue; | |
8140 | ||
8141 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8142 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); | |
13ae75b1 JM |
8143 | } |
8144 | ||
b9243ab0 JD |
8145 | /* if no rates are given set it back to the defaults */ |
8146 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
8147 | goto out; | |
8148 | ||
13ae75b1 JM |
8149 | /* |
8150 | * The nested attribute uses enum nl80211_band as the index. This maps | |
8151 | * directly to the enum ieee80211_band values used in cfg80211. | |
8152 | */ | |
24db78c0 | 8153 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
ae811e21 | 8154 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
13ae75b1 | 8155 | enum ieee80211_band band = nla_type(tx_rates); |
ae811e21 JB |
8156 | int err; |
8157 | ||
4c476991 JB |
8158 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
8159 | return -EINVAL; | |
13ae75b1 | 8160 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
8161 | if (sband == NULL) |
8162 | return -EINVAL; | |
ae811e21 JB |
8163 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
8164 | nla_len(tx_rates), nl80211_txattr_policy); | |
8165 | if (err) | |
8166 | return err; | |
13ae75b1 JM |
8167 | if (tb[NL80211_TXRATE_LEGACY]) { |
8168 | mask.control[band].legacy = rateset_to_mask( | |
8169 | sband, | |
8170 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
8171 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
8172 | if ((mask.control[band].legacy == 0) && |
8173 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
8174 | return -EINVAL; | |
24db78c0 | 8175 | } |
d1e33e65 | 8176 | if (tb[NL80211_TXRATE_HT]) { |
24db78c0 SW |
8177 | if (!ht_rateset_to_mask( |
8178 | sband, | |
d1e33e65 JD |
8179 | nla_data(tb[NL80211_TXRATE_HT]), |
8180 | nla_len(tb[NL80211_TXRATE_HT]), | |
8181 | mask.control[band].ht_mcs)) | |
24db78c0 SW |
8182 | return -EINVAL; |
8183 | } | |
204e35a9 JD |
8184 | if (tb[NL80211_TXRATE_VHT]) { |
8185 | if (!vht_set_mcs_mask( | |
8186 | sband, | |
8187 | nla_data(tb[NL80211_TXRATE_VHT]), | |
8188 | mask.control[band].vht_mcs)) | |
8189 | return -EINVAL; | |
8190 | } | |
0b9323f6 JD |
8191 | if (tb[NL80211_TXRATE_GI]) { |
8192 | mask.control[band].gi = | |
8193 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
8194 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
8195 | return -EINVAL; | |
8196 | } | |
24db78c0 SW |
8197 | |
8198 | if (mask.control[band].legacy == 0) { | |
204e35a9 JD |
8199 | /* don't allow empty legacy rates if HT or VHT |
8200 | * are not even supported. | |
8201 | */ | |
8202 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
8203 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
24db78c0 SW |
8204 | return -EINVAL; |
8205 | ||
8206 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
d1e33e65 | 8207 | if (mask.control[band].ht_mcs[i]) |
204e35a9 JD |
8208 | goto out; |
8209 | ||
8210 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
8211 | if (mask.control[band].vht_mcs[i]) | |
8212 | goto out; | |
24db78c0 SW |
8213 | |
8214 | /* legacy and mcs rates may not be both empty */ | |
204e35a9 | 8215 | return -EINVAL; |
13ae75b1 JM |
8216 | } |
8217 | } | |
8218 | ||
b9243ab0 | 8219 | out: |
e35e4d28 | 8220 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
8221 | } |
8222 | ||
2e161f78 | 8223 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8224 | { |
4c476991 | 8225 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8226 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 8227 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
8228 | |
8229 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
8230 | return -EINVAL; | |
8231 | ||
2e161f78 JB |
8232 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
8233 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 8234 | |
71bbc994 JB |
8235 | switch (wdev->iftype) { |
8236 | case NL80211_IFTYPE_STATION: | |
8237 | case NL80211_IFTYPE_ADHOC: | |
8238 | case NL80211_IFTYPE_P2P_CLIENT: | |
8239 | case NL80211_IFTYPE_AP: | |
8240 | case NL80211_IFTYPE_AP_VLAN: | |
8241 | case NL80211_IFTYPE_MESH_POINT: | |
8242 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8243 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8244 | break; |
8245 | default: | |
4c476991 | 8246 | return -EOPNOTSUPP; |
71bbc994 | 8247 | } |
026331c4 JM |
8248 | |
8249 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
8250 | if (!rdev->ops->mgmt_tx) |
8251 | return -EOPNOTSUPP; | |
026331c4 | 8252 | |
15e47304 | 8253 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
8254 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
8255 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
8256 | } |
8257 | ||
2e161f78 | 8258 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8259 | { |
4c476991 | 8260 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8261 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 8262 | struct cfg80211_chan_def chandef; |
026331c4 | 8263 | int err; |
d64d373f | 8264 | void *hdr = NULL; |
026331c4 | 8265 | u64 cookie; |
e247bd90 | 8266 | struct sk_buff *msg = NULL; |
b176e629 AO |
8267 | struct cfg80211_mgmt_tx_params params = { |
8268 | .dont_wait_for_ack = | |
8269 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
8270 | }; | |
026331c4 | 8271 | |
683b6d3b | 8272 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
8273 | return -EINVAL; |
8274 | ||
4c476991 JB |
8275 | if (!rdev->ops->mgmt_tx) |
8276 | return -EOPNOTSUPP; | |
026331c4 | 8277 | |
71bbc994 | 8278 | switch (wdev->iftype) { |
ea141b75 AQ |
8279 | case NL80211_IFTYPE_P2P_DEVICE: |
8280 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
8281 | return -EINVAL; | |
71bbc994 JB |
8282 | case NL80211_IFTYPE_STATION: |
8283 | case NL80211_IFTYPE_ADHOC: | |
8284 | case NL80211_IFTYPE_P2P_CLIENT: | |
8285 | case NL80211_IFTYPE_AP: | |
8286 | case NL80211_IFTYPE_AP_VLAN: | |
8287 | case NL80211_IFTYPE_MESH_POINT: | |
8288 | case NL80211_IFTYPE_P2P_GO: | |
8289 | break; | |
8290 | default: | |
4c476991 | 8291 | return -EOPNOTSUPP; |
71bbc994 | 8292 | } |
026331c4 | 8293 | |
f7ca38df | 8294 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 8295 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 8296 | return -EINVAL; |
b176e629 | 8297 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
8298 | |
8299 | /* | |
8300 | * We should wait on the channel for at least a minimum amount | |
8301 | * of time (10ms) but no longer than the driver supports. | |
8302 | */ | |
b176e629 AO |
8303 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
8304 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc JB |
8305 | return -EINVAL; |
8306 | ||
f7ca38df JB |
8307 | } |
8308 | ||
b176e629 | 8309 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 8310 | |
b176e629 | 8311 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
8312 | return -EINVAL; |
8313 | ||
b176e629 | 8314 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 8315 | |
ea141b75 AQ |
8316 | /* get the channel if any has been specified, otherwise pass NULL to |
8317 | * the driver. The latter will use the current one | |
8318 | */ | |
8319 | chandef.chan = NULL; | |
8320 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
8321 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
8322 | if (err) | |
8323 | return err; | |
8324 | } | |
8325 | ||
b176e629 | 8326 | if (!chandef.chan && params.offchan) |
ea141b75 | 8327 | return -EINVAL; |
026331c4 | 8328 | |
34d22ce2 AO |
8329 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
8330 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
8331 | ||
8332 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
8333 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8334 | int i; | |
8335 | ||
8336 | if (len % sizeof(u16)) | |
8337 | return -EINVAL; | |
8338 | ||
8339 | params.n_csa_offsets = len / sizeof(u16); | |
8340 | params.csa_offsets = | |
8341 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8342 | ||
8343 | /* check that all the offsets fit the frame */ | |
8344 | for (i = 0; i < params.n_csa_offsets; i++) { | |
8345 | if (params.csa_offsets[i] >= params.len) | |
8346 | return -EINVAL; | |
8347 | } | |
8348 | } | |
8349 | ||
b176e629 | 8350 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
8351 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
8352 | if (!msg) | |
8353 | return -ENOMEM; | |
026331c4 | 8354 | |
15e47304 | 8355 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 8356 | NL80211_CMD_FRAME); |
cb35fba3 DC |
8357 | if (!hdr) { |
8358 | err = -ENOBUFS; | |
e247bd90 JB |
8359 | goto free_msg; |
8360 | } | |
026331c4 | 8361 | } |
e247bd90 | 8362 | |
b176e629 AO |
8363 | params.chan = chandef.chan; |
8364 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
8365 | if (err) |
8366 | goto free_msg; | |
8367 | ||
e247bd90 | 8368 | if (msg) { |
9360ffd1 DM |
8369 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8370 | goto nla_put_failure; | |
026331c4 | 8371 | |
e247bd90 JB |
8372 | genlmsg_end(msg, hdr); |
8373 | return genlmsg_reply(msg, info); | |
8374 | } | |
8375 | ||
8376 | return 0; | |
026331c4 JM |
8377 | |
8378 | nla_put_failure: | |
8379 | err = -ENOBUFS; | |
8380 | free_msg: | |
8381 | nlmsg_free(msg); | |
026331c4 JM |
8382 | return err; |
8383 | } | |
8384 | ||
f7ca38df JB |
8385 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
8386 | { | |
8387 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 8388 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
8389 | u64 cookie; |
8390 | ||
8391 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8392 | return -EINVAL; | |
8393 | ||
8394 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
8395 | return -EOPNOTSUPP; | |
8396 | ||
71bbc994 JB |
8397 | switch (wdev->iftype) { |
8398 | case NL80211_IFTYPE_STATION: | |
8399 | case NL80211_IFTYPE_ADHOC: | |
8400 | case NL80211_IFTYPE_P2P_CLIENT: | |
8401 | case NL80211_IFTYPE_AP: | |
8402 | case NL80211_IFTYPE_AP_VLAN: | |
8403 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8404 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8405 | break; |
8406 | default: | |
f7ca38df | 8407 | return -EOPNOTSUPP; |
71bbc994 | 8408 | } |
f7ca38df JB |
8409 | |
8410 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
8411 | ||
e35e4d28 | 8412 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
8413 | } |
8414 | ||
ffb9eb3d KV |
8415 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
8416 | { | |
4c476991 | 8417 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 8418 | struct wireless_dev *wdev; |
4c476991 | 8419 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8420 | u8 ps_state; |
8421 | bool state; | |
8422 | int err; | |
8423 | ||
4c476991 JB |
8424 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
8425 | return -EINVAL; | |
ffb9eb3d KV |
8426 | |
8427 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
8428 | ||
4c476991 JB |
8429 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
8430 | return -EINVAL; | |
ffb9eb3d KV |
8431 | |
8432 | wdev = dev->ieee80211_ptr; | |
8433 | ||
4c476991 JB |
8434 | if (!rdev->ops->set_power_mgmt) |
8435 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8436 | |
8437 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
8438 | ||
8439 | if (state == wdev->ps) | |
4c476991 | 8440 | return 0; |
ffb9eb3d | 8441 | |
e35e4d28 | 8442 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
8443 | if (!err) |
8444 | wdev->ps = state; | |
ffb9eb3d KV |
8445 | return err; |
8446 | } | |
8447 | ||
8448 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
8449 | { | |
4c476991 | 8450 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
8451 | enum nl80211_ps_state ps_state; |
8452 | struct wireless_dev *wdev; | |
4c476991 | 8453 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8454 | struct sk_buff *msg; |
8455 | void *hdr; | |
8456 | int err; | |
8457 | ||
ffb9eb3d KV |
8458 | wdev = dev->ieee80211_ptr; |
8459 | ||
4c476991 JB |
8460 | if (!rdev->ops->set_power_mgmt) |
8461 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8462 | |
8463 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
8464 | if (!msg) |
8465 | return -ENOMEM; | |
ffb9eb3d | 8466 | |
15e47304 | 8467 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
8468 | NL80211_CMD_GET_POWER_SAVE); |
8469 | if (!hdr) { | |
4c476991 | 8470 | err = -ENOBUFS; |
ffb9eb3d KV |
8471 | goto free_msg; |
8472 | } | |
8473 | ||
8474 | if (wdev->ps) | |
8475 | ps_state = NL80211_PS_ENABLED; | |
8476 | else | |
8477 | ps_state = NL80211_PS_DISABLED; | |
8478 | ||
9360ffd1 DM |
8479 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
8480 | goto nla_put_failure; | |
ffb9eb3d KV |
8481 | |
8482 | genlmsg_end(msg, hdr); | |
4c476991 | 8483 | return genlmsg_reply(msg, info); |
ffb9eb3d | 8484 | |
4c476991 | 8485 | nla_put_failure: |
ffb9eb3d | 8486 | err = -ENOBUFS; |
4c476991 | 8487 | free_msg: |
ffb9eb3d | 8488 | nlmsg_free(msg); |
ffb9eb3d KV |
8489 | return err; |
8490 | } | |
8491 | ||
94e860f1 JB |
8492 | static const struct nla_policy |
8493 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
8494 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
8495 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
8496 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
8497 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
8498 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
8499 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
8500 | }; |
8501 | ||
84f10708 | 8502 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 8503 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
8504 | { |
8505 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 8506 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8507 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 8508 | |
d9d8b019 | 8509 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
8510 | return -EINVAL; |
8511 | ||
84f10708 TP |
8512 | if (!rdev->ops->set_cqm_txe_config) |
8513 | return -EOPNOTSUPP; | |
8514 | ||
8515 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
8516 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
8517 | return -EOPNOTSUPP; | |
8518 | ||
e35e4d28 | 8519 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
8520 | } |
8521 | ||
d6dc1a38 JO |
8522 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
8523 | s32 threshold, u32 hysteresis) | |
8524 | { | |
4c476991 | 8525 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 8526 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8527 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
8528 | |
8529 | if (threshold > 0) | |
8530 | return -EINVAL; | |
8531 | ||
1da5fcc8 JB |
8532 | /* disabling - hysteresis should also be zero then */ |
8533 | if (threshold == 0) | |
8534 | hysteresis = 0; | |
d6dc1a38 | 8535 | |
4c476991 JB |
8536 | if (!rdev->ops->set_cqm_rssi_config) |
8537 | return -EOPNOTSUPP; | |
d6dc1a38 | 8538 | |
074ac8df | 8539 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8540 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8541 | return -EOPNOTSUPP; | |
d6dc1a38 | 8542 | |
e35e4d28 | 8543 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
8544 | } |
8545 | ||
8546 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
8547 | { | |
8548 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
8549 | struct nlattr *cqm; | |
8550 | int err; | |
8551 | ||
8552 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
8553 | if (!cqm) |
8554 | return -EINVAL; | |
d6dc1a38 JO |
8555 | |
8556 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
8557 | nl80211_attr_cqm_policy); | |
8558 | if (err) | |
1da5fcc8 | 8559 | return err; |
d6dc1a38 JO |
8560 | |
8561 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
8562 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
8563 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
8564 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 8565 | |
1da5fcc8 JB |
8566 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
8567 | } | |
8568 | ||
8569 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
8570 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
8571 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
8572 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
8573 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
8574 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
8575 | ||
8576 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
8577 | } | |
8578 | ||
8579 | return -EINVAL; | |
d6dc1a38 JO |
8580 | } |
8581 | ||
6e0bd6c3 RL |
8582 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
8583 | { | |
8584 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8585 | struct net_device *dev = info->user_ptr[1]; | |
8586 | struct ocb_setup setup = {}; | |
8587 | int err; | |
8588 | ||
8589 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | |
8590 | if (err) | |
8591 | return err; | |
8592 | ||
8593 | return cfg80211_join_ocb(rdev, dev, &setup); | |
8594 | } | |
8595 | ||
8596 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | |
8597 | { | |
8598 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8599 | struct net_device *dev = info->user_ptr[1]; | |
8600 | ||
8601 | return cfg80211_leave_ocb(rdev, dev); | |
8602 | } | |
8603 | ||
29cbe68c JB |
8604 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
8605 | { | |
8606 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8607 | struct net_device *dev = info->user_ptr[1]; | |
8608 | struct mesh_config cfg; | |
c80d545d | 8609 | struct mesh_setup setup; |
29cbe68c JB |
8610 | int err; |
8611 | ||
8612 | /* start with default */ | |
8613 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 8614 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 8615 | |
24bdd9f4 | 8616 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 8617 | /* and parse parameters if given */ |
24bdd9f4 | 8618 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
8619 | if (err) |
8620 | return err; | |
8621 | } | |
8622 | ||
8623 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
8624 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
8625 | return -EINVAL; | |
8626 | ||
c80d545d JC |
8627 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
8628 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
8629 | ||
4bb62344 CYY |
8630 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8631 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
8632 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8633 | return -EINVAL; | |
8634 | ||
9bdbf04d MP |
8635 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
8636 | setup.beacon_interval = | |
8637 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
8638 | if (setup.beacon_interval < 10 || | |
8639 | setup.beacon_interval > 10000) | |
8640 | return -EINVAL; | |
8641 | } | |
8642 | ||
8643 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
8644 | setup.dtim_period = | |
8645 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
8646 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
8647 | return -EINVAL; | |
8648 | } | |
8649 | ||
c80d545d JC |
8650 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
8651 | /* parse additional setup parameters if given */ | |
8652 | err = nl80211_parse_mesh_setup(info, &setup); | |
8653 | if (err) | |
8654 | return err; | |
8655 | } | |
8656 | ||
d37bb18a TP |
8657 | if (setup.user_mpm) |
8658 | cfg.auto_open_plinks = false; | |
8659 | ||
cc1d2806 | 8660 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
8661 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
8662 | if (err) | |
8663 | return err; | |
cc1d2806 JB |
8664 | } else { |
8665 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 8666 | setup.chandef.chan = NULL; |
cc1d2806 JB |
8667 | } |
8668 | ||
ffb3cf30 AN |
8669 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8670 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8671 | int n_rates = | |
8672 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8673 | struct ieee80211_supported_band *sband; | |
8674 | ||
8675 | if (!setup.chandef.chan) | |
8676 | return -EINVAL; | |
8677 | ||
8678 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
8679 | ||
8680 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
8681 | &setup.basic_rates); | |
8682 | if (err) | |
8683 | return err; | |
8684 | } | |
8685 | ||
c80d545d | 8686 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
8687 | } |
8688 | ||
8689 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
8690 | { | |
8691 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8692 | struct net_device *dev = info->user_ptr[1]; | |
8693 | ||
8694 | return cfg80211_leave_mesh(rdev, dev); | |
8695 | } | |
8696 | ||
dfb89c56 | 8697 | #ifdef CONFIG_PM |
bb92d199 AK |
8698 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
8699 | struct cfg80211_registered_device *rdev) | |
8700 | { | |
6abb9cb9 | 8701 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
8702 | struct nlattr *nl_pats, *nl_pat; |
8703 | int i, pat_len; | |
8704 | ||
6abb9cb9 | 8705 | if (!wowlan->n_patterns) |
bb92d199 AK |
8706 | return 0; |
8707 | ||
8708 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
8709 | if (!nl_pats) | |
8710 | return -ENOBUFS; | |
8711 | ||
6abb9cb9 | 8712 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
8713 | nl_pat = nla_nest_start(msg, i + 1); |
8714 | if (!nl_pat) | |
8715 | return -ENOBUFS; | |
6abb9cb9 | 8716 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 8717 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 8718 | wowlan->patterns[i].mask) || |
50ac6607 AK |
8719 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
8720 | wowlan->patterns[i].pattern) || | |
8721 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 8722 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
8723 | return -ENOBUFS; |
8724 | nla_nest_end(msg, nl_pat); | |
8725 | } | |
8726 | nla_nest_end(msg, nl_pats); | |
8727 | ||
8728 | return 0; | |
8729 | } | |
8730 | ||
2a0e047e JB |
8731 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
8732 | struct cfg80211_wowlan_tcp *tcp) | |
8733 | { | |
8734 | struct nlattr *nl_tcp; | |
8735 | ||
8736 | if (!tcp) | |
8737 | return 0; | |
8738 | ||
8739 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
8740 | if (!nl_tcp) | |
8741 | return -ENOBUFS; | |
8742 | ||
8743 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
8744 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
8745 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
8746 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
8747 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
8748 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
8749 | tcp->payload_len, tcp->payload) || | |
8750 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
8751 | tcp->data_interval) || | |
8752 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
8753 | tcp->wake_len, tcp->wake_data) || | |
8754 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
8755 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
8756 | return -ENOBUFS; | |
8757 | ||
8758 | if (tcp->payload_seq.len && | |
8759 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
8760 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
8761 | return -ENOBUFS; | |
8762 | ||
8763 | if (tcp->payload_tok.len && | |
8764 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
8765 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
8766 | &tcp->payload_tok)) | |
8767 | return -ENOBUFS; | |
8768 | ||
e248ad30 JB |
8769 | nla_nest_end(msg, nl_tcp); |
8770 | ||
2a0e047e JB |
8771 | return 0; |
8772 | } | |
8773 | ||
75453ccb LC |
8774 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
8775 | struct cfg80211_sched_scan_request *req) | |
8776 | { | |
8777 | struct nlattr *nd, *freqs, *matches, *match; | |
8778 | int i; | |
8779 | ||
8780 | if (!req) | |
8781 | return 0; | |
8782 | ||
8783 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); | |
8784 | if (!nd) | |
8785 | return -ENOBUFS; | |
8786 | ||
8787 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, req->interval)) | |
8788 | return -ENOBUFS; | |
8789 | ||
8790 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
8791 | if (!freqs) | |
8792 | return -ENOBUFS; | |
8793 | ||
8794 | for (i = 0; i < req->n_channels; i++) | |
8795 | nla_put_u32(msg, i, req->channels[i]->center_freq); | |
8796 | ||
8797 | nla_nest_end(msg, freqs); | |
8798 | ||
8799 | if (req->n_match_sets) { | |
8800 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); | |
8801 | for (i = 0; i < req->n_match_sets; i++) { | |
8802 | match = nla_nest_start(msg, i); | |
8803 | nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, | |
8804 | req->match_sets[i].ssid.ssid_len, | |
8805 | req->match_sets[i].ssid.ssid); | |
8806 | nla_nest_end(msg, match); | |
8807 | } | |
8808 | nla_nest_end(msg, matches); | |
8809 | } | |
8810 | ||
8811 | nla_nest_end(msg, nd); | |
8812 | ||
8813 | return 0; | |
8814 | } | |
8815 | ||
ff1b6e69 JB |
8816 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
8817 | { | |
8818 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8819 | struct sk_buff *msg; | |
8820 | void *hdr; | |
2a0e047e | 8821 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 8822 | |
964dc9e2 | 8823 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
8824 | return -EOPNOTSUPP; |
8825 | ||
6abb9cb9 | 8826 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 8827 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
8828 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
8829 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
8830 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
8831 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
8832 | } |
8833 | ||
8834 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
8835 | if (!msg) |
8836 | return -ENOMEM; | |
8837 | ||
15e47304 | 8838 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
8839 | NL80211_CMD_GET_WOWLAN); |
8840 | if (!hdr) | |
8841 | goto nla_put_failure; | |
8842 | ||
6abb9cb9 | 8843 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
8844 | struct nlattr *nl_wowlan; |
8845 | ||
8846 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
8847 | if (!nl_wowlan) | |
8848 | goto nla_put_failure; | |
8849 | ||
6abb9cb9 | 8850 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 8851 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 8852 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 8853 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 8854 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 8855 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 8856 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 8857 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 8858 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 8859 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 8860 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 8861 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 8862 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
8863 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
8864 | goto nla_put_failure; | |
2a0e047e | 8865 | |
bb92d199 AK |
8866 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
8867 | goto nla_put_failure; | |
2a0e047e | 8868 | |
6abb9cb9 JB |
8869 | if (nl80211_send_wowlan_tcp(msg, |
8870 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e | 8871 | goto nla_put_failure; |
75453ccb LC |
8872 | |
8873 | if (nl80211_send_wowlan_nd( | |
8874 | msg, | |
8875 | rdev->wiphy.wowlan_config->nd_config)) | |
8876 | goto nla_put_failure; | |
2a0e047e | 8877 | |
ff1b6e69 JB |
8878 | nla_nest_end(msg, nl_wowlan); |
8879 | } | |
8880 | ||
8881 | genlmsg_end(msg, hdr); | |
8882 | return genlmsg_reply(msg, info); | |
8883 | ||
8884 | nla_put_failure: | |
8885 | nlmsg_free(msg); | |
8886 | return -ENOBUFS; | |
8887 | } | |
8888 | ||
2a0e047e JB |
8889 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
8890 | struct nlattr *attr, | |
8891 | struct cfg80211_wowlan *trig) | |
8892 | { | |
8893 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
8894 | struct cfg80211_wowlan_tcp *cfg; | |
8895 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
8896 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
8897 | u32 size; | |
8898 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
8899 | int err, port; | |
8900 | ||
964dc9e2 | 8901 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
8902 | return -EINVAL; |
8903 | ||
8904 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
8905 | nla_data(attr), nla_len(attr), | |
8906 | nl80211_wowlan_tcp_policy); | |
8907 | if (err) | |
8908 | return err; | |
8909 | ||
8910 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
8911 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
8912 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
8913 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
8914 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
8915 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
8916 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
8917 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
8918 | return -EINVAL; | |
8919 | ||
8920 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 8921 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
8922 | return -EINVAL; |
8923 | ||
8924 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 8925 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 8926 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
8927 | return -EINVAL; |
8928 | ||
8929 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 8930 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
8931 | return -EINVAL; |
8932 | ||
8933 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
8934 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
8935 | return -EINVAL; | |
8936 | ||
8937 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
8938 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8939 | ||
8940 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8941 | tokens_size = tokln - sizeof(*tok); | |
8942 | ||
8943 | if (!tok->len || tokens_size % tok->len) | |
8944 | return -EINVAL; | |
964dc9e2 | 8945 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 8946 | return -EINVAL; |
964dc9e2 | 8947 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 8948 | return -EINVAL; |
964dc9e2 | 8949 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 8950 | return -EINVAL; |
964dc9e2 | 8951 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
8952 | return -EINVAL; |
8953 | if (tok->offset + tok->len > data_size) | |
8954 | return -EINVAL; | |
8955 | } | |
8956 | ||
8957 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
8958 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 8959 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
8960 | return -EINVAL; |
8961 | if (seq->len == 0 || seq->len > 4) | |
8962 | return -EINVAL; | |
8963 | if (seq->len + seq->offset > data_size) | |
8964 | return -EINVAL; | |
8965 | } | |
8966 | ||
8967 | size = sizeof(*cfg); | |
8968 | size += data_size; | |
8969 | size += wake_size + wake_mask_size; | |
8970 | size += tokens_size; | |
8971 | ||
8972 | cfg = kzalloc(size, GFP_KERNEL); | |
8973 | if (!cfg) | |
8974 | return -ENOMEM; | |
8975 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
8976 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
8977 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
8978 | ETH_ALEN); | |
8979 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
8980 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
8981 | else | |
8982 | port = 0; | |
8983 | #ifdef CONFIG_INET | |
8984 | /* allocate a socket and port for it and use it */ | |
8985 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
8986 | IPPROTO_TCP, &cfg->sock, 1); | |
8987 | if (err) { | |
8988 | kfree(cfg); | |
8989 | return err; | |
8990 | } | |
8991 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
8992 | sock_release(cfg->sock); | |
8993 | kfree(cfg); | |
8994 | return -EADDRINUSE; | |
8995 | } | |
8996 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
8997 | #else | |
8998 | if (!port) { | |
8999 | kfree(cfg); | |
9000 | return -EINVAL; | |
9001 | } | |
9002 | cfg->src_port = port; | |
9003 | #endif | |
9004 | ||
9005 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
9006 | cfg->payload_len = data_size; | |
9007 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
9008 | memcpy((void *)cfg->payload, | |
9009 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
9010 | data_size); | |
9011 | if (seq) | |
9012 | cfg->payload_seq = *seq; | |
9013 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
9014 | cfg->wake_len = wake_size; | |
9015 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
9016 | memcpy((void *)cfg->wake_data, | |
9017 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
9018 | wake_size); | |
9019 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
9020 | data_size + wake_size; | |
9021 | memcpy((void *)cfg->wake_mask, | |
9022 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
9023 | wake_mask_size); | |
9024 | if (tok) { | |
9025 | cfg->tokens_size = tokens_size; | |
9026 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
9027 | } | |
9028 | ||
9029 | trig->tcp = cfg; | |
9030 | ||
9031 | return 0; | |
9032 | } | |
9033 | ||
8cd4d456 LC |
9034 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
9035 | const struct wiphy_wowlan_support *wowlan, | |
9036 | struct nlattr *attr, | |
9037 | struct cfg80211_wowlan *trig) | |
9038 | { | |
9039 | struct nlattr **tb; | |
9040 | int err; | |
9041 | ||
9042 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); | |
9043 | if (!tb) | |
9044 | return -ENOMEM; | |
9045 | ||
9046 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | |
9047 | err = -EOPNOTSUPP; | |
9048 | goto out; | |
9049 | } | |
9050 | ||
9051 | err = nla_parse(tb, NL80211_ATTR_MAX, | |
9052 | nla_data(attr), nla_len(attr), | |
9053 | nl80211_policy); | |
9054 | if (err) | |
9055 | goto out; | |
9056 | ||
ad2b26ab | 9057 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
8cd4d456 LC |
9058 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
9059 | if (err) | |
9060 | trig->nd_config = NULL; | |
9061 | ||
9062 | out: | |
9063 | kfree(tb); | |
9064 | return err; | |
9065 | } | |
9066 | ||
ff1b6e69 JB |
9067 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
9068 | { | |
9069 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9070 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 9071 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 9072 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 9073 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 9074 | int err, i; |
6abb9cb9 | 9075 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 9076 | |
964dc9e2 | 9077 | if (!wowlan) |
ff1b6e69 JB |
9078 | return -EOPNOTSUPP; |
9079 | ||
ae33bd81 JB |
9080 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
9081 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 9082 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
9083 | goto set_wakeup; |
9084 | } | |
ff1b6e69 JB |
9085 | |
9086 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
9087 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9088 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9089 | nl80211_wowlan_policy); | |
9090 | if (err) | |
9091 | return err; | |
9092 | ||
9093 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
9094 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
9095 | return -EINVAL; | |
9096 | new_triggers.any = true; | |
9097 | } | |
9098 | ||
9099 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
9100 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
9101 | return -EINVAL; | |
9102 | new_triggers.disconnect = true; | |
9103 | } | |
9104 | ||
9105 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
9106 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
9107 | return -EINVAL; | |
9108 | new_triggers.magic_pkt = true; | |
9109 | } | |
9110 | ||
77dbbb13 JB |
9111 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
9112 | return -EINVAL; | |
9113 | ||
9114 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
9115 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
9116 | return -EINVAL; | |
9117 | new_triggers.gtk_rekey_failure = true; | |
9118 | } | |
9119 | ||
9120 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
9121 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
9122 | return -EINVAL; | |
9123 | new_triggers.eap_identity_req = true; | |
9124 | } | |
9125 | ||
9126 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
9127 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
9128 | return -EINVAL; | |
9129 | new_triggers.four_way_handshake = true; | |
9130 | } | |
9131 | ||
9132 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
9133 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
9134 | return -EINVAL; | |
9135 | new_triggers.rfkill_release = true; | |
9136 | } | |
9137 | ||
ff1b6e69 JB |
9138 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
9139 | struct nlattr *pat; | |
9140 | int n_patterns = 0; | |
bb92d199 | 9141 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 9142 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 JB |
9143 | |
9144 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9145 | rem) | |
9146 | n_patterns++; | |
9147 | if (n_patterns > wowlan->n_patterns) | |
9148 | return -EINVAL; | |
9149 | ||
9150 | new_triggers.patterns = kcalloc(n_patterns, | |
9151 | sizeof(new_triggers.patterns[0]), | |
9152 | GFP_KERNEL); | |
9153 | if (!new_triggers.patterns) | |
9154 | return -ENOMEM; | |
9155 | ||
9156 | new_triggers.n_patterns = n_patterns; | |
9157 | i = 0; | |
9158 | ||
9159 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9160 | rem) { | |
922bd80f JB |
9161 | u8 *mask_pat; |
9162 | ||
50ac6607 AK |
9163 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9164 | nla_len(pat), NULL); | |
ff1b6e69 | 9165 | err = -EINVAL; |
50ac6607 AK |
9166 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
9167 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 9168 | goto error; |
50ac6607 | 9169 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 9170 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 9171 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
9172 | goto error; |
9173 | if (pat_len > wowlan->pattern_max_len || | |
9174 | pat_len < wowlan->pattern_min_len) | |
9175 | goto error; | |
9176 | ||
50ac6607 | 9177 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
9178 | pkt_offset = 0; |
9179 | else | |
9180 | pkt_offset = nla_get_u32( | |
50ac6607 | 9181 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
9182 | if (pkt_offset > wowlan->max_pkt_offset) |
9183 | goto error; | |
9184 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
9185 | ||
922bd80f JB |
9186 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9187 | if (!mask_pat) { | |
ff1b6e69 JB |
9188 | err = -ENOMEM; |
9189 | goto error; | |
9190 | } | |
922bd80f JB |
9191 | new_triggers.patterns[i].mask = mask_pat; |
9192 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 9193 | mask_len); |
922bd80f JB |
9194 | mask_pat += mask_len; |
9195 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 9196 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 9197 | memcpy(mask_pat, |
50ac6607 | 9198 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
9199 | pat_len); |
9200 | i++; | |
9201 | } | |
9202 | } | |
9203 | ||
2a0e047e JB |
9204 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
9205 | err = nl80211_parse_wowlan_tcp( | |
9206 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
9207 | &new_triggers); | |
9208 | if (err) | |
9209 | goto error; | |
9210 | } | |
9211 | ||
8cd4d456 LC |
9212 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
9213 | err = nl80211_parse_wowlan_nd( | |
9214 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | |
9215 | &new_triggers); | |
9216 | if (err) | |
9217 | goto error; | |
9218 | } | |
9219 | ||
ae33bd81 JB |
9220 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
9221 | if (!ntrig) { | |
9222 | err = -ENOMEM; | |
9223 | goto error; | |
ff1b6e69 | 9224 | } |
ae33bd81 | 9225 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 9226 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 9227 | |
ae33bd81 | 9228 | set_wakeup: |
6abb9cb9 JB |
9229 | if (rdev->ops->set_wakeup && |
9230 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
9231 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 9232 | |
ff1b6e69 JB |
9233 | return 0; |
9234 | error: | |
9235 | for (i = 0; i < new_triggers.n_patterns; i++) | |
9236 | kfree(new_triggers.patterns[i].mask); | |
9237 | kfree(new_triggers.patterns); | |
2a0e047e JB |
9238 | if (new_triggers.tcp && new_triggers.tcp->sock) |
9239 | sock_release(new_triggers.tcp->sock); | |
9240 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
9241 | return err; |
9242 | } | |
dfb89c56 | 9243 | #endif |
ff1b6e69 | 9244 | |
be29b99a AK |
9245 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
9246 | struct cfg80211_registered_device *rdev) | |
9247 | { | |
9248 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
9249 | int i, j, pat_len; | |
9250 | struct cfg80211_coalesce_rules *rule; | |
9251 | ||
9252 | if (!rdev->coalesce->n_rules) | |
9253 | return 0; | |
9254 | ||
9255 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
9256 | if (!nl_rules) | |
9257 | return -ENOBUFS; | |
9258 | ||
9259 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
9260 | nl_rule = nla_nest_start(msg, i + 1); | |
9261 | if (!nl_rule) | |
9262 | return -ENOBUFS; | |
9263 | ||
9264 | rule = &rdev->coalesce->rules[i]; | |
9265 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
9266 | rule->delay)) | |
9267 | return -ENOBUFS; | |
9268 | ||
9269 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
9270 | rule->condition)) | |
9271 | return -ENOBUFS; | |
9272 | ||
9273 | nl_pats = nla_nest_start(msg, | |
9274 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
9275 | if (!nl_pats) | |
9276 | return -ENOBUFS; | |
9277 | ||
9278 | for (j = 0; j < rule->n_patterns; j++) { | |
9279 | nl_pat = nla_nest_start(msg, j + 1); | |
9280 | if (!nl_pat) | |
9281 | return -ENOBUFS; | |
9282 | pat_len = rule->patterns[j].pattern_len; | |
9283 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
9284 | DIV_ROUND_UP(pat_len, 8), | |
9285 | rule->patterns[j].mask) || | |
9286 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
9287 | rule->patterns[j].pattern) || | |
9288 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
9289 | rule->patterns[j].pkt_offset)) | |
9290 | return -ENOBUFS; | |
9291 | nla_nest_end(msg, nl_pat); | |
9292 | } | |
9293 | nla_nest_end(msg, nl_pats); | |
9294 | nla_nest_end(msg, nl_rule); | |
9295 | } | |
9296 | nla_nest_end(msg, nl_rules); | |
9297 | ||
9298 | return 0; | |
9299 | } | |
9300 | ||
9301 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9302 | { | |
9303 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9304 | struct sk_buff *msg; | |
9305 | void *hdr; | |
9306 | ||
9307 | if (!rdev->wiphy.coalesce) | |
9308 | return -EOPNOTSUPP; | |
9309 | ||
9310 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9311 | if (!msg) | |
9312 | return -ENOMEM; | |
9313 | ||
9314 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9315 | NL80211_CMD_GET_COALESCE); | |
9316 | if (!hdr) | |
9317 | goto nla_put_failure; | |
9318 | ||
9319 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
9320 | goto nla_put_failure; | |
9321 | ||
9322 | genlmsg_end(msg, hdr); | |
9323 | return genlmsg_reply(msg, info); | |
9324 | ||
9325 | nla_put_failure: | |
9326 | nlmsg_free(msg); | |
9327 | return -ENOBUFS; | |
9328 | } | |
9329 | ||
9330 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
9331 | { | |
9332 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
9333 | int i, j; | |
9334 | struct cfg80211_coalesce_rules *rule; | |
9335 | ||
9336 | if (!coalesce) | |
9337 | return; | |
9338 | ||
9339 | for (i = 0; i < coalesce->n_rules; i++) { | |
9340 | rule = &coalesce->rules[i]; | |
9341 | for (j = 0; j < rule->n_patterns; j++) | |
9342 | kfree(rule->patterns[j].mask); | |
9343 | kfree(rule->patterns); | |
9344 | } | |
9345 | kfree(coalesce->rules); | |
9346 | kfree(coalesce); | |
9347 | rdev->coalesce = NULL; | |
9348 | } | |
9349 | ||
9350 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
9351 | struct nlattr *rule, | |
9352 | struct cfg80211_coalesce_rules *new_rule) | |
9353 | { | |
9354 | int err, i; | |
9355 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9356 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
9357 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
9358 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
9359 | ||
9360 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
9361 | nla_len(rule), nl80211_coalesce_policy); | |
9362 | if (err) | |
9363 | return err; | |
9364 | ||
9365 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
9366 | new_rule->delay = | |
9367 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
9368 | if (new_rule->delay > coalesce->max_delay) | |
9369 | return -EINVAL; | |
9370 | ||
9371 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
9372 | new_rule->condition = | |
9373 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
9374 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
9375 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
9376 | return -EINVAL; | |
9377 | ||
9378 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
9379 | return -EINVAL; | |
9380 | ||
9381 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9382 | rem) | |
9383 | n_patterns++; | |
9384 | if (n_patterns > coalesce->n_patterns) | |
9385 | return -EINVAL; | |
9386 | ||
9387 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
9388 | GFP_KERNEL); | |
9389 | if (!new_rule->patterns) | |
9390 | return -ENOMEM; | |
9391 | ||
9392 | new_rule->n_patterns = n_patterns; | |
9393 | i = 0; | |
9394 | ||
9395 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9396 | rem) { | |
922bd80f JB |
9397 | u8 *mask_pat; |
9398 | ||
be29b99a AK |
9399 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9400 | nla_len(pat), NULL); | |
9401 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
9402 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
9403 | return -EINVAL; | |
9404 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
9405 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
9406 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
9407 | return -EINVAL; | |
9408 | if (pat_len > coalesce->pattern_max_len || | |
9409 | pat_len < coalesce->pattern_min_len) | |
9410 | return -EINVAL; | |
9411 | ||
9412 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
9413 | pkt_offset = 0; | |
9414 | else | |
9415 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
9416 | if (pkt_offset > coalesce->max_pkt_offset) | |
9417 | return -EINVAL; | |
9418 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
9419 | ||
922bd80f JB |
9420 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9421 | if (!mask_pat) | |
be29b99a | 9422 | return -ENOMEM; |
922bd80f JB |
9423 | |
9424 | new_rule->patterns[i].mask = mask_pat; | |
9425 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
9426 | mask_len); | |
9427 | ||
9428 | mask_pat += mask_len; | |
9429 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 9430 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
9431 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
9432 | pat_len); | |
be29b99a AK |
9433 | i++; |
9434 | } | |
9435 | ||
9436 | return 0; | |
9437 | } | |
9438 | ||
9439 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9440 | { | |
9441 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9442 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9443 | struct cfg80211_coalesce new_coalesce = {}; | |
9444 | struct cfg80211_coalesce *n_coalesce; | |
9445 | int err, rem_rule, n_rules = 0, i, j; | |
9446 | struct nlattr *rule; | |
9447 | struct cfg80211_coalesce_rules *tmp_rule; | |
9448 | ||
9449 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
9450 | return -EOPNOTSUPP; | |
9451 | ||
9452 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
9453 | cfg80211_rdev_free_coalesce(rdev); | |
9454 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
9455 | return 0; | |
9456 | } | |
9457 | ||
9458 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9459 | rem_rule) | |
9460 | n_rules++; | |
9461 | if (n_rules > coalesce->n_rules) | |
9462 | return -EINVAL; | |
9463 | ||
9464 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
9465 | GFP_KERNEL); | |
9466 | if (!new_coalesce.rules) | |
9467 | return -ENOMEM; | |
9468 | ||
9469 | new_coalesce.n_rules = n_rules; | |
9470 | i = 0; | |
9471 | ||
9472 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9473 | rem_rule) { | |
9474 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
9475 | &new_coalesce.rules[i]); | |
9476 | if (err) | |
9477 | goto error; | |
9478 | ||
9479 | i++; | |
9480 | } | |
9481 | ||
9482 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
9483 | if (err) | |
9484 | goto error; | |
9485 | ||
9486 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
9487 | if (!n_coalesce) { | |
9488 | err = -ENOMEM; | |
9489 | goto error; | |
9490 | } | |
9491 | cfg80211_rdev_free_coalesce(rdev); | |
9492 | rdev->coalesce = n_coalesce; | |
9493 | ||
9494 | return 0; | |
9495 | error: | |
9496 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
9497 | tmp_rule = &new_coalesce.rules[i]; | |
9498 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
9499 | kfree(tmp_rule->patterns[j].mask); | |
9500 | kfree(tmp_rule->patterns); | |
9501 | } | |
9502 | kfree(new_coalesce.rules); | |
9503 | ||
9504 | return err; | |
9505 | } | |
9506 | ||
e5497d76 JB |
9507 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
9508 | { | |
9509 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9510 | struct net_device *dev = info->user_ptr[1]; | |
9511 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9512 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
9513 | struct cfg80211_gtk_rekey_data rekey_data; | |
9514 | int err; | |
9515 | ||
9516 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
9517 | return -EINVAL; | |
9518 | ||
9519 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
9520 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9521 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9522 | nl80211_rekey_policy); | |
9523 | if (err) | |
9524 | return err; | |
9525 | ||
9526 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
9527 | return -ERANGE; | |
9528 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
9529 | return -ERANGE; | |
9530 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
9531 | return -ERANGE; | |
9532 | ||
78f686ca JB |
9533 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
9534 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | |
9535 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | |
e5497d76 JB |
9536 | |
9537 | wdev_lock(wdev); | |
9538 | if (!wdev->current_bss) { | |
9539 | err = -ENOTCONN; | |
9540 | goto out; | |
9541 | } | |
9542 | ||
9543 | if (!rdev->ops->set_rekey_data) { | |
9544 | err = -EOPNOTSUPP; | |
9545 | goto out; | |
9546 | } | |
9547 | ||
e35e4d28 | 9548 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
9549 | out: |
9550 | wdev_unlock(wdev); | |
9551 | return err; | |
9552 | } | |
9553 | ||
28946da7 JB |
9554 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
9555 | struct genl_info *info) | |
9556 | { | |
9557 | struct net_device *dev = info->user_ptr[1]; | |
9558 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9559 | ||
9560 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9561 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9562 | return -EINVAL; | |
9563 | ||
15e47304 | 9564 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
9565 | return -EBUSY; |
9566 | ||
15e47304 | 9567 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
9568 | return 0; |
9569 | } | |
9570 | ||
7f6cf311 JB |
9571 | static int nl80211_probe_client(struct sk_buff *skb, |
9572 | struct genl_info *info) | |
9573 | { | |
9574 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9575 | struct net_device *dev = info->user_ptr[1]; | |
9576 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9577 | struct sk_buff *msg; | |
9578 | void *hdr; | |
9579 | const u8 *addr; | |
9580 | u64 cookie; | |
9581 | int err; | |
9582 | ||
9583 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9584 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9585 | return -EOPNOTSUPP; | |
9586 | ||
9587 | if (!info->attrs[NL80211_ATTR_MAC]) | |
9588 | return -EINVAL; | |
9589 | ||
9590 | if (!rdev->ops->probe_client) | |
9591 | return -EOPNOTSUPP; | |
9592 | ||
9593 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9594 | if (!msg) | |
9595 | return -ENOMEM; | |
9596 | ||
15e47304 | 9597 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 9598 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
9599 | if (!hdr) { |
9600 | err = -ENOBUFS; | |
7f6cf311 JB |
9601 | goto free_msg; |
9602 | } | |
9603 | ||
9604 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9605 | ||
e35e4d28 | 9606 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
9607 | if (err) |
9608 | goto free_msg; | |
9609 | ||
9360ffd1 DM |
9610 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9611 | goto nla_put_failure; | |
7f6cf311 JB |
9612 | |
9613 | genlmsg_end(msg, hdr); | |
9614 | ||
9615 | return genlmsg_reply(msg, info); | |
9616 | ||
9617 | nla_put_failure: | |
9618 | err = -ENOBUFS; | |
9619 | free_msg: | |
9620 | nlmsg_free(msg); | |
9621 | return err; | |
9622 | } | |
9623 | ||
5e760230 JB |
9624 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
9625 | { | |
9626 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
9627 | struct cfg80211_beacon_registration *reg, *nreg; |
9628 | int rv; | |
5e760230 JB |
9629 | |
9630 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
9631 | return -EOPNOTSUPP; | |
9632 | ||
37c73b5f BG |
9633 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
9634 | if (!nreg) | |
9635 | return -ENOMEM; | |
9636 | ||
9637 | /* First, check if already registered. */ | |
9638 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
9639 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
9640 | if (reg->nlportid == info->snd_portid) { | |
9641 | rv = -EALREADY; | |
9642 | goto out_err; | |
9643 | } | |
9644 | } | |
9645 | /* Add it to the list */ | |
9646 | nreg->nlportid = info->snd_portid; | |
9647 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 9648 | |
37c73b5f | 9649 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
9650 | |
9651 | return 0; | |
37c73b5f BG |
9652 | out_err: |
9653 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
9654 | kfree(nreg); | |
9655 | return rv; | |
5e760230 JB |
9656 | } |
9657 | ||
98104fde JB |
9658 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
9659 | { | |
9660 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9661 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9662 | int err; | |
9663 | ||
9664 | if (!rdev->ops->start_p2p_device) | |
9665 | return -EOPNOTSUPP; | |
9666 | ||
9667 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9668 | return -EOPNOTSUPP; | |
9669 | ||
9670 | if (wdev->p2p_started) | |
9671 | return 0; | |
9672 | ||
b6a55015 LC |
9673 | if (rfkill_blocked(rdev->rfkill)) |
9674 | return -ERFKILL; | |
98104fde | 9675 | |
eeb126e9 | 9676 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
9677 | if (err) |
9678 | return err; | |
9679 | ||
9680 | wdev->p2p_started = true; | |
98104fde | 9681 | rdev->opencount++; |
98104fde JB |
9682 | |
9683 | return 0; | |
9684 | } | |
9685 | ||
9686 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
9687 | { | |
9688 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9689 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9690 | ||
9691 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9692 | return -EOPNOTSUPP; | |
9693 | ||
9694 | if (!rdev->ops->stop_p2p_device) | |
9695 | return -EOPNOTSUPP; | |
9696 | ||
f9f47529 | 9697 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
9698 | |
9699 | return 0; | |
9700 | } | |
9701 | ||
3713b4e3 JB |
9702 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
9703 | struct genl_info *info) | |
9704 | { | |
9705 | void *hdr; | |
9706 | struct sk_buff *msg; | |
9707 | ||
9708 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9709 | if (!msg) | |
9710 | return -ENOMEM; | |
9711 | ||
9712 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9713 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
9714 | if (!hdr) | |
9715 | goto nla_put_failure; | |
9716 | ||
9717 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
9718 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
9719 | goto nla_put_failure; | |
9720 | ||
9721 | genlmsg_end(msg, hdr); | |
9722 | return genlmsg_reply(msg, info); | |
9723 | ||
9724 | nla_put_failure: | |
9725 | kfree_skb(msg); | |
9726 | return -ENOBUFS; | |
9727 | } | |
9728 | ||
355199e0 JM |
9729 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
9730 | { | |
9731 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9732 | struct cfg80211_update_ft_ies_params ft_params; | |
9733 | struct net_device *dev = info->user_ptr[1]; | |
9734 | ||
9735 | if (!rdev->ops->update_ft_ies) | |
9736 | return -EOPNOTSUPP; | |
9737 | ||
9738 | if (!info->attrs[NL80211_ATTR_MDID] || | |
9739 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
9740 | return -EINVAL; | |
9741 | ||
9742 | memset(&ft_params, 0, sizeof(ft_params)); | |
9743 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
9744 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
9745 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9746 | ||
9747 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
9748 | } | |
9749 | ||
5de17984 AS |
9750 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
9751 | struct genl_info *info) | |
9752 | { | |
9753 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9754 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9755 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
9756 | u16 duration; | |
9757 | int ret; | |
9758 | ||
9759 | if (!rdev->ops->crit_proto_start) | |
9760 | return -EOPNOTSUPP; | |
9761 | ||
9762 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
9763 | return -EINVAL; | |
9764 | ||
9765 | if (rdev->crit_proto_nlportid) | |
9766 | return -EBUSY; | |
9767 | ||
9768 | /* determine protocol if provided */ | |
9769 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
9770 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
9771 | ||
9772 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
9773 | return -EINVAL; | |
9774 | ||
9775 | /* timeout must be provided */ | |
9776 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
9777 | return -EINVAL; | |
9778 | ||
9779 | duration = | |
9780 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
9781 | ||
9782 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
9783 | return -ERANGE; | |
9784 | ||
9785 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
9786 | if (!ret) | |
9787 | rdev->crit_proto_nlportid = info->snd_portid; | |
9788 | ||
9789 | return ret; | |
9790 | } | |
9791 | ||
9792 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
9793 | struct genl_info *info) | |
9794 | { | |
9795 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9796 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9797 | ||
9798 | if (!rdev->ops->crit_proto_stop) | |
9799 | return -EOPNOTSUPP; | |
9800 | ||
9801 | if (rdev->crit_proto_nlportid) { | |
9802 | rdev->crit_proto_nlportid = 0; | |
9803 | rdev_crit_proto_stop(rdev, wdev); | |
9804 | } | |
9805 | return 0; | |
9806 | } | |
9807 | ||
ad7e718c JB |
9808 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
9809 | { | |
9810 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9811 | struct wireless_dev *wdev = | |
9812 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
9813 | int i, err; | |
9814 | u32 vid, subcmd; | |
9815 | ||
9816 | if (!rdev->wiphy.vendor_commands) | |
9817 | return -EOPNOTSUPP; | |
9818 | ||
9819 | if (IS_ERR(wdev)) { | |
9820 | err = PTR_ERR(wdev); | |
9821 | if (err != -EINVAL) | |
9822 | return err; | |
9823 | wdev = NULL; | |
9824 | } else if (wdev->wiphy != &rdev->wiphy) { | |
9825 | return -EINVAL; | |
9826 | } | |
9827 | ||
9828 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
9829 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
9830 | return -EINVAL; | |
9831 | ||
9832 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
9833 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
9834 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
9835 | const struct wiphy_vendor_command *vcmd; | |
9836 | void *data = NULL; | |
9837 | int len = 0; | |
9838 | ||
9839 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
9840 | ||
9841 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
9842 | continue; | |
9843 | ||
9844 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
9845 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
9846 | if (!wdev) | |
9847 | return -EINVAL; | |
9848 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
9849 | !wdev->netdev) | |
9850 | return -EINVAL; | |
9851 | ||
9852 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
9853 | if (wdev->netdev && | |
9854 | !netif_running(wdev->netdev)) | |
9855 | return -ENETDOWN; | |
9856 | if (!wdev->netdev && !wdev->p2p_started) | |
9857 | return -ENETDOWN; | |
9858 | } | |
9859 | } else { | |
9860 | wdev = NULL; | |
9861 | } | |
9862 | ||
9863 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
9864 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9865 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9866 | } | |
9867 | ||
9868 | rdev->cur_cmd_info = info; | |
9869 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
9870 | data, len); | |
9871 | rdev->cur_cmd_info = NULL; | |
9872 | return err; | |
9873 | } | |
9874 | ||
9875 | return -EOPNOTSUPP; | |
9876 | } | |
9877 | ||
9878 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | |
9879 | enum nl80211_commands cmd, | |
9880 | enum nl80211_attrs attr, | |
9881 | int approxlen) | |
9882 | { | |
f26cbf40 | 9883 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
9884 | |
9885 | if (WARN_ON(!rdev->cur_cmd_info)) | |
9886 | return NULL; | |
9887 | ||
9888 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, | |
9889 | rdev->cur_cmd_info->snd_portid, | |
9890 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 9891 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
9892 | } |
9893 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
9894 | ||
9895 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
9896 | { | |
9897 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
9898 | void *hdr = ((void **)skb->cb)[1]; | |
9899 | struct nlattr *data = ((void **)skb->cb)[2]; | |
9900 | ||
bd8c78e7 JB |
9901 | /* clear CB data for netlink core to own from now on */ |
9902 | memset(skb->cb, 0, sizeof(skb->cb)); | |
9903 | ||
ad7e718c JB |
9904 | if (WARN_ON(!rdev->cur_cmd_info)) { |
9905 | kfree_skb(skb); | |
9906 | return -EINVAL; | |
9907 | } | |
9908 | ||
9909 | nla_nest_end(skb, data); | |
9910 | genlmsg_end(skb, hdr); | |
9911 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
9912 | } | |
9913 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
9914 | ||
9915 | ||
fa9ffc74 KP |
9916 | static int nl80211_set_qos_map(struct sk_buff *skb, |
9917 | struct genl_info *info) | |
9918 | { | |
9919 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9920 | struct cfg80211_qos_map *qos_map = NULL; | |
9921 | struct net_device *dev = info->user_ptr[1]; | |
9922 | u8 *pos, len, num_des, des_len, des; | |
9923 | int ret; | |
9924 | ||
9925 | if (!rdev->ops->set_qos_map) | |
9926 | return -EOPNOTSUPP; | |
9927 | ||
9928 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
9929 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9930 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9931 | ||
9932 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
9933 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
9934 | return -EINVAL; | |
9935 | ||
9936 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
9937 | if (!qos_map) | |
9938 | return -ENOMEM; | |
9939 | ||
9940 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
9941 | if (num_des) { | |
9942 | des_len = num_des * | |
9943 | sizeof(struct cfg80211_dscp_exception); | |
9944 | memcpy(qos_map->dscp_exception, pos, des_len); | |
9945 | qos_map->num_des = num_des; | |
9946 | for (des = 0; des < num_des; des++) { | |
9947 | if (qos_map->dscp_exception[des].up > 7) { | |
9948 | kfree(qos_map); | |
9949 | return -EINVAL; | |
9950 | } | |
9951 | } | |
9952 | pos += des_len; | |
9953 | } | |
9954 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
9955 | } | |
9956 | ||
9957 | wdev_lock(dev->ieee80211_ptr); | |
9958 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
9959 | if (!ret) | |
9960 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
9961 | wdev_unlock(dev->ieee80211_ptr); | |
9962 | ||
9963 | kfree(qos_map); | |
9964 | return ret; | |
9965 | } | |
9966 | ||
960d01ac JB |
9967 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
9968 | { | |
9969 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9970 | struct net_device *dev = info->user_ptr[1]; | |
9971 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9972 | const u8 *peer; | |
9973 | u8 tsid, up; | |
9974 | u16 admitted_time = 0; | |
9975 | int err; | |
9976 | ||
723e73ac | 9977 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
960d01ac JB |
9978 | return -EOPNOTSUPP; |
9979 | ||
9980 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | |
9981 | !info->attrs[NL80211_ATTR_USER_PRIO]) | |
9982 | return -EINVAL; | |
9983 | ||
9984 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
9985 | if (tsid >= IEEE80211_NUM_TIDS) | |
9986 | return -EINVAL; | |
9987 | ||
9988 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); | |
9989 | if (up >= IEEE80211_NUM_UPS) | |
9990 | return -EINVAL; | |
9991 | ||
9992 | /* WMM uses TIDs 0-7 even for TSPEC */ | |
723e73ac | 9993 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
960d01ac | 9994 | /* TODO: handle 802.11 TSPEC/admission control |
723e73ac JB |
9995 | * need more attributes for that (e.g. BA session requirement); |
9996 | * change the WMM adminssion test above to allow both then | |
960d01ac JB |
9997 | */ |
9998 | return -EINVAL; | |
9999 | } | |
10000 | ||
10001 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10002 | ||
10003 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | |
10004 | admitted_time = | |
10005 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | |
10006 | if (!admitted_time) | |
10007 | return -EINVAL; | |
10008 | } | |
10009 | ||
10010 | wdev_lock(wdev); | |
10011 | switch (wdev->iftype) { | |
10012 | case NL80211_IFTYPE_STATION: | |
10013 | case NL80211_IFTYPE_P2P_CLIENT: | |
10014 | if (wdev->current_bss) | |
10015 | break; | |
10016 | err = -ENOTCONN; | |
10017 | goto out; | |
10018 | default: | |
10019 | err = -EOPNOTSUPP; | |
10020 | goto out; | |
10021 | } | |
10022 | ||
10023 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | |
10024 | ||
10025 | out: | |
10026 | wdev_unlock(wdev); | |
10027 | return err; | |
10028 | } | |
10029 | ||
10030 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | |
10031 | { | |
10032 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10033 | struct net_device *dev = info->user_ptr[1]; | |
10034 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10035 | const u8 *peer; | |
10036 | u8 tsid; | |
10037 | int err; | |
10038 | ||
10039 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | |
10040 | return -EINVAL; | |
10041 | ||
10042 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
10043 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10044 | ||
10045 | wdev_lock(wdev); | |
10046 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | |
10047 | wdev_unlock(wdev); | |
10048 | ||
10049 | return err; | |
10050 | } | |
10051 | ||
1057d35e AN |
10052 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
10053 | struct genl_info *info) | |
10054 | { | |
10055 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10056 | struct net_device *dev = info->user_ptr[1]; | |
10057 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10058 | struct cfg80211_chan_def chandef = {}; | |
10059 | const u8 *addr; | |
10060 | u8 oper_class; | |
10061 | int err; | |
10062 | ||
10063 | if (!rdev->ops->tdls_channel_switch || | |
10064 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
10065 | return -EOPNOTSUPP; | |
10066 | ||
10067 | switch (dev->ieee80211_ptr->iftype) { | |
10068 | case NL80211_IFTYPE_STATION: | |
10069 | case NL80211_IFTYPE_P2P_CLIENT: | |
10070 | break; | |
10071 | default: | |
10072 | return -EOPNOTSUPP; | |
10073 | } | |
10074 | ||
10075 | if (!info->attrs[NL80211_ATTR_MAC] || | |
10076 | !info->attrs[NL80211_ATTR_OPER_CLASS]) | |
10077 | return -EINVAL; | |
10078 | ||
10079 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
10080 | if (err) | |
10081 | return err; | |
10082 | ||
10083 | /* | |
10084 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | |
10085 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | |
10086 | * specification is not defined for them. | |
10087 | */ | |
10088 | if (chandef.chan->band == IEEE80211_BAND_2GHZ && | |
10089 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | |
10090 | chandef.width != NL80211_CHAN_WIDTH_20) | |
10091 | return -EINVAL; | |
10092 | ||
10093 | /* we will be active on the TDLS link */ | |
10094 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype)) | |
10095 | return -EINVAL; | |
10096 | ||
10097 | /* don't allow switching to DFS channels */ | |
10098 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | |
10099 | return -EINVAL; | |
10100 | ||
10101 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10102 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | |
10103 | ||
10104 | wdev_lock(wdev); | |
10105 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | |
10106 | wdev_unlock(wdev); | |
10107 | ||
10108 | return err; | |
10109 | } | |
10110 | ||
10111 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | |
10112 | struct genl_info *info) | |
10113 | { | |
10114 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10115 | struct net_device *dev = info->user_ptr[1]; | |
10116 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10117 | const u8 *addr; | |
10118 | ||
10119 | if (!rdev->ops->tdls_channel_switch || | |
10120 | !rdev->ops->tdls_cancel_channel_switch || | |
10121 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
10122 | return -EOPNOTSUPP; | |
10123 | ||
10124 | switch (dev->ieee80211_ptr->iftype) { | |
10125 | case NL80211_IFTYPE_STATION: | |
10126 | case NL80211_IFTYPE_P2P_CLIENT: | |
10127 | break; | |
10128 | default: | |
10129 | return -EOPNOTSUPP; | |
10130 | } | |
10131 | ||
10132 | if (!info->attrs[NL80211_ATTR_MAC]) | |
10133 | return -EINVAL; | |
10134 | ||
10135 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10136 | ||
10137 | wdev_lock(wdev); | |
10138 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); | |
10139 | wdev_unlock(wdev); | |
10140 | ||
10141 | return 0; | |
10142 | } | |
10143 | ||
4c476991 JB |
10144 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
10145 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
10146 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
10147 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
10148 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
10149 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 10150 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 10151 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
10152 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
10153 | NL80211_FLAG_CHECK_NETDEV_UP) | |
5393b917 | 10154 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
4c476991 | 10155 | |
f84f771d | 10156 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10157 | struct genl_info *info) |
10158 | { | |
10159 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 10160 | struct wireless_dev *wdev; |
4c476991 | 10161 | struct net_device *dev; |
4c476991 JB |
10162 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
10163 | ||
10164 | if (rtnl) | |
10165 | rtnl_lock(); | |
10166 | ||
10167 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 10168 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
10169 | if (IS_ERR(rdev)) { |
10170 | if (rtnl) | |
10171 | rtnl_unlock(); | |
10172 | return PTR_ERR(rdev); | |
10173 | } | |
10174 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
10175 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
10176 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
10177 | ASSERT_RTNL(); |
10178 | ||
89a54e48 JB |
10179 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
10180 | info->attrs); | |
10181 | if (IS_ERR(wdev)) { | |
4c476991 JB |
10182 | if (rtnl) |
10183 | rtnl_unlock(); | |
89a54e48 | 10184 | return PTR_ERR(wdev); |
4c476991 | 10185 | } |
89a54e48 | 10186 | |
89a54e48 | 10187 | dev = wdev->netdev; |
f26cbf40 | 10188 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 10189 | |
1bf614ef JB |
10190 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
10191 | if (!dev) { | |
1bf614ef JB |
10192 | if (rtnl) |
10193 | rtnl_unlock(); | |
10194 | return -EINVAL; | |
10195 | } | |
10196 | ||
10197 | info->user_ptr[1] = dev; | |
10198 | } else { | |
10199 | info->user_ptr[1] = wdev; | |
41265714 | 10200 | } |
1bf614ef JB |
10201 | |
10202 | if (dev) { | |
10203 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
10204 | !netif_running(dev)) { | |
1bf614ef JB |
10205 | if (rtnl) |
10206 | rtnl_unlock(); | |
10207 | return -ENETDOWN; | |
10208 | } | |
10209 | ||
10210 | dev_hold(dev); | |
98104fde JB |
10211 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
10212 | if (!wdev->p2p_started) { | |
98104fde JB |
10213 | if (rtnl) |
10214 | rtnl_unlock(); | |
10215 | return -ENETDOWN; | |
10216 | } | |
41265714 | 10217 | } |
89a54e48 | 10218 | |
4c476991 | 10219 | info->user_ptr[0] = rdev; |
4c476991 JB |
10220 | } |
10221 | ||
10222 | return 0; | |
10223 | } | |
10224 | ||
f84f771d | 10225 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10226 | struct genl_info *info) |
10227 | { | |
1bf614ef JB |
10228 | if (info->user_ptr[1]) { |
10229 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
10230 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10231 | ||
10232 | if (wdev->netdev) | |
10233 | dev_put(wdev->netdev); | |
10234 | } else { | |
10235 | dev_put(info->user_ptr[1]); | |
10236 | } | |
10237 | } | |
5393b917 | 10238 | |
4c476991 JB |
10239 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
10240 | rtnl_unlock(); | |
5393b917 JB |
10241 | |
10242 | /* If needed, clear the netlink message payload from the SKB | |
10243 | * as it might contain key data that shouldn't stick around on | |
10244 | * the heap after the SKB is freed. The netlink message header | |
10245 | * is still needed for further processing, so leave it intact. | |
10246 | */ | |
10247 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | |
10248 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | |
10249 | ||
10250 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | |
10251 | } | |
4c476991 JB |
10252 | } |
10253 | ||
4534de83 | 10254 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
10255 | { |
10256 | .cmd = NL80211_CMD_GET_WIPHY, | |
10257 | .doit = nl80211_get_wiphy, | |
10258 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 10259 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
10260 | .policy = nl80211_policy, |
10261 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10262 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10263 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10264 | }, |
10265 | { | |
10266 | .cmd = NL80211_CMD_SET_WIPHY, | |
10267 | .doit = nl80211_set_wiphy, | |
10268 | .policy = nl80211_policy, | |
10269 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 10270 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
10271 | }, |
10272 | { | |
10273 | .cmd = NL80211_CMD_GET_INTERFACE, | |
10274 | .doit = nl80211_get_interface, | |
10275 | .dumpit = nl80211_dump_interface, | |
10276 | .policy = nl80211_policy, | |
10277 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10278 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
10279 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10280 | }, |
10281 | { | |
10282 | .cmd = NL80211_CMD_SET_INTERFACE, | |
10283 | .doit = nl80211_set_interface, | |
10284 | .policy = nl80211_policy, | |
10285 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10286 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10287 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10288 | }, |
10289 | { | |
10290 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
10291 | .doit = nl80211_new_interface, | |
10292 | .policy = nl80211_policy, | |
10293 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10294 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10295 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10296 | }, |
10297 | { | |
10298 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
10299 | .doit = nl80211_del_interface, | |
10300 | .policy = nl80211_policy, | |
41ade00f | 10301 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 10302 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10303 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10304 | }, |
10305 | { | |
10306 | .cmd = NL80211_CMD_GET_KEY, | |
10307 | .doit = nl80211_get_key, | |
10308 | .policy = nl80211_policy, | |
10309 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10310 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10311 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10312 | }, |
10313 | { | |
10314 | .cmd = NL80211_CMD_SET_KEY, | |
10315 | .doit = nl80211_set_key, | |
10316 | .policy = nl80211_policy, | |
10317 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10318 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10319 | NL80211_FLAG_NEED_RTNL | |
10320 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10321 | }, |
10322 | { | |
10323 | .cmd = NL80211_CMD_NEW_KEY, | |
10324 | .doit = nl80211_new_key, | |
10325 | .policy = nl80211_policy, | |
10326 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10327 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10328 | NL80211_FLAG_NEED_RTNL | |
10329 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10330 | }, |
10331 | { | |
10332 | .cmd = NL80211_CMD_DEL_KEY, | |
10333 | .doit = nl80211_del_key, | |
10334 | .policy = nl80211_policy, | |
55682965 | 10335 | .flags = GENL_ADMIN_PERM, |
41265714 | 10336 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10337 | NL80211_FLAG_NEED_RTNL, |
55682965 | 10338 | }, |
ed1b6cc7 JB |
10339 | { |
10340 | .cmd = NL80211_CMD_SET_BEACON, | |
10341 | .policy = nl80211_policy, | |
10342 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10343 | .doit = nl80211_set_beacon, |
2b5f8b0b | 10344 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10345 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10346 | }, |
10347 | { | |
8860020e | 10348 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
10349 | .policy = nl80211_policy, |
10350 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10351 | .doit = nl80211_start_ap, |
2b5f8b0b | 10352 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10353 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10354 | }, |
10355 | { | |
8860020e | 10356 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
10357 | .policy = nl80211_policy, |
10358 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10359 | .doit = nl80211_stop_ap, |
2b5f8b0b | 10360 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10361 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 10362 | }, |
5727ef1b JB |
10363 | { |
10364 | .cmd = NL80211_CMD_GET_STATION, | |
10365 | .doit = nl80211_get_station, | |
2ec600d6 | 10366 | .dumpit = nl80211_dump_station, |
5727ef1b | 10367 | .policy = nl80211_policy, |
4c476991 JB |
10368 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10369 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
10370 | }, |
10371 | { | |
10372 | .cmd = NL80211_CMD_SET_STATION, | |
10373 | .doit = nl80211_set_station, | |
10374 | .policy = nl80211_policy, | |
10375 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10376 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10377 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10378 | }, |
10379 | { | |
10380 | .cmd = NL80211_CMD_NEW_STATION, | |
10381 | .doit = nl80211_new_station, | |
10382 | .policy = nl80211_policy, | |
10383 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10384 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10385 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10386 | }, |
10387 | { | |
10388 | .cmd = NL80211_CMD_DEL_STATION, | |
10389 | .doit = nl80211_del_station, | |
10390 | .policy = nl80211_policy, | |
2ec600d6 | 10391 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10392 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10393 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10394 | }, |
10395 | { | |
10396 | .cmd = NL80211_CMD_GET_MPATH, | |
10397 | .doit = nl80211_get_mpath, | |
10398 | .dumpit = nl80211_dump_mpath, | |
10399 | .policy = nl80211_policy, | |
10400 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10401 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10402 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 | 10403 | }, |
66be7d2b HR |
10404 | { |
10405 | .cmd = NL80211_CMD_GET_MPP, | |
10406 | .doit = nl80211_get_mpp, | |
10407 | .dumpit = nl80211_dump_mpp, | |
10408 | .policy = nl80211_policy, | |
10409 | .flags = GENL_ADMIN_PERM, | |
10410 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10411 | NL80211_FLAG_NEED_RTNL, | |
10412 | }, | |
2ec600d6 LCC |
10413 | { |
10414 | .cmd = NL80211_CMD_SET_MPATH, | |
10415 | .doit = nl80211_set_mpath, | |
10416 | .policy = nl80211_policy, | |
10417 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10418 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10419 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10420 | }, |
10421 | { | |
10422 | .cmd = NL80211_CMD_NEW_MPATH, | |
10423 | .doit = nl80211_new_mpath, | |
10424 | .policy = nl80211_policy, | |
10425 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10426 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10427 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10428 | }, |
10429 | { | |
10430 | .cmd = NL80211_CMD_DEL_MPATH, | |
10431 | .doit = nl80211_del_mpath, | |
10432 | .policy = nl80211_policy, | |
9f1ba906 | 10433 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10434 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10435 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
10436 | }, |
10437 | { | |
10438 | .cmd = NL80211_CMD_SET_BSS, | |
10439 | .doit = nl80211_set_bss, | |
10440 | .policy = nl80211_policy, | |
b2e1b302 | 10441 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10442 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10443 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 10444 | }, |
f130347c LR |
10445 | { |
10446 | .cmd = NL80211_CMD_GET_REG, | |
ad30ca2c AN |
10447 | .doit = nl80211_get_reg_do, |
10448 | .dumpit = nl80211_get_reg_dump, | |
f130347c | 10449 | .policy = nl80211_policy, |
5fe231e8 | 10450 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
10451 | /* can be retrieved by unprivileged users */ |
10452 | }, | |
b2e1b302 LR |
10453 | { |
10454 | .cmd = NL80211_CMD_SET_REG, | |
10455 | .doit = nl80211_set_reg, | |
10456 | .policy = nl80211_policy, | |
10457 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 10458 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
10459 | }, |
10460 | { | |
10461 | .cmd = NL80211_CMD_REQ_SET_REG, | |
10462 | .doit = nl80211_req_set_reg, | |
10463 | .policy = nl80211_policy, | |
93da9cc1 | 10464 | .flags = GENL_ADMIN_PERM, |
10465 | }, | |
10466 | { | |
24bdd9f4 JC |
10467 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
10468 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 10469 | .policy = nl80211_policy, |
10470 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 10471 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10472 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 10473 | }, |
10474 | { | |
24bdd9f4 JC |
10475 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
10476 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 10477 | .policy = nl80211_policy, |
9aed3cc1 | 10478 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 10479 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10480 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 10481 | }, |
2a519311 JB |
10482 | { |
10483 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
10484 | .doit = nl80211_trigger_scan, | |
10485 | .policy = nl80211_policy, | |
10486 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 10487 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10488 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
10489 | }, |
10490 | { | |
10491 | .cmd = NL80211_CMD_GET_SCAN, | |
10492 | .policy = nl80211_policy, | |
10493 | .dumpit = nl80211_dump_scan, | |
10494 | }, | |
807f8a8c LC |
10495 | { |
10496 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
10497 | .doit = nl80211_start_sched_scan, | |
10498 | .policy = nl80211_policy, | |
10499 | .flags = GENL_ADMIN_PERM, | |
10500 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10501 | NL80211_FLAG_NEED_RTNL, | |
10502 | }, | |
10503 | { | |
10504 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
10505 | .doit = nl80211_stop_sched_scan, | |
10506 | .policy = nl80211_policy, | |
10507 | .flags = GENL_ADMIN_PERM, | |
10508 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10509 | NL80211_FLAG_NEED_RTNL, | |
10510 | }, | |
636a5d36 JM |
10511 | { |
10512 | .cmd = NL80211_CMD_AUTHENTICATE, | |
10513 | .doit = nl80211_authenticate, | |
10514 | .policy = nl80211_policy, | |
10515 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10516 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10517 | NL80211_FLAG_NEED_RTNL | |
10518 | NL80211_FLAG_CLEAR_SKB, | |
636a5d36 JM |
10519 | }, |
10520 | { | |
10521 | .cmd = NL80211_CMD_ASSOCIATE, | |
10522 | .doit = nl80211_associate, | |
10523 | .policy = nl80211_policy, | |
10524 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10525 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10526 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10527 | }, |
10528 | { | |
10529 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
10530 | .doit = nl80211_deauthenticate, | |
10531 | .policy = nl80211_policy, | |
10532 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10533 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10534 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10535 | }, |
10536 | { | |
10537 | .cmd = NL80211_CMD_DISASSOCIATE, | |
10538 | .doit = nl80211_disassociate, | |
10539 | .policy = nl80211_policy, | |
10540 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10541 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10542 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 10543 | }, |
04a773ad JB |
10544 | { |
10545 | .cmd = NL80211_CMD_JOIN_IBSS, | |
10546 | .doit = nl80211_join_ibss, | |
10547 | .policy = nl80211_policy, | |
10548 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10549 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10550 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
10551 | }, |
10552 | { | |
10553 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
10554 | .doit = nl80211_leave_ibss, | |
10555 | .policy = nl80211_policy, | |
10556 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10557 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10558 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 10559 | }, |
aff89a9b JB |
10560 | #ifdef CONFIG_NL80211_TESTMODE |
10561 | { | |
10562 | .cmd = NL80211_CMD_TESTMODE, | |
10563 | .doit = nl80211_testmode_do, | |
71063f0e | 10564 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
10565 | .policy = nl80211_policy, |
10566 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10567 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10568 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
10569 | }, |
10570 | #endif | |
b23aa676 SO |
10571 | { |
10572 | .cmd = NL80211_CMD_CONNECT, | |
10573 | .doit = nl80211_connect, | |
10574 | .policy = nl80211_policy, | |
10575 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10576 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10577 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
10578 | }, |
10579 | { | |
10580 | .cmd = NL80211_CMD_DISCONNECT, | |
10581 | .doit = nl80211_disconnect, | |
10582 | .policy = nl80211_policy, | |
10583 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10584 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10585 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 10586 | }, |
463d0183 JB |
10587 | { |
10588 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
10589 | .doit = nl80211_wiphy_netns, | |
10590 | .policy = nl80211_policy, | |
10591 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10592 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10593 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 10594 | }, |
61fa713c HS |
10595 | { |
10596 | .cmd = NL80211_CMD_GET_SURVEY, | |
10597 | .policy = nl80211_policy, | |
10598 | .dumpit = nl80211_dump_survey, | |
10599 | }, | |
67fbb16b SO |
10600 | { |
10601 | .cmd = NL80211_CMD_SET_PMKSA, | |
10602 | .doit = nl80211_setdel_pmksa, | |
10603 | .policy = nl80211_policy, | |
10604 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10605 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10606 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10607 | }, |
10608 | { | |
10609 | .cmd = NL80211_CMD_DEL_PMKSA, | |
10610 | .doit = nl80211_setdel_pmksa, | |
10611 | .policy = nl80211_policy, | |
10612 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10613 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10614 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10615 | }, |
10616 | { | |
10617 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
10618 | .doit = nl80211_flush_pmksa, | |
10619 | .policy = nl80211_policy, | |
10620 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10621 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10622 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 10623 | }, |
9588bbd5 JM |
10624 | { |
10625 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
10626 | .doit = nl80211_remain_on_channel, | |
10627 | .policy = nl80211_policy, | |
10628 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10629 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10630 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
10631 | }, |
10632 | { | |
10633 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
10634 | .doit = nl80211_cancel_remain_on_channel, | |
10635 | .policy = nl80211_policy, | |
10636 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10637 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10638 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 10639 | }, |
13ae75b1 JM |
10640 | { |
10641 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
10642 | .doit = nl80211_set_tx_bitrate_mask, | |
10643 | .policy = nl80211_policy, | |
10644 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10645 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10646 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 10647 | }, |
026331c4 | 10648 | { |
2e161f78 JB |
10649 | .cmd = NL80211_CMD_REGISTER_FRAME, |
10650 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
10651 | .policy = nl80211_policy, |
10652 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10653 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10654 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
10655 | }, |
10656 | { | |
2e161f78 JB |
10657 | .cmd = NL80211_CMD_FRAME, |
10658 | .doit = nl80211_tx_mgmt, | |
026331c4 | 10659 | .policy = nl80211_policy, |
f7ca38df | 10660 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10661 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
10662 | NL80211_FLAG_NEED_RTNL, |
10663 | }, | |
10664 | { | |
10665 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
10666 | .doit = nl80211_tx_mgmt_cancel_wait, | |
10667 | .policy = nl80211_policy, | |
026331c4 | 10668 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10669 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10670 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 10671 | }, |
ffb9eb3d KV |
10672 | { |
10673 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
10674 | .doit = nl80211_set_power_save, | |
10675 | .policy = nl80211_policy, | |
10676 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10677 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10678 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
10679 | }, |
10680 | { | |
10681 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
10682 | .doit = nl80211_get_power_save, | |
10683 | .policy = nl80211_policy, | |
10684 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
10685 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10686 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 10687 | }, |
d6dc1a38 JO |
10688 | { |
10689 | .cmd = NL80211_CMD_SET_CQM, | |
10690 | .doit = nl80211_set_cqm, | |
10691 | .policy = nl80211_policy, | |
10692 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10693 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10694 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 10695 | }, |
f444de05 JB |
10696 | { |
10697 | .cmd = NL80211_CMD_SET_CHANNEL, | |
10698 | .doit = nl80211_set_channel, | |
10699 | .policy = nl80211_policy, | |
10700 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10701 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10702 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 10703 | }, |
e8347eba BJ |
10704 | { |
10705 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
10706 | .doit = nl80211_set_wds_peer, | |
10707 | .policy = nl80211_policy, | |
10708 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
10709 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10710 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 10711 | }, |
29cbe68c JB |
10712 | { |
10713 | .cmd = NL80211_CMD_JOIN_MESH, | |
10714 | .doit = nl80211_join_mesh, | |
10715 | .policy = nl80211_policy, | |
10716 | .flags = GENL_ADMIN_PERM, | |
10717 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10718 | NL80211_FLAG_NEED_RTNL, | |
10719 | }, | |
10720 | { | |
10721 | .cmd = NL80211_CMD_LEAVE_MESH, | |
10722 | .doit = nl80211_leave_mesh, | |
10723 | .policy = nl80211_policy, | |
10724 | .flags = GENL_ADMIN_PERM, | |
10725 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10726 | NL80211_FLAG_NEED_RTNL, | |
10727 | }, | |
6e0bd6c3 RL |
10728 | { |
10729 | .cmd = NL80211_CMD_JOIN_OCB, | |
10730 | .doit = nl80211_join_ocb, | |
10731 | .policy = nl80211_policy, | |
10732 | .flags = GENL_ADMIN_PERM, | |
10733 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10734 | NL80211_FLAG_NEED_RTNL, | |
10735 | }, | |
10736 | { | |
10737 | .cmd = NL80211_CMD_LEAVE_OCB, | |
10738 | .doit = nl80211_leave_ocb, | |
10739 | .policy = nl80211_policy, | |
10740 | .flags = GENL_ADMIN_PERM, | |
10741 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10742 | NL80211_FLAG_NEED_RTNL, | |
10743 | }, | |
dfb89c56 | 10744 | #ifdef CONFIG_PM |
ff1b6e69 JB |
10745 | { |
10746 | .cmd = NL80211_CMD_GET_WOWLAN, | |
10747 | .doit = nl80211_get_wowlan, | |
10748 | .policy = nl80211_policy, | |
10749 | /* can be retrieved by unprivileged users */ | |
10750 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10751 | NL80211_FLAG_NEED_RTNL, | |
10752 | }, | |
10753 | { | |
10754 | .cmd = NL80211_CMD_SET_WOWLAN, | |
10755 | .doit = nl80211_set_wowlan, | |
10756 | .policy = nl80211_policy, | |
10757 | .flags = GENL_ADMIN_PERM, | |
10758 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10759 | NL80211_FLAG_NEED_RTNL, | |
10760 | }, | |
dfb89c56 | 10761 | #endif |
e5497d76 JB |
10762 | { |
10763 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
10764 | .doit = nl80211_set_rekey_data, | |
10765 | .policy = nl80211_policy, | |
10766 | .flags = GENL_ADMIN_PERM, | |
10767 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
5393b917 JB |
10768 | NL80211_FLAG_NEED_RTNL | |
10769 | NL80211_FLAG_CLEAR_SKB, | |
e5497d76 | 10770 | }, |
109086ce AN |
10771 | { |
10772 | .cmd = NL80211_CMD_TDLS_MGMT, | |
10773 | .doit = nl80211_tdls_mgmt, | |
10774 | .policy = nl80211_policy, | |
10775 | .flags = GENL_ADMIN_PERM, | |
10776 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10777 | NL80211_FLAG_NEED_RTNL, | |
10778 | }, | |
10779 | { | |
10780 | .cmd = NL80211_CMD_TDLS_OPER, | |
10781 | .doit = nl80211_tdls_oper, | |
10782 | .policy = nl80211_policy, | |
10783 | .flags = GENL_ADMIN_PERM, | |
10784 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10785 | NL80211_FLAG_NEED_RTNL, | |
10786 | }, | |
28946da7 JB |
10787 | { |
10788 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
10789 | .doit = nl80211_register_unexpected_frame, | |
10790 | .policy = nl80211_policy, | |
10791 | .flags = GENL_ADMIN_PERM, | |
10792 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10793 | NL80211_FLAG_NEED_RTNL, | |
10794 | }, | |
7f6cf311 JB |
10795 | { |
10796 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
10797 | .doit = nl80211_probe_client, | |
10798 | .policy = nl80211_policy, | |
10799 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10800 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
10801 | NL80211_FLAG_NEED_RTNL, |
10802 | }, | |
5e760230 JB |
10803 | { |
10804 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
10805 | .doit = nl80211_register_beacons, | |
10806 | .policy = nl80211_policy, | |
10807 | .flags = GENL_ADMIN_PERM, | |
10808 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10809 | NL80211_FLAG_NEED_RTNL, | |
10810 | }, | |
1d9d9213 SW |
10811 | { |
10812 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
10813 | .doit = nl80211_set_noack_map, | |
10814 | .policy = nl80211_policy, | |
10815 | .flags = GENL_ADMIN_PERM, | |
10816 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10817 | NL80211_FLAG_NEED_RTNL, | |
10818 | }, | |
98104fde JB |
10819 | { |
10820 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
10821 | .doit = nl80211_start_p2p_device, | |
10822 | .policy = nl80211_policy, | |
10823 | .flags = GENL_ADMIN_PERM, | |
10824 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
10825 | NL80211_FLAG_NEED_RTNL, | |
10826 | }, | |
10827 | { | |
10828 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
10829 | .doit = nl80211_stop_p2p_device, | |
10830 | .policy = nl80211_policy, | |
10831 | .flags = GENL_ADMIN_PERM, | |
10832 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10833 | NL80211_FLAG_NEED_RTNL, | |
10834 | }, | |
f4e583c8 AQ |
10835 | { |
10836 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
10837 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
10838 | .policy = nl80211_policy, |
10839 | .flags = GENL_ADMIN_PERM, | |
10840 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10841 | NL80211_FLAG_NEED_RTNL, | |
10842 | }, | |
10843 | { | |
10844 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
10845 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
10846 | .policy = nl80211_policy, |
10847 | .flags = GENL_ADMIN_PERM, | |
10848 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10849 | NL80211_FLAG_NEED_RTNL, | |
10850 | }, | |
04f39047 SW |
10851 | { |
10852 | .cmd = NL80211_CMD_RADAR_DETECT, | |
10853 | .doit = nl80211_start_radar_detection, | |
10854 | .policy = nl80211_policy, | |
10855 | .flags = GENL_ADMIN_PERM, | |
10856 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10857 | NL80211_FLAG_NEED_RTNL, | |
10858 | }, | |
3713b4e3 JB |
10859 | { |
10860 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
10861 | .doit = nl80211_get_protocol_features, | |
10862 | .policy = nl80211_policy, | |
10863 | }, | |
355199e0 JM |
10864 | { |
10865 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
10866 | .doit = nl80211_update_ft_ies, | |
10867 | .policy = nl80211_policy, | |
10868 | .flags = GENL_ADMIN_PERM, | |
10869 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10870 | NL80211_FLAG_NEED_RTNL, | |
10871 | }, | |
5de17984 AS |
10872 | { |
10873 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
10874 | .doit = nl80211_crit_protocol_start, | |
10875 | .policy = nl80211_policy, | |
10876 | .flags = GENL_ADMIN_PERM, | |
10877 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10878 | NL80211_FLAG_NEED_RTNL, | |
10879 | }, | |
10880 | { | |
10881 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
10882 | .doit = nl80211_crit_protocol_stop, | |
10883 | .policy = nl80211_policy, | |
10884 | .flags = GENL_ADMIN_PERM, | |
10885 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10886 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
10887 | }, |
10888 | { | |
10889 | .cmd = NL80211_CMD_GET_COALESCE, | |
10890 | .doit = nl80211_get_coalesce, | |
10891 | .policy = nl80211_policy, | |
10892 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10893 | NL80211_FLAG_NEED_RTNL, | |
10894 | }, | |
10895 | { | |
10896 | .cmd = NL80211_CMD_SET_COALESCE, | |
10897 | .doit = nl80211_set_coalesce, | |
10898 | .policy = nl80211_policy, | |
10899 | .flags = GENL_ADMIN_PERM, | |
10900 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10901 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
10902 | }, |
10903 | { | |
10904 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
10905 | .doit = nl80211_channel_switch, | |
10906 | .policy = nl80211_policy, | |
10907 | .flags = GENL_ADMIN_PERM, | |
10908 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10909 | NL80211_FLAG_NEED_RTNL, | |
10910 | }, | |
ad7e718c JB |
10911 | { |
10912 | .cmd = NL80211_CMD_VENDOR, | |
10913 | .doit = nl80211_vendor_cmd, | |
10914 | .policy = nl80211_policy, | |
10915 | .flags = GENL_ADMIN_PERM, | |
10916 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10917 | NL80211_FLAG_NEED_RTNL, | |
10918 | }, | |
fa9ffc74 KP |
10919 | { |
10920 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
10921 | .doit = nl80211_set_qos_map, | |
10922 | .policy = nl80211_policy, | |
10923 | .flags = GENL_ADMIN_PERM, | |
10924 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10925 | NL80211_FLAG_NEED_RTNL, | |
10926 | }, | |
960d01ac JB |
10927 | { |
10928 | .cmd = NL80211_CMD_ADD_TX_TS, | |
10929 | .doit = nl80211_add_tx_ts, | |
10930 | .policy = nl80211_policy, | |
10931 | .flags = GENL_ADMIN_PERM, | |
10932 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10933 | NL80211_FLAG_NEED_RTNL, | |
10934 | }, | |
10935 | { | |
10936 | .cmd = NL80211_CMD_DEL_TX_TS, | |
10937 | .doit = nl80211_del_tx_ts, | |
10938 | .policy = nl80211_policy, | |
10939 | .flags = GENL_ADMIN_PERM, | |
10940 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10941 | NL80211_FLAG_NEED_RTNL, | |
10942 | }, | |
1057d35e AN |
10943 | { |
10944 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | |
10945 | .doit = nl80211_tdls_channel_switch, | |
10946 | .policy = nl80211_policy, | |
10947 | .flags = GENL_ADMIN_PERM, | |
10948 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10949 | NL80211_FLAG_NEED_RTNL, | |
10950 | }, | |
10951 | { | |
10952 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | |
10953 | .doit = nl80211_tdls_cancel_channel_switch, | |
10954 | .policy = nl80211_policy, | |
10955 | .flags = GENL_ADMIN_PERM, | |
10956 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10957 | NL80211_FLAG_NEED_RTNL, | |
10958 | }, | |
55682965 | 10959 | }; |
9588bbd5 | 10960 | |
55682965 JB |
10961 | /* notification functions */ |
10962 | ||
3bb20556 JB |
10963 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
10964 | enum nl80211_commands cmd) | |
55682965 JB |
10965 | { |
10966 | struct sk_buff *msg; | |
86e8cf98 | 10967 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 10968 | |
3bb20556 JB |
10969 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
10970 | cmd != NL80211_CMD_DEL_WIPHY); | |
10971 | ||
fd2120ca | 10972 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
10973 | if (!msg) |
10974 | return; | |
10975 | ||
3bb20556 | 10976 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
10977 | nlmsg_free(msg); |
10978 | return; | |
10979 | } | |
10980 | ||
68eb5503 | 10981 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10982 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
10983 | } |
10984 | ||
362a415d JB |
10985 | static int nl80211_add_scan_req(struct sk_buff *msg, |
10986 | struct cfg80211_registered_device *rdev) | |
10987 | { | |
10988 | struct cfg80211_scan_request *req = rdev->scan_req; | |
10989 | struct nlattr *nest; | |
10990 | int i; | |
10991 | ||
10992 | if (WARN_ON(!req)) | |
10993 | return 0; | |
10994 | ||
10995 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
10996 | if (!nest) | |
10997 | goto nla_put_failure; | |
9360ffd1 DM |
10998 | for (i = 0; i < req->n_ssids; i++) { |
10999 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
11000 | goto nla_put_failure; | |
11001 | } | |
362a415d JB |
11002 | nla_nest_end(msg, nest); |
11003 | ||
11004 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
11005 | if (!nest) | |
11006 | goto nla_put_failure; | |
9360ffd1 DM |
11007 | for (i = 0; i < req->n_channels; i++) { |
11008 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
11009 | goto nla_put_failure; | |
11010 | } | |
362a415d JB |
11011 | nla_nest_end(msg, nest); |
11012 | ||
9360ffd1 DM |
11013 | if (req->ie && |
11014 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
11015 | goto nla_put_failure; | |
362a415d | 11016 | |
ae917c9f JB |
11017 | if (req->flags && |
11018 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
11019 | goto nla_put_failure; | |
ed473771 | 11020 | |
362a415d JB |
11021 | return 0; |
11022 | nla_put_failure: | |
11023 | return -ENOBUFS; | |
11024 | } | |
11025 | ||
a538e2d5 JB |
11026 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
11027 | struct cfg80211_registered_device *rdev, | |
fd014284 | 11028 | struct wireless_dev *wdev, |
15e47304 | 11029 | u32 portid, u32 seq, int flags, |
a538e2d5 | 11030 | u32 cmd) |
2a519311 JB |
11031 | { |
11032 | void *hdr; | |
11033 | ||
15e47304 | 11034 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
11035 | if (!hdr) |
11036 | return -1; | |
11037 | ||
9360ffd1 | 11038 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
11039 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11040 | wdev->netdev->ifindex)) || | |
11041 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 11042 | goto nla_put_failure; |
2a519311 | 11043 | |
362a415d JB |
11044 | /* ignore errors and send incomplete event anyway */ |
11045 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
11046 | |
11047 | return genlmsg_end(msg, hdr); | |
11048 | ||
11049 | nla_put_failure: | |
11050 | genlmsg_cancel(msg, hdr); | |
11051 | return -EMSGSIZE; | |
11052 | } | |
11053 | ||
807f8a8c LC |
11054 | static int |
11055 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
11056 | struct cfg80211_registered_device *rdev, | |
11057 | struct net_device *netdev, | |
15e47304 | 11058 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
11059 | { |
11060 | void *hdr; | |
11061 | ||
15e47304 | 11062 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
11063 | if (!hdr) |
11064 | return -1; | |
11065 | ||
9360ffd1 DM |
11066 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11067 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
11068 | goto nla_put_failure; | |
807f8a8c LC |
11069 | |
11070 | return genlmsg_end(msg, hdr); | |
11071 | ||
11072 | nla_put_failure: | |
11073 | genlmsg_cancel(msg, hdr); | |
11074 | return -EMSGSIZE; | |
11075 | } | |
11076 | ||
a538e2d5 | 11077 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 11078 | struct wireless_dev *wdev) |
a538e2d5 JB |
11079 | { |
11080 | struct sk_buff *msg; | |
11081 | ||
58050fce | 11082 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
11083 | if (!msg) |
11084 | return; | |
11085 | ||
fd014284 | 11086 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
11087 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
11088 | nlmsg_free(msg); | |
11089 | return; | |
11090 | } | |
11091 | ||
68eb5503 | 11092 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11093 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
11094 | } |
11095 | ||
f9d15d16 JB |
11096 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
11097 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
11098 | { |
11099 | struct sk_buff *msg; | |
11100 | ||
fd2120ca | 11101 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 11102 | if (!msg) |
f9d15d16 | 11103 | return NULL; |
2a519311 | 11104 | |
fd014284 | 11105 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
11106 | aborted ? NL80211_CMD_SCAN_ABORTED : |
11107 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 11108 | nlmsg_free(msg); |
f9d15d16 | 11109 | return NULL; |
2a519311 JB |
11110 | } |
11111 | ||
f9d15d16 | 11112 | return msg; |
2a519311 JB |
11113 | } |
11114 | ||
f9d15d16 JB |
11115 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
11116 | struct sk_buff *msg) | |
2a519311 | 11117 | { |
2a519311 JB |
11118 | if (!msg) |
11119 | return; | |
11120 | ||
68eb5503 | 11121 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11122 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
11123 | } |
11124 | ||
807f8a8c LC |
11125 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
11126 | struct net_device *netdev) | |
11127 | { | |
11128 | struct sk_buff *msg; | |
11129 | ||
11130 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11131 | if (!msg) | |
11132 | return; | |
11133 | ||
11134 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
11135 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
11136 | nlmsg_free(msg); | |
11137 | return; | |
11138 | } | |
11139 | ||
68eb5503 | 11140 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11141 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11142 | } |
11143 | ||
11144 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
11145 | struct net_device *netdev, u32 cmd) | |
11146 | { | |
11147 | struct sk_buff *msg; | |
11148 | ||
58050fce | 11149 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
11150 | if (!msg) |
11151 | return; | |
11152 | ||
11153 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
11154 | nlmsg_free(msg); | |
11155 | return; | |
11156 | } | |
11157 | ||
68eb5503 | 11158 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11159 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11160 | } |
11161 | ||
b0d7aa59 JD |
11162 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
11163 | struct regulatory_request *request) | |
73d54c9e | 11164 | { |
73d54c9e | 11165 | /* Userspace can always count this one always being set */ |
9360ffd1 DM |
11166 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
11167 | goto nla_put_failure; | |
11168 | ||
11169 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
11170 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11171 | NL80211_REGDOM_TYPE_WORLD)) | |
11172 | goto nla_put_failure; | |
11173 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
11174 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11175 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
11176 | goto nla_put_failure; | |
11177 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
11178 | request->intersect) { | |
11179 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11180 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
11181 | goto nla_put_failure; | |
11182 | } else { | |
11183 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11184 | NL80211_REGDOM_TYPE_COUNTRY) || | |
11185 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
11186 | request->alpha2)) | |
11187 | goto nla_put_failure; | |
11188 | } | |
11189 | ||
ad30ca2c AN |
11190 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
11191 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); | |
11192 | ||
11193 | if (wiphy && | |
11194 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | |
11195 | goto nla_put_failure; | |
1bdd716c AN |
11196 | |
11197 | if (wiphy && | |
11198 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | |
11199 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
11200 | goto nla_put_failure; | |
ad30ca2c | 11201 | } |
73d54c9e | 11202 | |
b0d7aa59 JD |
11203 | return true; |
11204 | ||
11205 | nla_put_failure: | |
11206 | return false; | |
11207 | } | |
11208 | ||
11209 | /* | |
11210 | * This can happen on global regulatory changes or device specific settings | |
11211 | * based on custom regulatory domains. | |
11212 | */ | |
11213 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, | |
11214 | struct regulatory_request *request) | |
11215 | { | |
11216 | struct sk_buff *msg; | |
11217 | void *hdr; | |
11218 | ||
11219 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11220 | if (!msg) | |
11221 | return; | |
11222 | ||
11223 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); | |
11224 | if (!hdr) { | |
11225 | nlmsg_free(msg); | |
11226 | return; | |
11227 | } | |
11228 | ||
11229 | if (nl80211_reg_change_event_fill(msg, request) == false) | |
11230 | goto nla_put_failure; | |
11231 | ||
3b7b72ee | 11232 | genlmsg_end(msg, hdr); |
73d54c9e | 11233 | |
bc43b28c | 11234 | rcu_read_lock(); |
68eb5503 | 11235 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11236 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 11237 | rcu_read_unlock(); |
73d54c9e LR |
11238 | |
11239 | return; | |
11240 | ||
11241 | nla_put_failure: | |
11242 | genlmsg_cancel(msg, hdr); | |
11243 | nlmsg_free(msg); | |
11244 | } | |
11245 | ||
6039f6d2 JM |
11246 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
11247 | struct net_device *netdev, | |
11248 | const u8 *buf, size_t len, | |
b0b6aa2c EP |
11249 | enum nl80211_commands cmd, gfp_t gfp, |
11250 | int uapsd_queues) | |
6039f6d2 JM |
11251 | { |
11252 | struct sk_buff *msg; | |
11253 | void *hdr; | |
11254 | ||
e6d6e342 | 11255 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
11256 | if (!msg) |
11257 | return; | |
11258 | ||
11259 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11260 | if (!hdr) { | |
11261 | nlmsg_free(msg); | |
11262 | return; | |
11263 | } | |
11264 | ||
9360ffd1 DM |
11265 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11266 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11267 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
11268 | goto nla_put_failure; | |
6039f6d2 | 11269 | |
b0b6aa2c EP |
11270 | if (uapsd_queues >= 0) { |
11271 | struct nlattr *nla_wmm = | |
11272 | nla_nest_start(msg, NL80211_ATTR_STA_WME); | |
11273 | if (!nla_wmm) | |
11274 | goto nla_put_failure; | |
11275 | ||
11276 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
11277 | uapsd_queues)) | |
11278 | goto nla_put_failure; | |
11279 | ||
11280 | nla_nest_end(msg, nla_wmm); | |
11281 | } | |
11282 | ||
3b7b72ee | 11283 | genlmsg_end(msg, hdr); |
6039f6d2 | 11284 | |
68eb5503 | 11285 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11286 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
11287 | return; |
11288 | ||
11289 | nla_put_failure: | |
11290 | genlmsg_cancel(msg, hdr); | |
11291 | nlmsg_free(msg); | |
11292 | } | |
11293 | ||
11294 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11295 | struct net_device *netdev, const u8 *buf, |
11296 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11297 | { |
11298 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11299 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11300 | } |
11301 | ||
11302 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
11303 | struct net_device *netdev, const u8 *buf, | |
b0b6aa2c | 11304 | size_t len, gfp_t gfp, int uapsd_queues) |
6039f6d2 | 11305 | { |
e6d6e342 | 11306 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
b0b6aa2c | 11307 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
6039f6d2 JM |
11308 | } |
11309 | ||
53b46b84 | 11310 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
11311 | struct net_device *netdev, const u8 *buf, |
11312 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11313 | { |
11314 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11315 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11316 | } |
11317 | ||
53b46b84 JM |
11318 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
11319 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 11320 | size_t len, gfp_t gfp) |
6039f6d2 JM |
11321 | { |
11322 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11323 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
6039f6d2 JM |
11324 | } |
11325 | ||
6ff57cf8 JB |
11326 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
11327 | size_t len) | |
cf4e594e | 11328 | { |
947add36 JB |
11329 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11330 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11331 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
11332 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
11333 | u32 cmd; | |
947add36 | 11334 | |
6ff57cf8 JB |
11335 | if (WARN_ON(len < 2)) |
11336 | return; | |
cf4e594e | 11337 | |
6ff57cf8 JB |
11338 | if (ieee80211_is_deauth(mgmt->frame_control)) |
11339 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
11340 | else | |
11341 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 11342 | |
6ff57cf8 | 11343 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
b0b6aa2c | 11344 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
cf4e594e | 11345 | } |
6ff57cf8 | 11346 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 11347 | |
1b06bb40 LR |
11348 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
11349 | struct net_device *netdev, int cmd, | |
e6d6e342 | 11350 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
11351 | { |
11352 | struct sk_buff *msg; | |
11353 | void *hdr; | |
11354 | ||
e6d6e342 | 11355 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
11356 | if (!msg) |
11357 | return; | |
11358 | ||
11359 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11360 | if (!hdr) { | |
11361 | nlmsg_free(msg); | |
11362 | return; | |
11363 | } | |
11364 | ||
9360ffd1 DM |
11365 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11366 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11367 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
11368 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11369 | goto nla_put_failure; | |
1965c853 | 11370 | |
3b7b72ee | 11371 | genlmsg_end(msg, hdr); |
1965c853 | 11372 | |
68eb5503 | 11373 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11374 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
11375 | return; |
11376 | ||
11377 | nla_put_failure: | |
11378 | genlmsg_cancel(msg, hdr); | |
11379 | nlmsg_free(msg); | |
11380 | } | |
11381 | ||
11382 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11383 | struct net_device *netdev, const u8 *addr, |
11384 | gfp_t gfp) | |
1965c853 JM |
11385 | { |
11386 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 11387 | addr, gfp); |
1965c853 JM |
11388 | } |
11389 | ||
11390 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11391 | struct net_device *netdev, const u8 *addr, |
11392 | gfp_t gfp) | |
1965c853 | 11393 | { |
e6d6e342 JB |
11394 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
11395 | addr, gfp); | |
1965c853 JM |
11396 | } |
11397 | ||
b23aa676 SO |
11398 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
11399 | struct net_device *netdev, const u8 *bssid, | |
11400 | const u8 *req_ie, size_t req_ie_len, | |
11401 | const u8 *resp_ie, size_t resp_ie_len, | |
11402 | u16 status, gfp_t gfp) | |
11403 | { | |
11404 | struct sk_buff *msg; | |
11405 | void *hdr; | |
11406 | ||
58050fce | 11407 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
11408 | if (!msg) |
11409 | return; | |
11410 | ||
11411 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
11412 | if (!hdr) { | |
11413 | nlmsg_free(msg); | |
11414 | return; | |
11415 | } | |
11416 | ||
9360ffd1 DM |
11417 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11418 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11419 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
11420 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
11421 | (req_ie && | |
11422 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11423 | (resp_ie && | |
11424 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11425 | goto nla_put_failure; | |
b23aa676 | 11426 | |
3b7b72ee | 11427 | genlmsg_end(msg, hdr); |
b23aa676 | 11428 | |
68eb5503 | 11429 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11430 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11431 | return; |
11432 | ||
11433 | nla_put_failure: | |
11434 | genlmsg_cancel(msg, hdr); | |
11435 | nlmsg_free(msg); | |
11436 | ||
11437 | } | |
11438 | ||
11439 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
11440 | struct net_device *netdev, const u8 *bssid, | |
11441 | const u8 *req_ie, size_t req_ie_len, | |
11442 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
11443 | { | |
11444 | struct sk_buff *msg; | |
11445 | void *hdr; | |
11446 | ||
58050fce | 11447 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
11448 | if (!msg) |
11449 | return; | |
11450 | ||
11451 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
11452 | if (!hdr) { | |
11453 | nlmsg_free(msg); | |
11454 | return; | |
11455 | } | |
11456 | ||
9360ffd1 DM |
11457 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11458 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11459 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
11460 | (req_ie && | |
11461 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11462 | (resp_ie && | |
11463 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11464 | goto nla_put_failure; | |
b23aa676 | 11465 | |
3b7b72ee | 11466 | genlmsg_end(msg, hdr); |
b23aa676 | 11467 | |
68eb5503 | 11468 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11469 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11470 | return; |
11471 | ||
11472 | nla_put_failure: | |
11473 | genlmsg_cancel(msg, hdr); | |
11474 | nlmsg_free(msg); | |
11475 | ||
11476 | } | |
11477 | ||
11478 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
11479 | struct net_device *netdev, u16 reason, | |
667503dd | 11480 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
11481 | { |
11482 | struct sk_buff *msg; | |
11483 | void *hdr; | |
11484 | ||
58050fce | 11485 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
11486 | if (!msg) |
11487 | return; | |
11488 | ||
11489 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
11490 | if (!hdr) { | |
11491 | nlmsg_free(msg); | |
11492 | return; | |
11493 | } | |
11494 | ||
9360ffd1 DM |
11495 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11496 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11497 | (from_ap && reason && | |
11498 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
11499 | (from_ap && | |
11500 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
11501 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
11502 | goto nla_put_failure; | |
b23aa676 | 11503 | |
3b7b72ee | 11504 | genlmsg_end(msg, hdr); |
b23aa676 | 11505 | |
68eb5503 | 11506 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11507 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
11508 | return; |
11509 | ||
11510 | nla_put_failure: | |
11511 | genlmsg_cancel(msg, hdr); | |
11512 | nlmsg_free(msg); | |
11513 | ||
11514 | } | |
11515 | ||
04a773ad JB |
11516 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
11517 | struct net_device *netdev, const u8 *bssid, | |
11518 | gfp_t gfp) | |
11519 | { | |
11520 | struct sk_buff *msg; | |
11521 | void *hdr; | |
11522 | ||
fd2120ca | 11523 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
11524 | if (!msg) |
11525 | return; | |
11526 | ||
11527 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
11528 | if (!hdr) { | |
11529 | nlmsg_free(msg); | |
11530 | return; | |
11531 | } | |
11532 | ||
9360ffd1 DM |
11533 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11534 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11535 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
11536 | goto nla_put_failure; | |
04a773ad | 11537 | |
3b7b72ee | 11538 | genlmsg_end(msg, hdr); |
04a773ad | 11539 | |
68eb5503 | 11540 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11541 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
11542 | return; |
11543 | ||
11544 | nla_put_failure: | |
11545 | genlmsg_cancel(msg, hdr); | |
11546 | nlmsg_free(msg); | |
11547 | } | |
11548 | ||
947add36 JB |
11549 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
11550 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 11551 | { |
947add36 | 11552 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 11553 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
11554 | struct sk_buff *msg; |
11555 | void *hdr; | |
11556 | ||
947add36 JB |
11557 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
11558 | return; | |
11559 | ||
11560 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
11561 | ||
c93b5e71 JC |
11562 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11563 | if (!msg) | |
11564 | return; | |
11565 | ||
11566 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
11567 | if (!hdr) { | |
11568 | nlmsg_free(msg); | |
11569 | return; | |
11570 | } | |
11571 | ||
9360ffd1 | 11572 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
11573 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
11574 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
11575 | (ie_len && ie && |
11576 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
11577 | goto nla_put_failure; | |
c93b5e71 | 11578 | |
3b7b72ee | 11579 | genlmsg_end(msg, hdr); |
c93b5e71 | 11580 | |
68eb5503 | 11581 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11582 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
11583 | return; |
11584 | ||
11585 | nla_put_failure: | |
11586 | genlmsg_cancel(msg, hdr); | |
11587 | nlmsg_free(msg); | |
11588 | } | |
947add36 | 11589 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 11590 | |
a3b8b056 JM |
11591 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
11592 | struct net_device *netdev, const u8 *addr, | |
11593 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 11594 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
11595 | { |
11596 | struct sk_buff *msg; | |
11597 | void *hdr; | |
11598 | ||
e6d6e342 | 11599 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
11600 | if (!msg) |
11601 | return; | |
11602 | ||
11603 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
11604 | if (!hdr) { | |
11605 | nlmsg_free(msg); | |
11606 | return; | |
11607 | } | |
11608 | ||
9360ffd1 DM |
11609 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11610 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11611 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
11612 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
11613 | (key_id != -1 && | |
11614 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
11615 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
11616 | goto nla_put_failure; | |
a3b8b056 | 11617 | |
3b7b72ee | 11618 | genlmsg_end(msg, hdr); |
a3b8b056 | 11619 | |
68eb5503 | 11620 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11621 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
11622 | return; |
11623 | ||
11624 | nla_put_failure: | |
11625 | genlmsg_cancel(msg, hdr); | |
11626 | nlmsg_free(msg); | |
11627 | } | |
11628 | ||
6bad8766 LR |
11629 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
11630 | struct ieee80211_channel *channel_before, | |
11631 | struct ieee80211_channel *channel_after) | |
11632 | { | |
11633 | struct sk_buff *msg; | |
11634 | void *hdr; | |
11635 | struct nlattr *nl_freq; | |
11636 | ||
fd2120ca | 11637 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
11638 | if (!msg) |
11639 | return; | |
11640 | ||
11641 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
11642 | if (!hdr) { | |
11643 | nlmsg_free(msg); | |
11644 | return; | |
11645 | } | |
11646 | ||
11647 | /* | |
11648 | * Since we are applying the beacon hint to a wiphy we know its | |
11649 | * wiphy_idx is valid | |
11650 | */ | |
9360ffd1 DM |
11651 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
11652 | goto nla_put_failure; | |
6bad8766 LR |
11653 | |
11654 | /* Before */ | |
11655 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
11656 | if (!nl_freq) | |
11657 | goto nla_put_failure; | |
cdc89b97 | 11658 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
11659 | goto nla_put_failure; |
11660 | nla_nest_end(msg, nl_freq); | |
11661 | ||
11662 | /* After */ | |
11663 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
11664 | if (!nl_freq) | |
11665 | goto nla_put_failure; | |
cdc89b97 | 11666 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
11667 | goto nla_put_failure; |
11668 | nla_nest_end(msg, nl_freq); | |
11669 | ||
3b7b72ee | 11670 | genlmsg_end(msg, hdr); |
6bad8766 | 11671 | |
463d0183 | 11672 | rcu_read_lock(); |
68eb5503 | 11673 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11674 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 11675 | rcu_read_unlock(); |
6bad8766 LR |
11676 | |
11677 | return; | |
11678 | ||
11679 | nla_put_failure: | |
11680 | genlmsg_cancel(msg, hdr); | |
11681 | nlmsg_free(msg); | |
11682 | } | |
11683 | ||
9588bbd5 JM |
11684 | static void nl80211_send_remain_on_chan_event( |
11685 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 11686 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 11687 | struct ieee80211_channel *chan, |
9588bbd5 JM |
11688 | unsigned int duration, gfp_t gfp) |
11689 | { | |
11690 | struct sk_buff *msg; | |
11691 | void *hdr; | |
11692 | ||
11693 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11694 | if (!msg) | |
11695 | return; | |
11696 | ||
11697 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11698 | if (!hdr) { | |
11699 | nlmsg_free(msg); | |
11700 | return; | |
11701 | } | |
11702 | ||
9360ffd1 | 11703 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11704 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11705 | wdev->netdev->ifindex)) || | |
00f53350 | 11706 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 11707 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
11708 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
11709 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
11710 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
11711 | goto nla_put_failure; | |
9588bbd5 | 11712 | |
9360ffd1 DM |
11713 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
11714 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
11715 | goto nla_put_failure; | |
9588bbd5 | 11716 | |
3b7b72ee | 11717 | genlmsg_end(msg, hdr); |
9588bbd5 | 11718 | |
68eb5503 | 11719 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11720 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
11721 | return; |
11722 | ||
11723 | nla_put_failure: | |
11724 | genlmsg_cancel(msg, hdr); | |
11725 | nlmsg_free(msg); | |
11726 | } | |
11727 | ||
947add36 JB |
11728 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
11729 | struct ieee80211_channel *chan, | |
11730 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 11731 | { |
947add36 | 11732 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11733 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11734 | |
11735 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 11736 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 11737 | rdev, wdev, cookie, chan, |
42d97a59 | 11738 | duration, gfp); |
9588bbd5 | 11739 | } |
947add36 | 11740 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 11741 | |
947add36 JB |
11742 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
11743 | struct ieee80211_channel *chan, | |
11744 | gfp_t gfp) | |
9588bbd5 | 11745 | { |
947add36 | 11746 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11747 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11748 | |
11749 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 11750 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 11751 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 11752 | } |
947add36 | 11753 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 11754 | |
947add36 JB |
11755 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
11756 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 11757 | { |
947add36 | 11758 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11759 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
11760 | struct sk_buff *msg; |
11761 | ||
947add36 JB |
11762 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
11763 | ||
58050fce | 11764 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
11765 | if (!msg) |
11766 | return; | |
11767 | ||
cf5ead82 | 11768 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
66266b3a | 11769 | rdev, dev, mac_addr, sinfo) < 0) { |
98b62183 JB |
11770 | nlmsg_free(msg); |
11771 | return; | |
11772 | } | |
11773 | ||
68eb5503 | 11774 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11775 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 11776 | } |
947add36 | 11777 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 11778 | |
cf5ead82 JB |
11779 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
11780 | struct station_info *sinfo, gfp_t gfp) | |
ec15e68b | 11781 | { |
947add36 | 11782 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11783 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b | 11784 | struct sk_buff *msg; |
cf5ead82 JB |
11785 | struct station_info empty_sinfo = {}; |
11786 | ||
11787 | if (!sinfo) | |
11788 | sinfo = &empty_sinfo; | |
ec15e68b | 11789 | |
947add36 JB |
11790 | trace_cfg80211_del_sta(dev, mac_addr); |
11791 | ||
58050fce | 11792 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
11793 | if (!msg) |
11794 | return; | |
11795 | ||
cf5ead82 | 11796 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
57007121 | 11797 | rdev, dev, mac_addr, sinfo) < 0) { |
ec15e68b JM |
11798 | nlmsg_free(msg); |
11799 | return; | |
11800 | } | |
11801 | ||
68eb5503 | 11802 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11803 | NL80211_MCGRP_MLME, gfp); |
ec15e68b | 11804 | } |
cf5ead82 | 11805 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
ec15e68b | 11806 | |
947add36 JB |
11807 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
11808 | enum nl80211_connect_failed_reason reason, | |
11809 | gfp_t gfp) | |
ed44a951 | 11810 | { |
947add36 | 11811 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11812 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
11813 | struct sk_buff *msg; |
11814 | void *hdr; | |
11815 | ||
11816 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
11817 | if (!msg) | |
11818 | return; | |
11819 | ||
11820 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
11821 | if (!hdr) { | |
11822 | nlmsg_free(msg); | |
11823 | return; | |
11824 | } | |
11825 | ||
11826 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11827 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
11828 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
11829 | goto nla_put_failure; | |
11830 | ||
11831 | genlmsg_end(msg, hdr); | |
11832 | ||
68eb5503 | 11833 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11834 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
11835 | return; |
11836 | ||
11837 | nla_put_failure: | |
11838 | genlmsg_cancel(msg, hdr); | |
11839 | nlmsg_free(msg); | |
11840 | } | |
947add36 | 11841 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 11842 | |
b92ab5d8 JB |
11843 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
11844 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
11845 | { |
11846 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 11847 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
11848 | struct sk_buff *msg; |
11849 | void *hdr; | |
15e47304 | 11850 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 11851 | |
15e47304 | 11852 | if (!nlportid) |
28946da7 JB |
11853 | return false; |
11854 | ||
11855 | msg = nlmsg_new(100, gfp); | |
11856 | if (!msg) | |
11857 | return true; | |
11858 | ||
b92ab5d8 | 11859 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
11860 | if (!hdr) { |
11861 | nlmsg_free(msg); | |
11862 | return true; | |
11863 | } | |
11864 | ||
9360ffd1 DM |
11865 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11866 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11867 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11868 | goto nla_put_failure; | |
28946da7 | 11869 | |
9c90a9f6 | 11870 | genlmsg_end(msg, hdr); |
15e47304 | 11871 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
11872 | return true; |
11873 | ||
11874 | nla_put_failure: | |
11875 | genlmsg_cancel(msg, hdr); | |
11876 | nlmsg_free(msg); | |
11877 | return true; | |
11878 | } | |
11879 | ||
947add36 JB |
11880 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
11881 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11882 | { |
947add36 JB |
11883 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11884 | bool ret; | |
11885 | ||
11886 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
11887 | ||
11888 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11889 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
11890 | trace_cfg80211_return_bool(false); | |
11891 | return false; | |
11892 | } | |
11893 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
11894 | addr, gfp); | |
11895 | trace_cfg80211_return_bool(ret); | |
11896 | return ret; | |
b92ab5d8 | 11897 | } |
947add36 | 11898 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 11899 | |
947add36 JB |
11900 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
11901 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11902 | { |
947add36 JB |
11903 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11904 | bool ret; | |
11905 | ||
11906 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
11907 | ||
11908 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11909 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
11910 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
11911 | trace_cfg80211_return_bool(false); | |
11912 | return false; | |
11913 | } | |
11914 | ret = __nl80211_unexpected_frame(dev, | |
11915 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
11916 | addr, gfp); | |
11917 | trace_cfg80211_return_bool(ret); | |
11918 | return ret; | |
b92ab5d8 | 11919 | } |
947add36 | 11920 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 11921 | |
2e161f78 | 11922 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 11923 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 11924 | int freq, int sig_dbm, |
19504cf5 | 11925 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 11926 | { |
71bbc994 | 11927 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11928 | struct sk_buff *msg; |
11929 | void *hdr; | |
026331c4 JM |
11930 | |
11931 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11932 | if (!msg) | |
11933 | return -ENOMEM; | |
11934 | ||
2e161f78 | 11935 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
11936 | if (!hdr) { |
11937 | nlmsg_free(msg); | |
11938 | return -ENOMEM; | |
11939 | } | |
11940 | ||
9360ffd1 | 11941 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11942 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11943 | netdev->ifindex)) || | |
a838490b | 11944 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11945 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
11946 | (sig_dbm && | |
11947 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
11948 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11949 | (flags && | |
11950 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 11951 | goto nla_put_failure; |
026331c4 | 11952 | |
3b7b72ee | 11953 | genlmsg_end(msg, hdr); |
026331c4 | 11954 | |
15e47304 | 11955 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
11956 | |
11957 | nla_put_failure: | |
11958 | genlmsg_cancel(msg, hdr); | |
11959 | nlmsg_free(msg); | |
11960 | return -ENOBUFS; | |
11961 | } | |
11962 | ||
947add36 JB |
11963 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
11964 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 11965 | { |
947add36 | 11966 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11967 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 11968 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11969 | struct sk_buff *msg; |
11970 | void *hdr; | |
11971 | ||
947add36 JB |
11972 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
11973 | ||
026331c4 JM |
11974 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11975 | if (!msg) | |
11976 | return; | |
11977 | ||
2e161f78 | 11978 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
11979 | if (!hdr) { |
11980 | nlmsg_free(msg); | |
11981 | return; | |
11982 | } | |
11983 | ||
9360ffd1 | 11984 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11985 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11986 | netdev->ifindex)) || | |
a838490b | 11987 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11988 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11989 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
11990 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
11991 | goto nla_put_failure; | |
026331c4 | 11992 | |
3b7b72ee | 11993 | genlmsg_end(msg, hdr); |
026331c4 | 11994 | |
68eb5503 | 11995 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11996 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
11997 | return; |
11998 | ||
11999 | nla_put_failure: | |
12000 | genlmsg_cancel(msg, hdr); | |
12001 | nlmsg_free(msg); | |
12002 | } | |
947add36 | 12003 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 12004 | |
5b97f49d JB |
12005 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
12006 | const char *mac, gfp_t gfp) | |
d6dc1a38 | 12007 | { |
947add36 | 12008 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5b97f49d JB |
12009 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
12010 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12011 | void **cb; | |
947add36 | 12012 | |
d6dc1a38 | 12013 | if (!msg) |
5b97f49d | 12014 | return NULL; |
d6dc1a38 | 12015 | |
5b97f49d JB |
12016 | cb = (void **)msg->cb; |
12017 | ||
12018 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
12019 | if (!cb[0]) { | |
d6dc1a38 | 12020 | nlmsg_free(msg); |
5b97f49d | 12021 | return NULL; |
d6dc1a38 JO |
12022 | } |
12023 | ||
9360ffd1 | 12024 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 12025 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 12026 | goto nla_put_failure; |
d6dc1a38 | 12027 | |
5b97f49d | 12028 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
d6dc1a38 JO |
12029 | goto nla_put_failure; |
12030 | ||
5b97f49d JB |
12031 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
12032 | if (!cb[1]) | |
9360ffd1 | 12033 | goto nla_put_failure; |
d6dc1a38 | 12034 | |
5b97f49d | 12035 | cb[2] = rdev; |
d6dc1a38 | 12036 | |
5b97f49d JB |
12037 | return msg; |
12038 | nla_put_failure: | |
12039 | nlmsg_free(msg); | |
12040 | return NULL; | |
12041 | } | |
12042 | ||
12043 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) | |
12044 | { | |
12045 | void **cb = (void **)msg->cb; | |
12046 | struct cfg80211_registered_device *rdev = cb[2]; | |
12047 | ||
12048 | nla_nest_end(msg, cb[1]); | |
12049 | genlmsg_end(msg, cb[0]); | |
12050 | ||
12051 | memset(msg->cb, 0, sizeof(msg->cb)); | |
d6dc1a38 | 12052 | |
68eb5503 | 12053 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12054 | NL80211_MCGRP_MLME, gfp); |
5b97f49d JB |
12055 | } |
12056 | ||
12057 | void cfg80211_cqm_rssi_notify(struct net_device *dev, | |
12058 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
12059 | gfp_t gfp) | |
12060 | { | |
12061 | struct sk_buff *msg; | |
12062 | ||
12063 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); | |
12064 | ||
98f03342 JB |
12065 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
12066 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) | |
12067 | return; | |
12068 | ||
5b97f49d JB |
12069 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
12070 | if (!msg) | |
12071 | return; | |
12072 | ||
12073 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
12074 | rssi_event)) | |
12075 | goto nla_put_failure; | |
12076 | ||
12077 | cfg80211_send_cqm(msg, gfp); | |
12078 | ||
d6dc1a38 JO |
12079 | return; |
12080 | ||
12081 | nla_put_failure: | |
d6dc1a38 JO |
12082 | nlmsg_free(msg); |
12083 | } | |
947add36 | 12084 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 12085 | |
5b97f49d JB |
12086 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
12087 | const u8 *peer, u32 num_packets, | |
12088 | u32 rate, u32 intvl, gfp_t gfp) | |
12089 | { | |
12090 | struct sk_buff *msg; | |
12091 | ||
12092 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12093 | if (!msg) | |
12094 | return; | |
12095 | ||
12096 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
12097 | goto nla_put_failure; | |
12098 | ||
12099 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
12100 | goto nla_put_failure; | |
12101 | ||
12102 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
12103 | goto nla_put_failure; | |
12104 | ||
12105 | cfg80211_send_cqm(msg, gfp); | |
12106 | return; | |
12107 | ||
12108 | nla_put_failure: | |
12109 | nlmsg_free(msg); | |
12110 | } | |
12111 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); | |
12112 | ||
12113 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, | |
12114 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
12115 | { | |
12116 | struct sk_buff *msg; | |
12117 | ||
12118 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); | |
12119 | ||
12120 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12121 | if (!msg) | |
12122 | return; | |
12123 | ||
12124 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) | |
12125 | goto nla_put_failure; | |
12126 | ||
12127 | cfg80211_send_cqm(msg, gfp); | |
12128 | return; | |
12129 | ||
12130 | nla_put_failure: | |
12131 | nlmsg_free(msg); | |
12132 | } | |
12133 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); | |
12134 | ||
98f03342 JB |
12135 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
12136 | { | |
12137 | struct sk_buff *msg; | |
12138 | ||
12139 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); | |
12140 | if (!msg) | |
12141 | return; | |
12142 | ||
12143 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) | |
12144 | goto nla_put_failure; | |
12145 | ||
12146 | cfg80211_send_cqm(msg, gfp); | |
12147 | return; | |
12148 | ||
12149 | nla_put_failure: | |
12150 | nlmsg_free(msg); | |
12151 | } | |
12152 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); | |
12153 | ||
947add36 JB |
12154 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
12155 | struct net_device *netdev, const u8 *bssid, | |
12156 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
12157 | { |
12158 | struct sk_buff *msg; | |
12159 | struct nlattr *rekey_attr; | |
12160 | void *hdr; | |
12161 | ||
58050fce | 12162 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
12163 | if (!msg) |
12164 | return; | |
12165 | ||
12166 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
12167 | if (!hdr) { | |
12168 | nlmsg_free(msg); | |
12169 | return; | |
12170 | } | |
12171 | ||
9360ffd1 DM |
12172 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12173 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12174 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
12175 | goto nla_put_failure; | |
e5497d76 JB |
12176 | |
12177 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
12178 | if (!rekey_attr) | |
12179 | goto nla_put_failure; | |
12180 | ||
9360ffd1 DM |
12181 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
12182 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
12183 | goto nla_put_failure; | |
e5497d76 JB |
12184 | |
12185 | nla_nest_end(msg, rekey_attr); | |
12186 | ||
3b7b72ee | 12187 | genlmsg_end(msg, hdr); |
e5497d76 | 12188 | |
68eb5503 | 12189 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12190 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
12191 | return; |
12192 | ||
12193 | nla_put_failure: | |
12194 | genlmsg_cancel(msg, hdr); | |
12195 | nlmsg_free(msg); | |
12196 | } | |
12197 | ||
947add36 JB |
12198 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
12199 | const u8 *replay_ctr, gfp_t gfp) | |
12200 | { | |
12201 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12202 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12203 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12204 | |
12205 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
12206 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
12207 | } | |
12208 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
12209 | ||
12210 | static void | |
12211 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
12212 | struct net_device *netdev, int index, | |
12213 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
12214 | { |
12215 | struct sk_buff *msg; | |
12216 | struct nlattr *attr; | |
12217 | void *hdr; | |
12218 | ||
58050fce | 12219 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
12220 | if (!msg) |
12221 | return; | |
12222 | ||
12223 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
12224 | if (!hdr) { | |
12225 | nlmsg_free(msg); | |
12226 | return; | |
12227 | } | |
12228 | ||
9360ffd1 DM |
12229 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12230 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
12231 | goto nla_put_failure; | |
c9df56b4 JM |
12232 | |
12233 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
12234 | if (!attr) | |
12235 | goto nla_put_failure; | |
12236 | ||
9360ffd1 DM |
12237 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
12238 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
12239 | (preauth && | |
12240 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
12241 | goto nla_put_failure; | |
c9df56b4 JM |
12242 | |
12243 | nla_nest_end(msg, attr); | |
12244 | ||
3b7b72ee | 12245 | genlmsg_end(msg, hdr); |
c9df56b4 | 12246 | |
68eb5503 | 12247 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12248 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
12249 | return; |
12250 | ||
12251 | nla_put_failure: | |
12252 | genlmsg_cancel(msg, hdr); | |
12253 | nlmsg_free(msg); | |
12254 | } | |
12255 | ||
947add36 JB |
12256 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
12257 | const u8 *bssid, bool preauth, gfp_t gfp) | |
12258 | { | |
12259 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12260 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12261 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12262 | |
12263 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
12264 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
12265 | } | |
12266 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
12267 | ||
12268 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
12269 | struct net_device *netdev, | |
12270 | struct cfg80211_chan_def *chandef, | |
f8d7552e LC |
12271 | gfp_t gfp, |
12272 | enum nl80211_commands notif, | |
12273 | u8 count) | |
5314526b TP |
12274 | { |
12275 | struct sk_buff *msg; | |
12276 | void *hdr; | |
12277 | ||
58050fce | 12278 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
12279 | if (!msg) |
12280 | return; | |
12281 | ||
f8d7552e | 12282 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
5314526b TP |
12283 | if (!hdr) { |
12284 | nlmsg_free(msg); | |
12285 | return; | |
12286 | } | |
12287 | ||
683b6d3b JB |
12288 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
12289 | goto nla_put_failure; | |
12290 | ||
12291 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 12292 | goto nla_put_failure; |
5314526b | 12293 | |
f8d7552e LC |
12294 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
12295 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) | |
12296 | goto nla_put_failure; | |
12297 | ||
5314526b TP |
12298 | genlmsg_end(msg, hdr); |
12299 | ||
68eb5503 | 12300 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12301 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
12302 | return; |
12303 | ||
12304 | nla_put_failure: | |
12305 | genlmsg_cancel(msg, hdr); | |
12306 | nlmsg_free(msg); | |
12307 | } | |
12308 | ||
947add36 JB |
12309 | void cfg80211_ch_switch_notify(struct net_device *dev, |
12310 | struct cfg80211_chan_def *chandef) | |
84f10708 | 12311 | { |
947add36 JB |
12312 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
12313 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12314 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 12315 | |
e487eaeb | 12316 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 12317 | |
e487eaeb | 12318 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 | 12319 | |
9e0e2961 | 12320 | wdev->chandef = *chandef; |
96f55f12 | 12321 | wdev->preset_chandef = *chandef; |
f8d7552e LC |
12322 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
12323 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); | |
947add36 JB |
12324 | } |
12325 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
12326 | ||
f8d7552e LC |
12327 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
12328 | struct cfg80211_chan_def *chandef, | |
12329 | u8 count) | |
12330 | { | |
12331 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12332 | struct wiphy *wiphy = wdev->wiphy; | |
12333 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
12334 | ||
12335 | trace_cfg80211_ch_switch_started_notify(dev, chandef); | |
12336 | ||
12337 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | |
12338 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); | |
12339 | } | |
12340 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | |
12341 | ||
04f39047 SW |
12342 | void |
12343 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 12344 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
12345 | enum nl80211_radar_event event, |
12346 | struct net_device *netdev, gfp_t gfp) | |
12347 | { | |
12348 | struct sk_buff *msg; | |
12349 | void *hdr; | |
12350 | ||
12351 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12352 | if (!msg) | |
12353 | return; | |
12354 | ||
12355 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
12356 | if (!hdr) { | |
12357 | nlmsg_free(msg); | |
12358 | return; | |
12359 | } | |
12360 | ||
12361 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
12362 | goto nla_put_failure; | |
12363 | ||
12364 | /* NOP and radar events don't need a netdev parameter */ | |
12365 | if (netdev) { | |
12366 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
12367 | ||
12368 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12369 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12370 | goto nla_put_failure; | |
12371 | } | |
12372 | ||
12373 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
12374 | goto nla_put_failure; | |
12375 | ||
12376 | if (nl80211_send_chandef(msg, chandef)) | |
12377 | goto nla_put_failure; | |
12378 | ||
9c90a9f6 | 12379 | genlmsg_end(msg, hdr); |
04f39047 | 12380 | |
68eb5503 | 12381 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12382 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
12383 | return; |
12384 | ||
12385 | nla_put_failure: | |
12386 | genlmsg_cancel(msg, hdr); | |
12387 | nlmsg_free(msg); | |
12388 | } | |
12389 | ||
7f6cf311 JB |
12390 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
12391 | u64 cookie, bool acked, gfp_t gfp) | |
12392 | { | |
12393 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12394 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
12395 | struct sk_buff *msg; |
12396 | void *hdr; | |
7f6cf311 | 12397 | |
4ee3e063 BL |
12398 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
12399 | ||
58050fce | 12400 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 12401 | |
7f6cf311 JB |
12402 | if (!msg) |
12403 | return; | |
12404 | ||
12405 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
12406 | if (!hdr) { | |
12407 | nlmsg_free(msg); | |
12408 | return; | |
12409 | } | |
12410 | ||
9360ffd1 DM |
12411 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12412 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12413 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
12414 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
12415 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
12416 | goto nla_put_failure; | |
7f6cf311 | 12417 | |
9c90a9f6 | 12418 | genlmsg_end(msg, hdr); |
7f6cf311 | 12419 | |
68eb5503 | 12420 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12421 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
12422 | return; |
12423 | ||
12424 | nla_put_failure: | |
12425 | genlmsg_cancel(msg, hdr); | |
12426 | nlmsg_free(msg); | |
12427 | } | |
12428 | EXPORT_SYMBOL(cfg80211_probe_status); | |
12429 | ||
5e760230 JB |
12430 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
12431 | const u8 *frame, size_t len, | |
37c73b5f | 12432 | int freq, int sig_dbm) |
5e760230 | 12433 | { |
f26cbf40 | 12434 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
12435 | struct sk_buff *msg; |
12436 | void *hdr; | |
37c73b5f | 12437 | struct cfg80211_beacon_registration *reg; |
5e760230 | 12438 | |
4ee3e063 BL |
12439 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
12440 | ||
37c73b5f BG |
12441 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12442 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
12443 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
12444 | if (!msg) { | |
12445 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
12446 | return; | |
12447 | } | |
5e760230 | 12448 | |
37c73b5f BG |
12449 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
12450 | if (!hdr) | |
12451 | goto nla_put_failure; | |
5e760230 | 12452 | |
37c73b5f BG |
12453 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12454 | (freq && | |
12455 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
12456 | (sig_dbm && | |
12457 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
12458 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
12459 | goto nla_put_failure; | |
5e760230 | 12460 | |
37c73b5f | 12461 | genlmsg_end(msg, hdr); |
5e760230 | 12462 | |
37c73b5f BG |
12463 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
12464 | } | |
12465 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
12466 | return; |
12467 | ||
12468 | nla_put_failure: | |
37c73b5f BG |
12469 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
12470 | if (hdr) | |
12471 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
12472 | nlmsg_free(msg); |
12473 | } | |
12474 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
12475 | ||
cd8f7cb4 | 12476 | #ifdef CONFIG_PM |
8cd4d456 LC |
12477 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
12478 | struct cfg80211_wowlan_wakeup *wakeup) | |
12479 | { | |
12480 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | |
12481 | struct nlattr *nl_results, *nl_match, *nl_freqs; | |
12482 | int i, j; | |
12483 | ||
12484 | nl_results = nla_nest_start( | |
12485 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | |
12486 | if (!nl_results) | |
12487 | return -EMSGSIZE; | |
12488 | ||
12489 | for (i = 0; i < nd->n_matches; i++) { | |
12490 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | |
12491 | ||
12492 | nl_match = nla_nest_start(msg, i); | |
12493 | if (!nl_match) | |
12494 | break; | |
12495 | ||
12496 | /* The SSID attribute is optional in nl80211, but for | |
12497 | * simplicity reasons it's always present in the | |
12498 | * cfg80211 structure. If a driver can't pass the | |
12499 | * SSID, that needs to be changed. A zero length SSID | |
12500 | * is still a valid SSID (wildcard), so it cannot be | |
12501 | * used for this purpose. | |
12502 | */ | |
12503 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | |
12504 | match->ssid.ssid)) { | |
12505 | nla_nest_cancel(msg, nl_match); | |
12506 | goto out; | |
12507 | } | |
12508 | ||
12509 | if (match->n_channels) { | |
12510 | nl_freqs = nla_nest_start( | |
12511 | msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
12512 | if (!nl_freqs) { | |
12513 | nla_nest_cancel(msg, nl_match); | |
12514 | goto out; | |
12515 | } | |
12516 | ||
12517 | for (j = 0; j < match->n_channels; j++) { | |
12518 | if (nla_put_u32(msg, | |
12519 | NL80211_ATTR_WIPHY_FREQ, | |
12520 | match->channels[j])) { | |
12521 | nla_nest_cancel(msg, nl_freqs); | |
12522 | nla_nest_cancel(msg, nl_match); | |
12523 | goto out; | |
12524 | } | |
12525 | } | |
12526 | ||
12527 | nla_nest_end(msg, nl_freqs); | |
12528 | } | |
12529 | ||
12530 | nla_nest_end(msg, nl_match); | |
12531 | } | |
12532 | ||
12533 | out: | |
12534 | nla_nest_end(msg, nl_results); | |
12535 | return 0; | |
12536 | } | |
12537 | ||
cd8f7cb4 JB |
12538 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
12539 | struct cfg80211_wowlan_wakeup *wakeup, | |
12540 | gfp_t gfp) | |
12541 | { | |
f26cbf40 | 12542 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
12543 | struct sk_buff *msg; |
12544 | void *hdr; | |
9c90a9f6 | 12545 | int size = 200; |
cd8f7cb4 JB |
12546 | |
12547 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
12548 | ||
12549 | if (wakeup) | |
12550 | size += wakeup->packet_present_len; | |
12551 | ||
12552 | msg = nlmsg_new(size, gfp); | |
12553 | if (!msg) | |
12554 | return; | |
12555 | ||
12556 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
12557 | if (!hdr) | |
12558 | goto free_msg; | |
12559 | ||
12560 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12561 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12562 | goto free_msg; | |
12563 | ||
12564 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
12565 | wdev->netdev->ifindex)) | |
12566 | goto free_msg; | |
12567 | ||
12568 | if (wakeup) { | |
12569 | struct nlattr *reasons; | |
12570 | ||
12571 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
12572 | if (!reasons) |
12573 | goto free_msg; | |
cd8f7cb4 JB |
12574 | |
12575 | if (wakeup->disconnect && | |
12576 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
12577 | goto free_msg; | |
12578 | if (wakeup->magic_pkt && | |
12579 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
12580 | goto free_msg; | |
12581 | if (wakeup->gtk_rekey_failure && | |
12582 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
12583 | goto free_msg; | |
12584 | if (wakeup->eap_identity_req && | |
12585 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
12586 | goto free_msg; | |
12587 | if (wakeup->four_way_handshake && | |
12588 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
12589 | goto free_msg; | |
12590 | if (wakeup->rfkill_release && | |
12591 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
12592 | goto free_msg; | |
12593 | ||
12594 | if (wakeup->pattern_idx >= 0 && | |
12595 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
12596 | wakeup->pattern_idx)) | |
12597 | goto free_msg; | |
12598 | ||
ae917c9f JB |
12599 | if (wakeup->tcp_match && |
12600 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
12601 | goto free_msg; | |
2a0e047e | 12602 | |
ae917c9f JB |
12603 | if (wakeup->tcp_connlost && |
12604 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
12605 | goto free_msg; | |
2a0e047e | 12606 | |
ae917c9f JB |
12607 | if (wakeup->tcp_nomoretokens && |
12608 | nla_put_flag(msg, | |
12609 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
12610 | goto free_msg; | |
2a0e047e | 12611 | |
cd8f7cb4 JB |
12612 | if (wakeup->packet) { |
12613 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
12614 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
12615 | ||
12616 | if (!wakeup->packet_80211) { | |
12617 | pkt_attr = | |
12618 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
12619 | len_attr = | |
12620 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
12621 | } | |
12622 | ||
12623 | if (wakeup->packet_len && | |
12624 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
12625 | goto free_msg; | |
12626 | ||
12627 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
12628 | wakeup->packet)) | |
12629 | goto free_msg; | |
12630 | } | |
12631 | ||
8cd4d456 LC |
12632 | if (wakeup->net_detect && |
12633 | cfg80211_net_detect_results(msg, wakeup)) | |
12634 | goto free_msg; | |
12635 | ||
cd8f7cb4 JB |
12636 | nla_nest_end(msg, reasons); |
12637 | } | |
12638 | ||
9c90a9f6 | 12639 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 12640 | |
68eb5503 | 12641 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12642 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
12643 | return; |
12644 | ||
12645 | free_msg: | |
12646 | nlmsg_free(msg); | |
12647 | } | |
12648 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
12649 | #endif | |
12650 | ||
3475b094 JM |
12651 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
12652 | enum nl80211_tdls_operation oper, | |
12653 | u16 reason_code, gfp_t gfp) | |
12654 | { | |
12655 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12656 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
12657 | struct sk_buff *msg; |
12658 | void *hdr; | |
3475b094 JM |
12659 | |
12660 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
12661 | reason_code); | |
12662 | ||
12663 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12664 | if (!msg) | |
12665 | return; | |
12666 | ||
12667 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
12668 | if (!hdr) { | |
12669 | nlmsg_free(msg); | |
12670 | return; | |
12671 | } | |
12672 | ||
12673 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12674 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12675 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
12676 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
12677 | (reason_code > 0 && | |
12678 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
12679 | goto nla_put_failure; | |
12680 | ||
9c90a9f6 | 12681 | genlmsg_end(msg, hdr); |
3475b094 | 12682 | |
68eb5503 | 12683 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12684 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
12685 | return; |
12686 | ||
12687 | nla_put_failure: | |
12688 | genlmsg_cancel(msg, hdr); | |
12689 | nlmsg_free(msg); | |
12690 | } | |
12691 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
12692 | ||
026331c4 JM |
12693 | static int nl80211_netlink_notify(struct notifier_block * nb, |
12694 | unsigned long state, | |
12695 | void *_notify) | |
12696 | { | |
12697 | struct netlink_notify *notify = _notify; | |
12698 | struct cfg80211_registered_device *rdev; | |
12699 | struct wireless_dev *wdev; | |
37c73b5f | 12700 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
12701 | |
12702 | if (state != NETLINK_URELEASE) | |
12703 | return NOTIFY_DONE; | |
12704 | ||
12705 | rcu_read_lock(); | |
12706 | ||
5e760230 | 12707 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
78f22b6a | 12708 | bool schedule_destroy_work = false; |
93a1e86c JR |
12709 | bool schedule_scan_stop = false; |
12710 | struct cfg80211_sched_scan_request *sched_scan_req = | |
12711 | rcu_dereference(rdev->sched_scan_req); | |
12712 | ||
12713 | if (sched_scan_req && notify->portid && | |
12714 | sched_scan_req->owner_nlportid == notify->portid) | |
12715 | schedule_scan_stop = true; | |
78f22b6a JB |
12716 | |
12717 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { | |
15e47304 | 12718 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 12719 | |
78f22b6a JB |
12720 | if (wdev->owner_nlportid == notify->portid) |
12721 | schedule_destroy_work = true; | |
12722 | } | |
12723 | ||
37c73b5f BG |
12724 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12725 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
12726 | list) { | |
12727 | if (reg->nlportid == notify->portid) { | |
12728 | list_del(®->list); | |
12729 | kfree(reg); | |
12730 | break; | |
12731 | } | |
12732 | } | |
12733 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
78f22b6a JB |
12734 | |
12735 | if (schedule_destroy_work) { | |
12736 | struct cfg80211_iface_destroy *destroy; | |
12737 | ||
12738 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | |
12739 | if (destroy) { | |
12740 | destroy->nlportid = notify->portid; | |
12741 | spin_lock(&rdev->destroy_list_lock); | |
12742 | list_add(&destroy->list, &rdev->destroy_list); | |
12743 | spin_unlock(&rdev->destroy_list_lock); | |
12744 | schedule_work(&rdev->destroy_work); | |
12745 | } | |
93a1e86c JR |
12746 | } else if (schedule_scan_stop) { |
12747 | sched_scan_req->owner_nlportid = 0; | |
12748 | ||
12749 | if (rdev->ops->sched_scan_stop && | |
12750 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
12751 | schedule_work(&rdev->sched_scan_stop_wk); | |
78f22b6a | 12752 | } |
5e760230 | 12753 | } |
026331c4 JM |
12754 | |
12755 | rcu_read_unlock(); | |
12756 | ||
6784c7db | 12757 | return NOTIFY_OK; |
026331c4 JM |
12758 | } |
12759 | ||
12760 | static struct notifier_block nl80211_netlink_notifier = { | |
12761 | .notifier_call = nl80211_netlink_notify, | |
12762 | }; | |
12763 | ||
355199e0 JM |
12764 | void cfg80211_ft_event(struct net_device *netdev, |
12765 | struct cfg80211_ft_event_params *ft_event) | |
12766 | { | |
12767 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 12768 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
12769 | struct sk_buff *msg; |
12770 | void *hdr; | |
355199e0 JM |
12771 | |
12772 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
12773 | ||
12774 | if (!ft_event->target_ap) | |
12775 | return; | |
12776 | ||
12777 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12778 | if (!msg) | |
12779 | return; | |
12780 | ||
12781 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
12782 | if (!hdr) |
12783 | goto out; | |
355199e0 | 12784 | |
ae917c9f JB |
12785 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12786 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12787 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
12788 | goto out; | |
355199e0 | 12789 | |
ae917c9f JB |
12790 | if (ft_event->ies && |
12791 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
12792 | goto out; | |
12793 | if (ft_event->ric_ies && | |
12794 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
12795 | ft_event->ric_ies)) | |
12796 | goto out; | |
355199e0 | 12797 | |
9c90a9f6 | 12798 | genlmsg_end(msg, hdr); |
355199e0 | 12799 | |
68eb5503 | 12800 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12801 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
12802 | return; |
12803 | out: | |
12804 | nlmsg_free(msg); | |
355199e0 JM |
12805 | } |
12806 | EXPORT_SYMBOL(cfg80211_ft_event); | |
12807 | ||
5de17984 AS |
12808 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
12809 | { | |
12810 | struct cfg80211_registered_device *rdev; | |
12811 | struct sk_buff *msg; | |
12812 | void *hdr; | |
12813 | u32 nlportid; | |
12814 | ||
f26cbf40 | 12815 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
12816 | if (!rdev->crit_proto_nlportid) |
12817 | return; | |
12818 | ||
12819 | nlportid = rdev->crit_proto_nlportid; | |
12820 | rdev->crit_proto_nlportid = 0; | |
12821 | ||
12822 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12823 | if (!msg) | |
12824 | return; | |
12825 | ||
12826 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
12827 | if (!hdr) | |
12828 | goto nla_put_failure; | |
12829 | ||
12830 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12831 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12832 | goto nla_put_failure; | |
12833 | ||
12834 | genlmsg_end(msg, hdr); | |
12835 | ||
12836 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
12837 | return; | |
12838 | ||
12839 | nla_put_failure: | |
12840 | if (hdr) | |
12841 | genlmsg_cancel(msg, hdr); | |
12842 | nlmsg_free(msg); | |
12843 | ||
12844 | } | |
12845 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
12846 | ||
348baf0e JB |
12847 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
12848 | { | |
12849 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12850 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
12851 | struct sk_buff *msg; |
12852 | void *hdr; | |
12853 | ||
12854 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12855 | if (!msg) | |
12856 | return; | |
12857 | ||
12858 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
12859 | if (!hdr) | |
12860 | goto out; | |
12861 | ||
12862 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12863 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
12864 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12865 | goto out; | |
12866 | ||
12867 | genlmsg_end(msg, hdr); | |
12868 | ||
12869 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
12870 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
12871 | return; | |
12872 | out: | |
12873 | nlmsg_free(msg); | |
12874 | } | |
12875 | ||
55682965 JB |
12876 | /* initialisation/exit functions */ |
12877 | ||
12878 | int nl80211_init(void) | |
12879 | { | |
0d63cbb5 | 12880 | int err; |
55682965 | 12881 | |
2a94fe48 JB |
12882 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
12883 | nl80211_mcgrps); | |
55682965 JB |
12884 | if (err) |
12885 | return err; | |
12886 | ||
026331c4 JM |
12887 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
12888 | if (err) | |
12889 | goto err_out; | |
12890 | ||
55682965 JB |
12891 | return 0; |
12892 | err_out: | |
12893 | genl_unregister_family(&nl80211_fam); | |
12894 | return err; | |
12895 | } | |
12896 | ||
12897 | void nl80211_exit(void) | |
12898 | { | |
026331c4 | 12899 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
12900 | genl_unregister_family(&nl80211_fam); |
12901 | } |