]>
Commit | Line | Data |
---|---|---|
55682965 JB |
1 | /* |
2 | * This is the new netlink-based wireless configuration interface. | |
3 | * | |
026331c4 | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
2740f0cf | 5 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
55682965 JB |
6 | */ |
7 | ||
8 | #include <linux/if.h> | |
9 | #include <linux/module.h> | |
10 | #include <linux/err.h> | |
5a0e3ad6 | 11 | #include <linux/slab.h> |
55682965 JB |
12 | #include <linux/list.h> |
13 | #include <linux/if_ether.h> | |
14 | #include <linux/ieee80211.h> | |
15 | #include <linux/nl80211.h> | |
16 | #include <linux/rtnetlink.h> | |
17 | #include <linux/netlink.h> | |
2a519311 | 18 | #include <linux/etherdevice.h> |
463d0183 | 19 | #include <net/net_namespace.h> |
55682965 JB |
20 | #include <net/genetlink.h> |
21 | #include <net/cfg80211.h> | |
463d0183 | 22 | #include <net/sock.h> |
2a0e047e | 23 | #include <net/inet_connection_sock.h> |
55682965 JB |
24 | #include "core.h" |
25 | #include "nl80211.h" | |
b2e1b302 | 26 | #include "reg.h" |
e35e4d28 | 27 | #include "rdev-ops.h" |
55682965 | 28 | |
5fb628e9 JM |
29 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
30 | struct genl_info *info, | |
31 | struct cfg80211_crypto_settings *settings, | |
32 | int cipher_limit); | |
33 | ||
f84f771d | 34 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 | 35 | struct genl_info *info); |
f84f771d | 36 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
37 | struct genl_info *info); |
38 | ||
55682965 JB |
39 | /* the netlink family */ |
40 | static struct genl_family nl80211_fam = { | |
fb4e1568 MH |
41 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
42 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ | |
43 | .hdrsize = 0, /* no private header */ | |
44 | .version = 1, /* no particular meaning now */ | |
55682965 | 45 | .maxattr = NL80211_ATTR_MAX, |
463d0183 | 46 | .netnsok = true, |
4c476991 JB |
47 | .pre_doit = nl80211_pre_doit, |
48 | .post_doit = nl80211_post_doit, | |
55682965 JB |
49 | }; |
50 | ||
2a94fe48 JB |
51 | /* multicast groups */ |
52 | enum nl80211_multicast_groups { | |
53 | NL80211_MCGRP_CONFIG, | |
54 | NL80211_MCGRP_SCAN, | |
55 | NL80211_MCGRP_REGULATORY, | |
56 | NL80211_MCGRP_MLME, | |
567ffc35 | 57 | NL80211_MCGRP_VENDOR, |
2a94fe48 JB |
58 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
59 | }; | |
60 | ||
61 | static const struct genl_multicast_group nl80211_mcgrps[] = { | |
71b836ec JB |
62 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
63 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, | |
64 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, | |
65 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, | |
66 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, | |
2a94fe48 | 67 | #ifdef CONFIG_NL80211_TESTMODE |
71b836ec | 68 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
2a94fe48 JB |
69 | #endif |
70 | }; | |
71 | ||
89a54e48 JB |
72 | /* returns ERR_PTR values */ |
73 | static struct wireless_dev * | |
74 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 75 | { |
89a54e48 JB |
76 | struct cfg80211_registered_device *rdev; |
77 | struct wireless_dev *result = NULL; | |
78 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
79 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
80 | u64 wdev_id; | |
81 | int wiphy_idx = -1; | |
82 | int ifidx = -1; | |
55682965 | 83 | |
5fe231e8 | 84 | ASSERT_RTNL(); |
55682965 | 85 | |
89a54e48 JB |
86 | if (!have_ifidx && !have_wdev_id) |
87 | return ERR_PTR(-EINVAL); | |
55682965 | 88 | |
89a54e48 JB |
89 | if (have_ifidx) |
90 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
91 | if (have_wdev_id) { | |
92 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
93 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
94 | } |
95 | ||
89a54e48 JB |
96 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
97 | struct wireless_dev *wdev; | |
98 | ||
99 | if (wiphy_net(&rdev->wiphy) != netns) | |
100 | continue; | |
101 | ||
102 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
103 | continue; | |
104 | ||
89a54e48 JB |
105 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
106 | if (have_ifidx && wdev->netdev && | |
107 | wdev->netdev->ifindex == ifidx) { | |
108 | result = wdev; | |
109 | break; | |
110 | } | |
111 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
112 | result = wdev; | |
113 | break; | |
114 | } | |
115 | } | |
89a54e48 JB |
116 | |
117 | if (result) | |
118 | break; | |
119 | } | |
120 | ||
121 | if (result) | |
122 | return result; | |
123 | return ERR_PTR(-ENODEV); | |
55682965 JB |
124 | } |
125 | ||
a9455408 | 126 | static struct cfg80211_registered_device * |
878d9ec7 | 127 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 128 | { |
7fee4778 JB |
129 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
130 | struct net_device *netdev; | |
a9455408 | 131 | |
5fe231e8 | 132 | ASSERT_RTNL(); |
a9455408 | 133 | |
878d9ec7 | 134 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
135 | !attrs[NL80211_ATTR_IFINDEX] && |
136 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
137 | return ERR_PTR(-EINVAL); |
138 | ||
878d9ec7 | 139 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 140 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 141 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 142 | |
89a54e48 JB |
143 | if (attrs[NL80211_ATTR_WDEV]) { |
144 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
145 | struct wireless_dev *wdev; | |
146 | bool found = false; | |
147 | ||
148 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
149 | if (tmp) { | |
150 | /* make sure wdev exists */ | |
89a54e48 JB |
151 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
152 | if (wdev->identifier != (u32)wdev_id) | |
153 | continue; | |
154 | found = true; | |
155 | break; | |
156 | } | |
89a54e48 JB |
157 | |
158 | if (!found) | |
159 | tmp = NULL; | |
160 | ||
161 | if (rdev && tmp != rdev) | |
162 | return ERR_PTR(-EINVAL); | |
163 | rdev = tmp; | |
164 | } | |
165 | } | |
166 | ||
878d9ec7 JB |
167 | if (attrs[NL80211_ATTR_IFINDEX]) { |
168 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
7f2b8562 | 169 | netdev = __dev_get_by_index(netns, ifindex); |
7fee4778 JB |
170 | if (netdev) { |
171 | if (netdev->ieee80211_ptr) | |
f26cbf40 ZG |
172 | tmp = wiphy_to_rdev( |
173 | netdev->ieee80211_ptr->wiphy); | |
7fee4778 JB |
174 | else |
175 | tmp = NULL; | |
176 | ||
7fee4778 JB |
177 | /* not wireless device -- return error */ |
178 | if (!tmp) | |
179 | return ERR_PTR(-EINVAL); | |
180 | ||
181 | /* mismatch -- return error */ | |
182 | if (rdev && tmp != rdev) | |
183 | return ERR_PTR(-EINVAL); | |
184 | ||
185 | rdev = tmp; | |
a9455408 | 186 | } |
a9455408 | 187 | } |
a9455408 | 188 | |
4f7eff10 JB |
189 | if (!rdev) |
190 | return ERR_PTR(-ENODEV); | |
a9455408 | 191 | |
4f7eff10 JB |
192 | if (netns != wiphy_net(&rdev->wiphy)) |
193 | return ERR_PTR(-ENODEV); | |
194 | ||
195 | return rdev; | |
a9455408 JB |
196 | } |
197 | ||
198 | /* | |
199 | * This function returns a pointer to the driver | |
200 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
201 | * |
202 | * The result of this can be a PTR_ERR and hence must | |
203 | * be checked with IS_ERR() for errors. | |
204 | */ | |
205 | static struct cfg80211_registered_device * | |
4f7eff10 | 206 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 207 | { |
5fe231e8 | 208 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
209 | } |
210 | ||
55682965 | 211 | /* policy for the attributes */ |
8cd4d456 | 212 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
55682965 JB |
213 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
214 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 215 | .len = 20-1 }, |
31888487 | 216 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 217 | |
72bdcf34 | 218 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 219 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
220 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
221 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
222 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
223 | ||
b9a5f8ca JM |
224 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
225 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
226 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
227 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 228 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
3057dbfd | 229 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
55682965 JB |
230 | |
231 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
232 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
233 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 234 | |
e007b857 EP |
235 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
236 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 237 | |
b9454e83 | 238 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
239 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
240 | .len = WLAN_MAX_KEY_LEN }, | |
241 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
242 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
243 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 244 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 245 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
246 | |
247 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
248 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
249 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
250 | .len = IEEE80211_MAX_DATA_LEN }, | |
251 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
252 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
253 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
254 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
255 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
256 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
257 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 258 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 259 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 260 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 261 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 262 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 263 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 264 | |
b2e1b302 LR |
265 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
266 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
267 | ||
9f1ba906 JM |
268 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
269 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
270 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
271 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
272 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 273 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 274 | |
24bdd9f4 | 275 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 276 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 277 | |
6c739419 | 278 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
279 | |
280 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
281 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
282 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
283 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
284 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
285 | |
286 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
287 | .len = IEEE80211_MAX_SSID_LEN }, | |
288 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
289 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 290 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 291 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 292 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
293 | [NL80211_ATTR_STA_FLAGS2] = { |
294 | .len = sizeof(struct nl80211_sta_flag_update), | |
295 | }, | |
3f77316c | 296 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
297 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
298 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
299 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
300 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
301 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 302 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 303 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
304 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
305 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
306 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
307 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 308 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
309 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
310 | .len = IEEE80211_MAX_DATA_LEN }, | |
311 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 312 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 313 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 314 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 315 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
316 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
317 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 318 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
319 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
320 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 321 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 322 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 323 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 324 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 325 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 326 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 327 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 328 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 329 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
330 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
331 | .len = IEEE80211_MAX_DATA_LEN }, | |
332 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
333 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 334 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 335 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 336 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
337 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
338 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
339 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
340 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
341 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
31fa97c5 | 342 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
e247bd90 | 343 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
344 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
345 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 346 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
347 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
348 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
349 | .len = NL80211_HT_CAPABILITY_LEN | |
350 | }, | |
1d9d9213 | 351 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 352 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 353 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 354 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 355 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
e39e5b5e | 356 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
f461be3e | 357 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
ed473771 | 358 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
53cabad7 JB |
359 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
360 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | |
77765eaf VT |
361 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
362 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
363 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
364 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 365 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
366 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
367 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
368 | .len = NL80211_VHT_CAPABILITY_LEN, | |
369 | }, | |
355199e0 JM |
370 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
371 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
372 | .len = IEEE80211_MAX_DATA_LEN }, | |
5e4b6f56 | 373 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
16ef1fe2 SW |
374 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
375 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | |
376 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | |
9a774c78 AO |
377 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
378 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, | |
c01fc9ad SD |
379 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
380 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, | |
5336fa88 | 381 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
60f4a7b1 | 382 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
ad7e718c JB |
383 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
384 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, | |
385 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, | |
fa9ffc74 KP |
386 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
387 | .len = IEEE80211_QOS_MAP_LEN_MAX }, | |
1df4a510 JM |
388 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
389 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, | |
df942e7b | 390 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
18e5ca65 | 391 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
34d22ce2 | 392 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
bab5ab7d | 393 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
960d01ac JB |
394 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
395 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, | |
396 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, | |
18998c38 | 397 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
ad2b26ab | 398 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
1bdd716c | 399 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
55682965 JB |
400 | }; |
401 | ||
e31b8213 | 402 | /* policy for the key attributes */ |
b54452b0 | 403 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 404 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
405 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
406 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 407 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
408 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
409 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 410 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
411 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
412 | }; | |
413 | ||
414 | /* policy for the key default flags */ | |
415 | static const struct nla_policy | |
416 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
417 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
418 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
419 | }; |
420 | ||
ff1b6e69 JB |
421 | /* policy for WoWLAN attributes */ |
422 | static const struct nla_policy | |
423 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
424 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
425 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
426 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
427 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
428 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
429 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
430 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
431 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e | 432 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
8cd4d456 | 433 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
2a0e047e JB |
434 | }; |
435 | ||
436 | static const struct nla_policy | |
437 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
438 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
439 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
440 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
441 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
442 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
443 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
444 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
445 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
446 | }, | |
447 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
448 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
449 | }, | |
450 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
451 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
452 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
453 | }; |
454 | ||
be29b99a AK |
455 | /* policy for coalesce rule attributes */ |
456 | static const struct nla_policy | |
457 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
458 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
459 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
460 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
461 | }; | |
462 | ||
e5497d76 JB |
463 | /* policy for GTK rekey offload attributes */ |
464 | static const struct nla_policy | |
465 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
466 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
467 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
468 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
469 | }; | |
470 | ||
a1f1c21c LC |
471 | static const struct nla_policy |
472 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 473 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 474 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 475 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
476 | }; |
477 | ||
97990a06 JB |
478 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
479 | struct netlink_callback *cb, | |
480 | struct cfg80211_registered_device **rdev, | |
481 | struct wireless_dev **wdev) | |
a043897a | 482 | { |
97990a06 | 483 | int err; |
a043897a | 484 | |
97990a06 | 485 | rtnl_lock(); |
a043897a | 486 | |
97990a06 JB |
487 | if (!cb->args[0]) { |
488 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
489 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
490 | nl80211_policy); | |
491 | if (err) | |
492 | goto out_unlock; | |
67748893 | 493 | |
97990a06 JB |
494 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
495 | nl80211_fam.attrbuf); | |
496 | if (IS_ERR(*wdev)) { | |
497 | err = PTR_ERR(*wdev); | |
498 | goto out_unlock; | |
499 | } | |
f26cbf40 | 500 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
501 | /* 0 is the first index - add 1 to parse only once */ |
502 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
503 | cb->args[1] = (*wdev)->identifier; |
504 | } else { | |
c319d50b JB |
505 | /* subtract the 1 again here */ |
506 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 507 | struct wireless_dev *tmp; |
67748893 | 508 | |
97990a06 JB |
509 | if (!wiphy) { |
510 | err = -ENODEV; | |
511 | goto out_unlock; | |
512 | } | |
f26cbf40 | 513 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 514 | *wdev = NULL; |
67748893 | 515 | |
97990a06 JB |
516 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
517 | if (tmp->identifier == cb->args[1]) { | |
518 | *wdev = tmp; | |
519 | break; | |
520 | } | |
521 | } | |
67748893 | 522 | |
97990a06 JB |
523 | if (!*wdev) { |
524 | err = -ENODEV; | |
525 | goto out_unlock; | |
526 | } | |
67748893 JB |
527 | } |
528 | ||
67748893 | 529 | return 0; |
97990a06 | 530 | out_unlock: |
67748893 JB |
531 | rtnl_unlock(); |
532 | return err; | |
533 | } | |
534 | ||
97990a06 | 535 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 536 | { |
67748893 JB |
537 | rtnl_unlock(); |
538 | } | |
539 | ||
f4a11bb0 JB |
540 | /* IE validation */ |
541 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
542 | { | |
543 | const u8 *pos; | |
544 | int len; | |
545 | ||
546 | if (!attr) | |
547 | return true; | |
548 | ||
549 | pos = nla_data(attr); | |
550 | len = nla_len(attr); | |
551 | ||
552 | while (len) { | |
553 | u8 elemlen; | |
554 | ||
555 | if (len < 2) | |
556 | return false; | |
557 | len -= 2; | |
558 | ||
559 | elemlen = pos[1]; | |
560 | if (elemlen > len) | |
561 | return false; | |
562 | ||
563 | len -= elemlen; | |
564 | pos += 2 + elemlen; | |
565 | } | |
566 | ||
567 | return true; | |
568 | } | |
569 | ||
55682965 | 570 | /* message building helper */ |
15e47304 | 571 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
572 | int flags, u8 cmd) |
573 | { | |
574 | /* since there is no private header just add the generic one */ | |
15e47304 | 575 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
576 | } |
577 | ||
5dab3b8a | 578 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
579 | struct ieee80211_channel *chan, |
580 | bool large) | |
5dab3b8a | 581 | { |
ea077c1c RL |
582 | /* Some channels must be completely excluded from the |
583 | * list to protect old user-space tools from breaking | |
584 | */ | |
585 | if (!large && chan->flags & | |
586 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
587 | return 0; | |
588 | ||
9360ffd1 DM |
589 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
590 | chan->center_freq)) | |
591 | goto nla_put_failure; | |
5dab3b8a | 592 | |
9360ffd1 DM |
593 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
594 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
595 | goto nla_put_failure; | |
8fe02e16 LR |
596 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
597 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
598 | goto nla_put_failure; | |
599 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
600 | goto nla_put_failure; | |
601 | } | |
cdc89b97 JB |
602 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
603 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
604 | goto nla_put_failure; | |
605 | if (large) { | |
606 | u32 time; | |
607 | ||
608 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
609 | ||
610 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
611 | chan->dfs_state)) | |
612 | goto nla_put_failure; | |
613 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
614 | time)) | |
615 | goto nla_put_failure; | |
089027e5 JD |
616 | if (nla_put_u32(msg, |
617 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
618 | chan->dfs_cac_ms)) | |
619 | goto nla_put_failure; | |
cdc89b97 JB |
620 | } |
621 | } | |
5dab3b8a | 622 | |
fe1abafd JB |
623 | if (large) { |
624 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
625 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
626 | goto nla_put_failure; | |
627 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
628 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
629 | goto nla_put_failure; | |
630 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
631 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
632 | goto nla_put_failure; | |
633 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
634 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
635 | goto nla_put_failure; | |
570dbde1 DS |
636 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
637 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
638 | goto nla_put_failure; | |
639 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && | |
640 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) | |
641 | goto nla_put_failure; | |
ea077c1c RL |
642 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
643 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
644 | goto nla_put_failure; | |
645 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
646 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
647 | goto nla_put_failure; | |
fe1abafd JB |
648 | } |
649 | ||
9360ffd1 DM |
650 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
651 | DBM_TO_MBM(chan->max_power))) | |
652 | goto nla_put_failure; | |
5dab3b8a LR |
653 | |
654 | return 0; | |
655 | ||
656 | nla_put_failure: | |
657 | return -ENOBUFS; | |
658 | } | |
659 | ||
55682965 JB |
660 | /* netlink command implementations */ |
661 | ||
b9454e83 JB |
662 | struct key_parse { |
663 | struct key_params p; | |
664 | int idx; | |
e31b8213 | 665 | int type; |
b9454e83 | 666 | bool def, defmgmt; |
dbd2fd65 | 667 | bool def_uni, def_multi; |
b9454e83 JB |
668 | }; |
669 | ||
670 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
671 | { | |
672 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
673 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
674 | nl80211_key_policy); | |
675 | if (err) | |
676 | return err; | |
677 | ||
678 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
679 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
680 | ||
dbd2fd65 JB |
681 | if (k->def) { |
682 | k->def_uni = true; | |
683 | k->def_multi = true; | |
684 | } | |
685 | if (k->defmgmt) | |
686 | k->def_multi = true; | |
687 | ||
b9454e83 JB |
688 | if (tb[NL80211_KEY_IDX]) |
689 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
690 | ||
691 | if (tb[NL80211_KEY_DATA]) { | |
692 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
693 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
694 | } | |
695 | ||
696 | if (tb[NL80211_KEY_SEQ]) { | |
697 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
698 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
699 | } | |
700 | ||
701 | if (tb[NL80211_KEY_CIPHER]) | |
702 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
703 | ||
e31b8213 JB |
704 | if (tb[NL80211_KEY_TYPE]) { |
705 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
706 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
707 | return -EINVAL; | |
708 | } | |
709 | ||
dbd2fd65 JB |
710 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
711 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
712 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
713 | tb[NL80211_KEY_DEFAULT_TYPES], | |
714 | nl80211_key_default_policy); | |
dbd2fd65 JB |
715 | if (err) |
716 | return err; | |
717 | ||
718 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
719 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
720 | } | |
721 | ||
b9454e83 JB |
722 | return 0; |
723 | } | |
724 | ||
725 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
726 | { | |
727 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
728 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
729 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
730 | } | |
731 | ||
732 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
733 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
734 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
735 | } | |
736 | ||
737 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
738 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
739 | ||
740 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
741 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
742 | ||
743 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
744 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
745 | ||
dbd2fd65 JB |
746 | if (k->def) { |
747 | k->def_uni = true; | |
748 | k->def_multi = true; | |
749 | } | |
750 | if (k->defmgmt) | |
751 | k->def_multi = true; | |
752 | ||
e31b8213 JB |
753 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
754 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
755 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
756 | return -EINVAL; | |
757 | } | |
758 | ||
dbd2fd65 JB |
759 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
760 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
761 | int err = nla_parse_nested( | |
762 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
763 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
764 | nl80211_key_default_policy); | |
765 | if (err) | |
766 | return err; | |
767 | ||
768 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
769 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
770 | } | |
771 | ||
b9454e83 JB |
772 | return 0; |
773 | } | |
774 | ||
775 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
776 | { | |
777 | int err; | |
778 | ||
779 | memset(k, 0, sizeof(*k)); | |
780 | k->idx = -1; | |
e31b8213 | 781 | k->type = -1; |
b9454e83 JB |
782 | |
783 | if (info->attrs[NL80211_ATTR_KEY]) | |
784 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
785 | else | |
786 | err = nl80211_parse_key_old(info, k); | |
787 | ||
788 | if (err) | |
789 | return err; | |
790 | ||
791 | if (k->def && k->defmgmt) | |
792 | return -EINVAL; | |
793 | ||
dbd2fd65 JB |
794 | if (k->defmgmt) { |
795 | if (k->def_uni || !k->def_multi) | |
796 | return -EINVAL; | |
797 | } | |
798 | ||
b9454e83 JB |
799 | if (k->idx != -1) { |
800 | if (k->defmgmt) { | |
801 | if (k->idx < 4 || k->idx > 5) | |
802 | return -EINVAL; | |
803 | } else if (k->def) { | |
804 | if (k->idx < 0 || k->idx > 3) | |
805 | return -EINVAL; | |
806 | } else { | |
807 | if (k->idx < 0 || k->idx > 5) | |
808 | return -EINVAL; | |
809 | } | |
810 | } | |
811 | ||
812 | return 0; | |
813 | } | |
814 | ||
fffd0934 JB |
815 | static struct cfg80211_cached_keys * |
816 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 817 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
818 | { |
819 | struct key_parse parse; | |
820 | struct nlattr *key; | |
821 | struct cfg80211_cached_keys *result; | |
822 | int rem, err, def = 0; | |
823 | ||
824 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
825 | if (!result) | |
826 | return ERR_PTR(-ENOMEM); | |
827 | ||
828 | result->def = -1; | |
829 | result->defmgmt = -1; | |
830 | ||
831 | nla_for_each_nested(key, keys, rem) { | |
832 | memset(&parse, 0, sizeof(parse)); | |
833 | parse.idx = -1; | |
834 | ||
835 | err = nl80211_parse_key_new(key, &parse); | |
836 | if (err) | |
837 | goto error; | |
838 | err = -EINVAL; | |
839 | if (!parse.p.key) | |
840 | goto error; | |
841 | if (parse.idx < 0 || parse.idx > 4) | |
842 | goto error; | |
843 | if (parse.def) { | |
844 | if (def) | |
845 | goto error; | |
846 | def = 1; | |
847 | result->def = parse.idx; | |
dbd2fd65 JB |
848 | if (!parse.def_uni || !parse.def_multi) |
849 | goto error; | |
fffd0934 JB |
850 | } else if (parse.defmgmt) |
851 | goto error; | |
852 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 853 | parse.idx, false, NULL); |
fffd0934 JB |
854 | if (err) |
855 | goto error; | |
856 | result->params[parse.idx].cipher = parse.p.cipher; | |
857 | result->params[parse.idx].key_len = parse.p.key_len; | |
858 | result->params[parse.idx].key = result->data[parse.idx]; | |
859 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
860 | |
861 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
862 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
863 | if (no_ht) | |
864 | *no_ht = true; | |
865 | } | |
fffd0934 JB |
866 | } |
867 | ||
868 | return result; | |
869 | error: | |
870 | kfree(result); | |
871 | return ERR_PTR(err); | |
872 | } | |
873 | ||
874 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
875 | { | |
876 | ASSERT_WDEV_LOCK(wdev); | |
877 | ||
fffd0934 JB |
878 | switch (wdev->iftype) { |
879 | case NL80211_IFTYPE_AP: | |
880 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 881 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 882 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
883 | break; |
884 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 885 | case NL80211_IFTYPE_STATION: |
074ac8df | 886 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 887 | if (!wdev->current_bss) |
fffd0934 JB |
888 | return -ENOLINK; |
889 | break; | |
de4fcbad | 890 | case NL80211_IFTYPE_UNSPECIFIED: |
6e0bd6c3 | 891 | case NL80211_IFTYPE_OCB: |
de4fcbad JB |
892 | case NL80211_IFTYPE_MONITOR: |
893 | case NL80211_IFTYPE_P2P_DEVICE: | |
894 | case NL80211_IFTYPE_WDS: | |
895 | case NUM_NL80211_IFTYPES: | |
fffd0934 JB |
896 | return -EINVAL; |
897 | } | |
898 | ||
899 | return 0; | |
900 | } | |
901 | ||
664834de JM |
902 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
903 | struct nlattr *tb) | |
904 | { | |
905 | struct ieee80211_channel *chan; | |
906 | ||
907 | if (tb == NULL) | |
908 | return NULL; | |
909 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
910 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
911 | return NULL; | |
912 | return chan; | |
913 | } | |
914 | ||
7527a782 JB |
915 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
916 | { | |
917 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
918 | int i; | |
919 | ||
920 | if (!nl_modes) | |
921 | goto nla_put_failure; | |
922 | ||
923 | i = 0; | |
924 | while (ifmodes) { | |
9360ffd1 DM |
925 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
926 | goto nla_put_failure; | |
7527a782 JB |
927 | ifmodes >>= 1; |
928 | i++; | |
929 | } | |
930 | ||
931 | nla_nest_end(msg, nl_modes); | |
932 | return 0; | |
933 | ||
934 | nla_put_failure: | |
935 | return -ENOBUFS; | |
936 | } | |
937 | ||
938 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
939 | struct sk_buff *msg, |
940 | bool large) | |
7527a782 JB |
941 | { |
942 | struct nlattr *nl_combis; | |
943 | int i, j; | |
944 | ||
945 | nl_combis = nla_nest_start(msg, | |
946 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
947 | if (!nl_combis) | |
948 | goto nla_put_failure; | |
949 | ||
950 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
951 | const struct ieee80211_iface_combination *c; | |
952 | struct nlattr *nl_combi, *nl_limits; | |
953 | ||
954 | c = &wiphy->iface_combinations[i]; | |
955 | ||
956 | nl_combi = nla_nest_start(msg, i + 1); | |
957 | if (!nl_combi) | |
958 | goto nla_put_failure; | |
959 | ||
960 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
961 | if (!nl_limits) | |
962 | goto nla_put_failure; | |
963 | ||
964 | for (j = 0; j < c->n_limits; j++) { | |
965 | struct nlattr *nl_limit; | |
966 | ||
967 | nl_limit = nla_nest_start(msg, j + 1); | |
968 | if (!nl_limit) | |
969 | goto nla_put_failure; | |
9360ffd1 DM |
970 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
971 | c->limits[j].max)) | |
972 | goto nla_put_failure; | |
7527a782 JB |
973 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
974 | c->limits[j].types)) | |
975 | goto nla_put_failure; | |
976 | nla_nest_end(msg, nl_limit); | |
977 | } | |
978 | ||
979 | nla_nest_end(msg, nl_limits); | |
980 | ||
9360ffd1 DM |
981 | if (c->beacon_int_infra_match && |
982 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
983 | goto nla_put_failure; | |
984 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
985 | c->num_different_channels) || | |
986 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
987 | c->max_interfaces)) | |
988 | goto nla_put_failure; | |
cdc89b97 | 989 | if (large && |
8c48b50a FF |
990 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
991 | c->radar_detect_widths) || | |
992 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
993 | c->radar_detect_regions))) | |
cdc89b97 | 994 | goto nla_put_failure; |
7527a782 JB |
995 | |
996 | nla_nest_end(msg, nl_combi); | |
997 | } | |
998 | ||
999 | nla_nest_end(msg, nl_combis); | |
1000 | ||
1001 | return 0; | |
1002 | nla_put_failure: | |
1003 | return -ENOBUFS; | |
1004 | } | |
1005 | ||
3713b4e3 | 1006 | #ifdef CONFIG_PM |
b56cf720 JB |
1007 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
1008 | struct sk_buff *msg) | |
1009 | { | |
964dc9e2 | 1010 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
1011 | struct nlattr *nl_tcp; |
1012 | ||
1013 | if (!tcp) | |
1014 | return 0; | |
1015 | ||
1016 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
1017 | if (!nl_tcp) | |
1018 | return -ENOBUFS; | |
1019 | ||
1020 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1021 | tcp->data_payload_max)) | |
1022 | return -ENOBUFS; | |
1023 | ||
1024 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1025 | tcp->data_payload_max)) | |
1026 | return -ENOBUFS; | |
1027 | ||
1028 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1029 | return -ENOBUFS; | |
1030 | ||
1031 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1032 | sizeof(*tcp->tok), tcp->tok)) | |
1033 | return -ENOBUFS; | |
1034 | ||
1035 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1036 | tcp->data_interval_max)) | |
1037 | return -ENOBUFS; | |
1038 | ||
1039 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1040 | tcp->wake_payload_max)) | |
1041 | return -ENOBUFS; | |
1042 | ||
1043 | nla_nest_end(msg, nl_tcp); | |
1044 | return 0; | |
1045 | } | |
1046 | ||
3713b4e3 | 1047 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1048 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1049 | bool large) |
55682965 | 1050 | { |
3713b4e3 | 1051 | struct nlattr *nl_wowlan; |
55682965 | 1052 | |
1b8ec87a | 1053 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1054 | return 0; |
55682965 | 1055 | |
3713b4e3 JB |
1056 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1057 | if (!nl_wowlan) | |
1058 | return -ENOBUFS; | |
9360ffd1 | 1059 | |
1b8ec87a | 1060 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1061 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1062 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1063 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1064 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1065 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1066 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1067 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1068 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1069 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1070 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1071 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1072 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1073 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1074 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1075 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1076 | return -ENOBUFS; | |
9360ffd1 | 1077 | |
1b8ec87a | 1078 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1079 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1080 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1081 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1082 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1083 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1084 | }; |
9360ffd1 | 1085 | |
3713b4e3 JB |
1086 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1087 | sizeof(pat), &pat)) | |
1088 | return -ENOBUFS; | |
1089 | } | |
9360ffd1 | 1090 | |
75453ccb LC |
1091 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
1092 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, | |
1093 | rdev->wiphy.wowlan->max_nd_match_sets)) | |
1094 | return -ENOBUFS; | |
1095 | ||
1b8ec87a | 1096 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1097 | return -ENOBUFS; |
1098 | ||
8cd4d456 LC |
1099 | /* TODO: send wowlan net detect */ |
1100 | ||
3713b4e3 | 1101 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1102 | |
3713b4e3 JB |
1103 | return 0; |
1104 | } | |
1105 | #endif | |
9360ffd1 | 1106 | |
be29b99a | 1107 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1108 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1109 | { |
1110 | struct nl80211_coalesce_rule_support rule; | |
1111 | ||
1b8ec87a | 1112 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1113 | return 0; |
1114 | ||
1b8ec87a ZG |
1115 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1116 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1117 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1118 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1119 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1120 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1121 | |
1122 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1123 | return -ENOBUFS; | |
1124 | ||
1125 | return 0; | |
1126 | } | |
1127 | ||
3713b4e3 JB |
1128 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1129 | struct ieee80211_supported_band *sband) | |
1130 | { | |
1131 | struct nlattr *nl_rates, *nl_rate; | |
1132 | struct ieee80211_rate *rate; | |
1133 | int i; | |
87bbbe22 | 1134 | |
3713b4e3 JB |
1135 | /* add HT info */ |
1136 | if (sband->ht_cap.ht_supported && | |
1137 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1138 | sizeof(sband->ht_cap.mcs), | |
1139 | &sband->ht_cap.mcs) || | |
1140 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1141 | sband->ht_cap.cap) || | |
1142 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1143 | sband->ht_cap.ampdu_factor) || | |
1144 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1145 | sband->ht_cap.ampdu_density))) | |
1146 | return -ENOBUFS; | |
afe0cbf8 | 1147 | |
3713b4e3 JB |
1148 | /* add VHT info */ |
1149 | if (sband->vht_cap.vht_supported && | |
1150 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1151 | sizeof(sband->vht_cap.vht_mcs), | |
1152 | &sband->vht_cap.vht_mcs) || | |
1153 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1154 | sband->vht_cap.cap))) | |
1155 | return -ENOBUFS; | |
f59ac048 | 1156 | |
3713b4e3 JB |
1157 | /* add bitrates */ |
1158 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1159 | if (!nl_rates) | |
1160 | return -ENOBUFS; | |
ee688b00 | 1161 | |
3713b4e3 JB |
1162 | for (i = 0; i < sband->n_bitrates; i++) { |
1163 | nl_rate = nla_nest_start(msg, i); | |
1164 | if (!nl_rate) | |
1165 | return -ENOBUFS; | |
ee688b00 | 1166 | |
3713b4e3 JB |
1167 | rate = &sband->bitrates[i]; |
1168 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1169 | rate->bitrate)) | |
1170 | return -ENOBUFS; | |
1171 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1172 | nla_put_flag(msg, | |
1173 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1174 | return -ENOBUFS; | |
ee688b00 | 1175 | |
3713b4e3 JB |
1176 | nla_nest_end(msg, nl_rate); |
1177 | } | |
d51626df | 1178 | |
3713b4e3 | 1179 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1180 | |
3713b4e3 JB |
1181 | return 0; |
1182 | } | |
ee688b00 | 1183 | |
3713b4e3 JB |
1184 | static int |
1185 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1186 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1187 | { | |
1188 | u16 stypes; | |
1189 | struct nlattr *nl_ftypes, *nl_ifs; | |
1190 | enum nl80211_iftype ift; | |
1191 | int i; | |
ee688b00 | 1192 | |
3713b4e3 JB |
1193 | if (!mgmt_stypes) |
1194 | return 0; | |
5dab3b8a | 1195 | |
3713b4e3 JB |
1196 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1197 | if (!nl_ifs) | |
1198 | return -ENOBUFS; | |
e2f367f2 | 1199 | |
3713b4e3 JB |
1200 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1201 | nl_ftypes = nla_nest_start(msg, ift); | |
1202 | if (!nl_ftypes) | |
1203 | return -ENOBUFS; | |
1204 | i = 0; | |
1205 | stypes = mgmt_stypes[ift].tx; | |
1206 | while (stypes) { | |
1207 | if ((stypes & 1) && | |
1208 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1209 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1210 | return -ENOBUFS; | |
1211 | stypes >>= 1; | |
1212 | i++; | |
ee688b00 | 1213 | } |
3713b4e3 JB |
1214 | nla_nest_end(msg, nl_ftypes); |
1215 | } | |
ee688b00 | 1216 | |
3713b4e3 | 1217 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1218 | |
3713b4e3 JB |
1219 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1220 | if (!nl_ifs) | |
1221 | return -ENOBUFS; | |
ee688b00 | 1222 | |
3713b4e3 JB |
1223 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1224 | nl_ftypes = nla_nest_start(msg, ift); | |
1225 | if (!nl_ftypes) | |
1226 | return -ENOBUFS; | |
1227 | i = 0; | |
1228 | stypes = mgmt_stypes[ift].rx; | |
1229 | while (stypes) { | |
1230 | if ((stypes & 1) && | |
1231 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1232 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1233 | return -ENOBUFS; | |
1234 | stypes >>= 1; | |
1235 | i++; | |
1236 | } | |
1237 | nla_nest_end(msg, nl_ftypes); | |
1238 | } | |
1239 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1240 | |
3713b4e3 JB |
1241 | return 0; |
1242 | } | |
ee688b00 | 1243 | |
86e8cf98 JB |
1244 | struct nl80211_dump_wiphy_state { |
1245 | s64 filter_wiphy; | |
1246 | long start; | |
1247 | long split_start, band_start, chan_start; | |
1248 | bool split; | |
1249 | }; | |
1250 | ||
1b8ec87a | 1251 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 1252 | enum nl80211_commands cmd, |
3713b4e3 | 1253 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1254 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1255 | { |
1256 | void *hdr; | |
1257 | struct nlattr *nl_bands, *nl_band; | |
1258 | struct nlattr *nl_freqs, *nl_freq; | |
1259 | struct nlattr *nl_cmds; | |
1260 | enum ieee80211_band band; | |
1261 | struct ieee80211_channel *chan; | |
1262 | int i; | |
1263 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1264 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1265 | u32 features; |
ee688b00 | 1266 | |
3bb20556 | 1267 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
1268 | if (!hdr) |
1269 | return -ENOBUFS; | |
ee688b00 | 1270 | |
86e8cf98 JB |
1271 | if (WARN_ON(!state)) |
1272 | return -EINVAL; | |
ee688b00 | 1273 | |
1b8ec87a | 1274 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1275 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1276 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1277 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1278 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1279 | goto nla_put_failure; |
1280 | ||
3bb20556 JB |
1281 | if (cmd != NL80211_CMD_NEW_WIPHY) |
1282 | goto finish; | |
1283 | ||
86e8cf98 | 1284 | switch (state->split_start) { |
3713b4e3 JB |
1285 | case 0: |
1286 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1287 | rdev->wiphy.retry_short) || |
3713b4e3 | 1288 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1289 | rdev->wiphy.retry_long) || |
3713b4e3 | 1290 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1291 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1292 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1293 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1294 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1295 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1296 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1297 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1298 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1299 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1300 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1301 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1302 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1303 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1304 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
1b8ec87a | 1305 | rdev->wiphy.max_match_sets)) |
9360ffd1 | 1306 | goto nla_put_failure; |
3713b4e3 | 1307 | |
1b8ec87a | 1308 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1309 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1310 | goto nla_put_failure; |
1b8ec87a | 1311 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1312 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1313 | goto nla_put_failure; | |
1b8ec87a | 1314 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1315 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1316 | goto nla_put_failure; | |
1b8ec87a | 1317 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1318 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1319 | goto nla_put_failure; | |
1b8ec87a | 1320 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1321 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1322 | goto nla_put_failure; | |
1b8ec87a | 1323 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1324 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1325 | goto nla_put_failure; |
86e8cf98 JB |
1326 | state->split_start++; |
1327 | if (state->split) | |
3713b4e3 JB |
1328 | break; |
1329 | case 1: | |
1330 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1331 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1332 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1333 | goto nla_put_failure; |
4745fc09 | 1334 | |
3713b4e3 | 1335 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1336 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1337 | goto nla_put_failure; |
b23aa676 | 1338 | |
1b8ec87a | 1339 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1340 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1341 | goto nla_put_failure; |
b23aa676 | 1342 | |
3713b4e3 | 1343 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1344 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1345 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1346 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1347 | goto nla_put_failure; |
b23aa676 | 1348 | |
1b8ec87a | 1349 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1350 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1351 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1352 | goto nla_put_failure; |
8fdc621d | 1353 | |
1b8ec87a ZG |
1354 | if ((rdev->wiphy.available_antennas_tx || |
1355 | rdev->wiphy.available_antennas_rx) && | |
1356 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1357 | u32 tx_ant = 0, rx_ant = 0; |
1358 | int res; | |
1b8ec87a | 1359 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1360 | if (!res) { |
1361 | if (nla_put_u32(msg, | |
1362 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1363 | tx_ant) || | |
1364 | nla_put_u32(msg, | |
1365 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1366 | rx_ant)) | |
1367 | goto nla_put_failure; | |
1368 | } | |
1369 | } | |
a293911d | 1370 | |
86e8cf98 JB |
1371 | state->split_start++; |
1372 | if (state->split) | |
3713b4e3 JB |
1373 | break; |
1374 | case 2: | |
1375 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1376 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1377 | goto nla_put_failure; |
86e8cf98 JB |
1378 | state->split_start++; |
1379 | if (state->split) | |
3713b4e3 JB |
1380 | break; |
1381 | case 3: | |
1382 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1383 | if (!nl_bands) | |
1384 | goto nla_put_failure; | |
f7ca38df | 1385 | |
86e8cf98 JB |
1386 | for (band = state->band_start; |
1387 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1388 | struct ieee80211_supported_band *sband; |
2e161f78 | 1389 | |
1b8ec87a | 1390 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1391 | |
3713b4e3 JB |
1392 | if (!sband) |
1393 | continue; | |
1394 | ||
1395 | nl_band = nla_nest_start(msg, band); | |
1396 | if (!nl_band) | |
2e161f78 | 1397 | goto nla_put_failure; |
3713b4e3 | 1398 | |
86e8cf98 | 1399 | switch (state->chan_start) { |
3713b4e3 JB |
1400 | case 0: |
1401 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1402 | goto nla_put_failure; |
86e8cf98 JB |
1403 | state->chan_start++; |
1404 | if (state->split) | |
3713b4e3 JB |
1405 | break; |
1406 | default: | |
1407 | /* add frequencies */ | |
1408 | nl_freqs = nla_nest_start( | |
1409 | msg, NL80211_BAND_ATTR_FREQS); | |
1410 | if (!nl_freqs) | |
1411 | goto nla_put_failure; | |
1412 | ||
86e8cf98 | 1413 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1414 | i < sband->n_channels; |
1415 | i++) { | |
1416 | nl_freq = nla_nest_start(msg, i); | |
1417 | if (!nl_freq) | |
1418 | goto nla_put_failure; | |
1419 | ||
1420 | chan = &sband->channels[i]; | |
1421 | ||
86e8cf98 JB |
1422 | if (nl80211_msg_put_channel( |
1423 | msg, chan, | |
1424 | state->split)) | |
3713b4e3 JB |
1425 | goto nla_put_failure; |
1426 | ||
1427 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1428 | if (state->split) |
3713b4e3 JB |
1429 | break; |
1430 | } | |
1431 | if (i < sband->n_channels) | |
86e8cf98 | 1432 | state->chan_start = i + 2; |
3713b4e3 | 1433 | else |
86e8cf98 | 1434 | state->chan_start = 0; |
3713b4e3 JB |
1435 | nla_nest_end(msg, nl_freqs); |
1436 | } | |
1437 | ||
1438 | nla_nest_end(msg, nl_band); | |
1439 | ||
86e8cf98 | 1440 | if (state->split) { |
3713b4e3 | 1441 | /* start again here */ |
86e8cf98 | 1442 | if (state->chan_start) |
3713b4e3 JB |
1443 | band--; |
1444 | break; | |
2e161f78 | 1445 | } |
2e161f78 | 1446 | } |
3713b4e3 | 1447 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1448 | |
3713b4e3 | 1449 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1450 | state->band_start = band + 1; |
3713b4e3 | 1451 | else |
86e8cf98 | 1452 | state->band_start = 0; |
74b70a4e | 1453 | |
3713b4e3 | 1454 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1455 | if (state->band_start == 0 && state->chan_start == 0) |
1456 | state->split_start++; | |
1457 | if (state->split) | |
3713b4e3 JB |
1458 | break; |
1459 | case 4: | |
1460 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1461 | if (!nl_cmds) | |
2e161f78 JB |
1462 | goto nla_put_failure; |
1463 | ||
3713b4e3 JB |
1464 | i = 0; |
1465 | #define CMD(op, n) \ | |
1466 | do { \ | |
1b8ec87a | 1467 | if (rdev->ops->op) { \ |
3713b4e3 JB |
1468 | i++; \ |
1469 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1470 | goto nla_put_failure; \ | |
1471 | } \ | |
1472 | } while (0) | |
1473 | ||
1474 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1475 | CMD(change_virtual_intf, SET_INTERFACE); | |
1476 | CMD(add_key, NEW_KEY); | |
1477 | CMD(start_ap, START_AP); | |
1478 | CMD(add_station, NEW_STATION); | |
1479 | CMD(add_mpath, NEW_MPATH); | |
1480 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1481 | CMD(change_bss, SET_BSS); | |
1482 | CMD(auth, AUTHENTICATE); | |
1483 | CMD(assoc, ASSOCIATE); | |
1484 | CMD(deauth, DEAUTHENTICATE); | |
1485 | CMD(disassoc, DISASSOCIATE); | |
1486 | CMD(join_ibss, JOIN_IBSS); | |
1487 | CMD(join_mesh, JOIN_MESH); | |
1488 | CMD(set_pmksa, SET_PMKSA); | |
1489 | CMD(del_pmksa, DEL_PMKSA); | |
1490 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1b8ec87a | 1491 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
3713b4e3 JB |
1492 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
1493 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1494 | CMD(mgmt_tx, FRAME); | |
1495 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1b8ec87a | 1496 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
3713b4e3 JB |
1497 | i++; |
1498 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1499 | goto nla_put_failure; |
2e161f78 | 1500 | } |
1b8ec87a ZG |
1501 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
1502 | rdev->ops->join_mesh) { | |
3713b4e3 JB |
1503 | i++; |
1504 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1505 | goto nla_put_failure; | |
1506 | } | |
1507 | CMD(set_wds_peer, SET_WDS_PEER); | |
1b8ec87a | 1508 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
3713b4e3 JB |
1509 | CMD(tdls_mgmt, TDLS_MGMT); |
1510 | CMD(tdls_oper, TDLS_OPER); | |
1511 | } | |
1b8ec87a | 1512 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
3713b4e3 JB |
1513 | CMD(sched_scan_start, START_SCHED_SCAN); |
1514 | CMD(probe_client, PROBE_CLIENT); | |
1515 | CMD(set_noack_map, SET_NOACK_MAP); | |
1b8ec87a | 1516 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
3713b4e3 JB |
1517 | i++; |
1518 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1519 | goto nla_put_failure; | |
1520 | } | |
1521 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1522 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
02df00eb JB |
1523 | #ifdef CONFIG_NL80211_TESTMODE |
1524 | CMD(testmode_cmd, TESTMODE); | |
1525 | #endif | |
86e8cf98 | 1526 | if (state->split) { |
5de17984 AS |
1527 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1528 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 1529 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 1530 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 1531 | CMD(set_qos_map, SET_QOS_MAP); |
723e73ac JB |
1532 | if (rdev->wiphy.features & |
1533 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | |
960d01ac | 1534 | CMD(add_tx_ts, ADD_TX_TS); |
5de17984 | 1535 | } |
02df00eb | 1536 | /* add into the if now */ |
3713b4e3 | 1537 | #undef CMD |
ff1b6e69 | 1538 | |
1b8ec87a | 1539 | if (rdev->ops->connect || rdev->ops->auth) { |
3713b4e3 JB |
1540 | i++; |
1541 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1542 | goto nla_put_failure; |
ff1b6e69 JB |
1543 | } |
1544 | ||
1b8ec87a | 1545 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
3713b4e3 JB |
1546 | i++; |
1547 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1548 | goto nla_put_failure; | |
1549 | } | |
1550 | ||
1551 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1552 | state->split_start++; |
1553 | if (state->split) | |
3713b4e3 JB |
1554 | break; |
1555 | case 5: | |
1b8ec87a ZG |
1556 | if (rdev->ops->remain_on_channel && |
1557 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
1558 | nla_put_u32(msg, |
1559 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 1560 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
1561 | goto nla_put_failure; |
1562 | ||
1b8ec87a | 1563 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
1564 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
1565 | goto nla_put_failure; | |
1566 | ||
1567 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1568 | goto nla_put_failure; | |
86e8cf98 JB |
1569 | state->split_start++; |
1570 | if (state->split) | |
3713b4e3 JB |
1571 | break; |
1572 | case 6: | |
1573 | #ifdef CONFIG_PM | |
1b8ec87a | 1574 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 1575 | goto nla_put_failure; |
86e8cf98 JB |
1576 | state->split_start++; |
1577 | if (state->split) | |
3713b4e3 JB |
1578 | break; |
1579 | #else | |
86e8cf98 | 1580 | state->split_start++; |
dfb89c56 | 1581 | #endif |
3713b4e3 JB |
1582 | case 7: |
1583 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 1584 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 1585 | goto nla_put_failure; |
ff1b6e69 | 1586 | |
1b8ec87a | 1587 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 1588 | state->split)) |
3713b4e3 | 1589 | goto nla_put_failure; |
7527a782 | 1590 | |
86e8cf98 JB |
1591 | state->split_start++; |
1592 | if (state->split) | |
3713b4e3 JB |
1593 | break; |
1594 | case 8: | |
1b8ec87a | 1595 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 1596 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 1597 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 1598 | goto nla_put_failure; |
7527a782 | 1599 | |
1b8ec87a | 1600 | features = rdev->wiphy.features; |
fe1abafd JB |
1601 | /* |
1602 | * We can only add the per-channel limit information if the | |
1603 | * dump is split, otherwise it makes it too big. Therefore | |
1604 | * only advertise it in that case. | |
1605 | */ | |
86e8cf98 | 1606 | if (state->split) |
fe1abafd JB |
1607 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1608 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1609 | goto nla_put_failure; |
562a7480 | 1610 | |
1b8ec87a | 1611 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 1612 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
1613 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
1614 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 1615 | goto nla_put_failure; |
1f074bd8 | 1616 | |
1b8ec87a ZG |
1617 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1618 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 1619 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 1620 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 1621 | goto nla_put_failure; |
7e7c8926 | 1622 | |
3713b4e3 JB |
1623 | /* |
1624 | * Any information below this point is only available to | |
1625 | * applications that can deal with it being split. This | |
1626 | * helps ensure that newly added capabilities don't break | |
1627 | * older tools by overrunning their buffers. | |
1628 | * | |
1629 | * We still increment split_start so that in the split | |
1630 | * case we'll continue with more data in the next round, | |
1631 | * but break unconditionally so unsplit data stops here. | |
1632 | */ | |
86e8cf98 | 1633 | state->split_start++; |
3713b4e3 JB |
1634 | break; |
1635 | case 9: | |
1b8ec87a | 1636 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 1637 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
1638 | rdev->wiphy.extended_capabilities_len, |
1639 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 1640 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
1641 | rdev->wiphy.extended_capabilities_len, |
1642 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 1643 | goto nla_put_failure; |
a50df0c4 | 1644 | |
1b8ec87a | 1645 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 1646 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
1647 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
1648 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
1649 | goto nla_put_failure; |
1650 | ||
be29b99a AK |
1651 | state->split_start++; |
1652 | break; | |
1653 | case 10: | |
1b8ec87a | 1654 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
1655 | goto nla_put_failure; |
1656 | ||
1b8ec87a | 1657 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
1658 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
1659 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1660 | goto nla_put_failure; | |
b43504cf | 1661 | |
1b8ec87a | 1662 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 1663 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 1664 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
1665 | goto nla_put_failure; |
1666 | ||
ad7e718c JB |
1667 | state->split_start++; |
1668 | break; | |
1669 | case 11: | |
1b8ec87a | 1670 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
1671 | const struct nl80211_vendor_cmd_info *info; |
1672 | struct nlattr *nested; | |
1673 | ||
1674 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1675 | if (!nested) | |
1676 | goto nla_put_failure; | |
1677 | ||
1b8ec87a ZG |
1678 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
1679 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
1680 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1681 | goto nla_put_failure; | |
1682 | } | |
1683 | nla_nest_end(msg, nested); | |
1684 | } | |
1685 | ||
1b8ec87a | 1686 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
1687 | const struct nl80211_vendor_cmd_info *info; |
1688 | struct nlattr *nested; | |
ad7e718c | 1689 | |
567ffc35 JB |
1690 | nested = nla_nest_start(msg, |
1691 | NL80211_ATTR_VENDOR_EVENTS); | |
1692 | if (!nested) | |
ad7e718c | 1693 | goto nla_put_failure; |
567ffc35 | 1694 | |
1b8ec87a ZG |
1695 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
1696 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
1697 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1698 | goto nla_put_failure; | |
1699 | } | |
1700 | nla_nest_end(msg, nested); | |
1701 | } | |
9a774c78 AO |
1702 | state->split_start++; |
1703 | break; | |
1704 | case 12: | |
1705 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
1706 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
1707 | rdev->wiphy.max_num_csa_counters)) | |
1708 | goto nla_put_failure; | |
01e0daa4 | 1709 | |
1bdd716c AN |
1710 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
1711 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
1712 | goto nla_put_failure; | |
1713 | ||
d75bb06b GKS |
1714 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
1715 | sizeof(rdev->wiphy.ext_features), | |
1716 | rdev->wiphy.ext_features)) | |
1717 | goto nla_put_failure; | |
1718 | ||
3713b4e3 | 1719 | /* done */ |
86e8cf98 | 1720 | state->split_start = 0; |
3713b4e3 JB |
1721 | break; |
1722 | } | |
3bb20556 | 1723 | finish: |
55682965 JB |
1724 | return genlmsg_end(msg, hdr); |
1725 | ||
1726 | nla_put_failure: | |
bc3ed28c TG |
1727 | genlmsg_cancel(msg, hdr); |
1728 | return -EMSGSIZE; | |
55682965 JB |
1729 | } |
1730 | ||
86e8cf98 JB |
1731 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1732 | struct netlink_callback *cb, | |
1733 | struct nl80211_dump_wiphy_state *state) | |
1734 | { | |
1735 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1736 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1737 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1738 | /* ignore parse errors for backward compatibility */ | |
1739 | if (ret) | |
1740 | return 0; | |
1741 | ||
1742 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1743 | if (tb[NL80211_ATTR_WIPHY]) | |
1744 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1745 | if (tb[NL80211_ATTR_WDEV]) | |
1746 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1747 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1748 | struct net_device *netdev; | |
1749 | struct cfg80211_registered_device *rdev; | |
1750 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1751 | ||
7f2b8562 | 1752 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1753 | if (!netdev) |
1754 | return -ENODEV; | |
1755 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1756 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1757 | netdev->ieee80211_ptr->wiphy); |
1758 | state->filter_wiphy = rdev->wiphy_idx; | |
1759 | } | |
86e8cf98 JB |
1760 | } |
1761 | ||
1762 | return 0; | |
1763 | } | |
1764 | ||
55682965 JB |
1765 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1766 | { | |
645e77de | 1767 | int idx = 0, ret; |
86e8cf98 | 1768 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1769 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1770 | |
5fe231e8 | 1771 | rtnl_lock(); |
86e8cf98 JB |
1772 | if (!state) { |
1773 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1774 | if (!state) { |
1775 | rtnl_unlock(); | |
86e8cf98 | 1776 | return -ENOMEM; |
3713b4e3 | 1777 | } |
86e8cf98 JB |
1778 | state->filter_wiphy = -1; |
1779 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1780 | if (ret) { | |
1781 | kfree(state); | |
1782 | rtnl_unlock(); | |
1783 | return ret; | |
3713b4e3 | 1784 | } |
86e8cf98 | 1785 | cb->args[0] = (long)state; |
3713b4e3 JB |
1786 | } |
1787 | ||
1b8ec87a ZG |
1788 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1789 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1790 | continue; |
86e8cf98 | 1791 | if (++idx <= state->start) |
55682965 | 1792 | continue; |
86e8cf98 | 1793 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1794 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1795 | continue; |
1796 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1797 | do { | |
3bb20556 JB |
1798 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
1799 | skb, | |
3713b4e3 JB |
1800 | NETLINK_CB(cb->skb).portid, |
1801 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1802 | NLM_F_MULTI, state); |
3713b4e3 JB |
1803 | if (ret < 0) { |
1804 | /* | |
1805 | * If sending the wiphy data didn't fit (ENOBUFS | |
1806 | * or EMSGSIZE returned), this SKB is still | |
1807 | * empty (so it's not too big because another | |
1808 | * wiphy dataset is already in the skb) and | |
1809 | * we've not tried to adjust the dump allocation | |
1810 | * yet ... then adjust the alloc size to be | |
1811 | * bigger, and return 1 but with the empty skb. | |
1812 | * This results in an empty message being RX'ed | |
1813 | * in userspace, but that is ignored. | |
1814 | * | |
1815 | * We can then retry with the larger buffer. | |
1816 | */ | |
1817 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1818 | !skb->len && !state->split && |
3713b4e3 JB |
1819 | cb->min_dump_alloc < 4096) { |
1820 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1821 | state->split_start = 0; |
d98cae64 | 1822 | rtnl_unlock(); |
3713b4e3 JB |
1823 | return 1; |
1824 | } | |
1825 | idx--; | |
1826 | break; | |
645e77de | 1827 | } |
86e8cf98 | 1828 | } while (state->split_start > 0); |
3713b4e3 | 1829 | break; |
55682965 | 1830 | } |
5fe231e8 | 1831 | rtnl_unlock(); |
55682965 | 1832 | |
86e8cf98 | 1833 | state->start = idx; |
55682965 JB |
1834 | |
1835 | return skb->len; | |
1836 | } | |
1837 | ||
86e8cf98 JB |
1838 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1839 | { | |
1840 | kfree((void *)cb->args[0]); | |
1841 | return 0; | |
1842 | } | |
1843 | ||
55682965 JB |
1844 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1845 | { | |
1846 | struct sk_buff *msg; | |
1b8ec87a | 1847 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 1848 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1849 | |
645e77de | 1850 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1851 | if (!msg) |
4c476991 | 1852 | return -ENOMEM; |
55682965 | 1853 | |
3bb20556 JB |
1854 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
1855 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 1856 | &state) < 0) { |
4c476991 JB |
1857 | nlmsg_free(msg); |
1858 | return -ENOBUFS; | |
1859 | } | |
55682965 | 1860 | |
134e6375 | 1861 | return genlmsg_reply(msg, info); |
55682965 JB |
1862 | } |
1863 | ||
31888487 JM |
1864 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1865 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1866 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1867 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1868 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1869 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1870 | }; | |
1871 | ||
1872 | static int parse_txq_params(struct nlattr *tb[], | |
1873 | struct ieee80211_txq_params *txq_params) | |
1874 | { | |
a3304b0a | 1875 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1876 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1877 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1878 | return -EINVAL; | |
1879 | ||
a3304b0a | 1880 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1881 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1882 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1883 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1884 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1885 | ||
a3304b0a JB |
1886 | if (txq_params->ac >= NL80211_NUM_ACS) |
1887 | return -EINVAL; | |
1888 | ||
31888487 JM |
1889 | return 0; |
1890 | } | |
1891 | ||
f444de05 JB |
1892 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1893 | { | |
1894 | /* | |
cc1d2806 JB |
1895 | * You can only set the channel explicitly for WDS interfaces, |
1896 | * all others have their channel managed via their respective | |
1897 | * "establish a connection" command (connect, join, ...) | |
1898 | * | |
1899 | * For AP/GO and mesh mode, the channel can be set with the | |
1900 | * channel userspace API, but is only stored and passed to the | |
1901 | * low-level driver when the AP starts or the mesh is joined. | |
1902 | * This is for backward compatibility, userspace can also give | |
1903 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1904 | * |
1905 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1906 | * whatever else is going on, so they have their own special |
1907 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1908 | */ |
1909 | return !wdev || | |
1910 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1911 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1912 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1913 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1914 | } |
1915 | ||
683b6d3b JB |
1916 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1917 | struct genl_info *info, | |
1918 | struct cfg80211_chan_def *chandef) | |
1919 | { | |
dbeca2ea | 1920 | u32 control_freq; |
683b6d3b JB |
1921 | |
1922 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1923 | return -EINVAL; | |
1924 | ||
1925 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1926 | ||
1927 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1928 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1929 | chandef->center_freq1 = control_freq; | |
1930 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1931 | |
1932 | /* Primary channel not allowed */ | |
1933 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1934 | return -EINVAL; | |
1935 | ||
3d9d1d66 JB |
1936 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1937 | enum nl80211_channel_type chantype; | |
1938 | ||
1939 | chantype = nla_get_u32( | |
1940 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1941 | ||
1942 | switch (chantype) { | |
1943 | case NL80211_CHAN_NO_HT: | |
1944 | case NL80211_CHAN_HT20: | |
1945 | case NL80211_CHAN_HT40PLUS: | |
1946 | case NL80211_CHAN_HT40MINUS: | |
1947 | cfg80211_chandef_create(chandef, chandef->chan, | |
1948 | chantype); | |
1949 | break; | |
1950 | default: | |
1951 | return -EINVAL; | |
1952 | } | |
1953 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1954 | chandef->width = | |
1955 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1956 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1957 | chandef->center_freq1 = | |
1958 | nla_get_u32( | |
1959 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1960 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1961 | chandef->center_freq2 = | |
1962 | nla_get_u32( | |
1963 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1964 | } | |
1965 | ||
9f5e8f6e | 1966 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1967 | return -EINVAL; |
1968 | ||
9f5e8f6e JB |
1969 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1970 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1971 | return -EINVAL; |
1972 | ||
2f301ab2 SW |
1973 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1974 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1975 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1976 | return -EINVAL; | |
1977 | ||
683b6d3b JB |
1978 | return 0; |
1979 | } | |
1980 | ||
f444de05 | 1981 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 1982 | struct net_device *dev, |
f444de05 JB |
1983 | struct genl_info *info) |
1984 | { | |
683b6d3b | 1985 | struct cfg80211_chan_def chandef; |
f444de05 | 1986 | int result; |
e8c9bd5b | 1987 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 1988 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 1989 | |
e16821bc JM |
1990 | if (dev) |
1991 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
1992 | if (!nl80211_can_set_dev_channel(wdev)) |
1993 | return -EOPNOTSUPP; | |
e16821bc JM |
1994 | if (wdev) |
1995 | iftype = wdev->iftype; | |
f444de05 | 1996 | |
683b6d3b JB |
1997 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1998 | if (result) | |
1999 | return result; | |
f444de05 | 2000 | |
e8c9bd5b | 2001 | switch (iftype) { |
aa430da4 JB |
2002 | case NL80211_IFTYPE_AP: |
2003 | case NL80211_IFTYPE_P2P_GO: | |
174e0cd2 | 2004 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
aa430da4 JB |
2005 | result = -EINVAL; |
2006 | break; | |
2007 | } | |
e16821bc JM |
2008 | if (wdev->beacon_interval) { |
2009 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
2010 | !(rdev->wiphy.features & | |
2011 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
2012 | result = -EBUSY; | |
2013 | break; | |
2014 | } | |
2015 | ||
2016 | /* Only allow dynamic channel width changes */ | |
2017 | if (chandef.chan != wdev->preset_chandef.chan) { | |
2018 | result = -EBUSY; | |
2019 | break; | |
2020 | } | |
2021 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
2022 | if (result) | |
2023 | break; | |
2024 | } | |
683b6d3b | 2025 | wdev->preset_chandef = chandef; |
aa430da4 JB |
2026 | result = 0; |
2027 | break; | |
cc1d2806 | 2028 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 2029 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 2030 | break; |
e8c9bd5b | 2031 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 2032 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 2033 | break; |
aa430da4 | 2034 | default: |
e8c9bd5b | 2035 | result = -EINVAL; |
f444de05 | 2036 | } |
f444de05 JB |
2037 | |
2038 | return result; | |
2039 | } | |
2040 | ||
2041 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2042 | { | |
4c476991 JB |
2043 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2044 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2045 | |
e16821bc | 2046 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2047 | } |
2048 | ||
e8347eba BJ |
2049 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2050 | { | |
43b19952 JB |
2051 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2052 | struct net_device *dev = info->user_ptr[1]; | |
2053 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2054 | const u8 *bssid; |
e8347eba BJ |
2055 | |
2056 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2057 | return -EINVAL; | |
2058 | ||
43b19952 JB |
2059 | if (netif_running(dev)) |
2060 | return -EBUSY; | |
e8347eba | 2061 | |
43b19952 JB |
2062 | if (!rdev->ops->set_wds_peer) |
2063 | return -EOPNOTSUPP; | |
e8347eba | 2064 | |
43b19952 JB |
2065 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2066 | return -EOPNOTSUPP; | |
e8347eba BJ |
2067 | |
2068 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2069 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2070 | } |
2071 | ||
2072 | ||
55682965 JB |
2073 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2074 | { | |
2075 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2076 | struct net_device *netdev = NULL; |
2077 | struct wireless_dev *wdev; | |
a1e567c8 | 2078 | int result = 0, rem_txq_params = 0; |
31888487 | 2079 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2080 | u32 changed; |
2081 | u8 retry_short = 0, retry_long = 0; | |
2082 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2083 | u8 coverage_class = 0; |
55682965 | 2084 | |
5fe231e8 JB |
2085 | ASSERT_RTNL(); |
2086 | ||
f444de05 JB |
2087 | /* |
2088 | * Try to find the wiphy and netdev. Normally this | |
2089 | * function shouldn't need the netdev, but this is | |
2090 | * done for backward compatibility -- previously | |
2091 | * setting the channel was done per wiphy, but now | |
2092 | * it is per netdev. Previous userland like hostapd | |
2093 | * also passed a netdev to set_wiphy, so that it is | |
2094 | * possible to let that go to the right netdev! | |
2095 | */ | |
4bbf4d56 | 2096 | |
f444de05 JB |
2097 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2098 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2099 | ||
7f2b8562 | 2100 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2101 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2102 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2103 | else |
f444de05 | 2104 | netdev = NULL; |
4bbf4d56 JB |
2105 | } |
2106 | ||
f444de05 | 2107 | if (!netdev) { |
878d9ec7 JB |
2108 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2109 | info->attrs); | |
5fe231e8 | 2110 | if (IS_ERR(rdev)) |
4c476991 | 2111 | return PTR_ERR(rdev); |
f444de05 JB |
2112 | wdev = NULL; |
2113 | netdev = NULL; | |
2114 | result = 0; | |
71fe96bf | 2115 | } else |
f444de05 | 2116 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2117 | |
2118 | /* | |
2119 | * end workaround code, by now the rdev is available | |
2120 | * and locked, and wdev may or may not be NULL. | |
2121 | */ | |
4bbf4d56 JB |
2122 | |
2123 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2124 | result = cfg80211_dev_rename( |
2125 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2126 | |
4bbf4d56 | 2127 | if (result) |
7f2b8562 | 2128 | return result; |
31888487 JM |
2129 | |
2130 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2131 | struct ieee80211_txq_params txq_params; | |
2132 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2133 | ||
7f2b8562 YX |
2134 | if (!rdev->ops->set_txq_params) |
2135 | return -EOPNOTSUPP; | |
31888487 | 2136 | |
7f2b8562 YX |
2137 | if (!netdev) |
2138 | return -EINVAL; | |
f70f01c2 | 2139 | |
133a3ff2 | 2140 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2141 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2142 | return -EINVAL; | |
133a3ff2 | 2143 | |
7f2b8562 YX |
2144 | if (!netif_running(netdev)) |
2145 | return -ENETDOWN; | |
2b5f8b0b | 2146 | |
31888487 JM |
2147 | nla_for_each_nested(nl_txq_params, |
2148 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2149 | rem_txq_params) { | |
ae811e21 JB |
2150 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2151 | nla_data(nl_txq_params), | |
2152 | nla_len(nl_txq_params), | |
2153 | txq_params_policy); | |
2154 | if (result) | |
2155 | return result; | |
31888487 JM |
2156 | result = parse_txq_params(tb, &txq_params); |
2157 | if (result) | |
7f2b8562 | 2158 | return result; |
31888487 | 2159 | |
e35e4d28 HG |
2160 | result = rdev_set_txq_params(rdev, netdev, |
2161 | &txq_params); | |
31888487 | 2162 | if (result) |
7f2b8562 | 2163 | return result; |
31888487 JM |
2164 | } |
2165 | } | |
55682965 | 2166 | |
72bdcf34 | 2167 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2168 | result = __nl80211_set_channel( |
2169 | rdev, | |
2170 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2171 | info); | |
72bdcf34 | 2172 | if (result) |
7f2b8562 | 2173 | return result; |
72bdcf34 JM |
2174 | } |
2175 | ||
98d2ff8b | 2176 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2177 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2178 | enum nl80211_tx_power_setting type; |
2179 | int idx, mbm = 0; | |
2180 | ||
c8442118 JB |
2181 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2182 | txp_wdev = NULL; | |
2183 | ||
7f2b8562 YX |
2184 | if (!rdev->ops->set_tx_power) |
2185 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2186 | |
2187 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2188 | type = nla_get_u32(info->attrs[idx]); | |
2189 | ||
2190 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2191 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2192 | return -EINVAL; | |
98d2ff8b JO |
2193 | |
2194 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2195 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2196 | mbm = nla_get_u32(info->attrs[idx]); | |
2197 | } | |
2198 | ||
c8442118 | 2199 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2200 | if (result) |
7f2b8562 | 2201 | return result; |
98d2ff8b JO |
2202 | } |
2203 | ||
afe0cbf8 BR |
2204 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2205 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2206 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2207 | if ((!rdev->wiphy.available_antennas_tx && |
2208 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2209 | !rdev->ops->set_antenna) |
2210 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2211 | |
2212 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2213 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2214 | ||
a7ffac95 | 2215 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2216 | * available antenna masks, except for the "all" mask */ |
2217 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2218 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2219 | return -EINVAL; | |
a7ffac95 | 2220 | |
7f531e03 BR |
2221 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2222 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2223 | |
e35e4d28 | 2224 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2225 | if (result) |
7f2b8562 | 2226 | return result; |
afe0cbf8 BR |
2227 | } |
2228 | ||
b9a5f8ca JM |
2229 | changed = 0; |
2230 | ||
2231 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2232 | retry_short = nla_get_u8( | |
2233 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2234 | if (retry_short == 0) |
2235 | return -EINVAL; | |
2236 | ||
b9a5f8ca JM |
2237 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2238 | } | |
2239 | ||
2240 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2241 | retry_long = nla_get_u8( | |
2242 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2243 | if (retry_long == 0) |
2244 | return -EINVAL; | |
2245 | ||
b9a5f8ca JM |
2246 | changed |= WIPHY_PARAM_RETRY_LONG; |
2247 | } | |
2248 | ||
2249 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2250 | frag_threshold = nla_get_u32( | |
2251 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2252 | if (frag_threshold < 256) |
2253 | return -EINVAL; | |
2254 | ||
b9a5f8ca JM |
2255 | if (frag_threshold != (u32) -1) { |
2256 | /* | |
2257 | * Fragments (apart from the last one) are required to | |
2258 | * have even length. Make the fragmentation code | |
2259 | * simpler by stripping LSB should someone try to use | |
2260 | * odd threshold value. | |
2261 | */ | |
2262 | frag_threshold &= ~0x1; | |
2263 | } | |
2264 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2265 | } | |
2266 | ||
2267 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2268 | rts_threshold = nla_get_u32( | |
2269 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2270 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2271 | } | |
2272 | ||
81077e82 | 2273 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
3057dbfd LB |
2274 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
2275 | return -EINVAL; | |
2276 | ||
81077e82 LT |
2277 | coverage_class = nla_get_u8( |
2278 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2279 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2280 | } | |
2281 | ||
3057dbfd LB |
2282 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
2283 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | |
2284 | return -EOPNOTSUPP; | |
2285 | ||
2286 | changed |= WIPHY_PARAM_DYN_ACK; | |
81077e82 LT |
2287 | } |
2288 | ||
b9a5f8ca JM |
2289 | if (changed) { |
2290 | u8 old_retry_short, old_retry_long; | |
2291 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2292 | u8 old_coverage_class; |
b9a5f8ca | 2293 | |
7f2b8562 YX |
2294 | if (!rdev->ops->set_wiphy_params) |
2295 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2296 | |
2297 | old_retry_short = rdev->wiphy.retry_short; | |
2298 | old_retry_long = rdev->wiphy.retry_long; | |
2299 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2300 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2301 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2302 | |
2303 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2304 | rdev->wiphy.retry_short = retry_short; | |
2305 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2306 | rdev->wiphy.retry_long = retry_long; | |
2307 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2308 | rdev->wiphy.frag_threshold = frag_threshold; | |
2309 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2310 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2311 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2312 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2313 | |
e35e4d28 | 2314 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2315 | if (result) { |
2316 | rdev->wiphy.retry_short = old_retry_short; | |
2317 | rdev->wiphy.retry_long = old_retry_long; | |
2318 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2319 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2320 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2321 | } |
2322 | } | |
7f2b8562 | 2323 | return 0; |
55682965 JB |
2324 | } |
2325 | ||
71bbc994 JB |
2326 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2327 | { | |
2328 | return (u64)wdev->identifier | | |
f26cbf40 | 2329 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2330 | } |
55682965 | 2331 | |
683b6d3b | 2332 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2333 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2334 | { |
601555cd JB |
2335 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
2336 | return -EINVAL; | |
3d9d1d66 | 2337 | |
683b6d3b JB |
2338 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2339 | chandef->chan->center_freq)) | |
2340 | return -ENOBUFS; | |
3d9d1d66 JB |
2341 | switch (chandef->width) { |
2342 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2343 | case NL80211_CHAN_WIDTH_20: | |
2344 | case NL80211_CHAN_WIDTH_40: | |
2345 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2346 | cfg80211_get_chandef_type(chandef))) | |
2347 | return -ENOBUFS; | |
2348 | break; | |
2349 | default: | |
2350 | break; | |
2351 | } | |
2352 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2353 | return -ENOBUFS; | |
2354 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2355 | return -ENOBUFS; | |
2356 | if (chandef->center_freq2 && | |
2357 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2358 | return -ENOBUFS; |
2359 | return 0; | |
2360 | } | |
2361 | ||
15e47304 | 2362 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2363 | struct cfg80211_registered_device *rdev, |
8f894be2 | 2364 | struct wireless_dev *wdev, bool removal) |
55682965 | 2365 | { |
72fb2abc | 2366 | struct net_device *dev = wdev->netdev; |
8f894be2 | 2367 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
55682965 JB |
2368 | void *hdr; |
2369 | ||
8f894be2 TB |
2370 | if (removal) |
2371 | cmd = NL80211_CMD_DEL_INTERFACE; | |
2372 | ||
2373 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | |
55682965 JB |
2374 | if (!hdr) |
2375 | return -1; | |
2376 | ||
72fb2abc JB |
2377 | if (dev && |
2378 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2379 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2380 | goto nla_put_failure; |
2381 | ||
2382 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2383 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2384 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2385 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2386 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2387 | rdev->devlist_generation ^ | |
2388 | (cfg80211_rdev_list_generation << 2))) | |
2389 | goto nla_put_failure; | |
f5ea9120 | 2390 | |
5b7ccaf3 | 2391 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2392 | int ret; |
2393 | struct cfg80211_chan_def chandef; | |
2394 | ||
2395 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2396 | if (ret == 0) { | |
2397 | if (nl80211_send_chandef(msg, &chandef)) | |
2398 | goto nla_put_failure; | |
2399 | } | |
d91df0e3 PF |
2400 | } |
2401 | ||
b84e7a05 AQ |
2402 | if (wdev->ssid_len) { |
2403 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2404 | goto nla_put_failure; | |
2405 | } | |
2406 | ||
55682965 JB |
2407 | return genlmsg_end(msg, hdr); |
2408 | ||
2409 | nla_put_failure: | |
bc3ed28c TG |
2410 | genlmsg_cancel(msg, hdr); |
2411 | return -EMSGSIZE; | |
55682965 JB |
2412 | } |
2413 | ||
2414 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2415 | { | |
2416 | int wp_idx = 0; | |
2417 | int if_idx = 0; | |
2418 | int wp_start = cb->args[0]; | |
2419 | int if_start = cb->args[1]; | |
f5ea9120 | 2420 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2421 | struct wireless_dev *wdev; |
2422 | ||
5fe231e8 | 2423 | rtnl_lock(); |
f5ea9120 JB |
2424 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2425 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2426 | continue; |
bba95fef JB |
2427 | if (wp_idx < wp_start) { |
2428 | wp_idx++; | |
55682965 | 2429 | continue; |
bba95fef | 2430 | } |
55682965 JB |
2431 | if_idx = 0; |
2432 | ||
89a54e48 | 2433 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2434 | if (if_idx < if_start) { |
2435 | if_idx++; | |
55682965 | 2436 | continue; |
bba95fef | 2437 | } |
15e47304 | 2438 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2439 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
8f894be2 | 2440 | rdev, wdev, false) < 0) { |
bba95fef JB |
2441 | goto out; |
2442 | } | |
2443 | if_idx++; | |
55682965 | 2444 | } |
bba95fef JB |
2445 | |
2446 | wp_idx++; | |
55682965 | 2447 | } |
bba95fef | 2448 | out: |
5fe231e8 | 2449 | rtnl_unlock(); |
55682965 JB |
2450 | |
2451 | cb->args[0] = wp_idx; | |
2452 | cb->args[1] = if_idx; | |
2453 | ||
2454 | return skb->len; | |
2455 | } | |
2456 | ||
2457 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2458 | { | |
2459 | struct sk_buff *msg; | |
1b8ec87a | 2460 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2461 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2462 | |
fd2120ca | 2463 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2464 | if (!msg) |
4c476991 | 2465 | return -ENOMEM; |
55682965 | 2466 | |
15e47304 | 2467 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2468 | rdev, wdev, false) < 0) { |
4c476991 JB |
2469 | nlmsg_free(msg); |
2470 | return -ENOBUFS; | |
2471 | } | |
55682965 | 2472 | |
134e6375 | 2473 | return genlmsg_reply(msg, info); |
55682965 JB |
2474 | } |
2475 | ||
66f7ac50 MW |
2476 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2477 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2478 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2479 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2480 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2481 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2482 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2483 | }; |
2484 | ||
2485 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2486 | { | |
2487 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2488 | int flag; | |
2489 | ||
2490 | *mntrflags = 0; | |
2491 | ||
2492 | if (!nla) | |
2493 | return -EINVAL; | |
2494 | ||
2495 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2496 | nla, mntr_flags_policy)) | |
2497 | return -EINVAL; | |
2498 | ||
2499 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2500 | if (flags[flag]) | |
2501 | *mntrflags |= (1<<flag); | |
2502 | ||
2503 | return 0; | |
2504 | } | |
2505 | ||
9bc383de | 2506 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2507 | struct net_device *netdev, u8 use_4addr, |
2508 | enum nl80211_iftype iftype) | |
9bc383de | 2509 | { |
ad4bb6f8 | 2510 | if (!use_4addr) { |
f350a0a8 | 2511 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2512 | return -EBUSY; |
9bc383de | 2513 | return 0; |
ad4bb6f8 | 2514 | } |
9bc383de JB |
2515 | |
2516 | switch (iftype) { | |
2517 | case NL80211_IFTYPE_AP_VLAN: | |
2518 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2519 | return 0; | |
2520 | break; | |
2521 | case NL80211_IFTYPE_STATION: | |
2522 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2523 | return 0; | |
2524 | break; | |
2525 | default: | |
2526 | break; | |
2527 | } | |
2528 | ||
2529 | return -EOPNOTSUPP; | |
2530 | } | |
2531 | ||
55682965 JB |
2532 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2533 | { | |
4c476991 | 2534 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2535 | struct vif_params params; |
e36d56b6 | 2536 | int err; |
04a773ad | 2537 | enum nl80211_iftype otype, ntype; |
4c476991 | 2538 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2539 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2540 | bool change = false; |
55682965 | 2541 | |
2ec600d6 LCC |
2542 | memset(¶ms, 0, sizeof(params)); |
2543 | ||
04a773ad | 2544 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2545 | |
723b038d | 2546 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2547 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2548 | if (otype != ntype) |
ac7f9cfa | 2549 | change = true; |
4c476991 JB |
2550 | if (ntype > NL80211_IFTYPE_MAX) |
2551 | return -EINVAL; | |
723b038d JB |
2552 | } |
2553 | ||
92ffe055 | 2554 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2555 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2556 | ||
4c476991 JB |
2557 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2558 | return -EINVAL; | |
29cbe68c JB |
2559 | if (netif_running(dev)) |
2560 | return -EBUSY; | |
2561 | ||
2562 | wdev_lock(wdev); | |
2563 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2564 | IEEE80211_MAX_MESH_ID_LEN); | |
2565 | wdev->mesh_id_up_len = | |
2566 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2567 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2568 | wdev->mesh_id_up_len); | |
2569 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2570 | } |
2571 | ||
8b787643 FF |
2572 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2573 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2574 | change = true; | |
ad4bb6f8 | 2575 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2576 | if (err) |
4c476991 | 2577 | return err; |
8b787643 FF |
2578 | } else { |
2579 | params.use_4addr = -1; | |
2580 | } | |
2581 | ||
92ffe055 | 2582 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2583 | if (ntype != NL80211_IFTYPE_MONITOR) |
2584 | return -EINVAL; | |
92ffe055 JB |
2585 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2586 | &_flags); | |
ac7f9cfa | 2587 | if (err) |
4c476991 | 2588 | return err; |
ac7f9cfa JB |
2589 | |
2590 | flags = &_flags; | |
2591 | change = true; | |
92ffe055 | 2592 | } |
3b85875a | 2593 | |
18003297 | 2594 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2595 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2596 | return -EOPNOTSUPP; | |
2597 | ||
ac7f9cfa | 2598 | if (change) |
3d54d255 | 2599 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2600 | else |
2601 | err = 0; | |
60719ffd | 2602 | |
9bc383de JB |
2603 | if (!err && params.use_4addr != -1) |
2604 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2605 | ||
55682965 JB |
2606 | return err; |
2607 | } | |
2608 | ||
2609 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2610 | { | |
4c476991 | 2611 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2612 | struct vif_params params; |
84efbb84 | 2613 | struct wireless_dev *wdev; |
8f894be2 | 2614 | struct sk_buff *msg, *event; |
55682965 JB |
2615 | int err; |
2616 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2617 | u32 flags; |
55682965 | 2618 | |
78f22b6a JB |
2619 | /* to avoid failing a new interface creation due to pending removal */ |
2620 | cfg80211_destroy_ifaces(rdev); | |
2621 | ||
2ec600d6 LCC |
2622 | memset(¶ms, 0, sizeof(params)); |
2623 | ||
55682965 JB |
2624 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2625 | return -EINVAL; | |
2626 | ||
2627 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2628 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2629 | if (type > NL80211_IFTYPE_MAX) | |
2630 | return -EINVAL; | |
2631 | } | |
2632 | ||
79c97e97 | 2633 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2634 | !(rdev->wiphy.interface_modes & (1 << type))) |
2635 | return -EOPNOTSUPP; | |
55682965 | 2636 | |
e8f479b1 BG |
2637 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
2638 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && | |
2639 | info->attrs[NL80211_ATTR_MAC]) { | |
1c18f145 AS |
2640 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
2641 | ETH_ALEN); | |
2642 | if (!is_valid_ether_addr(params.macaddr)) | |
2643 | return -EADDRNOTAVAIL; | |
2644 | } | |
2645 | ||
9bc383de | 2646 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2647 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2648 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2649 | if (err) |
4c476991 | 2650 | return err; |
9bc383de | 2651 | } |
8b787643 | 2652 | |
1c90f9d4 JB |
2653 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2654 | if (!msg) | |
2655 | return -ENOMEM; | |
2656 | ||
66f7ac50 MW |
2657 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2658 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2659 | &flags); | |
e057d3c3 | 2660 | |
18003297 | 2661 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2662 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2663 | return -EOPNOTSUPP; | |
2664 | ||
e35e4d28 HG |
2665 | wdev = rdev_add_virtual_intf(rdev, |
2666 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2667 | type, err ? NULL : &flags, ¶ms); | |
d687cbb7 RM |
2668 | if (WARN_ON(!wdev)) { |
2669 | nlmsg_free(msg); | |
2670 | return -EPROTO; | |
2671 | } else if (IS_ERR(wdev)) { | |
1c90f9d4 | 2672 | nlmsg_free(msg); |
84efbb84 | 2673 | return PTR_ERR(wdev); |
1c90f9d4 | 2674 | } |
2ec600d6 | 2675 | |
18e5ca65 | 2676 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
78f22b6a JB |
2677 | wdev->owner_nlportid = info->snd_portid; |
2678 | ||
98104fde JB |
2679 | switch (type) { |
2680 | case NL80211_IFTYPE_MESH_POINT: | |
2681 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2682 | break; | |
29cbe68c JB |
2683 | wdev_lock(wdev); |
2684 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2685 | IEEE80211_MAX_MESH_ID_LEN); | |
2686 | wdev->mesh_id_up_len = | |
2687 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2688 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2689 | wdev->mesh_id_up_len); | |
2690 | wdev_unlock(wdev); | |
98104fde JB |
2691 | break; |
2692 | case NL80211_IFTYPE_P2P_DEVICE: | |
2693 | /* | |
2694 | * P2P Device doesn't have a netdev, so doesn't go | |
2695 | * through the netdev notifier and must be added here | |
2696 | */ | |
2697 | mutex_init(&wdev->mtx); | |
2698 | INIT_LIST_HEAD(&wdev->event_list); | |
2699 | spin_lock_init(&wdev->event_lock); | |
2700 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2701 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2702 | ||
98104fde JB |
2703 | wdev->identifier = ++rdev->wdev_id; |
2704 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2705 | rdev->devlist_generation++; | |
98104fde JB |
2706 | break; |
2707 | default: | |
2708 | break; | |
29cbe68c JB |
2709 | } |
2710 | ||
15e47304 | 2711 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2712 | rdev, wdev, false) < 0) { |
1c90f9d4 JB |
2713 | nlmsg_free(msg); |
2714 | return -ENOBUFS; | |
2715 | } | |
2716 | ||
8f894be2 TB |
2717 | event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2718 | if (event) { | |
2719 | if (nl80211_send_iface(event, 0, 0, 0, | |
2720 | rdev, wdev, false) < 0) { | |
2721 | nlmsg_free(event); | |
2722 | goto out; | |
2723 | } | |
2724 | ||
2725 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
2726 | event, 0, NL80211_MCGRP_CONFIG, | |
2727 | GFP_KERNEL); | |
2728 | } | |
2729 | ||
2730 | out: | |
1c90f9d4 | 2731 | return genlmsg_reply(msg, info); |
55682965 JB |
2732 | } |
2733 | ||
2734 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2735 | { | |
4c476991 | 2736 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2737 | struct wireless_dev *wdev = info->user_ptr[1]; |
8f894be2 TB |
2738 | struct sk_buff *msg; |
2739 | int status; | |
55682965 | 2740 | |
4c476991 JB |
2741 | if (!rdev->ops->del_virtual_intf) |
2742 | return -EOPNOTSUPP; | |
55682965 | 2743 | |
8f894be2 TB |
2744 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2745 | if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) { | |
2746 | nlmsg_free(msg); | |
2747 | msg = NULL; | |
2748 | } | |
2749 | ||
84efbb84 JB |
2750 | /* |
2751 | * If we remove a wireless device without a netdev then clear | |
2752 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2753 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2754 | * since the wdev has been freed, unlike with a netdev where | |
2755 | * we need the dev_put() for the netdev to really be freed. | |
2756 | */ | |
2757 | if (!wdev->netdev) | |
2758 | info->user_ptr[1] = NULL; | |
2759 | ||
8f894be2 TB |
2760 | status = rdev_del_virtual_intf(rdev, wdev); |
2761 | if (status >= 0 && msg) | |
2762 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
2763 | msg, 0, NL80211_MCGRP_CONFIG, | |
2764 | GFP_KERNEL); | |
2765 | else | |
2766 | nlmsg_free(msg); | |
2767 | ||
2768 | return status; | |
55682965 JB |
2769 | } |
2770 | ||
1d9d9213 SW |
2771 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2772 | { | |
2773 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2774 | struct net_device *dev = info->user_ptr[1]; | |
2775 | u16 noack_map; | |
2776 | ||
2777 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2778 | return -EINVAL; | |
2779 | ||
2780 | if (!rdev->ops->set_noack_map) | |
2781 | return -EOPNOTSUPP; | |
2782 | ||
2783 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2784 | ||
e35e4d28 | 2785 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2786 | } |
2787 | ||
41ade00f JB |
2788 | struct get_key_cookie { |
2789 | struct sk_buff *msg; | |
2790 | int error; | |
b9454e83 | 2791 | int idx; |
41ade00f JB |
2792 | }; |
2793 | ||
2794 | static void get_key_callback(void *c, struct key_params *params) | |
2795 | { | |
b9454e83 | 2796 | struct nlattr *key; |
41ade00f JB |
2797 | struct get_key_cookie *cookie = c; |
2798 | ||
9360ffd1 DM |
2799 | if ((params->key && |
2800 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2801 | params->key_len, params->key)) || | |
2802 | (params->seq && | |
2803 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2804 | params->seq_len, params->seq)) || | |
2805 | (params->cipher && | |
2806 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2807 | params->cipher))) | |
2808 | goto nla_put_failure; | |
41ade00f | 2809 | |
b9454e83 JB |
2810 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2811 | if (!key) | |
2812 | goto nla_put_failure; | |
2813 | ||
9360ffd1 DM |
2814 | if ((params->key && |
2815 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2816 | params->key_len, params->key)) || | |
2817 | (params->seq && | |
2818 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2819 | params->seq_len, params->seq)) || | |
2820 | (params->cipher && | |
2821 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2822 | params->cipher))) | |
2823 | goto nla_put_failure; | |
b9454e83 | 2824 | |
9360ffd1 DM |
2825 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2826 | goto nla_put_failure; | |
b9454e83 JB |
2827 | |
2828 | nla_nest_end(cookie->msg, key); | |
2829 | ||
41ade00f JB |
2830 | return; |
2831 | nla_put_failure: | |
2832 | cookie->error = 1; | |
2833 | } | |
2834 | ||
2835 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2836 | { | |
4c476991 | 2837 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2838 | int err; |
4c476991 | 2839 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2840 | u8 key_idx = 0; |
e31b8213 JB |
2841 | const u8 *mac_addr = NULL; |
2842 | bool pairwise; | |
41ade00f JB |
2843 | struct get_key_cookie cookie = { |
2844 | .error = 0, | |
2845 | }; | |
2846 | void *hdr; | |
2847 | struct sk_buff *msg; | |
2848 | ||
2849 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2850 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2851 | ||
3cfcf6ac | 2852 | if (key_idx > 5) |
41ade00f JB |
2853 | return -EINVAL; |
2854 | ||
2855 | if (info->attrs[NL80211_ATTR_MAC]) | |
2856 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2857 | ||
e31b8213 JB |
2858 | pairwise = !!mac_addr; |
2859 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2860 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2861 | if (kt >= NUM_NL80211_KEYTYPES) | |
2862 | return -EINVAL; | |
2863 | if (kt != NL80211_KEYTYPE_GROUP && | |
2864 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2865 | return -EINVAL; | |
2866 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2867 | } | |
2868 | ||
4c476991 JB |
2869 | if (!rdev->ops->get_key) |
2870 | return -EOPNOTSUPP; | |
41ade00f | 2871 | |
fd2120ca | 2872 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2873 | if (!msg) |
2874 | return -ENOMEM; | |
41ade00f | 2875 | |
15e47304 | 2876 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2877 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 2878 | if (!hdr) |
9fe271af | 2879 | goto nla_put_failure; |
41ade00f JB |
2880 | |
2881 | cookie.msg = msg; | |
b9454e83 | 2882 | cookie.idx = key_idx; |
41ade00f | 2883 | |
9360ffd1 DM |
2884 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2885 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2886 | goto nla_put_failure; | |
2887 | if (mac_addr && | |
2888 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2889 | goto nla_put_failure; | |
41ade00f | 2890 | |
e31b8213 JB |
2891 | if (pairwise && mac_addr && |
2892 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2893 | return -ENOENT; | |
2894 | ||
e35e4d28 HG |
2895 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2896 | get_key_callback); | |
41ade00f JB |
2897 | |
2898 | if (err) | |
6c95e2a2 | 2899 | goto free_msg; |
41ade00f JB |
2900 | |
2901 | if (cookie.error) | |
2902 | goto nla_put_failure; | |
2903 | ||
2904 | genlmsg_end(msg, hdr); | |
4c476991 | 2905 | return genlmsg_reply(msg, info); |
41ade00f JB |
2906 | |
2907 | nla_put_failure: | |
2908 | err = -ENOBUFS; | |
6c95e2a2 | 2909 | free_msg: |
41ade00f | 2910 | nlmsg_free(msg); |
41ade00f JB |
2911 | return err; |
2912 | } | |
2913 | ||
2914 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2915 | { | |
4c476991 | 2916 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2917 | struct key_parse key; |
41ade00f | 2918 | int err; |
4c476991 | 2919 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2920 | |
b9454e83 JB |
2921 | err = nl80211_parse_key(info, &key); |
2922 | if (err) | |
2923 | return err; | |
41ade00f | 2924 | |
b9454e83 | 2925 | if (key.idx < 0) |
41ade00f JB |
2926 | return -EINVAL; |
2927 | ||
b9454e83 JB |
2928 | /* only support setting default key */ |
2929 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2930 | return -EINVAL; |
2931 | ||
dbd2fd65 | 2932 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2933 | |
dbd2fd65 JB |
2934 | if (key.def) { |
2935 | if (!rdev->ops->set_default_key) { | |
2936 | err = -EOPNOTSUPP; | |
2937 | goto out; | |
2938 | } | |
41ade00f | 2939 | |
dbd2fd65 JB |
2940 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2941 | if (err) | |
2942 | goto out; | |
2943 | ||
e35e4d28 | 2944 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2945 | key.def_uni, key.def_multi); |
2946 | ||
2947 | if (err) | |
2948 | goto out; | |
fffd0934 | 2949 | |
3d23e349 | 2950 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2951 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2952 | #endif | |
2953 | } else { | |
2954 | if (key.def_uni || !key.def_multi) { | |
2955 | err = -EINVAL; | |
2956 | goto out; | |
2957 | } | |
2958 | ||
2959 | if (!rdev->ops->set_default_mgmt_key) { | |
2960 | err = -EOPNOTSUPP; | |
2961 | goto out; | |
2962 | } | |
2963 | ||
2964 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2965 | if (err) | |
2966 | goto out; | |
2967 | ||
e35e4d28 | 2968 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2969 | if (err) |
2970 | goto out; | |
2971 | ||
2972 | #ifdef CONFIG_CFG80211_WEXT | |
2973 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2974 | #endif |
dbd2fd65 JB |
2975 | } |
2976 | ||
2977 | out: | |
fffd0934 | 2978 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2979 | |
41ade00f JB |
2980 | return err; |
2981 | } | |
2982 | ||
2983 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2984 | { | |
4c476991 | 2985 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2986 | int err; |
4c476991 | 2987 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2988 | struct key_parse key; |
e31b8213 | 2989 | const u8 *mac_addr = NULL; |
41ade00f | 2990 | |
b9454e83 JB |
2991 | err = nl80211_parse_key(info, &key); |
2992 | if (err) | |
2993 | return err; | |
41ade00f | 2994 | |
b9454e83 | 2995 | if (!key.p.key) |
41ade00f JB |
2996 | return -EINVAL; |
2997 | ||
41ade00f JB |
2998 | if (info->attrs[NL80211_ATTR_MAC]) |
2999 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3000 | ||
e31b8213 JB |
3001 | if (key.type == -1) { |
3002 | if (mac_addr) | |
3003 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3004 | else | |
3005 | key.type = NL80211_KEYTYPE_GROUP; | |
3006 | } | |
3007 | ||
3008 | /* for now */ | |
3009 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3010 | key.type != NL80211_KEYTYPE_GROUP) | |
3011 | return -EINVAL; | |
3012 | ||
4c476991 JB |
3013 | if (!rdev->ops->add_key) |
3014 | return -EOPNOTSUPP; | |
25e47c18 | 3015 | |
e31b8213 JB |
3016 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
3017 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3018 | mac_addr)) | |
4c476991 | 3019 | return -EINVAL; |
41ade00f | 3020 | |
fffd0934 JB |
3021 | wdev_lock(dev->ieee80211_ptr); |
3022 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3023 | if (!err) | |
e35e4d28 HG |
3024 | err = rdev_add_key(rdev, dev, key.idx, |
3025 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3026 | mac_addr, &key.p); | |
fffd0934 | 3027 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3028 | |
41ade00f JB |
3029 | return err; |
3030 | } | |
3031 | ||
3032 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
3033 | { | |
4c476991 | 3034 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3035 | int err; |
4c476991 | 3036 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3037 | u8 *mac_addr = NULL; |
b9454e83 | 3038 | struct key_parse key; |
41ade00f | 3039 | |
b9454e83 JB |
3040 | err = nl80211_parse_key(info, &key); |
3041 | if (err) | |
3042 | return err; | |
41ade00f JB |
3043 | |
3044 | if (info->attrs[NL80211_ATTR_MAC]) | |
3045 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3046 | ||
e31b8213 JB |
3047 | if (key.type == -1) { |
3048 | if (mac_addr) | |
3049 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3050 | else | |
3051 | key.type = NL80211_KEYTYPE_GROUP; | |
3052 | } | |
3053 | ||
3054 | /* for now */ | |
3055 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3056 | key.type != NL80211_KEYTYPE_GROUP) | |
3057 | return -EINVAL; | |
3058 | ||
4c476991 JB |
3059 | if (!rdev->ops->del_key) |
3060 | return -EOPNOTSUPP; | |
41ade00f | 3061 | |
fffd0934 JB |
3062 | wdev_lock(dev->ieee80211_ptr); |
3063 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
3064 | |
3065 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
3066 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
3067 | err = -ENOENT; | |
3068 | ||
fffd0934 | 3069 | if (!err) |
e35e4d28 HG |
3070 | err = rdev_del_key(rdev, dev, key.idx, |
3071 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3072 | mac_addr); | |
41ade00f | 3073 | |
3d23e349 | 3074 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 3075 | if (!err) { |
b9454e83 | 3076 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 3077 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 3078 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
3079 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
3080 | } | |
3081 | #endif | |
fffd0934 | 3082 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 3083 | |
41ade00f JB |
3084 | return err; |
3085 | } | |
3086 | ||
77765eaf VT |
3087 | /* This function returns an error or the number of nested attributes */ |
3088 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
3089 | { | |
3090 | struct nlattr *attr; | |
3091 | int n_entries = 0, tmp; | |
3092 | ||
3093 | nla_for_each_nested(attr, nl_attr, tmp) { | |
3094 | if (nla_len(attr) != ETH_ALEN) | |
3095 | return -EINVAL; | |
3096 | ||
3097 | n_entries++; | |
3098 | } | |
3099 | ||
3100 | return n_entries; | |
3101 | } | |
3102 | ||
3103 | /* | |
3104 | * This function parses ACL information and allocates memory for ACL data. | |
3105 | * On successful return, the calling function is responsible to free the | |
3106 | * ACL buffer returned by this function. | |
3107 | */ | |
3108 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3109 | struct genl_info *info) | |
3110 | { | |
3111 | enum nl80211_acl_policy acl_policy; | |
3112 | struct nlattr *attr; | |
3113 | struct cfg80211_acl_data *acl; | |
3114 | int i = 0, n_entries, tmp; | |
3115 | ||
3116 | if (!wiphy->max_acl_mac_addrs) | |
3117 | return ERR_PTR(-EOPNOTSUPP); | |
3118 | ||
3119 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3120 | return ERR_PTR(-EINVAL); | |
3121 | ||
3122 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3123 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3124 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3125 | return ERR_PTR(-EINVAL); | |
3126 | ||
3127 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3128 | return ERR_PTR(-EINVAL); | |
3129 | ||
3130 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3131 | if (n_entries < 0) | |
3132 | return ERR_PTR(n_entries); | |
3133 | ||
3134 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3135 | return ERR_PTR(-ENOTSUPP); | |
3136 | ||
3137 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
3138 | GFP_KERNEL); | |
3139 | if (!acl) | |
3140 | return ERR_PTR(-ENOMEM); | |
3141 | ||
3142 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3143 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3144 | i++; | |
3145 | } | |
3146 | ||
3147 | acl->n_acl_entries = n_entries; | |
3148 | acl->acl_policy = acl_policy; | |
3149 | ||
3150 | return acl; | |
3151 | } | |
3152 | ||
3153 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3154 | { | |
3155 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3156 | struct net_device *dev = info->user_ptr[1]; | |
3157 | struct cfg80211_acl_data *acl; | |
3158 | int err; | |
3159 | ||
3160 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3161 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3162 | return -EOPNOTSUPP; | |
3163 | ||
3164 | if (!dev->ieee80211_ptr->beacon_interval) | |
3165 | return -EINVAL; | |
3166 | ||
3167 | acl = parse_acl_data(&rdev->wiphy, info); | |
3168 | if (IS_ERR(acl)) | |
3169 | return PTR_ERR(acl); | |
3170 | ||
3171 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3172 | ||
3173 | kfree(acl); | |
3174 | ||
3175 | return err; | |
3176 | } | |
3177 | ||
a1193be8 | 3178 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3179 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3180 | { |
8860020e | 3181 | bool haveinfo = false; |
ed1b6cc7 | 3182 | |
a1193be8 SW |
3183 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3184 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3185 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3186 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3187 | return -EINVAL; |
3188 | ||
8860020e | 3189 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3190 | |
a1193be8 SW |
3191 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3192 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3193 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3194 | if (!bcn->head_len) |
3195 | return -EINVAL; | |
3196 | haveinfo = true; | |
ed1b6cc7 JB |
3197 | } |
3198 | ||
a1193be8 SW |
3199 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3200 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3201 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3202 | haveinfo = true; |
ed1b6cc7 JB |
3203 | } |
3204 | ||
4c476991 JB |
3205 | if (!haveinfo) |
3206 | return -EINVAL; | |
3b85875a | 3207 | |
a1193be8 SW |
3208 | if (attrs[NL80211_ATTR_IE]) { |
3209 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3210 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3211 | } |
3212 | ||
a1193be8 | 3213 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3214 | bcn->proberesp_ies = |
a1193be8 | 3215 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3216 | bcn->proberesp_ies_len = |
a1193be8 | 3217 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3218 | } |
3219 | ||
a1193be8 | 3220 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3221 | bcn->assocresp_ies = |
a1193be8 | 3222 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3223 | bcn->assocresp_ies_len = |
a1193be8 | 3224 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3225 | } |
3226 | ||
a1193be8 SW |
3227 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3228 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3229 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3230 | } |
3231 | ||
8860020e JB |
3232 | return 0; |
3233 | } | |
3234 | ||
46c1dd0c FF |
3235 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3236 | struct cfg80211_ap_settings *params) | |
3237 | { | |
3238 | struct wireless_dev *wdev; | |
3239 | bool ret = false; | |
3240 | ||
89a54e48 | 3241 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3242 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3243 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3244 | continue; | |
3245 | ||
683b6d3b | 3246 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3247 | continue; |
3248 | ||
683b6d3b | 3249 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3250 | ret = true; |
3251 | break; | |
3252 | } | |
3253 | ||
46c1dd0c FF |
3254 | return ret; |
3255 | } | |
3256 | ||
e39e5b5e JM |
3257 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3258 | enum nl80211_auth_type auth_type, | |
3259 | enum nl80211_commands cmd) | |
3260 | { | |
3261 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3262 | return false; | |
3263 | ||
3264 | switch (cmd) { | |
3265 | case NL80211_CMD_AUTHENTICATE: | |
3266 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3267 | auth_type == NL80211_AUTHTYPE_SAE) | |
3268 | return false; | |
3269 | return true; | |
3270 | case NL80211_CMD_CONNECT: | |
3271 | case NL80211_CMD_START_AP: | |
3272 | /* SAE not supported yet */ | |
3273 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3274 | return false; | |
3275 | return true; | |
3276 | default: | |
3277 | return false; | |
3278 | } | |
3279 | } | |
3280 | ||
8860020e JB |
3281 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3282 | { | |
3283 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3284 | struct net_device *dev = info->user_ptr[1]; | |
3285 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3286 | struct cfg80211_ap_settings params; | |
3287 | int err; | |
3288 | ||
3289 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3290 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3291 | return -EOPNOTSUPP; | |
3292 | ||
3293 | if (!rdev->ops->start_ap) | |
3294 | return -EOPNOTSUPP; | |
3295 | ||
3296 | if (wdev->beacon_interval) | |
3297 | return -EALREADY; | |
3298 | ||
3299 | memset(¶ms, 0, sizeof(params)); | |
3300 | ||
3301 | /* these are required for START_AP */ | |
3302 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3303 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3304 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3305 | return -EINVAL; | |
3306 | ||
a1193be8 | 3307 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3308 | if (err) |
3309 | return err; | |
3310 | ||
3311 | params.beacon_interval = | |
3312 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3313 | params.dtim_period = | |
3314 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3315 | ||
3316 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3317 | if (err) | |
3318 | return err; | |
3319 | ||
3320 | /* | |
3321 | * In theory, some of these attributes should be required here | |
3322 | * but since they were not used when the command was originally | |
3323 | * added, keep them optional for old user space programs to let | |
3324 | * them continue to work with drivers that do not need the | |
3325 | * additional information -- drivers must check! | |
3326 | */ | |
3327 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3328 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3329 | params.ssid_len = | |
3330 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3331 | if (params.ssid_len == 0 || | |
3332 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3333 | return -EINVAL; | |
3334 | } | |
3335 | ||
3336 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3337 | params.hidden_ssid = nla_get_u32( | |
3338 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3339 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3340 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3341 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3342 | return -EINVAL; | |
3343 | } | |
3344 | ||
3345 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3346 | ||
3347 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3348 | params.auth_type = nla_get_u32( | |
3349 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3350 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3351 | NL80211_CMD_START_AP)) | |
8860020e JB |
3352 | return -EINVAL; |
3353 | } else | |
3354 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3355 | ||
3356 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3357 | NL80211_MAX_NR_CIPHER_SUITES); | |
3358 | if (err) | |
3359 | return err; | |
3360 | ||
1b658f11 VT |
3361 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3362 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3363 | return -EOPNOTSUPP; | |
3364 | params.inactivity_timeout = nla_get_u16( | |
3365 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3366 | } | |
3367 | ||
53cabad7 JB |
3368 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3369 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3370 | return -EINVAL; | |
3371 | params.p2p_ctwindow = | |
3372 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3373 | if (params.p2p_ctwindow > 127) | |
3374 | return -EINVAL; | |
3375 | if (params.p2p_ctwindow != 0 && | |
3376 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3377 | return -EINVAL; | |
3378 | } | |
3379 | ||
3380 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3381 | u8 tmp; | |
3382 | ||
3383 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3384 | return -EINVAL; | |
3385 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3386 | if (tmp > 1) | |
3387 | return -EINVAL; | |
3388 | params.p2p_opp_ps = tmp; | |
3389 | if (params.p2p_opp_ps != 0 && | |
3390 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3391 | return -EINVAL; | |
3392 | } | |
3393 | ||
aa430da4 | 3394 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3395 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3396 | if (err) | |
3397 | return err; | |
3398 | } else if (wdev->preset_chandef.chan) { | |
3399 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3400 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3401 | return -EINVAL; |
3402 | ||
174e0cd2 IP |
3403 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
3404 | wdev->iftype)) | |
aa430da4 JB |
3405 | return -EINVAL; |
3406 | ||
77765eaf VT |
3407 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3408 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3409 | if (IS_ERR(params.acl)) | |
3410 | return PTR_ERR(params.acl); | |
3411 | } | |
3412 | ||
18998c38 EP |
3413 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
3414 | params.smps_mode = | |
3415 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); | |
3416 | switch (params.smps_mode) { | |
3417 | case NL80211_SMPS_OFF: | |
3418 | break; | |
3419 | case NL80211_SMPS_STATIC: | |
3420 | if (!(rdev->wiphy.features & | |
3421 | NL80211_FEATURE_STATIC_SMPS)) | |
3422 | return -EINVAL; | |
3423 | break; | |
3424 | case NL80211_SMPS_DYNAMIC: | |
3425 | if (!(rdev->wiphy.features & | |
3426 | NL80211_FEATURE_DYNAMIC_SMPS)) | |
3427 | return -EINVAL; | |
3428 | break; | |
3429 | default: | |
3430 | return -EINVAL; | |
3431 | } | |
3432 | } else { | |
3433 | params.smps_mode = NL80211_SMPS_OFF; | |
3434 | } | |
3435 | ||
c56589ed | 3436 | wdev_lock(wdev); |
e35e4d28 | 3437 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3438 | if (!err) { |
683b6d3b | 3439 | wdev->preset_chandef = params.chandef; |
8860020e | 3440 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 3441 | wdev->chandef = params.chandef; |
06e191e2 AQ |
3442 | wdev->ssid_len = params.ssid_len; |
3443 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3444 | } |
c56589ed | 3445 | wdev_unlock(wdev); |
77765eaf VT |
3446 | |
3447 | kfree(params.acl); | |
3448 | ||
56d1893d | 3449 | return err; |
ed1b6cc7 JB |
3450 | } |
3451 | ||
8860020e JB |
3452 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3453 | { | |
3454 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3455 | struct net_device *dev = info->user_ptr[1]; | |
3456 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3457 | struct cfg80211_beacon_data params; | |
3458 | int err; | |
3459 | ||
3460 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3461 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3462 | return -EOPNOTSUPP; | |
3463 | ||
3464 | if (!rdev->ops->change_beacon) | |
3465 | return -EOPNOTSUPP; | |
3466 | ||
3467 | if (!wdev->beacon_interval) | |
3468 | return -EINVAL; | |
3469 | ||
a1193be8 | 3470 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3471 | if (err) |
3472 | return err; | |
3473 | ||
c56589ed SW |
3474 | wdev_lock(wdev); |
3475 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3476 | wdev_unlock(wdev); | |
3477 | ||
3478 | return err; | |
8860020e JB |
3479 | } |
3480 | ||
3481 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3482 | { |
4c476991 JB |
3483 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3484 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3485 | |
7c8d5e03 | 3486 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
3487 | } |
3488 | ||
5727ef1b JB |
3489 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3490 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3491 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3492 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3493 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3494 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3495 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3496 | }; |
3497 | ||
eccb8e8f | 3498 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3499 | enum nl80211_iftype iftype, |
eccb8e8f | 3500 | struct station_parameters *params) |
5727ef1b JB |
3501 | { |
3502 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3503 | struct nlattr *nla; |
5727ef1b JB |
3504 | int flag; |
3505 | ||
eccb8e8f JB |
3506 | /* |
3507 | * Try parsing the new attribute first so userspace | |
3508 | * can specify both for older kernels. | |
3509 | */ | |
3510 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3511 | if (nla) { | |
3512 | struct nl80211_sta_flag_update *sta_flags; | |
3513 | ||
3514 | sta_flags = nla_data(nla); | |
3515 | params->sta_flags_mask = sta_flags->mask; | |
3516 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3517 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3518 | if ((params->sta_flags_mask | |
3519 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3520 | return -EINVAL; | |
3521 | return 0; | |
3522 | } | |
3523 | ||
3524 | /* if present, parse the old attribute */ | |
5727ef1b | 3525 | |
eccb8e8f | 3526 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3527 | if (!nla) |
3528 | return 0; | |
3529 | ||
3530 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3531 | nla, sta_flags_policy)) | |
3532 | return -EINVAL; | |
3533 | ||
bdd3ae3d JB |
3534 | /* |
3535 | * Only allow certain flags for interface types so that | |
3536 | * other attributes are silently ignored. Remember that | |
3537 | * this is backward compatibility code with old userspace | |
3538 | * and shouldn't be hit in other cases anyway. | |
3539 | */ | |
3540 | switch (iftype) { | |
3541 | case NL80211_IFTYPE_AP: | |
3542 | case NL80211_IFTYPE_AP_VLAN: | |
3543 | case NL80211_IFTYPE_P2P_GO: | |
3544 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3545 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3546 | BIT(NL80211_STA_FLAG_WME) | | |
3547 | BIT(NL80211_STA_FLAG_MFP); | |
3548 | break; | |
3549 | case NL80211_IFTYPE_P2P_CLIENT: | |
3550 | case NL80211_IFTYPE_STATION: | |
3551 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3552 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3553 | break; | |
3554 | case NL80211_IFTYPE_MESH_POINT: | |
3555 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3556 | BIT(NL80211_STA_FLAG_MFP) | | |
3557 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3558 | default: | |
3559 | return -EINVAL; | |
3560 | } | |
5727ef1b | 3561 | |
3383b5a6 JB |
3562 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3563 | if (flags[flag]) { | |
eccb8e8f | 3564 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3565 | |
3383b5a6 JB |
3566 | /* no longer support new API additions in old API */ |
3567 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3568 | return -EINVAL; | |
3569 | } | |
3570 | } | |
3571 | ||
5727ef1b JB |
3572 | return 0; |
3573 | } | |
3574 | ||
c8dcfd8a FF |
3575 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3576 | int attr) | |
3577 | { | |
3578 | struct nlattr *rate; | |
8eb41c8d VK |
3579 | u32 bitrate; |
3580 | u16 bitrate_compat; | |
c8dcfd8a FF |
3581 | |
3582 | rate = nla_nest_start(msg, attr); | |
3583 | if (!rate) | |
db9c64cf | 3584 | return false; |
c8dcfd8a FF |
3585 | |
3586 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3587 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3588 | /* report 16-bit bitrate only if we can */ |
3589 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3590 | if (bitrate > 0 && |
3591 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3592 | return false; | |
3593 | if (bitrate_compat > 0 && | |
3594 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3595 | return false; | |
3596 | ||
3597 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3598 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3599 | return false; | |
3600 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3601 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3602 | return false; | |
3603 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3604 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3605 | return false; | |
3606 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3607 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3608 | return false; | |
3609 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3610 | return false; | |
3611 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3612 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3613 | return false; | |
3614 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3615 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3616 | return false; | |
3617 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3618 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3619 | return false; | |
3620 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3621 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3622 | return false; | |
3623 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3624 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3625 | return false; | |
3626 | } | |
c8dcfd8a FF |
3627 | |
3628 | nla_nest_end(msg, rate); | |
3629 | return true; | |
c8dcfd8a FF |
3630 | } |
3631 | ||
119363c7 FF |
3632 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3633 | int id) | |
3634 | { | |
3635 | void *attr; | |
3636 | int i = 0; | |
3637 | ||
3638 | if (!mask) | |
3639 | return true; | |
3640 | ||
3641 | attr = nla_nest_start(msg, id); | |
3642 | if (!attr) | |
3643 | return false; | |
3644 | ||
3645 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3646 | if (!(mask & BIT(i))) | |
3647 | continue; | |
3648 | ||
3649 | if (nla_put_u8(msg, i, signal[i])) | |
3650 | return false; | |
3651 | } | |
3652 | ||
3653 | nla_nest_end(msg, attr); | |
3654 | ||
3655 | return true; | |
3656 | } | |
3657 | ||
cf5ead82 JB |
3658 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
3659 | u32 seq, int flags, | |
66266b3a JL |
3660 | struct cfg80211_registered_device *rdev, |
3661 | struct net_device *dev, | |
98b62183 | 3662 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3663 | { |
3664 | void *hdr; | |
f4263c98 | 3665 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3666 | |
cf5ead82 | 3667 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
fd5b74dc JB |
3668 | if (!hdr) |
3669 | return -1; | |
3670 | ||
9360ffd1 DM |
3671 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3672 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3673 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3674 | goto nla_put_failure; | |
f5ea9120 | 3675 | |
2ec600d6 LCC |
3676 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3677 | if (!sinfoattr) | |
fd5b74dc | 3678 | goto nla_put_failure; |
319090bf JB |
3679 | |
3680 | #define PUT_SINFO(attr, memb, type) do { \ | |
3681 | if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \ | |
3682 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ | |
3683 | sinfo->memb)) \ | |
3684 | goto nla_put_failure; \ | |
3685 | } while (0) | |
3686 | ||
3687 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); | |
3688 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); | |
3689 | ||
3690 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | | |
3691 | BIT(NL80211_STA_INFO_RX_BYTES64)) && | |
9360ffd1 | 3692 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3693 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3694 | goto nla_put_failure; |
319090bf JB |
3695 | |
3696 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | | |
3697 | BIT(NL80211_STA_INFO_TX_BYTES64)) && | |
9360ffd1 | 3698 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3699 | (u32)sinfo->tx_bytes)) |
3700 | goto nla_put_failure; | |
319090bf JB |
3701 | |
3702 | PUT_SINFO(RX_BYTES64, rx_bytes, u64); | |
3703 | PUT_SINFO(TX_BYTES64, tx_bytes, u64); | |
3704 | PUT_SINFO(LLID, llid, u16); | |
3705 | PUT_SINFO(PLID, plid, u16); | |
3706 | PUT_SINFO(PLINK_STATE, plink_state, u8); | |
3707 | ||
66266b3a JL |
3708 | switch (rdev->wiphy.signal_type) { |
3709 | case CFG80211_SIGNAL_TYPE_MBM: | |
319090bf JB |
3710 | PUT_SINFO(SIGNAL, signal, u8); |
3711 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); | |
66266b3a JL |
3712 | break; |
3713 | default: | |
3714 | break; | |
3715 | } | |
319090bf | 3716 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
119363c7 FF |
3717 | if (!nl80211_put_signal(msg, sinfo->chains, |
3718 | sinfo->chain_signal, | |
3719 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3720 | goto nla_put_failure; | |
3721 | } | |
319090bf | 3722 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
119363c7 FF |
3723 | if (!nl80211_put_signal(msg, sinfo->chains, |
3724 | sinfo->chain_signal_avg, | |
3725 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3726 | goto nla_put_failure; | |
3727 | } | |
319090bf | 3728 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
c8dcfd8a FF |
3729 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3730 | NL80211_STA_INFO_TX_BITRATE)) | |
3731 | goto nla_put_failure; | |
3732 | } | |
319090bf | 3733 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
c8dcfd8a FF |
3734 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
3735 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3736 | goto nla_put_failure; |
420e7fab | 3737 | } |
319090bf JB |
3738 | |
3739 | PUT_SINFO(RX_PACKETS, rx_packets, u32); | |
3740 | PUT_SINFO(TX_PACKETS, tx_packets, u32); | |
3741 | PUT_SINFO(TX_RETRIES, tx_retries, u32); | |
3742 | PUT_SINFO(TX_FAILED, tx_failed, u32); | |
3743 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); | |
3744 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); | |
3745 | PUT_SINFO(LOCAL_PM, local_pm, u32); | |
3746 | PUT_SINFO(PEER_PM, peer_pm, u32); | |
3747 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); | |
3748 | ||
3749 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { | |
f4263c98 PS |
3750 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
3751 | if (!bss_param) | |
3752 | goto nla_put_failure; | |
3753 | ||
9360ffd1 DM |
3754 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3755 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3756 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3757 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3758 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3759 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3760 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3761 | sinfo->bss_param.dtim_period) || | |
3762 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3763 | sinfo->bss_param.beacon_interval)) | |
3764 | goto nla_put_failure; | |
f4263c98 PS |
3765 | |
3766 | nla_nest_end(msg, bss_param); | |
3767 | } | |
319090bf | 3768 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
9360ffd1 DM |
3769 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
3770 | sizeof(struct nl80211_sta_flag_update), | |
3771 | &sinfo->sta_flags)) | |
3772 | goto nla_put_failure; | |
319090bf JB |
3773 | |
3774 | PUT_SINFO(T_OFFSET, t_offset, u64); | |
3775 | PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64); | |
a76b1942 JB |
3776 | PUT_SINFO(BEACON_RX, rx_beacon, u64); |
3777 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); | |
319090bf JB |
3778 | |
3779 | #undef PUT_SINFO | |
6de39808 JB |
3780 | |
3781 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { | |
3782 | struct nlattr *tidsattr; | |
3783 | int tid; | |
3784 | ||
3785 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); | |
3786 | if (!tidsattr) | |
3787 | goto nla_put_failure; | |
3788 | ||
3789 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { | |
3790 | struct cfg80211_tid_stats *tidstats; | |
3791 | struct nlattr *tidattr; | |
3792 | ||
3793 | tidstats = &sinfo->pertid[tid]; | |
3794 | ||
3795 | if (!tidstats->filled) | |
3796 | continue; | |
3797 | ||
3798 | tidattr = nla_nest_start(msg, tid + 1); | |
3799 | if (!tidattr) | |
3800 | goto nla_put_failure; | |
3801 | ||
3802 | #define PUT_TIDVAL(attr, memb, type) do { \ | |
3803 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ | |
3804 | nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \ | |
3805 | tidstats->memb)) \ | |
3806 | goto nla_put_failure; \ | |
3807 | } while (0) | |
3808 | ||
3809 | PUT_TIDVAL(RX_MSDU, rx_msdu, u64); | |
3810 | PUT_TIDVAL(TX_MSDU, tx_msdu, u64); | |
3811 | PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64); | |
3812 | PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64); | |
3813 | ||
3814 | #undef PUT_TIDVAL | |
3815 | nla_nest_end(msg, tidattr); | |
3816 | } | |
3817 | ||
3818 | nla_nest_end(msg, tidsattr); | |
3819 | } | |
3820 | ||
2ec600d6 | 3821 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3822 | |
319090bf | 3823 | if (sinfo->assoc_req_ies_len && |
9360ffd1 DM |
3824 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
3825 | sinfo->assoc_req_ies)) | |
3826 | goto nla_put_failure; | |
50d3dfb7 | 3827 | |
fd5b74dc JB |
3828 | return genlmsg_end(msg, hdr); |
3829 | ||
3830 | nla_put_failure: | |
bc3ed28c TG |
3831 | genlmsg_cancel(msg, hdr); |
3832 | return -EMSGSIZE; | |
fd5b74dc JB |
3833 | } |
3834 | ||
2ec600d6 | 3835 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3836 | struct netlink_callback *cb) |
2ec600d6 | 3837 | { |
2ec600d6 | 3838 | struct station_info sinfo; |
1b8ec87a | 3839 | struct cfg80211_registered_device *rdev; |
97990a06 | 3840 | struct wireless_dev *wdev; |
2ec600d6 | 3841 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3842 | int sta_idx = cb->args[2]; |
2ec600d6 | 3843 | int err; |
2ec600d6 | 3844 | |
1b8ec87a | 3845 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
3846 | if (err) |
3847 | return err; | |
bba95fef | 3848 | |
97990a06 JB |
3849 | if (!wdev->netdev) { |
3850 | err = -EINVAL; | |
3851 | goto out_err; | |
3852 | } | |
3853 | ||
1b8ec87a | 3854 | if (!rdev->ops->dump_station) { |
eec60b03 | 3855 | err = -EOPNOTSUPP; |
bba95fef JB |
3856 | goto out_err; |
3857 | } | |
3858 | ||
bba95fef | 3859 | while (1) { |
f612cedf | 3860 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 3861 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
e35e4d28 | 3862 | mac_addr, &sinfo); |
bba95fef JB |
3863 | if (err == -ENOENT) |
3864 | break; | |
3865 | if (err) | |
3b85875a | 3866 | goto out_err; |
bba95fef | 3867 | |
cf5ead82 | 3868 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
15e47304 | 3869 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3870 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 3871 | rdev, wdev->netdev, mac_addr, |
bba95fef JB |
3872 | &sinfo) < 0) |
3873 | goto out; | |
3874 | ||
3875 | sta_idx++; | |
3876 | } | |
3877 | ||
3878 | ||
3879 | out: | |
97990a06 | 3880 | cb->args[2] = sta_idx; |
bba95fef | 3881 | err = skb->len; |
bba95fef | 3882 | out_err: |
1b8ec87a | 3883 | nl80211_finish_wdev_dump(rdev); |
bba95fef JB |
3884 | |
3885 | return err; | |
2ec600d6 | 3886 | } |
fd5b74dc | 3887 | |
5727ef1b JB |
3888 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3889 | { | |
4c476991 JB |
3890 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3891 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3892 | struct station_info sinfo; |
fd5b74dc JB |
3893 | struct sk_buff *msg; |
3894 | u8 *mac_addr = NULL; | |
4c476991 | 3895 | int err; |
fd5b74dc | 3896 | |
2ec600d6 | 3897 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3898 | |
3899 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3900 | return -EINVAL; | |
3901 | ||
3902 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3903 | ||
4c476991 JB |
3904 | if (!rdev->ops->get_station) |
3905 | return -EOPNOTSUPP; | |
3b85875a | 3906 | |
e35e4d28 | 3907 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3908 | if (err) |
4c476991 | 3909 | return err; |
2ec600d6 | 3910 | |
fd2120ca | 3911 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3912 | if (!msg) |
4c476991 | 3913 | return -ENOMEM; |
fd5b74dc | 3914 | |
cf5ead82 JB |
3915 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
3916 | info->snd_portid, info->snd_seq, 0, | |
66266b3a | 3917 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3918 | nlmsg_free(msg); |
3919 | return -ENOBUFS; | |
3920 | } | |
3b85875a | 3921 | |
4c476991 | 3922 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3923 | } |
3924 | ||
77ee7c89 JB |
3925 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3926 | struct station_parameters *params, | |
3927 | enum cfg80211_station_type statype) | |
3928 | { | |
3929 | if (params->listen_interval != -1) | |
3930 | return -EINVAL; | |
c72e1140 AN |
3931 | if (params->aid && |
3932 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
77ee7c89 JB |
3933 | return -EINVAL; |
3934 | ||
3935 | /* When you run into this, adjust the code below for the new flag */ | |
3936 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3937 | ||
3938 | switch (statype) { | |
eef941e6 TP |
3939 | case CFG80211_STA_MESH_PEER_KERNEL: |
3940 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3941 | /* |
3942 | * No ignoring the TDLS flag here -- the userspace mesh | |
3943 | * code doesn't have the bug of including TDLS in the | |
3944 | * mask everywhere. | |
3945 | */ | |
3946 | if (params->sta_flags_mask & | |
3947 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3948 | BIT(NL80211_STA_FLAG_MFP) | | |
3949 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3950 | return -EINVAL; | |
3951 | break; | |
3952 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3953 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3954 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3955 | return -EINVAL; | |
3956 | /* ignore since it can't change */ | |
3957 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3958 | break; | |
3959 | default: | |
3960 | /* disallow mesh-specific things */ | |
3961 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3962 | return -EINVAL; | |
3963 | if (params->local_pm) | |
3964 | return -EINVAL; | |
3965 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3966 | return -EINVAL; | |
3967 | } | |
3968 | ||
3969 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3970 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3971 | /* TDLS can't be set, ... */ | |
3972 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3973 | return -EINVAL; | |
3974 | /* | |
3975 | * ... but don't bother the driver with it. This works around | |
3976 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3977 | * TLDS_PEER flag in the mask even for AP mode. | |
3978 | */ | |
3979 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3980 | } | |
3981 | ||
3982 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3983 | /* reject other things that can't change */ | |
3984 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3985 | return -EINVAL; | |
3986 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3987 | return -EINVAL; | |
3988 | if (params->supported_rates) | |
3989 | return -EINVAL; | |
3990 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3991 | return -EINVAL; | |
3992 | } | |
3993 | ||
3994 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3995 | if (params->vlan) | |
3996 | return -EINVAL; | |
3997 | } | |
3998 | ||
3999 | switch (statype) { | |
4000 | case CFG80211_STA_AP_MLME_CLIENT: | |
4001 | /* Use this only for authorizing/unauthorizing a station */ | |
4002 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
4003 | return -EOPNOTSUPP; | |
4004 | break; | |
4005 | case CFG80211_STA_AP_CLIENT: | |
4006 | /* accept only the listed bits */ | |
4007 | if (params->sta_flags_mask & | |
4008 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4009 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4010 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4011 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
4012 | BIT(NL80211_STA_FLAG_WME) | | |
4013 | BIT(NL80211_STA_FLAG_MFP))) | |
4014 | return -EINVAL; | |
4015 | ||
4016 | /* but authenticated/associated only if driver handles it */ | |
4017 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4018 | params->sta_flags_mask & | |
4019 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4020 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4021 | return -EINVAL; | |
4022 | break; | |
4023 | case CFG80211_STA_IBSS: | |
4024 | case CFG80211_STA_AP_STA: | |
4025 | /* reject any changes other than AUTHORIZED */ | |
4026 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
4027 | return -EINVAL; | |
4028 | break; | |
4029 | case CFG80211_STA_TDLS_PEER_SETUP: | |
4030 | /* reject any changes other than AUTHORIZED or WME */ | |
4031 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4032 | BIT(NL80211_STA_FLAG_WME))) | |
4033 | return -EINVAL; | |
4034 | /* force (at least) rates when authorizing */ | |
4035 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
4036 | !params->supported_rates) | |
4037 | return -EINVAL; | |
4038 | break; | |
4039 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
4040 | /* reject any changes */ | |
4041 | return -EINVAL; | |
eef941e6 | 4042 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
4043 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
4044 | return -EINVAL; | |
4045 | break; | |
eef941e6 | 4046 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
4047 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
4048 | return -EINVAL; | |
4049 | break; | |
4050 | } | |
4051 | ||
4052 | return 0; | |
4053 | } | |
4054 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
4055 | ||
5727ef1b | 4056 | /* |
c258d2de | 4057 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 4058 | */ |
80b99899 JB |
4059 | static struct net_device *get_vlan(struct genl_info *info, |
4060 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 4061 | { |
463d0183 | 4062 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
4063 | struct net_device *v; |
4064 | int ret; | |
4065 | ||
4066 | if (!vlanattr) | |
4067 | return NULL; | |
4068 | ||
4069 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
4070 | if (!v) | |
4071 | return ERR_PTR(-ENODEV); | |
4072 | ||
4073 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
4074 | ret = -EINVAL; | |
4075 | goto error; | |
5727ef1b | 4076 | } |
80b99899 | 4077 | |
77ee7c89 JB |
4078 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
4079 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4080 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
4081 | ret = -EINVAL; | |
4082 | goto error; | |
4083 | } | |
4084 | ||
80b99899 JB |
4085 | if (!netif_running(v)) { |
4086 | ret = -ENETDOWN; | |
4087 | goto error; | |
4088 | } | |
4089 | ||
4090 | return v; | |
4091 | error: | |
4092 | dev_put(v); | |
4093 | return ERR_PTR(ret); | |
5727ef1b JB |
4094 | } |
4095 | ||
94e860f1 JB |
4096 | static const struct nla_policy |
4097 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
4098 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
4099 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
4100 | }; | |
4101 | ||
ff276691 JB |
4102 | static int nl80211_parse_sta_wme(struct genl_info *info, |
4103 | struct station_parameters *params) | |
df881293 | 4104 | { |
df881293 JM |
4105 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
4106 | struct nlattr *nla; | |
4107 | int err; | |
4108 | ||
df881293 JM |
4109 | /* parse WME attributes if present */ |
4110 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
4111 | return 0; | |
4112 | ||
4113 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
4114 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
4115 | nl80211_sta_wme_policy); | |
4116 | if (err) | |
4117 | return err; | |
4118 | ||
4119 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
4120 | params->uapsd_queues = nla_get_u8( | |
4121 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4122 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
4123 | return -EINVAL; | |
4124 | ||
4125 | if (tb[NL80211_STA_WME_MAX_SP]) | |
4126 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4127 | ||
4128 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
4129 | return -EINVAL; | |
4130 | ||
4131 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
4132 | ||
4133 | return 0; | |
4134 | } | |
4135 | ||
c01fc9ad SD |
4136 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4137 | struct station_parameters *params) | |
4138 | { | |
4139 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4140 | params->supported_channels = | |
4141 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4142 | params->supported_channels_len = | |
4143 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4144 | /* | |
4145 | * Need to include at least one (first channel, number of | |
4146 | * channels) tuple for each subband, and must have proper | |
4147 | * tuples for the rest of the data as well. | |
4148 | */ | |
4149 | if (params->supported_channels_len < 2) | |
4150 | return -EINVAL; | |
4151 | if (params->supported_channels_len % 2) | |
4152 | return -EINVAL; | |
4153 | } | |
4154 | ||
4155 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4156 | params->supported_oper_classes = | |
4157 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4158 | params->supported_oper_classes_len = | |
4159 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4160 | /* | |
4161 | * The value of the Length field of the Supported Operating | |
4162 | * Classes element is between 2 and 253. | |
4163 | */ | |
4164 | if (params->supported_oper_classes_len < 2 || | |
4165 | params->supported_oper_classes_len > 253) | |
4166 | return -EINVAL; | |
4167 | } | |
4168 | return 0; | |
4169 | } | |
4170 | ||
ff276691 JB |
4171 | static int nl80211_set_station_tdls(struct genl_info *info, |
4172 | struct station_parameters *params) | |
4173 | { | |
c01fc9ad | 4174 | int err; |
ff276691 | 4175 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4176 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4177 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4178 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4179 | params->ht_capa = | |
4180 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4181 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4182 | params->vht_capa = | |
4183 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4184 | ||
c01fc9ad SD |
4185 | err = nl80211_parse_sta_channel_info(info, params); |
4186 | if (err) | |
4187 | return err; | |
4188 | ||
ff276691 JB |
4189 | return nl80211_parse_sta_wme(info, params); |
4190 | } | |
4191 | ||
5727ef1b JB |
4192 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4193 | { | |
4c476991 | 4194 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4195 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4196 | struct station_parameters params; |
77ee7c89 JB |
4197 | u8 *mac_addr; |
4198 | int err; | |
5727ef1b JB |
4199 | |
4200 | memset(¶ms, 0, sizeof(params)); | |
4201 | ||
4202 | params.listen_interval = -1; | |
4203 | ||
77ee7c89 JB |
4204 | if (!rdev->ops->change_station) |
4205 | return -EOPNOTSUPP; | |
4206 | ||
5727ef1b JB |
4207 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4208 | return -EINVAL; | |
4209 | ||
4210 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4211 | return -EINVAL; | |
4212 | ||
4213 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4214 | ||
4215 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4216 | params.supported_rates = | |
4217 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4218 | params.supported_rates_len = | |
4219 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4220 | } | |
4221 | ||
9d62a986 JM |
4222 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4223 | params.capability = | |
4224 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4225 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4226 | } | |
4227 | ||
4228 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4229 | params.ext_capab = | |
4230 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4231 | params.ext_capab_len = | |
4232 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4233 | } | |
4234 | ||
df881293 | 4235 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 4236 | return -EINVAL; |
36aedc90 | 4237 | |
bdd3ae3d | 4238 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4239 | return -EINVAL; |
4240 | ||
f8bacc21 | 4241 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4242 | params.plink_action = |
f8bacc21 JB |
4243 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4244 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4245 | return -EINVAL; | |
4246 | } | |
2ec600d6 | 4247 | |
f8bacc21 | 4248 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4249 | params.plink_state = |
f8bacc21 JB |
4250 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4251 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4252 | return -EINVAL; | |
4253 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
4254 | } | |
9c3990aa | 4255 | |
3b1c5a53 MP |
4256 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4257 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4258 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4259 | ||
4260 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4261 | pm > NL80211_MESH_POWER_MAX) | |
4262 | return -EINVAL; | |
4263 | ||
4264 | params.local_pm = pm; | |
4265 | } | |
4266 | ||
77ee7c89 JB |
4267 | /* Include parameters for TDLS peer (will check later) */ |
4268 | err = nl80211_set_station_tdls(info, ¶ms); | |
4269 | if (err) | |
4270 | return err; | |
4271 | ||
4272 | params.vlan = get_vlan(info, rdev); | |
4273 | if (IS_ERR(params.vlan)) | |
4274 | return PTR_ERR(params.vlan); | |
4275 | ||
a97f4424 JB |
4276 | switch (dev->ieee80211_ptr->iftype) { |
4277 | case NL80211_IFTYPE_AP: | |
4278 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4279 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4280 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4281 | case NL80211_IFTYPE_STATION: |
267335d6 | 4282 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4283 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4284 | break; |
4285 | default: | |
77ee7c89 JB |
4286 | err = -EOPNOTSUPP; |
4287 | goto out_put_vlan; | |
034d655e JB |
4288 | } |
4289 | ||
77ee7c89 | 4290 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4291 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4292 | |
77ee7c89 | 4293 | out_put_vlan: |
5727ef1b JB |
4294 | if (params.vlan) |
4295 | dev_put(params.vlan); | |
3b85875a | 4296 | |
5727ef1b JB |
4297 | return err; |
4298 | } | |
4299 | ||
4300 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4301 | { | |
4c476991 | 4302 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4303 | int err; |
4c476991 | 4304 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4305 | struct station_parameters params; |
4306 | u8 *mac_addr = NULL; | |
4307 | ||
4308 | memset(¶ms, 0, sizeof(params)); | |
4309 | ||
984c311b JB |
4310 | if (!rdev->ops->add_station) |
4311 | return -EOPNOTSUPP; | |
4312 | ||
5727ef1b JB |
4313 | if (!info->attrs[NL80211_ATTR_MAC]) |
4314 | return -EINVAL; | |
4315 | ||
5727ef1b JB |
4316 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4317 | return -EINVAL; | |
4318 | ||
4319 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4320 | return -EINVAL; | |
4321 | ||
5e4b6f56 JM |
4322 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4323 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4324 | return -EINVAL; |
4325 | ||
5727ef1b JB |
4326 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4327 | params.supported_rates = | |
4328 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4329 | params.supported_rates_len = | |
4330 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4331 | params.listen_interval = | |
4332 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4333 | |
3d124ea2 | 4334 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4335 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4336 | else |
4337 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4338 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4339 | return -EINVAL; | |
51b50fbe | 4340 | |
9d62a986 JM |
4341 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4342 | params.capability = | |
4343 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4344 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4345 | } | |
4346 | ||
4347 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4348 | params.ext_capab = | |
4349 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4350 | params.ext_capab_len = | |
4351 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4352 | } | |
4353 | ||
36aedc90 JM |
4354 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4355 | params.ht_capa = | |
4356 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4357 | |
f461be3e MP |
4358 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4359 | params.vht_capa = | |
4360 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4361 | ||
60f4a7b1 MK |
4362 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4363 | params.opmode_notif_used = true; | |
4364 | params.opmode_notif = | |
4365 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4366 | } | |
4367 | ||
f8bacc21 | 4368 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4369 | params.plink_action = |
f8bacc21 JB |
4370 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4371 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4372 | return -EINVAL; | |
4373 | } | |
96b78dff | 4374 | |
c01fc9ad SD |
4375 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4376 | if (err) | |
4377 | return err; | |
4378 | ||
ff276691 JB |
4379 | err = nl80211_parse_sta_wme(info, ¶ms); |
4380 | if (err) | |
4381 | return err; | |
bdd90d5e | 4382 | |
bdd3ae3d | 4383 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4384 | return -EINVAL; |
4385 | ||
77ee7c89 JB |
4386 | /* When you run into this, adjust the code below for the new flag */ |
4387 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4388 | ||
bdd90d5e JB |
4389 | switch (dev->ieee80211_ptr->iftype) { |
4390 | case NL80211_IFTYPE_AP: | |
4391 | case NL80211_IFTYPE_AP_VLAN: | |
4392 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4393 | /* ignore WME attributes if iface/sta is not capable */ |
4394 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4395 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4396 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4397 | |
bdd90d5e | 4398 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4399 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4400 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4401 | return -EINVAL; |
bdd90d5e JB |
4402 | /* but don't bother the driver with it */ |
4403 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4404 | |
d582cffb JB |
4405 | /* allow authenticated/associated only if driver handles it */ |
4406 | if (!(rdev->wiphy.features & | |
4407 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4408 | params.sta_flags_mask & | |
4409 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4410 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4411 | return -EINVAL; | |
4412 | ||
bdd90d5e JB |
4413 | /* must be last in here for error handling */ |
4414 | params.vlan = get_vlan(info, rdev); | |
4415 | if (IS_ERR(params.vlan)) | |
4416 | return PTR_ERR(params.vlan); | |
4417 | break; | |
4418 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4419 | /* ignore uAPSD data */ |
4420 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4421 | ||
d582cffb JB |
4422 | /* associated is disallowed */ |
4423 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4424 | return -EINVAL; | |
bdd90d5e | 4425 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4426 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4427 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4428 | return -EINVAL; |
4429 | break; | |
4430 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4431 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4432 | /* ignore uAPSD data */ |
4433 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4434 | ||
77ee7c89 JB |
4435 | /* these are disallowed */ |
4436 | if (params.sta_flags_mask & | |
4437 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4438 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4439 | return -EINVAL; |
bdd90d5e JB |
4440 | /* Only TDLS peers can be added */ |
4441 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4442 | return -EINVAL; | |
4443 | /* Can only add if TDLS ... */ | |
4444 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4445 | return -EOPNOTSUPP; | |
4446 | /* ... with external setup is supported */ | |
4447 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4448 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4449 | /* |
4450 | * Older wpa_supplicant versions always mark the TDLS peer | |
4451 | * as authorized, but it shouldn't yet be. | |
4452 | */ | |
4453 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4454 | break; |
4455 | default: | |
4456 | return -EOPNOTSUPP; | |
c75786c9 EP |
4457 | } |
4458 | ||
bdd90d5e | 4459 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4460 | |
e35e4d28 | 4461 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4462 | |
5727ef1b JB |
4463 | if (params.vlan) |
4464 | dev_put(params.vlan); | |
5727ef1b JB |
4465 | return err; |
4466 | } | |
4467 | ||
4468 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4469 | { | |
4c476991 JB |
4470 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4471 | struct net_device *dev = info->user_ptr[1]; | |
89c771e5 JM |
4472 | struct station_del_parameters params; |
4473 | ||
4474 | memset(¶ms, 0, sizeof(params)); | |
5727ef1b JB |
4475 | |
4476 | if (info->attrs[NL80211_ATTR_MAC]) | |
89c771e5 | 4477 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5727ef1b | 4478 | |
e80cf853 | 4479 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4480 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4481 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4482 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4483 | return -EINVAL; | |
5727ef1b | 4484 | |
4c476991 JB |
4485 | if (!rdev->ops->del_station) |
4486 | return -EOPNOTSUPP; | |
3b85875a | 4487 | |
98856866 JM |
4488 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
4489 | params.subtype = | |
4490 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | |
4491 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | |
4492 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | |
4493 | return -EINVAL; | |
4494 | } else { | |
4495 | /* Default to Deauthentication frame */ | |
4496 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | |
4497 | } | |
4498 | ||
4499 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | |
4500 | params.reason_code = | |
4501 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
4502 | if (params.reason_code == 0) | |
4503 | return -EINVAL; /* 0 is reserved */ | |
4504 | } else { | |
4505 | /* Default to reason code 2 */ | |
4506 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | |
4507 | } | |
4508 | ||
89c771e5 | 4509 | return rdev_del_station(rdev, dev, ¶ms); |
5727ef1b JB |
4510 | } |
4511 | ||
15e47304 | 4512 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4513 | int flags, struct net_device *dev, |
4514 | u8 *dst, u8 *next_hop, | |
4515 | struct mpath_info *pinfo) | |
4516 | { | |
4517 | void *hdr; | |
4518 | struct nlattr *pinfoattr; | |
4519 | ||
1ef4c850 | 4520 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
2ec600d6 LCC |
4521 | if (!hdr) |
4522 | return -1; | |
4523 | ||
9360ffd1 DM |
4524 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4525 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4526 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4527 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4528 | goto nla_put_failure; | |
f5ea9120 | 4529 | |
2ec600d6 LCC |
4530 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4531 | if (!pinfoattr) | |
4532 | goto nla_put_failure; | |
9360ffd1 DM |
4533 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4534 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4535 | pinfo->frame_qlen)) | |
4536 | goto nla_put_failure; | |
4537 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4538 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4539 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4540 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4541 | pinfo->metric)) || | |
4542 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4543 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4544 | pinfo->exptime)) || | |
4545 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4546 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4547 | pinfo->flags)) || | |
4548 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4549 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4550 | pinfo->discovery_timeout)) || | |
4551 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4552 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4553 | pinfo->discovery_retries))) | |
4554 | goto nla_put_failure; | |
2ec600d6 LCC |
4555 | |
4556 | nla_nest_end(msg, pinfoattr); | |
4557 | ||
4558 | return genlmsg_end(msg, hdr); | |
4559 | ||
4560 | nla_put_failure: | |
bc3ed28c TG |
4561 | genlmsg_cancel(msg, hdr); |
4562 | return -EMSGSIZE; | |
2ec600d6 LCC |
4563 | } |
4564 | ||
4565 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4566 | struct netlink_callback *cb) |
2ec600d6 | 4567 | { |
2ec600d6 | 4568 | struct mpath_info pinfo; |
1b8ec87a | 4569 | struct cfg80211_registered_device *rdev; |
97990a06 | 4570 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4571 | u8 dst[ETH_ALEN]; |
4572 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4573 | int path_idx = cb->args[2]; |
2ec600d6 | 4574 | int err; |
2ec600d6 | 4575 | |
1b8ec87a | 4576 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
4577 | if (err) |
4578 | return err; | |
bba95fef | 4579 | |
1b8ec87a | 4580 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 4581 | err = -EOPNOTSUPP; |
bba95fef JB |
4582 | goto out_err; |
4583 | } | |
4584 | ||
97990a06 | 4585 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4586 | err = -EOPNOTSUPP; |
0448b5fc | 4587 | goto out_err; |
eec60b03 JM |
4588 | } |
4589 | ||
bba95fef | 4590 | while (1) { |
1b8ec87a | 4591 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 4592 | next_hop, &pinfo); |
bba95fef | 4593 | if (err == -ENOENT) |
2ec600d6 | 4594 | break; |
bba95fef | 4595 | if (err) |
3b85875a | 4596 | goto out_err; |
2ec600d6 | 4597 | |
15e47304 | 4598 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4599 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4600 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4601 | &pinfo) < 0) |
4602 | goto out; | |
2ec600d6 | 4603 | |
bba95fef | 4604 | path_idx++; |
2ec600d6 | 4605 | } |
2ec600d6 | 4606 | |
2ec600d6 | 4607 | |
bba95fef | 4608 | out: |
97990a06 | 4609 | cb->args[2] = path_idx; |
bba95fef | 4610 | err = skb->len; |
bba95fef | 4611 | out_err: |
1b8ec87a | 4612 | nl80211_finish_wdev_dump(rdev); |
bba95fef | 4613 | return err; |
2ec600d6 LCC |
4614 | } |
4615 | ||
4616 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4617 | { | |
4c476991 | 4618 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4619 | int err; |
4c476991 | 4620 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4621 | struct mpath_info pinfo; |
4622 | struct sk_buff *msg; | |
4623 | u8 *dst = NULL; | |
4624 | u8 next_hop[ETH_ALEN]; | |
4625 | ||
4626 | memset(&pinfo, 0, sizeof(pinfo)); | |
4627 | ||
4628 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4629 | return -EINVAL; | |
4630 | ||
4631 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4632 | ||
4c476991 JB |
4633 | if (!rdev->ops->get_mpath) |
4634 | return -EOPNOTSUPP; | |
2ec600d6 | 4635 | |
4c476991 JB |
4636 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4637 | return -EOPNOTSUPP; | |
eec60b03 | 4638 | |
e35e4d28 | 4639 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4640 | if (err) |
4c476991 | 4641 | return err; |
2ec600d6 | 4642 | |
fd2120ca | 4643 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4644 | if (!msg) |
4c476991 | 4645 | return -ENOMEM; |
2ec600d6 | 4646 | |
15e47304 | 4647 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4648 | dev, dst, next_hop, &pinfo) < 0) { |
4649 | nlmsg_free(msg); | |
4650 | return -ENOBUFS; | |
4651 | } | |
3b85875a | 4652 | |
4c476991 | 4653 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4654 | } |
4655 | ||
4656 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4657 | { | |
4c476991 JB |
4658 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4659 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4660 | u8 *dst = NULL; |
4661 | u8 *next_hop = NULL; | |
4662 | ||
4663 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4664 | return -EINVAL; | |
4665 | ||
4666 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4667 | return -EINVAL; | |
4668 | ||
4669 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4670 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4671 | ||
4c476991 JB |
4672 | if (!rdev->ops->change_mpath) |
4673 | return -EOPNOTSUPP; | |
35a8efe1 | 4674 | |
4c476991 JB |
4675 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4676 | return -EOPNOTSUPP; | |
2ec600d6 | 4677 | |
e35e4d28 | 4678 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4679 | } |
4c476991 | 4680 | |
2ec600d6 LCC |
4681 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4682 | { | |
4c476991 JB |
4683 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4684 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4685 | u8 *dst = NULL; |
4686 | u8 *next_hop = NULL; | |
4687 | ||
4688 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4689 | return -EINVAL; | |
4690 | ||
4691 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4692 | return -EINVAL; | |
4693 | ||
4694 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4695 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4696 | ||
4c476991 JB |
4697 | if (!rdev->ops->add_mpath) |
4698 | return -EOPNOTSUPP; | |
35a8efe1 | 4699 | |
4c476991 JB |
4700 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4701 | return -EOPNOTSUPP; | |
2ec600d6 | 4702 | |
e35e4d28 | 4703 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4704 | } |
4705 | ||
4706 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4707 | { | |
4c476991 JB |
4708 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4709 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4710 | u8 *dst = NULL; |
4711 | ||
4712 | if (info->attrs[NL80211_ATTR_MAC]) | |
4713 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4714 | ||
4c476991 JB |
4715 | if (!rdev->ops->del_mpath) |
4716 | return -EOPNOTSUPP; | |
3b85875a | 4717 | |
e35e4d28 | 4718 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4719 | } |
4720 | ||
66be7d2b HR |
4721 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
4722 | { | |
4723 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4724 | int err; | |
4725 | struct net_device *dev = info->user_ptr[1]; | |
4726 | struct mpath_info pinfo; | |
4727 | struct sk_buff *msg; | |
4728 | u8 *dst = NULL; | |
4729 | u8 mpp[ETH_ALEN]; | |
4730 | ||
4731 | memset(&pinfo, 0, sizeof(pinfo)); | |
4732 | ||
4733 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4734 | return -EINVAL; | |
4735 | ||
4736 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4737 | ||
4738 | if (!rdev->ops->get_mpp) | |
4739 | return -EOPNOTSUPP; | |
4740 | ||
4741 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
4742 | return -EOPNOTSUPP; | |
4743 | ||
4744 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | |
4745 | if (err) | |
4746 | return err; | |
4747 | ||
4748 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4749 | if (!msg) | |
4750 | return -ENOMEM; | |
4751 | ||
4752 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | |
4753 | dev, dst, mpp, &pinfo) < 0) { | |
4754 | nlmsg_free(msg); | |
4755 | return -ENOBUFS; | |
4756 | } | |
4757 | ||
4758 | return genlmsg_reply(msg, info); | |
4759 | } | |
4760 | ||
4761 | static int nl80211_dump_mpp(struct sk_buff *skb, | |
4762 | struct netlink_callback *cb) | |
4763 | { | |
4764 | struct mpath_info pinfo; | |
4765 | struct cfg80211_registered_device *rdev; | |
4766 | struct wireless_dev *wdev; | |
4767 | u8 dst[ETH_ALEN]; | |
4768 | u8 mpp[ETH_ALEN]; | |
4769 | int path_idx = cb->args[2]; | |
4770 | int err; | |
4771 | ||
4772 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | |
4773 | if (err) | |
4774 | return err; | |
4775 | ||
4776 | if (!rdev->ops->dump_mpp) { | |
4777 | err = -EOPNOTSUPP; | |
4778 | goto out_err; | |
4779 | } | |
4780 | ||
4781 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | |
4782 | err = -EOPNOTSUPP; | |
4783 | goto out_err; | |
4784 | } | |
4785 | ||
4786 | while (1) { | |
4787 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | |
4788 | mpp, &pinfo); | |
4789 | if (err == -ENOENT) | |
4790 | break; | |
4791 | if (err) | |
4792 | goto out_err; | |
4793 | ||
4794 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | |
4795 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
4796 | wdev->netdev, dst, mpp, | |
4797 | &pinfo) < 0) | |
4798 | goto out; | |
4799 | ||
4800 | path_idx++; | |
4801 | } | |
4802 | ||
4803 | out: | |
4804 | cb->args[2] = path_idx; | |
4805 | err = skb->len; | |
4806 | out_err: | |
4807 | nl80211_finish_wdev_dump(rdev); | |
4808 | return err; | |
4809 | } | |
4810 | ||
9f1ba906 JM |
4811 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4812 | { | |
4c476991 JB |
4813 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4814 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 4815 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 4816 | struct bss_parameters params; |
c56589ed | 4817 | int err; |
9f1ba906 JM |
4818 | |
4819 | memset(¶ms, 0, sizeof(params)); | |
4820 | /* default to not changing parameters */ | |
4821 | params.use_cts_prot = -1; | |
4822 | params.use_short_preamble = -1; | |
4823 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4824 | params.ap_isolate = -1; |
50b12f59 | 4825 | params.ht_opmode = -1; |
53cabad7 JB |
4826 | params.p2p_ctwindow = -1; |
4827 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4828 | |
4829 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4830 | params.use_cts_prot = | |
4831 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4832 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4833 | params.use_short_preamble = | |
4834 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4835 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4836 | params.use_short_slot_time = | |
4837 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4838 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4839 | params.basic_rates = | |
4840 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4841 | params.basic_rates_len = | |
4842 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4843 | } | |
fd8aaaf3 FF |
4844 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4845 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4846 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4847 | params.ht_opmode = | |
4848 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4849 | |
53cabad7 JB |
4850 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4851 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4852 | return -EINVAL; | |
4853 | params.p2p_ctwindow = | |
4854 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4855 | if (params.p2p_ctwindow < 0) | |
4856 | return -EINVAL; | |
4857 | if (params.p2p_ctwindow != 0 && | |
4858 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4859 | return -EINVAL; | |
4860 | } | |
4861 | ||
4862 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4863 | u8 tmp; | |
4864 | ||
4865 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4866 | return -EINVAL; | |
4867 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4868 | if (tmp > 1) | |
4869 | return -EINVAL; | |
4870 | params.p2p_opp_ps = tmp; | |
4871 | if (params.p2p_opp_ps && | |
4872 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4873 | return -EINVAL; | |
4874 | } | |
4875 | ||
4c476991 JB |
4876 | if (!rdev->ops->change_bss) |
4877 | return -EOPNOTSUPP; | |
9f1ba906 | 4878 | |
074ac8df | 4879 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4880 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4881 | return -EOPNOTSUPP; | |
3b85875a | 4882 | |
c56589ed SW |
4883 | wdev_lock(wdev); |
4884 | err = rdev_change_bss(rdev, dev, ¶ms); | |
4885 | wdev_unlock(wdev); | |
4886 | ||
4887 | return err; | |
9f1ba906 JM |
4888 | } |
4889 | ||
b54452b0 | 4890 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4891 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4892 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4893 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4894 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4895 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4896 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
089027e5 | 4897 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
b2e1b302 LR |
4898 | }; |
4899 | ||
4900 | static int parse_reg_rule(struct nlattr *tb[], | |
4901 | struct ieee80211_reg_rule *reg_rule) | |
4902 | { | |
4903 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4904 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4905 | ||
4906 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4907 | return -EINVAL; | |
4908 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4909 | return -EINVAL; | |
4910 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4911 | return -EINVAL; | |
b0dfd2ea JD |
4912 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
4913 | return -EINVAL; | |
b2e1b302 LR |
4914 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
4915 | return -EINVAL; | |
4916 | ||
4917 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4918 | ||
4919 | freq_range->start_freq_khz = | |
4920 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4921 | freq_range->end_freq_khz = | |
4922 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
b0dfd2ea JD |
4923 | freq_range->max_bandwidth_khz = |
4924 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
b2e1b302 LR |
4925 | |
4926 | power_rule->max_eirp = | |
4927 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4928 | ||
4929 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4930 | power_rule->max_antenna_gain = | |
4931 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4932 | ||
089027e5 JD |
4933 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
4934 | reg_rule->dfs_cac_ms = | |
4935 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
4936 | ||
b2e1b302 LR |
4937 | return 0; |
4938 | } | |
4939 | ||
4940 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4941 | { | |
b2e1b302 | 4942 | char *data = NULL; |
57b5ce07 | 4943 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4944 | |
80778f18 LR |
4945 | /* |
4946 | * You should only get this when cfg80211 hasn't yet initialized | |
4947 | * completely when built-in to the kernel right between the time | |
4948 | * window between nl80211_init() and regulatory_init(), if that is | |
4949 | * even possible. | |
4950 | */ | |
458f4f9e | 4951 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4952 | return -EINPROGRESS; |
80778f18 | 4953 | |
57b5ce07 LR |
4954 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4955 | user_reg_hint_type = | |
4956 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4957 | else | |
4958 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4959 | ||
4960 | switch (user_reg_hint_type) { | |
4961 | case NL80211_USER_REG_HINT_USER: | |
4962 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
4963 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4964 | return -EINVAL; | |
4965 | ||
4966 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4967 | return regulatory_hint_user(data, user_reg_hint_type); | |
4968 | case NL80211_USER_REG_HINT_INDOOR: | |
4969 | return regulatory_hint_indoor_user(); | |
57b5ce07 LR |
4970 | default: |
4971 | return -EINVAL; | |
4972 | } | |
b2e1b302 LR |
4973 | } |
4974 | ||
24bdd9f4 | 4975 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4976 | struct genl_info *info) |
93da9cc1 | 4977 | { |
4c476991 | 4978 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4979 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4980 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4981 | struct mesh_config cur_params; | |
4982 | int err = 0; | |
93da9cc1 | 4983 | void *hdr; |
4984 | struct nlattr *pinfoattr; | |
4985 | struct sk_buff *msg; | |
4986 | ||
29cbe68c JB |
4987 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4988 | return -EOPNOTSUPP; | |
4989 | ||
24bdd9f4 | 4990 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4991 | return -EOPNOTSUPP; |
f3f92586 | 4992 | |
29cbe68c JB |
4993 | wdev_lock(wdev); |
4994 | /* If not connected, get default parameters */ | |
4995 | if (!wdev->mesh_id_len) | |
4996 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4997 | else | |
e35e4d28 | 4998 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4999 | wdev_unlock(wdev); |
5000 | ||
93da9cc1 | 5001 | if (err) |
4c476991 | 5002 | return err; |
93da9cc1 | 5003 | |
5004 | /* Draw up a netlink message to send back */ | |
fd2120ca | 5005 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
5006 | if (!msg) |
5007 | return -ENOMEM; | |
15e47304 | 5008 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 5009 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 5010 | if (!hdr) |
efe1cf0c | 5011 | goto out; |
24bdd9f4 | 5012 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 5013 | if (!pinfoattr) |
5014 | goto nla_put_failure; | |
9360ffd1 DM |
5015 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5016 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
5017 | cur_params.dot11MeshRetryTimeout) || | |
5018 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
5019 | cur_params.dot11MeshConfirmTimeout) || | |
5020 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
5021 | cur_params.dot11MeshHoldingTimeout) || | |
5022 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
5023 | cur_params.dot11MeshMaxPeerLinks) || | |
5024 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
5025 | cur_params.dot11MeshMaxRetries) || | |
5026 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
5027 | cur_params.dot11MeshTTL) || | |
5028 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
5029 | cur_params.element_ttl) || | |
5030 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
5031 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
5032 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5033 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
5034 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5035 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
5036 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
5037 | cur_params.path_refresh_time) || | |
5038 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
5039 | cur_params.min_discovery_timeout) || | |
5040 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
5041 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
5042 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
5043 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
5044 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
5045 | cur_params.dot11MeshHWMPperrMinInterval) || | |
5046 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
5047 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
5048 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5049 | cur_params.dot11MeshHWMPRootMode) || | |
5050 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
5051 | cur_params.dot11MeshHWMPRannInterval) || | |
5052 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
5053 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
5054 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
5055 | cur_params.dot11MeshForwarding) || | |
5056 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
5057 | cur_params.rssi_threshold) || |
5058 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
5059 | cur_params.ht_opmode) || |
5060 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
5061 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
5062 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
5063 | cur_params.dot11MeshHWMProotInterval) || |
5064 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
5065 | cur_params.dot11MeshHWMPconfirmationInterval) || |
5066 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
5067 | cur_params.power_mode) || | |
5068 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
5069 | cur_params.dot11MeshAwakeWindowDuration) || |
5070 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5071 | cur_params.plink_timeout)) | |
9360ffd1 | 5072 | goto nla_put_failure; |
93da9cc1 | 5073 | nla_nest_end(msg, pinfoattr); |
5074 | genlmsg_end(msg, hdr); | |
4c476991 | 5075 | return genlmsg_reply(msg, info); |
93da9cc1 | 5076 | |
3b85875a | 5077 | nla_put_failure: |
93da9cc1 | 5078 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 5079 | out: |
d080e275 | 5080 | nlmsg_free(msg); |
4c476991 | 5081 | return -ENOBUFS; |
93da9cc1 | 5082 | } |
5083 | ||
b54452b0 | 5084 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 5085 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
5086 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
5087 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
5088 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
5089 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
5090 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 5091 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 5092 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 5093 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 5094 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
5095 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
5096 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
5097 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
5098 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 5099 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 5100 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 5101 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 5102 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 5103 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 5104 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
5105 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
5106 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
5107 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
5108 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 5109 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
5110 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
5111 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 5112 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 5113 | }; |
5114 | ||
c80d545d JC |
5115 | static const struct nla_policy |
5116 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 5117 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
5118 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
5119 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 5120 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 5121 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 5122 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 5123 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 5124 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 5125 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
5126 | }; |
5127 | ||
24bdd9f4 | 5128 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
5129 | struct mesh_config *cfg, |
5130 | u32 *mask_out) | |
93da9cc1 | 5131 | { |
93da9cc1 | 5132 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 5133 | u32 mask = 0; |
93da9cc1 | 5134 | |
ea54fba2 MP |
5135 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
5136 | do { \ | |
5137 | if (tb[attr]) { \ | |
5138 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
5139 | return -EINVAL; \ | |
5140 | cfg->param = fn(tb[attr]); \ | |
5141 | mask |= (1 << (attr - 1)); \ | |
5142 | } \ | |
5143 | } while (0) | |
bd90fdcc JB |
5144 | |
5145 | ||
24bdd9f4 | 5146 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 5147 | return -EINVAL; |
5148 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 5149 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 5150 | nl80211_meshconf_params_policy)) |
93da9cc1 | 5151 | return -EINVAL; |
5152 | ||
93da9cc1 | 5153 | /* This makes sure that there aren't more than 32 mesh config |
5154 | * parameters (otherwise our bitfield scheme would not work.) */ | |
5155 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
5156 | ||
5157 | /* Fill in the params struct */ | |
ea54fba2 | 5158 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
5159 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
5160 | nla_get_u16); | |
ea54fba2 | 5161 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
5162 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
5163 | nla_get_u16); | |
ea54fba2 | 5164 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
5165 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
5166 | nla_get_u16); | |
ea54fba2 | 5167 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
5168 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
5169 | nla_get_u16); | |
ea54fba2 | 5170 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
5171 | mask, NL80211_MESHCONF_MAX_RETRIES, |
5172 | nla_get_u8); | |
ea54fba2 | 5173 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 5174 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 5175 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
5176 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
5177 | nla_get_u8); | |
ea54fba2 | 5178 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
5179 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
5180 | nla_get_u8); | |
ea54fba2 MP |
5181 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
5182 | 1, 255, mask, | |
a4f606ea CYY |
5183 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5184 | nla_get_u32); | |
ea54fba2 | 5185 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
5186 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5187 | nla_get_u8); | |
ea54fba2 | 5188 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
5189 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
5190 | nla_get_u32); | |
ea54fba2 | 5191 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
5192 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
5193 | nla_get_u16); | |
ea54fba2 MP |
5194 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
5195 | 1, 65535, mask, | |
a4f606ea CYY |
5196 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
5197 | nla_get_u32); | |
93da9cc1 | 5198 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
5199 | 1, 65535, mask, |
5200 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 5201 | nla_get_u16); |
dca7e943 | 5202 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
5203 | 1, 65535, mask, |
5204 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 5205 | nla_get_u16); |
93da9cc1 | 5206 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5207 | dot11MeshHWMPnetDiameterTraversalTime, |
5208 | 1, 65535, mask, | |
a4f606ea CYY |
5209 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
5210 | nla_get_u16); | |
ea54fba2 MP |
5211 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
5212 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5213 | nla_get_u8); | |
5214 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
5215 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 5216 | nla_get_u16); |
63c5723b | 5217 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5218 | dot11MeshGateAnnouncementProtocol, 0, 1, |
5219 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 5220 | nla_get_u8); |
ea54fba2 | 5221 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
5222 | mask, NL80211_MESHCONF_FORWARDING, |
5223 | nla_get_u8); | |
83374fe9 | 5224 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 5225 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
83374fe9 | 5226 | nla_get_s32); |
ea54fba2 | 5227 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 5228 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
5229 | nla_get_u16); |
5230 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 5231 | 1, 65535, mask, |
ac1073a6 CYY |
5232 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
5233 | nla_get_u32); | |
ea54fba2 | 5234 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 5235 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
5236 | nla_get_u16); |
5237 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
5238 | dot11MeshHWMPconfirmationInterval, |
5239 | 1, 65535, mask, | |
728b19e5 | 5240 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 5241 | nla_get_u16); |
3b1c5a53 MP |
5242 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
5243 | NL80211_MESH_POWER_ACTIVE, | |
5244 | NL80211_MESH_POWER_MAX, | |
5245 | mask, NL80211_MESHCONF_POWER_MODE, | |
5246 | nla_get_u32); | |
5247 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
5248 | 0, 65535, mask, | |
5249 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
8e7c0538 CT |
5250 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
5251 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5252 | nla_get_u32); | |
bd90fdcc JB |
5253 | if (mask_out) |
5254 | *mask_out = mask; | |
c80d545d | 5255 | |
bd90fdcc JB |
5256 | return 0; |
5257 | ||
5258 | #undef FILL_IN_MESH_PARAM_IF_SET | |
5259 | } | |
5260 | ||
c80d545d JC |
5261 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
5262 | struct mesh_setup *setup) | |
5263 | { | |
bb2798d4 | 5264 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
5265 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
5266 | ||
5267 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
5268 | return -EINVAL; | |
5269 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
5270 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
5271 | nl80211_mesh_setup_params_policy)) | |
5272 | return -EINVAL; | |
5273 | ||
d299a1f2 JC |
5274 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
5275 | setup->sync_method = | |
5276 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
5277 | IEEE80211_SYNC_METHOD_VENDOR : | |
5278 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
5279 | ||
c80d545d JC |
5280 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
5281 | setup->path_sel_proto = | |
5282 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5283 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5284 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5285 | ||
5286 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5287 | setup->path_metric = | |
5288 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5289 | IEEE80211_PATH_METRIC_VENDOR : | |
5290 | IEEE80211_PATH_METRIC_AIRTIME; | |
5291 | ||
581a8b0f JC |
5292 | |
5293 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 5294 | struct nlattr *ieattr = |
581a8b0f | 5295 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5296 | if (!is_valid_ie_attr(ieattr)) |
5297 | return -EINVAL; | |
581a8b0f JC |
5298 | setup->ie = nla_data(ieattr); |
5299 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5300 | } |
bb2798d4 TP |
5301 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5302 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5303 | return -EINVAL; | |
5304 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5305 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5306 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5307 | if (setup->is_secure) |
5308 | setup->user_mpm = true; | |
c80d545d | 5309 | |
6e16d90b CT |
5310 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5311 | if (!setup->user_mpm) | |
5312 | return -EINVAL; | |
5313 | setup->auth_id = | |
5314 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5315 | } | |
5316 | ||
c80d545d JC |
5317 | return 0; |
5318 | } | |
5319 | ||
24bdd9f4 | 5320 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5321 | struct genl_info *info) |
bd90fdcc JB |
5322 | { |
5323 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5324 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5325 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5326 | struct mesh_config cfg; |
5327 | u32 mask; | |
5328 | int err; | |
5329 | ||
29cbe68c JB |
5330 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5331 | return -EOPNOTSUPP; | |
5332 | ||
24bdd9f4 | 5333 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5334 | return -EOPNOTSUPP; |
5335 | ||
24bdd9f4 | 5336 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5337 | if (err) |
5338 | return err; | |
5339 | ||
29cbe68c JB |
5340 | wdev_lock(wdev); |
5341 | if (!wdev->mesh_id_len) | |
5342 | err = -ENOLINK; | |
5343 | ||
5344 | if (!err) | |
e35e4d28 | 5345 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5346 | |
5347 | wdev_unlock(wdev); | |
5348 | ||
5349 | return err; | |
93da9cc1 | 5350 | } |
5351 | ||
ad30ca2c AN |
5352 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
5353 | struct sk_buff *msg) | |
f130347c | 5354 | { |
f130347c LR |
5355 | struct nlattr *nl_reg_rules; |
5356 | unsigned int i; | |
f130347c | 5357 | |
458f4f9e JB |
5358 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
5359 | (regdom->dfs_region && | |
5360 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
ad30ca2c | 5361 | goto nla_put_failure; |
458f4f9e | 5362 | |
f130347c LR |
5363 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5364 | if (!nl_reg_rules) | |
ad30ca2c | 5365 | goto nla_put_failure; |
f130347c | 5366 | |
458f4f9e | 5367 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5368 | struct nlattr *nl_reg_rule; |
5369 | const struct ieee80211_reg_rule *reg_rule; | |
5370 | const struct ieee80211_freq_range *freq_range; | |
5371 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 5372 | unsigned int max_bandwidth_khz; |
f130347c | 5373 | |
458f4f9e | 5374 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5375 | freq_range = ®_rule->freq_range; |
5376 | power_rule = ®_rule->power_rule; | |
5377 | ||
5378 | nl_reg_rule = nla_nest_start(msg, i); | |
5379 | if (!nl_reg_rule) | |
ad30ca2c | 5380 | goto nla_put_failure; |
f130347c | 5381 | |
97524820 JD |
5382 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
5383 | if (!max_bandwidth_khz) | |
5384 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
5385 | reg_rule); | |
5386 | ||
9360ffd1 DM |
5387 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5388 | reg_rule->flags) || | |
5389 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5390 | freq_range->start_freq_khz) || | |
5391 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5392 | freq_range->end_freq_khz) || | |
5393 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 5394 | max_bandwidth_khz) || |
9360ffd1 DM |
5395 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
5396 | power_rule->max_antenna_gain) || | |
5397 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
5398 | power_rule->max_eirp) || |
5399 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
5400 | reg_rule->dfs_cac_ms)) | |
ad30ca2c | 5401 | goto nla_put_failure; |
f130347c LR |
5402 | |
5403 | nla_nest_end(msg, nl_reg_rule); | |
5404 | } | |
5405 | ||
5406 | nla_nest_end(msg, nl_reg_rules); | |
ad30ca2c AN |
5407 | return 0; |
5408 | ||
5409 | nla_put_failure: | |
5410 | return -EMSGSIZE; | |
5411 | } | |
5412 | ||
5413 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) | |
5414 | { | |
5415 | const struct ieee80211_regdomain *regdom = NULL; | |
5416 | struct cfg80211_registered_device *rdev; | |
5417 | struct wiphy *wiphy = NULL; | |
5418 | struct sk_buff *msg; | |
5419 | void *hdr; | |
5420 | ||
5421 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5422 | if (!msg) | |
5423 | return -ENOBUFS; | |
5424 | ||
5425 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
5426 | NL80211_CMD_GET_REG); | |
5427 | if (!hdr) | |
5428 | goto put_failure; | |
5429 | ||
5430 | if (info->attrs[NL80211_ATTR_WIPHY]) { | |
1bdd716c AN |
5431 | bool self_managed; |
5432 | ||
ad30ca2c AN |
5433 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
5434 | if (IS_ERR(rdev)) { | |
5435 | nlmsg_free(msg); | |
5436 | return PTR_ERR(rdev); | |
5437 | } | |
5438 | ||
5439 | wiphy = &rdev->wiphy; | |
1bdd716c AN |
5440 | self_managed = wiphy->regulatory_flags & |
5441 | REGULATORY_WIPHY_SELF_MANAGED; | |
ad30ca2c AN |
5442 | regdom = get_wiphy_regdom(wiphy); |
5443 | ||
1bdd716c AN |
5444 | /* a self-managed-reg device must have a private regdom */ |
5445 | if (WARN_ON(!regdom && self_managed)) { | |
5446 | nlmsg_free(msg); | |
5447 | return -EINVAL; | |
5448 | } | |
5449 | ||
ad30ca2c AN |
5450 | if (regdom && |
5451 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5452 | goto nla_put_failure; | |
5453 | } | |
5454 | ||
5455 | if (!wiphy && reg_last_request_cell_base() && | |
5456 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5457 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5458 | goto nla_put_failure; | |
5459 | ||
5460 | rcu_read_lock(); | |
5461 | ||
5462 | if (!regdom) | |
5463 | regdom = rcu_dereference(cfg80211_regdomain); | |
5464 | ||
5465 | if (nl80211_put_regdom(regdom, msg)) | |
5466 | goto nla_put_failure_rcu; | |
5467 | ||
5468 | rcu_read_unlock(); | |
f130347c LR |
5469 | |
5470 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5471 | return genlmsg_reply(msg, info); |
f130347c | 5472 | |
458f4f9e JB |
5473 | nla_put_failure_rcu: |
5474 | rcu_read_unlock(); | |
f130347c LR |
5475 | nla_put_failure: |
5476 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5477 | put_failure: |
d080e275 | 5478 | nlmsg_free(msg); |
5fe231e8 | 5479 | return -EMSGSIZE; |
f130347c LR |
5480 | } |
5481 | ||
ad30ca2c AN |
5482 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
5483 | u32 seq, int flags, struct wiphy *wiphy, | |
5484 | const struct ieee80211_regdomain *regdom) | |
5485 | { | |
5486 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | |
5487 | NL80211_CMD_GET_REG); | |
5488 | ||
5489 | if (!hdr) | |
5490 | return -1; | |
5491 | ||
5492 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); | |
5493 | ||
5494 | if (nl80211_put_regdom(regdom, msg)) | |
5495 | goto nla_put_failure; | |
5496 | ||
5497 | if (!wiphy && reg_last_request_cell_base() && | |
5498 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5499 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5500 | goto nla_put_failure; | |
5501 | ||
5502 | if (wiphy && | |
5503 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5504 | goto nla_put_failure; | |
5505 | ||
1bdd716c AN |
5506 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
5507 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
5508 | goto nla_put_failure; | |
5509 | ||
ad30ca2c AN |
5510 | return genlmsg_end(msg, hdr); |
5511 | ||
5512 | nla_put_failure: | |
5513 | genlmsg_cancel(msg, hdr); | |
5514 | return -EMSGSIZE; | |
5515 | } | |
5516 | ||
5517 | static int nl80211_get_reg_dump(struct sk_buff *skb, | |
5518 | struct netlink_callback *cb) | |
5519 | { | |
5520 | const struct ieee80211_regdomain *regdom = NULL; | |
5521 | struct cfg80211_registered_device *rdev; | |
5522 | int err, reg_idx, start = cb->args[2]; | |
5523 | ||
5524 | rtnl_lock(); | |
5525 | ||
5526 | if (cfg80211_regdomain && start == 0) { | |
5527 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5528 | NLM_F_MULTI, NULL, | |
5529 | rtnl_dereference(cfg80211_regdomain)); | |
5530 | if (err < 0) | |
5531 | goto out_err; | |
5532 | } | |
5533 | ||
5534 | /* the global regdom is idx 0 */ | |
5535 | reg_idx = 1; | |
5536 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | |
5537 | regdom = get_wiphy_regdom(&rdev->wiphy); | |
5538 | if (!regdom) | |
5539 | continue; | |
5540 | ||
5541 | if (++reg_idx <= start) | |
5542 | continue; | |
5543 | ||
5544 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5545 | NLM_F_MULTI, &rdev->wiphy, regdom); | |
5546 | if (err < 0) { | |
5547 | reg_idx--; | |
5548 | break; | |
5549 | } | |
5550 | } | |
5551 | ||
5552 | cb->args[2] = reg_idx; | |
5553 | err = skb->len; | |
5554 | out_err: | |
5555 | rtnl_unlock(); | |
5556 | return err; | |
5557 | } | |
5558 | ||
b2e1b302 LR |
5559 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5560 | { | |
5561 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5562 | struct nlattr *nl_reg_rule; | |
ea372c54 JB |
5563 | char *alpha2; |
5564 | int rem_reg_rules, r; | |
b2e1b302 | 5565 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
4c7d3982 | 5566 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
ea372c54 | 5567 | struct ieee80211_regdomain *rd; |
b2e1b302 LR |
5568 | |
5569 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5570 | return -EINVAL; | |
5571 | ||
5572 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5573 | return -EINVAL; | |
5574 | ||
5575 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5576 | ||
8b60b078 LR |
5577 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5578 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5579 | ||
b2e1b302 | 5580 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5581 | rem_reg_rules) { |
b2e1b302 LR |
5582 | num_rules++; |
5583 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5584 | return -EINVAL; |
b2e1b302 LR |
5585 | } |
5586 | ||
e438768f LR |
5587 | if (!reg_is_valid_request(alpha2)) |
5588 | return -EINVAL; | |
5589 | ||
b2e1b302 | 5590 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5591 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5592 | |
5593 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5594 | if (!rd) |
5595 | return -ENOMEM; | |
b2e1b302 LR |
5596 | |
5597 | rd->n_reg_rules = num_rules; | |
5598 | rd->alpha2[0] = alpha2[0]; | |
5599 | rd->alpha2[1] = alpha2[1]; | |
5600 | ||
8b60b078 LR |
5601 | /* |
5602 | * Disable DFS master mode if the DFS region was | |
5603 | * not supported or known on this kernel. | |
5604 | */ | |
5605 | if (reg_supported_dfs_region(dfs_region)) | |
5606 | rd->dfs_region = dfs_region; | |
5607 | ||
b2e1b302 | 5608 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5609 | rem_reg_rules) { |
ae811e21 JB |
5610 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
5611 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
5612 | reg_rule_policy); | |
5613 | if (r) | |
5614 | goto bad_reg; | |
b2e1b302 LR |
5615 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5616 | if (r) | |
5617 | goto bad_reg; | |
5618 | ||
5619 | rule_idx++; | |
5620 | ||
d0e18f83 LR |
5621 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5622 | r = -EINVAL; | |
b2e1b302 | 5623 | goto bad_reg; |
d0e18f83 | 5624 | } |
b2e1b302 LR |
5625 | } |
5626 | ||
b2e1b302 | 5627 | r = set_regdom(rd); |
6913b49a | 5628 | /* set_regdom took ownership */ |
1a919318 | 5629 | rd = NULL; |
b2e1b302 | 5630 | |
d2372b31 | 5631 | bad_reg: |
b2e1b302 | 5632 | kfree(rd); |
d0e18f83 | 5633 | return r; |
b2e1b302 LR |
5634 | } |
5635 | ||
83f5e2cf JB |
5636 | static int validate_scan_freqs(struct nlattr *freqs) |
5637 | { | |
5638 | struct nlattr *attr1, *attr2; | |
5639 | int n_channels = 0, tmp1, tmp2; | |
5640 | ||
5641 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5642 | n_channels++; | |
5643 | /* | |
5644 | * Some hardware has a limited channel list for | |
5645 | * scanning, and it is pretty much nonsensical | |
5646 | * to scan for a channel twice, so disallow that | |
5647 | * and don't require drivers to check that the | |
5648 | * channel list they get isn't longer than what | |
5649 | * they can scan, as long as they can scan all | |
5650 | * the channels they registered at once. | |
5651 | */ | |
5652 | nla_for_each_nested(attr2, freqs, tmp2) | |
5653 | if (attr1 != attr2 && | |
5654 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5655 | return 0; | |
5656 | } | |
5657 | ||
5658 | return n_channels; | |
5659 | } | |
5660 | ||
ad2b26ab JB |
5661 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
5662 | u8 *mac_addr, u8 *mac_addr_mask) | |
5663 | { | |
5664 | int i; | |
5665 | ||
5666 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { | |
5667 | memset(mac_addr, 0, ETH_ALEN); | |
5668 | memset(mac_addr_mask, 0, ETH_ALEN); | |
5669 | mac_addr[0] = 0x2; | |
5670 | mac_addr_mask[0] = 0x3; | |
5671 | ||
5672 | return 0; | |
5673 | } | |
5674 | ||
5675 | /* need both or none */ | |
5676 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) | |
5677 | return -EINVAL; | |
5678 | ||
5679 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); | |
5680 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); | |
5681 | ||
5682 | /* don't allow or configure an mcast address */ | |
5683 | if (!is_multicast_ether_addr(mac_addr_mask) || | |
5684 | is_multicast_ether_addr(mac_addr)) | |
5685 | return -EINVAL; | |
5686 | ||
5687 | /* | |
5688 | * allow users to pass a MAC address that has bits set outside | |
5689 | * of the mask, but don't bother drivers with having to deal | |
5690 | * with such bits | |
5691 | */ | |
5692 | for (i = 0; i < ETH_ALEN; i++) | |
5693 | mac_addr[i] &= mac_addr_mask[i]; | |
5694 | ||
5695 | return 0; | |
5696 | } | |
5697 | ||
2a519311 JB |
5698 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5699 | { | |
4c476991 | 5700 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5701 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5702 | struct cfg80211_scan_request *request; |
2a519311 JB |
5703 | struct nlattr *attr; |
5704 | struct wiphy *wiphy; | |
83f5e2cf | 5705 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5706 | size_t ie_len; |
2a519311 | 5707 | |
f4a11bb0 JB |
5708 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5709 | return -EINVAL; | |
5710 | ||
79c97e97 | 5711 | wiphy = &rdev->wiphy; |
2a519311 | 5712 | |
4c476991 JB |
5713 | if (!rdev->ops->scan) |
5714 | return -EOPNOTSUPP; | |
2a519311 | 5715 | |
f9d15d16 | 5716 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
5717 | err = -EBUSY; |
5718 | goto unlock; | |
5719 | } | |
2a519311 JB |
5720 | |
5721 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5722 | n_channels = validate_scan_freqs( |
5723 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5724 | if (!n_channels) { |
5725 | err = -EINVAL; | |
5726 | goto unlock; | |
5727 | } | |
2a519311 | 5728 | } else { |
bdfbec2d | 5729 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
5730 | } |
5731 | ||
5732 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5733 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5734 | n_ssids++; | |
5735 | ||
f9f47529 JB |
5736 | if (n_ssids > wiphy->max_scan_ssids) { |
5737 | err = -EINVAL; | |
5738 | goto unlock; | |
5739 | } | |
2a519311 | 5740 | |
70692ad2 JM |
5741 | if (info->attrs[NL80211_ATTR_IE]) |
5742 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5743 | else | |
5744 | ie_len = 0; | |
5745 | ||
f9f47529 JB |
5746 | if (ie_len > wiphy->max_scan_ie_len) { |
5747 | err = -EINVAL; | |
5748 | goto unlock; | |
5749 | } | |
18a83659 | 5750 | |
2a519311 | 5751 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5752 | + sizeof(*request->ssids) * n_ssids |
5753 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5754 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5755 | if (!request) { |
5756 | err = -ENOMEM; | |
5757 | goto unlock; | |
5758 | } | |
2a519311 | 5759 | |
2a519311 | 5760 | if (n_ssids) |
5ba63533 | 5761 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5762 | request->n_ssids = n_ssids; |
70692ad2 JM |
5763 | if (ie_len) { |
5764 | if (request->ssids) | |
5765 | request->ie = (void *)(request->ssids + n_ssids); | |
5766 | else | |
5767 | request->ie = (void *)(request->channels + n_channels); | |
5768 | } | |
2a519311 | 5769 | |
584991dc | 5770 | i = 0; |
2a519311 JB |
5771 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5772 | /* user specified, bail out if channel not found */ | |
2a519311 | 5773 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5774 | struct ieee80211_channel *chan; |
5775 | ||
5776 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5777 | ||
5778 | if (!chan) { | |
2a519311 JB |
5779 | err = -EINVAL; |
5780 | goto out_free; | |
5781 | } | |
584991dc JB |
5782 | |
5783 | /* ignore disabled channels */ | |
5784 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5785 | continue; | |
5786 | ||
5787 | request->channels[i] = chan; | |
2a519311 JB |
5788 | i++; |
5789 | } | |
5790 | } else { | |
34850ab2 JB |
5791 | enum ieee80211_band band; |
5792 | ||
2a519311 | 5793 | /* all channels */ |
2a519311 JB |
5794 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5795 | int j; | |
5796 | if (!wiphy->bands[band]) | |
5797 | continue; | |
5798 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5799 | struct ieee80211_channel *chan; |
5800 | ||
5801 | chan = &wiphy->bands[band]->channels[j]; | |
5802 | ||
5803 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5804 | continue; | |
5805 | ||
5806 | request->channels[i] = chan; | |
2a519311 JB |
5807 | i++; |
5808 | } | |
5809 | } | |
5810 | } | |
5811 | ||
584991dc JB |
5812 | if (!i) { |
5813 | err = -EINVAL; | |
5814 | goto out_free; | |
5815 | } | |
5816 | ||
5817 | request->n_channels = i; | |
5818 | ||
2a519311 JB |
5819 | i = 0; |
5820 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5821 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5822 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5823 | err = -EINVAL; |
5824 | goto out_free; | |
5825 | } | |
57a27e1d | 5826 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5827 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5828 | i++; |
5829 | } | |
5830 | } | |
5831 | ||
70692ad2 JM |
5832 | if (info->attrs[NL80211_ATTR_IE]) { |
5833 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5834 | memcpy((void *)request->ie, |
5835 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5836 | request->ie_len); |
5837 | } | |
5838 | ||
34850ab2 | 5839 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5840 | if (wiphy->bands[i]) |
5841 | request->rates[i] = | |
5842 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5843 | |
5844 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5845 | nla_for_each_nested(attr, | |
5846 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5847 | tmp) { | |
5848 | enum ieee80211_band band = nla_type(attr); | |
5849 | ||
84404623 | 5850 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5851 | err = -EINVAL; |
5852 | goto out_free; | |
5853 | } | |
1b09cd82 FF |
5854 | |
5855 | if (!wiphy->bands[band]) | |
5856 | continue; | |
5857 | ||
34850ab2 JB |
5858 | err = ieee80211_get_ratemask(wiphy->bands[band], |
5859 | nla_data(attr), | |
5860 | nla_len(attr), | |
5861 | &request->rates[band]); | |
5862 | if (err) | |
5863 | goto out_free; | |
5864 | } | |
5865 | } | |
5866 | ||
46856bbf | 5867 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5868 | request->flags = nla_get_u32( |
5869 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5870 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5871 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5872 | err = -EOPNOTSUPP; |
5873 | goto out_free; | |
5874 | } | |
ad2b26ab JB |
5875 | |
5876 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
5877 | if (!(wiphy->features & | |
5878 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { | |
5879 | err = -EOPNOTSUPP; | |
5880 | goto out_free; | |
5881 | } | |
5882 | ||
5883 | if (wdev->current_bss) { | |
5884 | err = -EOPNOTSUPP; | |
5885 | goto out_free; | |
5886 | } | |
5887 | ||
5888 | err = nl80211_parse_random_mac(info->attrs, | |
5889 | request->mac_addr, | |
5890 | request->mac_addr_mask); | |
5891 | if (err) | |
5892 | goto out_free; | |
5893 | } | |
46856bbf | 5894 | } |
ed473771 | 5895 | |
e9f935e3 RM |
5896 | request->no_cck = |
5897 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5898 | ||
fd014284 | 5899 | request->wdev = wdev; |
79c97e97 | 5900 | request->wiphy = &rdev->wiphy; |
15d6030b | 5901 | request->scan_start = jiffies; |
2a519311 | 5902 | |
79c97e97 | 5903 | rdev->scan_req = request; |
e35e4d28 | 5904 | err = rdev_scan(rdev, request); |
2a519311 | 5905 | |
463d0183 | 5906 | if (!err) { |
fd014284 JB |
5907 | nl80211_send_scan_start(rdev, wdev); |
5908 | if (wdev->netdev) | |
5909 | dev_hold(wdev->netdev); | |
4c476991 | 5910 | } else { |
2a519311 | 5911 | out_free: |
79c97e97 | 5912 | rdev->scan_req = NULL; |
2a519311 JB |
5913 | kfree(request); |
5914 | } | |
3b85875a | 5915 | |
f9f47529 | 5916 | unlock: |
2a519311 JB |
5917 | return err; |
5918 | } | |
5919 | ||
256da02d | 5920 | static struct cfg80211_sched_scan_request * |
ad2b26ab | 5921 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
256da02d | 5922 | struct nlattr **attrs) |
807f8a8c LC |
5923 | { |
5924 | struct cfg80211_sched_scan_request *request; | |
807f8a8c | 5925 | struct nlattr *attr; |
a1f1c21c | 5926 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5927 | u32 interval; |
807f8a8c LC |
5928 | enum ieee80211_band band; |
5929 | size_t ie_len; | |
a1f1c21c | 5930 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 5931 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c | 5932 | |
256da02d LC |
5933 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
5934 | return ERR_PTR(-EINVAL); | |
807f8a8c | 5935 | |
256da02d LC |
5936 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5937 | return ERR_PTR(-EINVAL); | |
bbe6ad6d | 5938 | |
256da02d | 5939 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
bbe6ad6d | 5940 | if (interval == 0) |
256da02d | 5941 | return ERR_PTR(-EINVAL); |
807f8a8c | 5942 | |
256da02d | 5943 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c | 5944 | n_channels = validate_scan_freqs( |
256da02d | 5945 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
807f8a8c | 5946 | if (!n_channels) |
256da02d | 5947 | return ERR_PTR(-EINVAL); |
807f8a8c | 5948 | } else { |
bdfbec2d | 5949 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
5950 | } |
5951 | ||
256da02d LC |
5952 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
5953 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c LC |
5954 | tmp) |
5955 | n_ssids++; | |
5956 | ||
93b6aa69 | 5957 | if (n_ssids > wiphy->max_sched_scan_ssids) |
256da02d | 5958 | return ERR_PTR(-EINVAL); |
807f8a8c | 5959 | |
ea73cbce JB |
5960 | /* |
5961 | * First, count the number of 'real' matchsets. Due to an issue with | |
5962 | * the old implementation, matchsets containing only the RSSI attribute | |
5963 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
5964 | * RSSI for all matchsets, rather than their own matchset for reporting | |
5965 | * all APs with a strong RSSI. This is needed to be compatible with | |
5966 | * older userspace that treated a matchset with only the RSSI as the | |
5967 | * global RSSI for all other matchsets - if there are other matchsets. | |
5968 | */ | |
256da02d | 5969 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 5970 | nla_for_each_nested(attr, |
256da02d | 5971 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
ea73cbce JB |
5972 | tmp) { |
5973 | struct nlattr *rssi; | |
5974 | ||
5975 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5976 | nla_data(attr), nla_len(attr), | |
5977 | nl80211_match_policy); | |
5978 | if (err) | |
256da02d | 5979 | return ERR_PTR(err); |
ea73cbce JB |
5980 | /* add other standalone attributes here */ |
5981 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | |
5982 | n_match_sets++; | |
5983 | continue; | |
5984 | } | |
5985 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
5986 | if (rssi) | |
5987 | default_match_rssi = nla_get_s32(rssi); | |
5988 | } | |
5989 | } | |
5990 | ||
5991 | /* However, if there's no other matchset, add the RSSI one */ | |
5992 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
5993 | n_match_sets = 1; | |
a1f1c21c LC |
5994 | |
5995 | if (n_match_sets > wiphy->max_match_sets) | |
256da02d | 5996 | return ERR_PTR(-EINVAL); |
a1f1c21c | 5997 | |
256da02d LC |
5998 | if (attrs[NL80211_ATTR_IE]) |
5999 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); | |
807f8a8c LC |
6000 | else |
6001 | ie_len = 0; | |
6002 | ||
5a865bad | 6003 | if (ie_len > wiphy->max_sched_scan_ie_len) |
256da02d | 6004 | return ERR_PTR(-EINVAL); |
c10841ca | 6005 | |
807f8a8c | 6006 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 6007 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 6008 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 6009 | + sizeof(*request->channels) * n_channels |
807f8a8c | 6010 | + ie_len, GFP_KERNEL); |
256da02d LC |
6011 | if (!request) |
6012 | return ERR_PTR(-ENOMEM); | |
807f8a8c LC |
6013 | |
6014 | if (n_ssids) | |
6015 | request->ssids = (void *)&request->channels[n_channels]; | |
6016 | request->n_ssids = n_ssids; | |
6017 | if (ie_len) { | |
6018 | if (request->ssids) | |
6019 | request->ie = (void *)(request->ssids + n_ssids); | |
6020 | else | |
6021 | request->ie = (void *)(request->channels + n_channels); | |
6022 | } | |
6023 | ||
a1f1c21c LC |
6024 | if (n_match_sets) { |
6025 | if (request->ie) | |
6026 | request->match_sets = (void *)(request->ie + ie_len); | |
6027 | else if (request->ssids) | |
6028 | request->match_sets = | |
6029 | (void *)(request->ssids + n_ssids); | |
6030 | else | |
6031 | request->match_sets = | |
6032 | (void *)(request->channels + n_channels); | |
6033 | } | |
6034 | request->n_match_sets = n_match_sets; | |
6035 | ||
807f8a8c | 6036 | i = 0; |
256da02d | 6037 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c LC |
6038 | /* user specified, bail out if channel not found */ |
6039 | nla_for_each_nested(attr, | |
256da02d | 6040 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
807f8a8c LC |
6041 | tmp) { |
6042 | struct ieee80211_channel *chan; | |
6043 | ||
6044 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
6045 | ||
6046 | if (!chan) { | |
6047 | err = -EINVAL; | |
6048 | goto out_free; | |
6049 | } | |
6050 | ||
6051 | /* ignore disabled channels */ | |
6052 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6053 | continue; | |
6054 | ||
6055 | request->channels[i] = chan; | |
6056 | i++; | |
6057 | } | |
6058 | } else { | |
6059 | /* all channels */ | |
6060 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6061 | int j; | |
6062 | if (!wiphy->bands[band]) | |
6063 | continue; | |
6064 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
6065 | struct ieee80211_channel *chan; | |
6066 | ||
6067 | chan = &wiphy->bands[band]->channels[j]; | |
6068 | ||
6069 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6070 | continue; | |
6071 | ||
6072 | request->channels[i] = chan; | |
6073 | i++; | |
6074 | } | |
6075 | } | |
6076 | } | |
6077 | ||
6078 | if (!i) { | |
6079 | err = -EINVAL; | |
6080 | goto out_free; | |
6081 | } | |
6082 | ||
6083 | request->n_channels = i; | |
6084 | ||
6085 | i = 0; | |
256da02d LC |
6086 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) { |
6087 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c | 6088 | tmp) { |
57a27e1d | 6089 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
6090 | err = -EINVAL; |
6091 | goto out_free; | |
6092 | } | |
57a27e1d | 6093 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
6094 | memcpy(request->ssids[i].ssid, nla_data(attr), |
6095 | nla_len(attr)); | |
807f8a8c LC |
6096 | i++; |
6097 | } | |
6098 | } | |
6099 | ||
a1f1c21c | 6100 | i = 0; |
256da02d | 6101 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 6102 | nla_for_each_nested(attr, |
256da02d | 6103 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
a1f1c21c | 6104 | tmp) { |
88e920b4 | 6105 | struct nlattr *ssid, *rssi; |
a1f1c21c | 6106 | |
ae811e21 JB |
6107 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
6108 | nla_data(attr), nla_len(attr), | |
6109 | nl80211_match_policy); | |
6110 | if (err) | |
6111 | goto out_free; | |
4a4ab0d7 | 6112 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 6113 | if (ssid) { |
ea73cbce JB |
6114 | if (WARN_ON(i >= n_match_sets)) { |
6115 | /* this indicates a programming error, | |
6116 | * the loop above should have verified | |
6117 | * things properly | |
6118 | */ | |
6119 | err = -EINVAL; | |
6120 | goto out_free; | |
6121 | } | |
6122 | ||
a1f1c21c LC |
6123 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
6124 | err = -EINVAL; | |
6125 | goto out_free; | |
6126 | } | |
6127 | memcpy(request->match_sets[i].ssid.ssid, | |
6128 | nla_data(ssid), nla_len(ssid)); | |
6129 | request->match_sets[i].ssid.ssid_len = | |
6130 | nla_len(ssid); | |
ea73cbce JB |
6131 | /* special attribute - old implemenation w/a */ |
6132 | request->match_sets[i].rssi_thold = | |
6133 | default_match_rssi; | |
6134 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6135 | if (rssi) | |
6136 | request->match_sets[i].rssi_thold = | |
6137 | nla_get_s32(rssi); | |
a1f1c21c LC |
6138 | } |
6139 | i++; | |
6140 | } | |
ea73cbce JB |
6141 | |
6142 | /* there was no other matchset, so the RSSI one is alone */ | |
f89f46cf | 6143 | if (i == 0 && n_match_sets) |
ea73cbce JB |
6144 | request->match_sets[0].rssi_thold = default_match_rssi; |
6145 | ||
6146 | request->min_rssi_thold = INT_MAX; | |
6147 | for (i = 0; i < n_match_sets; i++) | |
6148 | request->min_rssi_thold = | |
6149 | min(request->match_sets[i].rssi_thold, | |
6150 | request->min_rssi_thold); | |
6151 | } else { | |
6152 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
6153 | } |
6154 | ||
9900e484 JB |
6155 | if (ie_len) { |
6156 | request->ie_len = ie_len; | |
807f8a8c | 6157 | memcpy((void *)request->ie, |
256da02d | 6158 | nla_data(attrs[NL80211_ATTR_IE]), |
807f8a8c LC |
6159 | request->ie_len); |
6160 | } | |
6161 | ||
256da02d | 6162 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 | 6163 | request->flags = nla_get_u32( |
256da02d | 6164 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
00c3a6ed JB |
6165 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
6166 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
6167 | err = -EOPNOTSUPP; |
6168 | goto out_free; | |
6169 | } | |
ad2b26ab JB |
6170 | |
6171 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
6172 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; | |
6173 | ||
6174 | if (!wdev) /* must be net-detect */ | |
6175 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
6176 | ||
6177 | if (!(wiphy->features & flg)) { | |
6178 | err = -EOPNOTSUPP; | |
6179 | goto out_free; | |
6180 | } | |
6181 | ||
6182 | if (wdev && wdev->current_bss) { | |
6183 | err = -EOPNOTSUPP; | |
6184 | goto out_free; | |
6185 | } | |
6186 | ||
6187 | err = nl80211_parse_random_mac(attrs, request->mac_addr, | |
6188 | request->mac_addr_mask); | |
6189 | if (err) | |
6190 | goto out_free; | |
6191 | } | |
46856bbf | 6192 | } |
ed473771 | 6193 | |
bbe6ad6d | 6194 | request->interval = interval; |
15d6030b | 6195 | request->scan_start = jiffies; |
807f8a8c | 6196 | |
256da02d | 6197 | return request; |
807f8a8c LC |
6198 | |
6199 | out_free: | |
6200 | kfree(request); | |
256da02d LC |
6201 | return ERR_PTR(err); |
6202 | } | |
6203 | ||
6204 | static int nl80211_start_sched_scan(struct sk_buff *skb, | |
6205 | struct genl_info *info) | |
6206 | { | |
6207 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6208 | struct net_device *dev = info->user_ptr[1]; | |
ad2b26ab | 6209 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
31a60ed1 | 6210 | struct cfg80211_sched_scan_request *sched_scan_req; |
256da02d LC |
6211 | int err; |
6212 | ||
6213 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6214 | !rdev->ops->sched_scan_start) | |
6215 | return -EOPNOTSUPP; | |
6216 | ||
6217 | if (rdev->sched_scan_req) | |
6218 | return -EINPROGRESS; | |
6219 | ||
31a60ed1 JR |
6220 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
6221 | info->attrs); | |
6222 | ||
6223 | err = PTR_ERR_OR_ZERO(sched_scan_req); | |
256da02d LC |
6224 | if (err) |
6225 | goto out_err; | |
6226 | ||
31a60ed1 | 6227 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
256da02d LC |
6228 | if (err) |
6229 | goto out_free; | |
6230 | ||
31a60ed1 JR |
6231 | sched_scan_req->dev = dev; |
6232 | sched_scan_req->wiphy = &rdev->wiphy; | |
6233 | ||
93a1e86c JR |
6234 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
6235 | sched_scan_req->owner_nlportid = info->snd_portid; | |
6236 | ||
31a60ed1 | 6237 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
256da02d LC |
6238 | |
6239 | nl80211_send_sched_scan(rdev, dev, | |
6240 | NL80211_CMD_START_SCHED_SCAN); | |
6241 | return 0; | |
6242 | ||
6243 | out_free: | |
31a60ed1 | 6244 | kfree(sched_scan_req); |
256da02d | 6245 | out_err: |
807f8a8c LC |
6246 | return err; |
6247 | } | |
6248 | ||
6249 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
6250 | struct genl_info *info) | |
6251 | { | |
6252 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6253 | ||
6254 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6255 | !rdev->ops->sched_scan_stop) | |
6256 | return -EOPNOTSUPP; | |
6257 | ||
5fe231e8 | 6258 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
6259 | } |
6260 | ||
04f39047 SW |
6261 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
6262 | struct genl_info *info) | |
6263 | { | |
6264 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6265 | struct net_device *dev = info->user_ptr[1]; | |
6266 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6267 | struct cfg80211_chan_def chandef; | |
55f7435c | 6268 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 6269 | unsigned int cac_time_ms; |
04f39047 SW |
6270 | int err; |
6271 | ||
55f7435c LR |
6272 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
6273 | if (dfs_region == NL80211_DFS_UNSET) | |
6274 | return -EINVAL; | |
6275 | ||
04f39047 SW |
6276 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6277 | if (err) | |
6278 | return err; | |
6279 | ||
ff311bc1 SW |
6280 | if (netif_carrier_ok(dev)) |
6281 | return -EBUSY; | |
6282 | ||
04f39047 SW |
6283 | if (wdev->cac_started) |
6284 | return -EBUSY; | |
6285 | ||
2beb6dab | 6286 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
00ec75fc | 6287 | wdev->iftype); |
04f39047 SW |
6288 | if (err < 0) |
6289 | return err; | |
6290 | ||
6291 | if (err == 0) | |
6292 | return -EINVAL; | |
6293 | ||
fe7c3a1f | 6294 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
6295 | return -EINVAL; |
6296 | ||
6297 | if (!rdev->ops->start_radar_detection) | |
6298 | return -EOPNOTSUPP; | |
6299 | ||
31559f35 JD |
6300 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
6301 | if (WARN_ON(!cac_time_ms)) | |
6302 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
6303 | ||
6304 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, | |
6305 | cac_time_ms); | |
04f39047 | 6306 | if (!err) { |
9e0e2961 | 6307 | wdev->chandef = chandef; |
04f39047 SW |
6308 | wdev->cac_started = true; |
6309 | wdev->cac_start_time = jiffies; | |
31559f35 | 6310 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 6311 | } |
04f39047 SW |
6312 | return err; |
6313 | } | |
6314 | ||
16ef1fe2 SW |
6315 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
6316 | { | |
6317 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6318 | struct net_device *dev = info->user_ptr[1]; | |
6319 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6320 | struct cfg80211_csa_settings params; | |
6321 | /* csa_attrs is defined static to avoid waste of stack size - this | |
6322 | * function is called under RTNL lock, so this should not be a problem. | |
6323 | */ | |
6324 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
16ef1fe2 | 6325 | int err; |
ee4bc9e7 | 6326 | bool need_new_beacon = false; |
9a774c78 | 6327 | int len, i; |
252e07ca | 6328 | u32 cs_count; |
16ef1fe2 SW |
6329 | |
6330 | if (!rdev->ops->channel_switch || | |
6331 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
6332 | return -EOPNOTSUPP; | |
6333 | ||
ee4bc9e7 SW |
6334 | switch (dev->ieee80211_ptr->iftype) { |
6335 | case NL80211_IFTYPE_AP: | |
6336 | case NL80211_IFTYPE_P2P_GO: | |
6337 | need_new_beacon = true; | |
6338 | ||
6339 | /* useless if AP is not running */ | |
6340 | if (!wdev->beacon_interval) | |
1ff79dfa | 6341 | return -ENOTCONN; |
ee4bc9e7 SW |
6342 | break; |
6343 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
6344 | if (!wdev->ssid_len) |
6345 | return -ENOTCONN; | |
6346 | break; | |
c6da674a | 6347 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
6348 | if (!wdev->mesh_id_len) |
6349 | return -ENOTCONN; | |
ee4bc9e7 SW |
6350 | break; |
6351 | default: | |
16ef1fe2 | 6352 | return -EOPNOTSUPP; |
ee4bc9e7 | 6353 | } |
16ef1fe2 SW |
6354 | |
6355 | memset(¶ms, 0, sizeof(params)); | |
6356 | ||
6357 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6358 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
6359 | return -EINVAL; | |
6360 | ||
6361 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 6362 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
6363 | return -EINVAL; |
6364 | ||
252e07ca LC |
6365 | /* Even though the attribute is u32, the specification says |
6366 | * u8, so let's make sure we don't overflow. | |
6367 | */ | |
6368 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
6369 | if (cs_count > 255) | |
6370 | return -EINVAL; | |
6371 | ||
6372 | params.count = cs_count; | |
16ef1fe2 | 6373 | |
ee4bc9e7 SW |
6374 | if (!need_new_beacon) |
6375 | goto skip_beacons; | |
6376 | ||
16ef1fe2 SW |
6377 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
6378 | if (err) | |
6379 | return err; | |
6380 | ||
6381 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
6382 | info->attrs[NL80211_ATTR_CSA_IES], | |
6383 | nl80211_policy); | |
6384 | if (err) | |
6385 | return err; | |
6386 | ||
6387 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
6388 | if (err) | |
6389 | return err; | |
6390 | ||
6391 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
6392 | return -EINVAL; | |
6393 | ||
9a774c78 AO |
6394 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
6395 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6396 | return -EINVAL; |
6397 | ||
9a774c78 AO |
6398 | params.n_counter_offsets_beacon = len / sizeof(u16); |
6399 | if (rdev->wiphy.max_num_csa_counters && | |
6400 | (params.n_counter_offsets_beacon > | |
6401 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
6402 | return -EINVAL; |
6403 | ||
9a774c78 AO |
6404 | params.counter_offsets_beacon = |
6405 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
6406 | ||
6407 | /* sanity checks - counters should fit and be the same */ | |
6408 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
6409 | u16 offset = params.counter_offsets_beacon[i]; | |
6410 | ||
6411 | if (offset >= params.beacon_csa.tail_len) | |
6412 | return -EINVAL; | |
6413 | ||
6414 | if (params.beacon_csa.tail[offset] != params.count) | |
6415 | return -EINVAL; | |
6416 | } | |
6417 | ||
16ef1fe2 | 6418 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
6419 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
6420 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6421 | return -EINVAL; |
6422 | ||
9a774c78 AO |
6423 | params.n_counter_offsets_presp = len / sizeof(u16); |
6424 | if (rdev->wiphy.max_num_csa_counters && | |
6425 | (params.n_counter_offsets_beacon > | |
6426 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 | 6427 | return -EINVAL; |
9a774c78 AO |
6428 | |
6429 | params.counter_offsets_presp = | |
6430 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
6431 | ||
6432 | /* sanity checks - counters should fit and be the same */ | |
6433 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
6434 | u16 offset = params.counter_offsets_presp[i]; | |
6435 | ||
6436 | if (offset >= params.beacon_csa.probe_resp_len) | |
6437 | return -EINVAL; | |
6438 | ||
6439 | if (params.beacon_csa.probe_resp[offset] != | |
6440 | params.count) | |
6441 | return -EINVAL; | |
6442 | } | |
16ef1fe2 SW |
6443 | } |
6444 | ||
ee4bc9e7 | 6445 | skip_beacons: |
16ef1fe2 SW |
6446 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
6447 | if (err) | |
6448 | return err; | |
6449 | ||
174e0cd2 IP |
6450 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
6451 | wdev->iftype)) | |
16ef1fe2 SW |
6452 | return -EINVAL; |
6453 | ||
2beb6dab LC |
6454 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
6455 | ¶ms.chandef, | |
6456 | wdev->iftype); | |
6457 | if (err < 0) | |
6458 | return err; | |
6459 | ||
dcc6c2f5 | 6460 | if (err > 0) |
2beb6dab | 6461 | params.radar_required = true; |
16ef1fe2 | 6462 | |
16ef1fe2 SW |
6463 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
6464 | params.block_tx = true; | |
6465 | ||
c56589ed SW |
6466 | wdev_lock(wdev); |
6467 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
6468 | wdev_unlock(wdev); | |
6469 | ||
6470 | return err; | |
16ef1fe2 SW |
6471 | } |
6472 | ||
9720bb3a JB |
6473 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
6474 | u32 seq, int flags, | |
2a519311 | 6475 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
6476 | struct wireless_dev *wdev, |
6477 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 6478 | { |
48ab905d | 6479 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 6480 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
6481 | void *hdr; |
6482 | struct nlattr *bss; | |
48ab905d JB |
6483 | |
6484 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 6485 | |
15e47304 | 6486 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
6487 | NL80211_CMD_NEW_SCAN_RESULTS); |
6488 | if (!hdr) | |
6489 | return -1; | |
6490 | ||
9720bb3a JB |
6491 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
6492 | ||
97990a06 JB |
6493 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
6494 | goto nla_put_failure; | |
6495 | if (wdev->netdev && | |
9360ffd1 DM |
6496 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
6497 | goto nla_put_failure; | |
97990a06 JB |
6498 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
6499 | goto nla_put_failure; | |
2a519311 JB |
6500 | |
6501 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
6502 | if (!bss) | |
6503 | goto nla_put_failure; | |
9360ffd1 | 6504 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 6505 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 6506 | goto nla_put_failure; |
9caf0364 JB |
6507 | |
6508 | rcu_read_lock(); | |
0e227084 JB |
6509 | /* indicate whether we have probe response data or not */ |
6510 | if (rcu_access_pointer(res->proberesp_ies) && | |
6511 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
6512 | goto fail_unlock_rcu; | |
6513 | ||
6514 | /* this pointer prefers to be pointed to probe response data | |
6515 | * but is always valid | |
6516 | */ | |
9caf0364 | 6517 | ies = rcu_dereference(res->ies); |
8cef2c9d JB |
6518 | if (ies) { |
6519 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
6520 | goto fail_unlock_rcu; | |
8cef2c9d JB |
6521 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
6522 | ies->len, ies->data)) | |
6523 | goto fail_unlock_rcu; | |
9caf0364 | 6524 | } |
0e227084 JB |
6525 | |
6526 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 6527 | ies = rcu_dereference(res->beacon_ies); |
0e227084 JB |
6528 | if (ies && ies->from_beacon) { |
6529 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) | |
8cef2c9d JB |
6530 | goto fail_unlock_rcu; |
6531 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
6532 | ies->len, ies->data)) | |
6533 | goto fail_unlock_rcu; | |
9caf0364 JB |
6534 | } |
6535 | rcu_read_unlock(); | |
6536 | ||
9360ffd1 DM |
6537 | if (res->beacon_interval && |
6538 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
6539 | goto nla_put_failure; | |
6540 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
6541 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 6542 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
6543 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
6544 | jiffies_to_msecs(jiffies - intbss->ts))) | |
6545 | goto nla_put_failure; | |
2a519311 | 6546 | |
77965c97 | 6547 | switch (rdev->wiphy.signal_type) { |
2a519311 | 6548 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
6549 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
6550 | goto nla_put_failure; | |
2a519311 JB |
6551 | break; |
6552 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
6553 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
6554 | goto nla_put_failure; | |
2a519311 JB |
6555 | break; |
6556 | default: | |
6557 | break; | |
6558 | } | |
6559 | ||
48ab905d | 6560 | switch (wdev->iftype) { |
074ac8df | 6561 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 6562 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
6563 | if (intbss == wdev->current_bss && |
6564 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6565 | NL80211_BSS_STATUS_ASSOCIATED)) | |
6566 | goto nla_put_failure; | |
48ab905d JB |
6567 | break; |
6568 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
6569 | if (intbss == wdev->current_bss && |
6570 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6571 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
6572 | goto nla_put_failure; | |
48ab905d JB |
6573 | break; |
6574 | default: | |
6575 | break; | |
6576 | } | |
6577 | ||
2a519311 JB |
6578 | nla_nest_end(msg, bss); |
6579 | ||
6580 | return genlmsg_end(msg, hdr); | |
6581 | ||
8cef2c9d JB |
6582 | fail_unlock_rcu: |
6583 | rcu_read_unlock(); | |
2a519311 JB |
6584 | nla_put_failure: |
6585 | genlmsg_cancel(msg, hdr); | |
6586 | return -EMSGSIZE; | |
6587 | } | |
6588 | ||
97990a06 | 6589 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 6590 | { |
48ab905d | 6591 | struct cfg80211_registered_device *rdev; |
2a519311 | 6592 | struct cfg80211_internal_bss *scan; |
48ab905d | 6593 | struct wireless_dev *wdev; |
97990a06 | 6594 | int start = cb->args[2], idx = 0; |
2a519311 JB |
6595 | int err; |
6596 | ||
97990a06 | 6597 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6598 | if (err) |
6599 | return err; | |
2a519311 | 6600 | |
48ab905d JB |
6601 | wdev_lock(wdev); |
6602 | spin_lock_bh(&rdev->bss_lock); | |
6603 | cfg80211_bss_expire(rdev); | |
6604 | ||
9720bb3a JB |
6605 | cb->seq = rdev->bss_generation; |
6606 | ||
48ab905d | 6607 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
6608 | if (++idx <= start) |
6609 | continue; | |
9720bb3a | 6610 | if (nl80211_send_bss(skb, cb, |
2a519311 | 6611 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 6612 | rdev, wdev, scan) < 0) { |
2a519311 | 6613 | idx--; |
67748893 | 6614 | break; |
2a519311 JB |
6615 | } |
6616 | } | |
6617 | ||
48ab905d JB |
6618 | spin_unlock_bh(&rdev->bss_lock); |
6619 | wdev_unlock(wdev); | |
2a519311 | 6620 | |
97990a06 JB |
6621 | cb->args[2] = idx; |
6622 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 6623 | |
67748893 | 6624 | return skb->len; |
2a519311 JB |
6625 | } |
6626 | ||
15e47304 | 6627 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
11f78ac3 JB |
6628 | int flags, struct net_device *dev, |
6629 | bool allow_radio_stats, | |
6630 | struct survey_info *survey) | |
61fa713c HS |
6631 | { |
6632 | void *hdr; | |
6633 | struct nlattr *infoattr; | |
6634 | ||
11f78ac3 JB |
6635 | /* skip radio stats if userspace didn't request them */ |
6636 | if (!survey->channel && !allow_radio_stats) | |
6637 | return 0; | |
6638 | ||
15e47304 | 6639 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
6640 | NL80211_CMD_NEW_SURVEY_RESULTS); |
6641 | if (!hdr) | |
6642 | return -ENOMEM; | |
6643 | ||
9360ffd1 DM |
6644 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
6645 | goto nla_put_failure; | |
61fa713c HS |
6646 | |
6647 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
6648 | if (!infoattr) | |
6649 | goto nla_put_failure; | |
6650 | ||
11f78ac3 JB |
6651 | if (survey->channel && |
6652 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
9360ffd1 DM |
6653 | survey->channel->center_freq)) |
6654 | goto nla_put_failure; | |
6655 | ||
6656 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
6657 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
6658 | goto nla_put_failure; | |
6659 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
6660 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
6661 | goto nla_put_failure; | |
4ed20beb JB |
6662 | if ((survey->filled & SURVEY_INFO_TIME) && |
6663 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME, | |
6664 | survey->time)) | |
9360ffd1 | 6665 | goto nla_put_failure; |
4ed20beb JB |
6666 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
6667 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY, | |
6668 | survey->time_busy)) | |
9360ffd1 | 6669 | goto nla_put_failure; |
4ed20beb JB |
6670 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
6671 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, | |
6672 | survey->time_ext_busy)) | |
9360ffd1 | 6673 | goto nla_put_failure; |
4ed20beb JB |
6674 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
6675 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX, | |
6676 | survey->time_rx)) | |
9360ffd1 | 6677 | goto nla_put_failure; |
4ed20beb JB |
6678 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
6679 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX, | |
6680 | survey->time_tx)) | |
9360ffd1 | 6681 | goto nla_put_failure; |
052536ab JB |
6682 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
6683 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN, | |
6684 | survey->time_scan)) | |
6685 | goto nla_put_failure; | |
61fa713c HS |
6686 | |
6687 | nla_nest_end(msg, infoattr); | |
6688 | ||
6689 | return genlmsg_end(msg, hdr); | |
6690 | ||
6691 | nla_put_failure: | |
6692 | genlmsg_cancel(msg, hdr); | |
6693 | return -EMSGSIZE; | |
6694 | } | |
6695 | ||
11f78ac3 | 6696 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
61fa713c HS |
6697 | { |
6698 | struct survey_info survey; | |
1b8ec87a | 6699 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
6700 | struct wireless_dev *wdev; |
6701 | int survey_idx = cb->args[2]; | |
61fa713c | 6702 | int res; |
11f78ac3 | 6703 | bool radio_stats; |
61fa713c | 6704 | |
1b8ec87a | 6705 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6706 | if (res) |
6707 | return res; | |
61fa713c | 6708 | |
11f78ac3 JB |
6709 | /* prepare_wdev_dump parsed the attributes */ |
6710 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; | |
6711 | ||
97990a06 JB |
6712 | if (!wdev->netdev) { |
6713 | res = -EINVAL; | |
6714 | goto out_err; | |
6715 | } | |
6716 | ||
1b8ec87a | 6717 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
6718 | res = -EOPNOTSUPP; |
6719 | goto out_err; | |
6720 | } | |
6721 | ||
6722 | while (1) { | |
1b8ec87a | 6723 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
6724 | if (res == -ENOENT) |
6725 | break; | |
6726 | if (res) | |
6727 | goto out_err; | |
6728 | ||
11f78ac3 JB |
6729 | /* don't send disabled channels, but do send non-channel data */ |
6730 | if (survey.channel && | |
6731 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { | |
180cdc79 LR |
6732 | survey_idx++; |
6733 | continue; | |
6734 | } | |
6735 | ||
61fa713c | 6736 | if (nl80211_send_survey(skb, |
15e47304 | 6737 | NETLINK_CB(cb->skb).portid, |
61fa713c | 6738 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
11f78ac3 | 6739 | wdev->netdev, radio_stats, &survey) < 0) |
61fa713c HS |
6740 | goto out; |
6741 | survey_idx++; | |
6742 | } | |
6743 | ||
6744 | out: | |
97990a06 | 6745 | cb->args[2] = survey_idx; |
61fa713c HS |
6746 | res = skb->len; |
6747 | out_err: | |
1b8ec87a | 6748 | nl80211_finish_wdev_dump(rdev); |
61fa713c HS |
6749 | return res; |
6750 | } | |
6751 | ||
b23aa676 SO |
6752 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
6753 | { | |
6754 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
6755 | NL80211_WPA_VERSION_2)); | |
6756 | } | |
6757 | ||
636a5d36 JM |
6758 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
6759 | { | |
4c476991 JB |
6760 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6761 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6762 | struct ieee80211_channel *chan; |
e39e5b5e JM |
6763 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
6764 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 6765 | enum nl80211_auth_type auth_type; |
fffd0934 | 6766 | struct key_parse key; |
d5cdfacb | 6767 | bool local_state_change; |
636a5d36 | 6768 | |
f4a11bb0 JB |
6769 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6770 | return -EINVAL; | |
6771 | ||
6772 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6773 | return -EINVAL; | |
6774 | ||
1778092e JM |
6775 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
6776 | return -EINVAL; | |
6777 | ||
19957bb3 JB |
6778 | if (!info->attrs[NL80211_ATTR_SSID]) |
6779 | return -EINVAL; | |
6780 | ||
6781 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
6782 | return -EINVAL; | |
6783 | ||
fffd0934 JB |
6784 | err = nl80211_parse_key(info, &key); |
6785 | if (err) | |
6786 | return err; | |
6787 | ||
6788 | if (key.idx >= 0) { | |
e31b8213 JB |
6789 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
6790 | return -EINVAL; | |
fffd0934 JB |
6791 | if (!key.p.key || !key.p.key_len) |
6792 | return -EINVAL; | |
6793 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
6794 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
6795 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
6796 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
6797 | return -EINVAL; | |
6798 | if (key.idx > 4) | |
6799 | return -EINVAL; | |
6800 | } else { | |
6801 | key.p.key_len = 0; | |
6802 | key.p.key = NULL; | |
6803 | } | |
6804 | ||
afea0b7a JB |
6805 | if (key.idx >= 0) { |
6806 | int i; | |
6807 | bool ok = false; | |
6808 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
6809 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
6810 | ok = true; | |
6811 | break; | |
6812 | } | |
6813 | } | |
4c476991 JB |
6814 | if (!ok) |
6815 | return -EINVAL; | |
afea0b7a JB |
6816 | } |
6817 | ||
4c476991 JB |
6818 | if (!rdev->ops->auth) |
6819 | return -EOPNOTSUPP; | |
636a5d36 | 6820 | |
074ac8df | 6821 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6822 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6823 | return -EOPNOTSUPP; | |
eec60b03 | 6824 | |
19957bb3 | 6825 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
6826 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6827 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6828 | if (!chan) | |
4c476991 | 6829 | return -EINVAL; |
636a5d36 | 6830 | |
19957bb3 JB |
6831 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6832 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6833 | |
6834 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6835 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6836 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6837 | } |
6838 | ||
19957bb3 | 6839 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 6840 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 6841 | return -EINVAL; |
636a5d36 | 6842 | |
e39e5b5e JM |
6843 | if (auth_type == NL80211_AUTHTYPE_SAE && |
6844 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
6845 | return -EINVAL; | |
6846 | ||
6847 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
6848 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
6849 | return -EINVAL; | |
6850 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6851 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6852 | /* need to include at least Auth Transaction and Status Code */ | |
6853 | if (sae_data_len < 4) | |
6854 | return -EINVAL; | |
6855 | } | |
6856 | ||
d5cdfacb JM |
6857 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6858 | ||
95de817b JB |
6859 | /* |
6860 | * Since we no longer track auth state, ignore | |
6861 | * requests to only change local state. | |
6862 | */ | |
6863 | if (local_state_change) | |
6864 | return 0; | |
6865 | ||
91bf9b26 JB |
6866 | wdev_lock(dev->ieee80211_ptr); |
6867 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
6868 | ssid, ssid_len, ie, ie_len, | |
6869 | key.p.key, key.p.key_len, key.idx, | |
6870 | sae_data, sae_data_len); | |
6871 | wdev_unlock(dev->ieee80211_ptr); | |
6872 | return err; | |
636a5d36 JM |
6873 | } |
6874 | ||
c0692b8f JB |
6875 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6876 | struct genl_info *info, | |
3dc27d25 JB |
6877 | struct cfg80211_crypto_settings *settings, |
6878 | int cipher_limit) | |
b23aa676 | 6879 | { |
c0b2bbd8 JB |
6880 | memset(settings, 0, sizeof(*settings)); |
6881 | ||
b23aa676 SO |
6882 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6883 | ||
c0692b8f JB |
6884 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6885 | u16 proto; | |
6886 | proto = nla_get_u16( | |
6887 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6888 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6889 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6890 | proto != ETH_P_PAE) | |
6891 | return -EINVAL; | |
6892 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6893 | settings->control_port_no_encrypt = true; | |
6894 | } else | |
6895 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6896 | ||
b23aa676 SO |
6897 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6898 | void *data; | |
6899 | int len, i; | |
6900 | ||
6901 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6902 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6903 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6904 | ||
6905 | if (len % sizeof(u32)) | |
6906 | return -EINVAL; | |
6907 | ||
3dc27d25 | 6908 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6909 | return -EINVAL; |
6910 | ||
6911 | memcpy(settings->ciphers_pairwise, data, len); | |
6912 | ||
6913 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6914 | if (!cfg80211_supported_cipher_suite( |
6915 | &rdev->wiphy, | |
b23aa676 SO |
6916 | settings->ciphers_pairwise[i])) |
6917 | return -EINVAL; | |
6918 | } | |
6919 | ||
6920 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6921 | settings->cipher_group = | |
6922 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6923 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6924 | settings->cipher_group)) | |
b23aa676 SO |
6925 | return -EINVAL; |
6926 | } | |
6927 | ||
6928 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6929 | settings->wpa_versions = | |
6930 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6931 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6932 | return -EINVAL; | |
6933 | } | |
6934 | ||
6935 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6936 | void *data; | |
6d30240e | 6937 | int len; |
b23aa676 SO |
6938 | |
6939 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6940 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6941 | settings->n_akm_suites = len / sizeof(u32); | |
6942 | ||
6943 | if (len % sizeof(u32)) | |
6944 | return -EINVAL; | |
6945 | ||
1b9ca027 JM |
6946 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6947 | return -EINVAL; | |
6948 | ||
b23aa676 | 6949 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6950 | } |
6951 | ||
6952 | return 0; | |
6953 | } | |
6954 | ||
636a5d36 JM |
6955 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6956 | { | |
4c476991 JB |
6957 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6958 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6959 | struct ieee80211_channel *chan; |
f62fab73 JB |
6960 | struct cfg80211_assoc_request req = {}; |
6961 | const u8 *bssid, *ssid; | |
6962 | int err, ssid_len = 0; | |
636a5d36 | 6963 | |
f4a11bb0 JB |
6964 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6965 | return -EINVAL; | |
6966 | ||
6967 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6968 | !info->attrs[NL80211_ATTR_SSID] || |
6969 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6970 | return -EINVAL; |
6971 | ||
4c476991 JB |
6972 | if (!rdev->ops->assoc) |
6973 | return -EOPNOTSUPP; | |
636a5d36 | 6974 | |
074ac8df | 6975 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6976 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6977 | return -EOPNOTSUPP; | |
eec60b03 | 6978 | |
19957bb3 | 6979 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6980 | |
664834de JM |
6981 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6982 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6983 | if (!chan) | |
4c476991 | 6984 | return -EINVAL; |
636a5d36 | 6985 | |
19957bb3 JB |
6986 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6987 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6988 | |
6989 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6990 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6991 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6992 | } |
6993 | ||
dc6382ce | 6994 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6995 | enum nl80211_mfp mfp = |
dc6382ce | 6996 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6997 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6998 | req.use_mfp = true; |
4c476991 JB |
6999 | else if (mfp != NL80211_MFP_NO) |
7000 | return -EINVAL; | |
dc6382ce JM |
7001 | } |
7002 | ||
3e5d7649 | 7003 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 7004 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 7005 | |
7e7c8926 | 7006 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 7007 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
7008 | |
7009 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
7010 | memcpy(&req.ht_capa_mask, |
7011 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7012 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
7013 | |
7014 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 7015 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 7016 | return -EINVAL; |
f62fab73 JB |
7017 | memcpy(&req.ht_capa, |
7018 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7019 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
7020 | } |
7021 | ||
ee2aca34 | 7022 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 7023 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
7024 | |
7025 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
7026 | memcpy(&req.vht_capa_mask, |
7027 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7028 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
7029 | |
7030 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 7031 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 7032 | return -EINVAL; |
f62fab73 JB |
7033 | memcpy(&req.vht_capa, |
7034 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7035 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
7036 | } |
7037 | ||
bab5ab7d AK |
7038 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7039 | if (!(rdev->wiphy.features & | |
7040 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7041 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7042 | return -EINVAL; | |
7043 | req.flags |= ASSOC_REQ_USE_RRM; | |
7044 | } | |
7045 | ||
f62fab73 | 7046 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
7047 | if (!err) { |
7048 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
7049 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
7050 | ssid, ssid_len, &req); | |
91bf9b26 JB |
7051 | wdev_unlock(dev->ieee80211_ptr); |
7052 | } | |
636a5d36 | 7053 | |
636a5d36 JM |
7054 | return err; |
7055 | } | |
7056 | ||
7057 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
7058 | { | |
4c476991 JB |
7059 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7060 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7061 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7062 | int ie_len = 0, err; |
19957bb3 | 7063 | u16 reason_code; |
d5cdfacb | 7064 | bool local_state_change; |
636a5d36 | 7065 | |
f4a11bb0 JB |
7066 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7067 | return -EINVAL; | |
7068 | ||
7069 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7070 | return -EINVAL; | |
7071 | ||
7072 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7073 | return -EINVAL; | |
7074 | ||
4c476991 JB |
7075 | if (!rdev->ops->deauth) |
7076 | return -EOPNOTSUPP; | |
636a5d36 | 7077 | |
074ac8df | 7078 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7079 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7080 | return -EOPNOTSUPP; | |
eec60b03 | 7081 | |
19957bb3 | 7082 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7083 | |
19957bb3 JB |
7084 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7085 | if (reason_code == 0) { | |
f4a11bb0 | 7086 | /* Reason Code 0 is reserved */ |
4c476991 | 7087 | return -EINVAL; |
255e737e | 7088 | } |
636a5d36 JM |
7089 | |
7090 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7091 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7092 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7093 | } |
7094 | ||
d5cdfacb JM |
7095 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7096 | ||
91bf9b26 JB |
7097 | wdev_lock(dev->ieee80211_ptr); |
7098 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
7099 | local_state_change); | |
7100 | wdev_unlock(dev->ieee80211_ptr); | |
7101 | return err; | |
636a5d36 JM |
7102 | } |
7103 | ||
7104 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
7105 | { | |
4c476991 JB |
7106 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7107 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7108 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7109 | int ie_len = 0, err; |
19957bb3 | 7110 | u16 reason_code; |
d5cdfacb | 7111 | bool local_state_change; |
636a5d36 | 7112 | |
f4a11bb0 JB |
7113 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7114 | return -EINVAL; | |
7115 | ||
7116 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7117 | return -EINVAL; | |
7118 | ||
7119 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7120 | return -EINVAL; | |
7121 | ||
4c476991 JB |
7122 | if (!rdev->ops->disassoc) |
7123 | return -EOPNOTSUPP; | |
636a5d36 | 7124 | |
074ac8df | 7125 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7126 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7127 | return -EOPNOTSUPP; | |
eec60b03 | 7128 | |
19957bb3 | 7129 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7130 | |
19957bb3 JB |
7131 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7132 | if (reason_code == 0) { | |
f4a11bb0 | 7133 | /* Reason Code 0 is reserved */ |
4c476991 | 7134 | return -EINVAL; |
255e737e | 7135 | } |
636a5d36 JM |
7136 | |
7137 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7138 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7139 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7140 | } |
7141 | ||
d5cdfacb JM |
7142 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7143 | ||
91bf9b26 JB |
7144 | wdev_lock(dev->ieee80211_ptr); |
7145 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
7146 | local_state_change); | |
7147 | wdev_unlock(dev->ieee80211_ptr); | |
7148 | return err; | |
636a5d36 JM |
7149 | } |
7150 | ||
dd5b4cc7 FF |
7151 | static bool |
7152 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
7153 | int mcast_rate[IEEE80211_NUM_BANDS], | |
7154 | int rateval) | |
7155 | { | |
7156 | struct wiphy *wiphy = &rdev->wiphy; | |
7157 | bool found = false; | |
7158 | int band, i; | |
7159 | ||
7160 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
7161 | struct ieee80211_supported_band *sband; | |
7162 | ||
7163 | sband = wiphy->bands[band]; | |
7164 | if (!sband) | |
7165 | continue; | |
7166 | ||
7167 | for (i = 0; i < sband->n_bitrates; i++) { | |
7168 | if (sband->bitrates[i].bitrate == rateval) { | |
7169 | mcast_rate[band] = i + 1; | |
7170 | found = true; | |
7171 | break; | |
7172 | } | |
7173 | } | |
7174 | } | |
7175 | ||
7176 | return found; | |
7177 | } | |
7178 | ||
04a773ad JB |
7179 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
7180 | { | |
4c476991 JB |
7181 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7182 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
7183 | struct cfg80211_ibss_params ibss; |
7184 | struct wiphy *wiphy; | |
fffd0934 | 7185 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
7186 | int err; |
7187 | ||
8e30bc55 JB |
7188 | memset(&ibss, 0, sizeof(ibss)); |
7189 | ||
04a773ad JB |
7190 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7191 | return -EINVAL; | |
7192 | ||
683b6d3b | 7193 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
7194 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
7195 | return -EINVAL; | |
7196 | ||
8e30bc55 JB |
7197 | ibss.beacon_interval = 100; |
7198 | ||
7199 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
7200 | ibss.beacon_interval = | |
7201 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7202 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
7203 | return -EINVAL; | |
7204 | } | |
7205 | ||
4c476991 JB |
7206 | if (!rdev->ops->join_ibss) |
7207 | return -EOPNOTSUPP; | |
04a773ad | 7208 | |
4c476991 JB |
7209 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7210 | return -EOPNOTSUPP; | |
04a773ad | 7211 | |
79c97e97 | 7212 | wiphy = &rdev->wiphy; |
04a773ad | 7213 | |
39193498 | 7214 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 7215 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
7216 | |
7217 | if (!is_valid_ether_addr(ibss.bssid)) | |
7218 | return -EINVAL; | |
7219 | } | |
04a773ad JB |
7220 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7221 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7222 | ||
7223 | if (info->attrs[NL80211_ATTR_IE]) { | |
7224 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7225 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7226 | } | |
7227 | ||
683b6d3b JB |
7228 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
7229 | if (err) | |
7230 | return err; | |
04a773ad | 7231 | |
174e0cd2 IP |
7232 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
7233 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
7234 | return -EINVAL; |
7235 | ||
2f301ab2 | 7236 | switch (ibss.chandef.width) { |
bf372645 SW |
7237 | case NL80211_CHAN_WIDTH_5: |
7238 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
7239 | case NL80211_CHAN_WIDTH_20_NOHT: |
7240 | break; | |
7241 | case NL80211_CHAN_WIDTH_20: | |
7242 | case NL80211_CHAN_WIDTH_40: | |
7243 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | |
7244 | break; | |
7245 | default: | |
c04d6150 | 7246 | return -EINVAL; |
2f301ab2 | 7247 | } |
db9c64cf | 7248 | |
04a773ad | 7249 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
7250 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
7251 | ||
fbd2c8dc TP |
7252 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
7253 | u8 *rates = | |
7254 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7255 | int n_rates = | |
7256 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7257 | struct ieee80211_supported_band *sband = | |
683b6d3b | 7258 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 7259 | |
34850ab2 JB |
7260 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
7261 | &ibss.basic_rates); | |
7262 | if (err) | |
7263 | return err; | |
fbd2c8dc | 7264 | } |
dd5b4cc7 | 7265 | |
803768f5 SW |
7266 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7267 | memcpy(&ibss.ht_capa_mask, | |
7268 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7269 | sizeof(ibss.ht_capa_mask)); | |
7270 | ||
7271 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
7272 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7273 | return -EINVAL; | |
7274 | memcpy(&ibss.ht_capa, | |
7275 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7276 | sizeof(ibss.ht_capa)); | |
7277 | } | |
7278 | ||
dd5b4cc7 FF |
7279 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7280 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
7281 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7282 | return -EINVAL; | |
fbd2c8dc | 7283 | |
4c476991 | 7284 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
7285 | bool no_ht = false; |
7286 | ||
4c476991 | 7287 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
7288 | info->attrs[NL80211_ATTR_KEYS], |
7289 | &no_ht); | |
4c476991 JB |
7290 | if (IS_ERR(connkeys)) |
7291 | return PTR_ERR(connkeys); | |
de7044ee | 7292 | |
3d9d1d66 JB |
7293 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
7294 | no_ht) { | |
de7044ee SM |
7295 | kfree(connkeys); |
7296 | return -EINVAL; | |
7297 | } | |
4c476991 | 7298 | } |
04a773ad | 7299 | |
267335d6 AQ |
7300 | ibss.control_port = |
7301 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
7302 | ||
5336fa88 SW |
7303 | ibss.userspace_handles_dfs = |
7304 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
7305 | ||
4c476991 | 7306 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 | 7307 | if (err) |
b47f610b | 7308 | kzfree(connkeys); |
04a773ad JB |
7309 | return err; |
7310 | } | |
7311 | ||
7312 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
7313 | { | |
4c476991 JB |
7314 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7315 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 7316 | |
4c476991 JB |
7317 | if (!rdev->ops->leave_ibss) |
7318 | return -EOPNOTSUPP; | |
04a773ad | 7319 | |
4c476991 JB |
7320 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7321 | return -EOPNOTSUPP; | |
04a773ad | 7322 | |
4c476991 | 7323 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
7324 | } |
7325 | ||
f4e583c8 AQ |
7326 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
7327 | { | |
7328 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7329 | struct net_device *dev = info->user_ptr[1]; | |
7330 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
7331 | u32 nla_rate; | |
7332 | int err; | |
7333 | ||
7334 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
7335 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
7336 | return -EOPNOTSUPP; | |
7337 | ||
7338 | if (!rdev->ops->set_mcast_rate) | |
7339 | return -EOPNOTSUPP; | |
7340 | ||
7341 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
7342 | ||
7343 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
7344 | return -EINVAL; | |
7345 | ||
7346 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
7347 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
7348 | return -EINVAL; | |
7349 | ||
7350 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
7351 | ||
7352 | return err; | |
7353 | } | |
7354 | ||
ad7e718c JB |
7355 | static struct sk_buff * |
7356 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
7357 | int approxlen, u32 portid, u32 seq, | |
7358 | enum nl80211_commands cmd, | |
567ffc35 JB |
7359 | enum nl80211_attrs attr, |
7360 | const struct nl80211_vendor_cmd_info *info, | |
7361 | gfp_t gfp) | |
ad7e718c JB |
7362 | { |
7363 | struct sk_buff *skb; | |
7364 | void *hdr; | |
7365 | struct nlattr *data; | |
7366 | ||
7367 | skb = nlmsg_new(approxlen + 100, gfp); | |
7368 | if (!skb) | |
7369 | return NULL; | |
7370 | ||
7371 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
7372 | if (!hdr) { | |
7373 | kfree_skb(skb); | |
7374 | return NULL; | |
7375 | } | |
7376 | ||
7377 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
7378 | goto nla_put_failure; | |
567ffc35 JB |
7379 | |
7380 | if (info) { | |
7381 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
7382 | info->vendor_id)) | |
7383 | goto nla_put_failure; | |
7384 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
7385 | info->subcmd)) | |
7386 | goto nla_put_failure; | |
7387 | } | |
7388 | ||
ad7e718c JB |
7389 | data = nla_nest_start(skb, attr); |
7390 | ||
7391 | ((void **)skb->cb)[0] = rdev; | |
7392 | ((void **)skb->cb)[1] = hdr; | |
7393 | ((void **)skb->cb)[2] = data; | |
7394 | ||
7395 | return skb; | |
7396 | ||
7397 | nla_put_failure: | |
7398 | kfree_skb(skb); | |
7399 | return NULL; | |
7400 | } | |
f4e583c8 | 7401 | |
e03ad6ea JB |
7402 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
7403 | enum nl80211_commands cmd, | |
7404 | enum nl80211_attrs attr, | |
7405 | int vendor_event_idx, | |
7406 | int approxlen, gfp_t gfp) | |
7407 | { | |
f26cbf40 | 7408 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
7409 | const struct nl80211_vendor_cmd_info *info; |
7410 | ||
7411 | switch (cmd) { | |
7412 | case NL80211_CMD_TESTMODE: | |
7413 | if (WARN_ON(vendor_event_idx != -1)) | |
7414 | return NULL; | |
7415 | info = NULL; | |
7416 | break; | |
7417 | case NL80211_CMD_VENDOR: | |
7418 | if (WARN_ON(vendor_event_idx < 0 || | |
7419 | vendor_event_idx >= wiphy->n_vendor_events)) | |
7420 | return NULL; | |
7421 | info = &wiphy->vendor_events[vendor_event_idx]; | |
7422 | break; | |
7423 | default: | |
7424 | WARN_ON(1); | |
7425 | return NULL; | |
7426 | } | |
7427 | ||
7428 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, | |
7429 | cmd, attr, info, gfp); | |
7430 | } | |
7431 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
7432 | ||
7433 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
7434 | { | |
7435 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
7436 | void *hdr = ((void **)skb->cb)[1]; | |
7437 | struct nlattr *data = ((void **)skb->cb)[2]; | |
7438 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
7439 | ||
bd8c78e7 JB |
7440 | /* clear CB data for netlink core to own from now on */ |
7441 | memset(skb->cb, 0, sizeof(skb->cb)); | |
7442 | ||
e03ad6ea JB |
7443 | nla_nest_end(skb, data); |
7444 | genlmsg_end(skb, hdr); | |
7445 | ||
7446 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
7447 | mcgrp = NL80211_MCGRP_VENDOR; | |
7448 | ||
7449 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
7450 | mcgrp, gfp); | |
7451 | } | |
7452 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
7453 | ||
aff89a9b | 7454 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
7455 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
7456 | { | |
4c476991 | 7457 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
7458 | struct wireless_dev *wdev = |
7459 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
7460 | int err; |
7461 | ||
fc73f11f DS |
7462 | if (!rdev->ops->testmode_cmd) |
7463 | return -EOPNOTSUPP; | |
7464 | ||
7465 | if (IS_ERR(wdev)) { | |
7466 | err = PTR_ERR(wdev); | |
7467 | if (err != -EINVAL) | |
7468 | return err; | |
7469 | wdev = NULL; | |
7470 | } else if (wdev->wiphy != &rdev->wiphy) { | |
7471 | return -EINVAL; | |
7472 | } | |
7473 | ||
aff89a9b JB |
7474 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
7475 | return -EINVAL; | |
7476 | ||
ad7e718c | 7477 | rdev->cur_cmd_info = info; |
fc73f11f | 7478 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
7479 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
7480 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 7481 | rdev->cur_cmd_info = NULL; |
aff89a9b | 7482 | |
aff89a9b JB |
7483 | return err; |
7484 | } | |
7485 | ||
71063f0e WYG |
7486 | static int nl80211_testmode_dump(struct sk_buff *skb, |
7487 | struct netlink_callback *cb) | |
7488 | { | |
00918d33 | 7489 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
7490 | int err; |
7491 | long phy_idx; | |
7492 | void *data = NULL; | |
7493 | int data_len = 0; | |
7494 | ||
5fe231e8 JB |
7495 | rtnl_lock(); |
7496 | ||
71063f0e WYG |
7497 | if (cb->args[0]) { |
7498 | /* | |
7499 | * 0 is a valid index, but not valid for args[0], | |
7500 | * so we need to offset by 1. | |
7501 | */ | |
7502 | phy_idx = cb->args[0] - 1; | |
7503 | } else { | |
7504 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
7505 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
7506 | nl80211_policy); | |
7507 | if (err) | |
5fe231e8 | 7508 | goto out_err; |
00918d33 | 7509 | |
2bd7e35d JB |
7510 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
7511 | nl80211_fam.attrbuf); | |
7512 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
7513 | err = PTR_ERR(rdev); |
7514 | goto out_err; | |
00918d33 | 7515 | } |
2bd7e35d JB |
7516 | phy_idx = rdev->wiphy_idx; |
7517 | rdev = NULL; | |
2bd7e35d | 7518 | |
71063f0e WYG |
7519 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
7520 | cb->args[1] = | |
7521 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
7522 | } | |
7523 | ||
7524 | if (cb->args[1]) { | |
7525 | data = nla_data((void *)cb->args[1]); | |
7526 | data_len = nla_len((void *)cb->args[1]); | |
7527 | } | |
7528 | ||
00918d33 JB |
7529 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
7530 | if (!rdev) { | |
5fe231e8 JB |
7531 | err = -ENOENT; |
7532 | goto out_err; | |
71063f0e | 7533 | } |
71063f0e | 7534 | |
00918d33 | 7535 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
7536 | err = -EOPNOTSUPP; |
7537 | goto out_err; | |
7538 | } | |
7539 | ||
7540 | while (1) { | |
15e47304 | 7541 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
7542 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
7543 | NL80211_CMD_TESTMODE); | |
7544 | struct nlattr *tmdata; | |
7545 | ||
cb35fba3 DC |
7546 | if (!hdr) |
7547 | break; | |
7548 | ||
9360ffd1 | 7549 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
7550 | genlmsg_cancel(skb, hdr); |
7551 | break; | |
7552 | } | |
7553 | ||
7554 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
7555 | if (!tmdata) { | |
7556 | genlmsg_cancel(skb, hdr); | |
7557 | break; | |
7558 | } | |
e35e4d28 | 7559 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
7560 | nla_nest_end(skb, tmdata); |
7561 | ||
7562 | if (err == -ENOBUFS || err == -ENOENT) { | |
7563 | genlmsg_cancel(skb, hdr); | |
7564 | break; | |
7565 | } else if (err) { | |
7566 | genlmsg_cancel(skb, hdr); | |
7567 | goto out_err; | |
7568 | } | |
7569 | ||
7570 | genlmsg_end(skb, hdr); | |
7571 | } | |
7572 | ||
7573 | err = skb->len; | |
7574 | /* see above */ | |
7575 | cb->args[0] = phy_idx + 1; | |
7576 | out_err: | |
5fe231e8 | 7577 | rtnl_unlock(); |
71063f0e WYG |
7578 | return err; |
7579 | } | |
aff89a9b JB |
7580 | #endif |
7581 | ||
b23aa676 SO |
7582 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
7583 | { | |
4c476991 JB |
7584 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7585 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
7586 | struct cfg80211_connect_params connect; |
7587 | struct wiphy *wiphy; | |
fffd0934 | 7588 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
7589 | int err; |
7590 | ||
7591 | memset(&connect, 0, sizeof(connect)); | |
7592 | ||
7593 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
7594 | return -EINVAL; | |
7595 | ||
7596 | if (!info->attrs[NL80211_ATTR_SSID] || | |
7597 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
7598 | return -EINVAL; | |
7599 | ||
7600 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
7601 | connect.auth_type = | |
7602 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
7603 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
7604 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
7605 | return -EINVAL; |
7606 | } else | |
7607 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
7608 | ||
7609 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
7610 | ||
c0692b8f | 7611 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 7612 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
7613 | if (err) |
7614 | return err; | |
b23aa676 | 7615 | |
074ac8df | 7616 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7617 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7618 | return -EOPNOTSUPP; | |
b23aa676 | 7619 | |
79c97e97 | 7620 | wiphy = &rdev->wiphy; |
b23aa676 | 7621 | |
4486ea98 BS |
7622 | connect.bg_scan_period = -1; |
7623 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
7624 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
7625 | connect.bg_scan_period = | |
7626 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
7627 | } | |
7628 | ||
b23aa676 SO |
7629 | if (info->attrs[NL80211_ATTR_MAC]) |
7630 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
7631 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
7632 | connect.bssid_hint = | |
7633 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
7634 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7635 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7636 | ||
7637 | if (info->attrs[NL80211_ATTR_IE]) { | |
7638 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7639 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7640 | } | |
7641 | ||
cee00a95 JM |
7642 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
7643 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
7644 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
7645 | connect.mfp != NL80211_MFP_NO) | |
7646 | return -EINVAL; | |
7647 | } else { | |
7648 | connect.mfp = NL80211_MFP_NO; | |
7649 | } | |
7650 | ||
b23aa676 | 7651 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
7652 | connect.channel = nl80211_get_valid_chan( |
7653 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7654 | if (!connect.channel) | |
1df4a510 JM |
7655 | return -EINVAL; |
7656 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
7657 | connect.channel_hint = nl80211_get_valid_chan( |
7658 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
7659 | if (!connect.channel_hint) | |
4c476991 | 7660 | return -EINVAL; |
b23aa676 SO |
7661 | } |
7662 | ||
fffd0934 JB |
7663 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
7664 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 7665 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
7666 | if (IS_ERR(connkeys)) |
7667 | return PTR_ERR(connkeys); | |
fffd0934 JB |
7668 | } |
7669 | ||
7e7c8926 BG |
7670 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
7671 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
7672 | ||
7673 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7674 | memcpy(&connect.ht_capa_mask, | |
7675 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7676 | sizeof(connect.ht_capa_mask)); | |
7677 | ||
7678 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e | 7679 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
b47f610b | 7680 | kzfree(connkeys); |
7e7c8926 | 7681 | return -EINVAL; |
b4e4f47e | 7682 | } |
7e7c8926 BG |
7683 | memcpy(&connect.ht_capa, |
7684 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7685 | sizeof(connect.ht_capa)); | |
7686 | } | |
7687 | ||
ee2aca34 JB |
7688 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
7689 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
7690 | ||
7691 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
7692 | memcpy(&connect.vht_capa_mask, | |
7693 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7694 | sizeof(connect.vht_capa_mask)); | |
7695 | ||
7696 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
7697 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
b47f610b | 7698 | kzfree(connkeys); |
ee2aca34 JB |
7699 | return -EINVAL; |
7700 | } | |
7701 | memcpy(&connect.vht_capa, | |
7702 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7703 | sizeof(connect.vht_capa)); | |
7704 | } | |
7705 | ||
bab5ab7d AK |
7706 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7707 | if (!(rdev->wiphy.features & | |
7708 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7709 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7710 | return -EINVAL; | |
7711 | connect.flags |= ASSOC_REQ_USE_RRM; | |
7712 | } | |
7713 | ||
83739b03 JB |
7714 | wdev_lock(dev->ieee80211_ptr); |
7715 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
7716 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 | 7717 | if (err) |
b47f610b | 7718 | kzfree(connkeys); |
b23aa676 SO |
7719 | return err; |
7720 | } | |
7721 | ||
7722 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
7723 | { | |
4c476991 JB |
7724 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7725 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 7726 | u16 reason; |
83739b03 | 7727 | int ret; |
b23aa676 SO |
7728 | |
7729 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7730 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
7731 | else | |
7732 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
7733 | ||
7734 | if (reason == 0) | |
7735 | return -EINVAL; | |
7736 | ||
074ac8df | 7737 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7738 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7739 | return -EOPNOTSUPP; | |
b23aa676 | 7740 | |
83739b03 JB |
7741 | wdev_lock(dev->ieee80211_ptr); |
7742 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
7743 | wdev_unlock(dev->ieee80211_ptr); | |
7744 | return ret; | |
b23aa676 SO |
7745 | } |
7746 | ||
463d0183 JB |
7747 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
7748 | { | |
4c476991 | 7749 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
7750 | struct net *net; |
7751 | int err; | |
7752 | u32 pid; | |
7753 | ||
7754 | if (!info->attrs[NL80211_ATTR_PID]) | |
7755 | return -EINVAL; | |
7756 | ||
7757 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
7758 | ||
463d0183 | 7759 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
7760 | if (IS_ERR(net)) |
7761 | return PTR_ERR(net); | |
463d0183 JB |
7762 | |
7763 | err = 0; | |
7764 | ||
7765 | /* check if anything to do */ | |
4c476991 JB |
7766 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
7767 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 7768 | |
463d0183 | 7769 | put_net(net); |
463d0183 JB |
7770 | return err; |
7771 | } | |
7772 | ||
67fbb16b SO |
7773 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
7774 | { | |
4c476991 | 7775 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
7776 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
7777 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 7778 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
7779 | struct cfg80211_pmksa pmksa; |
7780 | ||
7781 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
7782 | ||
7783 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7784 | return -EINVAL; | |
7785 | ||
7786 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
7787 | return -EINVAL; | |
7788 | ||
67fbb16b SO |
7789 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
7790 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7791 | ||
074ac8df | 7792 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7793 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7794 | return -EOPNOTSUPP; | |
67fbb16b SO |
7795 | |
7796 | switch (info->genlhdr->cmd) { | |
7797 | case NL80211_CMD_SET_PMKSA: | |
7798 | rdev_ops = rdev->ops->set_pmksa; | |
7799 | break; | |
7800 | case NL80211_CMD_DEL_PMKSA: | |
7801 | rdev_ops = rdev->ops->del_pmksa; | |
7802 | break; | |
7803 | default: | |
7804 | WARN_ON(1); | |
7805 | break; | |
7806 | } | |
7807 | ||
4c476991 JB |
7808 | if (!rdev_ops) |
7809 | return -EOPNOTSUPP; | |
67fbb16b | 7810 | |
4c476991 | 7811 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
7812 | } |
7813 | ||
7814 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
7815 | { | |
4c476991 JB |
7816 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7817 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 7818 | |
074ac8df | 7819 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7820 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7821 | return -EOPNOTSUPP; | |
67fbb16b | 7822 | |
4c476991 JB |
7823 | if (!rdev->ops->flush_pmksa) |
7824 | return -EOPNOTSUPP; | |
67fbb16b | 7825 | |
e35e4d28 | 7826 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
7827 | } |
7828 | ||
109086ce AN |
7829 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
7830 | { | |
7831 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7832 | struct net_device *dev = info->user_ptr[1]; | |
7833 | u8 action_code, dialog_token; | |
df942e7b | 7834 | u32 peer_capability = 0; |
109086ce AN |
7835 | u16 status_code; |
7836 | u8 *peer; | |
31fa97c5 | 7837 | bool initiator; |
109086ce AN |
7838 | |
7839 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7840 | !rdev->ops->tdls_mgmt) | |
7841 | return -EOPNOTSUPP; | |
7842 | ||
7843 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
7844 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
7845 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
7846 | !info->attrs[NL80211_ATTR_IE] || | |
7847 | !info->attrs[NL80211_ATTR_MAC]) | |
7848 | return -EINVAL; | |
7849 | ||
7850 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7851 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
7852 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
7853 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 7854 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
7855 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
7856 | peer_capability = | |
7857 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 7858 | |
e35e4d28 | 7859 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 7860 | dialog_token, status_code, peer_capability, |
31fa97c5 | 7861 | initiator, |
e35e4d28 HG |
7862 | nla_data(info->attrs[NL80211_ATTR_IE]), |
7863 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
7864 | } |
7865 | ||
7866 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
7867 | { | |
7868 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7869 | struct net_device *dev = info->user_ptr[1]; | |
7870 | enum nl80211_tdls_operation operation; | |
7871 | u8 *peer; | |
7872 | ||
7873 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7874 | !rdev->ops->tdls_oper) | |
7875 | return -EOPNOTSUPP; | |
7876 | ||
7877 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
7878 | !info->attrs[NL80211_ATTR_MAC]) | |
7879 | return -EINVAL; | |
7880 | ||
7881 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
7882 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7883 | ||
e35e4d28 | 7884 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
7885 | } |
7886 | ||
9588bbd5 JM |
7887 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
7888 | struct genl_info *info) | |
7889 | { | |
4c476991 | 7890 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7891 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7892 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
7893 | struct sk_buff *msg; |
7894 | void *hdr; | |
7895 | u64 cookie; | |
683b6d3b | 7896 | u32 duration; |
9588bbd5 JM |
7897 | int err; |
7898 | ||
7899 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7900 | !info->attrs[NL80211_ATTR_DURATION]) | |
7901 | return -EINVAL; | |
7902 | ||
7903 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
7904 | ||
ebf348fc JB |
7905 | if (!rdev->ops->remain_on_channel || |
7906 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
7907 | return -EOPNOTSUPP; | |
7908 | ||
9588bbd5 | 7909 | /* |
ebf348fc JB |
7910 | * We should be on that channel for at least a minimum amount of |
7911 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 7912 | */ |
ebf348fc | 7913 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 7914 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
7915 | return -EINVAL; |
7916 | ||
683b6d3b JB |
7917 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7918 | if (err) | |
7919 | return err; | |
9588bbd5 JM |
7920 | |
7921 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7922 | if (!msg) |
7923 | return -ENOMEM; | |
9588bbd5 | 7924 | |
15e47304 | 7925 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 7926 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
7927 | if (!hdr) { |
7928 | err = -ENOBUFS; | |
9588bbd5 JM |
7929 | goto free_msg; |
7930 | } | |
7931 | ||
683b6d3b JB |
7932 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7933 | duration, &cookie); | |
9588bbd5 JM |
7934 | |
7935 | if (err) | |
7936 | goto free_msg; | |
7937 | ||
9360ffd1 DM |
7938 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7939 | goto nla_put_failure; | |
9588bbd5 JM |
7940 | |
7941 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7942 | |
7943 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7944 | |
7945 | nla_put_failure: | |
7946 | err = -ENOBUFS; | |
7947 | free_msg: | |
7948 | nlmsg_free(msg); | |
9588bbd5 JM |
7949 | return err; |
7950 | } | |
7951 | ||
7952 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
7953 | struct genl_info *info) | |
7954 | { | |
4c476991 | 7955 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7956 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 7957 | u64 cookie; |
9588bbd5 JM |
7958 | |
7959 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7960 | return -EINVAL; | |
7961 | ||
4c476991 JB |
7962 | if (!rdev->ops->cancel_remain_on_channel) |
7963 | return -EOPNOTSUPP; | |
9588bbd5 | 7964 | |
9588bbd5 JM |
7965 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
7966 | ||
e35e4d28 | 7967 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
7968 | } |
7969 | ||
13ae75b1 JM |
7970 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
7971 | u8 *rates, u8 rates_len) | |
7972 | { | |
7973 | u8 i; | |
7974 | u32 mask = 0; | |
7975 | ||
7976 | for (i = 0; i < rates_len; i++) { | |
7977 | int rate = (rates[i] & 0x7f) * 5; | |
7978 | int ridx; | |
7979 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
7980 | struct ieee80211_rate *srate = | |
7981 | &sband->bitrates[ridx]; | |
7982 | if (rate == srate->bitrate) { | |
7983 | mask |= 1 << ridx; | |
7984 | break; | |
7985 | } | |
7986 | } | |
7987 | if (ridx == sband->n_bitrates) | |
7988 | return 0; /* rate not found */ | |
7989 | } | |
7990 | ||
7991 | return mask; | |
7992 | } | |
7993 | ||
24db78c0 SW |
7994 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
7995 | u8 *rates, u8 rates_len, | |
7996 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
7997 | { | |
7998 | u8 i; | |
7999 | ||
8000 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
8001 | ||
8002 | for (i = 0; i < rates_len; i++) { | |
8003 | int ridx, rbit; | |
8004 | ||
8005 | ridx = rates[i] / 8; | |
8006 | rbit = BIT(rates[i] % 8); | |
8007 | ||
8008 | /* check validity */ | |
910570b5 | 8009 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
8010 | return false; |
8011 | ||
8012 | /* check availability */ | |
8013 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
8014 | mcs[ridx] |= rbit; | |
8015 | else | |
8016 | return false; | |
8017 | } | |
8018 | ||
8019 | return true; | |
8020 | } | |
8021 | ||
204e35a9 JD |
8022 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
8023 | { | |
8024 | u16 mcs_mask = 0; | |
8025 | ||
8026 | switch (vht_mcs_map) { | |
8027 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
8028 | break; | |
8029 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
8030 | mcs_mask = 0x00FF; | |
8031 | break; | |
8032 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
8033 | mcs_mask = 0x01FF; | |
8034 | break; | |
8035 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
8036 | mcs_mask = 0x03FF; | |
8037 | break; | |
8038 | default: | |
8039 | break; | |
8040 | } | |
8041 | ||
8042 | return mcs_mask; | |
8043 | } | |
8044 | ||
8045 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
8046 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
8047 | { | |
8048 | u8 nss; | |
8049 | ||
8050 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
8051 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
8052 | vht_mcs_map >>= 2; | |
8053 | } | |
8054 | } | |
8055 | ||
8056 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
8057 | struct nl80211_txrate_vht *txrate, | |
8058 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
8059 | { | |
8060 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8061 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
8062 | u8 i; | |
8063 | ||
8064 | if (!sband->vht_cap.vht_supported) | |
8065 | return false; | |
8066 | ||
8067 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
8068 | ||
8069 | /* Build vht_mcs_mask from VHT capabilities */ | |
8070 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
8071 | ||
8072 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
8073 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
8074 | mcs[i] = txrate->mcs[i]; | |
8075 | else | |
8076 | return false; | |
8077 | } | |
8078 | ||
8079 | return true; | |
8080 | } | |
8081 | ||
b54452b0 | 8082 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
8083 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
8084 | .len = NL80211_MAX_SUPP_RATES }, | |
d1e33e65 JD |
8085 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
8086 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
204e35a9 | 8087 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
0b9323f6 | 8088 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
13ae75b1 JM |
8089 | }; |
8090 | ||
8091 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
8092 | struct genl_info *info) | |
8093 | { | |
8094 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 8095 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 8096 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
8097 | int rem, i; |
8098 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
8099 | struct nlattr *tx_rates; |
8100 | struct ieee80211_supported_band *sband; | |
204e35a9 | 8101 | u16 vht_tx_mcs_map; |
13ae75b1 | 8102 | |
4c476991 JB |
8103 | if (!rdev->ops->set_bitrate_mask) |
8104 | return -EOPNOTSUPP; | |
13ae75b1 JM |
8105 | |
8106 | memset(&mask, 0, sizeof(mask)); | |
8107 | /* Default to all rates enabled */ | |
8108 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
8109 | sband = rdev->wiphy.bands[i]; | |
7869303b JD |
8110 | |
8111 | if (!sband) | |
8112 | continue; | |
8113 | ||
8114 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; | |
d1e33e65 | 8115 | memcpy(mask.control[i].ht_mcs, |
7869303b | 8116 | sband->ht_cap.mcs.rx_mask, |
d1e33e65 | 8117 | sizeof(mask.control[i].ht_mcs)); |
204e35a9 JD |
8118 | |
8119 | if (!sband->vht_cap.vht_supported) | |
8120 | continue; | |
8121 | ||
8122 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8123 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); | |
13ae75b1 JM |
8124 | } |
8125 | ||
b9243ab0 JD |
8126 | /* if no rates are given set it back to the defaults */ |
8127 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
8128 | goto out; | |
8129 | ||
13ae75b1 JM |
8130 | /* |
8131 | * The nested attribute uses enum nl80211_band as the index. This maps | |
8132 | * directly to the enum ieee80211_band values used in cfg80211. | |
8133 | */ | |
24db78c0 | 8134 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
ae811e21 | 8135 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
13ae75b1 | 8136 | enum ieee80211_band band = nla_type(tx_rates); |
ae811e21 JB |
8137 | int err; |
8138 | ||
4c476991 JB |
8139 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
8140 | return -EINVAL; | |
13ae75b1 | 8141 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
8142 | if (sband == NULL) |
8143 | return -EINVAL; | |
ae811e21 JB |
8144 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
8145 | nla_len(tx_rates), nl80211_txattr_policy); | |
8146 | if (err) | |
8147 | return err; | |
13ae75b1 JM |
8148 | if (tb[NL80211_TXRATE_LEGACY]) { |
8149 | mask.control[band].legacy = rateset_to_mask( | |
8150 | sband, | |
8151 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
8152 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
8153 | if ((mask.control[band].legacy == 0) && |
8154 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
8155 | return -EINVAL; | |
24db78c0 | 8156 | } |
d1e33e65 | 8157 | if (tb[NL80211_TXRATE_HT]) { |
24db78c0 SW |
8158 | if (!ht_rateset_to_mask( |
8159 | sband, | |
d1e33e65 JD |
8160 | nla_data(tb[NL80211_TXRATE_HT]), |
8161 | nla_len(tb[NL80211_TXRATE_HT]), | |
8162 | mask.control[band].ht_mcs)) | |
24db78c0 SW |
8163 | return -EINVAL; |
8164 | } | |
204e35a9 JD |
8165 | if (tb[NL80211_TXRATE_VHT]) { |
8166 | if (!vht_set_mcs_mask( | |
8167 | sband, | |
8168 | nla_data(tb[NL80211_TXRATE_VHT]), | |
8169 | mask.control[band].vht_mcs)) | |
8170 | return -EINVAL; | |
8171 | } | |
0b9323f6 JD |
8172 | if (tb[NL80211_TXRATE_GI]) { |
8173 | mask.control[band].gi = | |
8174 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
8175 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
8176 | return -EINVAL; | |
8177 | } | |
24db78c0 SW |
8178 | |
8179 | if (mask.control[band].legacy == 0) { | |
204e35a9 JD |
8180 | /* don't allow empty legacy rates if HT or VHT |
8181 | * are not even supported. | |
8182 | */ | |
8183 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
8184 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
24db78c0 SW |
8185 | return -EINVAL; |
8186 | ||
8187 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
d1e33e65 | 8188 | if (mask.control[band].ht_mcs[i]) |
204e35a9 JD |
8189 | goto out; |
8190 | ||
8191 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
8192 | if (mask.control[band].vht_mcs[i]) | |
8193 | goto out; | |
24db78c0 SW |
8194 | |
8195 | /* legacy and mcs rates may not be both empty */ | |
204e35a9 | 8196 | return -EINVAL; |
13ae75b1 JM |
8197 | } |
8198 | } | |
8199 | ||
b9243ab0 | 8200 | out: |
e35e4d28 | 8201 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
8202 | } |
8203 | ||
2e161f78 | 8204 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8205 | { |
4c476991 | 8206 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8207 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 8208 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
8209 | |
8210 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
8211 | return -EINVAL; | |
8212 | ||
2e161f78 JB |
8213 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
8214 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 8215 | |
71bbc994 JB |
8216 | switch (wdev->iftype) { |
8217 | case NL80211_IFTYPE_STATION: | |
8218 | case NL80211_IFTYPE_ADHOC: | |
8219 | case NL80211_IFTYPE_P2P_CLIENT: | |
8220 | case NL80211_IFTYPE_AP: | |
8221 | case NL80211_IFTYPE_AP_VLAN: | |
8222 | case NL80211_IFTYPE_MESH_POINT: | |
8223 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8224 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8225 | break; |
8226 | default: | |
4c476991 | 8227 | return -EOPNOTSUPP; |
71bbc994 | 8228 | } |
026331c4 JM |
8229 | |
8230 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
8231 | if (!rdev->ops->mgmt_tx) |
8232 | return -EOPNOTSUPP; | |
026331c4 | 8233 | |
15e47304 | 8234 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
8235 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
8236 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
8237 | } |
8238 | ||
2e161f78 | 8239 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8240 | { |
4c476991 | 8241 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8242 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 8243 | struct cfg80211_chan_def chandef; |
026331c4 | 8244 | int err; |
d64d373f | 8245 | void *hdr = NULL; |
026331c4 | 8246 | u64 cookie; |
e247bd90 | 8247 | struct sk_buff *msg = NULL; |
b176e629 AO |
8248 | struct cfg80211_mgmt_tx_params params = { |
8249 | .dont_wait_for_ack = | |
8250 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
8251 | }; | |
026331c4 | 8252 | |
683b6d3b | 8253 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
8254 | return -EINVAL; |
8255 | ||
4c476991 JB |
8256 | if (!rdev->ops->mgmt_tx) |
8257 | return -EOPNOTSUPP; | |
026331c4 | 8258 | |
71bbc994 | 8259 | switch (wdev->iftype) { |
ea141b75 AQ |
8260 | case NL80211_IFTYPE_P2P_DEVICE: |
8261 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
8262 | return -EINVAL; | |
71bbc994 JB |
8263 | case NL80211_IFTYPE_STATION: |
8264 | case NL80211_IFTYPE_ADHOC: | |
8265 | case NL80211_IFTYPE_P2P_CLIENT: | |
8266 | case NL80211_IFTYPE_AP: | |
8267 | case NL80211_IFTYPE_AP_VLAN: | |
8268 | case NL80211_IFTYPE_MESH_POINT: | |
8269 | case NL80211_IFTYPE_P2P_GO: | |
8270 | break; | |
8271 | default: | |
4c476991 | 8272 | return -EOPNOTSUPP; |
71bbc994 | 8273 | } |
026331c4 | 8274 | |
f7ca38df | 8275 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 8276 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 8277 | return -EINVAL; |
b176e629 | 8278 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
8279 | |
8280 | /* | |
8281 | * We should wait on the channel for at least a minimum amount | |
8282 | * of time (10ms) but no longer than the driver supports. | |
8283 | */ | |
b176e629 AO |
8284 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
8285 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc JB |
8286 | return -EINVAL; |
8287 | ||
f7ca38df JB |
8288 | } |
8289 | ||
b176e629 | 8290 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 8291 | |
b176e629 | 8292 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
8293 | return -EINVAL; |
8294 | ||
b176e629 | 8295 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 8296 | |
ea141b75 AQ |
8297 | /* get the channel if any has been specified, otherwise pass NULL to |
8298 | * the driver. The latter will use the current one | |
8299 | */ | |
8300 | chandef.chan = NULL; | |
8301 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
8302 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
8303 | if (err) | |
8304 | return err; | |
8305 | } | |
8306 | ||
b176e629 | 8307 | if (!chandef.chan && params.offchan) |
ea141b75 | 8308 | return -EINVAL; |
026331c4 | 8309 | |
34d22ce2 AO |
8310 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
8311 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
8312 | ||
8313 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
8314 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8315 | int i; | |
8316 | ||
8317 | if (len % sizeof(u16)) | |
8318 | return -EINVAL; | |
8319 | ||
8320 | params.n_csa_offsets = len / sizeof(u16); | |
8321 | params.csa_offsets = | |
8322 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8323 | ||
8324 | /* check that all the offsets fit the frame */ | |
8325 | for (i = 0; i < params.n_csa_offsets; i++) { | |
8326 | if (params.csa_offsets[i] >= params.len) | |
8327 | return -EINVAL; | |
8328 | } | |
8329 | } | |
8330 | ||
b176e629 | 8331 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
8332 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
8333 | if (!msg) | |
8334 | return -ENOMEM; | |
026331c4 | 8335 | |
15e47304 | 8336 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 8337 | NL80211_CMD_FRAME); |
cb35fba3 DC |
8338 | if (!hdr) { |
8339 | err = -ENOBUFS; | |
e247bd90 JB |
8340 | goto free_msg; |
8341 | } | |
026331c4 | 8342 | } |
e247bd90 | 8343 | |
b176e629 AO |
8344 | params.chan = chandef.chan; |
8345 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
8346 | if (err) |
8347 | goto free_msg; | |
8348 | ||
e247bd90 | 8349 | if (msg) { |
9360ffd1 DM |
8350 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8351 | goto nla_put_failure; | |
026331c4 | 8352 | |
e247bd90 JB |
8353 | genlmsg_end(msg, hdr); |
8354 | return genlmsg_reply(msg, info); | |
8355 | } | |
8356 | ||
8357 | return 0; | |
026331c4 JM |
8358 | |
8359 | nla_put_failure: | |
8360 | err = -ENOBUFS; | |
8361 | free_msg: | |
8362 | nlmsg_free(msg); | |
026331c4 JM |
8363 | return err; |
8364 | } | |
8365 | ||
f7ca38df JB |
8366 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
8367 | { | |
8368 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 8369 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
8370 | u64 cookie; |
8371 | ||
8372 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8373 | return -EINVAL; | |
8374 | ||
8375 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
8376 | return -EOPNOTSUPP; | |
8377 | ||
71bbc994 JB |
8378 | switch (wdev->iftype) { |
8379 | case NL80211_IFTYPE_STATION: | |
8380 | case NL80211_IFTYPE_ADHOC: | |
8381 | case NL80211_IFTYPE_P2P_CLIENT: | |
8382 | case NL80211_IFTYPE_AP: | |
8383 | case NL80211_IFTYPE_AP_VLAN: | |
8384 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8385 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8386 | break; |
8387 | default: | |
f7ca38df | 8388 | return -EOPNOTSUPP; |
71bbc994 | 8389 | } |
f7ca38df JB |
8390 | |
8391 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
8392 | ||
e35e4d28 | 8393 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
8394 | } |
8395 | ||
ffb9eb3d KV |
8396 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
8397 | { | |
4c476991 | 8398 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 8399 | struct wireless_dev *wdev; |
4c476991 | 8400 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8401 | u8 ps_state; |
8402 | bool state; | |
8403 | int err; | |
8404 | ||
4c476991 JB |
8405 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
8406 | return -EINVAL; | |
ffb9eb3d KV |
8407 | |
8408 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
8409 | ||
4c476991 JB |
8410 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
8411 | return -EINVAL; | |
ffb9eb3d KV |
8412 | |
8413 | wdev = dev->ieee80211_ptr; | |
8414 | ||
4c476991 JB |
8415 | if (!rdev->ops->set_power_mgmt) |
8416 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8417 | |
8418 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
8419 | ||
8420 | if (state == wdev->ps) | |
4c476991 | 8421 | return 0; |
ffb9eb3d | 8422 | |
e35e4d28 | 8423 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
8424 | if (!err) |
8425 | wdev->ps = state; | |
ffb9eb3d KV |
8426 | return err; |
8427 | } | |
8428 | ||
8429 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
8430 | { | |
4c476991 | 8431 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
8432 | enum nl80211_ps_state ps_state; |
8433 | struct wireless_dev *wdev; | |
4c476991 | 8434 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8435 | struct sk_buff *msg; |
8436 | void *hdr; | |
8437 | int err; | |
8438 | ||
ffb9eb3d KV |
8439 | wdev = dev->ieee80211_ptr; |
8440 | ||
4c476991 JB |
8441 | if (!rdev->ops->set_power_mgmt) |
8442 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8443 | |
8444 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
8445 | if (!msg) |
8446 | return -ENOMEM; | |
ffb9eb3d | 8447 | |
15e47304 | 8448 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
8449 | NL80211_CMD_GET_POWER_SAVE); |
8450 | if (!hdr) { | |
4c476991 | 8451 | err = -ENOBUFS; |
ffb9eb3d KV |
8452 | goto free_msg; |
8453 | } | |
8454 | ||
8455 | if (wdev->ps) | |
8456 | ps_state = NL80211_PS_ENABLED; | |
8457 | else | |
8458 | ps_state = NL80211_PS_DISABLED; | |
8459 | ||
9360ffd1 DM |
8460 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
8461 | goto nla_put_failure; | |
ffb9eb3d KV |
8462 | |
8463 | genlmsg_end(msg, hdr); | |
4c476991 | 8464 | return genlmsg_reply(msg, info); |
ffb9eb3d | 8465 | |
4c476991 | 8466 | nla_put_failure: |
ffb9eb3d | 8467 | err = -ENOBUFS; |
4c476991 | 8468 | free_msg: |
ffb9eb3d | 8469 | nlmsg_free(msg); |
ffb9eb3d KV |
8470 | return err; |
8471 | } | |
8472 | ||
94e860f1 JB |
8473 | static const struct nla_policy |
8474 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
8475 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
8476 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
8477 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
8478 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
8479 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
8480 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
8481 | }; |
8482 | ||
84f10708 | 8483 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 8484 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
8485 | { |
8486 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 8487 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8488 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 8489 | |
d9d8b019 | 8490 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
8491 | return -EINVAL; |
8492 | ||
84f10708 TP |
8493 | if (!rdev->ops->set_cqm_txe_config) |
8494 | return -EOPNOTSUPP; | |
8495 | ||
8496 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
8497 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
8498 | return -EOPNOTSUPP; | |
8499 | ||
e35e4d28 | 8500 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
8501 | } |
8502 | ||
d6dc1a38 JO |
8503 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
8504 | s32 threshold, u32 hysteresis) | |
8505 | { | |
4c476991 | 8506 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 8507 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8508 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
8509 | |
8510 | if (threshold > 0) | |
8511 | return -EINVAL; | |
8512 | ||
1da5fcc8 JB |
8513 | /* disabling - hysteresis should also be zero then */ |
8514 | if (threshold == 0) | |
8515 | hysteresis = 0; | |
d6dc1a38 | 8516 | |
4c476991 JB |
8517 | if (!rdev->ops->set_cqm_rssi_config) |
8518 | return -EOPNOTSUPP; | |
d6dc1a38 | 8519 | |
074ac8df | 8520 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8521 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8522 | return -EOPNOTSUPP; | |
d6dc1a38 | 8523 | |
e35e4d28 | 8524 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
8525 | } |
8526 | ||
8527 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
8528 | { | |
8529 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
8530 | struct nlattr *cqm; | |
8531 | int err; | |
8532 | ||
8533 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
8534 | if (!cqm) |
8535 | return -EINVAL; | |
d6dc1a38 JO |
8536 | |
8537 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
8538 | nl80211_attr_cqm_policy); | |
8539 | if (err) | |
1da5fcc8 | 8540 | return err; |
d6dc1a38 JO |
8541 | |
8542 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
8543 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
8544 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
8545 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 8546 | |
1da5fcc8 JB |
8547 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
8548 | } | |
8549 | ||
8550 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
8551 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
8552 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
8553 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
8554 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
8555 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
8556 | ||
8557 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
8558 | } | |
8559 | ||
8560 | return -EINVAL; | |
d6dc1a38 JO |
8561 | } |
8562 | ||
6e0bd6c3 RL |
8563 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
8564 | { | |
8565 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8566 | struct net_device *dev = info->user_ptr[1]; | |
8567 | struct ocb_setup setup = {}; | |
8568 | int err; | |
8569 | ||
8570 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | |
8571 | if (err) | |
8572 | return err; | |
8573 | ||
8574 | return cfg80211_join_ocb(rdev, dev, &setup); | |
8575 | } | |
8576 | ||
8577 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | |
8578 | { | |
8579 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8580 | struct net_device *dev = info->user_ptr[1]; | |
8581 | ||
8582 | return cfg80211_leave_ocb(rdev, dev); | |
8583 | } | |
8584 | ||
29cbe68c JB |
8585 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
8586 | { | |
8587 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8588 | struct net_device *dev = info->user_ptr[1]; | |
8589 | struct mesh_config cfg; | |
c80d545d | 8590 | struct mesh_setup setup; |
29cbe68c JB |
8591 | int err; |
8592 | ||
8593 | /* start with default */ | |
8594 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 8595 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 8596 | |
24bdd9f4 | 8597 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 8598 | /* and parse parameters if given */ |
24bdd9f4 | 8599 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
8600 | if (err) |
8601 | return err; | |
8602 | } | |
8603 | ||
8604 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
8605 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
8606 | return -EINVAL; | |
8607 | ||
c80d545d JC |
8608 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
8609 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
8610 | ||
4bb62344 CYY |
8611 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8612 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
8613 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8614 | return -EINVAL; | |
8615 | ||
9bdbf04d MP |
8616 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
8617 | setup.beacon_interval = | |
8618 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
8619 | if (setup.beacon_interval < 10 || | |
8620 | setup.beacon_interval > 10000) | |
8621 | return -EINVAL; | |
8622 | } | |
8623 | ||
8624 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
8625 | setup.dtim_period = | |
8626 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
8627 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
8628 | return -EINVAL; | |
8629 | } | |
8630 | ||
c80d545d JC |
8631 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
8632 | /* parse additional setup parameters if given */ | |
8633 | err = nl80211_parse_mesh_setup(info, &setup); | |
8634 | if (err) | |
8635 | return err; | |
8636 | } | |
8637 | ||
d37bb18a TP |
8638 | if (setup.user_mpm) |
8639 | cfg.auto_open_plinks = false; | |
8640 | ||
cc1d2806 | 8641 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
8642 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
8643 | if (err) | |
8644 | return err; | |
cc1d2806 JB |
8645 | } else { |
8646 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 8647 | setup.chandef.chan = NULL; |
cc1d2806 JB |
8648 | } |
8649 | ||
ffb3cf30 AN |
8650 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8651 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8652 | int n_rates = | |
8653 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8654 | struct ieee80211_supported_band *sband; | |
8655 | ||
8656 | if (!setup.chandef.chan) | |
8657 | return -EINVAL; | |
8658 | ||
8659 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
8660 | ||
8661 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
8662 | &setup.basic_rates); | |
8663 | if (err) | |
8664 | return err; | |
8665 | } | |
8666 | ||
c80d545d | 8667 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
8668 | } |
8669 | ||
8670 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
8671 | { | |
8672 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8673 | struct net_device *dev = info->user_ptr[1]; | |
8674 | ||
8675 | return cfg80211_leave_mesh(rdev, dev); | |
8676 | } | |
8677 | ||
dfb89c56 | 8678 | #ifdef CONFIG_PM |
bb92d199 AK |
8679 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
8680 | struct cfg80211_registered_device *rdev) | |
8681 | { | |
6abb9cb9 | 8682 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
8683 | struct nlattr *nl_pats, *nl_pat; |
8684 | int i, pat_len; | |
8685 | ||
6abb9cb9 | 8686 | if (!wowlan->n_patterns) |
bb92d199 AK |
8687 | return 0; |
8688 | ||
8689 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
8690 | if (!nl_pats) | |
8691 | return -ENOBUFS; | |
8692 | ||
6abb9cb9 | 8693 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
8694 | nl_pat = nla_nest_start(msg, i + 1); |
8695 | if (!nl_pat) | |
8696 | return -ENOBUFS; | |
6abb9cb9 | 8697 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 8698 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 8699 | wowlan->patterns[i].mask) || |
50ac6607 AK |
8700 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
8701 | wowlan->patterns[i].pattern) || | |
8702 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 8703 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
8704 | return -ENOBUFS; |
8705 | nla_nest_end(msg, nl_pat); | |
8706 | } | |
8707 | nla_nest_end(msg, nl_pats); | |
8708 | ||
8709 | return 0; | |
8710 | } | |
8711 | ||
2a0e047e JB |
8712 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
8713 | struct cfg80211_wowlan_tcp *tcp) | |
8714 | { | |
8715 | struct nlattr *nl_tcp; | |
8716 | ||
8717 | if (!tcp) | |
8718 | return 0; | |
8719 | ||
8720 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
8721 | if (!nl_tcp) | |
8722 | return -ENOBUFS; | |
8723 | ||
8724 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
8725 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
8726 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
8727 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
8728 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
8729 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
8730 | tcp->payload_len, tcp->payload) || | |
8731 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
8732 | tcp->data_interval) || | |
8733 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
8734 | tcp->wake_len, tcp->wake_data) || | |
8735 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
8736 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
8737 | return -ENOBUFS; | |
8738 | ||
8739 | if (tcp->payload_seq.len && | |
8740 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
8741 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
8742 | return -ENOBUFS; | |
8743 | ||
8744 | if (tcp->payload_tok.len && | |
8745 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
8746 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
8747 | &tcp->payload_tok)) | |
8748 | return -ENOBUFS; | |
8749 | ||
e248ad30 JB |
8750 | nla_nest_end(msg, nl_tcp); |
8751 | ||
2a0e047e JB |
8752 | return 0; |
8753 | } | |
8754 | ||
75453ccb LC |
8755 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
8756 | struct cfg80211_sched_scan_request *req) | |
8757 | { | |
8758 | struct nlattr *nd, *freqs, *matches, *match; | |
8759 | int i; | |
8760 | ||
8761 | if (!req) | |
8762 | return 0; | |
8763 | ||
8764 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); | |
8765 | if (!nd) | |
8766 | return -ENOBUFS; | |
8767 | ||
8768 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, req->interval)) | |
8769 | return -ENOBUFS; | |
8770 | ||
8771 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
8772 | if (!freqs) | |
8773 | return -ENOBUFS; | |
8774 | ||
8775 | for (i = 0; i < req->n_channels; i++) | |
8776 | nla_put_u32(msg, i, req->channels[i]->center_freq); | |
8777 | ||
8778 | nla_nest_end(msg, freqs); | |
8779 | ||
8780 | if (req->n_match_sets) { | |
8781 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); | |
8782 | for (i = 0; i < req->n_match_sets; i++) { | |
8783 | match = nla_nest_start(msg, i); | |
8784 | nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, | |
8785 | req->match_sets[i].ssid.ssid_len, | |
8786 | req->match_sets[i].ssid.ssid); | |
8787 | nla_nest_end(msg, match); | |
8788 | } | |
8789 | nla_nest_end(msg, matches); | |
8790 | } | |
8791 | ||
8792 | nla_nest_end(msg, nd); | |
8793 | ||
8794 | return 0; | |
8795 | } | |
8796 | ||
ff1b6e69 JB |
8797 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
8798 | { | |
8799 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8800 | struct sk_buff *msg; | |
8801 | void *hdr; | |
2a0e047e | 8802 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 8803 | |
964dc9e2 | 8804 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
8805 | return -EOPNOTSUPP; |
8806 | ||
6abb9cb9 | 8807 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 8808 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
8809 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
8810 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
8811 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
8812 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
8813 | } |
8814 | ||
8815 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
8816 | if (!msg) |
8817 | return -ENOMEM; | |
8818 | ||
15e47304 | 8819 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
8820 | NL80211_CMD_GET_WOWLAN); |
8821 | if (!hdr) | |
8822 | goto nla_put_failure; | |
8823 | ||
6abb9cb9 | 8824 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
8825 | struct nlattr *nl_wowlan; |
8826 | ||
8827 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
8828 | if (!nl_wowlan) | |
8829 | goto nla_put_failure; | |
8830 | ||
6abb9cb9 | 8831 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 8832 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 8833 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 8834 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 8835 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 8836 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 8837 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 8838 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 8839 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 8840 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 8841 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 8842 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 8843 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
8844 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
8845 | goto nla_put_failure; | |
2a0e047e | 8846 | |
bb92d199 AK |
8847 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
8848 | goto nla_put_failure; | |
2a0e047e | 8849 | |
6abb9cb9 JB |
8850 | if (nl80211_send_wowlan_tcp(msg, |
8851 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e | 8852 | goto nla_put_failure; |
75453ccb LC |
8853 | |
8854 | if (nl80211_send_wowlan_nd( | |
8855 | msg, | |
8856 | rdev->wiphy.wowlan_config->nd_config)) | |
8857 | goto nla_put_failure; | |
2a0e047e | 8858 | |
ff1b6e69 JB |
8859 | nla_nest_end(msg, nl_wowlan); |
8860 | } | |
8861 | ||
8862 | genlmsg_end(msg, hdr); | |
8863 | return genlmsg_reply(msg, info); | |
8864 | ||
8865 | nla_put_failure: | |
8866 | nlmsg_free(msg); | |
8867 | return -ENOBUFS; | |
8868 | } | |
8869 | ||
2a0e047e JB |
8870 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
8871 | struct nlattr *attr, | |
8872 | struct cfg80211_wowlan *trig) | |
8873 | { | |
8874 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
8875 | struct cfg80211_wowlan_tcp *cfg; | |
8876 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
8877 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
8878 | u32 size; | |
8879 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
8880 | int err, port; | |
8881 | ||
964dc9e2 | 8882 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
8883 | return -EINVAL; |
8884 | ||
8885 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
8886 | nla_data(attr), nla_len(attr), | |
8887 | nl80211_wowlan_tcp_policy); | |
8888 | if (err) | |
8889 | return err; | |
8890 | ||
8891 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
8892 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
8893 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
8894 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
8895 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
8896 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
8897 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
8898 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
8899 | return -EINVAL; | |
8900 | ||
8901 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 8902 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
8903 | return -EINVAL; |
8904 | ||
8905 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 8906 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 8907 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
8908 | return -EINVAL; |
8909 | ||
8910 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 8911 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
8912 | return -EINVAL; |
8913 | ||
8914 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
8915 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
8916 | return -EINVAL; | |
8917 | ||
8918 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
8919 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8920 | ||
8921 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8922 | tokens_size = tokln - sizeof(*tok); | |
8923 | ||
8924 | if (!tok->len || tokens_size % tok->len) | |
8925 | return -EINVAL; | |
964dc9e2 | 8926 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 8927 | return -EINVAL; |
964dc9e2 | 8928 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 8929 | return -EINVAL; |
964dc9e2 | 8930 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 8931 | return -EINVAL; |
964dc9e2 | 8932 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
8933 | return -EINVAL; |
8934 | if (tok->offset + tok->len > data_size) | |
8935 | return -EINVAL; | |
8936 | } | |
8937 | ||
8938 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
8939 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 8940 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
8941 | return -EINVAL; |
8942 | if (seq->len == 0 || seq->len > 4) | |
8943 | return -EINVAL; | |
8944 | if (seq->len + seq->offset > data_size) | |
8945 | return -EINVAL; | |
8946 | } | |
8947 | ||
8948 | size = sizeof(*cfg); | |
8949 | size += data_size; | |
8950 | size += wake_size + wake_mask_size; | |
8951 | size += tokens_size; | |
8952 | ||
8953 | cfg = kzalloc(size, GFP_KERNEL); | |
8954 | if (!cfg) | |
8955 | return -ENOMEM; | |
8956 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
8957 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
8958 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
8959 | ETH_ALEN); | |
8960 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
8961 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
8962 | else | |
8963 | port = 0; | |
8964 | #ifdef CONFIG_INET | |
8965 | /* allocate a socket and port for it and use it */ | |
8966 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
8967 | IPPROTO_TCP, &cfg->sock, 1); | |
8968 | if (err) { | |
8969 | kfree(cfg); | |
8970 | return err; | |
8971 | } | |
8972 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
8973 | sock_release(cfg->sock); | |
8974 | kfree(cfg); | |
8975 | return -EADDRINUSE; | |
8976 | } | |
8977 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
8978 | #else | |
8979 | if (!port) { | |
8980 | kfree(cfg); | |
8981 | return -EINVAL; | |
8982 | } | |
8983 | cfg->src_port = port; | |
8984 | #endif | |
8985 | ||
8986 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
8987 | cfg->payload_len = data_size; | |
8988 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
8989 | memcpy((void *)cfg->payload, | |
8990 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
8991 | data_size); | |
8992 | if (seq) | |
8993 | cfg->payload_seq = *seq; | |
8994 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
8995 | cfg->wake_len = wake_size; | |
8996 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
8997 | memcpy((void *)cfg->wake_data, | |
8998 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
8999 | wake_size); | |
9000 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
9001 | data_size + wake_size; | |
9002 | memcpy((void *)cfg->wake_mask, | |
9003 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
9004 | wake_mask_size); | |
9005 | if (tok) { | |
9006 | cfg->tokens_size = tokens_size; | |
9007 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
9008 | } | |
9009 | ||
9010 | trig->tcp = cfg; | |
9011 | ||
9012 | return 0; | |
9013 | } | |
9014 | ||
8cd4d456 LC |
9015 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
9016 | const struct wiphy_wowlan_support *wowlan, | |
9017 | struct nlattr *attr, | |
9018 | struct cfg80211_wowlan *trig) | |
9019 | { | |
9020 | struct nlattr **tb; | |
9021 | int err; | |
9022 | ||
9023 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); | |
9024 | if (!tb) | |
9025 | return -ENOMEM; | |
9026 | ||
9027 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | |
9028 | err = -EOPNOTSUPP; | |
9029 | goto out; | |
9030 | } | |
9031 | ||
9032 | err = nla_parse(tb, NL80211_ATTR_MAX, | |
9033 | nla_data(attr), nla_len(attr), | |
9034 | nl80211_policy); | |
9035 | if (err) | |
9036 | goto out; | |
9037 | ||
ad2b26ab | 9038 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
8cd4d456 LC |
9039 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
9040 | if (err) | |
9041 | trig->nd_config = NULL; | |
9042 | ||
9043 | out: | |
9044 | kfree(tb); | |
9045 | return err; | |
9046 | } | |
9047 | ||
ff1b6e69 JB |
9048 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
9049 | { | |
9050 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9051 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 9052 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 9053 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 9054 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 9055 | int err, i; |
6abb9cb9 | 9056 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 9057 | |
964dc9e2 | 9058 | if (!wowlan) |
ff1b6e69 JB |
9059 | return -EOPNOTSUPP; |
9060 | ||
ae33bd81 JB |
9061 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
9062 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 9063 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
9064 | goto set_wakeup; |
9065 | } | |
ff1b6e69 JB |
9066 | |
9067 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
9068 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9069 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9070 | nl80211_wowlan_policy); | |
9071 | if (err) | |
9072 | return err; | |
9073 | ||
9074 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
9075 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
9076 | return -EINVAL; | |
9077 | new_triggers.any = true; | |
9078 | } | |
9079 | ||
9080 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
9081 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
9082 | return -EINVAL; | |
9083 | new_triggers.disconnect = true; | |
9084 | } | |
9085 | ||
9086 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
9087 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
9088 | return -EINVAL; | |
9089 | new_triggers.magic_pkt = true; | |
9090 | } | |
9091 | ||
77dbbb13 JB |
9092 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
9093 | return -EINVAL; | |
9094 | ||
9095 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
9096 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
9097 | return -EINVAL; | |
9098 | new_triggers.gtk_rekey_failure = true; | |
9099 | } | |
9100 | ||
9101 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
9102 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
9103 | return -EINVAL; | |
9104 | new_triggers.eap_identity_req = true; | |
9105 | } | |
9106 | ||
9107 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
9108 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
9109 | return -EINVAL; | |
9110 | new_triggers.four_way_handshake = true; | |
9111 | } | |
9112 | ||
9113 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
9114 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
9115 | return -EINVAL; | |
9116 | new_triggers.rfkill_release = true; | |
9117 | } | |
9118 | ||
ff1b6e69 JB |
9119 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
9120 | struct nlattr *pat; | |
9121 | int n_patterns = 0; | |
bb92d199 | 9122 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 9123 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 JB |
9124 | |
9125 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9126 | rem) | |
9127 | n_patterns++; | |
9128 | if (n_patterns > wowlan->n_patterns) | |
9129 | return -EINVAL; | |
9130 | ||
9131 | new_triggers.patterns = kcalloc(n_patterns, | |
9132 | sizeof(new_triggers.patterns[0]), | |
9133 | GFP_KERNEL); | |
9134 | if (!new_triggers.patterns) | |
9135 | return -ENOMEM; | |
9136 | ||
9137 | new_triggers.n_patterns = n_patterns; | |
9138 | i = 0; | |
9139 | ||
9140 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9141 | rem) { | |
922bd80f JB |
9142 | u8 *mask_pat; |
9143 | ||
50ac6607 AK |
9144 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9145 | nla_len(pat), NULL); | |
ff1b6e69 | 9146 | err = -EINVAL; |
50ac6607 AK |
9147 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
9148 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 9149 | goto error; |
50ac6607 | 9150 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 9151 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 9152 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
9153 | goto error; |
9154 | if (pat_len > wowlan->pattern_max_len || | |
9155 | pat_len < wowlan->pattern_min_len) | |
9156 | goto error; | |
9157 | ||
50ac6607 | 9158 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
9159 | pkt_offset = 0; |
9160 | else | |
9161 | pkt_offset = nla_get_u32( | |
50ac6607 | 9162 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
9163 | if (pkt_offset > wowlan->max_pkt_offset) |
9164 | goto error; | |
9165 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
9166 | ||
922bd80f JB |
9167 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9168 | if (!mask_pat) { | |
ff1b6e69 JB |
9169 | err = -ENOMEM; |
9170 | goto error; | |
9171 | } | |
922bd80f JB |
9172 | new_triggers.patterns[i].mask = mask_pat; |
9173 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 9174 | mask_len); |
922bd80f JB |
9175 | mask_pat += mask_len; |
9176 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 9177 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 9178 | memcpy(mask_pat, |
50ac6607 | 9179 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
9180 | pat_len); |
9181 | i++; | |
9182 | } | |
9183 | } | |
9184 | ||
2a0e047e JB |
9185 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
9186 | err = nl80211_parse_wowlan_tcp( | |
9187 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
9188 | &new_triggers); | |
9189 | if (err) | |
9190 | goto error; | |
9191 | } | |
9192 | ||
8cd4d456 LC |
9193 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
9194 | err = nl80211_parse_wowlan_nd( | |
9195 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | |
9196 | &new_triggers); | |
9197 | if (err) | |
9198 | goto error; | |
9199 | } | |
9200 | ||
ae33bd81 JB |
9201 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
9202 | if (!ntrig) { | |
9203 | err = -ENOMEM; | |
9204 | goto error; | |
ff1b6e69 | 9205 | } |
ae33bd81 | 9206 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 9207 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 9208 | |
ae33bd81 | 9209 | set_wakeup: |
6abb9cb9 JB |
9210 | if (rdev->ops->set_wakeup && |
9211 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
9212 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 9213 | |
ff1b6e69 JB |
9214 | return 0; |
9215 | error: | |
9216 | for (i = 0; i < new_triggers.n_patterns; i++) | |
9217 | kfree(new_triggers.patterns[i].mask); | |
9218 | kfree(new_triggers.patterns); | |
2a0e047e JB |
9219 | if (new_triggers.tcp && new_triggers.tcp->sock) |
9220 | sock_release(new_triggers.tcp->sock); | |
9221 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
9222 | return err; |
9223 | } | |
dfb89c56 | 9224 | #endif |
ff1b6e69 | 9225 | |
be29b99a AK |
9226 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
9227 | struct cfg80211_registered_device *rdev) | |
9228 | { | |
9229 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
9230 | int i, j, pat_len; | |
9231 | struct cfg80211_coalesce_rules *rule; | |
9232 | ||
9233 | if (!rdev->coalesce->n_rules) | |
9234 | return 0; | |
9235 | ||
9236 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
9237 | if (!nl_rules) | |
9238 | return -ENOBUFS; | |
9239 | ||
9240 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
9241 | nl_rule = nla_nest_start(msg, i + 1); | |
9242 | if (!nl_rule) | |
9243 | return -ENOBUFS; | |
9244 | ||
9245 | rule = &rdev->coalesce->rules[i]; | |
9246 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
9247 | rule->delay)) | |
9248 | return -ENOBUFS; | |
9249 | ||
9250 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
9251 | rule->condition)) | |
9252 | return -ENOBUFS; | |
9253 | ||
9254 | nl_pats = nla_nest_start(msg, | |
9255 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
9256 | if (!nl_pats) | |
9257 | return -ENOBUFS; | |
9258 | ||
9259 | for (j = 0; j < rule->n_patterns; j++) { | |
9260 | nl_pat = nla_nest_start(msg, j + 1); | |
9261 | if (!nl_pat) | |
9262 | return -ENOBUFS; | |
9263 | pat_len = rule->patterns[j].pattern_len; | |
9264 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
9265 | DIV_ROUND_UP(pat_len, 8), | |
9266 | rule->patterns[j].mask) || | |
9267 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
9268 | rule->patterns[j].pattern) || | |
9269 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
9270 | rule->patterns[j].pkt_offset)) | |
9271 | return -ENOBUFS; | |
9272 | nla_nest_end(msg, nl_pat); | |
9273 | } | |
9274 | nla_nest_end(msg, nl_pats); | |
9275 | nla_nest_end(msg, nl_rule); | |
9276 | } | |
9277 | nla_nest_end(msg, nl_rules); | |
9278 | ||
9279 | return 0; | |
9280 | } | |
9281 | ||
9282 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9283 | { | |
9284 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9285 | struct sk_buff *msg; | |
9286 | void *hdr; | |
9287 | ||
9288 | if (!rdev->wiphy.coalesce) | |
9289 | return -EOPNOTSUPP; | |
9290 | ||
9291 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9292 | if (!msg) | |
9293 | return -ENOMEM; | |
9294 | ||
9295 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9296 | NL80211_CMD_GET_COALESCE); | |
9297 | if (!hdr) | |
9298 | goto nla_put_failure; | |
9299 | ||
9300 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
9301 | goto nla_put_failure; | |
9302 | ||
9303 | genlmsg_end(msg, hdr); | |
9304 | return genlmsg_reply(msg, info); | |
9305 | ||
9306 | nla_put_failure: | |
9307 | nlmsg_free(msg); | |
9308 | return -ENOBUFS; | |
9309 | } | |
9310 | ||
9311 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
9312 | { | |
9313 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
9314 | int i, j; | |
9315 | struct cfg80211_coalesce_rules *rule; | |
9316 | ||
9317 | if (!coalesce) | |
9318 | return; | |
9319 | ||
9320 | for (i = 0; i < coalesce->n_rules; i++) { | |
9321 | rule = &coalesce->rules[i]; | |
9322 | for (j = 0; j < rule->n_patterns; j++) | |
9323 | kfree(rule->patterns[j].mask); | |
9324 | kfree(rule->patterns); | |
9325 | } | |
9326 | kfree(coalesce->rules); | |
9327 | kfree(coalesce); | |
9328 | rdev->coalesce = NULL; | |
9329 | } | |
9330 | ||
9331 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
9332 | struct nlattr *rule, | |
9333 | struct cfg80211_coalesce_rules *new_rule) | |
9334 | { | |
9335 | int err, i; | |
9336 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9337 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
9338 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
9339 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
9340 | ||
9341 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
9342 | nla_len(rule), nl80211_coalesce_policy); | |
9343 | if (err) | |
9344 | return err; | |
9345 | ||
9346 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
9347 | new_rule->delay = | |
9348 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
9349 | if (new_rule->delay > coalesce->max_delay) | |
9350 | return -EINVAL; | |
9351 | ||
9352 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
9353 | new_rule->condition = | |
9354 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
9355 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
9356 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
9357 | return -EINVAL; | |
9358 | ||
9359 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
9360 | return -EINVAL; | |
9361 | ||
9362 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9363 | rem) | |
9364 | n_patterns++; | |
9365 | if (n_patterns > coalesce->n_patterns) | |
9366 | return -EINVAL; | |
9367 | ||
9368 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
9369 | GFP_KERNEL); | |
9370 | if (!new_rule->patterns) | |
9371 | return -ENOMEM; | |
9372 | ||
9373 | new_rule->n_patterns = n_patterns; | |
9374 | i = 0; | |
9375 | ||
9376 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9377 | rem) { | |
922bd80f JB |
9378 | u8 *mask_pat; |
9379 | ||
be29b99a AK |
9380 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9381 | nla_len(pat), NULL); | |
9382 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
9383 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
9384 | return -EINVAL; | |
9385 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
9386 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
9387 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
9388 | return -EINVAL; | |
9389 | if (pat_len > coalesce->pattern_max_len || | |
9390 | pat_len < coalesce->pattern_min_len) | |
9391 | return -EINVAL; | |
9392 | ||
9393 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
9394 | pkt_offset = 0; | |
9395 | else | |
9396 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
9397 | if (pkt_offset > coalesce->max_pkt_offset) | |
9398 | return -EINVAL; | |
9399 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
9400 | ||
922bd80f JB |
9401 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9402 | if (!mask_pat) | |
be29b99a | 9403 | return -ENOMEM; |
922bd80f JB |
9404 | |
9405 | new_rule->patterns[i].mask = mask_pat; | |
9406 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
9407 | mask_len); | |
9408 | ||
9409 | mask_pat += mask_len; | |
9410 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 9411 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
9412 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
9413 | pat_len); | |
be29b99a AK |
9414 | i++; |
9415 | } | |
9416 | ||
9417 | return 0; | |
9418 | } | |
9419 | ||
9420 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9421 | { | |
9422 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9423 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9424 | struct cfg80211_coalesce new_coalesce = {}; | |
9425 | struct cfg80211_coalesce *n_coalesce; | |
9426 | int err, rem_rule, n_rules = 0, i, j; | |
9427 | struct nlattr *rule; | |
9428 | struct cfg80211_coalesce_rules *tmp_rule; | |
9429 | ||
9430 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
9431 | return -EOPNOTSUPP; | |
9432 | ||
9433 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
9434 | cfg80211_rdev_free_coalesce(rdev); | |
9435 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
9436 | return 0; | |
9437 | } | |
9438 | ||
9439 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9440 | rem_rule) | |
9441 | n_rules++; | |
9442 | if (n_rules > coalesce->n_rules) | |
9443 | return -EINVAL; | |
9444 | ||
9445 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
9446 | GFP_KERNEL); | |
9447 | if (!new_coalesce.rules) | |
9448 | return -ENOMEM; | |
9449 | ||
9450 | new_coalesce.n_rules = n_rules; | |
9451 | i = 0; | |
9452 | ||
9453 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9454 | rem_rule) { | |
9455 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
9456 | &new_coalesce.rules[i]); | |
9457 | if (err) | |
9458 | goto error; | |
9459 | ||
9460 | i++; | |
9461 | } | |
9462 | ||
9463 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
9464 | if (err) | |
9465 | goto error; | |
9466 | ||
9467 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
9468 | if (!n_coalesce) { | |
9469 | err = -ENOMEM; | |
9470 | goto error; | |
9471 | } | |
9472 | cfg80211_rdev_free_coalesce(rdev); | |
9473 | rdev->coalesce = n_coalesce; | |
9474 | ||
9475 | return 0; | |
9476 | error: | |
9477 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
9478 | tmp_rule = &new_coalesce.rules[i]; | |
9479 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
9480 | kfree(tmp_rule->patterns[j].mask); | |
9481 | kfree(tmp_rule->patterns); | |
9482 | } | |
9483 | kfree(new_coalesce.rules); | |
9484 | ||
9485 | return err; | |
9486 | } | |
9487 | ||
e5497d76 JB |
9488 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
9489 | { | |
9490 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9491 | struct net_device *dev = info->user_ptr[1]; | |
9492 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9493 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
9494 | struct cfg80211_gtk_rekey_data rekey_data; | |
9495 | int err; | |
9496 | ||
9497 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
9498 | return -EINVAL; | |
9499 | ||
9500 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
9501 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9502 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9503 | nl80211_rekey_policy); | |
9504 | if (err) | |
9505 | return err; | |
9506 | ||
9507 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
9508 | return -ERANGE; | |
9509 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
9510 | return -ERANGE; | |
9511 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
9512 | return -ERANGE; | |
9513 | ||
78f686ca JB |
9514 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
9515 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | |
9516 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | |
e5497d76 JB |
9517 | |
9518 | wdev_lock(wdev); | |
9519 | if (!wdev->current_bss) { | |
9520 | err = -ENOTCONN; | |
9521 | goto out; | |
9522 | } | |
9523 | ||
9524 | if (!rdev->ops->set_rekey_data) { | |
9525 | err = -EOPNOTSUPP; | |
9526 | goto out; | |
9527 | } | |
9528 | ||
e35e4d28 | 9529 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
9530 | out: |
9531 | wdev_unlock(wdev); | |
9532 | return err; | |
9533 | } | |
9534 | ||
28946da7 JB |
9535 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
9536 | struct genl_info *info) | |
9537 | { | |
9538 | struct net_device *dev = info->user_ptr[1]; | |
9539 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9540 | ||
9541 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9542 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9543 | return -EINVAL; | |
9544 | ||
15e47304 | 9545 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
9546 | return -EBUSY; |
9547 | ||
15e47304 | 9548 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
9549 | return 0; |
9550 | } | |
9551 | ||
7f6cf311 JB |
9552 | static int nl80211_probe_client(struct sk_buff *skb, |
9553 | struct genl_info *info) | |
9554 | { | |
9555 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9556 | struct net_device *dev = info->user_ptr[1]; | |
9557 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9558 | struct sk_buff *msg; | |
9559 | void *hdr; | |
9560 | const u8 *addr; | |
9561 | u64 cookie; | |
9562 | int err; | |
9563 | ||
9564 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9565 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9566 | return -EOPNOTSUPP; | |
9567 | ||
9568 | if (!info->attrs[NL80211_ATTR_MAC]) | |
9569 | return -EINVAL; | |
9570 | ||
9571 | if (!rdev->ops->probe_client) | |
9572 | return -EOPNOTSUPP; | |
9573 | ||
9574 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9575 | if (!msg) | |
9576 | return -ENOMEM; | |
9577 | ||
15e47304 | 9578 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 9579 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
9580 | if (!hdr) { |
9581 | err = -ENOBUFS; | |
7f6cf311 JB |
9582 | goto free_msg; |
9583 | } | |
9584 | ||
9585 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9586 | ||
e35e4d28 | 9587 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
9588 | if (err) |
9589 | goto free_msg; | |
9590 | ||
9360ffd1 DM |
9591 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9592 | goto nla_put_failure; | |
7f6cf311 JB |
9593 | |
9594 | genlmsg_end(msg, hdr); | |
9595 | ||
9596 | return genlmsg_reply(msg, info); | |
9597 | ||
9598 | nla_put_failure: | |
9599 | err = -ENOBUFS; | |
9600 | free_msg: | |
9601 | nlmsg_free(msg); | |
9602 | return err; | |
9603 | } | |
9604 | ||
5e760230 JB |
9605 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
9606 | { | |
9607 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
9608 | struct cfg80211_beacon_registration *reg, *nreg; |
9609 | int rv; | |
5e760230 JB |
9610 | |
9611 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
9612 | return -EOPNOTSUPP; | |
9613 | ||
37c73b5f BG |
9614 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
9615 | if (!nreg) | |
9616 | return -ENOMEM; | |
9617 | ||
9618 | /* First, check if already registered. */ | |
9619 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
9620 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
9621 | if (reg->nlportid == info->snd_portid) { | |
9622 | rv = -EALREADY; | |
9623 | goto out_err; | |
9624 | } | |
9625 | } | |
9626 | /* Add it to the list */ | |
9627 | nreg->nlportid = info->snd_portid; | |
9628 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 9629 | |
37c73b5f | 9630 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
9631 | |
9632 | return 0; | |
37c73b5f BG |
9633 | out_err: |
9634 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
9635 | kfree(nreg); | |
9636 | return rv; | |
5e760230 JB |
9637 | } |
9638 | ||
98104fde JB |
9639 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
9640 | { | |
9641 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9642 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9643 | int err; | |
9644 | ||
9645 | if (!rdev->ops->start_p2p_device) | |
9646 | return -EOPNOTSUPP; | |
9647 | ||
9648 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9649 | return -EOPNOTSUPP; | |
9650 | ||
9651 | if (wdev->p2p_started) | |
9652 | return 0; | |
9653 | ||
b6a55015 LC |
9654 | if (rfkill_blocked(rdev->rfkill)) |
9655 | return -ERFKILL; | |
98104fde | 9656 | |
eeb126e9 | 9657 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
9658 | if (err) |
9659 | return err; | |
9660 | ||
9661 | wdev->p2p_started = true; | |
98104fde | 9662 | rdev->opencount++; |
98104fde JB |
9663 | |
9664 | return 0; | |
9665 | } | |
9666 | ||
9667 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
9668 | { | |
9669 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9670 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9671 | ||
9672 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9673 | return -EOPNOTSUPP; | |
9674 | ||
9675 | if (!rdev->ops->stop_p2p_device) | |
9676 | return -EOPNOTSUPP; | |
9677 | ||
f9f47529 | 9678 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
9679 | |
9680 | return 0; | |
9681 | } | |
9682 | ||
3713b4e3 JB |
9683 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
9684 | struct genl_info *info) | |
9685 | { | |
9686 | void *hdr; | |
9687 | struct sk_buff *msg; | |
9688 | ||
9689 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9690 | if (!msg) | |
9691 | return -ENOMEM; | |
9692 | ||
9693 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9694 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
9695 | if (!hdr) | |
9696 | goto nla_put_failure; | |
9697 | ||
9698 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
9699 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
9700 | goto nla_put_failure; | |
9701 | ||
9702 | genlmsg_end(msg, hdr); | |
9703 | return genlmsg_reply(msg, info); | |
9704 | ||
9705 | nla_put_failure: | |
9706 | kfree_skb(msg); | |
9707 | return -ENOBUFS; | |
9708 | } | |
9709 | ||
355199e0 JM |
9710 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
9711 | { | |
9712 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9713 | struct cfg80211_update_ft_ies_params ft_params; | |
9714 | struct net_device *dev = info->user_ptr[1]; | |
9715 | ||
9716 | if (!rdev->ops->update_ft_ies) | |
9717 | return -EOPNOTSUPP; | |
9718 | ||
9719 | if (!info->attrs[NL80211_ATTR_MDID] || | |
9720 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
9721 | return -EINVAL; | |
9722 | ||
9723 | memset(&ft_params, 0, sizeof(ft_params)); | |
9724 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
9725 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
9726 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9727 | ||
9728 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
9729 | } | |
9730 | ||
5de17984 AS |
9731 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
9732 | struct genl_info *info) | |
9733 | { | |
9734 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9735 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9736 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
9737 | u16 duration; | |
9738 | int ret; | |
9739 | ||
9740 | if (!rdev->ops->crit_proto_start) | |
9741 | return -EOPNOTSUPP; | |
9742 | ||
9743 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
9744 | return -EINVAL; | |
9745 | ||
9746 | if (rdev->crit_proto_nlportid) | |
9747 | return -EBUSY; | |
9748 | ||
9749 | /* determine protocol if provided */ | |
9750 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
9751 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
9752 | ||
9753 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
9754 | return -EINVAL; | |
9755 | ||
9756 | /* timeout must be provided */ | |
9757 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
9758 | return -EINVAL; | |
9759 | ||
9760 | duration = | |
9761 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
9762 | ||
9763 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
9764 | return -ERANGE; | |
9765 | ||
9766 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
9767 | if (!ret) | |
9768 | rdev->crit_proto_nlportid = info->snd_portid; | |
9769 | ||
9770 | return ret; | |
9771 | } | |
9772 | ||
9773 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
9774 | struct genl_info *info) | |
9775 | { | |
9776 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9777 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9778 | ||
9779 | if (!rdev->ops->crit_proto_stop) | |
9780 | return -EOPNOTSUPP; | |
9781 | ||
9782 | if (rdev->crit_proto_nlportid) { | |
9783 | rdev->crit_proto_nlportid = 0; | |
9784 | rdev_crit_proto_stop(rdev, wdev); | |
9785 | } | |
9786 | return 0; | |
9787 | } | |
9788 | ||
ad7e718c JB |
9789 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
9790 | { | |
9791 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9792 | struct wireless_dev *wdev = | |
9793 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
9794 | int i, err; | |
9795 | u32 vid, subcmd; | |
9796 | ||
9797 | if (!rdev->wiphy.vendor_commands) | |
9798 | return -EOPNOTSUPP; | |
9799 | ||
9800 | if (IS_ERR(wdev)) { | |
9801 | err = PTR_ERR(wdev); | |
9802 | if (err != -EINVAL) | |
9803 | return err; | |
9804 | wdev = NULL; | |
9805 | } else if (wdev->wiphy != &rdev->wiphy) { | |
9806 | return -EINVAL; | |
9807 | } | |
9808 | ||
9809 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
9810 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
9811 | return -EINVAL; | |
9812 | ||
9813 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
9814 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
9815 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
9816 | const struct wiphy_vendor_command *vcmd; | |
9817 | void *data = NULL; | |
9818 | int len = 0; | |
9819 | ||
9820 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
9821 | ||
9822 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
9823 | continue; | |
9824 | ||
9825 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
9826 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
9827 | if (!wdev) | |
9828 | return -EINVAL; | |
9829 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
9830 | !wdev->netdev) | |
9831 | return -EINVAL; | |
9832 | ||
9833 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
9834 | if (wdev->netdev && | |
9835 | !netif_running(wdev->netdev)) | |
9836 | return -ENETDOWN; | |
9837 | if (!wdev->netdev && !wdev->p2p_started) | |
9838 | return -ENETDOWN; | |
9839 | } | |
9840 | } else { | |
9841 | wdev = NULL; | |
9842 | } | |
9843 | ||
9844 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
9845 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9846 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9847 | } | |
9848 | ||
9849 | rdev->cur_cmd_info = info; | |
9850 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
9851 | data, len); | |
9852 | rdev->cur_cmd_info = NULL; | |
9853 | return err; | |
9854 | } | |
9855 | ||
9856 | return -EOPNOTSUPP; | |
9857 | } | |
9858 | ||
9859 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | |
9860 | enum nl80211_commands cmd, | |
9861 | enum nl80211_attrs attr, | |
9862 | int approxlen) | |
9863 | { | |
f26cbf40 | 9864 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
9865 | |
9866 | if (WARN_ON(!rdev->cur_cmd_info)) | |
9867 | return NULL; | |
9868 | ||
9869 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, | |
9870 | rdev->cur_cmd_info->snd_portid, | |
9871 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 9872 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
9873 | } |
9874 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
9875 | ||
9876 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
9877 | { | |
9878 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
9879 | void *hdr = ((void **)skb->cb)[1]; | |
9880 | struct nlattr *data = ((void **)skb->cb)[2]; | |
9881 | ||
bd8c78e7 JB |
9882 | /* clear CB data for netlink core to own from now on */ |
9883 | memset(skb->cb, 0, sizeof(skb->cb)); | |
9884 | ||
ad7e718c JB |
9885 | if (WARN_ON(!rdev->cur_cmd_info)) { |
9886 | kfree_skb(skb); | |
9887 | return -EINVAL; | |
9888 | } | |
9889 | ||
9890 | nla_nest_end(skb, data); | |
9891 | genlmsg_end(skb, hdr); | |
9892 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
9893 | } | |
9894 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
9895 | ||
9896 | ||
fa9ffc74 KP |
9897 | static int nl80211_set_qos_map(struct sk_buff *skb, |
9898 | struct genl_info *info) | |
9899 | { | |
9900 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9901 | struct cfg80211_qos_map *qos_map = NULL; | |
9902 | struct net_device *dev = info->user_ptr[1]; | |
9903 | u8 *pos, len, num_des, des_len, des; | |
9904 | int ret; | |
9905 | ||
9906 | if (!rdev->ops->set_qos_map) | |
9907 | return -EOPNOTSUPP; | |
9908 | ||
9909 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
9910 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9911 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9912 | ||
9913 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
9914 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
9915 | return -EINVAL; | |
9916 | ||
9917 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
9918 | if (!qos_map) | |
9919 | return -ENOMEM; | |
9920 | ||
9921 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
9922 | if (num_des) { | |
9923 | des_len = num_des * | |
9924 | sizeof(struct cfg80211_dscp_exception); | |
9925 | memcpy(qos_map->dscp_exception, pos, des_len); | |
9926 | qos_map->num_des = num_des; | |
9927 | for (des = 0; des < num_des; des++) { | |
9928 | if (qos_map->dscp_exception[des].up > 7) { | |
9929 | kfree(qos_map); | |
9930 | return -EINVAL; | |
9931 | } | |
9932 | } | |
9933 | pos += des_len; | |
9934 | } | |
9935 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
9936 | } | |
9937 | ||
9938 | wdev_lock(dev->ieee80211_ptr); | |
9939 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
9940 | if (!ret) | |
9941 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
9942 | wdev_unlock(dev->ieee80211_ptr); | |
9943 | ||
9944 | kfree(qos_map); | |
9945 | return ret; | |
9946 | } | |
9947 | ||
960d01ac JB |
9948 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
9949 | { | |
9950 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9951 | struct net_device *dev = info->user_ptr[1]; | |
9952 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9953 | const u8 *peer; | |
9954 | u8 tsid, up; | |
9955 | u16 admitted_time = 0; | |
9956 | int err; | |
9957 | ||
723e73ac | 9958 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
960d01ac JB |
9959 | return -EOPNOTSUPP; |
9960 | ||
9961 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | |
9962 | !info->attrs[NL80211_ATTR_USER_PRIO]) | |
9963 | return -EINVAL; | |
9964 | ||
9965 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
9966 | if (tsid >= IEEE80211_NUM_TIDS) | |
9967 | return -EINVAL; | |
9968 | ||
9969 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); | |
9970 | if (up >= IEEE80211_NUM_UPS) | |
9971 | return -EINVAL; | |
9972 | ||
9973 | /* WMM uses TIDs 0-7 even for TSPEC */ | |
723e73ac | 9974 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
960d01ac | 9975 | /* TODO: handle 802.11 TSPEC/admission control |
723e73ac JB |
9976 | * need more attributes for that (e.g. BA session requirement); |
9977 | * change the WMM adminssion test above to allow both then | |
960d01ac JB |
9978 | */ |
9979 | return -EINVAL; | |
9980 | } | |
9981 | ||
9982 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9983 | ||
9984 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | |
9985 | admitted_time = | |
9986 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | |
9987 | if (!admitted_time) | |
9988 | return -EINVAL; | |
9989 | } | |
9990 | ||
9991 | wdev_lock(wdev); | |
9992 | switch (wdev->iftype) { | |
9993 | case NL80211_IFTYPE_STATION: | |
9994 | case NL80211_IFTYPE_P2P_CLIENT: | |
9995 | if (wdev->current_bss) | |
9996 | break; | |
9997 | err = -ENOTCONN; | |
9998 | goto out; | |
9999 | default: | |
10000 | err = -EOPNOTSUPP; | |
10001 | goto out; | |
10002 | } | |
10003 | ||
10004 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | |
10005 | ||
10006 | out: | |
10007 | wdev_unlock(wdev); | |
10008 | return err; | |
10009 | } | |
10010 | ||
10011 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | |
10012 | { | |
10013 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10014 | struct net_device *dev = info->user_ptr[1]; | |
10015 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10016 | const u8 *peer; | |
10017 | u8 tsid; | |
10018 | int err; | |
10019 | ||
10020 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | |
10021 | return -EINVAL; | |
10022 | ||
10023 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
10024 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10025 | ||
10026 | wdev_lock(wdev); | |
10027 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | |
10028 | wdev_unlock(wdev); | |
10029 | ||
10030 | return err; | |
10031 | } | |
10032 | ||
1057d35e AN |
10033 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
10034 | struct genl_info *info) | |
10035 | { | |
10036 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10037 | struct net_device *dev = info->user_ptr[1]; | |
10038 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10039 | struct cfg80211_chan_def chandef = {}; | |
10040 | const u8 *addr; | |
10041 | u8 oper_class; | |
10042 | int err; | |
10043 | ||
10044 | if (!rdev->ops->tdls_channel_switch || | |
10045 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
10046 | return -EOPNOTSUPP; | |
10047 | ||
10048 | switch (dev->ieee80211_ptr->iftype) { | |
10049 | case NL80211_IFTYPE_STATION: | |
10050 | case NL80211_IFTYPE_P2P_CLIENT: | |
10051 | break; | |
10052 | default: | |
10053 | return -EOPNOTSUPP; | |
10054 | } | |
10055 | ||
10056 | if (!info->attrs[NL80211_ATTR_MAC] || | |
10057 | !info->attrs[NL80211_ATTR_OPER_CLASS]) | |
10058 | return -EINVAL; | |
10059 | ||
10060 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
10061 | if (err) | |
10062 | return err; | |
10063 | ||
10064 | /* | |
10065 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | |
10066 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | |
10067 | * specification is not defined for them. | |
10068 | */ | |
10069 | if (chandef.chan->band == IEEE80211_BAND_2GHZ && | |
10070 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | |
10071 | chandef.width != NL80211_CHAN_WIDTH_20) | |
10072 | return -EINVAL; | |
10073 | ||
10074 | /* we will be active on the TDLS link */ | |
10075 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype)) | |
10076 | return -EINVAL; | |
10077 | ||
10078 | /* don't allow switching to DFS channels */ | |
10079 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | |
10080 | return -EINVAL; | |
10081 | ||
10082 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10083 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | |
10084 | ||
10085 | wdev_lock(wdev); | |
10086 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | |
10087 | wdev_unlock(wdev); | |
10088 | ||
10089 | return err; | |
10090 | } | |
10091 | ||
10092 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | |
10093 | struct genl_info *info) | |
10094 | { | |
10095 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10096 | struct net_device *dev = info->user_ptr[1]; | |
10097 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10098 | const u8 *addr; | |
10099 | ||
10100 | if (!rdev->ops->tdls_channel_switch || | |
10101 | !rdev->ops->tdls_cancel_channel_switch || | |
10102 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
10103 | return -EOPNOTSUPP; | |
10104 | ||
10105 | switch (dev->ieee80211_ptr->iftype) { | |
10106 | case NL80211_IFTYPE_STATION: | |
10107 | case NL80211_IFTYPE_P2P_CLIENT: | |
10108 | break; | |
10109 | default: | |
10110 | return -EOPNOTSUPP; | |
10111 | } | |
10112 | ||
10113 | if (!info->attrs[NL80211_ATTR_MAC]) | |
10114 | return -EINVAL; | |
10115 | ||
10116 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10117 | ||
10118 | wdev_lock(wdev); | |
10119 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); | |
10120 | wdev_unlock(wdev); | |
10121 | ||
10122 | return 0; | |
10123 | } | |
10124 | ||
4c476991 JB |
10125 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
10126 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
10127 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
10128 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
10129 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
10130 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 10131 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 10132 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
10133 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
10134 | NL80211_FLAG_CHECK_NETDEV_UP) | |
5393b917 | 10135 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
4c476991 | 10136 | |
f84f771d | 10137 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10138 | struct genl_info *info) |
10139 | { | |
10140 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 10141 | struct wireless_dev *wdev; |
4c476991 | 10142 | struct net_device *dev; |
4c476991 JB |
10143 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
10144 | ||
10145 | if (rtnl) | |
10146 | rtnl_lock(); | |
10147 | ||
10148 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 10149 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
10150 | if (IS_ERR(rdev)) { |
10151 | if (rtnl) | |
10152 | rtnl_unlock(); | |
10153 | return PTR_ERR(rdev); | |
10154 | } | |
10155 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
10156 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
10157 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
10158 | ASSERT_RTNL(); |
10159 | ||
89a54e48 JB |
10160 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
10161 | info->attrs); | |
10162 | if (IS_ERR(wdev)) { | |
4c476991 JB |
10163 | if (rtnl) |
10164 | rtnl_unlock(); | |
89a54e48 | 10165 | return PTR_ERR(wdev); |
4c476991 | 10166 | } |
89a54e48 | 10167 | |
89a54e48 | 10168 | dev = wdev->netdev; |
f26cbf40 | 10169 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 10170 | |
1bf614ef JB |
10171 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
10172 | if (!dev) { | |
1bf614ef JB |
10173 | if (rtnl) |
10174 | rtnl_unlock(); | |
10175 | return -EINVAL; | |
10176 | } | |
10177 | ||
10178 | info->user_ptr[1] = dev; | |
10179 | } else { | |
10180 | info->user_ptr[1] = wdev; | |
41265714 | 10181 | } |
1bf614ef JB |
10182 | |
10183 | if (dev) { | |
10184 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
10185 | !netif_running(dev)) { | |
1bf614ef JB |
10186 | if (rtnl) |
10187 | rtnl_unlock(); | |
10188 | return -ENETDOWN; | |
10189 | } | |
10190 | ||
10191 | dev_hold(dev); | |
98104fde JB |
10192 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
10193 | if (!wdev->p2p_started) { | |
98104fde JB |
10194 | if (rtnl) |
10195 | rtnl_unlock(); | |
10196 | return -ENETDOWN; | |
10197 | } | |
41265714 | 10198 | } |
89a54e48 | 10199 | |
4c476991 | 10200 | info->user_ptr[0] = rdev; |
4c476991 JB |
10201 | } |
10202 | ||
10203 | return 0; | |
10204 | } | |
10205 | ||
f84f771d | 10206 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10207 | struct genl_info *info) |
10208 | { | |
1bf614ef JB |
10209 | if (info->user_ptr[1]) { |
10210 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
10211 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10212 | ||
10213 | if (wdev->netdev) | |
10214 | dev_put(wdev->netdev); | |
10215 | } else { | |
10216 | dev_put(info->user_ptr[1]); | |
10217 | } | |
10218 | } | |
5393b917 | 10219 | |
4c476991 JB |
10220 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
10221 | rtnl_unlock(); | |
5393b917 JB |
10222 | |
10223 | /* If needed, clear the netlink message payload from the SKB | |
10224 | * as it might contain key data that shouldn't stick around on | |
10225 | * the heap after the SKB is freed. The netlink message header | |
10226 | * is still needed for further processing, so leave it intact. | |
10227 | */ | |
10228 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | |
10229 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | |
10230 | ||
10231 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | |
10232 | } | |
4c476991 JB |
10233 | } |
10234 | ||
4534de83 | 10235 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
10236 | { |
10237 | .cmd = NL80211_CMD_GET_WIPHY, | |
10238 | .doit = nl80211_get_wiphy, | |
10239 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 10240 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
10241 | .policy = nl80211_policy, |
10242 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10243 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10244 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10245 | }, |
10246 | { | |
10247 | .cmd = NL80211_CMD_SET_WIPHY, | |
10248 | .doit = nl80211_set_wiphy, | |
10249 | .policy = nl80211_policy, | |
10250 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 10251 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
10252 | }, |
10253 | { | |
10254 | .cmd = NL80211_CMD_GET_INTERFACE, | |
10255 | .doit = nl80211_get_interface, | |
10256 | .dumpit = nl80211_dump_interface, | |
10257 | .policy = nl80211_policy, | |
10258 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10259 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
10260 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10261 | }, |
10262 | { | |
10263 | .cmd = NL80211_CMD_SET_INTERFACE, | |
10264 | .doit = nl80211_set_interface, | |
10265 | .policy = nl80211_policy, | |
10266 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10267 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10268 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10269 | }, |
10270 | { | |
10271 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
10272 | .doit = nl80211_new_interface, | |
10273 | .policy = nl80211_policy, | |
10274 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10275 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10276 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10277 | }, |
10278 | { | |
10279 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
10280 | .doit = nl80211_del_interface, | |
10281 | .policy = nl80211_policy, | |
41ade00f | 10282 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 10283 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10284 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10285 | }, |
10286 | { | |
10287 | .cmd = NL80211_CMD_GET_KEY, | |
10288 | .doit = nl80211_get_key, | |
10289 | .policy = nl80211_policy, | |
10290 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10291 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10292 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10293 | }, |
10294 | { | |
10295 | .cmd = NL80211_CMD_SET_KEY, | |
10296 | .doit = nl80211_set_key, | |
10297 | .policy = nl80211_policy, | |
10298 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10299 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10300 | NL80211_FLAG_NEED_RTNL | |
10301 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10302 | }, |
10303 | { | |
10304 | .cmd = NL80211_CMD_NEW_KEY, | |
10305 | .doit = nl80211_new_key, | |
10306 | .policy = nl80211_policy, | |
10307 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10308 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10309 | NL80211_FLAG_NEED_RTNL | |
10310 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10311 | }, |
10312 | { | |
10313 | .cmd = NL80211_CMD_DEL_KEY, | |
10314 | .doit = nl80211_del_key, | |
10315 | .policy = nl80211_policy, | |
55682965 | 10316 | .flags = GENL_ADMIN_PERM, |
41265714 | 10317 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10318 | NL80211_FLAG_NEED_RTNL, |
55682965 | 10319 | }, |
ed1b6cc7 JB |
10320 | { |
10321 | .cmd = NL80211_CMD_SET_BEACON, | |
10322 | .policy = nl80211_policy, | |
10323 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10324 | .doit = nl80211_set_beacon, |
2b5f8b0b | 10325 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10326 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10327 | }, |
10328 | { | |
8860020e | 10329 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
10330 | .policy = nl80211_policy, |
10331 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10332 | .doit = nl80211_start_ap, |
2b5f8b0b | 10333 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10334 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10335 | }, |
10336 | { | |
8860020e | 10337 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
10338 | .policy = nl80211_policy, |
10339 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10340 | .doit = nl80211_stop_ap, |
2b5f8b0b | 10341 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10342 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 10343 | }, |
5727ef1b JB |
10344 | { |
10345 | .cmd = NL80211_CMD_GET_STATION, | |
10346 | .doit = nl80211_get_station, | |
2ec600d6 | 10347 | .dumpit = nl80211_dump_station, |
5727ef1b | 10348 | .policy = nl80211_policy, |
4c476991 JB |
10349 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10350 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
10351 | }, |
10352 | { | |
10353 | .cmd = NL80211_CMD_SET_STATION, | |
10354 | .doit = nl80211_set_station, | |
10355 | .policy = nl80211_policy, | |
10356 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10357 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10358 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10359 | }, |
10360 | { | |
10361 | .cmd = NL80211_CMD_NEW_STATION, | |
10362 | .doit = nl80211_new_station, | |
10363 | .policy = nl80211_policy, | |
10364 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10365 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10366 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10367 | }, |
10368 | { | |
10369 | .cmd = NL80211_CMD_DEL_STATION, | |
10370 | .doit = nl80211_del_station, | |
10371 | .policy = nl80211_policy, | |
2ec600d6 | 10372 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10373 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10374 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10375 | }, |
10376 | { | |
10377 | .cmd = NL80211_CMD_GET_MPATH, | |
10378 | .doit = nl80211_get_mpath, | |
10379 | .dumpit = nl80211_dump_mpath, | |
10380 | .policy = nl80211_policy, | |
10381 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10382 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10383 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 | 10384 | }, |
66be7d2b HR |
10385 | { |
10386 | .cmd = NL80211_CMD_GET_MPP, | |
10387 | .doit = nl80211_get_mpp, | |
10388 | .dumpit = nl80211_dump_mpp, | |
10389 | .policy = nl80211_policy, | |
10390 | .flags = GENL_ADMIN_PERM, | |
10391 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10392 | NL80211_FLAG_NEED_RTNL, | |
10393 | }, | |
2ec600d6 LCC |
10394 | { |
10395 | .cmd = NL80211_CMD_SET_MPATH, | |
10396 | .doit = nl80211_set_mpath, | |
10397 | .policy = nl80211_policy, | |
10398 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10399 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10400 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10401 | }, |
10402 | { | |
10403 | .cmd = NL80211_CMD_NEW_MPATH, | |
10404 | .doit = nl80211_new_mpath, | |
10405 | .policy = nl80211_policy, | |
10406 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10407 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10408 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10409 | }, |
10410 | { | |
10411 | .cmd = NL80211_CMD_DEL_MPATH, | |
10412 | .doit = nl80211_del_mpath, | |
10413 | .policy = nl80211_policy, | |
9f1ba906 | 10414 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10415 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10416 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
10417 | }, |
10418 | { | |
10419 | .cmd = NL80211_CMD_SET_BSS, | |
10420 | .doit = nl80211_set_bss, | |
10421 | .policy = nl80211_policy, | |
b2e1b302 | 10422 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10423 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10424 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 10425 | }, |
f130347c LR |
10426 | { |
10427 | .cmd = NL80211_CMD_GET_REG, | |
ad30ca2c AN |
10428 | .doit = nl80211_get_reg_do, |
10429 | .dumpit = nl80211_get_reg_dump, | |
f130347c | 10430 | .policy = nl80211_policy, |
5fe231e8 | 10431 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
10432 | /* can be retrieved by unprivileged users */ |
10433 | }, | |
b2e1b302 LR |
10434 | { |
10435 | .cmd = NL80211_CMD_SET_REG, | |
10436 | .doit = nl80211_set_reg, | |
10437 | .policy = nl80211_policy, | |
10438 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 10439 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
10440 | }, |
10441 | { | |
10442 | .cmd = NL80211_CMD_REQ_SET_REG, | |
10443 | .doit = nl80211_req_set_reg, | |
10444 | .policy = nl80211_policy, | |
93da9cc1 | 10445 | .flags = GENL_ADMIN_PERM, |
10446 | }, | |
10447 | { | |
24bdd9f4 JC |
10448 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
10449 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 10450 | .policy = nl80211_policy, |
10451 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 10452 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10453 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 10454 | }, |
10455 | { | |
24bdd9f4 JC |
10456 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
10457 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 10458 | .policy = nl80211_policy, |
9aed3cc1 | 10459 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 10460 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10461 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 10462 | }, |
2a519311 JB |
10463 | { |
10464 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
10465 | .doit = nl80211_trigger_scan, | |
10466 | .policy = nl80211_policy, | |
10467 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 10468 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10469 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
10470 | }, |
10471 | { | |
10472 | .cmd = NL80211_CMD_GET_SCAN, | |
10473 | .policy = nl80211_policy, | |
10474 | .dumpit = nl80211_dump_scan, | |
10475 | }, | |
807f8a8c LC |
10476 | { |
10477 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
10478 | .doit = nl80211_start_sched_scan, | |
10479 | .policy = nl80211_policy, | |
10480 | .flags = GENL_ADMIN_PERM, | |
10481 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10482 | NL80211_FLAG_NEED_RTNL, | |
10483 | }, | |
10484 | { | |
10485 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
10486 | .doit = nl80211_stop_sched_scan, | |
10487 | .policy = nl80211_policy, | |
10488 | .flags = GENL_ADMIN_PERM, | |
10489 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10490 | NL80211_FLAG_NEED_RTNL, | |
10491 | }, | |
636a5d36 JM |
10492 | { |
10493 | .cmd = NL80211_CMD_AUTHENTICATE, | |
10494 | .doit = nl80211_authenticate, | |
10495 | .policy = nl80211_policy, | |
10496 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10497 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10498 | NL80211_FLAG_NEED_RTNL | |
10499 | NL80211_FLAG_CLEAR_SKB, | |
636a5d36 JM |
10500 | }, |
10501 | { | |
10502 | .cmd = NL80211_CMD_ASSOCIATE, | |
10503 | .doit = nl80211_associate, | |
10504 | .policy = nl80211_policy, | |
10505 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10506 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10507 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10508 | }, |
10509 | { | |
10510 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
10511 | .doit = nl80211_deauthenticate, | |
10512 | .policy = nl80211_policy, | |
10513 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10514 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10515 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10516 | }, |
10517 | { | |
10518 | .cmd = NL80211_CMD_DISASSOCIATE, | |
10519 | .doit = nl80211_disassociate, | |
10520 | .policy = nl80211_policy, | |
10521 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10522 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10523 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 10524 | }, |
04a773ad JB |
10525 | { |
10526 | .cmd = NL80211_CMD_JOIN_IBSS, | |
10527 | .doit = nl80211_join_ibss, | |
10528 | .policy = nl80211_policy, | |
10529 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10530 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10531 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
10532 | }, |
10533 | { | |
10534 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
10535 | .doit = nl80211_leave_ibss, | |
10536 | .policy = nl80211_policy, | |
10537 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10538 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10539 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 10540 | }, |
aff89a9b JB |
10541 | #ifdef CONFIG_NL80211_TESTMODE |
10542 | { | |
10543 | .cmd = NL80211_CMD_TESTMODE, | |
10544 | .doit = nl80211_testmode_do, | |
71063f0e | 10545 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
10546 | .policy = nl80211_policy, |
10547 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10548 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10549 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
10550 | }, |
10551 | #endif | |
b23aa676 SO |
10552 | { |
10553 | .cmd = NL80211_CMD_CONNECT, | |
10554 | .doit = nl80211_connect, | |
10555 | .policy = nl80211_policy, | |
10556 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10557 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10558 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
10559 | }, |
10560 | { | |
10561 | .cmd = NL80211_CMD_DISCONNECT, | |
10562 | .doit = nl80211_disconnect, | |
10563 | .policy = nl80211_policy, | |
10564 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10565 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10566 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 10567 | }, |
463d0183 JB |
10568 | { |
10569 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
10570 | .doit = nl80211_wiphy_netns, | |
10571 | .policy = nl80211_policy, | |
10572 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10573 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10574 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 10575 | }, |
61fa713c HS |
10576 | { |
10577 | .cmd = NL80211_CMD_GET_SURVEY, | |
10578 | .policy = nl80211_policy, | |
10579 | .dumpit = nl80211_dump_survey, | |
10580 | }, | |
67fbb16b SO |
10581 | { |
10582 | .cmd = NL80211_CMD_SET_PMKSA, | |
10583 | .doit = nl80211_setdel_pmksa, | |
10584 | .policy = nl80211_policy, | |
10585 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10586 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10587 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10588 | }, |
10589 | { | |
10590 | .cmd = NL80211_CMD_DEL_PMKSA, | |
10591 | .doit = nl80211_setdel_pmksa, | |
10592 | .policy = nl80211_policy, | |
10593 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10594 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10595 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10596 | }, |
10597 | { | |
10598 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
10599 | .doit = nl80211_flush_pmksa, | |
10600 | .policy = nl80211_policy, | |
10601 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10602 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10603 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 10604 | }, |
9588bbd5 JM |
10605 | { |
10606 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
10607 | .doit = nl80211_remain_on_channel, | |
10608 | .policy = nl80211_policy, | |
10609 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10610 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10611 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
10612 | }, |
10613 | { | |
10614 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
10615 | .doit = nl80211_cancel_remain_on_channel, | |
10616 | .policy = nl80211_policy, | |
10617 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10618 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10619 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 10620 | }, |
13ae75b1 JM |
10621 | { |
10622 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
10623 | .doit = nl80211_set_tx_bitrate_mask, | |
10624 | .policy = nl80211_policy, | |
10625 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10626 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10627 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 10628 | }, |
026331c4 | 10629 | { |
2e161f78 JB |
10630 | .cmd = NL80211_CMD_REGISTER_FRAME, |
10631 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
10632 | .policy = nl80211_policy, |
10633 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10634 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10635 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
10636 | }, |
10637 | { | |
2e161f78 JB |
10638 | .cmd = NL80211_CMD_FRAME, |
10639 | .doit = nl80211_tx_mgmt, | |
026331c4 | 10640 | .policy = nl80211_policy, |
f7ca38df | 10641 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10642 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
10643 | NL80211_FLAG_NEED_RTNL, |
10644 | }, | |
10645 | { | |
10646 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
10647 | .doit = nl80211_tx_mgmt_cancel_wait, | |
10648 | .policy = nl80211_policy, | |
026331c4 | 10649 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10650 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10651 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 10652 | }, |
ffb9eb3d KV |
10653 | { |
10654 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
10655 | .doit = nl80211_set_power_save, | |
10656 | .policy = nl80211_policy, | |
10657 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10658 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10659 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
10660 | }, |
10661 | { | |
10662 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
10663 | .doit = nl80211_get_power_save, | |
10664 | .policy = nl80211_policy, | |
10665 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
10666 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10667 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 10668 | }, |
d6dc1a38 JO |
10669 | { |
10670 | .cmd = NL80211_CMD_SET_CQM, | |
10671 | .doit = nl80211_set_cqm, | |
10672 | .policy = nl80211_policy, | |
10673 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10674 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10675 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 10676 | }, |
f444de05 JB |
10677 | { |
10678 | .cmd = NL80211_CMD_SET_CHANNEL, | |
10679 | .doit = nl80211_set_channel, | |
10680 | .policy = nl80211_policy, | |
10681 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10682 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10683 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 10684 | }, |
e8347eba BJ |
10685 | { |
10686 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
10687 | .doit = nl80211_set_wds_peer, | |
10688 | .policy = nl80211_policy, | |
10689 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
10690 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10691 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 10692 | }, |
29cbe68c JB |
10693 | { |
10694 | .cmd = NL80211_CMD_JOIN_MESH, | |
10695 | .doit = nl80211_join_mesh, | |
10696 | .policy = nl80211_policy, | |
10697 | .flags = GENL_ADMIN_PERM, | |
10698 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10699 | NL80211_FLAG_NEED_RTNL, | |
10700 | }, | |
10701 | { | |
10702 | .cmd = NL80211_CMD_LEAVE_MESH, | |
10703 | .doit = nl80211_leave_mesh, | |
10704 | .policy = nl80211_policy, | |
10705 | .flags = GENL_ADMIN_PERM, | |
10706 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10707 | NL80211_FLAG_NEED_RTNL, | |
10708 | }, | |
6e0bd6c3 RL |
10709 | { |
10710 | .cmd = NL80211_CMD_JOIN_OCB, | |
10711 | .doit = nl80211_join_ocb, | |
10712 | .policy = nl80211_policy, | |
10713 | .flags = GENL_ADMIN_PERM, | |
10714 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10715 | NL80211_FLAG_NEED_RTNL, | |
10716 | }, | |
10717 | { | |
10718 | .cmd = NL80211_CMD_LEAVE_OCB, | |
10719 | .doit = nl80211_leave_ocb, | |
10720 | .policy = nl80211_policy, | |
10721 | .flags = GENL_ADMIN_PERM, | |
10722 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10723 | NL80211_FLAG_NEED_RTNL, | |
10724 | }, | |
dfb89c56 | 10725 | #ifdef CONFIG_PM |
ff1b6e69 JB |
10726 | { |
10727 | .cmd = NL80211_CMD_GET_WOWLAN, | |
10728 | .doit = nl80211_get_wowlan, | |
10729 | .policy = nl80211_policy, | |
10730 | /* can be retrieved by unprivileged users */ | |
10731 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10732 | NL80211_FLAG_NEED_RTNL, | |
10733 | }, | |
10734 | { | |
10735 | .cmd = NL80211_CMD_SET_WOWLAN, | |
10736 | .doit = nl80211_set_wowlan, | |
10737 | .policy = nl80211_policy, | |
10738 | .flags = GENL_ADMIN_PERM, | |
10739 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10740 | NL80211_FLAG_NEED_RTNL, | |
10741 | }, | |
dfb89c56 | 10742 | #endif |
e5497d76 JB |
10743 | { |
10744 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
10745 | .doit = nl80211_set_rekey_data, | |
10746 | .policy = nl80211_policy, | |
10747 | .flags = GENL_ADMIN_PERM, | |
10748 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
5393b917 JB |
10749 | NL80211_FLAG_NEED_RTNL | |
10750 | NL80211_FLAG_CLEAR_SKB, | |
e5497d76 | 10751 | }, |
109086ce AN |
10752 | { |
10753 | .cmd = NL80211_CMD_TDLS_MGMT, | |
10754 | .doit = nl80211_tdls_mgmt, | |
10755 | .policy = nl80211_policy, | |
10756 | .flags = GENL_ADMIN_PERM, | |
10757 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10758 | NL80211_FLAG_NEED_RTNL, | |
10759 | }, | |
10760 | { | |
10761 | .cmd = NL80211_CMD_TDLS_OPER, | |
10762 | .doit = nl80211_tdls_oper, | |
10763 | .policy = nl80211_policy, | |
10764 | .flags = GENL_ADMIN_PERM, | |
10765 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10766 | NL80211_FLAG_NEED_RTNL, | |
10767 | }, | |
28946da7 JB |
10768 | { |
10769 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
10770 | .doit = nl80211_register_unexpected_frame, | |
10771 | .policy = nl80211_policy, | |
10772 | .flags = GENL_ADMIN_PERM, | |
10773 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10774 | NL80211_FLAG_NEED_RTNL, | |
10775 | }, | |
7f6cf311 JB |
10776 | { |
10777 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
10778 | .doit = nl80211_probe_client, | |
10779 | .policy = nl80211_policy, | |
10780 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10781 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
10782 | NL80211_FLAG_NEED_RTNL, |
10783 | }, | |
5e760230 JB |
10784 | { |
10785 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
10786 | .doit = nl80211_register_beacons, | |
10787 | .policy = nl80211_policy, | |
10788 | .flags = GENL_ADMIN_PERM, | |
10789 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10790 | NL80211_FLAG_NEED_RTNL, | |
10791 | }, | |
1d9d9213 SW |
10792 | { |
10793 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
10794 | .doit = nl80211_set_noack_map, | |
10795 | .policy = nl80211_policy, | |
10796 | .flags = GENL_ADMIN_PERM, | |
10797 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10798 | NL80211_FLAG_NEED_RTNL, | |
10799 | }, | |
98104fde JB |
10800 | { |
10801 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
10802 | .doit = nl80211_start_p2p_device, | |
10803 | .policy = nl80211_policy, | |
10804 | .flags = GENL_ADMIN_PERM, | |
10805 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
10806 | NL80211_FLAG_NEED_RTNL, | |
10807 | }, | |
10808 | { | |
10809 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
10810 | .doit = nl80211_stop_p2p_device, | |
10811 | .policy = nl80211_policy, | |
10812 | .flags = GENL_ADMIN_PERM, | |
10813 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10814 | NL80211_FLAG_NEED_RTNL, | |
10815 | }, | |
f4e583c8 AQ |
10816 | { |
10817 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
10818 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
10819 | .policy = nl80211_policy, |
10820 | .flags = GENL_ADMIN_PERM, | |
10821 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10822 | NL80211_FLAG_NEED_RTNL, | |
10823 | }, | |
10824 | { | |
10825 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
10826 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
10827 | .policy = nl80211_policy, |
10828 | .flags = GENL_ADMIN_PERM, | |
10829 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10830 | NL80211_FLAG_NEED_RTNL, | |
10831 | }, | |
04f39047 SW |
10832 | { |
10833 | .cmd = NL80211_CMD_RADAR_DETECT, | |
10834 | .doit = nl80211_start_radar_detection, | |
10835 | .policy = nl80211_policy, | |
10836 | .flags = GENL_ADMIN_PERM, | |
10837 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10838 | NL80211_FLAG_NEED_RTNL, | |
10839 | }, | |
3713b4e3 JB |
10840 | { |
10841 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
10842 | .doit = nl80211_get_protocol_features, | |
10843 | .policy = nl80211_policy, | |
10844 | }, | |
355199e0 JM |
10845 | { |
10846 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
10847 | .doit = nl80211_update_ft_ies, | |
10848 | .policy = nl80211_policy, | |
10849 | .flags = GENL_ADMIN_PERM, | |
10850 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10851 | NL80211_FLAG_NEED_RTNL, | |
10852 | }, | |
5de17984 AS |
10853 | { |
10854 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
10855 | .doit = nl80211_crit_protocol_start, | |
10856 | .policy = nl80211_policy, | |
10857 | .flags = GENL_ADMIN_PERM, | |
10858 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10859 | NL80211_FLAG_NEED_RTNL, | |
10860 | }, | |
10861 | { | |
10862 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
10863 | .doit = nl80211_crit_protocol_stop, | |
10864 | .policy = nl80211_policy, | |
10865 | .flags = GENL_ADMIN_PERM, | |
10866 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10867 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
10868 | }, |
10869 | { | |
10870 | .cmd = NL80211_CMD_GET_COALESCE, | |
10871 | .doit = nl80211_get_coalesce, | |
10872 | .policy = nl80211_policy, | |
10873 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10874 | NL80211_FLAG_NEED_RTNL, | |
10875 | }, | |
10876 | { | |
10877 | .cmd = NL80211_CMD_SET_COALESCE, | |
10878 | .doit = nl80211_set_coalesce, | |
10879 | .policy = nl80211_policy, | |
10880 | .flags = GENL_ADMIN_PERM, | |
10881 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10882 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
10883 | }, |
10884 | { | |
10885 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
10886 | .doit = nl80211_channel_switch, | |
10887 | .policy = nl80211_policy, | |
10888 | .flags = GENL_ADMIN_PERM, | |
10889 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10890 | NL80211_FLAG_NEED_RTNL, | |
10891 | }, | |
ad7e718c JB |
10892 | { |
10893 | .cmd = NL80211_CMD_VENDOR, | |
10894 | .doit = nl80211_vendor_cmd, | |
10895 | .policy = nl80211_policy, | |
10896 | .flags = GENL_ADMIN_PERM, | |
10897 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10898 | NL80211_FLAG_NEED_RTNL, | |
10899 | }, | |
fa9ffc74 KP |
10900 | { |
10901 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
10902 | .doit = nl80211_set_qos_map, | |
10903 | .policy = nl80211_policy, | |
10904 | .flags = GENL_ADMIN_PERM, | |
10905 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10906 | NL80211_FLAG_NEED_RTNL, | |
10907 | }, | |
960d01ac JB |
10908 | { |
10909 | .cmd = NL80211_CMD_ADD_TX_TS, | |
10910 | .doit = nl80211_add_tx_ts, | |
10911 | .policy = nl80211_policy, | |
10912 | .flags = GENL_ADMIN_PERM, | |
10913 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10914 | NL80211_FLAG_NEED_RTNL, | |
10915 | }, | |
10916 | { | |
10917 | .cmd = NL80211_CMD_DEL_TX_TS, | |
10918 | .doit = nl80211_del_tx_ts, | |
10919 | .policy = nl80211_policy, | |
10920 | .flags = GENL_ADMIN_PERM, | |
10921 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10922 | NL80211_FLAG_NEED_RTNL, | |
10923 | }, | |
1057d35e AN |
10924 | { |
10925 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | |
10926 | .doit = nl80211_tdls_channel_switch, | |
10927 | .policy = nl80211_policy, | |
10928 | .flags = GENL_ADMIN_PERM, | |
10929 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10930 | NL80211_FLAG_NEED_RTNL, | |
10931 | }, | |
10932 | { | |
10933 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | |
10934 | .doit = nl80211_tdls_cancel_channel_switch, | |
10935 | .policy = nl80211_policy, | |
10936 | .flags = GENL_ADMIN_PERM, | |
10937 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10938 | NL80211_FLAG_NEED_RTNL, | |
10939 | }, | |
55682965 | 10940 | }; |
9588bbd5 | 10941 | |
55682965 JB |
10942 | /* notification functions */ |
10943 | ||
3bb20556 JB |
10944 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
10945 | enum nl80211_commands cmd) | |
55682965 JB |
10946 | { |
10947 | struct sk_buff *msg; | |
86e8cf98 | 10948 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 10949 | |
3bb20556 JB |
10950 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
10951 | cmd != NL80211_CMD_DEL_WIPHY); | |
10952 | ||
fd2120ca | 10953 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
10954 | if (!msg) |
10955 | return; | |
10956 | ||
3bb20556 | 10957 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
10958 | nlmsg_free(msg); |
10959 | return; | |
10960 | } | |
10961 | ||
68eb5503 | 10962 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10963 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
10964 | } |
10965 | ||
362a415d JB |
10966 | static int nl80211_add_scan_req(struct sk_buff *msg, |
10967 | struct cfg80211_registered_device *rdev) | |
10968 | { | |
10969 | struct cfg80211_scan_request *req = rdev->scan_req; | |
10970 | struct nlattr *nest; | |
10971 | int i; | |
10972 | ||
10973 | if (WARN_ON(!req)) | |
10974 | return 0; | |
10975 | ||
10976 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
10977 | if (!nest) | |
10978 | goto nla_put_failure; | |
9360ffd1 DM |
10979 | for (i = 0; i < req->n_ssids; i++) { |
10980 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
10981 | goto nla_put_failure; | |
10982 | } | |
362a415d JB |
10983 | nla_nest_end(msg, nest); |
10984 | ||
10985 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
10986 | if (!nest) | |
10987 | goto nla_put_failure; | |
9360ffd1 DM |
10988 | for (i = 0; i < req->n_channels; i++) { |
10989 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
10990 | goto nla_put_failure; | |
10991 | } | |
362a415d JB |
10992 | nla_nest_end(msg, nest); |
10993 | ||
9360ffd1 DM |
10994 | if (req->ie && |
10995 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
10996 | goto nla_put_failure; | |
362a415d | 10997 | |
ae917c9f JB |
10998 | if (req->flags && |
10999 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
11000 | goto nla_put_failure; | |
ed473771 | 11001 | |
362a415d JB |
11002 | return 0; |
11003 | nla_put_failure: | |
11004 | return -ENOBUFS; | |
11005 | } | |
11006 | ||
a538e2d5 JB |
11007 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
11008 | struct cfg80211_registered_device *rdev, | |
fd014284 | 11009 | struct wireless_dev *wdev, |
15e47304 | 11010 | u32 portid, u32 seq, int flags, |
a538e2d5 | 11011 | u32 cmd) |
2a519311 JB |
11012 | { |
11013 | void *hdr; | |
11014 | ||
15e47304 | 11015 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
11016 | if (!hdr) |
11017 | return -1; | |
11018 | ||
9360ffd1 | 11019 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
11020 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11021 | wdev->netdev->ifindex)) || | |
11022 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 11023 | goto nla_put_failure; |
2a519311 | 11024 | |
362a415d JB |
11025 | /* ignore errors and send incomplete event anyway */ |
11026 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
11027 | |
11028 | return genlmsg_end(msg, hdr); | |
11029 | ||
11030 | nla_put_failure: | |
11031 | genlmsg_cancel(msg, hdr); | |
11032 | return -EMSGSIZE; | |
11033 | } | |
11034 | ||
807f8a8c LC |
11035 | static int |
11036 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
11037 | struct cfg80211_registered_device *rdev, | |
11038 | struct net_device *netdev, | |
15e47304 | 11039 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
11040 | { |
11041 | void *hdr; | |
11042 | ||
15e47304 | 11043 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
11044 | if (!hdr) |
11045 | return -1; | |
11046 | ||
9360ffd1 DM |
11047 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11048 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
11049 | goto nla_put_failure; | |
807f8a8c LC |
11050 | |
11051 | return genlmsg_end(msg, hdr); | |
11052 | ||
11053 | nla_put_failure: | |
11054 | genlmsg_cancel(msg, hdr); | |
11055 | return -EMSGSIZE; | |
11056 | } | |
11057 | ||
a538e2d5 | 11058 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 11059 | struct wireless_dev *wdev) |
a538e2d5 JB |
11060 | { |
11061 | struct sk_buff *msg; | |
11062 | ||
58050fce | 11063 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
11064 | if (!msg) |
11065 | return; | |
11066 | ||
fd014284 | 11067 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
11068 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
11069 | nlmsg_free(msg); | |
11070 | return; | |
11071 | } | |
11072 | ||
68eb5503 | 11073 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11074 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
11075 | } |
11076 | ||
f9d15d16 JB |
11077 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
11078 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
11079 | { |
11080 | struct sk_buff *msg; | |
11081 | ||
fd2120ca | 11082 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 11083 | if (!msg) |
f9d15d16 | 11084 | return NULL; |
2a519311 | 11085 | |
fd014284 | 11086 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
11087 | aborted ? NL80211_CMD_SCAN_ABORTED : |
11088 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 11089 | nlmsg_free(msg); |
f9d15d16 | 11090 | return NULL; |
2a519311 JB |
11091 | } |
11092 | ||
f9d15d16 | 11093 | return msg; |
2a519311 JB |
11094 | } |
11095 | ||
f9d15d16 JB |
11096 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
11097 | struct sk_buff *msg) | |
2a519311 | 11098 | { |
2a519311 JB |
11099 | if (!msg) |
11100 | return; | |
11101 | ||
68eb5503 | 11102 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11103 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
11104 | } |
11105 | ||
807f8a8c LC |
11106 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
11107 | struct net_device *netdev) | |
11108 | { | |
11109 | struct sk_buff *msg; | |
11110 | ||
11111 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11112 | if (!msg) | |
11113 | return; | |
11114 | ||
11115 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
11116 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
11117 | nlmsg_free(msg); | |
11118 | return; | |
11119 | } | |
11120 | ||
68eb5503 | 11121 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11122 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11123 | } |
11124 | ||
11125 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
11126 | struct net_device *netdev, u32 cmd) | |
11127 | { | |
11128 | struct sk_buff *msg; | |
11129 | ||
58050fce | 11130 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
11131 | if (!msg) |
11132 | return; | |
11133 | ||
11134 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
11135 | nlmsg_free(msg); | |
11136 | return; | |
11137 | } | |
11138 | ||
68eb5503 | 11139 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11140 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11141 | } |
11142 | ||
b0d7aa59 JD |
11143 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
11144 | struct regulatory_request *request) | |
73d54c9e | 11145 | { |
73d54c9e | 11146 | /* Userspace can always count this one always being set */ |
9360ffd1 DM |
11147 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
11148 | goto nla_put_failure; | |
11149 | ||
11150 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
11151 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11152 | NL80211_REGDOM_TYPE_WORLD)) | |
11153 | goto nla_put_failure; | |
11154 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
11155 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11156 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
11157 | goto nla_put_failure; | |
11158 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
11159 | request->intersect) { | |
11160 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11161 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
11162 | goto nla_put_failure; | |
11163 | } else { | |
11164 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11165 | NL80211_REGDOM_TYPE_COUNTRY) || | |
11166 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
11167 | request->alpha2)) | |
11168 | goto nla_put_failure; | |
11169 | } | |
11170 | ||
ad30ca2c AN |
11171 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
11172 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); | |
11173 | ||
11174 | if (wiphy && | |
11175 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | |
11176 | goto nla_put_failure; | |
1bdd716c AN |
11177 | |
11178 | if (wiphy && | |
11179 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | |
11180 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
11181 | goto nla_put_failure; | |
ad30ca2c | 11182 | } |
73d54c9e | 11183 | |
b0d7aa59 JD |
11184 | return true; |
11185 | ||
11186 | nla_put_failure: | |
11187 | return false; | |
11188 | } | |
11189 | ||
11190 | /* | |
11191 | * This can happen on global regulatory changes or device specific settings | |
11192 | * based on custom regulatory domains. | |
11193 | */ | |
11194 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, | |
11195 | struct regulatory_request *request) | |
11196 | { | |
11197 | struct sk_buff *msg; | |
11198 | void *hdr; | |
11199 | ||
11200 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11201 | if (!msg) | |
11202 | return; | |
11203 | ||
11204 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); | |
11205 | if (!hdr) { | |
11206 | nlmsg_free(msg); | |
11207 | return; | |
11208 | } | |
11209 | ||
11210 | if (nl80211_reg_change_event_fill(msg, request) == false) | |
11211 | goto nla_put_failure; | |
11212 | ||
3b7b72ee | 11213 | genlmsg_end(msg, hdr); |
73d54c9e | 11214 | |
bc43b28c | 11215 | rcu_read_lock(); |
68eb5503 | 11216 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11217 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 11218 | rcu_read_unlock(); |
73d54c9e LR |
11219 | |
11220 | return; | |
11221 | ||
11222 | nla_put_failure: | |
11223 | genlmsg_cancel(msg, hdr); | |
11224 | nlmsg_free(msg); | |
11225 | } | |
11226 | ||
6039f6d2 JM |
11227 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
11228 | struct net_device *netdev, | |
11229 | const u8 *buf, size_t len, | |
b0b6aa2c EP |
11230 | enum nl80211_commands cmd, gfp_t gfp, |
11231 | int uapsd_queues) | |
6039f6d2 JM |
11232 | { |
11233 | struct sk_buff *msg; | |
11234 | void *hdr; | |
11235 | ||
e6d6e342 | 11236 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
11237 | if (!msg) |
11238 | return; | |
11239 | ||
11240 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11241 | if (!hdr) { | |
11242 | nlmsg_free(msg); | |
11243 | return; | |
11244 | } | |
11245 | ||
9360ffd1 DM |
11246 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11247 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11248 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
11249 | goto nla_put_failure; | |
6039f6d2 | 11250 | |
b0b6aa2c EP |
11251 | if (uapsd_queues >= 0) { |
11252 | struct nlattr *nla_wmm = | |
11253 | nla_nest_start(msg, NL80211_ATTR_STA_WME); | |
11254 | if (!nla_wmm) | |
11255 | goto nla_put_failure; | |
11256 | ||
11257 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
11258 | uapsd_queues)) | |
11259 | goto nla_put_failure; | |
11260 | ||
11261 | nla_nest_end(msg, nla_wmm); | |
11262 | } | |
11263 | ||
3b7b72ee | 11264 | genlmsg_end(msg, hdr); |
6039f6d2 | 11265 | |
68eb5503 | 11266 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11267 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
11268 | return; |
11269 | ||
11270 | nla_put_failure: | |
11271 | genlmsg_cancel(msg, hdr); | |
11272 | nlmsg_free(msg); | |
11273 | } | |
11274 | ||
11275 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11276 | struct net_device *netdev, const u8 *buf, |
11277 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11278 | { |
11279 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11280 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11281 | } |
11282 | ||
11283 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
11284 | struct net_device *netdev, const u8 *buf, | |
b0b6aa2c | 11285 | size_t len, gfp_t gfp, int uapsd_queues) |
6039f6d2 | 11286 | { |
e6d6e342 | 11287 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
b0b6aa2c | 11288 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
6039f6d2 JM |
11289 | } |
11290 | ||
53b46b84 | 11291 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
11292 | struct net_device *netdev, const u8 *buf, |
11293 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11294 | { |
11295 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11296 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11297 | } |
11298 | ||
53b46b84 JM |
11299 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
11300 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 11301 | size_t len, gfp_t gfp) |
6039f6d2 JM |
11302 | { |
11303 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11304 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
6039f6d2 JM |
11305 | } |
11306 | ||
6ff57cf8 JB |
11307 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
11308 | size_t len) | |
cf4e594e | 11309 | { |
947add36 JB |
11310 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11311 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11312 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
11313 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
11314 | u32 cmd; | |
947add36 | 11315 | |
6ff57cf8 JB |
11316 | if (WARN_ON(len < 2)) |
11317 | return; | |
cf4e594e | 11318 | |
6ff57cf8 JB |
11319 | if (ieee80211_is_deauth(mgmt->frame_control)) |
11320 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
11321 | else | |
11322 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 11323 | |
6ff57cf8 | 11324 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
b0b6aa2c | 11325 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
cf4e594e | 11326 | } |
6ff57cf8 | 11327 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 11328 | |
1b06bb40 LR |
11329 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
11330 | struct net_device *netdev, int cmd, | |
e6d6e342 | 11331 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
11332 | { |
11333 | struct sk_buff *msg; | |
11334 | void *hdr; | |
11335 | ||
e6d6e342 | 11336 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
11337 | if (!msg) |
11338 | return; | |
11339 | ||
11340 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11341 | if (!hdr) { | |
11342 | nlmsg_free(msg); | |
11343 | return; | |
11344 | } | |
11345 | ||
9360ffd1 DM |
11346 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11347 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11348 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
11349 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11350 | goto nla_put_failure; | |
1965c853 | 11351 | |
3b7b72ee | 11352 | genlmsg_end(msg, hdr); |
1965c853 | 11353 | |
68eb5503 | 11354 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11355 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
11356 | return; |
11357 | ||
11358 | nla_put_failure: | |
11359 | genlmsg_cancel(msg, hdr); | |
11360 | nlmsg_free(msg); | |
11361 | } | |
11362 | ||
11363 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11364 | struct net_device *netdev, const u8 *addr, |
11365 | gfp_t gfp) | |
1965c853 JM |
11366 | { |
11367 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 11368 | addr, gfp); |
1965c853 JM |
11369 | } |
11370 | ||
11371 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11372 | struct net_device *netdev, const u8 *addr, |
11373 | gfp_t gfp) | |
1965c853 | 11374 | { |
e6d6e342 JB |
11375 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
11376 | addr, gfp); | |
1965c853 JM |
11377 | } |
11378 | ||
b23aa676 SO |
11379 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
11380 | struct net_device *netdev, const u8 *bssid, | |
11381 | const u8 *req_ie, size_t req_ie_len, | |
11382 | const u8 *resp_ie, size_t resp_ie_len, | |
11383 | u16 status, gfp_t gfp) | |
11384 | { | |
11385 | struct sk_buff *msg; | |
11386 | void *hdr; | |
11387 | ||
58050fce | 11388 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
11389 | if (!msg) |
11390 | return; | |
11391 | ||
11392 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
11393 | if (!hdr) { | |
11394 | nlmsg_free(msg); | |
11395 | return; | |
11396 | } | |
11397 | ||
9360ffd1 DM |
11398 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11399 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11400 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
11401 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
11402 | (req_ie && | |
11403 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11404 | (resp_ie && | |
11405 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11406 | goto nla_put_failure; | |
b23aa676 | 11407 | |
3b7b72ee | 11408 | genlmsg_end(msg, hdr); |
b23aa676 | 11409 | |
68eb5503 | 11410 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11411 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11412 | return; |
11413 | ||
11414 | nla_put_failure: | |
11415 | genlmsg_cancel(msg, hdr); | |
11416 | nlmsg_free(msg); | |
11417 | ||
11418 | } | |
11419 | ||
11420 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
11421 | struct net_device *netdev, const u8 *bssid, | |
11422 | const u8 *req_ie, size_t req_ie_len, | |
11423 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
11424 | { | |
11425 | struct sk_buff *msg; | |
11426 | void *hdr; | |
11427 | ||
58050fce | 11428 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
11429 | if (!msg) |
11430 | return; | |
11431 | ||
11432 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
11433 | if (!hdr) { | |
11434 | nlmsg_free(msg); | |
11435 | return; | |
11436 | } | |
11437 | ||
9360ffd1 DM |
11438 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11439 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11440 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
11441 | (req_ie && | |
11442 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11443 | (resp_ie && | |
11444 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11445 | goto nla_put_failure; | |
b23aa676 | 11446 | |
3b7b72ee | 11447 | genlmsg_end(msg, hdr); |
b23aa676 | 11448 | |
68eb5503 | 11449 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11450 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11451 | return; |
11452 | ||
11453 | nla_put_failure: | |
11454 | genlmsg_cancel(msg, hdr); | |
11455 | nlmsg_free(msg); | |
11456 | ||
11457 | } | |
11458 | ||
11459 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
11460 | struct net_device *netdev, u16 reason, | |
667503dd | 11461 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
11462 | { |
11463 | struct sk_buff *msg; | |
11464 | void *hdr; | |
11465 | ||
58050fce | 11466 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
11467 | if (!msg) |
11468 | return; | |
11469 | ||
11470 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
11471 | if (!hdr) { | |
11472 | nlmsg_free(msg); | |
11473 | return; | |
11474 | } | |
11475 | ||
9360ffd1 DM |
11476 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11477 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11478 | (from_ap && reason && | |
11479 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
11480 | (from_ap && | |
11481 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
11482 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
11483 | goto nla_put_failure; | |
b23aa676 | 11484 | |
3b7b72ee | 11485 | genlmsg_end(msg, hdr); |
b23aa676 | 11486 | |
68eb5503 | 11487 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11488 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
11489 | return; |
11490 | ||
11491 | nla_put_failure: | |
11492 | genlmsg_cancel(msg, hdr); | |
11493 | nlmsg_free(msg); | |
11494 | ||
11495 | } | |
11496 | ||
04a773ad JB |
11497 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
11498 | struct net_device *netdev, const u8 *bssid, | |
11499 | gfp_t gfp) | |
11500 | { | |
11501 | struct sk_buff *msg; | |
11502 | void *hdr; | |
11503 | ||
fd2120ca | 11504 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
11505 | if (!msg) |
11506 | return; | |
11507 | ||
11508 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
11509 | if (!hdr) { | |
11510 | nlmsg_free(msg); | |
11511 | return; | |
11512 | } | |
11513 | ||
9360ffd1 DM |
11514 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11515 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11516 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
11517 | goto nla_put_failure; | |
04a773ad | 11518 | |
3b7b72ee | 11519 | genlmsg_end(msg, hdr); |
04a773ad | 11520 | |
68eb5503 | 11521 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11522 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
11523 | return; |
11524 | ||
11525 | nla_put_failure: | |
11526 | genlmsg_cancel(msg, hdr); | |
11527 | nlmsg_free(msg); | |
11528 | } | |
11529 | ||
947add36 JB |
11530 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
11531 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 11532 | { |
947add36 | 11533 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 11534 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
11535 | struct sk_buff *msg; |
11536 | void *hdr; | |
11537 | ||
947add36 JB |
11538 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
11539 | return; | |
11540 | ||
11541 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
11542 | ||
c93b5e71 JC |
11543 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11544 | if (!msg) | |
11545 | return; | |
11546 | ||
11547 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
11548 | if (!hdr) { | |
11549 | nlmsg_free(msg); | |
11550 | return; | |
11551 | } | |
11552 | ||
9360ffd1 | 11553 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
11554 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
11555 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
11556 | (ie_len && ie && |
11557 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
11558 | goto nla_put_failure; | |
c93b5e71 | 11559 | |
3b7b72ee | 11560 | genlmsg_end(msg, hdr); |
c93b5e71 | 11561 | |
68eb5503 | 11562 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11563 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
11564 | return; |
11565 | ||
11566 | nla_put_failure: | |
11567 | genlmsg_cancel(msg, hdr); | |
11568 | nlmsg_free(msg); | |
11569 | } | |
947add36 | 11570 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 11571 | |
a3b8b056 JM |
11572 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
11573 | struct net_device *netdev, const u8 *addr, | |
11574 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 11575 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
11576 | { |
11577 | struct sk_buff *msg; | |
11578 | void *hdr; | |
11579 | ||
e6d6e342 | 11580 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
11581 | if (!msg) |
11582 | return; | |
11583 | ||
11584 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
11585 | if (!hdr) { | |
11586 | nlmsg_free(msg); | |
11587 | return; | |
11588 | } | |
11589 | ||
9360ffd1 DM |
11590 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11591 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11592 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
11593 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
11594 | (key_id != -1 && | |
11595 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
11596 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
11597 | goto nla_put_failure; | |
a3b8b056 | 11598 | |
3b7b72ee | 11599 | genlmsg_end(msg, hdr); |
a3b8b056 | 11600 | |
68eb5503 | 11601 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11602 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
11603 | return; |
11604 | ||
11605 | nla_put_failure: | |
11606 | genlmsg_cancel(msg, hdr); | |
11607 | nlmsg_free(msg); | |
11608 | } | |
11609 | ||
6bad8766 LR |
11610 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
11611 | struct ieee80211_channel *channel_before, | |
11612 | struct ieee80211_channel *channel_after) | |
11613 | { | |
11614 | struct sk_buff *msg; | |
11615 | void *hdr; | |
11616 | struct nlattr *nl_freq; | |
11617 | ||
fd2120ca | 11618 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
11619 | if (!msg) |
11620 | return; | |
11621 | ||
11622 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
11623 | if (!hdr) { | |
11624 | nlmsg_free(msg); | |
11625 | return; | |
11626 | } | |
11627 | ||
11628 | /* | |
11629 | * Since we are applying the beacon hint to a wiphy we know its | |
11630 | * wiphy_idx is valid | |
11631 | */ | |
9360ffd1 DM |
11632 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
11633 | goto nla_put_failure; | |
6bad8766 LR |
11634 | |
11635 | /* Before */ | |
11636 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
11637 | if (!nl_freq) | |
11638 | goto nla_put_failure; | |
cdc89b97 | 11639 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
11640 | goto nla_put_failure; |
11641 | nla_nest_end(msg, nl_freq); | |
11642 | ||
11643 | /* After */ | |
11644 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
11645 | if (!nl_freq) | |
11646 | goto nla_put_failure; | |
cdc89b97 | 11647 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
11648 | goto nla_put_failure; |
11649 | nla_nest_end(msg, nl_freq); | |
11650 | ||
3b7b72ee | 11651 | genlmsg_end(msg, hdr); |
6bad8766 | 11652 | |
463d0183 | 11653 | rcu_read_lock(); |
68eb5503 | 11654 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11655 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 11656 | rcu_read_unlock(); |
6bad8766 LR |
11657 | |
11658 | return; | |
11659 | ||
11660 | nla_put_failure: | |
11661 | genlmsg_cancel(msg, hdr); | |
11662 | nlmsg_free(msg); | |
11663 | } | |
11664 | ||
9588bbd5 JM |
11665 | static void nl80211_send_remain_on_chan_event( |
11666 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 11667 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 11668 | struct ieee80211_channel *chan, |
9588bbd5 JM |
11669 | unsigned int duration, gfp_t gfp) |
11670 | { | |
11671 | struct sk_buff *msg; | |
11672 | void *hdr; | |
11673 | ||
11674 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11675 | if (!msg) | |
11676 | return; | |
11677 | ||
11678 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11679 | if (!hdr) { | |
11680 | nlmsg_free(msg); | |
11681 | return; | |
11682 | } | |
11683 | ||
9360ffd1 | 11684 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11685 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11686 | wdev->netdev->ifindex)) || | |
00f53350 | 11687 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 11688 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
11689 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
11690 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
11691 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
11692 | goto nla_put_failure; | |
9588bbd5 | 11693 | |
9360ffd1 DM |
11694 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
11695 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
11696 | goto nla_put_failure; | |
9588bbd5 | 11697 | |
3b7b72ee | 11698 | genlmsg_end(msg, hdr); |
9588bbd5 | 11699 | |
68eb5503 | 11700 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11701 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
11702 | return; |
11703 | ||
11704 | nla_put_failure: | |
11705 | genlmsg_cancel(msg, hdr); | |
11706 | nlmsg_free(msg); | |
11707 | } | |
11708 | ||
947add36 JB |
11709 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
11710 | struct ieee80211_channel *chan, | |
11711 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 11712 | { |
947add36 | 11713 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11714 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11715 | |
11716 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 11717 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 11718 | rdev, wdev, cookie, chan, |
42d97a59 | 11719 | duration, gfp); |
9588bbd5 | 11720 | } |
947add36 | 11721 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 11722 | |
947add36 JB |
11723 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
11724 | struct ieee80211_channel *chan, | |
11725 | gfp_t gfp) | |
9588bbd5 | 11726 | { |
947add36 | 11727 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11728 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11729 | |
11730 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 11731 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 11732 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 11733 | } |
947add36 | 11734 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 11735 | |
947add36 JB |
11736 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
11737 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 11738 | { |
947add36 | 11739 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11740 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
11741 | struct sk_buff *msg; |
11742 | ||
947add36 JB |
11743 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
11744 | ||
58050fce | 11745 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
11746 | if (!msg) |
11747 | return; | |
11748 | ||
cf5ead82 | 11749 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
66266b3a | 11750 | rdev, dev, mac_addr, sinfo) < 0) { |
98b62183 JB |
11751 | nlmsg_free(msg); |
11752 | return; | |
11753 | } | |
11754 | ||
68eb5503 | 11755 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11756 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 11757 | } |
947add36 | 11758 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 11759 | |
cf5ead82 JB |
11760 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
11761 | struct station_info *sinfo, gfp_t gfp) | |
ec15e68b | 11762 | { |
947add36 | 11763 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11764 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b | 11765 | struct sk_buff *msg; |
cf5ead82 JB |
11766 | struct station_info empty_sinfo = {}; |
11767 | ||
11768 | if (!sinfo) | |
11769 | sinfo = &empty_sinfo; | |
ec15e68b | 11770 | |
947add36 JB |
11771 | trace_cfg80211_del_sta(dev, mac_addr); |
11772 | ||
58050fce | 11773 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
11774 | if (!msg) |
11775 | return; | |
11776 | ||
cf5ead82 JB |
11777 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
11778 | rdev, dev, mac_addr, sinfo)) { | |
ec15e68b JM |
11779 | nlmsg_free(msg); |
11780 | return; | |
11781 | } | |
11782 | ||
68eb5503 | 11783 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11784 | NL80211_MCGRP_MLME, gfp); |
ec15e68b | 11785 | } |
cf5ead82 | 11786 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
ec15e68b | 11787 | |
947add36 JB |
11788 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
11789 | enum nl80211_connect_failed_reason reason, | |
11790 | gfp_t gfp) | |
ed44a951 | 11791 | { |
947add36 | 11792 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11793 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
11794 | struct sk_buff *msg; |
11795 | void *hdr; | |
11796 | ||
11797 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
11798 | if (!msg) | |
11799 | return; | |
11800 | ||
11801 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
11802 | if (!hdr) { | |
11803 | nlmsg_free(msg); | |
11804 | return; | |
11805 | } | |
11806 | ||
11807 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11808 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
11809 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
11810 | goto nla_put_failure; | |
11811 | ||
11812 | genlmsg_end(msg, hdr); | |
11813 | ||
68eb5503 | 11814 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11815 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
11816 | return; |
11817 | ||
11818 | nla_put_failure: | |
11819 | genlmsg_cancel(msg, hdr); | |
11820 | nlmsg_free(msg); | |
11821 | } | |
947add36 | 11822 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 11823 | |
b92ab5d8 JB |
11824 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
11825 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
11826 | { |
11827 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 11828 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
11829 | struct sk_buff *msg; |
11830 | void *hdr; | |
15e47304 | 11831 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 11832 | |
15e47304 | 11833 | if (!nlportid) |
28946da7 JB |
11834 | return false; |
11835 | ||
11836 | msg = nlmsg_new(100, gfp); | |
11837 | if (!msg) | |
11838 | return true; | |
11839 | ||
b92ab5d8 | 11840 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
11841 | if (!hdr) { |
11842 | nlmsg_free(msg); | |
11843 | return true; | |
11844 | } | |
11845 | ||
9360ffd1 DM |
11846 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11847 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11848 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11849 | goto nla_put_failure; | |
28946da7 | 11850 | |
9c90a9f6 | 11851 | genlmsg_end(msg, hdr); |
15e47304 | 11852 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
11853 | return true; |
11854 | ||
11855 | nla_put_failure: | |
11856 | genlmsg_cancel(msg, hdr); | |
11857 | nlmsg_free(msg); | |
11858 | return true; | |
11859 | } | |
11860 | ||
947add36 JB |
11861 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
11862 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11863 | { |
947add36 JB |
11864 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11865 | bool ret; | |
11866 | ||
11867 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
11868 | ||
11869 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11870 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
11871 | trace_cfg80211_return_bool(false); | |
11872 | return false; | |
11873 | } | |
11874 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
11875 | addr, gfp); | |
11876 | trace_cfg80211_return_bool(ret); | |
11877 | return ret; | |
b92ab5d8 | 11878 | } |
947add36 | 11879 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 11880 | |
947add36 JB |
11881 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
11882 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11883 | { |
947add36 JB |
11884 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11885 | bool ret; | |
11886 | ||
11887 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
11888 | ||
11889 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11890 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
11891 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
11892 | trace_cfg80211_return_bool(false); | |
11893 | return false; | |
11894 | } | |
11895 | ret = __nl80211_unexpected_frame(dev, | |
11896 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
11897 | addr, gfp); | |
11898 | trace_cfg80211_return_bool(ret); | |
11899 | return ret; | |
b92ab5d8 | 11900 | } |
947add36 | 11901 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 11902 | |
2e161f78 | 11903 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 11904 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 11905 | int freq, int sig_dbm, |
19504cf5 | 11906 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 11907 | { |
71bbc994 | 11908 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11909 | struct sk_buff *msg; |
11910 | void *hdr; | |
026331c4 JM |
11911 | |
11912 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11913 | if (!msg) | |
11914 | return -ENOMEM; | |
11915 | ||
2e161f78 | 11916 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
11917 | if (!hdr) { |
11918 | nlmsg_free(msg); | |
11919 | return -ENOMEM; | |
11920 | } | |
11921 | ||
9360ffd1 | 11922 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11923 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11924 | netdev->ifindex)) || | |
a838490b | 11925 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11926 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
11927 | (sig_dbm && | |
11928 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
11929 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11930 | (flags && | |
11931 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 11932 | goto nla_put_failure; |
026331c4 | 11933 | |
3b7b72ee | 11934 | genlmsg_end(msg, hdr); |
026331c4 | 11935 | |
15e47304 | 11936 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
11937 | |
11938 | nla_put_failure: | |
11939 | genlmsg_cancel(msg, hdr); | |
11940 | nlmsg_free(msg); | |
11941 | return -ENOBUFS; | |
11942 | } | |
11943 | ||
947add36 JB |
11944 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
11945 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 11946 | { |
947add36 | 11947 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11948 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 11949 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11950 | struct sk_buff *msg; |
11951 | void *hdr; | |
11952 | ||
947add36 JB |
11953 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
11954 | ||
026331c4 JM |
11955 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11956 | if (!msg) | |
11957 | return; | |
11958 | ||
2e161f78 | 11959 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
11960 | if (!hdr) { |
11961 | nlmsg_free(msg); | |
11962 | return; | |
11963 | } | |
11964 | ||
9360ffd1 | 11965 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11966 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11967 | netdev->ifindex)) || | |
a838490b | 11968 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11969 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11970 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
11971 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
11972 | goto nla_put_failure; | |
026331c4 | 11973 | |
3b7b72ee | 11974 | genlmsg_end(msg, hdr); |
026331c4 | 11975 | |
68eb5503 | 11976 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11977 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
11978 | return; |
11979 | ||
11980 | nla_put_failure: | |
11981 | genlmsg_cancel(msg, hdr); | |
11982 | nlmsg_free(msg); | |
11983 | } | |
947add36 | 11984 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 11985 | |
5b97f49d JB |
11986 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
11987 | const char *mac, gfp_t gfp) | |
d6dc1a38 | 11988 | { |
947add36 | 11989 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5b97f49d JB |
11990 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
11991 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11992 | void **cb; | |
947add36 | 11993 | |
d6dc1a38 | 11994 | if (!msg) |
5b97f49d | 11995 | return NULL; |
d6dc1a38 | 11996 | |
5b97f49d JB |
11997 | cb = (void **)msg->cb; |
11998 | ||
11999 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
12000 | if (!cb[0]) { | |
d6dc1a38 | 12001 | nlmsg_free(msg); |
5b97f49d | 12002 | return NULL; |
d6dc1a38 JO |
12003 | } |
12004 | ||
9360ffd1 | 12005 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 12006 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 12007 | goto nla_put_failure; |
d6dc1a38 | 12008 | |
5b97f49d | 12009 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
d6dc1a38 JO |
12010 | goto nla_put_failure; |
12011 | ||
5b97f49d JB |
12012 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
12013 | if (!cb[1]) | |
9360ffd1 | 12014 | goto nla_put_failure; |
d6dc1a38 | 12015 | |
5b97f49d | 12016 | cb[2] = rdev; |
d6dc1a38 | 12017 | |
5b97f49d JB |
12018 | return msg; |
12019 | nla_put_failure: | |
12020 | nlmsg_free(msg); | |
12021 | return NULL; | |
12022 | } | |
12023 | ||
12024 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) | |
12025 | { | |
12026 | void **cb = (void **)msg->cb; | |
12027 | struct cfg80211_registered_device *rdev = cb[2]; | |
12028 | ||
12029 | nla_nest_end(msg, cb[1]); | |
12030 | genlmsg_end(msg, cb[0]); | |
12031 | ||
12032 | memset(msg->cb, 0, sizeof(msg->cb)); | |
d6dc1a38 | 12033 | |
68eb5503 | 12034 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12035 | NL80211_MCGRP_MLME, gfp); |
5b97f49d JB |
12036 | } |
12037 | ||
12038 | void cfg80211_cqm_rssi_notify(struct net_device *dev, | |
12039 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
12040 | gfp_t gfp) | |
12041 | { | |
12042 | struct sk_buff *msg; | |
12043 | ||
12044 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); | |
12045 | ||
98f03342 JB |
12046 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
12047 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) | |
12048 | return; | |
12049 | ||
5b97f49d JB |
12050 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
12051 | if (!msg) | |
12052 | return; | |
12053 | ||
12054 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
12055 | rssi_event)) | |
12056 | goto nla_put_failure; | |
12057 | ||
12058 | cfg80211_send_cqm(msg, gfp); | |
12059 | ||
d6dc1a38 JO |
12060 | return; |
12061 | ||
12062 | nla_put_failure: | |
d6dc1a38 JO |
12063 | nlmsg_free(msg); |
12064 | } | |
947add36 | 12065 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 12066 | |
5b97f49d JB |
12067 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
12068 | const u8 *peer, u32 num_packets, | |
12069 | u32 rate, u32 intvl, gfp_t gfp) | |
12070 | { | |
12071 | struct sk_buff *msg; | |
12072 | ||
12073 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12074 | if (!msg) | |
12075 | return; | |
12076 | ||
12077 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
12078 | goto nla_put_failure; | |
12079 | ||
12080 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
12081 | goto nla_put_failure; | |
12082 | ||
12083 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
12084 | goto nla_put_failure; | |
12085 | ||
12086 | cfg80211_send_cqm(msg, gfp); | |
12087 | return; | |
12088 | ||
12089 | nla_put_failure: | |
12090 | nlmsg_free(msg); | |
12091 | } | |
12092 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); | |
12093 | ||
12094 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, | |
12095 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
12096 | { | |
12097 | struct sk_buff *msg; | |
12098 | ||
12099 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); | |
12100 | ||
12101 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12102 | if (!msg) | |
12103 | return; | |
12104 | ||
12105 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) | |
12106 | goto nla_put_failure; | |
12107 | ||
12108 | cfg80211_send_cqm(msg, gfp); | |
12109 | return; | |
12110 | ||
12111 | nla_put_failure: | |
12112 | nlmsg_free(msg); | |
12113 | } | |
12114 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); | |
12115 | ||
98f03342 JB |
12116 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
12117 | { | |
12118 | struct sk_buff *msg; | |
12119 | ||
12120 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); | |
12121 | if (!msg) | |
12122 | return; | |
12123 | ||
12124 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) | |
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_beacon_loss_notify); | |
12134 | ||
947add36 JB |
12135 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
12136 | struct net_device *netdev, const u8 *bssid, | |
12137 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
12138 | { |
12139 | struct sk_buff *msg; | |
12140 | struct nlattr *rekey_attr; | |
12141 | void *hdr; | |
12142 | ||
58050fce | 12143 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
12144 | if (!msg) |
12145 | return; | |
12146 | ||
12147 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
12148 | if (!hdr) { | |
12149 | nlmsg_free(msg); | |
12150 | return; | |
12151 | } | |
12152 | ||
9360ffd1 DM |
12153 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12154 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12155 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
12156 | goto nla_put_failure; | |
e5497d76 JB |
12157 | |
12158 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
12159 | if (!rekey_attr) | |
12160 | goto nla_put_failure; | |
12161 | ||
9360ffd1 DM |
12162 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
12163 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
12164 | goto nla_put_failure; | |
e5497d76 JB |
12165 | |
12166 | nla_nest_end(msg, rekey_attr); | |
12167 | ||
3b7b72ee | 12168 | genlmsg_end(msg, hdr); |
e5497d76 | 12169 | |
68eb5503 | 12170 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12171 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
12172 | return; |
12173 | ||
12174 | nla_put_failure: | |
12175 | genlmsg_cancel(msg, hdr); | |
12176 | nlmsg_free(msg); | |
12177 | } | |
12178 | ||
947add36 JB |
12179 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
12180 | const u8 *replay_ctr, gfp_t gfp) | |
12181 | { | |
12182 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12183 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12184 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12185 | |
12186 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
12187 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
12188 | } | |
12189 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
12190 | ||
12191 | static void | |
12192 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
12193 | struct net_device *netdev, int index, | |
12194 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
12195 | { |
12196 | struct sk_buff *msg; | |
12197 | struct nlattr *attr; | |
12198 | void *hdr; | |
12199 | ||
58050fce | 12200 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
12201 | if (!msg) |
12202 | return; | |
12203 | ||
12204 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
12205 | if (!hdr) { | |
12206 | nlmsg_free(msg); | |
12207 | return; | |
12208 | } | |
12209 | ||
9360ffd1 DM |
12210 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12211 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
12212 | goto nla_put_failure; | |
c9df56b4 JM |
12213 | |
12214 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
12215 | if (!attr) | |
12216 | goto nla_put_failure; | |
12217 | ||
9360ffd1 DM |
12218 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
12219 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
12220 | (preauth && | |
12221 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
12222 | goto nla_put_failure; | |
c9df56b4 JM |
12223 | |
12224 | nla_nest_end(msg, attr); | |
12225 | ||
3b7b72ee | 12226 | genlmsg_end(msg, hdr); |
c9df56b4 | 12227 | |
68eb5503 | 12228 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12229 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
12230 | return; |
12231 | ||
12232 | nla_put_failure: | |
12233 | genlmsg_cancel(msg, hdr); | |
12234 | nlmsg_free(msg); | |
12235 | } | |
12236 | ||
947add36 JB |
12237 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
12238 | const u8 *bssid, bool preauth, gfp_t gfp) | |
12239 | { | |
12240 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12241 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12242 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12243 | |
12244 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
12245 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
12246 | } | |
12247 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
12248 | ||
12249 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
12250 | struct net_device *netdev, | |
12251 | struct cfg80211_chan_def *chandef, | |
f8d7552e LC |
12252 | gfp_t gfp, |
12253 | enum nl80211_commands notif, | |
12254 | u8 count) | |
5314526b TP |
12255 | { |
12256 | struct sk_buff *msg; | |
12257 | void *hdr; | |
12258 | ||
58050fce | 12259 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
12260 | if (!msg) |
12261 | return; | |
12262 | ||
f8d7552e | 12263 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
5314526b TP |
12264 | if (!hdr) { |
12265 | nlmsg_free(msg); | |
12266 | return; | |
12267 | } | |
12268 | ||
683b6d3b JB |
12269 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
12270 | goto nla_put_failure; | |
12271 | ||
12272 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 12273 | goto nla_put_failure; |
5314526b | 12274 | |
f8d7552e LC |
12275 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
12276 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) | |
12277 | goto nla_put_failure; | |
12278 | ||
5314526b TP |
12279 | genlmsg_end(msg, hdr); |
12280 | ||
68eb5503 | 12281 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12282 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
12283 | return; |
12284 | ||
12285 | nla_put_failure: | |
12286 | genlmsg_cancel(msg, hdr); | |
12287 | nlmsg_free(msg); | |
12288 | } | |
12289 | ||
947add36 JB |
12290 | void cfg80211_ch_switch_notify(struct net_device *dev, |
12291 | struct cfg80211_chan_def *chandef) | |
84f10708 | 12292 | { |
947add36 JB |
12293 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
12294 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12295 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 12296 | |
e487eaeb | 12297 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 12298 | |
e487eaeb | 12299 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 | 12300 | |
9e0e2961 | 12301 | wdev->chandef = *chandef; |
96f55f12 | 12302 | wdev->preset_chandef = *chandef; |
f8d7552e LC |
12303 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
12304 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); | |
947add36 JB |
12305 | } |
12306 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
12307 | ||
f8d7552e LC |
12308 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
12309 | struct cfg80211_chan_def *chandef, | |
12310 | u8 count) | |
12311 | { | |
12312 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12313 | struct wiphy *wiphy = wdev->wiphy; | |
12314 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
12315 | ||
12316 | trace_cfg80211_ch_switch_started_notify(dev, chandef); | |
12317 | ||
12318 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | |
12319 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); | |
12320 | } | |
12321 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | |
12322 | ||
04f39047 SW |
12323 | void |
12324 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 12325 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
12326 | enum nl80211_radar_event event, |
12327 | struct net_device *netdev, gfp_t gfp) | |
12328 | { | |
12329 | struct sk_buff *msg; | |
12330 | void *hdr; | |
12331 | ||
12332 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12333 | if (!msg) | |
12334 | return; | |
12335 | ||
12336 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
12337 | if (!hdr) { | |
12338 | nlmsg_free(msg); | |
12339 | return; | |
12340 | } | |
12341 | ||
12342 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
12343 | goto nla_put_failure; | |
12344 | ||
12345 | /* NOP and radar events don't need a netdev parameter */ | |
12346 | if (netdev) { | |
12347 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
12348 | ||
12349 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12350 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12351 | goto nla_put_failure; | |
12352 | } | |
12353 | ||
12354 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
12355 | goto nla_put_failure; | |
12356 | ||
12357 | if (nl80211_send_chandef(msg, chandef)) | |
12358 | goto nla_put_failure; | |
12359 | ||
9c90a9f6 | 12360 | genlmsg_end(msg, hdr); |
04f39047 | 12361 | |
68eb5503 | 12362 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12363 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
12364 | return; |
12365 | ||
12366 | nla_put_failure: | |
12367 | genlmsg_cancel(msg, hdr); | |
12368 | nlmsg_free(msg); | |
12369 | } | |
12370 | ||
7f6cf311 JB |
12371 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
12372 | u64 cookie, bool acked, gfp_t gfp) | |
12373 | { | |
12374 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12375 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
12376 | struct sk_buff *msg; |
12377 | void *hdr; | |
7f6cf311 | 12378 | |
4ee3e063 BL |
12379 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
12380 | ||
58050fce | 12381 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 12382 | |
7f6cf311 JB |
12383 | if (!msg) |
12384 | return; | |
12385 | ||
12386 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
12387 | if (!hdr) { | |
12388 | nlmsg_free(msg); | |
12389 | return; | |
12390 | } | |
12391 | ||
9360ffd1 DM |
12392 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12393 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12394 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
12395 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
12396 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
12397 | goto nla_put_failure; | |
7f6cf311 | 12398 | |
9c90a9f6 | 12399 | genlmsg_end(msg, hdr); |
7f6cf311 | 12400 | |
68eb5503 | 12401 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12402 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
12403 | return; |
12404 | ||
12405 | nla_put_failure: | |
12406 | genlmsg_cancel(msg, hdr); | |
12407 | nlmsg_free(msg); | |
12408 | } | |
12409 | EXPORT_SYMBOL(cfg80211_probe_status); | |
12410 | ||
5e760230 JB |
12411 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
12412 | const u8 *frame, size_t len, | |
37c73b5f | 12413 | int freq, int sig_dbm) |
5e760230 | 12414 | { |
f26cbf40 | 12415 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
12416 | struct sk_buff *msg; |
12417 | void *hdr; | |
37c73b5f | 12418 | struct cfg80211_beacon_registration *reg; |
5e760230 | 12419 | |
4ee3e063 BL |
12420 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
12421 | ||
37c73b5f BG |
12422 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12423 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
12424 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
12425 | if (!msg) { | |
12426 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
12427 | return; | |
12428 | } | |
5e760230 | 12429 | |
37c73b5f BG |
12430 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
12431 | if (!hdr) | |
12432 | goto nla_put_failure; | |
5e760230 | 12433 | |
37c73b5f BG |
12434 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12435 | (freq && | |
12436 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
12437 | (sig_dbm && | |
12438 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
12439 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
12440 | goto nla_put_failure; | |
5e760230 | 12441 | |
37c73b5f | 12442 | genlmsg_end(msg, hdr); |
5e760230 | 12443 | |
37c73b5f BG |
12444 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
12445 | } | |
12446 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
12447 | return; |
12448 | ||
12449 | nla_put_failure: | |
37c73b5f BG |
12450 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
12451 | if (hdr) | |
12452 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
12453 | nlmsg_free(msg); |
12454 | } | |
12455 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
12456 | ||
cd8f7cb4 | 12457 | #ifdef CONFIG_PM |
8cd4d456 LC |
12458 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
12459 | struct cfg80211_wowlan_wakeup *wakeup) | |
12460 | { | |
12461 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | |
12462 | struct nlattr *nl_results, *nl_match, *nl_freqs; | |
12463 | int i, j; | |
12464 | ||
12465 | nl_results = nla_nest_start( | |
12466 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | |
12467 | if (!nl_results) | |
12468 | return -EMSGSIZE; | |
12469 | ||
12470 | for (i = 0; i < nd->n_matches; i++) { | |
12471 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | |
12472 | ||
12473 | nl_match = nla_nest_start(msg, i); | |
12474 | if (!nl_match) | |
12475 | break; | |
12476 | ||
12477 | /* The SSID attribute is optional in nl80211, but for | |
12478 | * simplicity reasons it's always present in the | |
12479 | * cfg80211 structure. If a driver can't pass the | |
12480 | * SSID, that needs to be changed. A zero length SSID | |
12481 | * is still a valid SSID (wildcard), so it cannot be | |
12482 | * used for this purpose. | |
12483 | */ | |
12484 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | |
12485 | match->ssid.ssid)) { | |
12486 | nla_nest_cancel(msg, nl_match); | |
12487 | goto out; | |
12488 | } | |
12489 | ||
12490 | if (match->n_channels) { | |
12491 | nl_freqs = nla_nest_start( | |
12492 | msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
12493 | if (!nl_freqs) { | |
12494 | nla_nest_cancel(msg, nl_match); | |
12495 | goto out; | |
12496 | } | |
12497 | ||
12498 | for (j = 0; j < match->n_channels; j++) { | |
12499 | if (nla_put_u32(msg, | |
12500 | NL80211_ATTR_WIPHY_FREQ, | |
12501 | match->channels[j])) { | |
12502 | nla_nest_cancel(msg, nl_freqs); | |
12503 | nla_nest_cancel(msg, nl_match); | |
12504 | goto out; | |
12505 | } | |
12506 | } | |
12507 | ||
12508 | nla_nest_end(msg, nl_freqs); | |
12509 | } | |
12510 | ||
12511 | nla_nest_end(msg, nl_match); | |
12512 | } | |
12513 | ||
12514 | out: | |
12515 | nla_nest_end(msg, nl_results); | |
12516 | return 0; | |
12517 | } | |
12518 | ||
cd8f7cb4 JB |
12519 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
12520 | struct cfg80211_wowlan_wakeup *wakeup, | |
12521 | gfp_t gfp) | |
12522 | { | |
f26cbf40 | 12523 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
12524 | struct sk_buff *msg; |
12525 | void *hdr; | |
9c90a9f6 | 12526 | int size = 200; |
cd8f7cb4 JB |
12527 | |
12528 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
12529 | ||
12530 | if (wakeup) | |
12531 | size += wakeup->packet_present_len; | |
12532 | ||
12533 | msg = nlmsg_new(size, gfp); | |
12534 | if (!msg) | |
12535 | return; | |
12536 | ||
12537 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
12538 | if (!hdr) | |
12539 | goto free_msg; | |
12540 | ||
12541 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12542 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12543 | goto free_msg; | |
12544 | ||
12545 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
12546 | wdev->netdev->ifindex)) | |
12547 | goto free_msg; | |
12548 | ||
12549 | if (wakeup) { | |
12550 | struct nlattr *reasons; | |
12551 | ||
12552 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
12553 | if (!reasons) |
12554 | goto free_msg; | |
cd8f7cb4 JB |
12555 | |
12556 | if (wakeup->disconnect && | |
12557 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
12558 | goto free_msg; | |
12559 | if (wakeup->magic_pkt && | |
12560 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
12561 | goto free_msg; | |
12562 | if (wakeup->gtk_rekey_failure && | |
12563 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
12564 | goto free_msg; | |
12565 | if (wakeup->eap_identity_req && | |
12566 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
12567 | goto free_msg; | |
12568 | if (wakeup->four_way_handshake && | |
12569 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
12570 | goto free_msg; | |
12571 | if (wakeup->rfkill_release && | |
12572 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
12573 | goto free_msg; | |
12574 | ||
12575 | if (wakeup->pattern_idx >= 0 && | |
12576 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
12577 | wakeup->pattern_idx)) | |
12578 | goto free_msg; | |
12579 | ||
ae917c9f JB |
12580 | if (wakeup->tcp_match && |
12581 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
12582 | goto free_msg; | |
2a0e047e | 12583 | |
ae917c9f JB |
12584 | if (wakeup->tcp_connlost && |
12585 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
12586 | goto free_msg; | |
2a0e047e | 12587 | |
ae917c9f JB |
12588 | if (wakeup->tcp_nomoretokens && |
12589 | nla_put_flag(msg, | |
12590 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
12591 | goto free_msg; | |
2a0e047e | 12592 | |
cd8f7cb4 JB |
12593 | if (wakeup->packet) { |
12594 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
12595 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
12596 | ||
12597 | if (!wakeup->packet_80211) { | |
12598 | pkt_attr = | |
12599 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
12600 | len_attr = | |
12601 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
12602 | } | |
12603 | ||
12604 | if (wakeup->packet_len && | |
12605 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
12606 | goto free_msg; | |
12607 | ||
12608 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
12609 | wakeup->packet)) | |
12610 | goto free_msg; | |
12611 | } | |
12612 | ||
8cd4d456 LC |
12613 | if (wakeup->net_detect && |
12614 | cfg80211_net_detect_results(msg, wakeup)) | |
12615 | goto free_msg; | |
12616 | ||
cd8f7cb4 JB |
12617 | nla_nest_end(msg, reasons); |
12618 | } | |
12619 | ||
9c90a9f6 | 12620 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 12621 | |
68eb5503 | 12622 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12623 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
12624 | return; |
12625 | ||
12626 | free_msg: | |
12627 | nlmsg_free(msg); | |
12628 | } | |
12629 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
12630 | #endif | |
12631 | ||
3475b094 JM |
12632 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
12633 | enum nl80211_tdls_operation oper, | |
12634 | u16 reason_code, gfp_t gfp) | |
12635 | { | |
12636 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12637 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
12638 | struct sk_buff *msg; |
12639 | void *hdr; | |
3475b094 JM |
12640 | |
12641 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
12642 | reason_code); | |
12643 | ||
12644 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12645 | if (!msg) | |
12646 | return; | |
12647 | ||
12648 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
12649 | if (!hdr) { | |
12650 | nlmsg_free(msg); | |
12651 | return; | |
12652 | } | |
12653 | ||
12654 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12655 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12656 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
12657 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
12658 | (reason_code > 0 && | |
12659 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
12660 | goto nla_put_failure; | |
12661 | ||
9c90a9f6 | 12662 | genlmsg_end(msg, hdr); |
3475b094 | 12663 | |
68eb5503 | 12664 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12665 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
12666 | return; |
12667 | ||
12668 | nla_put_failure: | |
12669 | genlmsg_cancel(msg, hdr); | |
12670 | nlmsg_free(msg); | |
12671 | } | |
12672 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
12673 | ||
026331c4 JM |
12674 | static int nl80211_netlink_notify(struct notifier_block * nb, |
12675 | unsigned long state, | |
12676 | void *_notify) | |
12677 | { | |
12678 | struct netlink_notify *notify = _notify; | |
12679 | struct cfg80211_registered_device *rdev; | |
12680 | struct wireless_dev *wdev; | |
37c73b5f | 12681 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
12682 | |
12683 | if (state != NETLINK_URELEASE) | |
12684 | return NOTIFY_DONE; | |
12685 | ||
12686 | rcu_read_lock(); | |
12687 | ||
5e760230 | 12688 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
78f22b6a | 12689 | bool schedule_destroy_work = false; |
93a1e86c JR |
12690 | bool schedule_scan_stop = false; |
12691 | struct cfg80211_sched_scan_request *sched_scan_req = | |
12692 | rcu_dereference(rdev->sched_scan_req); | |
12693 | ||
12694 | if (sched_scan_req && notify->portid && | |
12695 | sched_scan_req->owner_nlportid == notify->portid) | |
12696 | schedule_scan_stop = true; | |
78f22b6a JB |
12697 | |
12698 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { | |
15e47304 | 12699 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 12700 | |
78f22b6a JB |
12701 | if (wdev->owner_nlportid == notify->portid) |
12702 | schedule_destroy_work = true; | |
12703 | } | |
12704 | ||
37c73b5f BG |
12705 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12706 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
12707 | list) { | |
12708 | if (reg->nlportid == notify->portid) { | |
12709 | list_del(®->list); | |
12710 | kfree(reg); | |
12711 | break; | |
12712 | } | |
12713 | } | |
12714 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
78f22b6a JB |
12715 | |
12716 | if (schedule_destroy_work) { | |
12717 | struct cfg80211_iface_destroy *destroy; | |
12718 | ||
12719 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | |
12720 | if (destroy) { | |
12721 | destroy->nlportid = notify->portid; | |
12722 | spin_lock(&rdev->destroy_list_lock); | |
12723 | list_add(&destroy->list, &rdev->destroy_list); | |
12724 | spin_unlock(&rdev->destroy_list_lock); | |
12725 | schedule_work(&rdev->destroy_work); | |
12726 | } | |
93a1e86c JR |
12727 | } else if (schedule_scan_stop) { |
12728 | sched_scan_req->owner_nlportid = 0; | |
12729 | ||
12730 | if (rdev->ops->sched_scan_stop && | |
12731 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
12732 | schedule_work(&rdev->sched_scan_stop_wk); | |
78f22b6a | 12733 | } |
5e760230 | 12734 | } |
026331c4 JM |
12735 | |
12736 | rcu_read_unlock(); | |
12737 | ||
6784c7db | 12738 | return NOTIFY_OK; |
026331c4 JM |
12739 | } |
12740 | ||
12741 | static struct notifier_block nl80211_netlink_notifier = { | |
12742 | .notifier_call = nl80211_netlink_notify, | |
12743 | }; | |
12744 | ||
355199e0 JM |
12745 | void cfg80211_ft_event(struct net_device *netdev, |
12746 | struct cfg80211_ft_event_params *ft_event) | |
12747 | { | |
12748 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 12749 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
12750 | struct sk_buff *msg; |
12751 | void *hdr; | |
355199e0 JM |
12752 | |
12753 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
12754 | ||
12755 | if (!ft_event->target_ap) | |
12756 | return; | |
12757 | ||
12758 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12759 | if (!msg) | |
12760 | return; | |
12761 | ||
12762 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
12763 | if (!hdr) |
12764 | goto out; | |
355199e0 | 12765 | |
ae917c9f JB |
12766 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12767 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12768 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
12769 | goto out; | |
355199e0 | 12770 | |
ae917c9f JB |
12771 | if (ft_event->ies && |
12772 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
12773 | goto out; | |
12774 | if (ft_event->ric_ies && | |
12775 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
12776 | ft_event->ric_ies)) | |
12777 | goto out; | |
355199e0 | 12778 | |
9c90a9f6 | 12779 | genlmsg_end(msg, hdr); |
355199e0 | 12780 | |
68eb5503 | 12781 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12782 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
12783 | return; |
12784 | out: | |
12785 | nlmsg_free(msg); | |
355199e0 JM |
12786 | } |
12787 | EXPORT_SYMBOL(cfg80211_ft_event); | |
12788 | ||
5de17984 AS |
12789 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
12790 | { | |
12791 | struct cfg80211_registered_device *rdev; | |
12792 | struct sk_buff *msg; | |
12793 | void *hdr; | |
12794 | u32 nlportid; | |
12795 | ||
f26cbf40 | 12796 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
12797 | if (!rdev->crit_proto_nlportid) |
12798 | return; | |
12799 | ||
12800 | nlportid = rdev->crit_proto_nlportid; | |
12801 | rdev->crit_proto_nlportid = 0; | |
12802 | ||
12803 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12804 | if (!msg) | |
12805 | return; | |
12806 | ||
12807 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
12808 | if (!hdr) | |
12809 | goto nla_put_failure; | |
12810 | ||
12811 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12812 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12813 | goto nla_put_failure; | |
12814 | ||
12815 | genlmsg_end(msg, hdr); | |
12816 | ||
12817 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
12818 | return; | |
12819 | ||
12820 | nla_put_failure: | |
12821 | if (hdr) | |
12822 | genlmsg_cancel(msg, hdr); | |
12823 | nlmsg_free(msg); | |
12824 | ||
12825 | } | |
12826 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
12827 | ||
348baf0e JB |
12828 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
12829 | { | |
12830 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12831 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
12832 | struct sk_buff *msg; |
12833 | void *hdr; | |
12834 | ||
12835 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12836 | if (!msg) | |
12837 | return; | |
12838 | ||
12839 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
12840 | if (!hdr) | |
12841 | goto out; | |
12842 | ||
12843 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12844 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
12845 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12846 | goto out; | |
12847 | ||
12848 | genlmsg_end(msg, hdr); | |
12849 | ||
12850 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
12851 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
12852 | return; | |
12853 | out: | |
12854 | nlmsg_free(msg); | |
12855 | } | |
12856 | ||
55682965 JB |
12857 | /* initialisation/exit functions */ |
12858 | ||
12859 | int nl80211_init(void) | |
12860 | { | |
0d63cbb5 | 12861 | int err; |
55682965 | 12862 | |
2a94fe48 JB |
12863 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
12864 | nl80211_mcgrps); | |
55682965 JB |
12865 | if (err) |
12866 | return err; | |
12867 | ||
026331c4 JM |
12868 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
12869 | if (err) | |
12870 | goto err_out; | |
12871 | ||
55682965 JB |
12872 | return 0; |
12873 | err_out: | |
12874 | genl_unregister_family(&nl80211_fam); | |
12875 | return err; | |
12876 | } | |
12877 | ||
12878 | void nl80211_exit(void) | |
12879 | { | |
026331c4 | 12880 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
12881 | genl_unregister_family(&nl80211_fam); |
12882 | } |