]>
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[] = { | |
62 | [NL80211_MCGRP_CONFIG] = { .name = "config", }, | |
63 | [NL80211_MCGRP_SCAN] = { .name = "scan", }, | |
64 | [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", }, | |
65 | [NL80211_MCGRP_MLME] = { .name = "mlme", }, | |
567ffc35 | 66 | [NL80211_MCGRP_VENDOR] = { .name = "vendor", }, |
2a94fe48 JB |
67 | #ifdef CONFIG_NL80211_TESTMODE |
68 | [NL80211_MCGRP_TESTMODE] = { .name = "testmode", } | |
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 | |
1b8ec87a | 1091 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1092 | return -ENOBUFS; |
1093 | ||
8cd4d456 LC |
1094 | /* TODO: send wowlan net detect */ |
1095 | ||
3713b4e3 | 1096 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1097 | |
3713b4e3 JB |
1098 | return 0; |
1099 | } | |
1100 | #endif | |
9360ffd1 | 1101 | |
be29b99a | 1102 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1103 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1104 | { |
1105 | struct nl80211_coalesce_rule_support rule; | |
1106 | ||
1b8ec87a | 1107 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1108 | return 0; |
1109 | ||
1b8ec87a ZG |
1110 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1111 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1112 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1113 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1114 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1115 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1116 | |
1117 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1118 | return -ENOBUFS; | |
1119 | ||
1120 | return 0; | |
1121 | } | |
1122 | ||
3713b4e3 JB |
1123 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1124 | struct ieee80211_supported_band *sband) | |
1125 | { | |
1126 | struct nlattr *nl_rates, *nl_rate; | |
1127 | struct ieee80211_rate *rate; | |
1128 | int i; | |
87bbbe22 | 1129 | |
3713b4e3 JB |
1130 | /* add HT info */ |
1131 | if (sband->ht_cap.ht_supported && | |
1132 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1133 | sizeof(sband->ht_cap.mcs), | |
1134 | &sband->ht_cap.mcs) || | |
1135 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1136 | sband->ht_cap.cap) || | |
1137 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1138 | sband->ht_cap.ampdu_factor) || | |
1139 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1140 | sband->ht_cap.ampdu_density))) | |
1141 | return -ENOBUFS; | |
afe0cbf8 | 1142 | |
3713b4e3 JB |
1143 | /* add VHT info */ |
1144 | if (sband->vht_cap.vht_supported && | |
1145 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1146 | sizeof(sband->vht_cap.vht_mcs), | |
1147 | &sband->vht_cap.vht_mcs) || | |
1148 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1149 | sband->vht_cap.cap))) | |
1150 | return -ENOBUFS; | |
f59ac048 | 1151 | |
3713b4e3 JB |
1152 | /* add bitrates */ |
1153 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1154 | if (!nl_rates) | |
1155 | return -ENOBUFS; | |
ee688b00 | 1156 | |
3713b4e3 JB |
1157 | for (i = 0; i < sband->n_bitrates; i++) { |
1158 | nl_rate = nla_nest_start(msg, i); | |
1159 | if (!nl_rate) | |
1160 | return -ENOBUFS; | |
ee688b00 | 1161 | |
3713b4e3 JB |
1162 | rate = &sband->bitrates[i]; |
1163 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1164 | rate->bitrate)) | |
1165 | return -ENOBUFS; | |
1166 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1167 | nla_put_flag(msg, | |
1168 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1169 | return -ENOBUFS; | |
ee688b00 | 1170 | |
3713b4e3 JB |
1171 | nla_nest_end(msg, nl_rate); |
1172 | } | |
d51626df | 1173 | |
3713b4e3 | 1174 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1175 | |
3713b4e3 JB |
1176 | return 0; |
1177 | } | |
ee688b00 | 1178 | |
3713b4e3 JB |
1179 | static int |
1180 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1181 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1182 | { | |
1183 | u16 stypes; | |
1184 | struct nlattr *nl_ftypes, *nl_ifs; | |
1185 | enum nl80211_iftype ift; | |
1186 | int i; | |
ee688b00 | 1187 | |
3713b4e3 JB |
1188 | if (!mgmt_stypes) |
1189 | return 0; | |
5dab3b8a | 1190 | |
3713b4e3 JB |
1191 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1192 | if (!nl_ifs) | |
1193 | return -ENOBUFS; | |
e2f367f2 | 1194 | |
3713b4e3 JB |
1195 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1196 | nl_ftypes = nla_nest_start(msg, ift); | |
1197 | if (!nl_ftypes) | |
1198 | return -ENOBUFS; | |
1199 | i = 0; | |
1200 | stypes = mgmt_stypes[ift].tx; | |
1201 | while (stypes) { | |
1202 | if ((stypes & 1) && | |
1203 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1204 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1205 | return -ENOBUFS; | |
1206 | stypes >>= 1; | |
1207 | i++; | |
ee688b00 | 1208 | } |
3713b4e3 JB |
1209 | nla_nest_end(msg, nl_ftypes); |
1210 | } | |
ee688b00 | 1211 | |
3713b4e3 | 1212 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1213 | |
3713b4e3 JB |
1214 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1215 | if (!nl_ifs) | |
1216 | return -ENOBUFS; | |
ee688b00 | 1217 | |
3713b4e3 JB |
1218 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1219 | nl_ftypes = nla_nest_start(msg, ift); | |
1220 | if (!nl_ftypes) | |
1221 | return -ENOBUFS; | |
1222 | i = 0; | |
1223 | stypes = mgmt_stypes[ift].rx; | |
1224 | while (stypes) { | |
1225 | if ((stypes & 1) && | |
1226 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1227 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1228 | return -ENOBUFS; | |
1229 | stypes >>= 1; | |
1230 | i++; | |
1231 | } | |
1232 | nla_nest_end(msg, nl_ftypes); | |
1233 | } | |
1234 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1235 | |
3713b4e3 JB |
1236 | return 0; |
1237 | } | |
ee688b00 | 1238 | |
86e8cf98 JB |
1239 | struct nl80211_dump_wiphy_state { |
1240 | s64 filter_wiphy; | |
1241 | long start; | |
1242 | long split_start, band_start, chan_start; | |
1243 | bool split; | |
1244 | }; | |
1245 | ||
1b8ec87a | 1246 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 1247 | enum nl80211_commands cmd, |
3713b4e3 | 1248 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1249 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1250 | { |
1251 | void *hdr; | |
1252 | struct nlattr *nl_bands, *nl_band; | |
1253 | struct nlattr *nl_freqs, *nl_freq; | |
1254 | struct nlattr *nl_cmds; | |
1255 | enum ieee80211_band band; | |
1256 | struct ieee80211_channel *chan; | |
1257 | int i; | |
1258 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1259 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1260 | u32 features; |
ee688b00 | 1261 | |
3bb20556 | 1262 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
1263 | if (!hdr) |
1264 | return -ENOBUFS; | |
ee688b00 | 1265 | |
86e8cf98 JB |
1266 | if (WARN_ON(!state)) |
1267 | return -EINVAL; | |
ee688b00 | 1268 | |
1b8ec87a | 1269 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1270 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1271 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1272 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1273 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1274 | goto nla_put_failure; |
1275 | ||
3bb20556 JB |
1276 | if (cmd != NL80211_CMD_NEW_WIPHY) |
1277 | goto finish; | |
1278 | ||
86e8cf98 | 1279 | switch (state->split_start) { |
3713b4e3 JB |
1280 | case 0: |
1281 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1282 | rdev->wiphy.retry_short) || |
3713b4e3 | 1283 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1284 | rdev->wiphy.retry_long) || |
3713b4e3 | 1285 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1286 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1287 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1288 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1289 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1290 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1291 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1292 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1293 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1294 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1295 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1296 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1297 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1298 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1299 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
1b8ec87a | 1300 | rdev->wiphy.max_match_sets)) |
9360ffd1 | 1301 | goto nla_put_failure; |
3713b4e3 | 1302 | |
1b8ec87a | 1303 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1304 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1305 | goto nla_put_failure; |
1b8ec87a | 1306 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1307 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1308 | goto nla_put_failure; | |
1b8ec87a | 1309 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1310 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1311 | goto nla_put_failure; | |
1b8ec87a | 1312 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1313 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1314 | goto nla_put_failure; | |
1b8ec87a | 1315 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1316 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1317 | goto nla_put_failure; | |
1b8ec87a | 1318 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1319 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1320 | goto nla_put_failure; |
86e8cf98 JB |
1321 | state->split_start++; |
1322 | if (state->split) | |
3713b4e3 JB |
1323 | break; |
1324 | case 1: | |
1325 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1326 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1327 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1328 | goto nla_put_failure; |
4745fc09 | 1329 | |
3713b4e3 | 1330 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1331 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1332 | goto nla_put_failure; |
b23aa676 | 1333 | |
1b8ec87a | 1334 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1335 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1336 | goto nla_put_failure; |
b23aa676 | 1337 | |
3713b4e3 | 1338 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1339 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1340 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1341 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1342 | goto nla_put_failure; |
b23aa676 | 1343 | |
1b8ec87a | 1344 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1345 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1346 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1347 | goto nla_put_failure; |
8fdc621d | 1348 | |
1b8ec87a ZG |
1349 | if ((rdev->wiphy.available_antennas_tx || |
1350 | rdev->wiphy.available_antennas_rx) && | |
1351 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1352 | u32 tx_ant = 0, rx_ant = 0; |
1353 | int res; | |
1b8ec87a | 1354 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1355 | if (!res) { |
1356 | if (nla_put_u32(msg, | |
1357 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1358 | tx_ant) || | |
1359 | nla_put_u32(msg, | |
1360 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1361 | rx_ant)) | |
1362 | goto nla_put_failure; | |
1363 | } | |
1364 | } | |
a293911d | 1365 | |
86e8cf98 JB |
1366 | state->split_start++; |
1367 | if (state->split) | |
3713b4e3 JB |
1368 | break; |
1369 | case 2: | |
1370 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1371 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1372 | goto nla_put_failure; |
86e8cf98 JB |
1373 | state->split_start++; |
1374 | if (state->split) | |
3713b4e3 JB |
1375 | break; |
1376 | case 3: | |
1377 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1378 | if (!nl_bands) | |
1379 | goto nla_put_failure; | |
f7ca38df | 1380 | |
86e8cf98 JB |
1381 | for (band = state->band_start; |
1382 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1383 | struct ieee80211_supported_band *sband; |
2e161f78 | 1384 | |
1b8ec87a | 1385 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1386 | |
3713b4e3 JB |
1387 | if (!sband) |
1388 | continue; | |
1389 | ||
1390 | nl_band = nla_nest_start(msg, band); | |
1391 | if (!nl_band) | |
2e161f78 | 1392 | goto nla_put_failure; |
3713b4e3 | 1393 | |
86e8cf98 | 1394 | switch (state->chan_start) { |
3713b4e3 JB |
1395 | case 0: |
1396 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1397 | goto nla_put_failure; |
86e8cf98 JB |
1398 | state->chan_start++; |
1399 | if (state->split) | |
3713b4e3 JB |
1400 | break; |
1401 | default: | |
1402 | /* add frequencies */ | |
1403 | nl_freqs = nla_nest_start( | |
1404 | msg, NL80211_BAND_ATTR_FREQS); | |
1405 | if (!nl_freqs) | |
1406 | goto nla_put_failure; | |
1407 | ||
86e8cf98 | 1408 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1409 | i < sband->n_channels; |
1410 | i++) { | |
1411 | nl_freq = nla_nest_start(msg, i); | |
1412 | if (!nl_freq) | |
1413 | goto nla_put_failure; | |
1414 | ||
1415 | chan = &sband->channels[i]; | |
1416 | ||
86e8cf98 JB |
1417 | if (nl80211_msg_put_channel( |
1418 | msg, chan, | |
1419 | state->split)) | |
3713b4e3 JB |
1420 | goto nla_put_failure; |
1421 | ||
1422 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1423 | if (state->split) |
3713b4e3 JB |
1424 | break; |
1425 | } | |
1426 | if (i < sband->n_channels) | |
86e8cf98 | 1427 | state->chan_start = i + 2; |
3713b4e3 | 1428 | else |
86e8cf98 | 1429 | state->chan_start = 0; |
3713b4e3 JB |
1430 | nla_nest_end(msg, nl_freqs); |
1431 | } | |
1432 | ||
1433 | nla_nest_end(msg, nl_band); | |
1434 | ||
86e8cf98 | 1435 | if (state->split) { |
3713b4e3 | 1436 | /* start again here */ |
86e8cf98 | 1437 | if (state->chan_start) |
3713b4e3 JB |
1438 | band--; |
1439 | break; | |
2e161f78 | 1440 | } |
2e161f78 | 1441 | } |
3713b4e3 | 1442 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1443 | |
3713b4e3 | 1444 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1445 | state->band_start = band + 1; |
3713b4e3 | 1446 | else |
86e8cf98 | 1447 | state->band_start = 0; |
74b70a4e | 1448 | |
3713b4e3 | 1449 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1450 | if (state->band_start == 0 && state->chan_start == 0) |
1451 | state->split_start++; | |
1452 | if (state->split) | |
3713b4e3 JB |
1453 | break; |
1454 | case 4: | |
1455 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1456 | if (!nl_cmds) | |
2e161f78 JB |
1457 | goto nla_put_failure; |
1458 | ||
3713b4e3 JB |
1459 | i = 0; |
1460 | #define CMD(op, n) \ | |
1461 | do { \ | |
1b8ec87a | 1462 | if (rdev->ops->op) { \ |
3713b4e3 JB |
1463 | i++; \ |
1464 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1465 | goto nla_put_failure; \ | |
1466 | } \ | |
1467 | } while (0) | |
1468 | ||
1469 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1470 | CMD(change_virtual_intf, SET_INTERFACE); | |
1471 | CMD(add_key, NEW_KEY); | |
1472 | CMD(start_ap, START_AP); | |
1473 | CMD(add_station, NEW_STATION); | |
1474 | CMD(add_mpath, NEW_MPATH); | |
1475 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1476 | CMD(change_bss, SET_BSS); | |
1477 | CMD(auth, AUTHENTICATE); | |
1478 | CMD(assoc, ASSOCIATE); | |
1479 | CMD(deauth, DEAUTHENTICATE); | |
1480 | CMD(disassoc, DISASSOCIATE); | |
1481 | CMD(join_ibss, JOIN_IBSS); | |
1482 | CMD(join_mesh, JOIN_MESH); | |
1483 | CMD(set_pmksa, SET_PMKSA); | |
1484 | CMD(del_pmksa, DEL_PMKSA); | |
1485 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1b8ec87a | 1486 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
3713b4e3 JB |
1487 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
1488 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1489 | CMD(mgmt_tx, FRAME); | |
1490 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1b8ec87a | 1491 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
3713b4e3 JB |
1492 | i++; |
1493 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1494 | goto nla_put_failure; |
2e161f78 | 1495 | } |
1b8ec87a ZG |
1496 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
1497 | rdev->ops->join_mesh) { | |
3713b4e3 JB |
1498 | i++; |
1499 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1500 | goto nla_put_failure; | |
1501 | } | |
1502 | CMD(set_wds_peer, SET_WDS_PEER); | |
1b8ec87a | 1503 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
3713b4e3 JB |
1504 | CMD(tdls_mgmt, TDLS_MGMT); |
1505 | CMD(tdls_oper, TDLS_OPER); | |
1506 | } | |
1b8ec87a | 1507 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
3713b4e3 JB |
1508 | CMD(sched_scan_start, START_SCHED_SCAN); |
1509 | CMD(probe_client, PROBE_CLIENT); | |
1510 | CMD(set_noack_map, SET_NOACK_MAP); | |
1b8ec87a | 1511 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
3713b4e3 JB |
1512 | i++; |
1513 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1514 | goto nla_put_failure; | |
1515 | } | |
1516 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1517 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
02df00eb JB |
1518 | #ifdef CONFIG_NL80211_TESTMODE |
1519 | CMD(testmode_cmd, TESTMODE); | |
1520 | #endif | |
86e8cf98 | 1521 | if (state->split) { |
5de17984 AS |
1522 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1523 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 1524 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 1525 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 1526 | CMD(set_qos_map, SET_QOS_MAP); |
723e73ac JB |
1527 | if (rdev->wiphy.features & |
1528 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | |
960d01ac | 1529 | CMD(add_tx_ts, ADD_TX_TS); |
5de17984 | 1530 | } |
02df00eb | 1531 | /* add into the if now */ |
3713b4e3 | 1532 | #undef CMD |
ff1b6e69 | 1533 | |
1b8ec87a | 1534 | if (rdev->ops->connect || rdev->ops->auth) { |
3713b4e3 JB |
1535 | i++; |
1536 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1537 | goto nla_put_failure; |
ff1b6e69 JB |
1538 | } |
1539 | ||
1b8ec87a | 1540 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
3713b4e3 JB |
1541 | i++; |
1542 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1543 | goto nla_put_failure; | |
1544 | } | |
1545 | ||
1546 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1547 | state->split_start++; |
1548 | if (state->split) | |
3713b4e3 JB |
1549 | break; |
1550 | case 5: | |
1b8ec87a ZG |
1551 | if (rdev->ops->remain_on_channel && |
1552 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
1553 | nla_put_u32(msg, |
1554 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 1555 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
1556 | goto nla_put_failure; |
1557 | ||
1b8ec87a | 1558 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
1559 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
1560 | goto nla_put_failure; | |
1561 | ||
1562 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1563 | goto nla_put_failure; | |
86e8cf98 JB |
1564 | state->split_start++; |
1565 | if (state->split) | |
3713b4e3 JB |
1566 | break; |
1567 | case 6: | |
1568 | #ifdef CONFIG_PM | |
1b8ec87a | 1569 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 1570 | goto nla_put_failure; |
86e8cf98 JB |
1571 | state->split_start++; |
1572 | if (state->split) | |
3713b4e3 JB |
1573 | break; |
1574 | #else | |
86e8cf98 | 1575 | state->split_start++; |
dfb89c56 | 1576 | #endif |
3713b4e3 JB |
1577 | case 7: |
1578 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 1579 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 1580 | goto nla_put_failure; |
ff1b6e69 | 1581 | |
1b8ec87a | 1582 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 1583 | state->split)) |
3713b4e3 | 1584 | goto nla_put_failure; |
7527a782 | 1585 | |
86e8cf98 JB |
1586 | state->split_start++; |
1587 | if (state->split) | |
3713b4e3 JB |
1588 | break; |
1589 | case 8: | |
1b8ec87a | 1590 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 1591 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 1592 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 1593 | goto nla_put_failure; |
7527a782 | 1594 | |
1b8ec87a | 1595 | features = rdev->wiphy.features; |
fe1abafd JB |
1596 | /* |
1597 | * We can only add the per-channel limit information if the | |
1598 | * dump is split, otherwise it makes it too big. Therefore | |
1599 | * only advertise it in that case. | |
1600 | */ | |
86e8cf98 | 1601 | if (state->split) |
fe1abafd JB |
1602 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1603 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1604 | goto nla_put_failure; |
562a7480 | 1605 | |
1b8ec87a | 1606 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 1607 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
1608 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
1609 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 1610 | goto nla_put_failure; |
1f074bd8 | 1611 | |
1b8ec87a ZG |
1612 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1613 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 1614 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 1615 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 1616 | goto nla_put_failure; |
7e7c8926 | 1617 | |
3713b4e3 JB |
1618 | /* |
1619 | * Any information below this point is only available to | |
1620 | * applications that can deal with it being split. This | |
1621 | * helps ensure that newly added capabilities don't break | |
1622 | * older tools by overrunning their buffers. | |
1623 | * | |
1624 | * We still increment split_start so that in the split | |
1625 | * case we'll continue with more data in the next round, | |
1626 | * but break unconditionally so unsplit data stops here. | |
1627 | */ | |
86e8cf98 | 1628 | state->split_start++; |
3713b4e3 JB |
1629 | break; |
1630 | case 9: | |
1b8ec87a | 1631 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 1632 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
1633 | rdev->wiphy.extended_capabilities_len, |
1634 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 1635 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
1636 | rdev->wiphy.extended_capabilities_len, |
1637 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 1638 | goto nla_put_failure; |
a50df0c4 | 1639 | |
1b8ec87a | 1640 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 1641 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
1642 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
1643 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
1644 | goto nla_put_failure; |
1645 | ||
be29b99a AK |
1646 | state->split_start++; |
1647 | break; | |
1648 | case 10: | |
1b8ec87a | 1649 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
1650 | goto nla_put_failure; |
1651 | ||
1b8ec87a | 1652 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
1653 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
1654 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1655 | goto nla_put_failure; | |
b43504cf | 1656 | |
1b8ec87a | 1657 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 1658 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 1659 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
1660 | goto nla_put_failure; |
1661 | ||
ad7e718c JB |
1662 | state->split_start++; |
1663 | break; | |
1664 | case 11: | |
1b8ec87a | 1665 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
1666 | const struct nl80211_vendor_cmd_info *info; |
1667 | struct nlattr *nested; | |
1668 | ||
1669 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1670 | if (!nested) | |
1671 | goto nla_put_failure; | |
1672 | ||
1b8ec87a ZG |
1673 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
1674 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
1675 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1676 | goto nla_put_failure; | |
1677 | } | |
1678 | nla_nest_end(msg, nested); | |
1679 | } | |
1680 | ||
1b8ec87a | 1681 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
1682 | const struct nl80211_vendor_cmd_info *info; |
1683 | struct nlattr *nested; | |
ad7e718c | 1684 | |
567ffc35 JB |
1685 | nested = nla_nest_start(msg, |
1686 | NL80211_ATTR_VENDOR_EVENTS); | |
1687 | if (!nested) | |
ad7e718c | 1688 | goto nla_put_failure; |
567ffc35 | 1689 | |
1b8ec87a ZG |
1690 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
1691 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
1692 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1693 | goto nla_put_failure; | |
1694 | } | |
1695 | nla_nest_end(msg, nested); | |
1696 | } | |
9a774c78 AO |
1697 | state->split_start++; |
1698 | break; | |
1699 | case 12: | |
1700 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
1701 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
1702 | rdev->wiphy.max_num_csa_counters)) | |
1703 | goto nla_put_failure; | |
01e0daa4 | 1704 | |
1bdd716c AN |
1705 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
1706 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
1707 | goto nla_put_failure; | |
1708 | ||
d75bb06b GKS |
1709 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
1710 | sizeof(rdev->wiphy.ext_features), | |
1711 | rdev->wiphy.ext_features)) | |
1712 | goto nla_put_failure; | |
1713 | ||
3713b4e3 | 1714 | /* done */ |
86e8cf98 | 1715 | state->split_start = 0; |
3713b4e3 JB |
1716 | break; |
1717 | } | |
3bb20556 | 1718 | finish: |
55682965 JB |
1719 | return genlmsg_end(msg, hdr); |
1720 | ||
1721 | nla_put_failure: | |
bc3ed28c TG |
1722 | genlmsg_cancel(msg, hdr); |
1723 | return -EMSGSIZE; | |
55682965 JB |
1724 | } |
1725 | ||
86e8cf98 JB |
1726 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1727 | struct netlink_callback *cb, | |
1728 | struct nl80211_dump_wiphy_state *state) | |
1729 | { | |
1730 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1731 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1732 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1733 | /* ignore parse errors for backward compatibility */ | |
1734 | if (ret) | |
1735 | return 0; | |
1736 | ||
1737 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1738 | if (tb[NL80211_ATTR_WIPHY]) | |
1739 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1740 | if (tb[NL80211_ATTR_WDEV]) | |
1741 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1742 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1743 | struct net_device *netdev; | |
1744 | struct cfg80211_registered_device *rdev; | |
1745 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1746 | ||
7f2b8562 | 1747 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1748 | if (!netdev) |
1749 | return -ENODEV; | |
1750 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1751 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1752 | netdev->ieee80211_ptr->wiphy); |
1753 | state->filter_wiphy = rdev->wiphy_idx; | |
1754 | } | |
86e8cf98 JB |
1755 | } |
1756 | ||
1757 | return 0; | |
1758 | } | |
1759 | ||
55682965 JB |
1760 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1761 | { | |
645e77de | 1762 | int idx = 0, ret; |
86e8cf98 | 1763 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1764 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1765 | |
5fe231e8 | 1766 | rtnl_lock(); |
86e8cf98 JB |
1767 | if (!state) { |
1768 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1769 | if (!state) { |
1770 | rtnl_unlock(); | |
86e8cf98 | 1771 | return -ENOMEM; |
3713b4e3 | 1772 | } |
86e8cf98 JB |
1773 | state->filter_wiphy = -1; |
1774 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1775 | if (ret) { | |
1776 | kfree(state); | |
1777 | rtnl_unlock(); | |
1778 | return ret; | |
3713b4e3 | 1779 | } |
86e8cf98 | 1780 | cb->args[0] = (long)state; |
3713b4e3 JB |
1781 | } |
1782 | ||
1b8ec87a ZG |
1783 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1784 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1785 | continue; |
86e8cf98 | 1786 | if (++idx <= state->start) |
55682965 | 1787 | continue; |
86e8cf98 | 1788 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1789 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1790 | continue; |
1791 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1792 | do { | |
3bb20556 JB |
1793 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
1794 | skb, | |
3713b4e3 JB |
1795 | NETLINK_CB(cb->skb).portid, |
1796 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1797 | NLM_F_MULTI, state); |
3713b4e3 JB |
1798 | if (ret < 0) { |
1799 | /* | |
1800 | * If sending the wiphy data didn't fit (ENOBUFS | |
1801 | * or EMSGSIZE returned), this SKB is still | |
1802 | * empty (so it's not too big because another | |
1803 | * wiphy dataset is already in the skb) and | |
1804 | * we've not tried to adjust the dump allocation | |
1805 | * yet ... then adjust the alloc size to be | |
1806 | * bigger, and return 1 but with the empty skb. | |
1807 | * This results in an empty message being RX'ed | |
1808 | * in userspace, but that is ignored. | |
1809 | * | |
1810 | * We can then retry with the larger buffer. | |
1811 | */ | |
1812 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1813 | !skb->len && !state->split && |
3713b4e3 JB |
1814 | cb->min_dump_alloc < 4096) { |
1815 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1816 | state->split_start = 0; |
d98cae64 | 1817 | rtnl_unlock(); |
3713b4e3 JB |
1818 | return 1; |
1819 | } | |
1820 | idx--; | |
1821 | break; | |
645e77de | 1822 | } |
86e8cf98 | 1823 | } while (state->split_start > 0); |
3713b4e3 | 1824 | break; |
55682965 | 1825 | } |
5fe231e8 | 1826 | rtnl_unlock(); |
55682965 | 1827 | |
86e8cf98 | 1828 | state->start = idx; |
55682965 JB |
1829 | |
1830 | return skb->len; | |
1831 | } | |
1832 | ||
86e8cf98 JB |
1833 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1834 | { | |
1835 | kfree((void *)cb->args[0]); | |
1836 | return 0; | |
1837 | } | |
1838 | ||
55682965 JB |
1839 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1840 | { | |
1841 | struct sk_buff *msg; | |
1b8ec87a | 1842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 1843 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1844 | |
645e77de | 1845 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1846 | if (!msg) |
4c476991 | 1847 | return -ENOMEM; |
55682965 | 1848 | |
3bb20556 JB |
1849 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
1850 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 1851 | &state) < 0) { |
4c476991 JB |
1852 | nlmsg_free(msg); |
1853 | return -ENOBUFS; | |
1854 | } | |
55682965 | 1855 | |
134e6375 | 1856 | return genlmsg_reply(msg, info); |
55682965 JB |
1857 | } |
1858 | ||
31888487 JM |
1859 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1860 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1861 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1862 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1863 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1864 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1865 | }; | |
1866 | ||
1867 | static int parse_txq_params(struct nlattr *tb[], | |
1868 | struct ieee80211_txq_params *txq_params) | |
1869 | { | |
a3304b0a | 1870 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1871 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1872 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1873 | return -EINVAL; | |
1874 | ||
a3304b0a | 1875 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1876 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1877 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1878 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1879 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1880 | ||
a3304b0a JB |
1881 | if (txq_params->ac >= NL80211_NUM_ACS) |
1882 | return -EINVAL; | |
1883 | ||
31888487 JM |
1884 | return 0; |
1885 | } | |
1886 | ||
f444de05 JB |
1887 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1888 | { | |
1889 | /* | |
cc1d2806 JB |
1890 | * You can only set the channel explicitly for WDS interfaces, |
1891 | * all others have their channel managed via their respective | |
1892 | * "establish a connection" command (connect, join, ...) | |
1893 | * | |
1894 | * For AP/GO and mesh mode, the channel can be set with the | |
1895 | * channel userspace API, but is only stored and passed to the | |
1896 | * low-level driver when the AP starts or the mesh is joined. | |
1897 | * This is for backward compatibility, userspace can also give | |
1898 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1899 | * |
1900 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1901 | * whatever else is going on, so they have their own special |
1902 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1903 | */ |
1904 | return !wdev || | |
1905 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1906 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1907 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1908 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1909 | } |
1910 | ||
683b6d3b JB |
1911 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1912 | struct genl_info *info, | |
1913 | struct cfg80211_chan_def *chandef) | |
1914 | { | |
dbeca2ea | 1915 | u32 control_freq; |
683b6d3b JB |
1916 | |
1917 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1918 | return -EINVAL; | |
1919 | ||
1920 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1921 | ||
1922 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1923 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1924 | chandef->center_freq1 = control_freq; | |
1925 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1926 | |
1927 | /* Primary channel not allowed */ | |
1928 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1929 | return -EINVAL; | |
1930 | ||
3d9d1d66 JB |
1931 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1932 | enum nl80211_channel_type chantype; | |
1933 | ||
1934 | chantype = nla_get_u32( | |
1935 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1936 | ||
1937 | switch (chantype) { | |
1938 | case NL80211_CHAN_NO_HT: | |
1939 | case NL80211_CHAN_HT20: | |
1940 | case NL80211_CHAN_HT40PLUS: | |
1941 | case NL80211_CHAN_HT40MINUS: | |
1942 | cfg80211_chandef_create(chandef, chandef->chan, | |
1943 | chantype); | |
1944 | break; | |
1945 | default: | |
1946 | return -EINVAL; | |
1947 | } | |
1948 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1949 | chandef->width = | |
1950 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1951 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1952 | chandef->center_freq1 = | |
1953 | nla_get_u32( | |
1954 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1955 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1956 | chandef->center_freq2 = | |
1957 | nla_get_u32( | |
1958 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1959 | } | |
1960 | ||
9f5e8f6e | 1961 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1962 | return -EINVAL; |
1963 | ||
9f5e8f6e JB |
1964 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1965 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1966 | return -EINVAL; |
1967 | ||
2f301ab2 SW |
1968 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1969 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1970 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1971 | return -EINVAL; | |
1972 | ||
683b6d3b JB |
1973 | return 0; |
1974 | } | |
1975 | ||
f444de05 | 1976 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 1977 | struct net_device *dev, |
f444de05 JB |
1978 | struct genl_info *info) |
1979 | { | |
683b6d3b | 1980 | struct cfg80211_chan_def chandef; |
f444de05 | 1981 | int result; |
e8c9bd5b | 1982 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 1983 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 1984 | |
e16821bc JM |
1985 | if (dev) |
1986 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
1987 | if (!nl80211_can_set_dev_channel(wdev)) |
1988 | return -EOPNOTSUPP; | |
e16821bc JM |
1989 | if (wdev) |
1990 | iftype = wdev->iftype; | |
f444de05 | 1991 | |
683b6d3b JB |
1992 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1993 | if (result) | |
1994 | return result; | |
f444de05 | 1995 | |
e8c9bd5b | 1996 | switch (iftype) { |
aa430da4 JB |
1997 | case NL80211_IFTYPE_AP: |
1998 | case NL80211_IFTYPE_P2P_GO: | |
174e0cd2 | 1999 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
aa430da4 JB |
2000 | result = -EINVAL; |
2001 | break; | |
2002 | } | |
e16821bc JM |
2003 | if (wdev->beacon_interval) { |
2004 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
2005 | !(rdev->wiphy.features & | |
2006 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
2007 | result = -EBUSY; | |
2008 | break; | |
2009 | } | |
2010 | ||
2011 | /* Only allow dynamic channel width changes */ | |
2012 | if (chandef.chan != wdev->preset_chandef.chan) { | |
2013 | result = -EBUSY; | |
2014 | break; | |
2015 | } | |
2016 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
2017 | if (result) | |
2018 | break; | |
2019 | } | |
683b6d3b | 2020 | wdev->preset_chandef = chandef; |
aa430da4 JB |
2021 | result = 0; |
2022 | break; | |
cc1d2806 | 2023 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 2024 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 2025 | break; |
e8c9bd5b | 2026 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 2027 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 2028 | break; |
aa430da4 | 2029 | default: |
e8c9bd5b | 2030 | result = -EINVAL; |
f444de05 | 2031 | } |
f444de05 JB |
2032 | |
2033 | return result; | |
2034 | } | |
2035 | ||
2036 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2037 | { | |
4c476991 JB |
2038 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2039 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2040 | |
e16821bc | 2041 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2042 | } |
2043 | ||
e8347eba BJ |
2044 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2045 | { | |
43b19952 JB |
2046 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2047 | struct net_device *dev = info->user_ptr[1]; | |
2048 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2049 | const u8 *bssid; |
e8347eba BJ |
2050 | |
2051 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2052 | return -EINVAL; | |
2053 | ||
43b19952 JB |
2054 | if (netif_running(dev)) |
2055 | return -EBUSY; | |
e8347eba | 2056 | |
43b19952 JB |
2057 | if (!rdev->ops->set_wds_peer) |
2058 | return -EOPNOTSUPP; | |
e8347eba | 2059 | |
43b19952 JB |
2060 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2061 | return -EOPNOTSUPP; | |
e8347eba BJ |
2062 | |
2063 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2064 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2065 | } |
2066 | ||
2067 | ||
55682965 JB |
2068 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2069 | { | |
2070 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2071 | struct net_device *netdev = NULL; |
2072 | struct wireless_dev *wdev; | |
a1e567c8 | 2073 | int result = 0, rem_txq_params = 0; |
31888487 | 2074 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2075 | u32 changed; |
2076 | u8 retry_short = 0, retry_long = 0; | |
2077 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2078 | u8 coverage_class = 0; |
55682965 | 2079 | |
5fe231e8 JB |
2080 | ASSERT_RTNL(); |
2081 | ||
f444de05 JB |
2082 | /* |
2083 | * Try to find the wiphy and netdev. Normally this | |
2084 | * function shouldn't need the netdev, but this is | |
2085 | * done for backward compatibility -- previously | |
2086 | * setting the channel was done per wiphy, but now | |
2087 | * it is per netdev. Previous userland like hostapd | |
2088 | * also passed a netdev to set_wiphy, so that it is | |
2089 | * possible to let that go to the right netdev! | |
2090 | */ | |
4bbf4d56 | 2091 | |
f444de05 JB |
2092 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2093 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2094 | ||
7f2b8562 | 2095 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2096 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2097 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2098 | else |
f444de05 | 2099 | netdev = NULL; |
4bbf4d56 JB |
2100 | } |
2101 | ||
f444de05 | 2102 | if (!netdev) { |
878d9ec7 JB |
2103 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2104 | info->attrs); | |
5fe231e8 | 2105 | if (IS_ERR(rdev)) |
4c476991 | 2106 | return PTR_ERR(rdev); |
f444de05 JB |
2107 | wdev = NULL; |
2108 | netdev = NULL; | |
2109 | result = 0; | |
71fe96bf | 2110 | } else |
f444de05 | 2111 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2112 | |
2113 | /* | |
2114 | * end workaround code, by now the rdev is available | |
2115 | * and locked, and wdev may or may not be NULL. | |
2116 | */ | |
4bbf4d56 JB |
2117 | |
2118 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2119 | result = cfg80211_dev_rename( |
2120 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2121 | |
4bbf4d56 | 2122 | if (result) |
7f2b8562 | 2123 | return result; |
31888487 JM |
2124 | |
2125 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2126 | struct ieee80211_txq_params txq_params; | |
2127 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2128 | ||
7f2b8562 YX |
2129 | if (!rdev->ops->set_txq_params) |
2130 | return -EOPNOTSUPP; | |
31888487 | 2131 | |
7f2b8562 YX |
2132 | if (!netdev) |
2133 | return -EINVAL; | |
f70f01c2 | 2134 | |
133a3ff2 | 2135 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2136 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2137 | return -EINVAL; | |
133a3ff2 | 2138 | |
7f2b8562 YX |
2139 | if (!netif_running(netdev)) |
2140 | return -ENETDOWN; | |
2b5f8b0b | 2141 | |
31888487 JM |
2142 | nla_for_each_nested(nl_txq_params, |
2143 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2144 | rem_txq_params) { | |
ae811e21 JB |
2145 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2146 | nla_data(nl_txq_params), | |
2147 | nla_len(nl_txq_params), | |
2148 | txq_params_policy); | |
2149 | if (result) | |
2150 | return result; | |
31888487 JM |
2151 | result = parse_txq_params(tb, &txq_params); |
2152 | if (result) | |
7f2b8562 | 2153 | return result; |
31888487 | 2154 | |
e35e4d28 HG |
2155 | result = rdev_set_txq_params(rdev, netdev, |
2156 | &txq_params); | |
31888487 | 2157 | if (result) |
7f2b8562 | 2158 | return result; |
31888487 JM |
2159 | } |
2160 | } | |
55682965 | 2161 | |
72bdcf34 | 2162 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2163 | result = __nl80211_set_channel( |
2164 | rdev, | |
2165 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2166 | info); | |
72bdcf34 | 2167 | if (result) |
7f2b8562 | 2168 | return result; |
72bdcf34 JM |
2169 | } |
2170 | ||
98d2ff8b | 2171 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2172 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2173 | enum nl80211_tx_power_setting type; |
2174 | int idx, mbm = 0; | |
2175 | ||
c8442118 JB |
2176 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2177 | txp_wdev = NULL; | |
2178 | ||
7f2b8562 YX |
2179 | if (!rdev->ops->set_tx_power) |
2180 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2181 | |
2182 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2183 | type = nla_get_u32(info->attrs[idx]); | |
2184 | ||
2185 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2186 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2187 | return -EINVAL; | |
98d2ff8b JO |
2188 | |
2189 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2190 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2191 | mbm = nla_get_u32(info->attrs[idx]); | |
2192 | } | |
2193 | ||
c8442118 | 2194 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2195 | if (result) |
7f2b8562 | 2196 | return result; |
98d2ff8b JO |
2197 | } |
2198 | ||
afe0cbf8 BR |
2199 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2200 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2201 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2202 | if ((!rdev->wiphy.available_antennas_tx && |
2203 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2204 | !rdev->ops->set_antenna) |
2205 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2206 | |
2207 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2208 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2209 | ||
a7ffac95 | 2210 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2211 | * available antenna masks, except for the "all" mask */ |
2212 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2213 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2214 | return -EINVAL; | |
a7ffac95 | 2215 | |
7f531e03 BR |
2216 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2217 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2218 | |
e35e4d28 | 2219 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2220 | if (result) |
7f2b8562 | 2221 | return result; |
afe0cbf8 BR |
2222 | } |
2223 | ||
b9a5f8ca JM |
2224 | changed = 0; |
2225 | ||
2226 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2227 | retry_short = nla_get_u8( | |
2228 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2229 | if (retry_short == 0) |
2230 | return -EINVAL; | |
2231 | ||
b9a5f8ca JM |
2232 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2233 | } | |
2234 | ||
2235 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2236 | retry_long = nla_get_u8( | |
2237 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2238 | if (retry_long == 0) |
2239 | return -EINVAL; | |
2240 | ||
b9a5f8ca JM |
2241 | changed |= WIPHY_PARAM_RETRY_LONG; |
2242 | } | |
2243 | ||
2244 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2245 | frag_threshold = nla_get_u32( | |
2246 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2247 | if (frag_threshold < 256) |
2248 | return -EINVAL; | |
2249 | ||
b9a5f8ca JM |
2250 | if (frag_threshold != (u32) -1) { |
2251 | /* | |
2252 | * Fragments (apart from the last one) are required to | |
2253 | * have even length. Make the fragmentation code | |
2254 | * simpler by stripping LSB should someone try to use | |
2255 | * odd threshold value. | |
2256 | */ | |
2257 | frag_threshold &= ~0x1; | |
2258 | } | |
2259 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2260 | } | |
2261 | ||
2262 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2263 | rts_threshold = nla_get_u32( | |
2264 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2265 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2266 | } | |
2267 | ||
81077e82 | 2268 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
3057dbfd LB |
2269 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
2270 | return -EINVAL; | |
2271 | ||
81077e82 LT |
2272 | coverage_class = nla_get_u8( |
2273 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2274 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2275 | } | |
2276 | ||
3057dbfd LB |
2277 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
2278 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | |
2279 | return -EOPNOTSUPP; | |
2280 | ||
2281 | changed |= WIPHY_PARAM_DYN_ACK; | |
81077e82 LT |
2282 | } |
2283 | ||
b9a5f8ca JM |
2284 | if (changed) { |
2285 | u8 old_retry_short, old_retry_long; | |
2286 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2287 | u8 old_coverage_class; |
b9a5f8ca | 2288 | |
7f2b8562 YX |
2289 | if (!rdev->ops->set_wiphy_params) |
2290 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2291 | |
2292 | old_retry_short = rdev->wiphy.retry_short; | |
2293 | old_retry_long = rdev->wiphy.retry_long; | |
2294 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2295 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2296 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2297 | |
2298 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2299 | rdev->wiphy.retry_short = retry_short; | |
2300 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2301 | rdev->wiphy.retry_long = retry_long; | |
2302 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2303 | rdev->wiphy.frag_threshold = frag_threshold; | |
2304 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2305 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2306 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2307 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2308 | |
e35e4d28 | 2309 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2310 | if (result) { |
2311 | rdev->wiphy.retry_short = old_retry_short; | |
2312 | rdev->wiphy.retry_long = old_retry_long; | |
2313 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2314 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2315 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2316 | } |
2317 | } | |
7f2b8562 | 2318 | return 0; |
55682965 JB |
2319 | } |
2320 | ||
71bbc994 JB |
2321 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2322 | { | |
2323 | return (u64)wdev->identifier | | |
f26cbf40 | 2324 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2325 | } |
55682965 | 2326 | |
683b6d3b | 2327 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2328 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2329 | { |
601555cd JB |
2330 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
2331 | return -EINVAL; | |
3d9d1d66 | 2332 | |
683b6d3b JB |
2333 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2334 | chandef->chan->center_freq)) | |
2335 | return -ENOBUFS; | |
3d9d1d66 JB |
2336 | switch (chandef->width) { |
2337 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2338 | case NL80211_CHAN_WIDTH_20: | |
2339 | case NL80211_CHAN_WIDTH_40: | |
2340 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2341 | cfg80211_get_chandef_type(chandef))) | |
2342 | return -ENOBUFS; | |
2343 | break; | |
2344 | default: | |
2345 | break; | |
2346 | } | |
2347 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2348 | return -ENOBUFS; | |
2349 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2350 | return -ENOBUFS; | |
2351 | if (chandef->center_freq2 && | |
2352 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2353 | return -ENOBUFS; |
2354 | return 0; | |
2355 | } | |
2356 | ||
15e47304 | 2357 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2358 | struct cfg80211_registered_device *rdev, |
8f894be2 | 2359 | struct wireless_dev *wdev, bool removal) |
55682965 | 2360 | { |
72fb2abc | 2361 | struct net_device *dev = wdev->netdev; |
8f894be2 | 2362 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
55682965 JB |
2363 | void *hdr; |
2364 | ||
8f894be2 TB |
2365 | if (removal) |
2366 | cmd = NL80211_CMD_DEL_INTERFACE; | |
2367 | ||
2368 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | |
55682965 JB |
2369 | if (!hdr) |
2370 | return -1; | |
2371 | ||
72fb2abc JB |
2372 | if (dev && |
2373 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2374 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2375 | goto nla_put_failure; |
2376 | ||
2377 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2378 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2379 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2380 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2381 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2382 | rdev->devlist_generation ^ | |
2383 | (cfg80211_rdev_list_generation << 2))) | |
2384 | goto nla_put_failure; | |
f5ea9120 | 2385 | |
5b7ccaf3 | 2386 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2387 | int ret; |
2388 | struct cfg80211_chan_def chandef; | |
2389 | ||
2390 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2391 | if (ret == 0) { | |
2392 | if (nl80211_send_chandef(msg, &chandef)) | |
2393 | goto nla_put_failure; | |
2394 | } | |
d91df0e3 PF |
2395 | } |
2396 | ||
b84e7a05 AQ |
2397 | if (wdev->ssid_len) { |
2398 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2399 | goto nla_put_failure; | |
2400 | } | |
2401 | ||
55682965 JB |
2402 | return genlmsg_end(msg, hdr); |
2403 | ||
2404 | nla_put_failure: | |
bc3ed28c TG |
2405 | genlmsg_cancel(msg, hdr); |
2406 | return -EMSGSIZE; | |
55682965 JB |
2407 | } |
2408 | ||
2409 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2410 | { | |
2411 | int wp_idx = 0; | |
2412 | int if_idx = 0; | |
2413 | int wp_start = cb->args[0]; | |
2414 | int if_start = cb->args[1]; | |
f5ea9120 | 2415 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2416 | struct wireless_dev *wdev; |
2417 | ||
5fe231e8 | 2418 | rtnl_lock(); |
f5ea9120 JB |
2419 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2420 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2421 | continue; |
bba95fef JB |
2422 | if (wp_idx < wp_start) { |
2423 | wp_idx++; | |
55682965 | 2424 | continue; |
bba95fef | 2425 | } |
55682965 JB |
2426 | if_idx = 0; |
2427 | ||
89a54e48 | 2428 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2429 | if (if_idx < if_start) { |
2430 | if_idx++; | |
55682965 | 2431 | continue; |
bba95fef | 2432 | } |
15e47304 | 2433 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2434 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
8f894be2 | 2435 | rdev, wdev, false) < 0) { |
bba95fef JB |
2436 | goto out; |
2437 | } | |
2438 | if_idx++; | |
55682965 | 2439 | } |
bba95fef JB |
2440 | |
2441 | wp_idx++; | |
55682965 | 2442 | } |
bba95fef | 2443 | out: |
5fe231e8 | 2444 | rtnl_unlock(); |
55682965 JB |
2445 | |
2446 | cb->args[0] = wp_idx; | |
2447 | cb->args[1] = if_idx; | |
2448 | ||
2449 | return skb->len; | |
2450 | } | |
2451 | ||
2452 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2453 | { | |
2454 | struct sk_buff *msg; | |
1b8ec87a | 2455 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2456 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2457 | |
fd2120ca | 2458 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2459 | if (!msg) |
4c476991 | 2460 | return -ENOMEM; |
55682965 | 2461 | |
15e47304 | 2462 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2463 | rdev, wdev, false) < 0) { |
4c476991 JB |
2464 | nlmsg_free(msg); |
2465 | return -ENOBUFS; | |
2466 | } | |
55682965 | 2467 | |
134e6375 | 2468 | return genlmsg_reply(msg, info); |
55682965 JB |
2469 | } |
2470 | ||
66f7ac50 MW |
2471 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2472 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2473 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2474 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2475 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2476 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2477 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2478 | }; |
2479 | ||
2480 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2481 | { | |
2482 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2483 | int flag; | |
2484 | ||
2485 | *mntrflags = 0; | |
2486 | ||
2487 | if (!nla) | |
2488 | return -EINVAL; | |
2489 | ||
2490 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2491 | nla, mntr_flags_policy)) | |
2492 | return -EINVAL; | |
2493 | ||
2494 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2495 | if (flags[flag]) | |
2496 | *mntrflags |= (1<<flag); | |
2497 | ||
2498 | return 0; | |
2499 | } | |
2500 | ||
9bc383de | 2501 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2502 | struct net_device *netdev, u8 use_4addr, |
2503 | enum nl80211_iftype iftype) | |
9bc383de | 2504 | { |
ad4bb6f8 | 2505 | if (!use_4addr) { |
f350a0a8 | 2506 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2507 | return -EBUSY; |
9bc383de | 2508 | return 0; |
ad4bb6f8 | 2509 | } |
9bc383de JB |
2510 | |
2511 | switch (iftype) { | |
2512 | case NL80211_IFTYPE_AP_VLAN: | |
2513 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2514 | return 0; | |
2515 | break; | |
2516 | case NL80211_IFTYPE_STATION: | |
2517 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2518 | return 0; | |
2519 | break; | |
2520 | default: | |
2521 | break; | |
2522 | } | |
2523 | ||
2524 | return -EOPNOTSUPP; | |
2525 | } | |
2526 | ||
55682965 JB |
2527 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2528 | { | |
4c476991 | 2529 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2530 | struct vif_params params; |
e36d56b6 | 2531 | int err; |
04a773ad | 2532 | enum nl80211_iftype otype, ntype; |
4c476991 | 2533 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2534 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2535 | bool change = false; |
55682965 | 2536 | |
2ec600d6 LCC |
2537 | memset(¶ms, 0, sizeof(params)); |
2538 | ||
04a773ad | 2539 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2540 | |
723b038d | 2541 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2542 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2543 | if (otype != ntype) |
ac7f9cfa | 2544 | change = true; |
4c476991 JB |
2545 | if (ntype > NL80211_IFTYPE_MAX) |
2546 | return -EINVAL; | |
723b038d JB |
2547 | } |
2548 | ||
92ffe055 | 2549 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2550 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2551 | ||
4c476991 JB |
2552 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2553 | return -EINVAL; | |
29cbe68c JB |
2554 | if (netif_running(dev)) |
2555 | return -EBUSY; | |
2556 | ||
2557 | wdev_lock(wdev); | |
2558 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2559 | IEEE80211_MAX_MESH_ID_LEN); | |
2560 | wdev->mesh_id_up_len = | |
2561 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2562 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2563 | wdev->mesh_id_up_len); | |
2564 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2565 | } |
2566 | ||
8b787643 FF |
2567 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2568 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2569 | change = true; | |
ad4bb6f8 | 2570 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2571 | if (err) |
4c476991 | 2572 | return err; |
8b787643 FF |
2573 | } else { |
2574 | params.use_4addr = -1; | |
2575 | } | |
2576 | ||
92ffe055 | 2577 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2578 | if (ntype != NL80211_IFTYPE_MONITOR) |
2579 | return -EINVAL; | |
92ffe055 JB |
2580 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2581 | &_flags); | |
ac7f9cfa | 2582 | if (err) |
4c476991 | 2583 | return err; |
ac7f9cfa JB |
2584 | |
2585 | flags = &_flags; | |
2586 | change = true; | |
92ffe055 | 2587 | } |
3b85875a | 2588 | |
18003297 | 2589 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2590 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2591 | return -EOPNOTSUPP; | |
2592 | ||
ac7f9cfa | 2593 | if (change) |
3d54d255 | 2594 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2595 | else |
2596 | err = 0; | |
60719ffd | 2597 | |
9bc383de JB |
2598 | if (!err && params.use_4addr != -1) |
2599 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2600 | ||
55682965 JB |
2601 | return err; |
2602 | } | |
2603 | ||
2604 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2605 | { | |
4c476991 | 2606 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2607 | struct vif_params params; |
84efbb84 | 2608 | struct wireless_dev *wdev; |
8f894be2 | 2609 | struct sk_buff *msg, *event; |
55682965 JB |
2610 | int err; |
2611 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2612 | u32 flags; |
55682965 | 2613 | |
78f22b6a JB |
2614 | /* to avoid failing a new interface creation due to pending removal */ |
2615 | cfg80211_destroy_ifaces(rdev); | |
2616 | ||
2ec600d6 LCC |
2617 | memset(¶ms, 0, sizeof(params)); |
2618 | ||
55682965 JB |
2619 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2620 | return -EINVAL; | |
2621 | ||
2622 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2623 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2624 | if (type > NL80211_IFTYPE_MAX) | |
2625 | return -EINVAL; | |
2626 | } | |
2627 | ||
79c97e97 | 2628 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2629 | !(rdev->wiphy.interface_modes & (1 << type))) |
2630 | return -EOPNOTSUPP; | |
55682965 | 2631 | |
e8f479b1 BG |
2632 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
2633 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && | |
2634 | info->attrs[NL80211_ATTR_MAC]) { | |
1c18f145 AS |
2635 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
2636 | ETH_ALEN); | |
2637 | if (!is_valid_ether_addr(params.macaddr)) | |
2638 | return -EADDRNOTAVAIL; | |
2639 | } | |
2640 | ||
9bc383de | 2641 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2642 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2643 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2644 | if (err) |
4c476991 | 2645 | return err; |
9bc383de | 2646 | } |
8b787643 | 2647 | |
1c90f9d4 JB |
2648 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2649 | if (!msg) | |
2650 | return -ENOMEM; | |
2651 | ||
66f7ac50 MW |
2652 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2653 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2654 | &flags); | |
e057d3c3 | 2655 | |
18003297 | 2656 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2657 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2658 | return -EOPNOTSUPP; | |
2659 | ||
e35e4d28 HG |
2660 | wdev = rdev_add_virtual_intf(rdev, |
2661 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2662 | type, err ? NULL : &flags, ¶ms); | |
d687cbb7 RM |
2663 | if (WARN_ON(!wdev)) { |
2664 | nlmsg_free(msg); | |
2665 | return -EPROTO; | |
2666 | } else if (IS_ERR(wdev)) { | |
1c90f9d4 | 2667 | nlmsg_free(msg); |
84efbb84 | 2668 | return PTR_ERR(wdev); |
1c90f9d4 | 2669 | } |
2ec600d6 | 2670 | |
18e5ca65 | 2671 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
78f22b6a JB |
2672 | wdev->owner_nlportid = info->snd_portid; |
2673 | ||
98104fde JB |
2674 | switch (type) { |
2675 | case NL80211_IFTYPE_MESH_POINT: | |
2676 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2677 | break; | |
29cbe68c JB |
2678 | wdev_lock(wdev); |
2679 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2680 | IEEE80211_MAX_MESH_ID_LEN); | |
2681 | wdev->mesh_id_up_len = | |
2682 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2683 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2684 | wdev->mesh_id_up_len); | |
2685 | wdev_unlock(wdev); | |
98104fde JB |
2686 | break; |
2687 | case NL80211_IFTYPE_P2P_DEVICE: | |
2688 | /* | |
2689 | * P2P Device doesn't have a netdev, so doesn't go | |
2690 | * through the netdev notifier and must be added here | |
2691 | */ | |
2692 | mutex_init(&wdev->mtx); | |
2693 | INIT_LIST_HEAD(&wdev->event_list); | |
2694 | spin_lock_init(&wdev->event_lock); | |
2695 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2696 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2697 | ||
98104fde JB |
2698 | wdev->identifier = ++rdev->wdev_id; |
2699 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2700 | rdev->devlist_generation++; | |
98104fde JB |
2701 | break; |
2702 | default: | |
2703 | break; | |
29cbe68c JB |
2704 | } |
2705 | ||
15e47304 | 2706 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2707 | rdev, wdev, false) < 0) { |
1c90f9d4 JB |
2708 | nlmsg_free(msg); |
2709 | return -ENOBUFS; | |
2710 | } | |
2711 | ||
8f894be2 TB |
2712 | event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2713 | if (event) { | |
2714 | if (nl80211_send_iface(event, 0, 0, 0, | |
2715 | rdev, wdev, false) < 0) { | |
2716 | nlmsg_free(event); | |
2717 | goto out; | |
2718 | } | |
2719 | ||
2720 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
2721 | event, 0, NL80211_MCGRP_CONFIG, | |
2722 | GFP_KERNEL); | |
2723 | } | |
2724 | ||
2725 | out: | |
1c90f9d4 | 2726 | return genlmsg_reply(msg, info); |
55682965 JB |
2727 | } |
2728 | ||
2729 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2730 | { | |
4c476991 | 2731 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2732 | struct wireless_dev *wdev = info->user_ptr[1]; |
8f894be2 TB |
2733 | struct sk_buff *msg; |
2734 | int status; | |
55682965 | 2735 | |
4c476991 JB |
2736 | if (!rdev->ops->del_virtual_intf) |
2737 | return -EOPNOTSUPP; | |
55682965 | 2738 | |
8f894be2 TB |
2739 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2740 | if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) { | |
2741 | nlmsg_free(msg); | |
2742 | msg = NULL; | |
2743 | } | |
2744 | ||
84efbb84 JB |
2745 | /* |
2746 | * If we remove a wireless device without a netdev then clear | |
2747 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2748 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2749 | * since the wdev has been freed, unlike with a netdev where | |
2750 | * we need the dev_put() for the netdev to really be freed. | |
2751 | */ | |
2752 | if (!wdev->netdev) | |
2753 | info->user_ptr[1] = NULL; | |
2754 | ||
8f894be2 TB |
2755 | status = rdev_del_virtual_intf(rdev, wdev); |
2756 | if (status >= 0 && msg) | |
2757 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
2758 | msg, 0, NL80211_MCGRP_CONFIG, | |
2759 | GFP_KERNEL); | |
2760 | else | |
2761 | nlmsg_free(msg); | |
2762 | ||
2763 | return status; | |
55682965 JB |
2764 | } |
2765 | ||
1d9d9213 SW |
2766 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2767 | { | |
2768 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2769 | struct net_device *dev = info->user_ptr[1]; | |
2770 | u16 noack_map; | |
2771 | ||
2772 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2773 | return -EINVAL; | |
2774 | ||
2775 | if (!rdev->ops->set_noack_map) | |
2776 | return -EOPNOTSUPP; | |
2777 | ||
2778 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2779 | ||
e35e4d28 | 2780 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2781 | } |
2782 | ||
41ade00f JB |
2783 | struct get_key_cookie { |
2784 | struct sk_buff *msg; | |
2785 | int error; | |
b9454e83 | 2786 | int idx; |
41ade00f JB |
2787 | }; |
2788 | ||
2789 | static void get_key_callback(void *c, struct key_params *params) | |
2790 | { | |
b9454e83 | 2791 | struct nlattr *key; |
41ade00f JB |
2792 | struct get_key_cookie *cookie = c; |
2793 | ||
9360ffd1 DM |
2794 | if ((params->key && |
2795 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2796 | params->key_len, params->key)) || | |
2797 | (params->seq && | |
2798 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2799 | params->seq_len, params->seq)) || | |
2800 | (params->cipher && | |
2801 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2802 | params->cipher))) | |
2803 | goto nla_put_failure; | |
41ade00f | 2804 | |
b9454e83 JB |
2805 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2806 | if (!key) | |
2807 | goto nla_put_failure; | |
2808 | ||
9360ffd1 DM |
2809 | if ((params->key && |
2810 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2811 | params->key_len, params->key)) || | |
2812 | (params->seq && | |
2813 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2814 | params->seq_len, params->seq)) || | |
2815 | (params->cipher && | |
2816 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2817 | params->cipher))) | |
2818 | goto nla_put_failure; | |
b9454e83 | 2819 | |
9360ffd1 DM |
2820 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2821 | goto nla_put_failure; | |
b9454e83 JB |
2822 | |
2823 | nla_nest_end(cookie->msg, key); | |
2824 | ||
41ade00f JB |
2825 | return; |
2826 | nla_put_failure: | |
2827 | cookie->error = 1; | |
2828 | } | |
2829 | ||
2830 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2831 | { | |
4c476991 | 2832 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2833 | int err; |
4c476991 | 2834 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2835 | u8 key_idx = 0; |
e31b8213 JB |
2836 | const u8 *mac_addr = NULL; |
2837 | bool pairwise; | |
41ade00f JB |
2838 | struct get_key_cookie cookie = { |
2839 | .error = 0, | |
2840 | }; | |
2841 | void *hdr; | |
2842 | struct sk_buff *msg; | |
2843 | ||
2844 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2845 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2846 | ||
3cfcf6ac | 2847 | if (key_idx > 5) |
41ade00f JB |
2848 | return -EINVAL; |
2849 | ||
2850 | if (info->attrs[NL80211_ATTR_MAC]) | |
2851 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2852 | ||
e31b8213 JB |
2853 | pairwise = !!mac_addr; |
2854 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2855 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2856 | if (kt >= NUM_NL80211_KEYTYPES) | |
2857 | return -EINVAL; | |
2858 | if (kt != NL80211_KEYTYPE_GROUP && | |
2859 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2860 | return -EINVAL; | |
2861 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2862 | } | |
2863 | ||
4c476991 JB |
2864 | if (!rdev->ops->get_key) |
2865 | return -EOPNOTSUPP; | |
41ade00f | 2866 | |
fd2120ca | 2867 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2868 | if (!msg) |
2869 | return -ENOMEM; | |
41ade00f | 2870 | |
15e47304 | 2871 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2872 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 2873 | if (!hdr) |
9fe271af | 2874 | goto nla_put_failure; |
41ade00f JB |
2875 | |
2876 | cookie.msg = msg; | |
b9454e83 | 2877 | cookie.idx = key_idx; |
41ade00f | 2878 | |
9360ffd1 DM |
2879 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2880 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2881 | goto nla_put_failure; | |
2882 | if (mac_addr && | |
2883 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2884 | goto nla_put_failure; | |
41ade00f | 2885 | |
e31b8213 JB |
2886 | if (pairwise && mac_addr && |
2887 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2888 | return -ENOENT; | |
2889 | ||
e35e4d28 HG |
2890 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2891 | get_key_callback); | |
41ade00f JB |
2892 | |
2893 | if (err) | |
6c95e2a2 | 2894 | goto free_msg; |
41ade00f JB |
2895 | |
2896 | if (cookie.error) | |
2897 | goto nla_put_failure; | |
2898 | ||
2899 | genlmsg_end(msg, hdr); | |
4c476991 | 2900 | return genlmsg_reply(msg, info); |
41ade00f JB |
2901 | |
2902 | nla_put_failure: | |
2903 | err = -ENOBUFS; | |
6c95e2a2 | 2904 | free_msg: |
41ade00f | 2905 | nlmsg_free(msg); |
41ade00f JB |
2906 | return err; |
2907 | } | |
2908 | ||
2909 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2910 | { | |
4c476991 | 2911 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2912 | struct key_parse key; |
41ade00f | 2913 | int err; |
4c476991 | 2914 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2915 | |
b9454e83 JB |
2916 | err = nl80211_parse_key(info, &key); |
2917 | if (err) | |
2918 | return err; | |
41ade00f | 2919 | |
b9454e83 | 2920 | if (key.idx < 0) |
41ade00f JB |
2921 | return -EINVAL; |
2922 | ||
b9454e83 JB |
2923 | /* only support setting default key */ |
2924 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2925 | return -EINVAL; |
2926 | ||
dbd2fd65 | 2927 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2928 | |
dbd2fd65 JB |
2929 | if (key.def) { |
2930 | if (!rdev->ops->set_default_key) { | |
2931 | err = -EOPNOTSUPP; | |
2932 | goto out; | |
2933 | } | |
41ade00f | 2934 | |
dbd2fd65 JB |
2935 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2936 | if (err) | |
2937 | goto out; | |
2938 | ||
e35e4d28 | 2939 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2940 | key.def_uni, key.def_multi); |
2941 | ||
2942 | if (err) | |
2943 | goto out; | |
fffd0934 | 2944 | |
3d23e349 | 2945 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2946 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2947 | #endif | |
2948 | } else { | |
2949 | if (key.def_uni || !key.def_multi) { | |
2950 | err = -EINVAL; | |
2951 | goto out; | |
2952 | } | |
2953 | ||
2954 | if (!rdev->ops->set_default_mgmt_key) { | |
2955 | err = -EOPNOTSUPP; | |
2956 | goto out; | |
2957 | } | |
2958 | ||
2959 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2960 | if (err) | |
2961 | goto out; | |
2962 | ||
e35e4d28 | 2963 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2964 | if (err) |
2965 | goto out; | |
2966 | ||
2967 | #ifdef CONFIG_CFG80211_WEXT | |
2968 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2969 | #endif |
dbd2fd65 JB |
2970 | } |
2971 | ||
2972 | out: | |
fffd0934 | 2973 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2974 | |
41ade00f JB |
2975 | return err; |
2976 | } | |
2977 | ||
2978 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2979 | { | |
4c476991 | 2980 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2981 | int err; |
4c476991 | 2982 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2983 | struct key_parse key; |
e31b8213 | 2984 | const u8 *mac_addr = NULL; |
41ade00f | 2985 | |
b9454e83 JB |
2986 | err = nl80211_parse_key(info, &key); |
2987 | if (err) | |
2988 | return err; | |
41ade00f | 2989 | |
b9454e83 | 2990 | if (!key.p.key) |
41ade00f JB |
2991 | return -EINVAL; |
2992 | ||
41ade00f JB |
2993 | if (info->attrs[NL80211_ATTR_MAC]) |
2994 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2995 | ||
e31b8213 JB |
2996 | if (key.type == -1) { |
2997 | if (mac_addr) | |
2998 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2999 | else | |
3000 | key.type = NL80211_KEYTYPE_GROUP; | |
3001 | } | |
3002 | ||
3003 | /* for now */ | |
3004 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3005 | key.type != NL80211_KEYTYPE_GROUP) | |
3006 | return -EINVAL; | |
3007 | ||
4c476991 JB |
3008 | if (!rdev->ops->add_key) |
3009 | return -EOPNOTSUPP; | |
25e47c18 | 3010 | |
e31b8213 JB |
3011 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
3012 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3013 | mac_addr)) | |
4c476991 | 3014 | return -EINVAL; |
41ade00f | 3015 | |
fffd0934 JB |
3016 | wdev_lock(dev->ieee80211_ptr); |
3017 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3018 | if (!err) | |
e35e4d28 HG |
3019 | err = rdev_add_key(rdev, dev, key.idx, |
3020 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3021 | mac_addr, &key.p); | |
fffd0934 | 3022 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3023 | |
41ade00f JB |
3024 | return err; |
3025 | } | |
3026 | ||
3027 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
3028 | { | |
4c476991 | 3029 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3030 | int err; |
4c476991 | 3031 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3032 | u8 *mac_addr = NULL; |
b9454e83 | 3033 | struct key_parse key; |
41ade00f | 3034 | |
b9454e83 JB |
3035 | err = nl80211_parse_key(info, &key); |
3036 | if (err) | |
3037 | return err; | |
41ade00f JB |
3038 | |
3039 | if (info->attrs[NL80211_ATTR_MAC]) | |
3040 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3041 | ||
e31b8213 JB |
3042 | if (key.type == -1) { |
3043 | if (mac_addr) | |
3044 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3045 | else | |
3046 | key.type = NL80211_KEYTYPE_GROUP; | |
3047 | } | |
3048 | ||
3049 | /* for now */ | |
3050 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3051 | key.type != NL80211_KEYTYPE_GROUP) | |
3052 | return -EINVAL; | |
3053 | ||
4c476991 JB |
3054 | if (!rdev->ops->del_key) |
3055 | return -EOPNOTSUPP; | |
41ade00f | 3056 | |
fffd0934 JB |
3057 | wdev_lock(dev->ieee80211_ptr); |
3058 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
3059 | |
3060 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
3061 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
3062 | err = -ENOENT; | |
3063 | ||
fffd0934 | 3064 | if (!err) |
e35e4d28 HG |
3065 | err = rdev_del_key(rdev, dev, key.idx, |
3066 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3067 | mac_addr); | |
41ade00f | 3068 | |
3d23e349 | 3069 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 3070 | if (!err) { |
b9454e83 | 3071 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 3072 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 3073 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
3074 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
3075 | } | |
3076 | #endif | |
fffd0934 | 3077 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 3078 | |
41ade00f JB |
3079 | return err; |
3080 | } | |
3081 | ||
77765eaf VT |
3082 | /* This function returns an error or the number of nested attributes */ |
3083 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
3084 | { | |
3085 | struct nlattr *attr; | |
3086 | int n_entries = 0, tmp; | |
3087 | ||
3088 | nla_for_each_nested(attr, nl_attr, tmp) { | |
3089 | if (nla_len(attr) != ETH_ALEN) | |
3090 | return -EINVAL; | |
3091 | ||
3092 | n_entries++; | |
3093 | } | |
3094 | ||
3095 | return n_entries; | |
3096 | } | |
3097 | ||
3098 | /* | |
3099 | * This function parses ACL information and allocates memory for ACL data. | |
3100 | * On successful return, the calling function is responsible to free the | |
3101 | * ACL buffer returned by this function. | |
3102 | */ | |
3103 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3104 | struct genl_info *info) | |
3105 | { | |
3106 | enum nl80211_acl_policy acl_policy; | |
3107 | struct nlattr *attr; | |
3108 | struct cfg80211_acl_data *acl; | |
3109 | int i = 0, n_entries, tmp; | |
3110 | ||
3111 | if (!wiphy->max_acl_mac_addrs) | |
3112 | return ERR_PTR(-EOPNOTSUPP); | |
3113 | ||
3114 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3115 | return ERR_PTR(-EINVAL); | |
3116 | ||
3117 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3118 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3119 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3120 | return ERR_PTR(-EINVAL); | |
3121 | ||
3122 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3123 | return ERR_PTR(-EINVAL); | |
3124 | ||
3125 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3126 | if (n_entries < 0) | |
3127 | return ERR_PTR(n_entries); | |
3128 | ||
3129 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3130 | return ERR_PTR(-ENOTSUPP); | |
3131 | ||
3132 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
3133 | GFP_KERNEL); | |
3134 | if (!acl) | |
3135 | return ERR_PTR(-ENOMEM); | |
3136 | ||
3137 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3138 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3139 | i++; | |
3140 | } | |
3141 | ||
3142 | acl->n_acl_entries = n_entries; | |
3143 | acl->acl_policy = acl_policy; | |
3144 | ||
3145 | return acl; | |
3146 | } | |
3147 | ||
3148 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3149 | { | |
3150 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3151 | struct net_device *dev = info->user_ptr[1]; | |
3152 | struct cfg80211_acl_data *acl; | |
3153 | int err; | |
3154 | ||
3155 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3156 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3157 | return -EOPNOTSUPP; | |
3158 | ||
3159 | if (!dev->ieee80211_ptr->beacon_interval) | |
3160 | return -EINVAL; | |
3161 | ||
3162 | acl = parse_acl_data(&rdev->wiphy, info); | |
3163 | if (IS_ERR(acl)) | |
3164 | return PTR_ERR(acl); | |
3165 | ||
3166 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3167 | ||
3168 | kfree(acl); | |
3169 | ||
3170 | return err; | |
3171 | } | |
3172 | ||
a1193be8 | 3173 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3174 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3175 | { |
8860020e | 3176 | bool haveinfo = false; |
ed1b6cc7 | 3177 | |
a1193be8 SW |
3178 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3179 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3180 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3181 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3182 | return -EINVAL; |
3183 | ||
8860020e | 3184 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3185 | |
a1193be8 SW |
3186 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3187 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3188 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3189 | if (!bcn->head_len) |
3190 | return -EINVAL; | |
3191 | haveinfo = true; | |
ed1b6cc7 JB |
3192 | } |
3193 | ||
a1193be8 SW |
3194 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3195 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3196 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3197 | haveinfo = true; |
ed1b6cc7 JB |
3198 | } |
3199 | ||
4c476991 JB |
3200 | if (!haveinfo) |
3201 | return -EINVAL; | |
3b85875a | 3202 | |
a1193be8 SW |
3203 | if (attrs[NL80211_ATTR_IE]) { |
3204 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3205 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3206 | } |
3207 | ||
a1193be8 | 3208 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3209 | bcn->proberesp_ies = |
a1193be8 | 3210 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3211 | bcn->proberesp_ies_len = |
a1193be8 | 3212 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3213 | } |
3214 | ||
a1193be8 | 3215 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3216 | bcn->assocresp_ies = |
a1193be8 | 3217 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3218 | bcn->assocresp_ies_len = |
a1193be8 | 3219 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3220 | } |
3221 | ||
a1193be8 SW |
3222 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3223 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3224 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3225 | } |
3226 | ||
8860020e JB |
3227 | return 0; |
3228 | } | |
3229 | ||
46c1dd0c FF |
3230 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3231 | struct cfg80211_ap_settings *params) | |
3232 | { | |
3233 | struct wireless_dev *wdev; | |
3234 | bool ret = false; | |
3235 | ||
89a54e48 | 3236 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3237 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3238 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3239 | continue; | |
3240 | ||
683b6d3b | 3241 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3242 | continue; |
3243 | ||
683b6d3b | 3244 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3245 | ret = true; |
3246 | break; | |
3247 | } | |
3248 | ||
46c1dd0c FF |
3249 | return ret; |
3250 | } | |
3251 | ||
e39e5b5e JM |
3252 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3253 | enum nl80211_auth_type auth_type, | |
3254 | enum nl80211_commands cmd) | |
3255 | { | |
3256 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3257 | return false; | |
3258 | ||
3259 | switch (cmd) { | |
3260 | case NL80211_CMD_AUTHENTICATE: | |
3261 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3262 | auth_type == NL80211_AUTHTYPE_SAE) | |
3263 | return false; | |
3264 | return true; | |
3265 | case NL80211_CMD_CONNECT: | |
3266 | case NL80211_CMD_START_AP: | |
3267 | /* SAE not supported yet */ | |
3268 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3269 | return false; | |
3270 | return true; | |
3271 | default: | |
3272 | return false; | |
3273 | } | |
3274 | } | |
3275 | ||
8860020e JB |
3276 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3277 | { | |
3278 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3279 | struct net_device *dev = info->user_ptr[1]; | |
3280 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3281 | struct cfg80211_ap_settings params; | |
3282 | int err; | |
3283 | ||
3284 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3285 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3286 | return -EOPNOTSUPP; | |
3287 | ||
3288 | if (!rdev->ops->start_ap) | |
3289 | return -EOPNOTSUPP; | |
3290 | ||
3291 | if (wdev->beacon_interval) | |
3292 | return -EALREADY; | |
3293 | ||
3294 | memset(¶ms, 0, sizeof(params)); | |
3295 | ||
3296 | /* these are required for START_AP */ | |
3297 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3298 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3299 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3300 | return -EINVAL; | |
3301 | ||
a1193be8 | 3302 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3303 | if (err) |
3304 | return err; | |
3305 | ||
3306 | params.beacon_interval = | |
3307 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3308 | params.dtim_period = | |
3309 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3310 | ||
3311 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3312 | if (err) | |
3313 | return err; | |
3314 | ||
3315 | /* | |
3316 | * In theory, some of these attributes should be required here | |
3317 | * but since they were not used when the command was originally | |
3318 | * added, keep them optional for old user space programs to let | |
3319 | * them continue to work with drivers that do not need the | |
3320 | * additional information -- drivers must check! | |
3321 | */ | |
3322 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3323 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3324 | params.ssid_len = | |
3325 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3326 | if (params.ssid_len == 0 || | |
3327 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3328 | return -EINVAL; | |
3329 | } | |
3330 | ||
3331 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3332 | params.hidden_ssid = nla_get_u32( | |
3333 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3334 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3335 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3336 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3337 | return -EINVAL; | |
3338 | } | |
3339 | ||
3340 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3341 | ||
3342 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3343 | params.auth_type = nla_get_u32( | |
3344 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3345 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3346 | NL80211_CMD_START_AP)) | |
8860020e JB |
3347 | return -EINVAL; |
3348 | } else | |
3349 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3350 | ||
3351 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3352 | NL80211_MAX_NR_CIPHER_SUITES); | |
3353 | if (err) | |
3354 | return err; | |
3355 | ||
1b658f11 VT |
3356 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3357 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3358 | return -EOPNOTSUPP; | |
3359 | params.inactivity_timeout = nla_get_u16( | |
3360 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3361 | } | |
3362 | ||
53cabad7 JB |
3363 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3364 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3365 | return -EINVAL; | |
3366 | params.p2p_ctwindow = | |
3367 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3368 | if (params.p2p_ctwindow > 127) | |
3369 | return -EINVAL; | |
3370 | if (params.p2p_ctwindow != 0 && | |
3371 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3372 | return -EINVAL; | |
3373 | } | |
3374 | ||
3375 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3376 | u8 tmp; | |
3377 | ||
3378 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3379 | return -EINVAL; | |
3380 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3381 | if (tmp > 1) | |
3382 | return -EINVAL; | |
3383 | params.p2p_opp_ps = tmp; | |
3384 | if (params.p2p_opp_ps != 0 && | |
3385 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3386 | return -EINVAL; | |
3387 | } | |
3388 | ||
aa430da4 | 3389 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3390 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3391 | if (err) | |
3392 | return err; | |
3393 | } else if (wdev->preset_chandef.chan) { | |
3394 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3395 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3396 | return -EINVAL; |
3397 | ||
174e0cd2 IP |
3398 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
3399 | wdev->iftype)) | |
aa430da4 JB |
3400 | return -EINVAL; |
3401 | ||
77765eaf VT |
3402 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3403 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3404 | if (IS_ERR(params.acl)) | |
3405 | return PTR_ERR(params.acl); | |
3406 | } | |
3407 | ||
18998c38 EP |
3408 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
3409 | params.smps_mode = | |
3410 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); | |
3411 | switch (params.smps_mode) { | |
3412 | case NL80211_SMPS_OFF: | |
3413 | break; | |
3414 | case NL80211_SMPS_STATIC: | |
3415 | if (!(rdev->wiphy.features & | |
3416 | NL80211_FEATURE_STATIC_SMPS)) | |
3417 | return -EINVAL; | |
3418 | break; | |
3419 | case NL80211_SMPS_DYNAMIC: | |
3420 | if (!(rdev->wiphy.features & | |
3421 | NL80211_FEATURE_DYNAMIC_SMPS)) | |
3422 | return -EINVAL; | |
3423 | break; | |
3424 | default: | |
3425 | return -EINVAL; | |
3426 | } | |
3427 | } else { | |
3428 | params.smps_mode = NL80211_SMPS_OFF; | |
3429 | } | |
3430 | ||
c56589ed | 3431 | wdev_lock(wdev); |
e35e4d28 | 3432 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3433 | if (!err) { |
683b6d3b | 3434 | wdev->preset_chandef = params.chandef; |
8860020e | 3435 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 3436 | wdev->chandef = params.chandef; |
06e191e2 AQ |
3437 | wdev->ssid_len = params.ssid_len; |
3438 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3439 | } |
c56589ed | 3440 | wdev_unlock(wdev); |
77765eaf VT |
3441 | |
3442 | kfree(params.acl); | |
3443 | ||
56d1893d | 3444 | return err; |
ed1b6cc7 JB |
3445 | } |
3446 | ||
8860020e JB |
3447 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3448 | { | |
3449 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3450 | struct net_device *dev = info->user_ptr[1]; | |
3451 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3452 | struct cfg80211_beacon_data params; | |
3453 | int err; | |
3454 | ||
3455 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3456 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3457 | return -EOPNOTSUPP; | |
3458 | ||
3459 | if (!rdev->ops->change_beacon) | |
3460 | return -EOPNOTSUPP; | |
3461 | ||
3462 | if (!wdev->beacon_interval) | |
3463 | return -EINVAL; | |
3464 | ||
a1193be8 | 3465 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3466 | if (err) |
3467 | return err; | |
3468 | ||
c56589ed SW |
3469 | wdev_lock(wdev); |
3470 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3471 | wdev_unlock(wdev); | |
3472 | ||
3473 | return err; | |
8860020e JB |
3474 | } |
3475 | ||
3476 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3477 | { |
4c476991 JB |
3478 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3479 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3480 | |
7c8d5e03 | 3481 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
3482 | } |
3483 | ||
5727ef1b JB |
3484 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3485 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3486 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3487 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3488 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3489 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3490 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3491 | }; |
3492 | ||
eccb8e8f | 3493 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3494 | enum nl80211_iftype iftype, |
eccb8e8f | 3495 | struct station_parameters *params) |
5727ef1b JB |
3496 | { |
3497 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3498 | struct nlattr *nla; |
5727ef1b JB |
3499 | int flag; |
3500 | ||
eccb8e8f JB |
3501 | /* |
3502 | * Try parsing the new attribute first so userspace | |
3503 | * can specify both for older kernels. | |
3504 | */ | |
3505 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3506 | if (nla) { | |
3507 | struct nl80211_sta_flag_update *sta_flags; | |
3508 | ||
3509 | sta_flags = nla_data(nla); | |
3510 | params->sta_flags_mask = sta_flags->mask; | |
3511 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3512 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3513 | if ((params->sta_flags_mask | |
3514 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3515 | return -EINVAL; | |
3516 | return 0; | |
3517 | } | |
3518 | ||
3519 | /* if present, parse the old attribute */ | |
5727ef1b | 3520 | |
eccb8e8f | 3521 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3522 | if (!nla) |
3523 | return 0; | |
3524 | ||
3525 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3526 | nla, sta_flags_policy)) | |
3527 | return -EINVAL; | |
3528 | ||
bdd3ae3d JB |
3529 | /* |
3530 | * Only allow certain flags for interface types so that | |
3531 | * other attributes are silently ignored. Remember that | |
3532 | * this is backward compatibility code with old userspace | |
3533 | * and shouldn't be hit in other cases anyway. | |
3534 | */ | |
3535 | switch (iftype) { | |
3536 | case NL80211_IFTYPE_AP: | |
3537 | case NL80211_IFTYPE_AP_VLAN: | |
3538 | case NL80211_IFTYPE_P2P_GO: | |
3539 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3540 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3541 | BIT(NL80211_STA_FLAG_WME) | | |
3542 | BIT(NL80211_STA_FLAG_MFP); | |
3543 | break; | |
3544 | case NL80211_IFTYPE_P2P_CLIENT: | |
3545 | case NL80211_IFTYPE_STATION: | |
3546 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3547 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3548 | break; | |
3549 | case NL80211_IFTYPE_MESH_POINT: | |
3550 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3551 | BIT(NL80211_STA_FLAG_MFP) | | |
3552 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3553 | default: | |
3554 | return -EINVAL; | |
3555 | } | |
5727ef1b | 3556 | |
3383b5a6 JB |
3557 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3558 | if (flags[flag]) { | |
eccb8e8f | 3559 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3560 | |
3383b5a6 JB |
3561 | /* no longer support new API additions in old API */ |
3562 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3563 | return -EINVAL; | |
3564 | } | |
3565 | } | |
3566 | ||
5727ef1b JB |
3567 | return 0; |
3568 | } | |
3569 | ||
c8dcfd8a FF |
3570 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3571 | int attr) | |
3572 | { | |
3573 | struct nlattr *rate; | |
8eb41c8d VK |
3574 | u32 bitrate; |
3575 | u16 bitrate_compat; | |
c8dcfd8a FF |
3576 | |
3577 | rate = nla_nest_start(msg, attr); | |
3578 | if (!rate) | |
db9c64cf | 3579 | return false; |
c8dcfd8a FF |
3580 | |
3581 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3582 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3583 | /* report 16-bit bitrate only if we can */ |
3584 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3585 | if (bitrate > 0 && |
3586 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3587 | return false; | |
3588 | if (bitrate_compat > 0 && | |
3589 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3590 | return false; | |
3591 | ||
3592 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3593 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3594 | return false; | |
3595 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3596 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3597 | return false; | |
3598 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3599 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3600 | return false; | |
3601 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3602 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3603 | return false; | |
3604 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3605 | return false; | |
3606 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3607 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3608 | return false; | |
3609 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3610 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3611 | return false; | |
3612 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3613 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3614 | return false; | |
3615 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3616 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3617 | return false; | |
3618 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3619 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3620 | return false; | |
3621 | } | |
c8dcfd8a FF |
3622 | |
3623 | nla_nest_end(msg, rate); | |
3624 | return true; | |
c8dcfd8a FF |
3625 | } |
3626 | ||
119363c7 FF |
3627 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3628 | int id) | |
3629 | { | |
3630 | void *attr; | |
3631 | int i = 0; | |
3632 | ||
3633 | if (!mask) | |
3634 | return true; | |
3635 | ||
3636 | attr = nla_nest_start(msg, id); | |
3637 | if (!attr) | |
3638 | return false; | |
3639 | ||
3640 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3641 | if (!(mask & BIT(i))) | |
3642 | continue; | |
3643 | ||
3644 | if (nla_put_u8(msg, i, signal[i])) | |
3645 | return false; | |
3646 | } | |
3647 | ||
3648 | nla_nest_end(msg, attr); | |
3649 | ||
3650 | return true; | |
3651 | } | |
3652 | ||
15e47304 | 3653 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3654 | int flags, |
3655 | struct cfg80211_registered_device *rdev, | |
3656 | struct net_device *dev, | |
98b62183 | 3657 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3658 | { |
3659 | void *hdr; | |
f4263c98 | 3660 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3661 | |
15e47304 | 3662 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3663 | if (!hdr) |
3664 | return -1; | |
3665 | ||
9360ffd1 DM |
3666 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3667 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3668 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3669 | goto nla_put_failure; | |
f5ea9120 | 3670 | |
2ec600d6 LCC |
3671 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3672 | if (!sinfoattr) | |
fd5b74dc | 3673 | goto nla_put_failure; |
9360ffd1 DM |
3674 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3675 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3676 | sinfo->connected_time)) | |
3677 | goto nla_put_failure; | |
3678 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3679 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3680 | sinfo->inactive_time)) | |
3681 | goto nla_put_failure; | |
42745e03 VK |
3682 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3683 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3684 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3685 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3686 | goto nla_put_failure; |
42745e03 | 3687 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
4325d724 | 3688 | STATION_INFO_TX_BYTES64)) && |
9360ffd1 | 3689 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3690 | (u32)sinfo->tx_bytes)) |
3691 | goto nla_put_failure; | |
3692 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3693 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3694 | sinfo->rx_bytes)) | |
3695 | goto nla_put_failure; | |
3696 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3697 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3698 | sinfo->tx_bytes)) |
3699 | goto nla_put_failure; | |
3700 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3701 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3702 | goto nla_put_failure; | |
3703 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3704 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3705 | goto nla_put_failure; | |
3706 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3707 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3708 | sinfo->plink_state)) | |
3709 | goto nla_put_failure; | |
66266b3a JL |
3710 | switch (rdev->wiphy.signal_type) { |
3711 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3712 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3713 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3714 | sinfo->signal)) | |
3715 | goto nla_put_failure; | |
3716 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3717 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3718 | sinfo->signal_avg)) | |
3719 | goto nla_put_failure; | |
66266b3a JL |
3720 | break; |
3721 | default: | |
3722 | break; | |
3723 | } | |
119363c7 FF |
3724 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
3725 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3726 | sinfo->chain_signal, | |
3727 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3728 | goto nla_put_failure; | |
3729 | } | |
3730 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { | |
3731 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3732 | sinfo->chain_signal_avg, | |
3733 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3734 | goto nla_put_failure; | |
3735 | } | |
420e7fab | 3736 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3737 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3738 | NL80211_STA_INFO_TX_BITRATE)) | |
3739 | goto nla_put_failure; | |
3740 | } | |
3741 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3742 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3743 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3744 | goto nla_put_failure; |
420e7fab | 3745 | } |
9360ffd1 DM |
3746 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3747 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3748 | sinfo->rx_packets)) | |
3749 | goto nla_put_failure; | |
3750 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3751 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3752 | sinfo->tx_packets)) | |
3753 | goto nla_put_failure; | |
3754 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3755 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3756 | sinfo->tx_retries)) | |
3757 | goto nla_put_failure; | |
3758 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3759 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3760 | sinfo->tx_failed)) | |
3761 | goto nla_put_failure; | |
867d849f AQ |
3762 | if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) && |
3763 | nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT, | |
3764 | sinfo->expected_throughput)) | |
3765 | goto nla_put_failure; | |
9360ffd1 DM |
3766 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
3767 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3768 | sinfo->beacon_loss_count)) | |
3769 | goto nla_put_failure; | |
3b1c5a53 MP |
3770 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3771 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3772 | sinfo->local_pm)) | |
3773 | goto nla_put_failure; | |
3774 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3775 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3776 | sinfo->peer_pm)) | |
3777 | goto nla_put_failure; | |
3778 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3779 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3780 | sinfo->nonpeer_pm)) | |
3781 | goto nla_put_failure; | |
f4263c98 PS |
3782 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3783 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3784 | if (!bss_param) | |
3785 | goto nla_put_failure; | |
3786 | ||
9360ffd1 DM |
3787 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3788 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3789 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3790 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3791 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3792 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3793 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3794 | sinfo->bss_param.dtim_period) || | |
3795 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3796 | sinfo->bss_param.beacon_interval)) | |
3797 | goto nla_put_failure; | |
f4263c98 PS |
3798 | |
3799 | nla_nest_end(msg, bss_param); | |
3800 | } | |
9360ffd1 DM |
3801 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3802 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3803 | sizeof(struct nl80211_sta_flag_update), | |
3804 | &sinfo->sta_flags)) | |
3805 | goto nla_put_failure; | |
7eab0f64 JL |
3806 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3807 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3808 | sinfo->t_offset)) | |
3809 | goto nla_put_failure; | |
2ec600d6 | 3810 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3811 | |
9360ffd1 DM |
3812 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3813 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3814 | sinfo->assoc_req_ies)) | |
3815 | goto nla_put_failure; | |
50d3dfb7 | 3816 | |
fd5b74dc JB |
3817 | return genlmsg_end(msg, hdr); |
3818 | ||
3819 | nla_put_failure: | |
bc3ed28c TG |
3820 | genlmsg_cancel(msg, hdr); |
3821 | return -EMSGSIZE; | |
fd5b74dc JB |
3822 | } |
3823 | ||
2ec600d6 | 3824 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3825 | struct netlink_callback *cb) |
2ec600d6 | 3826 | { |
2ec600d6 | 3827 | struct station_info sinfo; |
1b8ec87a | 3828 | struct cfg80211_registered_device *rdev; |
97990a06 | 3829 | struct wireless_dev *wdev; |
2ec600d6 | 3830 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3831 | int sta_idx = cb->args[2]; |
2ec600d6 | 3832 | int err; |
2ec600d6 | 3833 | |
1b8ec87a | 3834 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
3835 | if (err) |
3836 | return err; | |
bba95fef | 3837 | |
97990a06 JB |
3838 | if (!wdev->netdev) { |
3839 | err = -EINVAL; | |
3840 | goto out_err; | |
3841 | } | |
3842 | ||
1b8ec87a | 3843 | if (!rdev->ops->dump_station) { |
eec60b03 | 3844 | err = -EOPNOTSUPP; |
bba95fef JB |
3845 | goto out_err; |
3846 | } | |
3847 | ||
bba95fef | 3848 | while (1) { |
f612cedf | 3849 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 3850 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
e35e4d28 | 3851 | mac_addr, &sinfo); |
bba95fef JB |
3852 | if (err == -ENOENT) |
3853 | break; | |
3854 | if (err) | |
3b85875a | 3855 | goto out_err; |
bba95fef JB |
3856 | |
3857 | if (nl80211_send_station(skb, | |
15e47304 | 3858 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3859 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 3860 | rdev, wdev->netdev, mac_addr, |
bba95fef JB |
3861 | &sinfo) < 0) |
3862 | goto out; | |
3863 | ||
3864 | sta_idx++; | |
3865 | } | |
3866 | ||
3867 | ||
3868 | out: | |
97990a06 | 3869 | cb->args[2] = sta_idx; |
bba95fef | 3870 | err = skb->len; |
bba95fef | 3871 | out_err: |
1b8ec87a | 3872 | nl80211_finish_wdev_dump(rdev); |
bba95fef JB |
3873 | |
3874 | return err; | |
2ec600d6 | 3875 | } |
fd5b74dc | 3876 | |
5727ef1b JB |
3877 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3878 | { | |
4c476991 JB |
3879 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3880 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3881 | struct station_info sinfo; |
fd5b74dc JB |
3882 | struct sk_buff *msg; |
3883 | u8 *mac_addr = NULL; | |
4c476991 | 3884 | int err; |
fd5b74dc | 3885 | |
2ec600d6 | 3886 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3887 | |
3888 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3889 | return -EINVAL; | |
3890 | ||
3891 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3892 | ||
4c476991 JB |
3893 | if (!rdev->ops->get_station) |
3894 | return -EOPNOTSUPP; | |
3b85875a | 3895 | |
e35e4d28 | 3896 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3897 | if (err) |
4c476991 | 3898 | return err; |
2ec600d6 | 3899 | |
fd2120ca | 3900 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3901 | if (!msg) |
4c476991 | 3902 | return -ENOMEM; |
fd5b74dc | 3903 | |
15e47304 | 3904 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3905 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3906 | nlmsg_free(msg); |
3907 | return -ENOBUFS; | |
3908 | } | |
3b85875a | 3909 | |
4c476991 | 3910 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3911 | } |
3912 | ||
77ee7c89 JB |
3913 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3914 | struct station_parameters *params, | |
3915 | enum cfg80211_station_type statype) | |
3916 | { | |
3917 | if (params->listen_interval != -1) | |
3918 | return -EINVAL; | |
c72e1140 AN |
3919 | if (params->aid && |
3920 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
77ee7c89 JB |
3921 | return -EINVAL; |
3922 | ||
3923 | /* When you run into this, adjust the code below for the new flag */ | |
3924 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3925 | ||
3926 | switch (statype) { | |
eef941e6 TP |
3927 | case CFG80211_STA_MESH_PEER_KERNEL: |
3928 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3929 | /* |
3930 | * No ignoring the TDLS flag here -- the userspace mesh | |
3931 | * code doesn't have the bug of including TDLS in the | |
3932 | * mask everywhere. | |
3933 | */ | |
3934 | if (params->sta_flags_mask & | |
3935 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3936 | BIT(NL80211_STA_FLAG_MFP) | | |
3937 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3938 | return -EINVAL; | |
3939 | break; | |
3940 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3941 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3942 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3943 | return -EINVAL; | |
3944 | /* ignore since it can't change */ | |
3945 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3946 | break; | |
3947 | default: | |
3948 | /* disallow mesh-specific things */ | |
3949 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3950 | return -EINVAL; | |
3951 | if (params->local_pm) | |
3952 | return -EINVAL; | |
3953 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3954 | return -EINVAL; | |
3955 | } | |
3956 | ||
3957 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3958 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3959 | /* TDLS can't be set, ... */ | |
3960 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3961 | return -EINVAL; | |
3962 | /* | |
3963 | * ... but don't bother the driver with it. This works around | |
3964 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3965 | * TLDS_PEER flag in the mask even for AP mode. | |
3966 | */ | |
3967 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3968 | } | |
3969 | ||
3970 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3971 | /* reject other things that can't change */ | |
3972 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3973 | return -EINVAL; | |
3974 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3975 | return -EINVAL; | |
3976 | if (params->supported_rates) | |
3977 | return -EINVAL; | |
3978 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3979 | return -EINVAL; | |
3980 | } | |
3981 | ||
3982 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3983 | if (params->vlan) | |
3984 | return -EINVAL; | |
3985 | } | |
3986 | ||
3987 | switch (statype) { | |
3988 | case CFG80211_STA_AP_MLME_CLIENT: | |
3989 | /* Use this only for authorizing/unauthorizing a station */ | |
3990 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3991 | return -EOPNOTSUPP; | |
3992 | break; | |
3993 | case CFG80211_STA_AP_CLIENT: | |
3994 | /* accept only the listed bits */ | |
3995 | if (params->sta_flags_mask & | |
3996 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3997 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3998 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
3999 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
4000 | BIT(NL80211_STA_FLAG_WME) | | |
4001 | BIT(NL80211_STA_FLAG_MFP))) | |
4002 | return -EINVAL; | |
4003 | ||
4004 | /* but authenticated/associated only if driver handles it */ | |
4005 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4006 | params->sta_flags_mask & | |
4007 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4008 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4009 | return -EINVAL; | |
4010 | break; | |
4011 | case CFG80211_STA_IBSS: | |
4012 | case CFG80211_STA_AP_STA: | |
4013 | /* reject any changes other than AUTHORIZED */ | |
4014 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
4015 | return -EINVAL; | |
4016 | break; | |
4017 | case CFG80211_STA_TDLS_PEER_SETUP: | |
4018 | /* reject any changes other than AUTHORIZED or WME */ | |
4019 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4020 | BIT(NL80211_STA_FLAG_WME))) | |
4021 | return -EINVAL; | |
4022 | /* force (at least) rates when authorizing */ | |
4023 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
4024 | !params->supported_rates) | |
4025 | return -EINVAL; | |
4026 | break; | |
4027 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
4028 | /* reject any changes */ | |
4029 | return -EINVAL; | |
eef941e6 | 4030 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
4031 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
4032 | return -EINVAL; | |
4033 | break; | |
eef941e6 | 4034 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
4035 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
4036 | return -EINVAL; | |
4037 | break; | |
4038 | } | |
4039 | ||
4040 | return 0; | |
4041 | } | |
4042 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
4043 | ||
5727ef1b | 4044 | /* |
c258d2de | 4045 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 4046 | */ |
80b99899 JB |
4047 | static struct net_device *get_vlan(struct genl_info *info, |
4048 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 4049 | { |
463d0183 | 4050 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
4051 | struct net_device *v; |
4052 | int ret; | |
4053 | ||
4054 | if (!vlanattr) | |
4055 | return NULL; | |
4056 | ||
4057 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
4058 | if (!v) | |
4059 | return ERR_PTR(-ENODEV); | |
4060 | ||
4061 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
4062 | ret = -EINVAL; | |
4063 | goto error; | |
5727ef1b | 4064 | } |
80b99899 | 4065 | |
77ee7c89 JB |
4066 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
4067 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4068 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
4069 | ret = -EINVAL; | |
4070 | goto error; | |
4071 | } | |
4072 | ||
80b99899 JB |
4073 | if (!netif_running(v)) { |
4074 | ret = -ENETDOWN; | |
4075 | goto error; | |
4076 | } | |
4077 | ||
4078 | return v; | |
4079 | error: | |
4080 | dev_put(v); | |
4081 | return ERR_PTR(ret); | |
5727ef1b JB |
4082 | } |
4083 | ||
94e860f1 JB |
4084 | static const struct nla_policy |
4085 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
4086 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
4087 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
4088 | }; | |
4089 | ||
ff276691 JB |
4090 | static int nl80211_parse_sta_wme(struct genl_info *info, |
4091 | struct station_parameters *params) | |
df881293 | 4092 | { |
df881293 JM |
4093 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
4094 | struct nlattr *nla; | |
4095 | int err; | |
4096 | ||
df881293 JM |
4097 | /* parse WME attributes if present */ |
4098 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
4099 | return 0; | |
4100 | ||
4101 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
4102 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
4103 | nl80211_sta_wme_policy); | |
4104 | if (err) | |
4105 | return err; | |
4106 | ||
4107 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
4108 | params->uapsd_queues = nla_get_u8( | |
4109 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4110 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
4111 | return -EINVAL; | |
4112 | ||
4113 | if (tb[NL80211_STA_WME_MAX_SP]) | |
4114 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4115 | ||
4116 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
4117 | return -EINVAL; | |
4118 | ||
4119 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
4120 | ||
4121 | return 0; | |
4122 | } | |
4123 | ||
c01fc9ad SD |
4124 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4125 | struct station_parameters *params) | |
4126 | { | |
4127 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4128 | params->supported_channels = | |
4129 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4130 | params->supported_channels_len = | |
4131 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4132 | /* | |
4133 | * Need to include at least one (first channel, number of | |
4134 | * channels) tuple for each subband, and must have proper | |
4135 | * tuples for the rest of the data as well. | |
4136 | */ | |
4137 | if (params->supported_channels_len < 2) | |
4138 | return -EINVAL; | |
4139 | if (params->supported_channels_len % 2) | |
4140 | return -EINVAL; | |
4141 | } | |
4142 | ||
4143 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4144 | params->supported_oper_classes = | |
4145 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4146 | params->supported_oper_classes_len = | |
4147 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4148 | /* | |
4149 | * The value of the Length field of the Supported Operating | |
4150 | * Classes element is between 2 and 253. | |
4151 | */ | |
4152 | if (params->supported_oper_classes_len < 2 || | |
4153 | params->supported_oper_classes_len > 253) | |
4154 | return -EINVAL; | |
4155 | } | |
4156 | return 0; | |
4157 | } | |
4158 | ||
ff276691 JB |
4159 | static int nl80211_set_station_tdls(struct genl_info *info, |
4160 | struct station_parameters *params) | |
4161 | { | |
c01fc9ad | 4162 | int err; |
ff276691 | 4163 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4164 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4165 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4166 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4167 | params->ht_capa = | |
4168 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4169 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4170 | params->vht_capa = | |
4171 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4172 | ||
c01fc9ad SD |
4173 | err = nl80211_parse_sta_channel_info(info, params); |
4174 | if (err) | |
4175 | return err; | |
4176 | ||
ff276691 JB |
4177 | return nl80211_parse_sta_wme(info, params); |
4178 | } | |
4179 | ||
5727ef1b JB |
4180 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4181 | { | |
4c476991 | 4182 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4183 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4184 | struct station_parameters params; |
77ee7c89 JB |
4185 | u8 *mac_addr; |
4186 | int err; | |
5727ef1b JB |
4187 | |
4188 | memset(¶ms, 0, sizeof(params)); | |
4189 | ||
4190 | params.listen_interval = -1; | |
4191 | ||
77ee7c89 JB |
4192 | if (!rdev->ops->change_station) |
4193 | return -EOPNOTSUPP; | |
4194 | ||
5727ef1b JB |
4195 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4196 | return -EINVAL; | |
4197 | ||
4198 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4199 | return -EINVAL; | |
4200 | ||
4201 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4202 | ||
4203 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4204 | params.supported_rates = | |
4205 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4206 | params.supported_rates_len = | |
4207 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4208 | } | |
4209 | ||
9d62a986 JM |
4210 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4211 | params.capability = | |
4212 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4213 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4214 | } | |
4215 | ||
4216 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4217 | params.ext_capab = | |
4218 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4219 | params.ext_capab_len = | |
4220 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4221 | } | |
4222 | ||
df881293 | 4223 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 4224 | return -EINVAL; |
36aedc90 | 4225 | |
bdd3ae3d | 4226 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4227 | return -EINVAL; |
4228 | ||
f8bacc21 | 4229 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4230 | params.plink_action = |
f8bacc21 JB |
4231 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4232 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4233 | return -EINVAL; | |
4234 | } | |
2ec600d6 | 4235 | |
f8bacc21 | 4236 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4237 | params.plink_state = |
f8bacc21 JB |
4238 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4239 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4240 | return -EINVAL; | |
4241 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
4242 | } | |
9c3990aa | 4243 | |
3b1c5a53 MP |
4244 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4245 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4246 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4247 | ||
4248 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4249 | pm > NL80211_MESH_POWER_MAX) | |
4250 | return -EINVAL; | |
4251 | ||
4252 | params.local_pm = pm; | |
4253 | } | |
4254 | ||
77ee7c89 JB |
4255 | /* Include parameters for TDLS peer (will check later) */ |
4256 | err = nl80211_set_station_tdls(info, ¶ms); | |
4257 | if (err) | |
4258 | return err; | |
4259 | ||
4260 | params.vlan = get_vlan(info, rdev); | |
4261 | if (IS_ERR(params.vlan)) | |
4262 | return PTR_ERR(params.vlan); | |
4263 | ||
a97f4424 JB |
4264 | switch (dev->ieee80211_ptr->iftype) { |
4265 | case NL80211_IFTYPE_AP: | |
4266 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4267 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4268 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4269 | case NL80211_IFTYPE_STATION: |
267335d6 | 4270 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4271 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4272 | break; |
4273 | default: | |
77ee7c89 JB |
4274 | err = -EOPNOTSUPP; |
4275 | goto out_put_vlan; | |
034d655e JB |
4276 | } |
4277 | ||
77ee7c89 | 4278 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4279 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4280 | |
77ee7c89 | 4281 | out_put_vlan: |
5727ef1b JB |
4282 | if (params.vlan) |
4283 | dev_put(params.vlan); | |
3b85875a | 4284 | |
5727ef1b JB |
4285 | return err; |
4286 | } | |
4287 | ||
4288 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4289 | { | |
4c476991 | 4290 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4291 | int err; |
4c476991 | 4292 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4293 | struct station_parameters params; |
4294 | u8 *mac_addr = NULL; | |
4295 | ||
4296 | memset(¶ms, 0, sizeof(params)); | |
4297 | ||
984c311b JB |
4298 | if (!rdev->ops->add_station) |
4299 | return -EOPNOTSUPP; | |
4300 | ||
5727ef1b JB |
4301 | if (!info->attrs[NL80211_ATTR_MAC]) |
4302 | return -EINVAL; | |
4303 | ||
5727ef1b JB |
4304 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4305 | return -EINVAL; | |
4306 | ||
4307 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4308 | return -EINVAL; | |
4309 | ||
5e4b6f56 JM |
4310 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4311 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4312 | return -EINVAL; |
4313 | ||
5727ef1b JB |
4314 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4315 | params.supported_rates = | |
4316 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4317 | params.supported_rates_len = | |
4318 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4319 | params.listen_interval = | |
4320 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4321 | |
3d124ea2 | 4322 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4323 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4324 | else |
4325 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4326 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4327 | return -EINVAL; | |
51b50fbe | 4328 | |
9d62a986 JM |
4329 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4330 | params.capability = | |
4331 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4332 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4333 | } | |
4334 | ||
4335 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4336 | params.ext_capab = | |
4337 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4338 | params.ext_capab_len = | |
4339 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4340 | } | |
4341 | ||
36aedc90 JM |
4342 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4343 | params.ht_capa = | |
4344 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4345 | |
f461be3e MP |
4346 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4347 | params.vht_capa = | |
4348 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4349 | ||
60f4a7b1 MK |
4350 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4351 | params.opmode_notif_used = true; | |
4352 | params.opmode_notif = | |
4353 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4354 | } | |
4355 | ||
f8bacc21 | 4356 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4357 | params.plink_action = |
f8bacc21 JB |
4358 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4359 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4360 | return -EINVAL; | |
4361 | } | |
96b78dff | 4362 | |
c01fc9ad SD |
4363 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4364 | if (err) | |
4365 | return err; | |
4366 | ||
ff276691 JB |
4367 | err = nl80211_parse_sta_wme(info, ¶ms); |
4368 | if (err) | |
4369 | return err; | |
bdd90d5e | 4370 | |
bdd3ae3d | 4371 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4372 | return -EINVAL; |
4373 | ||
77ee7c89 JB |
4374 | /* When you run into this, adjust the code below for the new flag */ |
4375 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4376 | ||
bdd90d5e JB |
4377 | switch (dev->ieee80211_ptr->iftype) { |
4378 | case NL80211_IFTYPE_AP: | |
4379 | case NL80211_IFTYPE_AP_VLAN: | |
4380 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4381 | /* ignore WME attributes if iface/sta is not capable */ |
4382 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4383 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4384 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4385 | |
bdd90d5e | 4386 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4387 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4388 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4389 | return -EINVAL; |
bdd90d5e JB |
4390 | /* but don't bother the driver with it */ |
4391 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4392 | |
d582cffb JB |
4393 | /* allow authenticated/associated only if driver handles it */ |
4394 | if (!(rdev->wiphy.features & | |
4395 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4396 | params.sta_flags_mask & | |
4397 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4398 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4399 | return -EINVAL; | |
4400 | ||
bdd90d5e JB |
4401 | /* must be last in here for error handling */ |
4402 | params.vlan = get_vlan(info, rdev); | |
4403 | if (IS_ERR(params.vlan)) | |
4404 | return PTR_ERR(params.vlan); | |
4405 | break; | |
4406 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4407 | /* ignore uAPSD data */ |
4408 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4409 | ||
d582cffb JB |
4410 | /* associated is disallowed */ |
4411 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4412 | return -EINVAL; | |
bdd90d5e | 4413 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4414 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4415 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4416 | return -EINVAL; |
4417 | break; | |
4418 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4419 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4420 | /* ignore uAPSD data */ |
4421 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4422 | ||
77ee7c89 JB |
4423 | /* these are disallowed */ |
4424 | if (params.sta_flags_mask & | |
4425 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4426 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4427 | return -EINVAL; |
bdd90d5e JB |
4428 | /* Only TDLS peers can be added */ |
4429 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4430 | return -EINVAL; | |
4431 | /* Can only add if TDLS ... */ | |
4432 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4433 | return -EOPNOTSUPP; | |
4434 | /* ... with external setup is supported */ | |
4435 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4436 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4437 | /* |
4438 | * Older wpa_supplicant versions always mark the TDLS peer | |
4439 | * as authorized, but it shouldn't yet be. | |
4440 | */ | |
4441 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4442 | break; |
4443 | default: | |
4444 | return -EOPNOTSUPP; | |
c75786c9 EP |
4445 | } |
4446 | ||
bdd90d5e | 4447 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4448 | |
e35e4d28 | 4449 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4450 | |
5727ef1b JB |
4451 | if (params.vlan) |
4452 | dev_put(params.vlan); | |
5727ef1b JB |
4453 | return err; |
4454 | } | |
4455 | ||
4456 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4457 | { | |
4c476991 JB |
4458 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4459 | struct net_device *dev = info->user_ptr[1]; | |
89c771e5 JM |
4460 | struct station_del_parameters params; |
4461 | ||
4462 | memset(¶ms, 0, sizeof(params)); | |
5727ef1b JB |
4463 | |
4464 | if (info->attrs[NL80211_ATTR_MAC]) | |
89c771e5 | 4465 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5727ef1b | 4466 | |
e80cf853 | 4467 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4468 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4469 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4470 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4471 | return -EINVAL; | |
5727ef1b | 4472 | |
4c476991 JB |
4473 | if (!rdev->ops->del_station) |
4474 | return -EOPNOTSUPP; | |
3b85875a | 4475 | |
98856866 JM |
4476 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
4477 | params.subtype = | |
4478 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | |
4479 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | |
4480 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | |
4481 | return -EINVAL; | |
4482 | } else { | |
4483 | /* Default to Deauthentication frame */ | |
4484 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | |
4485 | } | |
4486 | ||
4487 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | |
4488 | params.reason_code = | |
4489 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
4490 | if (params.reason_code == 0) | |
4491 | return -EINVAL; /* 0 is reserved */ | |
4492 | } else { | |
4493 | /* Default to reason code 2 */ | |
4494 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | |
4495 | } | |
4496 | ||
89c771e5 | 4497 | return rdev_del_station(rdev, dev, ¶ms); |
5727ef1b JB |
4498 | } |
4499 | ||
15e47304 | 4500 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4501 | int flags, struct net_device *dev, |
4502 | u8 *dst, u8 *next_hop, | |
4503 | struct mpath_info *pinfo) | |
4504 | { | |
4505 | void *hdr; | |
4506 | struct nlattr *pinfoattr; | |
4507 | ||
1ef4c850 | 4508 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
2ec600d6 LCC |
4509 | if (!hdr) |
4510 | return -1; | |
4511 | ||
9360ffd1 DM |
4512 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4513 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4514 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4515 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4516 | goto nla_put_failure; | |
f5ea9120 | 4517 | |
2ec600d6 LCC |
4518 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4519 | if (!pinfoattr) | |
4520 | goto nla_put_failure; | |
9360ffd1 DM |
4521 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4522 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4523 | pinfo->frame_qlen)) | |
4524 | goto nla_put_failure; | |
4525 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4526 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4527 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4528 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4529 | pinfo->metric)) || | |
4530 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4531 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4532 | pinfo->exptime)) || | |
4533 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4534 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4535 | pinfo->flags)) || | |
4536 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4537 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4538 | pinfo->discovery_timeout)) || | |
4539 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4540 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4541 | pinfo->discovery_retries))) | |
4542 | goto nla_put_failure; | |
2ec600d6 LCC |
4543 | |
4544 | nla_nest_end(msg, pinfoattr); | |
4545 | ||
4546 | return genlmsg_end(msg, hdr); | |
4547 | ||
4548 | nla_put_failure: | |
bc3ed28c TG |
4549 | genlmsg_cancel(msg, hdr); |
4550 | return -EMSGSIZE; | |
2ec600d6 LCC |
4551 | } |
4552 | ||
4553 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4554 | struct netlink_callback *cb) |
2ec600d6 | 4555 | { |
2ec600d6 | 4556 | struct mpath_info pinfo; |
1b8ec87a | 4557 | struct cfg80211_registered_device *rdev; |
97990a06 | 4558 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4559 | u8 dst[ETH_ALEN]; |
4560 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4561 | int path_idx = cb->args[2]; |
2ec600d6 | 4562 | int err; |
2ec600d6 | 4563 | |
1b8ec87a | 4564 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
4565 | if (err) |
4566 | return err; | |
bba95fef | 4567 | |
1b8ec87a | 4568 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 4569 | err = -EOPNOTSUPP; |
bba95fef JB |
4570 | goto out_err; |
4571 | } | |
4572 | ||
97990a06 | 4573 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4574 | err = -EOPNOTSUPP; |
0448b5fc | 4575 | goto out_err; |
eec60b03 JM |
4576 | } |
4577 | ||
bba95fef | 4578 | while (1) { |
1b8ec87a | 4579 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 4580 | next_hop, &pinfo); |
bba95fef | 4581 | if (err == -ENOENT) |
2ec600d6 | 4582 | break; |
bba95fef | 4583 | if (err) |
3b85875a | 4584 | goto out_err; |
2ec600d6 | 4585 | |
15e47304 | 4586 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4587 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4588 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4589 | &pinfo) < 0) |
4590 | goto out; | |
2ec600d6 | 4591 | |
bba95fef | 4592 | path_idx++; |
2ec600d6 | 4593 | } |
2ec600d6 | 4594 | |
2ec600d6 | 4595 | |
bba95fef | 4596 | out: |
97990a06 | 4597 | cb->args[2] = path_idx; |
bba95fef | 4598 | err = skb->len; |
bba95fef | 4599 | out_err: |
1b8ec87a | 4600 | nl80211_finish_wdev_dump(rdev); |
bba95fef | 4601 | return err; |
2ec600d6 LCC |
4602 | } |
4603 | ||
4604 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4605 | { | |
4c476991 | 4606 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4607 | int err; |
4c476991 | 4608 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4609 | struct mpath_info pinfo; |
4610 | struct sk_buff *msg; | |
4611 | u8 *dst = NULL; | |
4612 | u8 next_hop[ETH_ALEN]; | |
4613 | ||
4614 | memset(&pinfo, 0, sizeof(pinfo)); | |
4615 | ||
4616 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4617 | return -EINVAL; | |
4618 | ||
4619 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4620 | ||
4c476991 JB |
4621 | if (!rdev->ops->get_mpath) |
4622 | return -EOPNOTSUPP; | |
2ec600d6 | 4623 | |
4c476991 JB |
4624 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4625 | return -EOPNOTSUPP; | |
eec60b03 | 4626 | |
e35e4d28 | 4627 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4628 | if (err) |
4c476991 | 4629 | return err; |
2ec600d6 | 4630 | |
fd2120ca | 4631 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4632 | if (!msg) |
4c476991 | 4633 | return -ENOMEM; |
2ec600d6 | 4634 | |
15e47304 | 4635 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4636 | dev, dst, next_hop, &pinfo) < 0) { |
4637 | nlmsg_free(msg); | |
4638 | return -ENOBUFS; | |
4639 | } | |
3b85875a | 4640 | |
4c476991 | 4641 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4642 | } |
4643 | ||
4644 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4645 | { | |
4c476991 JB |
4646 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4647 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4648 | u8 *dst = NULL; |
4649 | u8 *next_hop = NULL; | |
4650 | ||
4651 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4652 | return -EINVAL; | |
4653 | ||
4654 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4655 | return -EINVAL; | |
4656 | ||
4657 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4658 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4659 | ||
4c476991 JB |
4660 | if (!rdev->ops->change_mpath) |
4661 | return -EOPNOTSUPP; | |
35a8efe1 | 4662 | |
4c476991 JB |
4663 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4664 | return -EOPNOTSUPP; | |
2ec600d6 | 4665 | |
e35e4d28 | 4666 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4667 | } |
4c476991 | 4668 | |
2ec600d6 LCC |
4669 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4670 | { | |
4c476991 JB |
4671 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4672 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4673 | u8 *dst = NULL; |
4674 | u8 *next_hop = NULL; | |
4675 | ||
4676 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4677 | return -EINVAL; | |
4678 | ||
4679 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4680 | return -EINVAL; | |
4681 | ||
4682 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4683 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4684 | ||
4c476991 JB |
4685 | if (!rdev->ops->add_mpath) |
4686 | return -EOPNOTSUPP; | |
35a8efe1 | 4687 | |
4c476991 JB |
4688 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4689 | return -EOPNOTSUPP; | |
2ec600d6 | 4690 | |
e35e4d28 | 4691 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4692 | } |
4693 | ||
4694 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4695 | { | |
4c476991 JB |
4696 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4697 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4698 | u8 *dst = NULL; |
4699 | ||
4700 | if (info->attrs[NL80211_ATTR_MAC]) | |
4701 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4702 | ||
4c476991 JB |
4703 | if (!rdev->ops->del_mpath) |
4704 | return -EOPNOTSUPP; | |
3b85875a | 4705 | |
e35e4d28 | 4706 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4707 | } |
4708 | ||
66be7d2b HR |
4709 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
4710 | { | |
4711 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4712 | int err; | |
4713 | struct net_device *dev = info->user_ptr[1]; | |
4714 | struct mpath_info pinfo; | |
4715 | struct sk_buff *msg; | |
4716 | u8 *dst = NULL; | |
4717 | u8 mpp[ETH_ALEN]; | |
4718 | ||
4719 | memset(&pinfo, 0, sizeof(pinfo)); | |
4720 | ||
4721 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4722 | return -EINVAL; | |
4723 | ||
4724 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4725 | ||
4726 | if (!rdev->ops->get_mpp) | |
4727 | return -EOPNOTSUPP; | |
4728 | ||
4729 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
4730 | return -EOPNOTSUPP; | |
4731 | ||
4732 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | |
4733 | if (err) | |
4734 | return err; | |
4735 | ||
4736 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4737 | if (!msg) | |
4738 | return -ENOMEM; | |
4739 | ||
4740 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | |
4741 | dev, dst, mpp, &pinfo) < 0) { | |
4742 | nlmsg_free(msg); | |
4743 | return -ENOBUFS; | |
4744 | } | |
4745 | ||
4746 | return genlmsg_reply(msg, info); | |
4747 | } | |
4748 | ||
4749 | static int nl80211_dump_mpp(struct sk_buff *skb, | |
4750 | struct netlink_callback *cb) | |
4751 | { | |
4752 | struct mpath_info pinfo; | |
4753 | struct cfg80211_registered_device *rdev; | |
4754 | struct wireless_dev *wdev; | |
4755 | u8 dst[ETH_ALEN]; | |
4756 | u8 mpp[ETH_ALEN]; | |
4757 | int path_idx = cb->args[2]; | |
4758 | int err; | |
4759 | ||
4760 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | |
4761 | if (err) | |
4762 | return err; | |
4763 | ||
4764 | if (!rdev->ops->dump_mpp) { | |
4765 | err = -EOPNOTSUPP; | |
4766 | goto out_err; | |
4767 | } | |
4768 | ||
4769 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | |
4770 | err = -EOPNOTSUPP; | |
4771 | goto out_err; | |
4772 | } | |
4773 | ||
4774 | while (1) { | |
4775 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | |
4776 | mpp, &pinfo); | |
4777 | if (err == -ENOENT) | |
4778 | break; | |
4779 | if (err) | |
4780 | goto out_err; | |
4781 | ||
4782 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | |
4783 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
4784 | wdev->netdev, dst, mpp, | |
4785 | &pinfo) < 0) | |
4786 | goto out; | |
4787 | ||
4788 | path_idx++; | |
4789 | } | |
4790 | ||
4791 | out: | |
4792 | cb->args[2] = path_idx; | |
4793 | err = skb->len; | |
4794 | out_err: | |
4795 | nl80211_finish_wdev_dump(rdev); | |
4796 | return err; | |
4797 | } | |
4798 | ||
9f1ba906 JM |
4799 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4800 | { | |
4c476991 JB |
4801 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4802 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 4803 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 4804 | struct bss_parameters params; |
c56589ed | 4805 | int err; |
9f1ba906 JM |
4806 | |
4807 | memset(¶ms, 0, sizeof(params)); | |
4808 | /* default to not changing parameters */ | |
4809 | params.use_cts_prot = -1; | |
4810 | params.use_short_preamble = -1; | |
4811 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4812 | params.ap_isolate = -1; |
50b12f59 | 4813 | params.ht_opmode = -1; |
53cabad7 JB |
4814 | params.p2p_ctwindow = -1; |
4815 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4816 | |
4817 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4818 | params.use_cts_prot = | |
4819 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4820 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4821 | params.use_short_preamble = | |
4822 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4823 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4824 | params.use_short_slot_time = | |
4825 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4826 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4827 | params.basic_rates = | |
4828 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4829 | params.basic_rates_len = | |
4830 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4831 | } | |
fd8aaaf3 FF |
4832 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4833 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4834 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4835 | params.ht_opmode = | |
4836 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4837 | |
53cabad7 JB |
4838 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4839 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4840 | return -EINVAL; | |
4841 | params.p2p_ctwindow = | |
4842 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4843 | if (params.p2p_ctwindow < 0) | |
4844 | return -EINVAL; | |
4845 | if (params.p2p_ctwindow != 0 && | |
4846 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4847 | return -EINVAL; | |
4848 | } | |
4849 | ||
4850 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4851 | u8 tmp; | |
4852 | ||
4853 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4854 | return -EINVAL; | |
4855 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4856 | if (tmp > 1) | |
4857 | return -EINVAL; | |
4858 | params.p2p_opp_ps = tmp; | |
4859 | if (params.p2p_opp_ps && | |
4860 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4861 | return -EINVAL; | |
4862 | } | |
4863 | ||
4c476991 JB |
4864 | if (!rdev->ops->change_bss) |
4865 | return -EOPNOTSUPP; | |
9f1ba906 | 4866 | |
074ac8df | 4867 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4868 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4869 | return -EOPNOTSUPP; | |
3b85875a | 4870 | |
c56589ed SW |
4871 | wdev_lock(wdev); |
4872 | err = rdev_change_bss(rdev, dev, ¶ms); | |
4873 | wdev_unlock(wdev); | |
4874 | ||
4875 | return err; | |
9f1ba906 JM |
4876 | } |
4877 | ||
b54452b0 | 4878 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4879 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4880 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4881 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4882 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4883 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4884 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
089027e5 | 4885 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
b2e1b302 LR |
4886 | }; |
4887 | ||
4888 | static int parse_reg_rule(struct nlattr *tb[], | |
4889 | struct ieee80211_reg_rule *reg_rule) | |
4890 | { | |
4891 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4892 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4893 | ||
4894 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4895 | return -EINVAL; | |
4896 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4897 | return -EINVAL; | |
4898 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4899 | return -EINVAL; | |
b0dfd2ea JD |
4900 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
4901 | return -EINVAL; | |
b2e1b302 LR |
4902 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
4903 | return -EINVAL; | |
4904 | ||
4905 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4906 | ||
4907 | freq_range->start_freq_khz = | |
4908 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4909 | freq_range->end_freq_khz = | |
4910 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
b0dfd2ea JD |
4911 | freq_range->max_bandwidth_khz = |
4912 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
b2e1b302 LR |
4913 | |
4914 | power_rule->max_eirp = | |
4915 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4916 | ||
4917 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4918 | power_rule->max_antenna_gain = | |
4919 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4920 | ||
089027e5 JD |
4921 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
4922 | reg_rule->dfs_cac_ms = | |
4923 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
4924 | ||
b2e1b302 LR |
4925 | return 0; |
4926 | } | |
4927 | ||
4928 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4929 | { | |
b2e1b302 | 4930 | char *data = NULL; |
57b5ce07 | 4931 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4932 | |
80778f18 LR |
4933 | /* |
4934 | * You should only get this when cfg80211 hasn't yet initialized | |
4935 | * completely when built-in to the kernel right between the time | |
4936 | * window between nl80211_init() and regulatory_init(), if that is | |
4937 | * even possible. | |
4938 | */ | |
458f4f9e | 4939 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4940 | return -EINPROGRESS; |
80778f18 | 4941 | |
57b5ce07 LR |
4942 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4943 | user_reg_hint_type = | |
4944 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4945 | else | |
4946 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4947 | ||
4948 | switch (user_reg_hint_type) { | |
4949 | case NL80211_USER_REG_HINT_USER: | |
4950 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
4951 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4952 | return -EINVAL; | |
4953 | ||
4954 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4955 | return regulatory_hint_user(data, user_reg_hint_type); | |
4956 | case NL80211_USER_REG_HINT_INDOOR: | |
4957 | return regulatory_hint_indoor_user(); | |
57b5ce07 LR |
4958 | default: |
4959 | return -EINVAL; | |
4960 | } | |
b2e1b302 LR |
4961 | } |
4962 | ||
24bdd9f4 | 4963 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4964 | struct genl_info *info) |
93da9cc1 | 4965 | { |
4c476991 | 4966 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4967 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4968 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4969 | struct mesh_config cur_params; | |
4970 | int err = 0; | |
93da9cc1 | 4971 | void *hdr; |
4972 | struct nlattr *pinfoattr; | |
4973 | struct sk_buff *msg; | |
4974 | ||
29cbe68c JB |
4975 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4976 | return -EOPNOTSUPP; | |
4977 | ||
24bdd9f4 | 4978 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4979 | return -EOPNOTSUPP; |
f3f92586 | 4980 | |
29cbe68c JB |
4981 | wdev_lock(wdev); |
4982 | /* If not connected, get default parameters */ | |
4983 | if (!wdev->mesh_id_len) | |
4984 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4985 | else | |
e35e4d28 | 4986 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4987 | wdev_unlock(wdev); |
4988 | ||
93da9cc1 | 4989 | if (err) |
4c476991 | 4990 | return err; |
93da9cc1 | 4991 | |
4992 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4993 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4994 | if (!msg) |
4995 | return -ENOMEM; | |
15e47304 | 4996 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4997 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4998 | if (!hdr) |
efe1cf0c | 4999 | goto out; |
24bdd9f4 | 5000 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 5001 | if (!pinfoattr) |
5002 | goto nla_put_failure; | |
9360ffd1 DM |
5003 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5004 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
5005 | cur_params.dot11MeshRetryTimeout) || | |
5006 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
5007 | cur_params.dot11MeshConfirmTimeout) || | |
5008 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
5009 | cur_params.dot11MeshHoldingTimeout) || | |
5010 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
5011 | cur_params.dot11MeshMaxPeerLinks) || | |
5012 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
5013 | cur_params.dot11MeshMaxRetries) || | |
5014 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
5015 | cur_params.dot11MeshTTL) || | |
5016 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
5017 | cur_params.element_ttl) || | |
5018 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
5019 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
5020 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5021 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
5022 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5023 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
5024 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
5025 | cur_params.path_refresh_time) || | |
5026 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
5027 | cur_params.min_discovery_timeout) || | |
5028 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
5029 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
5030 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
5031 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
5032 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
5033 | cur_params.dot11MeshHWMPperrMinInterval) || | |
5034 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
5035 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
5036 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5037 | cur_params.dot11MeshHWMPRootMode) || | |
5038 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
5039 | cur_params.dot11MeshHWMPRannInterval) || | |
5040 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
5041 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
5042 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
5043 | cur_params.dot11MeshForwarding) || | |
5044 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
5045 | cur_params.rssi_threshold) || |
5046 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
5047 | cur_params.ht_opmode) || |
5048 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
5049 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
5050 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
5051 | cur_params.dot11MeshHWMProotInterval) || |
5052 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
5053 | cur_params.dot11MeshHWMPconfirmationInterval) || |
5054 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
5055 | cur_params.power_mode) || | |
5056 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
5057 | cur_params.dot11MeshAwakeWindowDuration) || |
5058 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5059 | cur_params.plink_timeout)) | |
9360ffd1 | 5060 | goto nla_put_failure; |
93da9cc1 | 5061 | nla_nest_end(msg, pinfoattr); |
5062 | genlmsg_end(msg, hdr); | |
4c476991 | 5063 | return genlmsg_reply(msg, info); |
93da9cc1 | 5064 | |
3b85875a | 5065 | nla_put_failure: |
93da9cc1 | 5066 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 5067 | out: |
d080e275 | 5068 | nlmsg_free(msg); |
4c476991 | 5069 | return -ENOBUFS; |
93da9cc1 | 5070 | } |
5071 | ||
b54452b0 | 5072 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 5073 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
5074 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
5075 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
5076 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
5077 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
5078 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 5079 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 5080 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 5081 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 5082 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
5083 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
5084 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
5085 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
5086 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 5087 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 5088 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 5089 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 5090 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 5091 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 5092 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
5093 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
5094 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
5095 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
5096 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 5097 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
5098 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
5099 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 5100 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 5101 | }; |
5102 | ||
c80d545d JC |
5103 | static const struct nla_policy |
5104 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 5105 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
5106 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
5107 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 5108 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 5109 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 5110 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 5111 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 5112 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 5113 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
5114 | }; |
5115 | ||
24bdd9f4 | 5116 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
5117 | struct mesh_config *cfg, |
5118 | u32 *mask_out) | |
93da9cc1 | 5119 | { |
93da9cc1 | 5120 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 5121 | u32 mask = 0; |
93da9cc1 | 5122 | |
ea54fba2 MP |
5123 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
5124 | do { \ | |
5125 | if (tb[attr]) { \ | |
5126 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
5127 | return -EINVAL; \ | |
5128 | cfg->param = fn(tb[attr]); \ | |
5129 | mask |= (1 << (attr - 1)); \ | |
5130 | } \ | |
5131 | } while (0) | |
bd90fdcc JB |
5132 | |
5133 | ||
24bdd9f4 | 5134 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 5135 | return -EINVAL; |
5136 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 5137 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 5138 | nl80211_meshconf_params_policy)) |
93da9cc1 | 5139 | return -EINVAL; |
5140 | ||
93da9cc1 | 5141 | /* This makes sure that there aren't more than 32 mesh config |
5142 | * parameters (otherwise our bitfield scheme would not work.) */ | |
5143 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
5144 | ||
5145 | /* Fill in the params struct */ | |
ea54fba2 | 5146 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
5147 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
5148 | nla_get_u16); | |
ea54fba2 | 5149 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
5150 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
5151 | nla_get_u16); | |
ea54fba2 | 5152 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
5153 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
5154 | nla_get_u16); | |
ea54fba2 | 5155 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
5156 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
5157 | nla_get_u16); | |
ea54fba2 | 5158 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
5159 | mask, NL80211_MESHCONF_MAX_RETRIES, |
5160 | nla_get_u8); | |
ea54fba2 | 5161 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 5162 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 5163 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
5164 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
5165 | nla_get_u8); | |
ea54fba2 | 5166 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
5167 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
5168 | nla_get_u8); | |
ea54fba2 MP |
5169 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
5170 | 1, 255, mask, | |
a4f606ea CYY |
5171 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5172 | nla_get_u32); | |
ea54fba2 | 5173 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
5174 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5175 | nla_get_u8); | |
ea54fba2 | 5176 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
5177 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
5178 | nla_get_u32); | |
ea54fba2 | 5179 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
5180 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
5181 | nla_get_u16); | |
ea54fba2 MP |
5182 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
5183 | 1, 65535, mask, | |
a4f606ea CYY |
5184 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
5185 | nla_get_u32); | |
93da9cc1 | 5186 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
5187 | 1, 65535, mask, |
5188 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 5189 | nla_get_u16); |
dca7e943 | 5190 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
5191 | 1, 65535, mask, |
5192 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 5193 | nla_get_u16); |
93da9cc1 | 5194 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5195 | dot11MeshHWMPnetDiameterTraversalTime, |
5196 | 1, 65535, mask, | |
a4f606ea CYY |
5197 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
5198 | nla_get_u16); | |
ea54fba2 MP |
5199 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
5200 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5201 | nla_get_u8); | |
5202 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
5203 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 5204 | nla_get_u16); |
63c5723b | 5205 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5206 | dot11MeshGateAnnouncementProtocol, 0, 1, |
5207 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 5208 | nla_get_u8); |
ea54fba2 | 5209 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
5210 | mask, NL80211_MESHCONF_FORWARDING, |
5211 | nla_get_u8); | |
83374fe9 | 5212 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 5213 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
83374fe9 | 5214 | nla_get_s32); |
ea54fba2 | 5215 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 5216 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
5217 | nla_get_u16); |
5218 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 5219 | 1, 65535, mask, |
ac1073a6 CYY |
5220 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
5221 | nla_get_u32); | |
ea54fba2 | 5222 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 5223 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
5224 | nla_get_u16); |
5225 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
5226 | dot11MeshHWMPconfirmationInterval, |
5227 | 1, 65535, mask, | |
728b19e5 | 5228 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 5229 | nla_get_u16); |
3b1c5a53 MP |
5230 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
5231 | NL80211_MESH_POWER_ACTIVE, | |
5232 | NL80211_MESH_POWER_MAX, | |
5233 | mask, NL80211_MESHCONF_POWER_MODE, | |
5234 | nla_get_u32); | |
5235 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
5236 | 0, 65535, mask, | |
5237 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
8e7c0538 CT |
5238 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
5239 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5240 | nla_get_u32); | |
bd90fdcc JB |
5241 | if (mask_out) |
5242 | *mask_out = mask; | |
c80d545d | 5243 | |
bd90fdcc JB |
5244 | return 0; |
5245 | ||
5246 | #undef FILL_IN_MESH_PARAM_IF_SET | |
5247 | } | |
5248 | ||
c80d545d JC |
5249 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
5250 | struct mesh_setup *setup) | |
5251 | { | |
bb2798d4 | 5252 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
5253 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
5254 | ||
5255 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
5256 | return -EINVAL; | |
5257 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
5258 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
5259 | nl80211_mesh_setup_params_policy)) | |
5260 | return -EINVAL; | |
5261 | ||
d299a1f2 JC |
5262 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
5263 | setup->sync_method = | |
5264 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
5265 | IEEE80211_SYNC_METHOD_VENDOR : | |
5266 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
5267 | ||
c80d545d JC |
5268 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
5269 | setup->path_sel_proto = | |
5270 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5271 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5272 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5273 | ||
5274 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5275 | setup->path_metric = | |
5276 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5277 | IEEE80211_PATH_METRIC_VENDOR : | |
5278 | IEEE80211_PATH_METRIC_AIRTIME; | |
5279 | ||
581a8b0f JC |
5280 | |
5281 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 5282 | struct nlattr *ieattr = |
581a8b0f | 5283 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5284 | if (!is_valid_ie_attr(ieattr)) |
5285 | return -EINVAL; | |
581a8b0f JC |
5286 | setup->ie = nla_data(ieattr); |
5287 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5288 | } |
bb2798d4 TP |
5289 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5290 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5291 | return -EINVAL; | |
5292 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5293 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5294 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5295 | if (setup->is_secure) |
5296 | setup->user_mpm = true; | |
c80d545d | 5297 | |
6e16d90b CT |
5298 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5299 | if (!setup->user_mpm) | |
5300 | return -EINVAL; | |
5301 | setup->auth_id = | |
5302 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5303 | } | |
5304 | ||
c80d545d JC |
5305 | return 0; |
5306 | } | |
5307 | ||
24bdd9f4 | 5308 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5309 | struct genl_info *info) |
bd90fdcc JB |
5310 | { |
5311 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5312 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5313 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5314 | struct mesh_config cfg; |
5315 | u32 mask; | |
5316 | int err; | |
5317 | ||
29cbe68c JB |
5318 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5319 | return -EOPNOTSUPP; | |
5320 | ||
24bdd9f4 | 5321 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5322 | return -EOPNOTSUPP; |
5323 | ||
24bdd9f4 | 5324 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5325 | if (err) |
5326 | return err; | |
5327 | ||
29cbe68c JB |
5328 | wdev_lock(wdev); |
5329 | if (!wdev->mesh_id_len) | |
5330 | err = -ENOLINK; | |
5331 | ||
5332 | if (!err) | |
e35e4d28 | 5333 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5334 | |
5335 | wdev_unlock(wdev); | |
5336 | ||
5337 | return err; | |
93da9cc1 | 5338 | } |
5339 | ||
ad30ca2c AN |
5340 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
5341 | struct sk_buff *msg) | |
f130347c | 5342 | { |
f130347c LR |
5343 | struct nlattr *nl_reg_rules; |
5344 | unsigned int i; | |
f130347c | 5345 | |
458f4f9e JB |
5346 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
5347 | (regdom->dfs_region && | |
5348 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
ad30ca2c | 5349 | goto nla_put_failure; |
458f4f9e | 5350 | |
f130347c LR |
5351 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5352 | if (!nl_reg_rules) | |
ad30ca2c | 5353 | goto nla_put_failure; |
f130347c | 5354 | |
458f4f9e | 5355 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5356 | struct nlattr *nl_reg_rule; |
5357 | const struct ieee80211_reg_rule *reg_rule; | |
5358 | const struct ieee80211_freq_range *freq_range; | |
5359 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 5360 | unsigned int max_bandwidth_khz; |
f130347c | 5361 | |
458f4f9e | 5362 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5363 | freq_range = ®_rule->freq_range; |
5364 | power_rule = ®_rule->power_rule; | |
5365 | ||
5366 | nl_reg_rule = nla_nest_start(msg, i); | |
5367 | if (!nl_reg_rule) | |
ad30ca2c | 5368 | goto nla_put_failure; |
f130347c | 5369 | |
97524820 JD |
5370 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
5371 | if (!max_bandwidth_khz) | |
5372 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
5373 | reg_rule); | |
5374 | ||
9360ffd1 DM |
5375 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5376 | reg_rule->flags) || | |
5377 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5378 | freq_range->start_freq_khz) || | |
5379 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5380 | freq_range->end_freq_khz) || | |
5381 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 5382 | max_bandwidth_khz) || |
9360ffd1 DM |
5383 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
5384 | power_rule->max_antenna_gain) || | |
5385 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
5386 | power_rule->max_eirp) || |
5387 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
5388 | reg_rule->dfs_cac_ms)) | |
ad30ca2c | 5389 | goto nla_put_failure; |
f130347c LR |
5390 | |
5391 | nla_nest_end(msg, nl_reg_rule); | |
5392 | } | |
5393 | ||
5394 | nla_nest_end(msg, nl_reg_rules); | |
ad30ca2c AN |
5395 | return 0; |
5396 | ||
5397 | nla_put_failure: | |
5398 | return -EMSGSIZE; | |
5399 | } | |
5400 | ||
5401 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) | |
5402 | { | |
5403 | const struct ieee80211_regdomain *regdom = NULL; | |
5404 | struct cfg80211_registered_device *rdev; | |
5405 | struct wiphy *wiphy = NULL; | |
5406 | struct sk_buff *msg; | |
5407 | void *hdr; | |
5408 | ||
5409 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5410 | if (!msg) | |
5411 | return -ENOBUFS; | |
5412 | ||
5413 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
5414 | NL80211_CMD_GET_REG); | |
5415 | if (!hdr) | |
5416 | goto put_failure; | |
5417 | ||
5418 | if (info->attrs[NL80211_ATTR_WIPHY]) { | |
1bdd716c AN |
5419 | bool self_managed; |
5420 | ||
ad30ca2c AN |
5421 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
5422 | if (IS_ERR(rdev)) { | |
5423 | nlmsg_free(msg); | |
5424 | return PTR_ERR(rdev); | |
5425 | } | |
5426 | ||
5427 | wiphy = &rdev->wiphy; | |
1bdd716c AN |
5428 | self_managed = wiphy->regulatory_flags & |
5429 | REGULATORY_WIPHY_SELF_MANAGED; | |
ad30ca2c AN |
5430 | regdom = get_wiphy_regdom(wiphy); |
5431 | ||
1bdd716c AN |
5432 | /* a self-managed-reg device must have a private regdom */ |
5433 | if (WARN_ON(!regdom && self_managed)) { | |
5434 | nlmsg_free(msg); | |
5435 | return -EINVAL; | |
5436 | } | |
5437 | ||
ad30ca2c AN |
5438 | if (regdom && |
5439 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5440 | goto nla_put_failure; | |
5441 | } | |
5442 | ||
5443 | if (!wiphy && reg_last_request_cell_base() && | |
5444 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5445 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5446 | goto nla_put_failure; | |
5447 | ||
5448 | rcu_read_lock(); | |
5449 | ||
5450 | if (!regdom) | |
5451 | regdom = rcu_dereference(cfg80211_regdomain); | |
5452 | ||
5453 | if (nl80211_put_regdom(regdom, msg)) | |
5454 | goto nla_put_failure_rcu; | |
5455 | ||
5456 | rcu_read_unlock(); | |
f130347c LR |
5457 | |
5458 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5459 | return genlmsg_reply(msg, info); |
f130347c | 5460 | |
458f4f9e JB |
5461 | nla_put_failure_rcu: |
5462 | rcu_read_unlock(); | |
f130347c LR |
5463 | nla_put_failure: |
5464 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5465 | put_failure: |
d080e275 | 5466 | nlmsg_free(msg); |
5fe231e8 | 5467 | return -EMSGSIZE; |
f130347c LR |
5468 | } |
5469 | ||
ad30ca2c AN |
5470 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
5471 | u32 seq, int flags, struct wiphy *wiphy, | |
5472 | const struct ieee80211_regdomain *regdom) | |
5473 | { | |
5474 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | |
5475 | NL80211_CMD_GET_REG); | |
5476 | ||
5477 | if (!hdr) | |
5478 | return -1; | |
5479 | ||
5480 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); | |
5481 | ||
5482 | if (nl80211_put_regdom(regdom, msg)) | |
5483 | goto nla_put_failure; | |
5484 | ||
5485 | if (!wiphy && reg_last_request_cell_base() && | |
5486 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5487 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5488 | goto nla_put_failure; | |
5489 | ||
5490 | if (wiphy && | |
5491 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5492 | goto nla_put_failure; | |
5493 | ||
1bdd716c AN |
5494 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
5495 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
5496 | goto nla_put_failure; | |
5497 | ||
ad30ca2c AN |
5498 | return genlmsg_end(msg, hdr); |
5499 | ||
5500 | nla_put_failure: | |
5501 | genlmsg_cancel(msg, hdr); | |
5502 | return -EMSGSIZE; | |
5503 | } | |
5504 | ||
5505 | static int nl80211_get_reg_dump(struct sk_buff *skb, | |
5506 | struct netlink_callback *cb) | |
5507 | { | |
5508 | const struct ieee80211_regdomain *regdom = NULL; | |
5509 | struct cfg80211_registered_device *rdev; | |
5510 | int err, reg_idx, start = cb->args[2]; | |
5511 | ||
5512 | rtnl_lock(); | |
5513 | ||
5514 | if (cfg80211_regdomain && start == 0) { | |
5515 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5516 | NLM_F_MULTI, NULL, | |
5517 | rtnl_dereference(cfg80211_regdomain)); | |
5518 | if (err < 0) | |
5519 | goto out_err; | |
5520 | } | |
5521 | ||
5522 | /* the global regdom is idx 0 */ | |
5523 | reg_idx = 1; | |
5524 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | |
5525 | regdom = get_wiphy_regdom(&rdev->wiphy); | |
5526 | if (!regdom) | |
5527 | continue; | |
5528 | ||
5529 | if (++reg_idx <= start) | |
5530 | continue; | |
5531 | ||
5532 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5533 | NLM_F_MULTI, &rdev->wiphy, regdom); | |
5534 | if (err < 0) { | |
5535 | reg_idx--; | |
5536 | break; | |
5537 | } | |
5538 | } | |
5539 | ||
5540 | cb->args[2] = reg_idx; | |
5541 | err = skb->len; | |
5542 | out_err: | |
5543 | rtnl_unlock(); | |
5544 | return err; | |
5545 | } | |
5546 | ||
b2e1b302 LR |
5547 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5548 | { | |
5549 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5550 | struct nlattr *nl_reg_rule; | |
ea372c54 JB |
5551 | char *alpha2; |
5552 | int rem_reg_rules, r; | |
b2e1b302 | 5553 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
4c7d3982 | 5554 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
ea372c54 | 5555 | struct ieee80211_regdomain *rd; |
b2e1b302 LR |
5556 | |
5557 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5558 | return -EINVAL; | |
5559 | ||
5560 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5561 | return -EINVAL; | |
5562 | ||
5563 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5564 | ||
8b60b078 LR |
5565 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5566 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5567 | ||
b2e1b302 | 5568 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5569 | rem_reg_rules) { |
b2e1b302 LR |
5570 | num_rules++; |
5571 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5572 | return -EINVAL; |
b2e1b302 LR |
5573 | } |
5574 | ||
e438768f LR |
5575 | if (!reg_is_valid_request(alpha2)) |
5576 | return -EINVAL; | |
5577 | ||
b2e1b302 | 5578 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5579 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5580 | |
5581 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5582 | if (!rd) |
5583 | return -ENOMEM; | |
b2e1b302 LR |
5584 | |
5585 | rd->n_reg_rules = num_rules; | |
5586 | rd->alpha2[0] = alpha2[0]; | |
5587 | rd->alpha2[1] = alpha2[1]; | |
5588 | ||
8b60b078 LR |
5589 | /* |
5590 | * Disable DFS master mode if the DFS region was | |
5591 | * not supported or known on this kernel. | |
5592 | */ | |
5593 | if (reg_supported_dfs_region(dfs_region)) | |
5594 | rd->dfs_region = dfs_region; | |
5595 | ||
b2e1b302 | 5596 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5597 | rem_reg_rules) { |
ae811e21 JB |
5598 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
5599 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
5600 | reg_rule_policy); | |
5601 | if (r) | |
5602 | goto bad_reg; | |
b2e1b302 LR |
5603 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5604 | if (r) | |
5605 | goto bad_reg; | |
5606 | ||
5607 | rule_idx++; | |
5608 | ||
d0e18f83 LR |
5609 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5610 | r = -EINVAL; | |
b2e1b302 | 5611 | goto bad_reg; |
d0e18f83 | 5612 | } |
b2e1b302 LR |
5613 | } |
5614 | ||
b2e1b302 | 5615 | r = set_regdom(rd); |
6913b49a | 5616 | /* set_regdom took ownership */ |
1a919318 | 5617 | rd = NULL; |
b2e1b302 | 5618 | |
d2372b31 | 5619 | bad_reg: |
b2e1b302 | 5620 | kfree(rd); |
d0e18f83 | 5621 | return r; |
b2e1b302 LR |
5622 | } |
5623 | ||
83f5e2cf JB |
5624 | static int validate_scan_freqs(struct nlattr *freqs) |
5625 | { | |
5626 | struct nlattr *attr1, *attr2; | |
5627 | int n_channels = 0, tmp1, tmp2; | |
5628 | ||
5629 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5630 | n_channels++; | |
5631 | /* | |
5632 | * Some hardware has a limited channel list for | |
5633 | * scanning, and it is pretty much nonsensical | |
5634 | * to scan for a channel twice, so disallow that | |
5635 | * and don't require drivers to check that the | |
5636 | * channel list they get isn't longer than what | |
5637 | * they can scan, as long as they can scan all | |
5638 | * the channels they registered at once. | |
5639 | */ | |
5640 | nla_for_each_nested(attr2, freqs, tmp2) | |
5641 | if (attr1 != attr2 && | |
5642 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5643 | return 0; | |
5644 | } | |
5645 | ||
5646 | return n_channels; | |
5647 | } | |
5648 | ||
ad2b26ab JB |
5649 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
5650 | u8 *mac_addr, u8 *mac_addr_mask) | |
5651 | { | |
5652 | int i; | |
5653 | ||
5654 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { | |
5655 | memset(mac_addr, 0, ETH_ALEN); | |
5656 | memset(mac_addr_mask, 0, ETH_ALEN); | |
5657 | mac_addr[0] = 0x2; | |
5658 | mac_addr_mask[0] = 0x3; | |
5659 | ||
5660 | return 0; | |
5661 | } | |
5662 | ||
5663 | /* need both or none */ | |
5664 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) | |
5665 | return -EINVAL; | |
5666 | ||
5667 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); | |
5668 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); | |
5669 | ||
5670 | /* don't allow or configure an mcast address */ | |
5671 | if (!is_multicast_ether_addr(mac_addr_mask) || | |
5672 | is_multicast_ether_addr(mac_addr)) | |
5673 | return -EINVAL; | |
5674 | ||
5675 | /* | |
5676 | * allow users to pass a MAC address that has bits set outside | |
5677 | * of the mask, but don't bother drivers with having to deal | |
5678 | * with such bits | |
5679 | */ | |
5680 | for (i = 0; i < ETH_ALEN; i++) | |
5681 | mac_addr[i] &= mac_addr_mask[i]; | |
5682 | ||
5683 | return 0; | |
5684 | } | |
5685 | ||
2a519311 JB |
5686 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5687 | { | |
4c476991 | 5688 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5689 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5690 | struct cfg80211_scan_request *request; |
2a519311 JB |
5691 | struct nlattr *attr; |
5692 | struct wiphy *wiphy; | |
83f5e2cf | 5693 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5694 | size_t ie_len; |
2a519311 | 5695 | |
f4a11bb0 JB |
5696 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5697 | return -EINVAL; | |
5698 | ||
79c97e97 | 5699 | wiphy = &rdev->wiphy; |
2a519311 | 5700 | |
4c476991 JB |
5701 | if (!rdev->ops->scan) |
5702 | return -EOPNOTSUPP; | |
2a519311 | 5703 | |
f9d15d16 | 5704 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
5705 | err = -EBUSY; |
5706 | goto unlock; | |
5707 | } | |
2a519311 JB |
5708 | |
5709 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5710 | n_channels = validate_scan_freqs( |
5711 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5712 | if (!n_channels) { |
5713 | err = -EINVAL; | |
5714 | goto unlock; | |
5715 | } | |
2a519311 | 5716 | } else { |
bdfbec2d | 5717 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
5718 | } |
5719 | ||
5720 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5721 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5722 | n_ssids++; | |
5723 | ||
f9f47529 JB |
5724 | if (n_ssids > wiphy->max_scan_ssids) { |
5725 | err = -EINVAL; | |
5726 | goto unlock; | |
5727 | } | |
2a519311 | 5728 | |
70692ad2 JM |
5729 | if (info->attrs[NL80211_ATTR_IE]) |
5730 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5731 | else | |
5732 | ie_len = 0; | |
5733 | ||
f9f47529 JB |
5734 | if (ie_len > wiphy->max_scan_ie_len) { |
5735 | err = -EINVAL; | |
5736 | goto unlock; | |
5737 | } | |
18a83659 | 5738 | |
2a519311 | 5739 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5740 | + sizeof(*request->ssids) * n_ssids |
5741 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5742 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5743 | if (!request) { |
5744 | err = -ENOMEM; | |
5745 | goto unlock; | |
5746 | } | |
2a519311 | 5747 | |
2a519311 | 5748 | if (n_ssids) |
5ba63533 | 5749 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5750 | request->n_ssids = n_ssids; |
70692ad2 JM |
5751 | if (ie_len) { |
5752 | if (request->ssids) | |
5753 | request->ie = (void *)(request->ssids + n_ssids); | |
5754 | else | |
5755 | request->ie = (void *)(request->channels + n_channels); | |
5756 | } | |
2a519311 | 5757 | |
584991dc | 5758 | i = 0; |
2a519311 JB |
5759 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5760 | /* user specified, bail out if channel not found */ | |
2a519311 | 5761 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5762 | struct ieee80211_channel *chan; |
5763 | ||
5764 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5765 | ||
5766 | if (!chan) { | |
2a519311 JB |
5767 | err = -EINVAL; |
5768 | goto out_free; | |
5769 | } | |
584991dc JB |
5770 | |
5771 | /* ignore disabled channels */ | |
5772 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5773 | continue; | |
5774 | ||
5775 | request->channels[i] = chan; | |
2a519311 JB |
5776 | i++; |
5777 | } | |
5778 | } else { | |
34850ab2 JB |
5779 | enum ieee80211_band band; |
5780 | ||
2a519311 | 5781 | /* all channels */ |
2a519311 JB |
5782 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5783 | int j; | |
5784 | if (!wiphy->bands[band]) | |
5785 | continue; | |
5786 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5787 | struct ieee80211_channel *chan; |
5788 | ||
5789 | chan = &wiphy->bands[band]->channels[j]; | |
5790 | ||
5791 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5792 | continue; | |
5793 | ||
5794 | request->channels[i] = chan; | |
2a519311 JB |
5795 | i++; |
5796 | } | |
5797 | } | |
5798 | } | |
5799 | ||
584991dc JB |
5800 | if (!i) { |
5801 | err = -EINVAL; | |
5802 | goto out_free; | |
5803 | } | |
5804 | ||
5805 | request->n_channels = i; | |
5806 | ||
2a519311 JB |
5807 | i = 0; |
5808 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5809 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5810 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5811 | err = -EINVAL; |
5812 | goto out_free; | |
5813 | } | |
57a27e1d | 5814 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5815 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5816 | i++; |
5817 | } | |
5818 | } | |
5819 | ||
70692ad2 JM |
5820 | if (info->attrs[NL80211_ATTR_IE]) { |
5821 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5822 | memcpy((void *)request->ie, |
5823 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5824 | request->ie_len); |
5825 | } | |
5826 | ||
34850ab2 | 5827 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5828 | if (wiphy->bands[i]) |
5829 | request->rates[i] = | |
5830 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5831 | |
5832 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5833 | nla_for_each_nested(attr, | |
5834 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5835 | tmp) { | |
5836 | enum ieee80211_band band = nla_type(attr); | |
5837 | ||
84404623 | 5838 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5839 | err = -EINVAL; |
5840 | goto out_free; | |
5841 | } | |
1b09cd82 FF |
5842 | |
5843 | if (!wiphy->bands[band]) | |
5844 | continue; | |
5845 | ||
34850ab2 JB |
5846 | err = ieee80211_get_ratemask(wiphy->bands[band], |
5847 | nla_data(attr), | |
5848 | nla_len(attr), | |
5849 | &request->rates[band]); | |
5850 | if (err) | |
5851 | goto out_free; | |
5852 | } | |
5853 | } | |
5854 | ||
46856bbf | 5855 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5856 | request->flags = nla_get_u32( |
5857 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5858 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5859 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5860 | err = -EOPNOTSUPP; |
5861 | goto out_free; | |
5862 | } | |
ad2b26ab JB |
5863 | |
5864 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
5865 | if (!(wiphy->features & | |
5866 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { | |
5867 | err = -EOPNOTSUPP; | |
5868 | goto out_free; | |
5869 | } | |
5870 | ||
5871 | if (wdev->current_bss) { | |
5872 | err = -EOPNOTSUPP; | |
5873 | goto out_free; | |
5874 | } | |
5875 | ||
5876 | err = nl80211_parse_random_mac(info->attrs, | |
5877 | request->mac_addr, | |
5878 | request->mac_addr_mask); | |
5879 | if (err) | |
5880 | goto out_free; | |
5881 | } | |
46856bbf | 5882 | } |
ed473771 | 5883 | |
e9f935e3 RM |
5884 | request->no_cck = |
5885 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5886 | ||
fd014284 | 5887 | request->wdev = wdev; |
79c97e97 | 5888 | request->wiphy = &rdev->wiphy; |
15d6030b | 5889 | request->scan_start = jiffies; |
2a519311 | 5890 | |
79c97e97 | 5891 | rdev->scan_req = request; |
e35e4d28 | 5892 | err = rdev_scan(rdev, request); |
2a519311 | 5893 | |
463d0183 | 5894 | if (!err) { |
fd014284 JB |
5895 | nl80211_send_scan_start(rdev, wdev); |
5896 | if (wdev->netdev) | |
5897 | dev_hold(wdev->netdev); | |
4c476991 | 5898 | } else { |
2a519311 | 5899 | out_free: |
79c97e97 | 5900 | rdev->scan_req = NULL; |
2a519311 JB |
5901 | kfree(request); |
5902 | } | |
3b85875a | 5903 | |
f9f47529 | 5904 | unlock: |
2a519311 JB |
5905 | return err; |
5906 | } | |
5907 | ||
256da02d | 5908 | static struct cfg80211_sched_scan_request * |
ad2b26ab | 5909 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
256da02d | 5910 | struct nlattr **attrs) |
807f8a8c LC |
5911 | { |
5912 | struct cfg80211_sched_scan_request *request; | |
807f8a8c | 5913 | struct nlattr *attr; |
a1f1c21c | 5914 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5915 | u32 interval; |
807f8a8c LC |
5916 | enum ieee80211_band band; |
5917 | size_t ie_len; | |
a1f1c21c | 5918 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 5919 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c | 5920 | |
256da02d LC |
5921 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
5922 | return ERR_PTR(-EINVAL); | |
807f8a8c | 5923 | |
256da02d LC |
5924 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5925 | return ERR_PTR(-EINVAL); | |
bbe6ad6d | 5926 | |
256da02d | 5927 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
bbe6ad6d | 5928 | if (interval == 0) |
256da02d | 5929 | return ERR_PTR(-EINVAL); |
807f8a8c | 5930 | |
256da02d | 5931 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c | 5932 | n_channels = validate_scan_freqs( |
256da02d | 5933 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
807f8a8c | 5934 | if (!n_channels) |
256da02d | 5935 | return ERR_PTR(-EINVAL); |
807f8a8c | 5936 | } else { |
bdfbec2d | 5937 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
5938 | } |
5939 | ||
256da02d LC |
5940 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
5941 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c LC |
5942 | tmp) |
5943 | n_ssids++; | |
5944 | ||
93b6aa69 | 5945 | if (n_ssids > wiphy->max_sched_scan_ssids) |
256da02d | 5946 | return ERR_PTR(-EINVAL); |
807f8a8c | 5947 | |
ea73cbce JB |
5948 | /* |
5949 | * First, count the number of 'real' matchsets. Due to an issue with | |
5950 | * the old implementation, matchsets containing only the RSSI attribute | |
5951 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
5952 | * RSSI for all matchsets, rather than their own matchset for reporting | |
5953 | * all APs with a strong RSSI. This is needed to be compatible with | |
5954 | * older userspace that treated a matchset with only the RSSI as the | |
5955 | * global RSSI for all other matchsets - if there are other matchsets. | |
5956 | */ | |
256da02d | 5957 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 5958 | nla_for_each_nested(attr, |
256da02d | 5959 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
ea73cbce JB |
5960 | tmp) { |
5961 | struct nlattr *rssi; | |
5962 | ||
5963 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5964 | nla_data(attr), nla_len(attr), | |
5965 | nl80211_match_policy); | |
5966 | if (err) | |
256da02d | 5967 | return ERR_PTR(err); |
ea73cbce JB |
5968 | /* add other standalone attributes here */ |
5969 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | |
5970 | n_match_sets++; | |
5971 | continue; | |
5972 | } | |
5973 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
5974 | if (rssi) | |
5975 | default_match_rssi = nla_get_s32(rssi); | |
5976 | } | |
5977 | } | |
5978 | ||
5979 | /* However, if there's no other matchset, add the RSSI one */ | |
5980 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
5981 | n_match_sets = 1; | |
a1f1c21c LC |
5982 | |
5983 | if (n_match_sets > wiphy->max_match_sets) | |
256da02d | 5984 | return ERR_PTR(-EINVAL); |
a1f1c21c | 5985 | |
256da02d LC |
5986 | if (attrs[NL80211_ATTR_IE]) |
5987 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); | |
807f8a8c LC |
5988 | else |
5989 | ie_len = 0; | |
5990 | ||
5a865bad | 5991 | if (ie_len > wiphy->max_sched_scan_ie_len) |
256da02d | 5992 | return ERR_PTR(-EINVAL); |
c10841ca | 5993 | |
807f8a8c | 5994 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 5995 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 5996 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 5997 | + sizeof(*request->channels) * n_channels |
807f8a8c | 5998 | + ie_len, GFP_KERNEL); |
256da02d LC |
5999 | if (!request) |
6000 | return ERR_PTR(-ENOMEM); | |
807f8a8c LC |
6001 | |
6002 | if (n_ssids) | |
6003 | request->ssids = (void *)&request->channels[n_channels]; | |
6004 | request->n_ssids = n_ssids; | |
6005 | if (ie_len) { | |
6006 | if (request->ssids) | |
6007 | request->ie = (void *)(request->ssids + n_ssids); | |
6008 | else | |
6009 | request->ie = (void *)(request->channels + n_channels); | |
6010 | } | |
6011 | ||
a1f1c21c LC |
6012 | if (n_match_sets) { |
6013 | if (request->ie) | |
6014 | request->match_sets = (void *)(request->ie + ie_len); | |
6015 | else if (request->ssids) | |
6016 | request->match_sets = | |
6017 | (void *)(request->ssids + n_ssids); | |
6018 | else | |
6019 | request->match_sets = | |
6020 | (void *)(request->channels + n_channels); | |
6021 | } | |
6022 | request->n_match_sets = n_match_sets; | |
6023 | ||
807f8a8c | 6024 | i = 0; |
256da02d | 6025 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c LC |
6026 | /* user specified, bail out if channel not found */ |
6027 | nla_for_each_nested(attr, | |
256da02d | 6028 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
807f8a8c LC |
6029 | tmp) { |
6030 | struct ieee80211_channel *chan; | |
6031 | ||
6032 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
6033 | ||
6034 | if (!chan) { | |
6035 | err = -EINVAL; | |
6036 | goto out_free; | |
6037 | } | |
6038 | ||
6039 | /* ignore disabled channels */ | |
6040 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6041 | continue; | |
6042 | ||
6043 | request->channels[i] = chan; | |
6044 | i++; | |
6045 | } | |
6046 | } else { | |
6047 | /* all channels */ | |
6048 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6049 | int j; | |
6050 | if (!wiphy->bands[band]) | |
6051 | continue; | |
6052 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
6053 | struct ieee80211_channel *chan; | |
6054 | ||
6055 | chan = &wiphy->bands[band]->channels[j]; | |
6056 | ||
6057 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6058 | continue; | |
6059 | ||
6060 | request->channels[i] = chan; | |
6061 | i++; | |
6062 | } | |
6063 | } | |
6064 | } | |
6065 | ||
6066 | if (!i) { | |
6067 | err = -EINVAL; | |
6068 | goto out_free; | |
6069 | } | |
6070 | ||
6071 | request->n_channels = i; | |
6072 | ||
6073 | i = 0; | |
256da02d LC |
6074 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) { |
6075 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c | 6076 | tmp) { |
57a27e1d | 6077 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
6078 | err = -EINVAL; |
6079 | goto out_free; | |
6080 | } | |
57a27e1d | 6081 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
6082 | memcpy(request->ssids[i].ssid, nla_data(attr), |
6083 | nla_len(attr)); | |
807f8a8c LC |
6084 | i++; |
6085 | } | |
6086 | } | |
6087 | ||
a1f1c21c | 6088 | i = 0; |
256da02d | 6089 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 6090 | nla_for_each_nested(attr, |
256da02d | 6091 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
a1f1c21c | 6092 | tmp) { |
88e920b4 | 6093 | struct nlattr *ssid, *rssi; |
a1f1c21c | 6094 | |
ae811e21 JB |
6095 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
6096 | nla_data(attr), nla_len(attr), | |
6097 | nl80211_match_policy); | |
6098 | if (err) | |
6099 | goto out_free; | |
4a4ab0d7 | 6100 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 6101 | if (ssid) { |
ea73cbce JB |
6102 | if (WARN_ON(i >= n_match_sets)) { |
6103 | /* this indicates a programming error, | |
6104 | * the loop above should have verified | |
6105 | * things properly | |
6106 | */ | |
6107 | err = -EINVAL; | |
6108 | goto out_free; | |
6109 | } | |
6110 | ||
a1f1c21c LC |
6111 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
6112 | err = -EINVAL; | |
6113 | goto out_free; | |
6114 | } | |
6115 | memcpy(request->match_sets[i].ssid.ssid, | |
6116 | nla_data(ssid), nla_len(ssid)); | |
6117 | request->match_sets[i].ssid.ssid_len = | |
6118 | nla_len(ssid); | |
ea73cbce JB |
6119 | /* special attribute - old implemenation w/a */ |
6120 | request->match_sets[i].rssi_thold = | |
6121 | default_match_rssi; | |
6122 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6123 | if (rssi) | |
6124 | request->match_sets[i].rssi_thold = | |
6125 | nla_get_s32(rssi); | |
a1f1c21c LC |
6126 | } |
6127 | i++; | |
6128 | } | |
ea73cbce JB |
6129 | |
6130 | /* there was no other matchset, so the RSSI one is alone */ | |
6131 | if (i == 0) | |
6132 | request->match_sets[0].rssi_thold = default_match_rssi; | |
6133 | ||
6134 | request->min_rssi_thold = INT_MAX; | |
6135 | for (i = 0; i < n_match_sets; i++) | |
6136 | request->min_rssi_thold = | |
6137 | min(request->match_sets[i].rssi_thold, | |
6138 | request->min_rssi_thold); | |
6139 | } else { | |
6140 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
6141 | } |
6142 | ||
9900e484 JB |
6143 | if (ie_len) { |
6144 | request->ie_len = ie_len; | |
807f8a8c | 6145 | memcpy((void *)request->ie, |
256da02d | 6146 | nla_data(attrs[NL80211_ATTR_IE]), |
807f8a8c LC |
6147 | request->ie_len); |
6148 | } | |
6149 | ||
256da02d | 6150 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 | 6151 | request->flags = nla_get_u32( |
256da02d | 6152 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
00c3a6ed JB |
6153 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
6154 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
6155 | err = -EOPNOTSUPP; |
6156 | goto out_free; | |
6157 | } | |
ad2b26ab JB |
6158 | |
6159 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
6160 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; | |
6161 | ||
6162 | if (!wdev) /* must be net-detect */ | |
6163 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
6164 | ||
6165 | if (!(wiphy->features & flg)) { | |
6166 | err = -EOPNOTSUPP; | |
6167 | goto out_free; | |
6168 | } | |
6169 | ||
6170 | if (wdev && wdev->current_bss) { | |
6171 | err = -EOPNOTSUPP; | |
6172 | goto out_free; | |
6173 | } | |
6174 | ||
6175 | err = nl80211_parse_random_mac(attrs, request->mac_addr, | |
6176 | request->mac_addr_mask); | |
6177 | if (err) | |
6178 | goto out_free; | |
6179 | } | |
46856bbf | 6180 | } |
ed473771 | 6181 | |
bbe6ad6d | 6182 | request->interval = interval; |
15d6030b | 6183 | request->scan_start = jiffies; |
807f8a8c | 6184 | |
256da02d | 6185 | return request; |
807f8a8c LC |
6186 | |
6187 | out_free: | |
6188 | kfree(request); | |
256da02d LC |
6189 | return ERR_PTR(err); |
6190 | } | |
6191 | ||
6192 | static int nl80211_start_sched_scan(struct sk_buff *skb, | |
6193 | struct genl_info *info) | |
6194 | { | |
6195 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6196 | struct net_device *dev = info->user_ptr[1]; | |
ad2b26ab | 6197 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
31a60ed1 | 6198 | struct cfg80211_sched_scan_request *sched_scan_req; |
256da02d LC |
6199 | int err; |
6200 | ||
6201 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6202 | !rdev->ops->sched_scan_start) | |
6203 | return -EOPNOTSUPP; | |
6204 | ||
6205 | if (rdev->sched_scan_req) | |
6206 | return -EINPROGRESS; | |
6207 | ||
31a60ed1 JR |
6208 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
6209 | info->attrs); | |
6210 | ||
6211 | err = PTR_ERR_OR_ZERO(sched_scan_req); | |
256da02d LC |
6212 | if (err) |
6213 | goto out_err; | |
6214 | ||
31a60ed1 | 6215 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
256da02d LC |
6216 | if (err) |
6217 | goto out_free; | |
6218 | ||
31a60ed1 JR |
6219 | sched_scan_req->dev = dev; |
6220 | sched_scan_req->wiphy = &rdev->wiphy; | |
6221 | ||
93a1e86c JR |
6222 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
6223 | sched_scan_req->owner_nlportid = info->snd_portid; | |
6224 | ||
31a60ed1 | 6225 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
256da02d LC |
6226 | |
6227 | nl80211_send_sched_scan(rdev, dev, | |
6228 | NL80211_CMD_START_SCHED_SCAN); | |
6229 | return 0; | |
6230 | ||
6231 | out_free: | |
31a60ed1 | 6232 | kfree(sched_scan_req); |
256da02d | 6233 | out_err: |
807f8a8c LC |
6234 | return err; |
6235 | } | |
6236 | ||
6237 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
6238 | struct genl_info *info) | |
6239 | { | |
6240 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6241 | ||
6242 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6243 | !rdev->ops->sched_scan_stop) | |
6244 | return -EOPNOTSUPP; | |
6245 | ||
5fe231e8 | 6246 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
6247 | } |
6248 | ||
04f39047 SW |
6249 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
6250 | struct genl_info *info) | |
6251 | { | |
6252 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6253 | struct net_device *dev = info->user_ptr[1]; | |
6254 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6255 | struct cfg80211_chan_def chandef; | |
55f7435c | 6256 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 6257 | unsigned int cac_time_ms; |
04f39047 SW |
6258 | int err; |
6259 | ||
55f7435c LR |
6260 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
6261 | if (dfs_region == NL80211_DFS_UNSET) | |
6262 | return -EINVAL; | |
6263 | ||
04f39047 SW |
6264 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6265 | if (err) | |
6266 | return err; | |
6267 | ||
ff311bc1 SW |
6268 | if (netif_carrier_ok(dev)) |
6269 | return -EBUSY; | |
6270 | ||
04f39047 SW |
6271 | if (wdev->cac_started) |
6272 | return -EBUSY; | |
6273 | ||
2beb6dab | 6274 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
00ec75fc | 6275 | wdev->iftype); |
04f39047 SW |
6276 | if (err < 0) |
6277 | return err; | |
6278 | ||
6279 | if (err == 0) | |
6280 | return -EINVAL; | |
6281 | ||
fe7c3a1f | 6282 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
6283 | return -EINVAL; |
6284 | ||
6285 | if (!rdev->ops->start_radar_detection) | |
6286 | return -EOPNOTSUPP; | |
6287 | ||
31559f35 JD |
6288 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
6289 | if (WARN_ON(!cac_time_ms)) | |
6290 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
6291 | ||
6292 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, | |
6293 | cac_time_ms); | |
04f39047 | 6294 | if (!err) { |
9e0e2961 | 6295 | wdev->chandef = chandef; |
04f39047 SW |
6296 | wdev->cac_started = true; |
6297 | wdev->cac_start_time = jiffies; | |
31559f35 | 6298 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 6299 | } |
04f39047 SW |
6300 | return err; |
6301 | } | |
6302 | ||
16ef1fe2 SW |
6303 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
6304 | { | |
6305 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6306 | struct net_device *dev = info->user_ptr[1]; | |
6307 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6308 | struct cfg80211_csa_settings params; | |
6309 | /* csa_attrs is defined static to avoid waste of stack size - this | |
6310 | * function is called under RTNL lock, so this should not be a problem. | |
6311 | */ | |
6312 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
16ef1fe2 | 6313 | int err; |
ee4bc9e7 | 6314 | bool need_new_beacon = false; |
9a774c78 | 6315 | int len, i; |
252e07ca | 6316 | u32 cs_count; |
16ef1fe2 SW |
6317 | |
6318 | if (!rdev->ops->channel_switch || | |
6319 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
6320 | return -EOPNOTSUPP; | |
6321 | ||
ee4bc9e7 SW |
6322 | switch (dev->ieee80211_ptr->iftype) { |
6323 | case NL80211_IFTYPE_AP: | |
6324 | case NL80211_IFTYPE_P2P_GO: | |
6325 | need_new_beacon = true; | |
6326 | ||
6327 | /* useless if AP is not running */ | |
6328 | if (!wdev->beacon_interval) | |
1ff79dfa | 6329 | return -ENOTCONN; |
ee4bc9e7 SW |
6330 | break; |
6331 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
6332 | if (!wdev->ssid_len) |
6333 | return -ENOTCONN; | |
6334 | break; | |
c6da674a | 6335 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
6336 | if (!wdev->mesh_id_len) |
6337 | return -ENOTCONN; | |
ee4bc9e7 SW |
6338 | break; |
6339 | default: | |
16ef1fe2 | 6340 | return -EOPNOTSUPP; |
ee4bc9e7 | 6341 | } |
16ef1fe2 SW |
6342 | |
6343 | memset(¶ms, 0, sizeof(params)); | |
6344 | ||
6345 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6346 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
6347 | return -EINVAL; | |
6348 | ||
6349 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 6350 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
6351 | return -EINVAL; |
6352 | ||
252e07ca LC |
6353 | /* Even though the attribute is u32, the specification says |
6354 | * u8, so let's make sure we don't overflow. | |
6355 | */ | |
6356 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
6357 | if (cs_count > 255) | |
6358 | return -EINVAL; | |
6359 | ||
6360 | params.count = cs_count; | |
16ef1fe2 | 6361 | |
ee4bc9e7 SW |
6362 | if (!need_new_beacon) |
6363 | goto skip_beacons; | |
6364 | ||
16ef1fe2 SW |
6365 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
6366 | if (err) | |
6367 | return err; | |
6368 | ||
6369 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
6370 | info->attrs[NL80211_ATTR_CSA_IES], | |
6371 | nl80211_policy); | |
6372 | if (err) | |
6373 | return err; | |
6374 | ||
6375 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
6376 | if (err) | |
6377 | return err; | |
6378 | ||
6379 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
6380 | return -EINVAL; | |
6381 | ||
9a774c78 AO |
6382 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
6383 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6384 | return -EINVAL; |
6385 | ||
9a774c78 AO |
6386 | params.n_counter_offsets_beacon = len / sizeof(u16); |
6387 | if (rdev->wiphy.max_num_csa_counters && | |
6388 | (params.n_counter_offsets_beacon > | |
6389 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
6390 | return -EINVAL; |
6391 | ||
9a774c78 AO |
6392 | params.counter_offsets_beacon = |
6393 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
6394 | ||
6395 | /* sanity checks - counters should fit and be the same */ | |
6396 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
6397 | u16 offset = params.counter_offsets_beacon[i]; | |
6398 | ||
6399 | if (offset >= params.beacon_csa.tail_len) | |
6400 | return -EINVAL; | |
6401 | ||
6402 | if (params.beacon_csa.tail[offset] != params.count) | |
6403 | return -EINVAL; | |
6404 | } | |
6405 | ||
16ef1fe2 | 6406 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
6407 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
6408 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6409 | return -EINVAL; |
6410 | ||
9a774c78 AO |
6411 | params.n_counter_offsets_presp = len / sizeof(u16); |
6412 | if (rdev->wiphy.max_num_csa_counters && | |
6413 | (params.n_counter_offsets_beacon > | |
6414 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 | 6415 | return -EINVAL; |
9a774c78 AO |
6416 | |
6417 | params.counter_offsets_presp = | |
6418 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
6419 | ||
6420 | /* sanity checks - counters should fit and be the same */ | |
6421 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
6422 | u16 offset = params.counter_offsets_presp[i]; | |
6423 | ||
6424 | if (offset >= params.beacon_csa.probe_resp_len) | |
6425 | return -EINVAL; | |
6426 | ||
6427 | if (params.beacon_csa.probe_resp[offset] != | |
6428 | params.count) | |
6429 | return -EINVAL; | |
6430 | } | |
16ef1fe2 SW |
6431 | } |
6432 | ||
ee4bc9e7 | 6433 | skip_beacons: |
16ef1fe2 SW |
6434 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
6435 | if (err) | |
6436 | return err; | |
6437 | ||
174e0cd2 IP |
6438 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
6439 | wdev->iftype)) | |
16ef1fe2 SW |
6440 | return -EINVAL; |
6441 | ||
2beb6dab LC |
6442 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
6443 | ¶ms.chandef, | |
6444 | wdev->iftype); | |
6445 | if (err < 0) | |
6446 | return err; | |
6447 | ||
dcc6c2f5 | 6448 | if (err > 0) |
2beb6dab | 6449 | params.radar_required = true; |
16ef1fe2 | 6450 | |
16ef1fe2 SW |
6451 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
6452 | params.block_tx = true; | |
6453 | ||
c56589ed SW |
6454 | wdev_lock(wdev); |
6455 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
6456 | wdev_unlock(wdev); | |
6457 | ||
6458 | return err; | |
16ef1fe2 SW |
6459 | } |
6460 | ||
9720bb3a JB |
6461 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
6462 | u32 seq, int flags, | |
2a519311 | 6463 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
6464 | struct wireless_dev *wdev, |
6465 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 6466 | { |
48ab905d | 6467 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 6468 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
6469 | void *hdr; |
6470 | struct nlattr *bss; | |
48ab905d JB |
6471 | |
6472 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 6473 | |
15e47304 | 6474 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
6475 | NL80211_CMD_NEW_SCAN_RESULTS); |
6476 | if (!hdr) | |
6477 | return -1; | |
6478 | ||
9720bb3a JB |
6479 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
6480 | ||
97990a06 JB |
6481 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
6482 | goto nla_put_failure; | |
6483 | if (wdev->netdev && | |
9360ffd1 DM |
6484 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
6485 | goto nla_put_failure; | |
97990a06 JB |
6486 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
6487 | goto nla_put_failure; | |
2a519311 JB |
6488 | |
6489 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
6490 | if (!bss) | |
6491 | goto nla_put_failure; | |
9360ffd1 | 6492 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 6493 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 6494 | goto nla_put_failure; |
9caf0364 JB |
6495 | |
6496 | rcu_read_lock(); | |
0e227084 JB |
6497 | /* indicate whether we have probe response data or not */ |
6498 | if (rcu_access_pointer(res->proberesp_ies) && | |
6499 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
6500 | goto fail_unlock_rcu; | |
6501 | ||
6502 | /* this pointer prefers to be pointed to probe response data | |
6503 | * but is always valid | |
6504 | */ | |
9caf0364 | 6505 | ies = rcu_dereference(res->ies); |
8cef2c9d JB |
6506 | if (ies) { |
6507 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
6508 | goto fail_unlock_rcu; | |
8cef2c9d JB |
6509 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
6510 | ies->len, ies->data)) | |
6511 | goto fail_unlock_rcu; | |
9caf0364 | 6512 | } |
0e227084 JB |
6513 | |
6514 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 6515 | ies = rcu_dereference(res->beacon_ies); |
0e227084 JB |
6516 | if (ies && ies->from_beacon) { |
6517 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) | |
8cef2c9d JB |
6518 | goto fail_unlock_rcu; |
6519 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
6520 | ies->len, ies->data)) | |
6521 | goto fail_unlock_rcu; | |
9caf0364 JB |
6522 | } |
6523 | rcu_read_unlock(); | |
6524 | ||
9360ffd1 DM |
6525 | if (res->beacon_interval && |
6526 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
6527 | goto nla_put_failure; | |
6528 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
6529 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 6530 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
6531 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
6532 | jiffies_to_msecs(jiffies - intbss->ts))) | |
6533 | goto nla_put_failure; | |
2a519311 | 6534 | |
77965c97 | 6535 | switch (rdev->wiphy.signal_type) { |
2a519311 | 6536 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
6537 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
6538 | goto nla_put_failure; | |
2a519311 JB |
6539 | break; |
6540 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
6541 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
6542 | goto nla_put_failure; | |
2a519311 JB |
6543 | break; |
6544 | default: | |
6545 | break; | |
6546 | } | |
6547 | ||
48ab905d | 6548 | switch (wdev->iftype) { |
074ac8df | 6549 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 6550 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
6551 | if (intbss == wdev->current_bss && |
6552 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6553 | NL80211_BSS_STATUS_ASSOCIATED)) | |
6554 | goto nla_put_failure; | |
48ab905d JB |
6555 | break; |
6556 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
6557 | if (intbss == wdev->current_bss && |
6558 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6559 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
6560 | goto nla_put_failure; | |
48ab905d JB |
6561 | break; |
6562 | default: | |
6563 | break; | |
6564 | } | |
6565 | ||
2a519311 JB |
6566 | nla_nest_end(msg, bss); |
6567 | ||
6568 | return genlmsg_end(msg, hdr); | |
6569 | ||
8cef2c9d JB |
6570 | fail_unlock_rcu: |
6571 | rcu_read_unlock(); | |
2a519311 JB |
6572 | nla_put_failure: |
6573 | genlmsg_cancel(msg, hdr); | |
6574 | return -EMSGSIZE; | |
6575 | } | |
6576 | ||
97990a06 | 6577 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 6578 | { |
48ab905d | 6579 | struct cfg80211_registered_device *rdev; |
2a519311 | 6580 | struct cfg80211_internal_bss *scan; |
48ab905d | 6581 | struct wireless_dev *wdev; |
97990a06 | 6582 | int start = cb->args[2], idx = 0; |
2a519311 JB |
6583 | int err; |
6584 | ||
97990a06 | 6585 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6586 | if (err) |
6587 | return err; | |
2a519311 | 6588 | |
48ab905d JB |
6589 | wdev_lock(wdev); |
6590 | spin_lock_bh(&rdev->bss_lock); | |
6591 | cfg80211_bss_expire(rdev); | |
6592 | ||
9720bb3a JB |
6593 | cb->seq = rdev->bss_generation; |
6594 | ||
48ab905d | 6595 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
6596 | if (++idx <= start) |
6597 | continue; | |
9720bb3a | 6598 | if (nl80211_send_bss(skb, cb, |
2a519311 | 6599 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 6600 | rdev, wdev, scan) < 0) { |
2a519311 | 6601 | idx--; |
67748893 | 6602 | break; |
2a519311 JB |
6603 | } |
6604 | } | |
6605 | ||
48ab905d JB |
6606 | spin_unlock_bh(&rdev->bss_lock); |
6607 | wdev_unlock(wdev); | |
2a519311 | 6608 | |
97990a06 JB |
6609 | cb->args[2] = idx; |
6610 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 6611 | |
67748893 | 6612 | return skb->len; |
2a519311 JB |
6613 | } |
6614 | ||
15e47304 | 6615 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
6616 | int flags, struct net_device *dev, |
6617 | struct survey_info *survey) | |
6618 | { | |
6619 | void *hdr; | |
6620 | struct nlattr *infoattr; | |
6621 | ||
15e47304 | 6622 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
6623 | NL80211_CMD_NEW_SURVEY_RESULTS); |
6624 | if (!hdr) | |
6625 | return -ENOMEM; | |
6626 | ||
9360ffd1 DM |
6627 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
6628 | goto nla_put_failure; | |
61fa713c HS |
6629 | |
6630 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
6631 | if (!infoattr) | |
6632 | goto nla_put_failure; | |
6633 | ||
9360ffd1 DM |
6634 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
6635 | survey->channel->center_freq)) | |
6636 | goto nla_put_failure; | |
6637 | ||
6638 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
6639 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
6640 | goto nla_put_failure; | |
6641 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
6642 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
6643 | goto nla_put_failure; | |
6644 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
6645 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
6646 | survey->channel_time)) | |
6647 | goto nla_put_failure; | |
6648 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
6649 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
6650 | survey->channel_time_busy)) | |
6651 | goto nla_put_failure; | |
6652 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
6653 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
6654 | survey->channel_time_ext_busy)) | |
6655 | goto nla_put_failure; | |
6656 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
6657 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
6658 | survey->channel_time_rx)) | |
6659 | goto nla_put_failure; | |
6660 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
6661 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
6662 | survey->channel_time_tx)) | |
6663 | goto nla_put_failure; | |
61fa713c HS |
6664 | |
6665 | nla_nest_end(msg, infoattr); | |
6666 | ||
6667 | return genlmsg_end(msg, hdr); | |
6668 | ||
6669 | nla_put_failure: | |
6670 | genlmsg_cancel(msg, hdr); | |
6671 | return -EMSGSIZE; | |
6672 | } | |
6673 | ||
6674 | static int nl80211_dump_survey(struct sk_buff *skb, | |
6675 | struct netlink_callback *cb) | |
6676 | { | |
6677 | struct survey_info survey; | |
1b8ec87a | 6678 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
6679 | struct wireless_dev *wdev; |
6680 | int survey_idx = cb->args[2]; | |
61fa713c HS |
6681 | int res; |
6682 | ||
1b8ec87a | 6683 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6684 | if (res) |
6685 | return res; | |
61fa713c | 6686 | |
97990a06 JB |
6687 | if (!wdev->netdev) { |
6688 | res = -EINVAL; | |
6689 | goto out_err; | |
6690 | } | |
6691 | ||
1b8ec87a | 6692 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
6693 | res = -EOPNOTSUPP; |
6694 | goto out_err; | |
6695 | } | |
6696 | ||
6697 | while (1) { | |
1b8ec87a | 6698 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
6699 | if (res == -ENOENT) |
6700 | break; | |
6701 | if (res) | |
6702 | goto out_err; | |
6703 | ||
180cdc79 LR |
6704 | /* Survey without a channel doesn't make sense */ |
6705 | if (!survey.channel) { | |
6706 | res = -EINVAL; | |
6707 | goto out; | |
6708 | } | |
6709 | ||
ea9eba6a | 6710 | if (survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
180cdc79 LR |
6711 | survey_idx++; |
6712 | continue; | |
6713 | } | |
6714 | ||
61fa713c | 6715 | if (nl80211_send_survey(skb, |
15e47304 | 6716 | NETLINK_CB(cb->skb).portid, |
61fa713c | 6717 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 6718 | wdev->netdev, &survey) < 0) |
61fa713c HS |
6719 | goto out; |
6720 | survey_idx++; | |
6721 | } | |
6722 | ||
6723 | out: | |
97990a06 | 6724 | cb->args[2] = survey_idx; |
61fa713c HS |
6725 | res = skb->len; |
6726 | out_err: | |
1b8ec87a | 6727 | nl80211_finish_wdev_dump(rdev); |
61fa713c HS |
6728 | return res; |
6729 | } | |
6730 | ||
b23aa676 SO |
6731 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
6732 | { | |
6733 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
6734 | NL80211_WPA_VERSION_2)); | |
6735 | } | |
6736 | ||
636a5d36 JM |
6737 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
6738 | { | |
4c476991 JB |
6739 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6740 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6741 | struct ieee80211_channel *chan; |
e39e5b5e JM |
6742 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
6743 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 6744 | enum nl80211_auth_type auth_type; |
fffd0934 | 6745 | struct key_parse key; |
d5cdfacb | 6746 | bool local_state_change; |
636a5d36 | 6747 | |
f4a11bb0 JB |
6748 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6749 | return -EINVAL; | |
6750 | ||
6751 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6752 | return -EINVAL; | |
6753 | ||
1778092e JM |
6754 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
6755 | return -EINVAL; | |
6756 | ||
19957bb3 JB |
6757 | if (!info->attrs[NL80211_ATTR_SSID]) |
6758 | return -EINVAL; | |
6759 | ||
6760 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
6761 | return -EINVAL; | |
6762 | ||
fffd0934 JB |
6763 | err = nl80211_parse_key(info, &key); |
6764 | if (err) | |
6765 | return err; | |
6766 | ||
6767 | if (key.idx >= 0) { | |
e31b8213 JB |
6768 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
6769 | return -EINVAL; | |
fffd0934 JB |
6770 | if (!key.p.key || !key.p.key_len) |
6771 | return -EINVAL; | |
6772 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
6773 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
6774 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
6775 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
6776 | return -EINVAL; | |
6777 | if (key.idx > 4) | |
6778 | return -EINVAL; | |
6779 | } else { | |
6780 | key.p.key_len = 0; | |
6781 | key.p.key = NULL; | |
6782 | } | |
6783 | ||
afea0b7a JB |
6784 | if (key.idx >= 0) { |
6785 | int i; | |
6786 | bool ok = false; | |
6787 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
6788 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
6789 | ok = true; | |
6790 | break; | |
6791 | } | |
6792 | } | |
4c476991 JB |
6793 | if (!ok) |
6794 | return -EINVAL; | |
afea0b7a JB |
6795 | } |
6796 | ||
4c476991 JB |
6797 | if (!rdev->ops->auth) |
6798 | return -EOPNOTSUPP; | |
636a5d36 | 6799 | |
074ac8df | 6800 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6801 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6802 | return -EOPNOTSUPP; | |
eec60b03 | 6803 | |
19957bb3 | 6804 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
6805 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6806 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6807 | if (!chan) | |
4c476991 | 6808 | return -EINVAL; |
636a5d36 | 6809 | |
19957bb3 JB |
6810 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6811 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6812 | |
6813 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6814 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6815 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6816 | } |
6817 | ||
19957bb3 | 6818 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 6819 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 6820 | return -EINVAL; |
636a5d36 | 6821 | |
e39e5b5e JM |
6822 | if (auth_type == NL80211_AUTHTYPE_SAE && |
6823 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
6824 | return -EINVAL; | |
6825 | ||
6826 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
6827 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
6828 | return -EINVAL; | |
6829 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6830 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6831 | /* need to include at least Auth Transaction and Status Code */ | |
6832 | if (sae_data_len < 4) | |
6833 | return -EINVAL; | |
6834 | } | |
6835 | ||
d5cdfacb JM |
6836 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6837 | ||
95de817b JB |
6838 | /* |
6839 | * Since we no longer track auth state, ignore | |
6840 | * requests to only change local state. | |
6841 | */ | |
6842 | if (local_state_change) | |
6843 | return 0; | |
6844 | ||
91bf9b26 JB |
6845 | wdev_lock(dev->ieee80211_ptr); |
6846 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
6847 | ssid, ssid_len, ie, ie_len, | |
6848 | key.p.key, key.p.key_len, key.idx, | |
6849 | sae_data, sae_data_len); | |
6850 | wdev_unlock(dev->ieee80211_ptr); | |
6851 | return err; | |
636a5d36 JM |
6852 | } |
6853 | ||
c0692b8f JB |
6854 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6855 | struct genl_info *info, | |
3dc27d25 JB |
6856 | struct cfg80211_crypto_settings *settings, |
6857 | int cipher_limit) | |
b23aa676 | 6858 | { |
c0b2bbd8 JB |
6859 | memset(settings, 0, sizeof(*settings)); |
6860 | ||
b23aa676 SO |
6861 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6862 | ||
c0692b8f JB |
6863 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6864 | u16 proto; | |
6865 | proto = nla_get_u16( | |
6866 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6867 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6868 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6869 | proto != ETH_P_PAE) | |
6870 | return -EINVAL; | |
6871 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6872 | settings->control_port_no_encrypt = true; | |
6873 | } else | |
6874 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6875 | ||
b23aa676 SO |
6876 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6877 | void *data; | |
6878 | int len, i; | |
6879 | ||
6880 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6881 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6882 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6883 | ||
6884 | if (len % sizeof(u32)) | |
6885 | return -EINVAL; | |
6886 | ||
3dc27d25 | 6887 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6888 | return -EINVAL; |
6889 | ||
6890 | memcpy(settings->ciphers_pairwise, data, len); | |
6891 | ||
6892 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6893 | if (!cfg80211_supported_cipher_suite( |
6894 | &rdev->wiphy, | |
b23aa676 SO |
6895 | settings->ciphers_pairwise[i])) |
6896 | return -EINVAL; | |
6897 | } | |
6898 | ||
6899 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6900 | settings->cipher_group = | |
6901 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6902 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6903 | settings->cipher_group)) | |
b23aa676 SO |
6904 | return -EINVAL; |
6905 | } | |
6906 | ||
6907 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6908 | settings->wpa_versions = | |
6909 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6910 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6911 | return -EINVAL; | |
6912 | } | |
6913 | ||
6914 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6915 | void *data; | |
6d30240e | 6916 | int len; |
b23aa676 SO |
6917 | |
6918 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6919 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6920 | settings->n_akm_suites = len / sizeof(u32); | |
6921 | ||
6922 | if (len % sizeof(u32)) | |
6923 | return -EINVAL; | |
6924 | ||
1b9ca027 JM |
6925 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6926 | return -EINVAL; | |
6927 | ||
b23aa676 | 6928 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6929 | } |
6930 | ||
6931 | return 0; | |
6932 | } | |
6933 | ||
636a5d36 JM |
6934 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6935 | { | |
4c476991 JB |
6936 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6937 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6938 | struct ieee80211_channel *chan; |
f62fab73 JB |
6939 | struct cfg80211_assoc_request req = {}; |
6940 | const u8 *bssid, *ssid; | |
6941 | int err, ssid_len = 0; | |
636a5d36 | 6942 | |
f4a11bb0 JB |
6943 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6944 | return -EINVAL; | |
6945 | ||
6946 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6947 | !info->attrs[NL80211_ATTR_SSID] || |
6948 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6949 | return -EINVAL; |
6950 | ||
4c476991 JB |
6951 | if (!rdev->ops->assoc) |
6952 | return -EOPNOTSUPP; | |
636a5d36 | 6953 | |
074ac8df | 6954 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6955 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6956 | return -EOPNOTSUPP; | |
eec60b03 | 6957 | |
19957bb3 | 6958 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6959 | |
664834de JM |
6960 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6961 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6962 | if (!chan) | |
4c476991 | 6963 | return -EINVAL; |
636a5d36 | 6964 | |
19957bb3 JB |
6965 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6966 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6967 | |
6968 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6969 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6970 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6971 | } |
6972 | ||
dc6382ce | 6973 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6974 | enum nl80211_mfp mfp = |
dc6382ce | 6975 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6976 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6977 | req.use_mfp = true; |
4c476991 JB |
6978 | else if (mfp != NL80211_MFP_NO) |
6979 | return -EINVAL; | |
dc6382ce JM |
6980 | } |
6981 | ||
3e5d7649 | 6982 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 6983 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 6984 | |
7e7c8926 | 6985 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 6986 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
6987 | |
6988 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
6989 | memcpy(&req.ht_capa_mask, |
6990 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6991 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
6992 | |
6993 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 6994 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 6995 | return -EINVAL; |
f62fab73 JB |
6996 | memcpy(&req.ht_capa, |
6997 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6998 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
6999 | } |
7000 | ||
ee2aca34 | 7001 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 7002 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
7003 | |
7004 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
7005 | memcpy(&req.vht_capa_mask, |
7006 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7007 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
7008 | |
7009 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 7010 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 7011 | return -EINVAL; |
f62fab73 JB |
7012 | memcpy(&req.vht_capa, |
7013 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7014 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
7015 | } |
7016 | ||
bab5ab7d AK |
7017 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7018 | if (!(rdev->wiphy.features & | |
7019 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7020 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7021 | return -EINVAL; | |
7022 | req.flags |= ASSOC_REQ_USE_RRM; | |
7023 | } | |
7024 | ||
f62fab73 | 7025 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
7026 | if (!err) { |
7027 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
7028 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
7029 | ssid, ssid_len, &req); | |
91bf9b26 JB |
7030 | wdev_unlock(dev->ieee80211_ptr); |
7031 | } | |
636a5d36 | 7032 | |
636a5d36 JM |
7033 | return err; |
7034 | } | |
7035 | ||
7036 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
7037 | { | |
4c476991 JB |
7038 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7039 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7040 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7041 | int ie_len = 0, err; |
19957bb3 | 7042 | u16 reason_code; |
d5cdfacb | 7043 | bool local_state_change; |
636a5d36 | 7044 | |
f4a11bb0 JB |
7045 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7046 | return -EINVAL; | |
7047 | ||
7048 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7049 | return -EINVAL; | |
7050 | ||
7051 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7052 | return -EINVAL; | |
7053 | ||
4c476991 JB |
7054 | if (!rdev->ops->deauth) |
7055 | return -EOPNOTSUPP; | |
636a5d36 | 7056 | |
074ac8df | 7057 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7058 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7059 | return -EOPNOTSUPP; | |
eec60b03 | 7060 | |
19957bb3 | 7061 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7062 | |
19957bb3 JB |
7063 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7064 | if (reason_code == 0) { | |
f4a11bb0 | 7065 | /* Reason Code 0 is reserved */ |
4c476991 | 7066 | return -EINVAL; |
255e737e | 7067 | } |
636a5d36 JM |
7068 | |
7069 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7070 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7071 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7072 | } |
7073 | ||
d5cdfacb JM |
7074 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7075 | ||
91bf9b26 JB |
7076 | wdev_lock(dev->ieee80211_ptr); |
7077 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
7078 | local_state_change); | |
7079 | wdev_unlock(dev->ieee80211_ptr); | |
7080 | return err; | |
636a5d36 JM |
7081 | } |
7082 | ||
7083 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
7084 | { | |
4c476991 JB |
7085 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7086 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7087 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7088 | int ie_len = 0, err; |
19957bb3 | 7089 | u16 reason_code; |
d5cdfacb | 7090 | bool local_state_change; |
636a5d36 | 7091 | |
f4a11bb0 JB |
7092 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7093 | return -EINVAL; | |
7094 | ||
7095 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7096 | return -EINVAL; | |
7097 | ||
7098 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7099 | return -EINVAL; | |
7100 | ||
4c476991 JB |
7101 | if (!rdev->ops->disassoc) |
7102 | return -EOPNOTSUPP; | |
636a5d36 | 7103 | |
074ac8df | 7104 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7105 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7106 | return -EOPNOTSUPP; | |
eec60b03 | 7107 | |
19957bb3 | 7108 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7109 | |
19957bb3 JB |
7110 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7111 | if (reason_code == 0) { | |
f4a11bb0 | 7112 | /* Reason Code 0 is reserved */ |
4c476991 | 7113 | return -EINVAL; |
255e737e | 7114 | } |
636a5d36 JM |
7115 | |
7116 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7117 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7118 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7119 | } |
7120 | ||
d5cdfacb JM |
7121 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7122 | ||
91bf9b26 JB |
7123 | wdev_lock(dev->ieee80211_ptr); |
7124 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
7125 | local_state_change); | |
7126 | wdev_unlock(dev->ieee80211_ptr); | |
7127 | return err; | |
636a5d36 JM |
7128 | } |
7129 | ||
dd5b4cc7 FF |
7130 | static bool |
7131 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
7132 | int mcast_rate[IEEE80211_NUM_BANDS], | |
7133 | int rateval) | |
7134 | { | |
7135 | struct wiphy *wiphy = &rdev->wiphy; | |
7136 | bool found = false; | |
7137 | int band, i; | |
7138 | ||
7139 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
7140 | struct ieee80211_supported_band *sband; | |
7141 | ||
7142 | sband = wiphy->bands[band]; | |
7143 | if (!sband) | |
7144 | continue; | |
7145 | ||
7146 | for (i = 0; i < sband->n_bitrates; i++) { | |
7147 | if (sband->bitrates[i].bitrate == rateval) { | |
7148 | mcast_rate[band] = i + 1; | |
7149 | found = true; | |
7150 | break; | |
7151 | } | |
7152 | } | |
7153 | } | |
7154 | ||
7155 | return found; | |
7156 | } | |
7157 | ||
04a773ad JB |
7158 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
7159 | { | |
4c476991 JB |
7160 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7161 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
7162 | struct cfg80211_ibss_params ibss; |
7163 | struct wiphy *wiphy; | |
fffd0934 | 7164 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
7165 | int err; |
7166 | ||
8e30bc55 JB |
7167 | memset(&ibss, 0, sizeof(ibss)); |
7168 | ||
04a773ad JB |
7169 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7170 | return -EINVAL; | |
7171 | ||
683b6d3b | 7172 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
7173 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
7174 | return -EINVAL; | |
7175 | ||
8e30bc55 JB |
7176 | ibss.beacon_interval = 100; |
7177 | ||
7178 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
7179 | ibss.beacon_interval = | |
7180 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7181 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
7182 | return -EINVAL; | |
7183 | } | |
7184 | ||
4c476991 JB |
7185 | if (!rdev->ops->join_ibss) |
7186 | return -EOPNOTSUPP; | |
04a773ad | 7187 | |
4c476991 JB |
7188 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7189 | return -EOPNOTSUPP; | |
04a773ad | 7190 | |
79c97e97 | 7191 | wiphy = &rdev->wiphy; |
04a773ad | 7192 | |
39193498 | 7193 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 7194 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
7195 | |
7196 | if (!is_valid_ether_addr(ibss.bssid)) | |
7197 | return -EINVAL; | |
7198 | } | |
04a773ad JB |
7199 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7200 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7201 | ||
7202 | if (info->attrs[NL80211_ATTR_IE]) { | |
7203 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7204 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7205 | } | |
7206 | ||
683b6d3b JB |
7207 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
7208 | if (err) | |
7209 | return err; | |
04a773ad | 7210 | |
174e0cd2 IP |
7211 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
7212 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
7213 | return -EINVAL; |
7214 | ||
2f301ab2 | 7215 | switch (ibss.chandef.width) { |
bf372645 SW |
7216 | case NL80211_CHAN_WIDTH_5: |
7217 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
7218 | case NL80211_CHAN_WIDTH_20_NOHT: |
7219 | break; | |
7220 | case NL80211_CHAN_WIDTH_20: | |
7221 | case NL80211_CHAN_WIDTH_40: | |
7222 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | |
7223 | break; | |
7224 | default: | |
c04d6150 | 7225 | return -EINVAL; |
2f301ab2 | 7226 | } |
db9c64cf | 7227 | |
04a773ad | 7228 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
7229 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
7230 | ||
fbd2c8dc TP |
7231 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
7232 | u8 *rates = | |
7233 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7234 | int n_rates = | |
7235 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7236 | struct ieee80211_supported_band *sband = | |
683b6d3b | 7237 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 7238 | |
34850ab2 JB |
7239 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
7240 | &ibss.basic_rates); | |
7241 | if (err) | |
7242 | return err; | |
fbd2c8dc | 7243 | } |
dd5b4cc7 | 7244 | |
803768f5 SW |
7245 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7246 | memcpy(&ibss.ht_capa_mask, | |
7247 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7248 | sizeof(ibss.ht_capa_mask)); | |
7249 | ||
7250 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
7251 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7252 | return -EINVAL; | |
7253 | memcpy(&ibss.ht_capa, | |
7254 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7255 | sizeof(ibss.ht_capa)); | |
7256 | } | |
7257 | ||
dd5b4cc7 FF |
7258 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7259 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
7260 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7261 | return -EINVAL; | |
fbd2c8dc | 7262 | |
4c476991 | 7263 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
7264 | bool no_ht = false; |
7265 | ||
4c476991 | 7266 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
7267 | info->attrs[NL80211_ATTR_KEYS], |
7268 | &no_ht); | |
4c476991 JB |
7269 | if (IS_ERR(connkeys)) |
7270 | return PTR_ERR(connkeys); | |
de7044ee | 7271 | |
3d9d1d66 JB |
7272 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
7273 | no_ht) { | |
de7044ee SM |
7274 | kfree(connkeys); |
7275 | return -EINVAL; | |
7276 | } | |
4c476991 | 7277 | } |
04a773ad | 7278 | |
267335d6 AQ |
7279 | ibss.control_port = |
7280 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
7281 | ||
5336fa88 SW |
7282 | ibss.userspace_handles_dfs = |
7283 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
7284 | ||
4c476991 | 7285 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 | 7286 | if (err) |
b47f610b | 7287 | kzfree(connkeys); |
04a773ad JB |
7288 | return err; |
7289 | } | |
7290 | ||
7291 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
7292 | { | |
4c476991 JB |
7293 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7294 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 7295 | |
4c476991 JB |
7296 | if (!rdev->ops->leave_ibss) |
7297 | return -EOPNOTSUPP; | |
04a773ad | 7298 | |
4c476991 JB |
7299 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7300 | return -EOPNOTSUPP; | |
04a773ad | 7301 | |
4c476991 | 7302 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
7303 | } |
7304 | ||
f4e583c8 AQ |
7305 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
7306 | { | |
7307 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7308 | struct net_device *dev = info->user_ptr[1]; | |
7309 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
7310 | u32 nla_rate; | |
7311 | int err; | |
7312 | ||
7313 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
7314 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
7315 | return -EOPNOTSUPP; | |
7316 | ||
7317 | if (!rdev->ops->set_mcast_rate) | |
7318 | return -EOPNOTSUPP; | |
7319 | ||
7320 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
7321 | ||
7322 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
7323 | return -EINVAL; | |
7324 | ||
7325 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
7326 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
7327 | return -EINVAL; | |
7328 | ||
7329 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
7330 | ||
7331 | return err; | |
7332 | } | |
7333 | ||
ad7e718c JB |
7334 | static struct sk_buff * |
7335 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
7336 | int approxlen, u32 portid, u32 seq, | |
7337 | enum nl80211_commands cmd, | |
567ffc35 JB |
7338 | enum nl80211_attrs attr, |
7339 | const struct nl80211_vendor_cmd_info *info, | |
7340 | gfp_t gfp) | |
ad7e718c JB |
7341 | { |
7342 | struct sk_buff *skb; | |
7343 | void *hdr; | |
7344 | struct nlattr *data; | |
7345 | ||
7346 | skb = nlmsg_new(approxlen + 100, gfp); | |
7347 | if (!skb) | |
7348 | return NULL; | |
7349 | ||
7350 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
7351 | if (!hdr) { | |
7352 | kfree_skb(skb); | |
7353 | return NULL; | |
7354 | } | |
7355 | ||
7356 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
7357 | goto nla_put_failure; | |
567ffc35 JB |
7358 | |
7359 | if (info) { | |
7360 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
7361 | info->vendor_id)) | |
7362 | goto nla_put_failure; | |
7363 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
7364 | info->subcmd)) | |
7365 | goto nla_put_failure; | |
7366 | } | |
7367 | ||
ad7e718c JB |
7368 | data = nla_nest_start(skb, attr); |
7369 | ||
7370 | ((void **)skb->cb)[0] = rdev; | |
7371 | ((void **)skb->cb)[1] = hdr; | |
7372 | ((void **)skb->cb)[2] = data; | |
7373 | ||
7374 | return skb; | |
7375 | ||
7376 | nla_put_failure: | |
7377 | kfree_skb(skb); | |
7378 | return NULL; | |
7379 | } | |
f4e583c8 | 7380 | |
e03ad6ea JB |
7381 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
7382 | enum nl80211_commands cmd, | |
7383 | enum nl80211_attrs attr, | |
7384 | int vendor_event_idx, | |
7385 | int approxlen, gfp_t gfp) | |
7386 | { | |
f26cbf40 | 7387 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
7388 | const struct nl80211_vendor_cmd_info *info; |
7389 | ||
7390 | switch (cmd) { | |
7391 | case NL80211_CMD_TESTMODE: | |
7392 | if (WARN_ON(vendor_event_idx != -1)) | |
7393 | return NULL; | |
7394 | info = NULL; | |
7395 | break; | |
7396 | case NL80211_CMD_VENDOR: | |
7397 | if (WARN_ON(vendor_event_idx < 0 || | |
7398 | vendor_event_idx >= wiphy->n_vendor_events)) | |
7399 | return NULL; | |
7400 | info = &wiphy->vendor_events[vendor_event_idx]; | |
7401 | break; | |
7402 | default: | |
7403 | WARN_ON(1); | |
7404 | return NULL; | |
7405 | } | |
7406 | ||
7407 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, | |
7408 | cmd, attr, info, gfp); | |
7409 | } | |
7410 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
7411 | ||
7412 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
7413 | { | |
7414 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
7415 | void *hdr = ((void **)skb->cb)[1]; | |
7416 | struct nlattr *data = ((void **)skb->cb)[2]; | |
7417 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
7418 | ||
bd8c78e7 JB |
7419 | /* clear CB data for netlink core to own from now on */ |
7420 | memset(skb->cb, 0, sizeof(skb->cb)); | |
7421 | ||
e03ad6ea JB |
7422 | nla_nest_end(skb, data); |
7423 | genlmsg_end(skb, hdr); | |
7424 | ||
7425 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
7426 | mcgrp = NL80211_MCGRP_VENDOR; | |
7427 | ||
7428 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
7429 | mcgrp, gfp); | |
7430 | } | |
7431 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
7432 | ||
aff89a9b | 7433 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
7434 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
7435 | { | |
4c476991 | 7436 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
7437 | struct wireless_dev *wdev = |
7438 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
7439 | int err; |
7440 | ||
fc73f11f DS |
7441 | if (!rdev->ops->testmode_cmd) |
7442 | return -EOPNOTSUPP; | |
7443 | ||
7444 | if (IS_ERR(wdev)) { | |
7445 | err = PTR_ERR(wdev); | |
7446 | if (err != -EINVAL) | |
7447 | return err; | |
7448 | wdev = NULL; | |
7449 | } else if (wdev->wiphy != &rdev->wiphy) { | |
7450 | return -EINVAL; | |
7451 | } | |
7452 | ||
aff89a9b JB |
7453 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
7454 | return -EINVAL; | |
7455 | ||
ad7e718c | 7456 | rdev->cur_cmd_info = info; |
fc73f11f | 7457 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
7458 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
7459 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 7460 | rdev->cur_cmd_info = NULL; |
aff89a9b | 7461 | |
aff89a9b JB |
7462 | return err; |
7463 | } | |
7464 | ||
71063f0e WYG |
7465 | static int nl80211_testmode_dump(struct sk_buff *skb, |
7466 | struct netlink_callback *cb) | |
7467 | { | |
00918d33 | 7468 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
7469 | int err; |
7470 | long phy_idx; | |
7471 | void *data = NULL; | |
7472 | int data_len = 0; | |
7473 | ||
5fe231e8 JB |
7474 | rtnl_lock(); |
7475 | ||
71063f0e WYG |
7476 | if (cb->args[0]) { |
7477 | /* | |
7478 | * 0 is a valid index, but not valid for args[0], | |
7479 | * so we need to offset by 1. | |
7480 | */ | |
7481 | phy_idx = cb->args[0] - 1; | |
7482 | } else { | |
7483 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
7484 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
7485 | nl80211_policy); | |
7486 | if (err) | |
5fe231e8 | 7487 | goto out_err; |
00918d33 | 7488 | |
2bd7e35d JB |
7489 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
7490 | nl80211_fam.attrbuf); | |
7491 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
7492 | err = PTR_ERR(rdev); |
7493 | goto out_err; | |
00918d33 | 7494 | } |
2bd7e35d JB |
7495 | phy_idx = rdev->wiphy_idx; |
7496 | rdev = NULL; | |
2bd7e35d | 7497 | |
71063f0e WYG |
7498 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
7499 | cb->args[1] = | |
7500 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
7501 | } | |
7502 | ||
7503 | if (cb->args[1]) { | |
7504 | data = nla_data((void *)cb->args[1]); | |
7505 | data_len = nla_len((void *)cb->args[1]); | |
7506 | } | |
7507 | ||
00918d33 JB |
7508 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
7509 | if (!rdev) { | |
5fe231e8 JB |
7510 | err = -ENOENT; |
7511 | goto out_err; | |
71063f0e | 7512 | } |
71063f0e | 7513 | |
00918d33 | 7514 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
7515 | err = -EOPNOTSUPP; |
7516 | goto out_err; | |
7517 | } | |
7518 | ||
7519 | while (1) { | |
15e47304 | 7520 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
7521 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
7522 | NL80211_CMD_TESTMODE); | |
7523 | struct nlattr *tmdata; | |
7524 | ||
cb35fba3 DC |
7525 | if (!hdr) |
7526 | break; | |
7527 | ||
9360ffd1 | 7528 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
7529 | genlmsg_cancel(skb, hdr); |
7530 | break; | |
7531 | } | |
7532 | ||
7533 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
7534 | if (!tmdata) { | |
7535 | genlmsg_cancel(skb, hdr); | |
7536 | break; | |
7537 | } | |
e35e4d28 | 7538 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
7539 | nla_nest_end(skb, tmdata); |
7540 | ||
7541 | if (err == -ENOBUFS || err == -ENOENT) { | |
7542 | genlmsg_cancel(skb, hdr); | |
7543 | break; | |
7544 | } else if (err) { | |
7545 | genlmsg_cancel(skb, hdr); | |
7546 | goto out_err; | |
7547 | } | |
7548 | ||
7549 | genlmsg_end(skb, hdr); | |
7550 | } | |
7551 | ||
7552 | err = skb->len; | |
7553 | /* see above */ | |
7554 | cb->args[0] = phy_idx + 1; | |
7555 | out_err: | |
5fe231e8 | 7556 | rtnl_unlock(); |
71063f0e WYG |
7557 | return err; |
7558 | } | |
aff89a9b JB |
7559 | #endif |
7560 | ||
b23aa676 SO |
7561 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
7562 | { | |
4c476991 JB |
7563 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7564 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
7565 | struct cfg80211_connect_params connect; |
7566 | struct wiphy *wiphy; | |
fffd0934 | 7567 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
7568 | int err; |
7569 | ||
7570 | memset(&connect, 0, sizeof(connect)); | |
7571 | ||
7572 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
7573 | return -EINVAL; | |
7574 | ||
7575 | if (!info->attrs[NL80211_ATTR_SSID] || | |
7576 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
7577 | return -EINVAL; | |
7578 | ||
7579 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
7580 | connect.auth_type = | |
7581 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
7582 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
7583 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
7584 | return -EINVAL; |
7585 | } else | |
7586 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
7587 | ||
7588 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
7589 | ||
c0692b8f | 7590 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 7591 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
7592 | if (err) |
7593 | return err; | |
b23aa676 | 7594 | |
074ac8df | 7595 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7596 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7597 | return -EOPNOTSUPP; | |
b23aa676 | 7598 | |
79c97e97 | 7599 | wiphy = &rdev->wiphy; |
b23aa676 | 7600 | |
4486ea98 BS |
7601 | connect.bg_scan_period = -1; |
7602 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
7603 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
7604 | connect.bg_scan_period = | |
7605 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
7606 | } | |
7607 | ||
b23aa676 SO |
7608 | if (info->attrs[NL80211_ATTR_MAC]) |
7609 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
7610 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
7611 | connect.bssid_hint = | |
7612 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
7613 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7614 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7615 | ||
7616 | if (info->attrs[NL80211_ATTR_IE]) { | |
7617 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7618 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7619 | } | |
7620 | ||
cee00a95 JM |
7621 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
7622 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
7623 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
7624 | connect.mfp != NL80211_MFP_NO) | |
7625 | return -EINVAL; | |
7626 | } else { | |
7627 | connect.mfp = NL80211_MFP_NO; | |
7628 | } | |
7629 | ||
b23aa676 | 7630 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
7631 | connect.channel = nl80211_get_valid_chan( |
7632 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7633 | if (!connect.channel) | |
1df4a510 JM |
7634 | return -EINVAL; |
7635 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
7636 | connect.channel_hint = nl80211_get_valid_chan( |
7637 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
7638 | if (!connect.channel_hint) | |
4c476991 | 7639 | return -EINVAL; |
b23aa676 SO |
7640 | } |
7641 | ||
fffd0934 JB |
7642 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
7643 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 7644 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
7645 | if (IS_ERR(connkeys)) |
7646 | return PTR_ERR(connkeys); | |
fffd0934 JB |
7647 | } |
7648 | ||
7e7c8926 BG |
7649 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
7650 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
7651 | ||
7652 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7653 | memcpy(&connect.ht_capa_mask, | |
7654 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7655 | sizeof(connect.ht_capa_mask)); | |
7656 | ||
7657 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e | 7658 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
b47f610b | 7659 | kzfree(connkeys); |
7e7c8926 | 7660 | return -EINVAL; |
b4e4f47e | 7661 | } |
7e7c8926 BG |
7662 | memcpy(&connect.ht_capa, |
7663 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7664 | sizeof(connect.ht_capa)); | |
7665 | } | |
7666 | ||
ee2aca34 JB |
7667 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
7668 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
7669 | ||
7670 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
7671 | memcpy(&connect.vht_capa_mask, | |
7672 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7673 | sizeof(connect.vht_capa_mask)); | |
7674 | ||
7675 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
7676 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
b47f610b | 7677 | kzfree(connkeys); |
ee2aca34 JB |
7678 | return -EINVAL; |
7679 | } | |
7680 | memcpy(&connect.vht_capa, | |
7681 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7682 | sizeof(connect.vht_capa)); | |
7683 | } | |
7684 | ||
bab5ab7d AK |
7685 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7686 | if (!(rdev->wiphy.features & | |
7687 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7688 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7689 | return -EINVAL; | |
7690 | connect.flags |= ASSOC_REQ_USE_RRM; | |
7691 | } | |
7692 | ||
83739b03 JB |
7693 | wdev_lock(dev->ieee80211_ptr); |
7694 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
7695 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 | 7696 | if (err) |
b47f610b | 7697 | kzfree(connkeys); |
b23aa676 SO |
7698 | return err; |
7699 | } | |
7700 | ||
7701 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
7702 | { | |
4c476991 JB |
7703 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7704 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 7705 | u16 reason; |
83739b03 | 7706 | int ret; |
b23aa676 SO |
7707 | |
7708 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7709 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
7710 | else | |
7711 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
7712 | ||
7713 | if (reason == 0) | |
7714 | return -EINVAL; | |
7715 | ||
074ac8df | 7716 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7717 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7718 | return -EOPNOTSUPP; | |
b23aa676 | 7719 | |
83739b03 JB |
7720 | wdev_lock(dev->ieee80211_ptr); |
7721 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
7722 | wdev_unlock(dev->ieee80211_ptr); | |
7723 | return ret; | |
b23aa676 SO |
7724 | } |
7725 | ||
463d0183 JB |
7726 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
7727 | { | |
4c476991 | 7728 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
7729 | struct net *net; |
7730 | int err; | |
7731 | u32 pid; | |
7732 | ||
7733 | if (!info->attrs[NL80211_ATTR_PID]) | |
7734 | return -EINVAL; | |
7735 | ||
7736 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
7737 | ||
463d0183 | 7738 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
7739 | if (IS_ERR(net)) |
7740 | return PTR_ERR(net); | |
463d0183 JB |
7741 | |
7742 | err = 0; | |
7743 | ||
7744 | /* check if anything to do */ | |
4c476991 JB |
7745 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
7746 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 7747 | |
463d0183 | 7748 | put_net(net); |
463d0183 JB |
7749 | return err; |
7750 | } | |
7751 | ||
67fbb16b SO |
7752 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
7753 | { | |
4c476991 | 7754 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
7755 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
7756 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 7757 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
7758 | struct cfg80211_pmksa pmksa; |
7759 | ||
7760 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
7761 | ||
7762 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7763 | return -EINVAL; | |
7764 | ||
7765 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
7766 | return -EINVAL; | |
7767 | ||
67fbb16b SO |
7768 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
7769 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7770 | ||
074ac8df | 7771 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7772 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7773 | return -EOPNOTSUPP; | |
67fbb16b SO |
7774 | |
7775 | switch (info->genlhdr->cmd) { | |
7776 | case NL80211_CMD_SET_PMKSA: | |
7777 | rdev_ops = rdev->ops->set_pmksa; | |
7778 | break; | |
7779 | case NL80211_CMD_DEL_PMKSA: | |
7780 | rdev_ops = rdev->ops->del_pmksa; | |
7781 | break; | |
7782 | default: | |
7783 | WARN_ON(1); | |
7784 | break; | |
7785 | } | |
7786 | ||
4c476991 JB |
7787 | if (!rdev_ops) |
7788 | return -EOPNOTSUPP; | |
67fbb16b | 7789 | |
4c476991 | 7790 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
7791 | } |
7792 | ||
7793 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
7794 | { | |
4c476991 JB |
7795 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7796 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 7797 | |
074ac8df | 7798 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7799 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7800 | return -EOPNOTSUPP; | |
67fbb16b | 7801 | |
4c476991 JB |
7802 | if (!rdev->ops->flush_pmksa) |
7803 | return -EOPNOTSUPP; | |
67fbb16b | 7804 | |
e35e4d28 | 7805 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
7806 | } |
7807 | ||
109086ce AN |
7808 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
7809 | { | |
7810 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7811 | struct net_device *dev = info->user_ptr[1]; | |
7812 | u8 action_code, dialog_token; | |
df942e7b | 7813 | u32 peer_capability = 0; |
109086ce AN |
7814 | u16 status_code; |
7815 | u8 *peer; | |
31fa97c5 | 7816 | bool initiator; |
109086ce AN |
7817 | |
7818 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7819 | !rdev->ops->tdls_mgmt) | |
7820 | return -EOPNOTSUPP; | |
7821 | ||
7822 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
7823 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
7824 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
7825 | !info->attrs[NL80211_ATTR_IE] || | |
7826 | !info->attrs[NL80211_ATTR_MAC]) | |
7827 | return -EINVAL; | |
7828 | ||
7829 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7830 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
7831 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
7832 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 7833 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
7834 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
7835 | peer_capability = | |
7836 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 7837 | |
e35e4d28 | 7838 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 7839 | dialog_token, status_code, peer_capability, |
31fa97c5 | 7840 | initiator, |
e35e4d28 HG |
7841 | nla_data(info->attrs[NL80211_ATTR_IE]), |
7842 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
7843 | } |
7844 | ||
7845 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
7846 | { | |
7847 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7848 | struct net_device *dev = info->user_ptr[1]; | |
7849 | enum nl80211_tdls_operation operation; | |
7850 | u8 *peer; | |
7851 | ||
7852 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7853 | !rdev->ops->tdls_oper) | |
7854 | return -EOPNOTSUPP; | |
7855 | ||
7856 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
7857 | !info->attrs[NL80211_ATTR_MAC]) | |
7858 | return -EINVAL; | |
7859 | ||
7860 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
7861 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7862 | ||
e35e4d28 | 7863 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
7864 | } |
7865 | ||
9588bbd5 JM |
7866 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
7867 | struct genl_info *info) | |
7868 | { | |
4c476991 | 7869 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7870 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7871 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
7872 | struct sk_buff *msg; |
7873 | void *hdr; | |
7874 | u64 cookie; | |
683b6d3b | 7875 | u32 duration; |
9588bbd5 JM |
7876 | int err; |
7877 | ||
7878 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7879 | !info->attrs[NL80211_ATTR_DURATION]) | |
7880 | return -EINVAL; | |
7881 | ||
7882 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
7883 | ||
ebf348fc JB |
7884 | if (!rdev->ops->remain_on_channel || |
7885 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
7886 | return -EOPNOTSUPP; | |
7887 | ||
9588bbd5 | 7888 | /* |
ebf348fc JB |
7889 | * We should be on that channel for at least a minimum amount of |
7890 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 7891 | */ |
ebf348fc | 7892 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 7893 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
7894 | return -EINVAL; |
7895 | ||
683b6d3b JB |
7896 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7897 | if (err) | |
7898 | return err; | |
9588bbd5 JM |
7899 | |
7900 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7901 | if (!msg) |
7902 | return -ENOMEM; | |
9588bbd5 | 7903 | |
15e47304 | 7904 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 7905 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
7906 | if (!hdr) { |
7907 | err = -ENOBUFS; | |
9588bbd5 JM |
7908 | goto free_msg; |
7909 | } | |
7910 | ||
683b6d3b JB |
7911 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7912 | duration, &cookie); | |
9588bbd5 JM |
7913 | |
7914 | if (err) | |
7915 | goto free_msg; | |
7916 | ||
9360ffd1 DM |
7917 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7918 | goto nla_put_failure; | |
9588bbd5 JM |
7919 | |
7920 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7921 | |
7922 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7923 | |
7924 | nla_put_failure: | |
7925 | err = -ENOBUFS; | |
7926 | free_msg: | |
7927 | nlmsg_free(msg); | |
9588bbd5 JM |
7928 | return err; |
7929 | } | |
7930 | ||
7931 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
7932 | struct genl_info *info) | |
7933 | { | |
4c476991 | 7934 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7935 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 7936 | u64 cookie; |
9588bbd5 JM |
7937 | |
7938 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7939 | return -EINVAL; | |
7940 | ||
4c476991 JB |
7941 | if (!rdev->ops->cancel_remain_on_channel) |
7942 | return -EOPNOTSUPP; | |
9588bbd5 | 7943 | |
9588bbd5 JM |
7944 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
7945 | ||
e35e4d28 | 7946 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
7947 | } |
7948 | ||
13ae75b1 JM |
7949 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
7950 | u8 *rates, u8 rates_len) | |
7951 | { | |
7952 | u8 i; | |
7953 | u32 mask = 0; | |
7954 | ||
7955 | for (i = 0; i < rates_len; i++) { | |
7956 | int rate = (rates[i] & 0x7f) * 5; | |
7957 | int ridx; | |
7958 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
7959 | struct ieee80211_rate *srate = | |
7960 | &sband->bitrates[ridx]; | |
7961 | if (rate == srate->bitrate) { | |
7962 | mask |= 1 << ridx; | |
7963 | break; | |
7964 | } | |
7965 | } | |
7966 | if (ridx == sband->n_bitrates) | |
7967 | return 0; /* rate not found */ | |
7968 | } | |
7969 | ||
7970 | return mask; | |
7971 | } | |
7972 | ||
24db78c0 SW |
7973 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
7974 | u8 *rates, u8 rates_len, | |
7975 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
7976 | { | |
7977 | u8 i; | |
7978 | ||
7979 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
7980 | ||
7981 | for (i = 0; i < rates_len; i++) { | |
7982 | int ridx, rbit; | |
7983 | ||
7984 | ridx = rates[i] / 8; | |
7985 | rbit = BIT(rates[i] % 8); | |
7986 | ||
7987 | /* check validity */ | |
910570b5 | 7988 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
7989 | return false; |
7990 | ||
7991 | /* check availability */ | |
7992 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
7993 | mcs[ridx] |= rbit; | |
7994 | else | |
7995 | return false; | |
7996 | } | |
7997 | ||
7998 | return true; | |
7999 | } | |
8000 | ||
204e35a9 JD |
8001 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
8002 | { | |
8003 | u16 mcs_mask = 0; | |
8004 | ||
8005 | switch (vht_mcs_map) { | |
8006 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
8007 | break; | |
8008 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
8009 | mcs_mask = 0x00FF; | |
8010 | break; | |
8011 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
8012 | mcs_mask = 0x01FF; | |
8013 | break; | |
8014 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
8015 | mcs_mask = 0x03FF; | |
8016 | break; | |
8017 | default: | |
8018 | break; | |
8019 | } | |
8020 | ||
8021 | return mcs_mask; | |
8022 | } | |
8023 | ||
8024 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
8025 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
8026 | { | |
8027 | u8 nss; | |
8028 | ||
8029 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
8030 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
8031 | vht_mcs_map >>= 2; | |
8032 | } | |
8033 | } | |
8034 | ||
8035 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
8036 | struct nl80211_txrate_vht *txrate, | |
8037 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
8038 | { | |
8039 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8040 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
8041 | u8 i; | |
8042 | ||
8043 | if (!sband->vht_cap.vht_supported) | |
8044 | return false; | |
8045 | ||
8046 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
8047 | ||
8048 | /* Build vht_mcs_mask from VHT capabilities */ | |
8049 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
8050 | ||
8051 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
8052 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
8053 | mcs[i] = txrate->mcs[i]; | |
8054 | else | |
8055 | return false; | |
8056 | } | |
8057 | ||
8058 | return true; | |
8059 | } | |
8060 | ||
b54452b0 | 8061 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
8062 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
8063 | .len = NL80211_MAX_SUPP_RATES }, | |
d1e33e65 JD |
8064 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
8065 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
204e35a9 | 8066 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
0b9323f6 | 8067 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
13ae75b1 JM |
8068 | }; |
8069 | ||
8070 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
8071 | struct genl_info *info) | |
8072 | { | |
8073 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 8074 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 8075 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
8076 | int rem, i; |
8077 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
8078 | struct nlattr *tx_rates; |
8079 | struct ieee80211_supported_band *sband; | |
204e35a9 | 8080 | u16 vht_tx_mcs_map; |
13ae75b1 | 8081 | |
4c476991 JB |
8082 | if (!rdev->ops->set_bitrate_mask) |
8083 | return -EOPNOTSUPP; | |
13ae75b1 JM |
8084 | |
8085 | memset(&mask, 0, sizeof(mask)); | |
8086 | /* Default to all rates enabled */ | |
8087 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
8088 | sband = rdev->wiphy.bands[i]; | |
7869303b JD |
8089 | |
8090 | if (!sband) | |
8091 | continue; | |
8092 | ||
8093 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; | |
d1e33e65 | 8094 | memcpy(mask.control[i].ht_mcs, |
7869303b | 8095 | sband->ht_cap.mcs.rx_mask, |
d1e33e65 | 8096 | sizeof(mask.control[i].ht_mcs)); |
204e35a9 JD |
8097 | |
8098 | if (!sband->vht_cap.vht_supported) | |
8099 | continue; | |
8100 | ||
8101 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8102 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); | |
13ae75b1 JM |
8103 | } |
8104 | ||
b9243ab0 JD |
8105 | /* if no rates are given set it back to the defaults */ |
8106 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
8107 | goto out; | |
8108 | ||
13ae75b1 JM |
8109 | /* |
8110 | * The nested attribute uses enum nl80211_band as the index. This maps | |
8111 | * directly to the enum ieee80211_band values used in cfg80211. | |
8112 | */ | |
24db78c0 | 8113 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
ae811e21 | 8114 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
13ae75b1 | 8115 | enum ieee80211_band band = nla_type(tx_rates); |
ae811e21 JB |
8116 | int err; |
8117 | ||
4c476991 JB |
8118 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
8119 | return -EINVAL; | |
13ae75b1 | 8120 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
8121 | if (sband == NULL) |
8122 | return -EINVAL; | |
ae811e21 JB |
8123 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
8124 | nla_len(tx_rates), nl80211_txattr_policy); | |
8125 | if (err) | |
8126 | return err; | |
13ae75b1 JM |
8127 | if (tb[NL80211_TXRATE_LEGACY]) { |
8128 | mask.control[band].legacy = rateset_to_mask( | |
8129 | sband, | |
8130 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
8131 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
8132 | if ((mask.control[band].legacy == 0) && |
8133 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
8134 | return -EINVAL; | |
24db78c0 | 8135 | } |
d1e33e65 | 8136 | if (tb[NL80211_TXRATE_HT]) { |
24db78c0 SW |
8137 | if (!ht_rateset_to_mask( |
8138 | sband, | |
d1e33e65 JD |
8139 | nla_data(tb[NL80211_TXRATE_HT]), |
8140 | nla_len(tb[NL80211_TXRATE_HT]), | |
8141 | mask.control[band].ht_mcs)) | |
24db78c0 SW |
8142 | return -EINVAL; |
8143 | } | |
204e35a9 JD |
8144 | if (tb[NL80211_TXRATE_VHT]) { |
8145 | if (!vht_set_mcs_mask( | |
8146 | sband, | |
8147 | nla_data(tb[NL80211_TXRATE_VHT]), | |
8148 | mask.control[band].vht_mcs)) | |
8149 | return -EINVAL; | |
8150 | } | |
0b9323f6 JD |
8151 | if (tb[NL80211_TXRATE_GI]) { |
8152 | mask.control[band].gi = | |
8153 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
8154 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
8155 | return -EINVAL; | |
8156 | } | |
24db78c0 SW |
8157 | |
8158 | if (mask.control[band].legacy == 0) { | |
204e35a9 JD |
8159 | /* don't allow empty legacy rates if HT or VHT |
8160 | * are not even supported. | |
8161 | */ | |
8162 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
8163 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
24db78c0 SW |
8164 | return -EINVAL; |
8165 | ||
8166 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
d1e33e65 | 8167 | if (mask.control[band].ht_mcs[i]) |
204e35a9 JD |
8168 | goto out; |
8169 | ||
8170 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
8171 | if (mask.control[band].vht_mcs[i]) | |
8172 | goto out; | |
24db78c0 SW |
8173 | |
8174 | /* legacy and mcs rates may not be both empty */ | |
204e35a9 | 8175 | return -EINVAL; |
13ae75b1 JM |
8176 | } |
8177 | } | |
8178 | ||
b9243ab0 | 8179 | out: |
e35e4d28 | 8180 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
8181 | } |
8182 | ||
2e161f78 | 8183 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8184 | { |
4c476991 | 8185 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8186 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 8187 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
8188 | |
8189 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
8190 | return -EINVAL; | |
8191 | ||
2e161f78 JB |
8192 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
8193 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 8194 | |
71bbc994 JB |
8195 | switch (wdev->iftype) { |
8196 | case NL80211_IFTYPE_STATION: | |
8197 | case NL80211_IFTYPE_ADHOC: | |
8198 | case NL80211_IFTYPE_P2P_CLIENT: | |
8199 | case NL80211_IFTYPE_AP: | |
8200 | case NL80211_IFTYPE_AP_VLAN: | |
8201 | case NL80211_IFTYPE_MESH_POINT: | |
8202 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8203 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8204 | break; |
8205 | default: | |
4c476991 | 8206 | return -EOPNOTSUPP; |
71bbc994 | 8207 | } |
026331c4 JM |
8208 | |
8209 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
8210 | if (!rdev->ops->mgmt_tx) |
8211 | return -EOPNOTSUPP; | |
026331c4 | 8212 | |
15e47304 | 8213 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
8214 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
8215 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
8216 | } |
8217 | ||
2e161f78 | 8218 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8219 | { |
4c476991 | 8220 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8221 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 8222 | struct cfg80211_chan_def chandef; |
026331c4 | 8223 | int err; |
d64d373f | 8224 | void *hdr = NULL; |
026331c4 | 8225 | u64 cookie; |
e247bd90 | 8226 | struct sk_buff *msg = NULL; |
b176e629 AO |
8227 | struct cfg80211_mgmt_tx_params params = { |
8228 | .dont_wait_for_ack = | |
8229 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
8230 | }; | |
026331c4 | 8231 | |
683b6d3b | 8232 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
8233 | return -EINVAL; |
8234 | ||
4c476991 JB |
8235 | if (!rdev->ops->mgmt_tx) |
8236 | return -EOPNOTSUPP; | |
026331c4 | 8237 | |
71bbc994 | 8238 | switch (wdev->iftype) { |
ea141b75 AQ |
8239 | case NL80211_IFTYPE_P2P_DEVICE: |
8240 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
8241 | return -EINVAL; | |
71bbc994 JB |
8242 | case NL80211_IFTYPE_STATION: |
8243 | case NL80211_IFTYPE_ADHOC: | |
8244 | case NL80211_IFTYPE_P2P_CLIENT: | |
8245 | case NL80211_IFTYPE_AP: | |
8246 | case NL80211_IFTYPE_AP_VLAN: | |
8247 | case NL80211_IFTYPE_MESH_POINT: | |
8248 | case NL80211_IFTYPE_P2P_GO: | |
8249 | break; | |
8250 | default: | |
4c476991 | 8251 | return -EOPNOTSUPP; |
71bbc994 | 8252 | } |
026331c4 | 8253 | |
f7ca38df | 8254 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 8255 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 8256 | return -EINVAL; |
b176e629 | 8257 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
8258 | |
8259 | /* | |
8260 | * We should wait on the channel for at least a minimum amount | |
8261 | * of time (10ms) but no longer than the driver supports. | |
8262 | */ | |
b176e629 AO |
8263 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
8264 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc JB |
8265 | return -EINVAL; |
8266 | ||
f7ca38df JB |
8267 | } |
8268 | ||
b176e629 | 8269 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 8270 | |
b176e629 | 8271 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
8272 | return -EINVAL; |
8273 | ||
b176e629 | 8274 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 8275 | |
ea141b75 AQ |
8276 | /* get the channel if any has been specified, otherwise pass NULL to |
8277 | * the driver. The latter will use the current one | |
8278 | */ | |
8279 | chandef.chan = NULL; | |
8280 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
8281 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
8282 | if (err) | |
8283 | return err; | |
8284 | } | |
8285 | ||
b176e629 | 8286 | if (!chandef.chan && params.offchan) |
ea141b75 | 8287 | return -EINVAL; |
026331c4 | 8288 | |
34d22ce2 AO |
8289 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
8290 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
8291 | ||
8292 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
8293 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8294 | int i; | |
8295 | ||
8296 | if (len % sizeof(u16)) | |
8297 | return -EINVAL; | |
8298 | ||
8299 | params.n_csa_offsets = len / sizeof(u16); | |
8300 | params.csa_offsets = | |
8301 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8302 | ||
8303 | /* check that all the offsets fit the frame */ | |
8304 | for (i = 0; i < params.n_csa_offsets; i++) { | |
8305 | if (params.csa_offsets[i] >= params.len) | |
8306 | return -EINVAL; | |
8307 | } | |
8308 | } | |
8309 | ||
b176e629 | 8310 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
8311 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
8312 | if (!msg) | |
8313 | return -ENOMEM; | |
026331c4 | 8314 | |
15e47304 | 8315 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 8316 | NL80211_CMD_FRAME); |
cb35fba3 DC |
8317 | if (!hdr) { |
8318 | err = -ENOBUFS; | |
e247bd90 JB |
8319 | goto free_msg; |
8320 | } | |
026331c4 | 8321 | } |
e247bd90 | 8322 | |
b176e629 AO |
8323 | params.chan = chandef.chan; |
8324 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
8325 | if (err) |
8326 | goto free_msg; | |
8327 | ||
e247bd90 | 8328 | if (msg) { |
9360ffd1 DM |
8329 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8330 | goto nla_put_failure; | |
026331c4 | 8331 | |
e247bd90 JB |
8332 | genlmsg_end(msg, hdr); |
8333 | return genlmsg_reply(msg, info); | |
8334 | } | |
8335 | ||
8336 | return 0; | |
026331c4 JM |
8337 | |
8338 | nla_put_failure: | |
8339 | err = -ENOBUFS; | |
8340 | free_msg: | |
8341 | nlmsg_free(msg); | |
026331c4 JM |
8342 | return err; |
8343 | } | |
8344 | ||
f7ca38df JB |
8345 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
8346 | { | |
8347 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 8348 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
8349 | u64 cookie; |
8350 | ||
8351 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8352 | return -EINVAL; | |
8353 | ||
8354 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
8355 | return -EOPNOTSUPP; | |
8356 | ||
71bbc994 JB |
8357 | switch (wdev->iftype) { |
8358 | case NL80211_IFTYPE_STATION: | |
8359 | case NL80211_IFTYPE_ADHOC: | |
8360 | case NL80211_IFTYPE_P2P_CLIENT: | |
8361 | case NL80211_IFTYPE_AP: | |
8362 | case NL80211_IFTYPE_AP_VLAN: | |
8363 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8364 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8365 | break; |
8366 | default: | |
f7ca38df | 8367 | return -EOPNOTSUPP; |
71bbc994 | 8368 | } |
f7ca38df JB |
8369 | |
8370 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
8371 | ||
e35e4d28 | 8372 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
8373 | } |
8374 | ||
ffb9eb3d KV |
8375 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
8376 | { | |
4c476991 | 8377 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 8378 | struct wireless_dev *wdev; |
4c476991 | 8379 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8380 | u8 ps_state; |
8381 | bool state; | |
8382 | int err; | |
8383 | ||
4c476991 JB |
8384 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
8385 | return -EINVAL; | |
ffb9eb3d KV |
8386 | |
8387 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
8388 | ||
4c476991 JB |
8389 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
8390 | return -EINVAL; | |
ffb9eb3d KV |
8391 | |
8392 | wdev = dev->ieee80211_ptr; | |
8393 | ||
4c476991 JB |
8394 | if (!rdev->ops->set_power_mgmt) |
8395 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8396 | |
8397 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
8398 | ||
8399 | if (state == wdev->ps) | |
4c476991 | 8400 | return 0; |
ffb9eb3d | 8401 | |
e35e4d28 | 8402 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
8403 | if (!err) |
8404 | wdev->ps = state; | |
ffb9eb3d KV |
8405 | return err; |
8406 | } | |
8407 | ||
8408 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
8409 | { | |
4c476991 | 8410 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
8411 | enum nl80211_ps_state ps_state; |
8412 | struct wireless_dev *wdev; | |
4c476991 | 8413 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8414 | struct sk_buff *msg; |
8415 | void *hdr; | |
8416 | int err; | |
8417 | ||
ffb9eb3d KV |
8418 | wdev = dev->ieee80211_ptr; |
8419 | ||
4c476991 JB |
8420 | if (!rdev->ops->set_power_mgmt) |
8421 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8422 | |
8423 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
8424 | if (!msg) |
8425 | return -ENOMEM; | |
ffb9eb3d | 8426 | |
15e47304 | 8427 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
8428 | NL80211_CMD_GET_POWER_SAVE); |
8429 | if (!hdr) { | |
4c476991 | 8430 | err = -ENOBUFS; |
ffb9eb3d KV |
8431 | goto free_msg; |
8432 | } | |
8433 | ||
8434 | if (wdev->ps) | |
8435 | ps_state = NL80211_PS_ENABLED; | |
8436 | else | |
8437 | ps_state = NL80211_PS_DISABLED; | |
8438 | ||
9360ffd1 DM |
8439 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
8440 | goto nla_put_failure; | |
ffb9eb3d KV |
8441 | |
8442 | genlmsg_end(msg, hdr); | |
4c476991 | 8443 | return genlmsg_reply(msg, info); |
ffb9eb3d | 8444 | |
4c476991 | 8445 | nla_put_failure: |
ffb9eb3d | 8446 | err = -ENOBUFS; |
4c476991 | 8447 | free_msg: |
ffb9eb3d | 8448 | nlmsg_free(msg); |
ffb9eb3d KV |
8449 | return err; |
8450 | } | |
8451 | ||
94e860f1 JB |
8452 | static const struct nla_policy |
8453 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
8454 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
8455 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
8456 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
8457 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
8458 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
8459 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
8460 | }; |
8461 | ||
84f10708 | 8462 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 8463 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
8464 | { |
8465 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 8466 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8467 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 8468 | |
d9d8b019 | 8469 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
8470 | return -EINVAL; |
8471 | ||
84f10708 TP |
8472 | if (!rdev->ops->set_cqm_txe_config) |
8473 | return -EOPNOTSUPP; | |
8474 | ||
8475 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
8476 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
8477 | return -EOPNOTSUPP; | |
8478 | ||
e35e4d28 | 8479 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
8480 | } |
8481 | ||
d6dc1a38 JO |
8482 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
8483 | s32 threshold, u32 hysteresis) | |
8484 | { | |
4c476991 | 8485 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 8486 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8487 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
8488 | |
8489 | if (threshold > 0) | |
8490 | return -EINVAL; | |
8491 | ||
1da5fcc8 JB |
8492 | /* disabling - hysteresis should also be zero then */ |
8493 | if (threshold == 0) | |
8494 | hysteresis = 0; | |
d6dc1a38 | 8495 | |
4c476991 JB |
8496 | if (!rdev->ops->set_cqm_rssi_config) |
8497 | return -EOPNOTSUPP; | |
d6dc1a38 | 8498 | |
074ac8df | 8499 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8500 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8501 | return -EOPNOTSUPP; | |
d6dc1a38 | 8502 | |
e35e4d28 | 8503 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
8504 | } |
8505 | ||
8506 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
8507 | { | |
8508 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
8509 | struct nlattr *cqm; | |
8510 | int err; | |
8511 | ||
8512 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
8513 | if (!cqm) |
8514 | return -EINVAL; | |
d6dc1a38 JO |
8515 | |
8516 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
8517 | nl80211_attr_cqm_policy); | |
8518 | if (err) | |
1da5fcc8 | 8519 | return err; |
d6dc1a38 JO |
8520 | |
8521 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
8522 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
8523 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
8524 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 8525 | |
1da5fcc8 JB |
8526 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
8527 | } | |
8528 | ||
8529 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
8530 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
8531 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
8532 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
8533 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
8534 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
8535 | ||
8536 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
8537 | } | |
8538 | ||
8539 | return -EINVAL; | |
d6dc1a38 JO |
8540 | } |
8541 | ||
6e0bd6c3 RL |
8542 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
8543 | { | |
8544 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8545 | struct net_device *dev = info->user_ptr[1]; | |
8546 | struct ocb_setup setup = {}; | |
8547 | int err; | |
8548 | ||
8549 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | |
8550 | if (err) | |
8551 | return err; | |
8552 | ||
8553 | return cfg80211_join_ocb(rdev, dev, &setup); | |
8554 | } | |
8555 | ||
8556 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | |
8557 | { | |
8558 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8559 | struct net_device *dev = info->user_ptr[1]; | |
8560 | ||
8561 | return cfg80211_leave_ocb(rdev, dev); | |
8562 | } | |
8563 | ||
29cbe68c JB |
8564 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
8565 | { | |
8566 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8567 | struct net_device *dev = info->user_ptr[1]; | |
8568 | struct mesh_config cfg; | |
c80d545d | 8569 | struct mesh_setup setup; |
29cbe68c JB |
8570 | int err; |
8571 | ||
8572 | /* start with default */ | |
8573 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 8574 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 8575 | |
24bdd9f4 | 8576 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 8577 | /* and parse parameters if given */ |
24bdd9f4 | 8578 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
8579 | if (err) |
8580 | return err; | |
8581 | } | |
8582 | ||
8583 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
8584 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
8585 | return -EINVAL; | |
8586 | ||
c80d545d JC |
8587 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
8588 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
8589 | ||
4bb62344 CYY |
8590 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8591 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
8592 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8593 | return -EINVAL; | |
8594 | ||
9bdbf04d MP |
8595 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
8596 | setup.beacon_interval = | |
8597 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
8598 | if (setup.beacon_interval < 10 || | |
8599 | setup.beacon_interval > 10000) | |
8600 | return -EINVAL; | |
8601 | } | |
8602 | ||
8603 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
8604 | setup.dtim_period = | |
8605 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
8606 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
8607 | return -EINVAL; | |
8608 | } | |
8609 | ||
c80d545d JC |
8610 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
8611 | /* parse additional setup parameters if given */ | |
8612 | err = nl80211_parse_mesh_setup(info, &setup); | |
8613 | if (err) | |
8614 | return err; | |
8615 | } | |
8616 | ||
d37bb18a TP |
8617 | if (setup.user_mpm) |
8618 | cfg.auto_open_plinks = false; | |
8619 | ||
cc1d2806 | 8620 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
8621 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
8622 | if (err) | |
8623 | return err; | |
cc1d2806 JB |
8624 | } else { |
8625 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 8626 | setup.chandef.chan = NULL; |
cc1d2806 JB |
8627 | } |
8628 | ||
ffb3cf30 AN |
8629 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8630 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8631 | int n_rates = | |
8632 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8633 | struct ieee80211_supported_band *sband; | |
8634 | ||
8635 | if (!setup.chandef.chan) | |
8636 | return -EINVAL; | |
8637 | ||
8638 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
8639 | ||
8640 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
8641 | &setup.basic_rates); | |
8642 | if (err) | |
8643 | return err; | |
8644 | } | |
8645 | ||
c80d545d | 8646 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
8647 | } |
8648 | ||
8649 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
8650 | { | |
8651 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8652 | struct net_device *dev = info->user_ptr[1]; | |
8653 | ||
8654 | return cfg80211_leave_mesh(rdev, dev); | |
8655 | } | |
8656 | ||
dfb89c56 | 8657 | #ifdef CONFIG_PM |
bb92d199 AK |
8658 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
8659 | struct cfg80211_registered_device *rdev) | |
8660 | { | |
6abb9cb9 | 8661 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
8662 | struct nlattr *nl_pats, *nl_pat; |
8663 | int i, pat_len; | |
8664 | ||
6abb9cb9 | 8665 | if (!wowlan->n_patterns) |
bb92d199 AK |
8666 | return 0; |
8667 | ||
8668 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
8669 | if (!nl_pats) | |
8670 | return -ENOBUFS; | |
8671 | ||
6abb9cb9 | 8672 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
8673 | nl_pat = nla_nest_start(msg, i + 1); |
8674 | if (!nl_pat) | |
8675 | return -ENOBUFS; | |
6abb9cb9 | 8676 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 8677 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 8678 | wowlan->patterns[i].mask) || |
50ac6607 AK |
8679 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
8680 | wowlan->patterns[i].pattern) || | |
8681 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 8682 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
8683 | return -ENOBUFS; |
8684 | nla_nest_end(msg, nl_pat); | |
8685 | } | |
8686 | nla_nest_end(msg, nl_pats); | |
8687 | ||
8688 | return 0; | |
8689 | } | |
8690 | ||
2a0e047e JB |
8691 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
8692 | struct cfg80211_wowlan_tcp *tcp) | |
8693 | { | |
8694 | struct nlattr *nl_tcp; | |
8695 | ||
8696 | if (!tcp) | |
8697 | return 0; | |
8698 | ||
8699 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
8700 | if (!nl_tcp) | |
8701 | return -ENOBUFS; | |
8702 | ||
8703 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
8704 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
8705 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
8706 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
8707 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
8708 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
8709 | tcp->payload_len, tcp->payload) || | |
8710 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
8711 | tcp->data_interval) || | |
8712 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
8713 | tcp->wake_len, tcp->wake_data) || | |
8714 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
8715 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
8716 | return -ENOBUFS; | |
8717 | ||
8718 | if (tcp->payload_seq.len && | |
8719 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
8720 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
8721 | return -ENOBUFS; | |
8722 | ||
8723 | if (tcp->payload_tok.len && | |
8724 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
8725 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
8726 | &tcp->payload_tok)) | |
8727 | return -ENOBUFS; | |
8728 | ||
e248ad30 JB |
8729 | nla_nest_end(msg, nl_tcp); |
8730 | ||
2a0e047e JB |
8731 | return 0; |
8732 | } | |
8733 | ||
ff1b6e69 JB |
8734 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
8735 | { | |
8736 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8737 | struct sk_buff *msg; | |
8738 | void *hdr; | |
2a0e047e | 8739 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 8740 | |
964dc9e2 | 8741 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
8742 | return -EOPNOTSUPP; |
8743 | ||
6abb9cb9 | 8744 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 8745 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
8746 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
8747 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
8748 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
8749 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
8750 | } |
8751 | ||
8752 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
8753 | if (!msg) |
8754 | return -ENOMEM; | |
8755 | ||
15e47304 | 8756 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
8757 | NL80211_CMD_GET_WOWLAN); |
8758 | if (!hdr) | |
8759 | goto nla_put_failure; | |
8760 | ||
6abb9cb9 | 8761 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
8762 | struct nlattr *nl_wowlan; |
8763 | ||
8764 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
8765 | if (!nl_wowlan) | |
8766 | goto nla_put_failure; | |
8767 | ||
6abb9cb9 | 8768 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 8769 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 8770 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 8771 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 8772 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 8773 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 8774 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 8775 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 8776 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 8777 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 8778 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 8779 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 8780 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
8781 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
8782 | goto nla_put_failure; | |
2a0e047e | 8783 | |
bb92d199 AK |
8784 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
8785 | goto nla_put_failure; | |
2a0e047e | 8786 | |
6abb9cb9 JB |
8787 | if (nl80211_send_wowlan_tcp(msg, |
8788 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e JB |
8789 | goto nla_put_failure; |
8790 | ||
ff1b6e69 JB |
8791 | nla_nest_end(msg, nl_wowlan); |
8792 | } | |
8793 | ||
8794 | genlmsg_end(msg, hdr); | |
8795 | return genlmsg_reply(msg, info); | |
8796 | ||
8797 | nla_put_failure: | |
8798 | nlmsg_free(msg); | |
8799 | return -ENOBUFS; | |
8800 | } | |
8801 | ||
2a0e047e JB |
8802 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
8803 | struct nlattr *attr, | |
8804 | struct cfg80211_wowlan *trig) | |
8805 | { | |
8806 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
8807 | struct cfg80211_wowlan_tcp *cfg; | |
8808 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
8809 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
8810 | u32 size; | |
8811 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
8812 | int err, port; | |
8813 | ||
964dc9e2 | 8814 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
8815 | return -EINVAL; |
8816 | ||
8817 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
8818 | nla_data(attr), nla_len(attr), | |
8819 | nl80211_wowlan_tcp_policy); | |
8820 | if (err) | |
8821 | return err; | |
8822 | ||
8823 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
8824 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
8825 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
8826 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
8827 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
8828 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
8829 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
8830 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
8831 | return -EINVAL; | |
8832 | ||
8833 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 8834 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
8835 | return -EINVAL; |
8836 | ||
8837 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 8838 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 8839 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
8840 | return -EINVAL; |
8841 | ||
8842 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 8843 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
8844 | return -EINVAL; |
8845 | ||
8846 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
8847 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
8848 | return -EINVAL; | |
8849 | ||
8850 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
8851 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8852 | ||
8853 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8854 | tokens_size = tokln - sizeof(*tok); | |
8855 | ||
8856 | if (!tok->len || tokens_size % tok->len) | |
8857 | return -EINVAL; | |
964dc9e2 | 8858 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 8859 | return -EINVAL; |
964dc9e2 | 8860 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 8861 | return -EINVAL; |
964dc9e2 | 8862 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 8863 | return -EINVAL; |
964dc9e2 | 8864 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
8865 | return -EINVAL; |
8866 | if (tok->offset + tok->len > data_size) | |
8867 | return -EINVAL; | |
8868 | } | |
8869 | ||
8870 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
8871 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 8872 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
8873 | return -EINVAL; |
8874 | if (seq->len == 0 || seq->len > 4) | |
8875 | return -EINVAL; | |
8876 | if (seq->len + seq->offset > data_size) | |
8877 | return -EINVAL; | |
8878 | } | |
8879 | ||
8880 | size = sizeof(*cfg); | |
8881 | size += data_size; | |
8882 | size += wake_size + wake_mask_size; | |
8883 | size += tokens_size; | |
8884 | ||
8885 | cfg = kzalloc(size, GFP_KERNEL); | |
8886 | if (!cfg) | |
8887 | return -ENOMEM; | |
8888 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
8889 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
8890 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
8891 | ETH_ALEN); | |
8892 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
8893 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
8894 | else | |
8895 | port = 0; | |
8896 | #ifdef CONFIG_INET | |
8897 | /* allocate a socket and port for it and use it */ | |
8898 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
8899 | IPPROTO_TCP, &cfg->sock, 1); | |
8900 | if (err) { | |
8901 | kfree(cfg); | |
8902 | return err; | |
8903 | } | |
8904 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
8905 | sock_release(cfg->sock); | |
8906 | kfree(cfg); | |
8907 | return -EADDRINUSE; | |
8908 | } | |
8909 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
8910 | #else | |
8911 | if (!port) { | |
8912 | kfree(cfg); | |
8913 | return -EINVAL; | |
8914 | } | |
8915 | cfg->src_port = port; | |
8916 | #endif | |
8917 | ||
8918 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
8919 | cfg->payload_len = data_size; | |
8920 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
8921 | memcpy((void *)cfg->payload, | |
8922 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
8923 | data_size); | |
8924 | if (seq) | |
8925 | cfg->payload_seq = *seq; | |
8926 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
8927 | cfg->wake_len = wake_size; | |
8928 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
8929 | memcpy((void *)cfg->wake_data, | |
8930 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
8931 | wake_size); | |
8932 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
8933 | data_size + wake_size; | |
8934 | memcpy((void *)cfg->wake_mask, | |
8935 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
8936 | wake_mask_size); | |
8937 | if (tok) { | |
8938 | cfg->tokens_size = tokens_size; | |
8939 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
8940 | } | |
8941 | ||
8942 | trig->tcp = cfg; | |
8943 | ||
8944 | return 0; | |
8945 | } | |
8946 | ||
8cd4d456 LC |
8947 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
8948 | const struct wiphy_wowlan_support *wowlan, | |
8949 | struct nlattr *attr, | |
8950 | struct cfg80211_wowlan *trig) | |
8951 | { | |
8952 | struct nlattr **tb; | |
8953 | int err; | |
8954 | ||
8955 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); | |
8956 | if (!tb) | |
8957 | return -ENOMEM; | |
8958 | ||
8959 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | |
8960 | err = -EOPNOTSUPP; | |
8961 | goto out; | |
8962 | } | |
8963 | ||
8964 | err = nla_parse(tb, NL80211_ATTR_MAX, | |
8965 | nla_data(attr), nla_len(attr), | |
8966 | nl80211_policy); | |
8967 | if (err) | |
8968 | goto out; | |
8969 | ||
ad2b26ab | 8970 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
8cd4d456 LC |
8971 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
8972 | if (err) | |
8973 | trig->nd_config = NULL; | |
8974 | ||
8975 | out: | |
8976 | kfree(tb); | |
8977 | return err; | |
8978 | } | |
8979 | ||
ff1b6e69 JB |
8980 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
8981 | { | |
8982 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8983 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 8984 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 8985 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 8986 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 8987 | int err, i; |
6abb9cb9 | 8988 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 8989 | |
964dc9e2 | 8990 | if (!wowlan) |
ff1b6e69 JB |
8991 | return -EOPNOTSUPP; |
8992 | ||
ae33bd81 JB |
8993 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
8994 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 8995 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
8996 | goto set_wakeup; |
8997 | } | |
ff1b6e69 JB |
8998 | |
8999 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
9000 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9001 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9002 | nl80211_wowlan_policy); | |
9003 | if (err) | |
9004 | return err; | |
9005 | ||
9006 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
9007 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
9008 | return -EINVAL; | |
9009 | new_triggers.any = true; | |
9010 | } | |
9011 | ||
9012 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
9013 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
9014 | return -EINVAL; | |
9015 | new_triggers.disconnect = true; | |
9016 | } | |
9017 | ||
9018 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
9019 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
9020 | return -EINVAL; | |
9021 | new_triggers.magic_pkt = true; | |
9022 | } | |
9023 | ||
77dbbb13 JB |
9024 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
9025 | return -EINVAL; | |
9026 | ||
9027 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
9028 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
9029 | return -EINVAL; | |
9030 | new_triggers.gtk_rekey_failure = true; | |
9031 | } | |
9032 | ||
9033 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
9034 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
9035 | return -EINVAL; | |
9036 | new_triggers.eap_identity_req = true; | |
9037 | } | |
9038 | ||
9039 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
9040 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
9041 | return -EINVAL; | |
9042 | new_triggers.four_way_handshake = true; | |
9043 | } | |
9044 | ||
9045 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
9046 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
9047 | return -EINVAL; | |
9048 | new_triggers.rfkill_release = true; | |
9049 | } | |
9050 | ||
ff1b6e69 JB |
9051 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
9052 | struct nlattr *pat; | |
9053 | int n_patterns = 0; | |
bb92d199 | 9054 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 9055 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 JB |
9056 | |
9057 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9058 | rem) | |
9059 | n_patterns++; | |
9060 | if (n_patterns > wowlan->n_patterns) | |
9061 | return -EINVAL; | |
9062 | ||
9063 | new_triggers.patterns = kcalloc(n_patterns, | |
9064 | sizeof(new_triggers.patterns[0]), | |
9065 | GFP_KERNEL); | |
9066 | if (!new_triggers.patterns) | |
9067 | return -ENOMEM; | |
9068 | ||
9069 | new_triggers.n_patterns = n_patterns; | |
9070 | i = 0; | |
9071 | ||
9072 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9073 | rem) { | |
922bd80f JB |
9074 | u8 *mask_pat; |
9075 | ||
50ac6607 AK |
9076 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9077 | nla_len(pat), NULL); | |
ff1b6e69 | 9078 | err = -EINVAL; |
50ac6607 AK |
9079 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
9080 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 9081 | goto error; |
50ac6607 | 9082 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 9083 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 9084 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
9085 | goto error; |
9086 | if (pat_len > wowlan->pattern_max_len || | |
9087 | pat_len < wowlan->pattern_min_len) | |
9088 | goto error; | |
9089 | ||
50ac6607 | 9090 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
9091 | pkt_offset = 0; |
9092 | else | |
9093 | pkt_offset = nla_get_u32( | |
50ac6607 | 9094 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
9095 | if (pkt_offset > wowlan->max_pkt_offset) |
9096 | goto error; | |
9097 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
9098 | ||
922bd80f JB |
9099 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9100 | if (!mask_pat) { | |
ff1b6e69 JB |
9101 | err = -ENOMEM; |
9102 | goto error; | |
9103 | } | |
922bd80f JB |
9104 | new_triggers.patterns[i].mask = mask_pat; |
9105 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 9106 | mask_len); |
922bd80f JB |
9107 | mask_pat += mask_len; |
9108 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 9109 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 9110 | memcpy(mask_pat, |
50ac6607 | 9111 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
9112 | pat_len); |
9113 | i++; | |
9114 | } | |
9115 | } | |
9116 | ||
2a0e047e JB |
9117 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
9118 | err = nl80211_parse_wowlan_tcp( | |
9119 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
9120 | &new_triggers); | |
9121 | if (err) | |
9122 | goto error; | |
9123 | } | |
9124 | ||
8cd4d456 LC |
9125 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
9126 | err = nl80211_parse_wowlan_nd( | |
9127 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | |
9128 | &new_triggers); | |
9129 | if (err) | |
9130 | goto error; | |
9131 | } | |
9132 | ||
ae33bd81 JB |
9133 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
9134 | if (!ntrig) { | |
9135 | err = -ENOMEM; | |
9136 | goto error; | |
ff1b6e69 | 9137 | } |
ae33bd81 | 9138 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 9139 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 9140 | |
ae33bd81 | 9141 | set_wakeup: |
6abb9cb9 JB |
9142 | if (rdev->ops->set_wakeup && |
9143 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
9144 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 9145 | |
ff1b6e69 JB |
9146 | return 0; |
9147 | error: | |
9148 | for (i = 0; i < new_triggers.n_patterns; i++) | |
9149 | kfree(new_triggers.patterns[i].mask); | |
9150 | kfree(new_triggers.patterns); | |
2a0e047e JB |
9151 | if (new_triggers.tcp && new_triggers.tcp->sock) |
9152 | sock_release(new_triggers.tcp->sock); | |
9153 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
9154 | return err; |
9155 | } | |
dfb89c56 | 9156 | #endif |
ff1b6e69 | 9157 | |
be29b99a AK |
9158 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
9159 | struct cfg80211_registered_device *rdev) | |
9160 | { | |
9161 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
9162 | int i, j, pat_len; | |
9163 | struct cfg80211_coalesce_rules *rule; | |
9164 | ||
9165 | if (!rdev->coalesce->n_rules) | |
9166 | return 0; | |
9167 | ||
9168 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
9169 | if (!nl_rules) | |
9170 | return -ENOBUFS; | |
9171 | ||
9172 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
9173 | nl_rule = nla_nest_start(msg, i + 1); | |
9174 | if (!nl_rule) | |
9175 | return -ENOBUFS; | |
9176 | ||
9177 | rule = &rdev->coalesce->rules[i]; | |
9178 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
9179 | rule->delay)) | |
9180 | return -ENOBUFS; | |
9181 | ||
9182 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
9183 | rule->condition)) | |
9184 | return -ENOBUFS; | |
9185 | ||
9186 | nl_pats = nla_nest_start(msg, | |
9187 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
9188 | if (!nl_pats) | |
9189 | return -ENOBUFS; | |
9190 | ||
9191 | for (j = 0; j < rule->n_patterns; j++) { | |
9192 | nl_pat = nla_nest_start(msg, j + 1); | |
9193 | if (!nl_pat) | |
9194 | return -ENOBUFS; | |
9195 | pat_len = rule->patterns[j].pattern_len; | |
9196 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
9197 | DIV_ROUND_UP(pat_len, 8), | |
9198 | rule->patterns[j].mask) || | |
9199 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
9200 | rule->patterns[j].pattern) || | |
9201 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
9202 | rule->patterns[j].pkt_offset)) | |
9203 | return -ENOBUFS; | |
9204 | nla_nest_end(msg, nl_pat); | |
9205 | } | |
9206 | nla_nest_end(msg, nl_pats); | |
9207 | nla_nest_end(msg, nl_rule); | |
9208 | } | |
9209 | nla_nest_end(msg, nl_rules); | |
9210 | ||
9211 | return 0; | |
9212 | } | |
9213 | ||
9214 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9215 | { | |
9216 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9217 | struct sk_buff *msg; | |
9218 | void *hdr; | |
9219 | ||
9220 | if (!rdev->wiphy.coalesce) | |
9221 | return -EOPNOTSUPP; | |
9222 | ||
9223 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9224 | if (!msg) | |
9225 | return -ENOMEM; | |
9226 | ||
9227 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9228 | NL80211_CMD_GET_COALESCE); | |
9229 | if (!hdr) | |
9230 | goto nla_put_failure; | |
9231 | ||
9232 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
9233 | goto nla_put_failure; | |
9234 | ||
9235 | genlmsg_end(msg, hdr); | |
9236 | return genlmsg_reply(msg, info); | |
9237 | ||
9238 | nla_put_failure: | |
9239 | nlmsg_free(msg); | |
9240 | return -ENOBUFS; | |
9241 | } | |
9242 | ||
9243 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
9244 | { | |
9245 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
9246 | int i, j; | |
9247 | struct cfg80211_coalesce_rules *rule; | |
9248 | ||
9249 | if (!coalesce) | |
9250 | return; | |
9251 | ||
9252 | for (i = 0; i < coalesce->n_rules; i++) { | |
9253 | rule = &coalesce->rules[i]; | |
9254 | for (j = 0; j < rule->n_patterns; j++) | |
9255 | kfree(rule->patterns[j].mask); | |
9256 | kfree(rule->patterns); | |
9257 | } | |
9258 | kfree(coalesce->rules); | |
9259 | kfree(coalesce); | |
9260 | rdev->coalesce = NULL; | |
9261 | } | |
9262 | ||
9263 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
9264 | struct nlattr *rule, | |
9265 | struct cfg80211_coalesce_rules *new_rule) | |
9266 | { | |
9267 | int err, i; | |
9268 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9269 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
9270 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
9271 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
9272 | ||
9273 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
9274 | nla_len(rule), nl80211_coalesce_policy); | |
9275 | if (err) | |
9276 | return err; | |
9277 | ||
9278 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
9279 | new_rule->delay = | |
9280 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
9281 | if (new_rule->delay > coalesce->max_delay) | |
9282 | return -EINVAL; | |
9283 | ||
9284 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
9285 | new_rule->condition = | |
9286 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
9287 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
9288 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
9289 | return -EINVAL; | |
9290 | ||
9291 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
9292 | return -EINVAL; | |
9293 | ||
9294 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9295 | rem) | |
9296 | n_patterns++; | |
9297 | if (n_patterns > coalesce->n_patterns) | |
9298 | return -EINVAL; | |
9299 | ||
9300 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
9301 | GFP_KERNEL); | |
9302 | if (!new_rule->patterns) | |
9303 | return -ENOMEM; | |
9304 | ||
9305 | new_rule->n_patterns = n_patterns; | |
9306 | i = 0; | |
9307 | ||
9308 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9309 | rem) { | |
922bd80f JB |
9310 | u8 *mask_pat; |
9311 | ||
be29b99a AK |
9312 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9313 | nla_len(pat), NULL); | |
9314 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
9315 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
9316 | return -EINVAL; | |
9317 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
9318 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
9319 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
9320 | return -EINVAL; | |
9321 | if (pat_len > coalesce->pattern_max_len || | |
9322 | pat_len < coalesce->pattern_min_len) | |
9323 | return -EINVAL; | |
9324 | ||
9325 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
9326 | pkt_offset = 0; | |
9327 | else | |
9328 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
9329 | if (pkt_offset > coalesce->max_pkt_offset) | |
9330 | return -EINVAL; | |
9331 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
9332 | ||
922bd80f JB |
9333 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9334 | if (!mask_pat) | |
be29b99a | 9335 | return -ENOMEM; |
922bd80f JB |
9336 | |
9337 | new_rule->patterns[i].mask = mask_pat; | |
9338 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
9339 | mask_len); | |
9340 | ||
9341 | mask_pat += mask_len; | |
9342 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 9343 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
9344 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
9345 | pat_len); | |
be29b99a AK |
9346 | i++; |
9347 | } | |
9348 | ||
9349 | return 0; | |
9350 | } | |
9351 | ||
9352 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9353 | { | |
9354 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9355 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9356 | struct cfg80211_coalesce new_coalesce = {}; | |
9357 | struct cfg80211_coalesce *n_coalesce; | |
9358 | int err, rem_rule, n_rules = 0, i, j; | |
9359 | struct nlattr *rule; | |
9360 | struct cfg80211_coalesce_rules *tmp_rule; | |
9361 | ||
9362 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
9363 | return -EOPNOTSUPP; | |
9364 | ||
9365 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
9366 | cfg80211_rdev_free_coalesce(rdev); | |
9367 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
9368 | return 0; | |
9369 | } | |
9370 | ||
9371 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9372 | rem_rule) | |
9373 | n_rules++; | |
9374 | if (n_rules > coalesce->n_rules) | |
9375 | return -EINVAL; | |
9376 | ||
9377 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
9378 | GFP_KERNEL); | |
9379 | if (!new_coalesce.rules) | |
9380 | return -ENOMEM; | |
9381 | ||
9382 | new_coalesce.n_rules = n_rules; | |
9383 | i = 0; | |
9384 | ||
9385 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9386 | rem_rule) { | |
9387 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
9388 | &new_coalesce.rules[i]); | |
9389 | if (err) | |
9390 | goto error; | |
9391 | ||
9392 | i++; | |
9393 | } | |
9394 | ||
9395 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
9396 | if (err) | |
9397 | goto error; | |
9398 | ||
9399 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
9400 | if (!n_coalesce) { | |
9401 | err = -ENOMEM; | |
9402 | goto error; | |
9403 | } | |
9404 | cfg80211_rdev_free_coalesce(rdev); | |
9405 | rdev->coalesce = n_coalesce; | |
9406 | ||
9407 | return 0; | |
9408 | error: | |
9409 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
9410 | tmp_rule = &new_coalesce.rules[i]; | |
9411 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
9412 | kfree(tmp_rule->patterns[j].mask); | |
9413 | kfree(tmp_rule->patterns); | |
9414 | } | |
9415 | kfree(new_coalesce.rules); | |
9416 | ||
9417 | return err; | |
9418 | } | |
9419 | ||
e5497d76 JB |
9420 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
9421 | { | |
9422 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9423 | struct net_device *dev = info->user_ptr[1]; | |
9424 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9425 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
9426 | struct cfg80211_gtk_rekey_data rekey_data; | |
9427 | int err; | |
9428 | ||
9429 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
9430 | return -EINVAL; | |
9431 | ||
9432 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
9433 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9434 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9435 | nl80211_rekey_policy); | |
9436 | if (err) | |
9437 | return err; | |
9438 | ||
9439 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
9440 | return -ERANGE; | |
9441 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
9442 | return -ERANGE; | |
9443 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
9444 | return -ERANGE; | |
9445 | ||
78f686ca JB |
9446 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
9447 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | |
9448 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | |
e5497d76 JB |
9449 | |
9450 | wdev_lock(wdev); | |
9451 | if (!wdev->current_bss) { | |
9452 | err = -ENOTCONN; | |
9453 | goto out; | |
9454 | } | |
9455 | ||
9456 | if (!rdev->ops->set_rekey_data) { | |
9457 | err = -EOPNOTSUPP; | |
9458 | goto out; | |
9459 | } | |
9460 | ||
e35e4d28 | 9461 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
9462 | out: |
9463 | wdev_unlock(wdev); | |
9464 | return err; | |
9465 | } | |
9466 | ||
28946da7 JB |
9467 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
9468 | struct genl_info *info) | |
9469 | { | |
9470 | struct net_device *dev = info->user_ptr[1]; | |
9471 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9472 | ||
9473 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9474 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9475 | return -EINVAL; | |
9476 | ||
15e47304 | 9477 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
9478 | return -EBUSY; |
9479 | ||
15e47304 | 9480 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
9481 | return 0; |
9482 | } | |
9483 | ||
7f6cf311 JB |
9484 | static int nl80211_probe_client(struct sk_buff *skb, |
9485 | struct genl_info *info) | |
9486 | { | |
9487 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9488 | struct net_device *dev = info->user_ptr[1]; | |
9489 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9490 | struct sk_buff *msg; | |
9491 | void *hdr; | |
9492 | const u8 *addr; | |
9493 | u64 cookie; | |
9494 | int err; | |
9495 | ||
9496 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9497 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9498 | return -EOPNOTSUPP; | |
9499 | ||
9500 | if (!info->attrs[NL80211_ATTR_MAC]) | |
9501 | return -EINVAL; | |
9502 | ||
9503 | if (!rdev->ops->probe_client) | |
9504 | return -EOPNOTSUPP; | |
9505 | ||
9506 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9507 | if (!msg) | |
9508 | return -ENOMEM; | |
9509 | ||
15e47304 | 9510 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 9511 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
9512 | if (!hdr) { |
9513 | err = -ENOBUFS; | |
7f6cf311 JB |
9514 | goto free_msg; |
9515 | } | |
9516 | ||
9517 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9518 | ||
e35e4d28 | 9519 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
9520 | if (err) |
9521 | goto free_msg; | |
9522 | ||
9360ffd1 DM |
9523 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9524 | goto nla_put_failure; | |
7f6cf311 JB |
9525 | |
9526 | genlmsg_end(msg, hdr); | |
9527 | ||
9528 | return genlmsg_reply(msg, info); | |
9529 | ||
9530 | nla_put_failure: | |
9531 | err = -ENOBUFS; | |
9532 | free_msg: | |
9533 | nlmsg_free(msg); | |
9534 | return err; | |
9535 | } | |
9536 | ||
5e760230 JB |
9537 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
9538 | { | |
9539 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
9540 | struct cfg80211_beacon_registration *reg, *nreg; |
9541 | int rv; | |
5e760230 JB |
9542 | |
9543 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
9544 | return -EOPNOTSUPP; | |
9545 | ||
37c73b5f BG |
9546 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
9547 | if (!nreg) | |
9548 | return -ENOMEM; | |
9549 | ||
9550 | /* First, check if already registered. */ | |
9551 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
9552 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
9553 | if (reg->nlportid == info->snd_portid) { | |
9554 | rv = -EALREADY; | |
9555 | goto out_err; | |
9556 | } | |
9557 | } | |
9558 | /* Add it to the list */ | |
9559 | nreg->nlportid = info->snd_portid; | |
9560 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 9561 | |
37c73b5f | 9562 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
9563 | |
9564 | return 0; | |
37c73b5f BG |
9565 | out_err: |
9566 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
9567 | kfree(nreg); | |
9568 | return rv; | |
5e760230 JB |
9569 | } |
9570 | ||
98104fde JB |
9571 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
9572 | { | |
9573 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9574 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9575 | int err; | |
9576 | ||
9577 | if (!rdev->ops->start_p2p_device) | |
9578 | return -EOPNOTSUPP; | |
9579 | ||
9580 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9581 | return -EOPNOTSUPP; | |
9582 | ||
9583 | if (wdev->p2p_started) | |
9584 | return 0; | |
9585 | ||
b6a55015 LC |
9586 | if (rfkill_blocked(rdev->rfkill)) |
9587 | return -ERFKILL; | |
98104fde | 9588 | |
eeb126e9 | 9589 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
9590 | if (err) |
9591 | return err; | |
9592 | ||
9593 | wdev->p2p_started = true; | |
98104fde | 9594 | rdev->opencount++; |
98104fde JB |
9595 | |
9596 | return 0; | |
9597 | } | |
9598 | ||
9599 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
9600 | { | |
9601 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9602 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9603 | ||
9604 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9605 | return -EOPNOTSUPP; | |
9606 | ||
9607 | if (!rdev->ops->stop_p2p_device) | |
9608 | return -EOPNOTSUPP; | |
9609 | ||
f9f47529 | 9610 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
9611 | |
9612 | return 0; | |
9613 | } | |
9614 | ||
3713b4e3 JB |
9615 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
9616 | struct genl_info *info) | |
9617 | { | |
9618 | void *hdr; | |
9619 | struct sk_buff *msg; | |
9620 | ||
9621 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9622 | if (!msg) | |
9623 | return -ENOMEM; | |
9624 | ||
9625 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9626 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
9627 | if (!hdr) | |
9628 | goto nla_put_failure; | |
9629 | ||
9630 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
9631 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
9632 | goto nla_put_failure; | |
9633 | ||
9634 | genlmsg_end(msg, hdr); | |
9635 | return genlmsg_reply(msg, info); | |
9636 | ||
9637 | nla_put_failure: | |
9638 | kfree_skb(msg); | |
9639 | return -ENOBUFS; | |
9640 | } | |
9641 | ||
355199e0 JM |
9642 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
9643 | { | |
9644 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9645 | struct cfg80211_update_ft_ies_params ft_params; | |
9646 | struct net_device *dev = info->user_ptr[1]; | |
9647 | ||
9648 | if (!rdev->ops->update_ft_ies) | |
9649 | return -EOPNOTSUPP; | |
9650 | ||
9651 | if (!info->attrs[NL80211_ATTR_MDID] || | |
9652 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
9653 | return -EINVAL; | |
9654 | ||
9655 | memset(&ft_params, 0, sizeof(ft_params)); | |
9656 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
9657 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
9658 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9659 | ||
9660 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
9661 | } | |
9662 | ||
5de17984 AS |
9663 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
9664 | struct genl_info *info) | |
9665 | { | |
9666 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9667 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9668 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
9669 | u16 duration; | |
9670 | int ret; | |
9671 | ||
9672 | if (!rdev->ops->crit_proto_start) | |
9673 | return -EOPNOTSUPP; | |
9674 | ||
9675 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
9676 | return -EINVAL; | |
9677 | ||
9678 | if (rdev->crit_proto_nlportid) | |
9679 | return -EBUSY; | |
9680 | ||
9681 | /* determine protocol if provided */ | |
9682 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
9683 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
9684 | ||
9685 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
9686 | return -EINVAL; | |
9687 | ||
9688 | /* timeout must be provided */ | |
9689 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
9690 | return -EINVAL; | |
9691 | ||
9692 | duration = | |
9693 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
9694 | ||
9695 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
9696 | return -ERANGE; | |
9697 | ||
9698 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
9699 | if (!ret) | |
9700 | rdev->crit_proto_nlportid = info->snd_portid; | |
9701 | ||
9702 | return ret; | |
9703 | } | |
9704 | ||
9705 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
9706 | struct genl_info *info) | |
9707 | { | |
9708 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9709 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9710 | ||
9711 | if (!rdev->ops->crit_proto_stop) | |
9712 | return -EOPNOTSUPP; | |
9713 | ||
9714 | if (rdev->crit_proto_nlportid) { | |
9715 | rdev->crit_proto_nlportid = 0; | |
9716 | rdev_crit_proto_stop(rdev, wdev); | |
9717 | } | |
9718 | return 0; | |
9719 | } | |
9720 | ||
ad7e718c JB |
9721 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
9722 | { | |
9723 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9724 | struct wireless_dev *wdev = | |
9725 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
9726 | int i, err; | |
9727 | u32 vid, subcmd; | |
9728 | ||
9729 | if (!rdev->wiphy.vendor_commands) | |
9730 | return -EOPNOTSUPP; | |
9731 | ||
9732 | if (IS_ERR(wdev)) { | |
9733 | err = PTR_ERR(wdev); | |
9734 | if (err != -EINVAL) | |
9735 | return err; | |
9736 | wdev = NULL; | |
9737 | } else if (wdev->wiphy != &rdev->wiphy) { | |
9738 | return -EINVAL; | |
9739 | } | |
9740 | ||
9741 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
9742 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
9743 | return -EINVAL; | |
9744 | ||
9745 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
9746 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
9747 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
9748 | const struct wiphy_vendor_command *vcmd; | |
9749 | void *data = NULL; | |
9750 | int len = 0; | |
9751 | ||
9752 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
9753 | ||
9754 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
9755 | continue; | |
9756 | ||
9757 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
9758 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
9759 | if (!wdev) | |
9760 | return -EINVAL; | |
9761 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
9762 | !wdev->netdev) | |
9763 | return -EINVAL; | |
9764 | ||
9765 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
9766 | if (wdev->netdev && | |
9767 | !netif_running(wdev->netdev)) | |
9768 | return -ENETDOWN; | |
9769 | if (!wdev->netdev && !wdev->p2p_started) | |
9770 | return -ENETDOWN; | |
9771 | } | |
9772 | } else { | |
9773 | wdev = NULL; | |
9774 | } | |
9775 | ||
9776 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
9777 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9778 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9779 | } | |
9780 | ||
9781 | rdev->cur_cmd_info = info; | |
9782 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
9783 | data, len); | |
9784 | rdev->cur_cmd_info = NULL; | |
9785 | return err; | |
9786 | } | |
9787 | ||
9788 | return -EOPNOTSUPP; | |
9789 | } | |
9790 | ||
9791 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | |
9792 | enum nl80211_commands cmd, | |
9793 | enum nl80211_attrs attr, | |
9794 | int approxlen) | |
9795 | { | |
f26cbf40 | 9796 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
9797 | |
9798 | if (WARN_ON(!rdev->cur_cmd_info)) | |
9799 | return NULL; | |
9800 | ||
9801 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, | |
9802 | rdev->cur_cmd_info->snd_portid, | |
9803 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 9804 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
9805 | } |
9806 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
9807 | ||
9808 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
9809 | { | |
9810 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
9811 | void *hdr = ((void **)skb->cb)[1]; | |
9812 | struct nlattr *data = ((void **)skb->cb)[2]; | |
9813 | ||
bd8c78e7 JB |
9814 | /* clear CB data for netlink core to own from now on */ |
9815 | memset(skb->cb, 0, sizeof(skb->cb)); | |
9816 | ||
ad7e718c JB |
9817 | if (WARN_ON(!rdev->cur_cmd_info)) { |
9818 | kfree_skb(skb); | |
9819 | return -EINVAL; | |
9820 | } | |
9821 | ||
9822 | nla_nest_end(skb, data); | |
9823 | genlmsg_end(skb, hdr); | |
9824 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
9825 | } | |
9826 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
9827 | ||
9828 | ||
fa9ffc74 KP |
9829 | static int nl80211_set_qos_map(struct sk_buff *skb, |
9830 | struct genl_info *info) | |
9831 | { | |
9832 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9833 | struct cfg80211_qos_map *qos_map = NULL; | |
9834 | struct net_device *dev = info->user_ptr[1]; | |
9835 | u8 *pos, len, num_des, des_len, des; | |
9836 | int ret; | |
9837 | ||
9838 | if (!rdev->ops->set_qos_map) | |
9839 | return -EOPNOTSUPP; | |
9840 | ||
9841 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
9842 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9843 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9844 | ||
9845 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
9846 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
9847 | return -EINVAL; | |
9848 | ||
9849 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
9850 | if (!qos_map) | |
9851 | return -ENOMEM; | |
9852 | ||
9853 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
9854 | if (num_des) { | |
9855 | des_len = num_des * | |
9856 | sizeof(struct cfg80211_dscp_exception); | |
9857 | memcpy(qos_map->dscp_exception, pos, des_len); | |
9858 | qos_map->num_des = num_des; | |
9859 | for (des = 0; des < num_des; des++) { | |
9860 | if (qos_map->dscp_exception[des].up > 7) { | |
9861 | kfree(qos_map); | |
9862 | return -EINVAL; | |
9863 | } | |
9864 | } | |
9865 | pos += des_len; | |
9866 | } | |
9867 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
9868 | } | |
9869 | ||
9870 | wdev_lock(dev->ieee80211_ptr); | |
9871 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
9872 | if (!ret) | |
9873 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
9874 | wdev_unlock(dev->ieee80211_ptr); | |
9875 | ||
9876 | kfree(qos_map); | |
9877 | return ret; | |
9878 | } | |
9879 | ||
960d01ac JB |
9880 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
9881 | { | |
9882 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9883 | struct net_device *dev = info->user_ptr[1]; | |
9884 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9885 | const u8 *peer; | |
9886 | u8 tsid, up; | |
9887 | u16 admitted_time = 0; | |
9888 | int err; | |
9889 | ||
723e73ac | 9890 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
960d01ac JB |
9891 | return -EOPNOTSUPP; |
9892 | ||
9893 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | |
9894 | !info->attrs[NL80211_ATTR_USER_PRIO]) | |
9895 | return -EINVAL; | |
9896 | ||
9897 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
9898 | if (tsid >= IEEE80211_NUM_TIDS) | |
9899 | return -EINVAL; | |
9900 | ||
9901 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); | |
9902 | if (up >= IEEE80211_NUM_UPS) | |
9903 | return -EINVAL; | |
9904 | ||
9905 | /* WMM uses TIDs 0-7 even for TSPEC */ | |
723e73ac | 9906 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
960d01ac | 9907 | /* TODO: handle 802.11 TSPEC/admission control |
723e73ac JB |
9908 | * need more attributes for that (e.g. BA session requirement); |
9909 | * change the WMM adminssion test above to allow both then | |
960d01ac JB |
9910 | */ |
9911 | return -EINVAL; | |
9912 | } | |
9913 | ||
9914 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9915 | ||
9916 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | |
9917 | admitted_time = | |
9918 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | |
9919 | if (!admitted_time) | |
9920 | return -EINVAL; | |
9921 | } | |
9922 | ||
9923 | wdev_lock(wdev); | |
9924 | switch (wdev->iftype) { | |
9925 | case NL80211_IFTYPE_STATION: | |
9926 | case NL80211_IFTYPE_P2P_CLIENT: | |
9927 | if (wdev->current_bss) | |
9928 | break; | |
9929 | err = -ENOTCONN; | |
9930 | goto out; | |
9931 | default: | |
9932 | err = -EOPNOTSUPP; | |
9933 | goto out; | |
9934 | } | |
9935 | ||
9936 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | |
9937 | ||
9938 | out: | |
9939 | wdev_unlock(wdev); | |
9940 | return err; | |
9941 | } | |
9942 | ||
9943 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | |
9944 | { | |
9945 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9946 | struct net_device *dev = info->user_ptr[1]; | |
9947 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9948 | const u8 *peer; | |
9949 | u8 tsid; | |
9950 | int err; | |
9951 | ||
9952 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | |
9953 | return -EINVAL; | |
9954 | ||
9955 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
9956 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9957 | ||
9958 | wdev_lock(wdev); | |
9959 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | |
9960 | wdev_unlock(wdev); | |
9961 | ||
9962 | return err; | |
9963 | } | |
9964 | ||
1057d35e AN |
9965 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
9966 | struct genl_info *info) | |
9967 | { | |
9968 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9969 | struct net_device *dev = info->user_ptr[1]; | |
9970 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9971 | struct cfg80211_chan_def chandef = {}; | |
9972 | const u8 *addr; | |
9973 | u8 oper_class; | |
9974 | int err; | |
9975 | ||
9976 | if (!rdev->ops->tdls_channel_switch || | |
9977 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
9978 | return -EOPNOTSUPP; | |
9979 | ||
9980 | switch (dev->ieee80211_ptr->iftype) { | |
9981 | case NL80211_IFTYPE_STATION: | |
9982 | case NL80211_IFTYPE_P2P_CLIENT: | |
9983 | break; | |
9984 | default: | |
9985 | return -EOPNOTSUPP; | |
9986 | } | |
9987 | ||
9988 | if (!info->attrs[NL80211_ATTR_MAC] || | |
9989 | !info->attrs[NL80211_ATTR_OPER_CLASS]) | |
9990 | return -EINVAL; | |
9991 | ||
9992 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
9993 | if (err) | |
9994 | return err; | |
9995 | ||
9996 | /* | |
9997 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | |
9998 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | |
9999 | * specification is not defined for them. | |
10000 | */ | |
10001 | if (chandef.chan->band == IEEE80211_BAND_2GHZ && | |
10002 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | |
10003 | chandef.width != NL80211_CHAN_WIDTH_20) | |
10004 | return -EINVAL; | |
10005 | ||
10006 | /* we will be active on the TDLS link */ | |
10007 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype)) | |
10008 | return -EINVAL; | |
10009 | ||
10010 | /* don't allow switching to DFS channels */ | |
10011 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | |
10012 | return -EINVAL; | |
10013 | ||
10014 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10015 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | |
10016 | ||
10017 | wdev_lock(wdev); | |
10018 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | |
10019 | wdev_unlock(wdev); | |
10020 | ||
10021 | return err; | |
10022 | } | |
10023 | ||
10024 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | |
10025 | struct genl_info *info) | |
10026 | { | |
10027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10028 | struct net_device *dev = info->user_ptr[1]; | |
10029 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10030 | const u8 *addr; | |
10031 | ||
10032 | if (!rdev->ops->tdls_channel_switch || | |
10033 | !rdev->ops->tdls_cancel_channel_switch || | |
10034 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
10035 | return -EOPNOTSUPP; | |
10036 | ||
10037 | switch (dev->ieee80211_ptr->iftype) { | |
10038 | case NL80211_IFTYPE_STATION: | |
10039 | case NL80211_IFTYPE_P2P_CLIENT: | |
10040 | break; | |
10041 | default: | |
10042 | return -EOPNOTSUPP; | |
10043 | } | |
10044 | ||
10045 | if (!info->attrs[NL80211_ATTR_MAC]) | |
10046 | return -EINVAL; | |
10047 | ||
10048 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10049 | ||
10050 | wdev_lock(wdev); | |
10051 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); | |
10052 | wdev_unlock(wdev); | |
10053 | ||
10054 | return 0; | |
10055 | } | |
10056 | ||
4c476991 JB |
10057 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
10058 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
10059 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
10060 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
10061 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
10062 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 10063 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 10064 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
10065 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
10066 | NL80211_FLAG_CHECK_NETDEV_UP) | |
5393b917 | 10067 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
4c476991 | 10068 | |
f84f771d | 10069 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10070 | struct genl_info *info) |
10071 | { | |
10072 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 10073 | struct wireless_dev *wdev; |
4c476991 | 10074 | struct net_device *dev; |
4c476991 JB |
10075 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
10076 | ||
10077 | if (rtnl) | |
10078 | rtnl_lock(); | |
10079 | ||
10080 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 10081 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
10082 | if (IS_ERR(rdev)) { |
10083 | if (rtnl) | |
10084 | rtnl_unlock(); | |
10085 | return PTR_ERR(rdev); | |
10086 | } | |
10087 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
10088 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
10089 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
10090 | ASSERT_RTNL(); |
10091 | ||
89a54e48 JB |
10092 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
10093 | info->attrs); | |
10094 | if (IS_ERR(wdev)) { | |
4c476991 JB |
10095 | if (rtnl) |
10096 | rtnl_unlock(); | |
89a54e48 | 10097 | return PTR_ERR(wdev); |
4c476991 | 10098 | } |
89a54e48 | 10099 | |
89a54e48 | 10100 | dev = wdev->netdev; |
f26cbf40 | 10101 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 10102 | |
1bf614ef JB |
10103 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
10104 | if (!dev) { | |
1bf614ef JB |
10105 | if (rtnl) |
10106 | rtnl_unlock(); | |
10107 | return -EINVAL; | |
10108 | } | |
10109 | ||
10110 | info->user_ptr[1] = dev; | |
10111 | } else { | |
10112 | info->user_ptr[1] = wdev; | |
41265714 | 10113 | } |
1bf614ef JB |
10114 | |
10115 | if (dev) { | |
10116 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
10117 | !netif_running(dev)) { | |
1bf614ef JB |
10118 | if (rtnl) |
10119 | rtnl_unlock(); | |
10120 | return -ENETDOWN; | |
10121 | } | |
10122 | ||
10123 | dev_hold(dev); | |
98104fde JB |
10124 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
10125 | if (!wdev->p2p_started) { | |
98104fde JB |
10126 | if (rtnl) |
10127 | rtnl_unlock(); | |
10128 | return -ENETDOWN; | |
10129 | } | |
41265714 | 10130 | } |
89a54e48 | 10131 | |
4c476991 | 10132 | info->user_ptr[0] = rdev; |
4c476991 JB |
10133 | } |
10134 | ||
10135 | return 0; | |
10136 | } | |
10137 | ||
f84f771d | 10138 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10139 | struct genl_info *info) |
10140 | { | |
1bf614ef JB |
10141 | if (info->user_ptr[1]) { |
10142 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
10143 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10144 | ||
10145 | if (wdev->netdev) | |
10146 | dev_put(wdev->netdev); | |
10147 | } else { | |
10148 | dev_put(info->user_ptr[1]); | |
10149 | } | |
10150 | } | |
5393b917 | 10151 | |
4c476991 JB |
10152 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
10153 | rtnl_unlock(); | |
5393b917 JB |
10154 | |
10155 | /* If needed, clear the netlink message payload from the SKB | |
10156 | * as it might contain key data that shouldn't stick around on | |
10157 | * the heap after the SKB is freed. The netlink message header | |
10158 | * is still needed for further processing, so leave it intact. | |
10159 | */ | |
10160 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | |
10161 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | |
10162 | ||
10163 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | |
10164 | } | |
4c476991 JB |
10165 | } |
10166 | ||
4534de83 | 10167 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
10168 | { |
10169 | .cmd = NL80211_CMD_GET_WIPHY, | |
10170 | .doit = nl80211_get_wiphy, | |
10171 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 10172 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
10173 | .policy = nl80211_policy, |
10174 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10175 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10176 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10177 | }, |
10178 | { | |
10179 | .cmd = NL80211_CMD_SET_WIPHY, | |
10180 | .doit = nl80211_set_wiphy, | |
10181 | .policy = nl80211_policy, | |
10182 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 10183 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
10184 | }, |
10185 | { | |
10186 | .cmd = NL80211_CMD_GET_INTERFACE, | |
10187 | .doit = nl80211_get_interface, | |
10188 | .dumpit = nl80211_dump_interface, | |
10189 | .policy = nl80211_policy, | |
10190 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10191 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
10192 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10193 | }, |
10194 | { | |
10195 | .cmd = NL80211_CMD_SET_INTERFACE, | |
10196 | .doit = nl80211_set_interface, | |
10197 | .policy = nl80211_policy, | |
10198 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10199 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10200 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10201 | }, |
10202 | { | |
10203 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
10204 | .doit = nl80211_new_interface, | |
10205 | .policy = nl80211_policy, | |
10206 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10207 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10208 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10209 | }, |
10210 | { | |
10211 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
10212 | .doit = nl80211_del_interface, | |
10213 | .policy = nl80211_policy, | |
41ade00f | 10214 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 10215 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10216 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10217 | }, |
10218 | { | |
10219 | .cmd = NL80211_CMD_GET_KEY, | |
10220 | .doit = nl80211_get_key, | |
10221 | .policy = nl80211_policy, | |
10222 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10223 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10224 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10225 | }, |
10226 | { | |
10227 | .cmd = NL80211_CMD_SET_KEY, | |
10228 | .doit = nl80211_set_key, | |
10229 | .policy = nl80211_policy, | |
10230 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10231 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10232 | NL80211_FLAG_NEED_RTNL | |
10233 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10234 | }, |
10235 | { | |
10236 | .cmd = NL80211_CMD_NEW_KEY, | |
10237 | .doit = nl80211_new_key, | |
10238 | .policy = nl80211_policy, | |
10239 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10240 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10241 | NL80211_FLAG_NEED_RTNL | |
10242 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10243 | }, |
10244 | { | |
10245 | .cmd = NL80211_CMD_DEL_KEY, | |
10246 | .doit = nl80211_del_key, | |
10247 | .policy = nl80211_policy, | |
55682965 | 10248 | .flags = GENL_ADMIN_PERM, |
41265714 | 10249 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10250 | NL80211_FLAG_NEED_RTNL, |
55682965 | 10251 | }, |
ed1b6cc7 JB |
10252 | { |
10253 | .cmd = NL80211_CMD_SET_BEACON, | |
10254 | .policy = nl80211_policy, | |
10255 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10256 | .doit = nl80211_set_beacon, |
2b5f8b0b | 10257 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10258 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10259 | }, |
10260 | { | |
8860020e | 10261 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
10262 | .policy = nl80211_policy, |
10263 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10264 | .doit = nl80211_start_ap, |
2b5f8b0b | 10265 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10266 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10267 | }, |
10268 | { | |
8860020e | 10269 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
10270 | .policy = nl80211_policy, |
10271 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10272 | .doit = nl80211_stop_ap, |
2b5f8b0b | 10273 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10274 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 10275 | }, |
5727ef1b JB |
10276 | { |
10277 | .cmd = NL80211_CMD_GET_STATION, | |
10278 | .doit = nl80211_get_station, | |
2ec600d6 | 10279 | .dumpit = nl80211_dump_station, |
5727ef1b | 10280 | .policy = nl80211_policy, |
4c476991 JB |
10281 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10282 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
10283 | }, |
10284 | { | |
10285 | .cmd = NL80211_CMD_SET_STATION, | |
10286 | .doit = nl80211_set_station, | |
10287 | .policy = nl80211_policy, | |
10288 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10289 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10290 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10291 | }, |
10292 | { | |
10293 | .cmd = NL80211_CMD_NEW_STATION, | |
10294 | .doit = nl80211_new_station, | |
10295 | .policy = nl80211_policy, | |
10296 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10297 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10298 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10299 | }, |
10300 | { | |
10301 | .cmd = NL80211_CMD_DEL_STATION, | |
10302 | .doit = nl80211_del_station, | |
10303 | .policy = nl80211_policy, | |
2ec600d6 | 10304 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10305 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10306 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10307 | }, |
10308 | { | |
10309 | .cmd = NL80211_CMD_GET_MPATH, | |
10310 | .doit = nl80211_get_mpath, | |
10311 | .dumpit = nl80211_dump_mpath, | |
10312 | .policy = nl80211_policy, | |
10313 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10314 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10315 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 | 10316 | }, |
66be7d2b HR |
10317 | { |
10318 | .cmd = NL80211_CMD_GET_MPP, | |
10319 | .doit = nl80211_get_mpp, | |
10320 | .dumpit = nl80211_dump_mpp, | |
10321 | .policy = nl80211_policy, | |
10322 | .flags = GENL_ADMIN_PERM, | |
10323 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10324 | NL80211_FLAG_NEED_RTNL, | |
10325 | }, | |
2ec600d6 LCC |
10326 | { |
10327 | .cmd = NL80211_CMD_SET_MPATH, | |
10328 | .doit = nl80211_set_mpath, | |
10329 | .policy = nl80211_policy, | |
10330 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10331 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10332 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10333 | }, |
10334 | { | |
10335 | .cmd = NL80211_CMD_NEW_MPATH, | |
10336 | .doit = nl80211_new_mpath, | |
10337 | .policy = nl80211_policy, | |
10338 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10339 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10340 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10341 | }, |
10342 | { | |
10343 | .cmd = NL80211_CMD_DEL_MPATH, | |
10344 | .doit = nl80211_del_mpath, | |
10345 | .policy = nl80211_policy, | |
9f1ba906 | 10346 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10347 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10348 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
10349 | }, |
10350 | { | |
10351 | .cmd = NL80211_CMD_SET_BSS, | |
10352 | .doit = nl80211_set_bss, | |
10353 | .policy = nl80211_policy, | |
b2e1b302 | 10354 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10355 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10356 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 10357 | }, |
f130347c LR |
10358 | { |
10359 | .cmd = NL80211_CMD_GET_REG, | |
ad30ca2c AN |
10360 | .doit = nl80211_get_reg_do, |
10361 | .dumpit = nl80211_get_reg_dump, | |
f130347c | 10362 | .policy = nl80211_policy, |
5fe231e8 | 10363 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
10364 | /* can be retrieved by unprivileged users */ |
10365 | }, | |
b2e1b302 LR |
10366 | { |
10367 | .cmd = NL80211_CMD_SET_REG, | |
10368 | .doit = nl80211_set_reg, | |
10369 | .policy = nl80211_policy, | |
10370 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 10371 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
10372 | }, |
10373 | { | |
10374 | .cmd = NL80211_CMD_REQ_SET_REG, | |
10375 | .doit = nl80211_req_set_reg, | |
10376 | .policy = nl80211_policy, | |
93da9cc1 | 10377 | .flags = GENL_ADMIN_PERM, |
10378 | }, | |
10379 | { | |
24bdd9f4 JC |
10380 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
10381 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 10382 | .policy = nl80211_policy, |
10383 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 10384 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10385 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 10386 | }, |
10387 | { | |
24bdd9f4 JC |
10388 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
10389 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 10390 | .policy = nl80211_policy, |
9aed3cc1 | 10391 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 10392 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10393 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 10394 | }, |
2a519311 JB |
10395 | { |
10396 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
10397 | .doit = nl80211_trigger_scan, | |
10398 | .policy = nl80211_policy, | |
10399 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 10400 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10401 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
10402 | }, |
10403 | { | |
10404 | .cmd = NL80211_CMD_GET_SCAN, | |
10405 | .policy = nl80211_policy, | |
10406 | .dumpit = nl80211_dump_scan, | |
10407 | }, | |
807f8a8c LC |
10408 | { |
10409 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
10410 | .doit = nl80211_start_sched_scan, | |
10411 | .policy = nl80211_policy, | |
10412 | .flags = GENL_ADMIN_PERM, | |
10413 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10414 | NL80211_FLAG_NEED_RTNL, | |
10415 | }, | |
10416 | { | |
10417 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
10418 | .doit = nl80211_stop_sched_scan, | |
10419 | .policy = nl80211_policy, | |
10420 | .flags = GENL_ADMIN_PERM, | |
10421 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10422 | NL80211_FLAG_NEED_RTNL, | |
10423 | }, | |
636a5d36 JM |
10424 | { |
10425 | .cmd = NL80211_CMD_AUTHENTICATE, | |
10426 | .doit = nl80211_authenticate, | |
10427 | .policy = nl80211_policy, | |
10428 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10429 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10430 | NL80211_FLAG_NEED_RTNL | |
10431 | NL80211_FLAG_CLEAR_SKB, | |
636a5d36 JM |
10432 | }, |
10433 | { | |
10434 | .cmd = NL80211_CMD_ASSOCIATE, | |
10435 | .doit = nl80211_associate, | |
10436 | .policy = nl80211_policy, | |
10437 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10438 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10439 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10440 | }, |
10441 | { | |
10442 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
10443 | .doit = nl80211_deauthenticate, | |
10444 | .policy = nl80211_policy, | |
10445 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10446 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10447 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10448 | }, |
10449 | { | |
10450 | .cmd = NL80211_CMD_DISASSOCIATE, | |
10451 | .doit = nl80211_disassociate, | |
10452 | .policy = nl80211_policy, | |
10453 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10454 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10455 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 10456 | }, |
04a773ad JB |
10457 | { |
10458 | .cmd = NL80211_CMD_JOIN_IBSS, | |
10459 | .doit = nl80211_join_ibss, | |
10460 | .policy = nl80211_policy, | |
10461 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10462 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10463 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
10464 | }, |
10465 | { | |
10466 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
10467 | .doit = nl80211_leave_ibss, | |
10468 | .policy = nl80211_policy, | |
10469 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10470 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10471 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 10472 | }, |
aff89a9b JB |
10473 | #ifdef CONFIG_NL80211_TESTMODE |
10474 | { | |
10475 | .cmd = NL80211_CMD_TESTMODE, | |
10476 | .doit = nl80211_testmode_do, | |
71063f0e | 10477 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
10478 | .policy = nl80211_policy, |
10479 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10480 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10481 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
10482 | }, |
10483 | #endif | |
b23aa676 SO |
10484 | { |
10485 | .cmd = NL80211_CMD_CONNECT, | |
10486 | .doit = nl80211_connect, | |
10487 | .policy = nl80211_policy, | |
10488 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10489 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10490 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
10491 | }, |
10492 | { | |
10493 | .cmd = NL80211_CMD_DISCONNECT, | |
10494 | .doit = nl80211_disconnect, | |
10495 | .policy = nl80211_policy, | |
10496 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10497 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10498 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 10499 | }, |
463d0183 JB |
10500 | { |
10501 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
10502 | .doit = nl80211_wiphy_netns, | |
10503 | .policy = nl80211_policy, | |
10504 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10505 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10506 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 10507 | }, |
61fa713c HS |
10508 | { |
10509 | .cmd = NL80211_CMD_GET_SURVEY, | |
10510 | .policy = nl80211_policy, | |
10511 | .dumpit = nl80211_dump_survey, | |
10512 | }, | |
67fbb16b SO |
10513 | { |
10514 | .cmd = NL80211_CMD_SET_PMKSA, | |
10515 | .doit = nl80211_setdel_pmksa, | |
10516 | .policy = nl80211_policy, | |
10517 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10518 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10519 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10520 | }, |
10521 | { | |
10522 | .cmd = NL80211_CMD_DEL_PMKSA, | |
10523 | .doit = nl80211_setdel_pmksa, | |
10524 | .policy = nl80211_policy, | |
10525 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10526 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10527 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10528 | }, |
10529 | { | |
10530 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
10531 | .doit = nl80211_flush_pmksa, | |
10532 | .policy = nl80211_policy, | |
10533 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10534 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10535 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 10536 | }, |
9588bbd5 JM |
10537 | { |
10538 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
10539 | .doit = nl80211_remain_on_channel, | |
10540 | .policy = nl80211_policy, | |
10541 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10542 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10543 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
10544 | }, |
10545 | { | |
10546 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
10547 | .doit = nl80211_cancel_remain_on_channel, | |
10548 | .policy = nl80211_policy, | |
10549 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10550 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10551 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 10552 | }, |
13ae75b1 JM |
10553 | { |
10554 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
10555 | .doit = nl80211_set_tx_bitrate_mask, | |
10556 | .policy = nl80211_policy, | |
10557 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10558 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10559 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 10560 | }, |
026331c4 | 10561 | { |
2e161f78 JB |
10562 | .cmd = NL80211_CMD_REGISTER_FRAME, |
10563 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
10564 | .policy = nl80211_policy, |
10565 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10566 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10567 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
10568 | }, |
10569 | { | |
2e161f78 JB |
10570 | .cmd = NL80211_CMD_FRAME, |
10571 | .doit = nl80211_tx_mgmt, | |
026331c4 | 10572 | .policy = nl80211_policy, |
f7ca38df | 10573 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10574 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
10575 | NL80211_FLAG_NEED_RTNL, |
10576 | }, | |
10577 | { | |
10578 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
10579 | .doit = nl80211_tx_mgmt_cancel_wait, | |
10580 | .policy = nl80211_policy, | |
026331c4 | 10581 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10582 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10583 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 10584 | }, |
ffb9eb3d KV |
10585 | { |
10586 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
10587 | .doit = nl80211_set_power_save, | |
10588 | .policy = nl80211_policy, | |
10589 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10590 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10591 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
10592 | }, |
10593 | { | |
10594 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
10595 | .doit = nl80211_get_power_save, | |
10596 | .policy = nl80211_policy, | |
10597 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
10598 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10599 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 10600 | }, |
d6dc1a38 JO |
10601 | { |
10602 | .cmd = NL80211_CMD_SET_CQM, | |
10603 | .doit = nl80211_set_cqm, | |
10604 | .policy = nl80211_policy, | |
10605 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10606 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10607 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 10608 | }, |
f444de05 JB |
10609 | { |
10610 | .cmd = NL80211_CMD_SET_CHANNEL, | |
10611 | .doit = nl80211_set_channel, | |
10612 | .policy = nl80211_policy, | |
10613 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10614 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10615 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 10616 | }, |
e8347eba BJ |
10617 | { |
10618 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
10619 | .doit = nl80211_set_wds_peer, | |
10620 | .policy = nl80211_policy, | |
10621 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
10622 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10623 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 10624 | }, |
29cbe68c JB |
10625 | { |
10626 | .cmd = NL80211_CMD_JOIN_MESH, | |
10627 | .doit = nl80211_join_mesh, | |
10628 | .policy = nl80211_policy, | |
10629 | .flags = GENL_ADMIN_PERM, | |
10630 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10631 | NL80211_FLAG_NEED_RTNL, | |
10632 | }, | |
10633 | { | |
10634 | .cmd = NL80211_CMD_LEAVE_MESH, | |
10635 | .doit = nl80211_leave_mesh, | |
10636 | .policy = nl80211_policy, | |
10637 | .flags = GENL_ADMIN_PERM, | |
10638 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10639 | NL80211_FLAG_NEED_RTNL, | |
10640 | }, | |
6e0bd6c3 RL |
10641 | { |
10642 | .cmd = NL80211_CMD_JOIN_OCB, | |
10643 | .doit = nl80211_join_ocb, | |
10644 | .policy = nl80211_policy, | |
10645 | .flags = GENL_ADMIN_PERM, | |
10646 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10647 | NL80211_FLAG_NEED_RTNL, | |
10648 | }, | |
10649 | { | |
10650 | .cmd = NL80211_CMD_LEAVE_OCB, | |
10651 | .doit = nl80211_leave_ocb, | |
10652 | .policy = nl80211_policy, | |
10653 | .flags = GENL_ADMIN_PERM, | |
10654 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10655 | NL80211_FLAG_NEED_RTNL, | |
10656 | }, | |
dfb89c56 | 10657 | #ifdef CONFIG_PM |
ff1b6e69 JB |
10658 | { |
10659 | .cmd = NL80211_CMD_GET_WOWLAN, | |
10660 | .doit = nl80211_get_wowlan, | |
10661 | .policy = nl80211_policy, | |
10662 | /* can be retrieved by unprivileged users */ | |
10663 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10664 | NL80211_FLAG_NEED_RTNL, | |
10665 | }, | |
10666 | { | |
10667 | .cmd = NL80211_CMD_SET_WOWLAN, | |
10668 | .doit = nl80211_set_wowlan, | |
10669 | .policy = nl80211_policy, | |
10670 | .flags = GENL_ADMIN_PERM, | |
10671 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10672 | NL80211_FLAG_NEED_RTNL, | |
10673 | }, | |
dfb89c56 | 10674 | #endif |
e5497d76 JB |
10675 | { |
10676 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
10677 | .doit = nl80211_set_rekey_data, | |
10678 | .policy = nl80211_policy, | |
10679 | .flags = GENL_ADMIN_PERM, | |
10680 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
5393b917 JB |
10681 | NL80211_FLAG_NEED_RTNL | |
10682 | NL80211_FLAG_CLEAR_SKB, | |
e5497d76 | 10683 | }, |
109086ce AN |
10684 | { |
10685 | .cmd = NL80211_CMD_TDLS_MGMT, | |
10686 | .doit = nl80211_tdls_mgmt, | |
10687 | .policy = nl80211_policy, | |
10688 | .flags = GENL_ADMIN_PERM, | |
10689 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10690 | NL80211_FLAG_NEED_RTNL, | |
10691 | }, | |
10692 | { | |
10693 | .cmd = NL80211_CMD_TDLS_OPER, | |
10694 | .doit = nl80211_tdls_oper, | |
10695 | .policy = nl80211_policy, | |
10696 | .flags = GENL_ADMIN_PERM, | |
10697 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10698 | NL80211_FLAG_NEED_RTNL, | |
10699 | }, | |
28946da7 JB |
10700 | { |
10701 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
10702 | .doit = nl80211_register_unexpected_frame, | |
10703 | .policy = nl80211_policy, | |
10704 | .flags = GENL_ADMIN_PERM, | |
10705 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10706 | NL80211_FLAG_NEED_RTNL, | |
10707 | }, | |
7f6cf311 JB |
10708 | { |
10709 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
10710 | .doit = nl80211_probe_client, | |
10711 | .policy = nl80211_policy, | |
10712 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10713 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
10714 | NL80211_FLAG_NEED_RTNL, |
10715 | }, | |
5e760230 JB |
10716 | { |
10717 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
10718 | .doit = nl80211_register_beacons, | |
10719 | .policy = nl80211_policy, | |
10720 | .flags = GENL_ADMIN_PERM, | |
10721 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10722 | NL80211_FLAG_NEED_RTNL, | |
10723 | }, | |
1d9d9213 SW |
10724 | { |
10725 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
10726 | .doit = nl80211_set_noack_map, | |
10727 | .policy = nl80211_policy, | |
10728 | .flags = GENL_ADMIN_PERM, | |
10729 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10730 | NL80211_FLAG_NEED_RTNL, | |
10731 | }, | |
98104fde JB |
10732 | { |
10733 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
10734 | .doit = nl80211_start_p2p_device, | |
10735 | .policy = nl80211_policy, | |
10736 | .flags = GENL_ADMIN_PERM, | |
10737 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
10738 | NL80211_FLAG_NEED_RTNL, | |
10739 | }, | |
10740 | { | |
10741 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
10742 | .doit = nl80211_stop_p2p_device, | |
10743 | .policy = nl80211_policy, | |
10744 | .flags = GENL_ADMIN_PERM, | |
10745 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10746 | NL80211_FLAG_NEED_RTNL, | |
10747 | }, | |
f4e583c8 AQ |
10748 | { |
10749 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
10750 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
10751 | .policy = nl80211_policy, |
10752 | .flags = GENL_ADMIN_PERM, | |
10753 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10754 | NL80211_FLAG_NEED_RTNL, | |
10755 | }, | |
10756 | { | |
10757 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
10758 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
10759 | .policy = nl80211_policy, |
10760 | .flags = GENL_ADMIN_PERM, | |
10761 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10762 | NL80211_FLAG_NEED_RTNL, | |
10763 | }, | |
04f39047 SW |
10764 | { |
10765 | .cmd = NL80211_CMD_RADAR_DETECT, | |
10766 | .doit = nl80211_start_radar_detection, | |
10767 | .policy = nl80211_policy, | |
10768 | .flags = GENL_ADMIN_PERM, | |
10769 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10770 | NL80211_FLAG_NEED_RTNL, | |
10771 | }, | |
3713b4e3 JB |
10772 | { |
10773 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
10774 | .doit = nl80211_get_protocol_features, | |
10775 | .policy = nl80211_policy, | |
10776 | }, | |
355199e0 JM |
10777 | { |
10778 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
10779 | .doit = nl80211_update_ft_ies, | |
10780 | .policy = nl80211_policy, | |
10781 | .flags = GENL_ADMIN_PERM, | |
10782 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10783 | NL80211_FLAG_NEED_RTNL, | |
10784 | }, | |
5de17984 AS |
10785 | { |
10786 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
10787 | .doit = nl80211_crit_protocol_start, | |
10788 | .policy = nl80211_policy, | |
10789 | .flags = GENL_ADMIN_PERM, | |
10790 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10791 | NL80211_FLAG_NEED_RTNL, | |
10792 | }, | |
10793 | { | |
10794 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
10795 | .doit = nl80211_crit_protocol_stop, | |
10796 | .policy = nl80211_policy, | |
10797 | .flags = GENL_ADMIN_PERM, | |
10798 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10799 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
10800 | }, |
10801 | { | |
10802 | .cmd = NL80211_CMD_GET_COALESCE, | |
10803 | .doit = nl80211_get_coalesce, | |
10804 | .policy = nl80211_policy, | |
10805 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10806 | NL80211_FLAG_NEED_RTNL, | |
10807 | }, | |
10808 | { | |
10809 | .cmd = NL80211_CMD_SET_COALESCE, | |
10810 | .doit = nl80211_set_coalesce, | |
10811 | .policy = nl80211_policy, | |
10812 | .flags = GENL_ADMIN_PERM, | |
10813 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10814 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
10815 | }, |
10816 | { | |
10817 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
10818 | .doit = nl80211_channel_switch, | |
10819 | .policy = nl80211_policy, | |
10820 | .flags = GENL_ADMIN_PERM, | |
10821 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10822 | NL80211_FLAG_NEED_RTNL, | |
10823 | }, | |
ad7e718c JB |
10824 | { |
10825 | .cmd = NL80211_CMD_VENDOR, | |
10826 | .doit = nl80211_vendor_cmd, | |
10827 | .policy = nl80211_policy, | |
10828 | .flags = GENL_ADMIN_PERM, | |
10829 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10830 | NL80211_FLAG_NEED_RTNL, | |
10831 | }, | |
fa9ffc74 KP |
10832 | { |
10833 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
10834 | .doit = nl80211_set_qos_map, | |
10835 | .policy = nl80211_policy, | |
10836 | .flags = GENL_ADMIN_PERM, | |
10837 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10838 | NL80211_FLAG_NEED_RTNL, | |
10839 | }, | |
960d01ac JB |
10840 | { |
10841 | .cmd = NL80211_CMD_ADD_TX_TS, | |
10842 | .doit = nl80211_add_tx_ts, | |
10843 | .policy = nl80211_policy, | |
10844 | .flags = GENL_ADMIN_PERM, | |
10845 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10846 | NL80211_FLAG_NEED_RTNL, | |
10847 | }, | |
10848 | { | |
10849 | .cmd = NL80211_CMD_DEL_TX_TS, | |
10850 | .doit = nl80211_del_tx_ts, | |
10851 | .policy = nl80211_policy, | |
10852 | .flags = GENL_ADMIN_PERM, | |
10853 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10854 | NL80211_FLAG_NEED_RTNL, | |
10855 | }, | |
1057d35e AN |
10856 | { |
10857 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | |
10858 | .doit = nl80211_tdls_channel_switch, | |
10859 | .policy = nl80211_policy, | |
10860 | .flags = GENL_ADMIN_PERM, | |
10861 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10862 | NL80211_FLAG_NEED_RTNL, | |
10863 | }, | |
10864 | { | |
10865 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | |
10866 | .doit = nl80211_tdls_cancel_channel_switch, | |
10867 | .policy = nl80211_policy, | |
10868 | .flags = GENL_ADMIN_PERM, | |
10869 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10870 | NL80211_FLAG_NEED_RTNL, | |
10871 | }, | |
55682965 | 10872 | }; |
9588bbd5 | 10873 | |
55682965 JB |
10874 | /* notification functions */ |
10875 | ||
3bb20556 JB |
10876 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
10877 | enum nl80211_commands cmd) | |
55682965 JB |
10878 | { |
10879 | struct sk_buff *msg; | |
86e8cf98 | 10880 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 10881 | |
3bb20556 JB |
10882 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
10883 | cmd != NL80211_CMD_DEL_WIPHY); | |
10884 | ||
fd2120ca | 10885 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
10886 | if (!msg) |
10887 | return; | |
10888 | ||
3bb20556 | 10889 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
10890 | nlmsg_free(msg); |
10891 | return; | |
10892 | } | |
10893 | ||
68eb5503 | 10894 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10895 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
10896 | } |
10897 | ||
362a415d JB |
10898 | static int nl80211_add_scan_req(struct sk_buff *msg, |
10899 | struct cfg80211_registered_device *rdev) | |
10900 | { | |
10901 | struct cfg80211_scan_request *req = rdev->scan_req; | |
10902 | struct nlattr *nest; | |
10903 | int i; | |
10904 | ||
10905 | if (WARN_ON(!req)) | |
10906 | return 0; | |
10907 | ||
10908 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
10909 | if (!nest) | |
10910 | goto nla_put_failure; | |
9360ffd1 DM |
10911 | for (i = 0; i < req->n_ssids; i++) { |
10912 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
10913 | goto nla_put_failure; | |
10914 | } | |
362a415d JB |
10915 | nla_nest_end(msg, nest); |
10916 | ||
10917 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
10918 | if (!nest) | |
10919 | goto nla_put_failure; | |
9360ffd1 DM |
10920 | for (i = 0; i < req->n_channels; i++) { |
10921 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
10922 | goto nla_put_failure; | |
10923 | } | |
362a415d JB |
10924 | nla_nest_end(msg, nest); |
10925 | ||
9360ffd1 DM |
10926 | if (req->ie && |
10927 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
10928 | goto nla_put_failure; | |
362a415d | 10929 | |
ae917c9f JB |
10930 | if (req->flags && |
10931 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
10932 | goto nla_put_failure; | |
ed473771 | 10933 | |
362a415d JB |
10934 | return 0; |
10935 | nla_put_failure: | |
10936 | return -ENOBUFS; | |
10937 | } | |
10938 | ||
a538e2d5 JB |
10939 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
10940 | struct cfg80211_registered_device *rdev, | |
fd014284 | 10941 | struct wireless_dev *wdev, |
15e47304 | 10942 | u32 portid, u32 seq, int flags, |
a538e2d5 | 10943 | u32 cmd) |
2a519311 JB |
10944 | { |
10945 | void *hdr; | |
10946 | ||
15e47304 | 10947 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
10948 | if (!hdr) |
10949 | return -1; | |
10950 | ||
9360ffd1 | 10951 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
10952 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10953 | wdev->netdev->ifindex)) || | |
10954 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 10955 | goto nla_put_failure; |
2a519311 | 10956 | |
362a415d JB |
10957 | /* ignore errors and send incomplete event anyway */ |
10958 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
10959 | |
10960 | return genlmsg_end(msg, hdr); | |
10961 | ||
10962 | nla_put_failure: | |
10963 | genlmsg_cancel(msg, hdr); | |
10964 | return -EMSGSIZE; | |
10965 | } | |
10966 | ||
807f8a8c LC |
10967 | static int |
10968 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
10969 | struct cfg80211_registered_device *rdev, | |
10970 | struct net_device *netdev, | |
15e47304 | 10971 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
10972 | { |
10973 | void *hdr; | |
10974 | ||
15e47304 | 10975 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
10976 | if (!hdr) |
10977 | return -1; | |
10978 | ||
9360ffd1 DM |
10979 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10980 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
10981 | goto nla_put_failure; | |
807f8a8c LC |
10982 | |
10983 | return genlmsg_end(msg, hdr); | |
10984 | ||
10985 | nla_put_failure: | |
10986 | genlmsg_cancel(msg, hdr); | |
10987 | return -EMSGSIZE; | |
10988 | } | |
10989 | ||
a538e2d5 | 10990 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 10991 | struct wireless_dev *wdev) |
a538e2d5 JB |
10992 | { |
10993 | struct sk_buff *msg; | |
10994 | ||
58050fce | 10995 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
10996 | if (!msg) |
10997 | return; | |
10998 | ||
fd014284 | 10999 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
11000 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
11001 | nlmsg_free(msg); | |
11002 | return; | |
11003 | } | |
11004 | ||
68eb5503 | 11005 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11006 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
11007 | } |
11008 | ||
f9d15d16 JB |
11009 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
11010 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
11011 | { |
11012 | struct sk_buff *msg; | |
11013 | ||
fd2120ca | 11014 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 11015 | if (!msg) |
f9d15d16 | 11016 | return NULL; |
2a519311 | 11017 | |
fd014284 | 11018 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
11019 | aborted ? NL80211_CMD_SCAN_ABORTED : |
11020 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 11021 | nlmsg_free(msg); |
f9d15d16 | 11022 | return NULL; |
2a519311 JB |
11023 | } |
11024 | ||
f9d15d16 | 11025 | return msg; |
2a519311 JB |
11026 | } |
11027 | ||
f9d15d16 JB |
11028 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
11029 | struct sk_buff *msg) | |
2a519311 | 11030 | { |
2a519311 JB |
11031 | if (!msg) |
11032 | return; | |
11033 | ||
68eb5503 | 11034 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11035 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
11036 | } |
11037 | ||
807f8a8c LC |
11038 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
11039 | struct net_device *netdev) | |
11040 | { | |
11041 | struct sk_buff *msg; | |
11042 | ||
11043 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11044 | if (!msg) | |
11045 | return; | |
11046 | ||
11047 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
11048 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
11049 | nlmsg_free(msg); | |
11050 | return; | |
11051 | } | |
11052 | ||
68eb5503 | 11053 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11054 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11055 | } |
11056 | ||
11057 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
11058 | struct net_device *netdev, u32 cmd) | |
11059 | { | |
11060 | struct sk_buff *msg; | |
11061 | ||
58050fce | 11062 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
11063 | if (!msg) |
11064 | return; | |
11065 | ||
11066 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
11067 | nlmsg_free(msg); | |
11068 | return; | |
11069 | } | |
11070 | ||
68eb5503 | 11071 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11072 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11073 | } |
11074 | ||
b0d7aa59 JD |
11075 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
11076 | struct regulatory_request *request) | |
73d54c9e | 11077 | { |
73d54c9e | 11078 | /* Userspace can always count this one always being set */ |
9360ffd1 DM |
11079 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
11080 | goto nla_put_failure; | |
11081 | ||
11082 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
11083 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11084 | NL80211_REGDOM_TYPE_WORLD)) | |
11085 | goto nla_put_failure; | |
11086 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
11087 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11088 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
11089 | goto nla_put_failure; | |
11090 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
11091 | request->intersect) { | |
11092 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11093 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
11094 | goto nla_put_failure; | |
11095 | } else { | |
11096 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11097 | NL80211_REGDOM_TYPE_COUNTRY) || | |
11098 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
11099 | request->alpha2)) | |
11100 | goto nla_put_failure; | |
11101 | } | |
11102 | ||
ad30ca2c AN |
11103 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
11104 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); | |
11105 | ||
11106 | if (wiphy && | |
11107 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | |
11108 | goto nla_put_failure; | |
1bdd716c AN |
11109 | |
11110 | if (wiphy && | |
11111 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | |
11112 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
11113 | goto nla_put_failure; | |
ad30ca2c | 11114 | } |
73d54c9e | 11115 | |
b0d7aa59 JD |
11116 | return true; |
11117 | ||
11118 | nla_put_failure: | |
11119 | return false; | |
11120 | } | |
11121 | ||
11122 | /* | |
11123 | * This can happen on global regulatory changes or device specific settings | |
11124 | * based on custom regulatory domains. | |
11125 | */ | |
11126 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, | |
11127 | struct regulatory_request *request) | |
11128 | { | |
11129 | struct sk_buff *msg; | |
11130 | void *hdr; | |
11131 | ||
11132 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11133 | if (!msg) | |
11134 | return; | |
11135 | ||
11136 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); | |
11137 | if (!hdr) { | |
11138 | nlmsg_free(msg); | |
11139 | return; | |
11140 | } | |
11141 | ||
11142 | if (nl80211_reg_change_event_fill(msg, request) == false) | |
11143 | goto nla_put_failure; | |
11144 | ||
3b7b72ee | 11145 | genlmsg_end(msg, hdr); |
73d54c9e | 11146 | |
bc43b28c | 11147 | rcu_read_lock(); |
68eb5503 | 11148 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11149 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 11150 | rcu_read_unlock(); |
73d54c9e LR |
11151 | |
11152 | return; | |
11153 | ||
11154 | nla_put_failure: | |
11155 | genlmsg_cancel(msg, hdr); | |
11156 | nlmsg_free(msg); | |
11157 | } | |
11158 | ||
6039f6d2 JM |
11159 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
11160 | struct net_device *netdev, | |
11161 | const u8 *buf, size_t len, | |
b0b6aa2c EP |
11162 | enum nl80211_commands cmd, gfp_t gfp, |
11163 | int uapsd_queues) | |
6039f6d2 JM |
11164 | { |
11165 | struct sk_buff *msg; | |
11166 | void *hdr; | |
11167 | ||
e6d6e342 | 11168 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
11169 | if (!msg) |
11170 | return; | |
11171 | ||
11172 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11173 | if (!hdr) { | |
11174 | nlmsg_free(msg); | |
11175 | return; | |
11176 | } | |
11177 | ||
9360ffd1 DM |
11178 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11179 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11180 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
11181 | goto nla_put_failure; | |
6039f6d2 | 11182 | |
b0b6aa2c EP |
11183 | if (uapsd_queues >= 0) { |
11184 | struct nlattr *nla_wmm = | |
11185 | nla_nest_start(msg, NL80211_ATTR_STA_WME); | |
11186 | if (!nla_wmm) | |
11187 | goto nla_put_failure; | |
11188 | ||
11189 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
11190 | uapsd_queues)) | |
11191 | goto nla_put_failure; | |
11192 | ||
11193 | nla_nest_end(msg, nla_wmm); | |
11194 | } | |
11195 | ||
3b7b72ee | 11196 | genlmsg_end(msg, hdr); |
6039f6d2 | 11197 | |
68eb5503 | 11198 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11199 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
11200 | return; |
11201 | ||
11202 | nla_put_failure: | |
11203 | genlmsg_cancel(msg, hdr); | |
11204 | nlmsg_free(msg); | |
11205 | } | |
11206 | ||
11207 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11208 | struct net_device *netdev, const u8 *buf, |
11209 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11210 | { |
11211 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11212 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11213 | } |
11214 | ||
11215 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
11216 | struct net_device *netdev, const u8 *buf, | |
b0b6aa2c | 11217 | size_t len, gfp_t gfp, int uapsd_queues) |
6039f6d2 | 11218 | { |
e6d6e342 | 11219 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
b0b6aa2c | 11220 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
6039f6d2 JM |
11221 | } |
11222 | ||
53b46b84 | 11223 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
11224 | struct net_device *netdev, const u8 *buf, |
11225 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11226 | { |
11227 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11228 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11229 | } |
11230 | ||
53b46b84 JM |
11231 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
11232 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 11233 | size_t len, gfp_t gfp) |
6039f6d2 JM |
11234 | { |
11235 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11236 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
6039f6d2 JM |
11237 | } |
11238 | ||
6ff57cf8 JB |
11239 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
11240 | size_t len) | |
cf4e594e | 11241 | { |
947add36 JB |
11242 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11243 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11244 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
11245 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
11246 | u32 cmd; | |
947add36 | 11247 | |
6ff57cf8 JB |
11248 | if (WARN_ON(len < 2)) |
11249 | return; | |
cf4e594e | 11250 | |
6ff57cf8 JB |
11251 | if (ieee80211_is_deauth(mgmt->frame_control)) |
11252 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
11253 | else | |
11254 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 11255 | |
6ff57cf8 | 11256 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
b0b6aa2c | 11257 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
cf4e594e | 11258 | } |
6ff57cf8 | 11259 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 11260 | |
1b06bb40 LR |
11261 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
11262 | struct net_device *netdev, int cmd, | |
e6d6e342 | 11263 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
11264 | { |
11265 | struct sk_buff *msg; | |
11266 | void *hdr; | |
11267 | ||
e6d6e342 | 11268 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
11269 | if (!msg) |
11270 | return; | |
11271 | ||
11272 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11273 | if (!hdr) { | |
11274 | nlmsg_free(msg); | |
11275 | return; | |
11276 | } | |
11277 | ||
9360ffd1 DM |
11278 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11279 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11280 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
11281 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11282 | goto nla_put_failure; | |
1965c853 | 11283 | |
3b7b72ee | 11284 | genlmsg_end(msg, hdr); |
1965c853 | 11285 | |
68eb5503 | 11286 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11287 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
11288 | return; |
11289 | ||
11290 | nla_put_failure: | |
11291 | genlmsg_cancel(msg, hdr); | |
11292 | nlmsg_free(msg); | |
11293 | } | |
11294 | ||
11295 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11296 | struct net_device *netdev, const u8 *addr, |
11297 | gfp_t gfp) | |
1965c853 JM |
11298 | { |
11299 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 11300 | addr, gfp); |
1965c853 JM |
11301 | } |
11302 | ||
11303 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11304 | struct net_device *netdev, const u8 *addr, |
11305 | gfp_t gfp) | |
1965c853 | 11306 | { |
e6d6e342 JB |
11307 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
11308 | addr, gfp); | |
1965c853 JM |
11309 | } |
11310 | ||
b23aa676 SO |
11311 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
11312 | struct net_device *netdev, const u8 *bssid, | |
11313 | const u8 *req_ie, size_t req_ie_len, | |
11314 | const u8 *resp_ie, size_t resp_ie_len, | |
11315 | u16 status, gfp_t gfp) | |
11316 | { | |
11317 | struct sk_buff *msg; | |
11318 | void *hdr; | |
11319 | ||
58050fce | 11320 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
11321 | if (!msg) |
11322 | return; | |
11323 | ||
11324 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
11325 | if (!hdr) { | |
11326 | nlmsg_free(msg); | |
11327 | return; | |
11328 | } | |
11329 | ||
9360ffd1 DM |
11330 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11331 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11332 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
11333 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
11334 | (req_ie && | |
11335 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11336 | (resp_ie && | |
11337 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11338 | goto nla_put_failure; | |
b23aa676 | 11339 | |
3b7b72ee | 11340 | genlmsg_end(msg, hdr); |
b23aa676 | 11341 | |
68eb5503 | 11342 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11343 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11344 | return; |
11345 | ||
11346 | nla_put_failure: | |
11347 | genlmsg_cancel(msg, hdr); | |
11348 | nlmsg_free(msg); | |
11349 | ||
11350 | } | |
11351 | ||
11352 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
11353 | struct net_device *netdev, const u8 *bssid, | |
11354 | const u8 *req_ie, size_t req_ie_len, | |
11355 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
11356 | { | |
11357 | struct sk_buff *msg; | |
11358 | void *hdr; | |
11359 | ||
58050fce | 11360 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
11361 | if (!msg) |
11362 | return; | |
11363 | ||
11364 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
11365 | if (!hdr) { | |
11366 | nlmsg_free(msg); | |
11367 | return; | |
11368 | } | |
11369 | ||
9360ffd1 DM |
11370 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11371 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11372 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
11373 | (req_ie && | |
11374 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11375 | (resp_ie && | |
11376 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11377 | goto nla_put_failure; | |
b23aa676 | 11378 | |
3b7b72ee | 11379 | genlmsg_end(msg, hdr); |
b23aa676 | 11380 | |
68eb5503 | 11381 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11382 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11383 | return; |
11384 | ||
11385 | nla_put_failure: | |
11386 | genlmsg_cancel(msg, hdr); | |
11387 | nlmsg_free(msg); | |
11388 | ||
11389 | } | |
11390 | ||
11391 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
11392 | struct net_device *netdev, u16 reason, | |
667503dd | 11393 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
11394 | { |
11395 | struct sk_buff *msg; | |
11396 | void *hdr; | |
11397 | ||
58050fce | 11398 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
11399 | if (!msg) |
11400 | return; | |
11401 | ||
11402 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
11403 | if (!hdr) { | |
11404 | nlmsg_free(msg); | |
11405 | return; | |
11406 | } | |
11407 | ||
9360ffd1 DM |
11408 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11409 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11410 | (from_ap && reason && | |
11411 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
11412 | (from_ap && | |
11413 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
11414 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
11415 | goto nla_put_failure; | |
b23aa676 | 11416 | |
3b7b72ee | 11417 | genlmsg_end(msg, hdr); |
b23aa676 | 11418 | |
68eb5503 | 11419 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11420 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
11421 | return; |
11422 | ||
11423 | nla_put_failure: | |
11424 | genlmsg_cancel(msg, hdr); | |
11425 | nlmsg_free(msg); | |
11426 | ||
11427 | } | |
11428 | ||
04a773ad JB |
11429 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
11430 | struct net_device *netdev, const u8 *bssid, | |
11431 | gfp_t gfp) | |
11432 | { | |
11433 | struct sk_buff *msg; | |
11434 | void *hdr; | |
11435 | ||
fd2120ca | 11436 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
11437 | if (!msg) |
11438 | return; | |
11439 | ||
11440 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
11441 | if (!hdr) { | |
11442 | nlmsg_free(msg); | |
11443 | return; | |
11444 | } | |
11445 | ||
9360ffd1 DM |
11446 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11447 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11448 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
11449 | goto nla_put_failure; | |
04a773ad | 11450 | |
3b7b72ee | 11451 | genlmsg_end(msg, hdr); |
04a773ad | 11452 | |
68eb5503 | 11453 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11454 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
11455 | return; |
11456 | ||
11457 | nla_put_failure: | |
11458 | genlmsg_cancel(msg, hdr); | |
11459 | nlmsg_free(msg); | |
11460 | } | |
11461 | ||
947add36 JB |
11462 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
11463 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 11464 | { |
947add36 | 11465 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 11466 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
11467 | struct sk_buff *msg; |
11468 | void *hdr; | |
11469 | ||
947add36 JB |
11470 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
11471 | return; | |
11472 | ||
11473 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
11474 | ||
c93b5e71 JC |
11475 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11476 | if (!msg) | |
11477 | return; | |
11478 | ||
11479 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
11480 | if (!hdr) { | |
11481 | nlmsg_free(msg); | |
11482 | return; | |
11483 | } | |
11484 | ||
9360ffd1 | 11485 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
11486 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
11487 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
11488 | (ie_len && ie && |
11489 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
11490 | goto nla_put_failure; | |
c93b5e71 | 11491 | |
3b7b72ee | 11492 | genlmsg_end(msg, hdr); |
c93b5e71 | 11493 | |
68eb5503 | 11494 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11495 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
11496 | return; |
11497 | ||
11498 | nla_put_failure: | |
11499 | genlmsg_cancel(msg, hdr); | |
11500 | nlmsg_free(msg); | |
11501 | } | |
947add36 | 11502 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 11503 | |
a3b8b056 JM |
11504 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
11505 | struct net_device *netdev, const u8 *addr, | |
11506 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 11507 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
11508 | { |
11509 | struct sk_buff *msg; | |
11510 | void *hdr; | |
11511 | ||
e6d6e342 | 11512 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
11513 | if (!msg) |
11514 | return; | |
11515 | ||
11516 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
11517 | if (!hdr) { | |
11518 | nlmsg_free(msg); | |
11519 | return; | |
11520 | } | |
11521 | ||
9360ffd1 DM |
11522 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11523 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11524 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
11525 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
11526 | (key_id != -1 && | |
11527 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
11528 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
11529 | goto nla_put_failure; | |
a3b8b056 | 11530 | |
3b7b72ee | 11531 | genlmsg_end(msg, hdr); |
a3b8b056 | 11532 | |
68eb5503 | 11533 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11534 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
11535 | return; |
11536 | ||
11537 | nla_put_failure: | |
11538 | genlmsg_cancel(msg, hdr); | |
11539 | nlmsg_free(msg); | |
11540 | } | |
11541 | ||
6bad8766 LR |
11542 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
11543 | struct ieee80211_channel *channel_before, | |
11544 | struct ieee80211_channel *channel_after) | |
11545 | { | |
11546 | struct sk_buff *msg; | |
11547 | void *hdr; | |
11548 | struct nlattr *nl_freq; | |
11549 | ||
fd2120ca | 11550 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
11551 | if (!msg) |
11552 | return; | |
11553 | ||
11554 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
11555 | if (!hdr) { | |
11556 | nlmsg_free(msg); | |
11557 | return; | |
11558 | } | |
11559 | ||
11560 | /* | |
11561 | * Since we are applying the beacon hint to a wiphy we know its | |
11562 | * wiphy_idx is valid | |
11563 | */ | |
9360ffd1 DM |
11564 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
11565 | goto nla_put_failure; | |
6bad8766 LR |
11566 | |
11567 | /* Before */ | |
11568 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
11569 | if (!nl_freq) | |
11570 | goto nla_put_failure; | |
cdc89b97 | 11571 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
11572 | goto nla_put_failure; |
11573 | nla_nest_end(msg, nl_freq); | |
11574 | ||
11575 | /* After */ | |
11576 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
11577 | if (!nl_freq) | |
11578 | goto nla_put_failure; | |
cdc89b97 | 11579 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
11580 | goto nla_put_failure; |
11581 | nla_nest_end(msg, nl_freq); | |
11582 | ||
3b7b72ee | 11583 | genlmsg_end(msg, hdr); |
6bad8766 | 11584 | |
463d0183 | 11585 | rcu_read_lock(); |
68eb5503 | 11586 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11587 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 11588 | rcu_read_unlock(); |
6bad8766 LR |
11589 | |
11590 | return; | |
11591 | ||
11592 | nla_put_failure: | |
11593 | genlmsg_cancel(msg, hdr); | |
11594 | nlmsg_free(msg); | |
11595 | } | |
11596 | ||
9588bbd5 JM |
11597 | static void nl80211_send_remain_on_chan_event( |
11598 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 11599 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 11600 | struct ieee80211_channel *chan, |
9588bbd5 JM |
11601 | unsigned int duration, gfp_t gfp) |
11602 | { | |
11603 | struct sk_buff *msg; | |
11604 | void *hdr; | |
11605 | ||
11606 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11607 | if (!msg) | |
11608 | return; | |
11609 | ||
11610 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11611 | if (!hdr) { | |
11612 | nlmsg_free(msg); | |
11613 | return; | |
11614 | } | |
11615 | ||
9360ffd1 | 11616 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11617 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11618 | wdev->netdev->ifindex)) || | |
00f53350 | 11619 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 11620 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
11621 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
11622 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
11623 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
11624 | goto nla_put_failure; | |
9588bbd5 | 11625 | |
9360ffd1 DM |
11626 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
11627 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
11628 | goto nla_put_failure; | |
9588bbd5 | 11629 | |
3b7b72ee | 11630 | genlmsg_end(msg, hdr); |
9588bbd5 | 11631 | |
68eb5503 | 11632 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11633 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
11634 | return; |
11635 | ||
11636 | nla_put_failure: | |
11637 | genlmsg_cancel(msg, hdr); | |
11638 | nlmsg_free(msg); | |
11639 | } | |
11640 | ||
947add36 JB |
11641 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
11642 | struct ieee80211_channel *chan, | |
11643 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 11644 | { |
947add36 | 11645 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11646 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11647 | |
11648 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 11649 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 11650 | rdev, wdev, cookie, chan, |
42d97a59 | 11651 | duration, gfp); |
9588bbd5 | 11652 | } |
947add36 | 11653 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 11654 | |
947add36 JB |
11655 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
11656 | struct ieee80211_channel *chan, | |
11657 | gfp_t gfp) | |
9588bbd5 | 11658 | { |
947add36 | 11659 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11660 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11661 | |
11662 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 11663 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 11664 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 11665 | } |
947add36 | 11666 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 11667 | |
947add36 JB |
11668 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
11669 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 11670 | { |
947add36 | 11671 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11672 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
11673 | struct sk_buff *msg; |
11674 | ||
947add36 JB |
11675 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
11676 | ||
58050fce | 11677 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
11678 | if (!msg) |
11679 | return; | |
11680 | ||
66266b3a JL |
11681 | if (nl80211_send_station(msg, 0, 0, 0, |
11682 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
11683 | nlmsg_free(msg); |
11684 | return; | |
11685 | } | |
11686 | ||
68eb5503 | 11687 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11688 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 11689 | } |
947add36 | 11690 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 11691 | |
947add36 | 11692 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 11693 | { |
947add36 | 11694 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11695 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b JM |
11696 | struct sk_buff *msg; |
11697 | void *hdr; | |
11698 | ||
947add36 JB |
11699 | trace_cfg80211_del_sta(dev, mac_addr); |
11700 | ||
58050fce | 11701 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
11702 | if (!msg) |
11703 | return; | |
11704 | ||
11705 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
11706 | if (!hdr) { | |
11707 | nlmsg_free(msg); | |
11708 | return; | |
11709 | } | |
11710 | ||
9360ffd1 DM |
11711 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
11712 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
11713 | goto nla_put_failure; | |
ec15e68b | 11714 | |
3b7b72ee | 11715 | genlmsg_end(msg, hdr); |
ec15e68b | 11716 | |
68eb5503 | 11717 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11718 | NL80211_MCGRP_MLME, gfp); |
ec15e68b JM |
11719 | return; |
11720 | ||
11721 | nla_put_failure: | |
11722 | genlmsg_cancel(msg, hdr); | |
11723 | nlmsg_free(msg); | |
11724 | } | |
947add36 | 11725 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 11726 | |
947add36 JB |
11727 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
11728 | enum nl80211_connect_failed_reason reason, | |
11729 | gfp_t gfp) | |
ed44a951 | 11730 | { |
947add36 | 11731 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11732 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
11733 | struct sk_buff *msg; |
11734 | void *hdr; | |
11735 | ||
11736 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
11737 | if (!msg) | |
11738 | return; | |
11739 | ||
11740 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
11741 | if (!hdr) { | |
11742 | nlmsg_free(msg); | |
11743 | return; | |
11744 | } | |
11745 | ||
11746 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11747 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
11748 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
11749 | goto nla_put_failure; | |
11750 | ||
11751 | genlmsg_end(msg, hdr); | |
11752 | ||
68eb5503 | 11753 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11754 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
11755 | return; |
11756 | ||
11757 | nla_put_failure: | |
11758 | genlmsg_cancel(msg, hdr); | |
11759 | nlmsg_free(msg); | |
11760 | } | |
947add36 | 11761 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 11762 | |
b92ab5d8 JB |
11763 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
11764 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
11765 | { |
11766 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 11767 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
11768 | struct sk_buff *msg; |
11769 | void *hdr; | |
15e47304 | 11770 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 11771 | |
15e47304 | 11772 | if (!nlportid) |
28946da7 JB |
11773 | return false; |
11774 | ||
11775 | msg = nlmsg_new(100, gfp); | |
11776 | if (!msg) | |
11777 | return true; | |
11778 | ||
b92ab5d8 | 11779 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
11780 | if (!hdr) { |
11781 | nlmsg_free(msg); | |
11782 | return true; | |
11783 | } | |
11784 | ||
9360ffd1 DM |
11785 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11786 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11787 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11788 | goto nla_put_failure; | |
28946da7 | 11789 | |
9c90a9f6 | 11790 | genlmsg_end(msg, hdr); |
15e47304 | 11791 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
11792 | return true; |
11793 | ||
11794 | nla_put_failure: | |
11795 | genlmsg_cancel(msg, hdr); | |
11796 | nlmsg_free(msg); | |
11797 | return true; | |
11798 | } | |
11799 | ||
947add36 JB |
11800 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
11801 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11802 | { |
947add36 JB |
11803 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11804 | bool ret; | |
11805 | ||
11806 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
11807 | ||
11808 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11809 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
11810 | trace_cfg80211_return_bool(false); | |
11811 | return false; | |
11812 | } | |
11813 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
11814 | addr, gfp); | |
11815 | trace_cfg80211_return_bool(ret); | |
11816 | return ret; | |
b92ab5d8 | 11817 | } |
947add36 | 11818 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 11819 | |
947add36 JB |
11820 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
11821 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11822 | { |
947add36 JB |
11823 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11824 | bool ret; | |
11825 | ||
11826 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
11827 | ||
11828 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11829 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
11830 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
11831 | trace_cfg80211_return_bool(false); | |
11832 | return false; | |
11833 | } | |
11834 | ret = __nl80211_unexpected_frame(dev, | |
11835 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
11836 | addr, gfp); | |
11837 | trace_cfg80211_return_bool(ret); | |
11838 | return ret; | |
b92ab5d8 | 11839 | } |
947add36 | 11840 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 11841 | |
2e161f78 | 11842 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 11843 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 11844 | int freq, int sig_dbm, |
19504cf5 | 11845 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 11846 | { |
71bbc994 | 11847 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11848 | struct sk_buff *msg; |
11849 | void *hdr; | |
026331c4 JM |
11850 | |
11851 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11852 | if (!msg) | |
11853 | return -ENOMEM; | |
11854 | ||
2e161f78 | 11855 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
11856 | if (!hdr) { |
11857 | nlmsg_free(msg); | |
11858 | return -ENOMEM; | |
11859 | } | |
11860 | ||
9360ffd1 | 11861 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11862 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11863 | netdev->ifindex)) || | |
a838490b | 11864 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11865 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
11866 | (sig_dbm && | |
11867 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
11868 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11869 | (flags && | |
11870 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 11871 | goto nla_put_failure; |
026331c4 | 11872 | |
3b7b72ee | 11873 | genlmsg_end(msg, hdr); |
026331c4 | 11874 | |
15e47304 | 11875 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
11876 | |
11877 | nla_put_failure: | |
11878 | genlmsg_cancel(msg, hdr); | |
11879 | nlmsg_free(msg); | |
11880 | return -ENOBUFS; | |
11881 | } | |
11882 | ||
947add36 JB |
11883 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
11884 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 11885 | { |
947add36 | 11886 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11887 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 11888 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11889 | struct sk_buff *msg; |
11890 | void *hdr; | |
11891 | ||
947add36 JB |
11892 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
11893 | ||
026331c4 JM |
11894 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11895 | if (!msg) | |
11896 | return; | |
11897 | ||
2e161f78 | 11898 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
11899 | if (!hdr) { |
11900 | nlmsg_free(msg); | |
11901 | return; | |
11902 | } | |
11903 | ||
9360ffd1 | 11904 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11905 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11906 | netdev->ifindex)) || | |
a838490b | 11907 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11908 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11909 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
11910 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
11911 | goto nla_put_failure; | |
026331c4 | 11912 | |
3b7b72ee | 11913 | genlmsg_end(msg, hdr); |
026331c4 | 11914 | |
68eb5503 | 11915 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11916 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
11917 | return; |
11918 | ||
11919 | nla_put_failure: | |
11920 | genlmsg_cancel(msg, hdr); | |
11921 | nlmsg_free(msg); | |
11922 | } | |
947add36 | 11923 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 11924 | |
5b97f49d JB |
11925 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
11926 | const char *mac, gfp_t gfp) | |
d6dc1a38 | 11927 | { |
947add36 | 11928 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5b97f49d JB |
11929 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
11930 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11931 | void **cb; | |
947add36 | 11932 | |
d6dc1a38 | 11933 | if (!msg) |
5b97f49d | 11934 | return NULL; |
d6dc1a38 | 11935 | |
5b97f49d JB |
11936 | cb = (void **)msg->cb; |
11937 | ||
11938 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11939 | if (!cb[0]) { | |
d6dc1a38 | 11940 | nlmsg_free(msg); |
5b97f49d | 11941 | return NULL; |
d6dc1a38 JO |
11942 | } |
11943 | ||
9360ffd1 | 11944 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 11945 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 11946 | goto nla_put_failure; |
d6dc1a38 | 11947 | |
5b97f49d | 11948 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
d6dc1a38 JO |
11949 | goto nla_put_failure; |
11950 | ||
5b97f49d JB |
11951 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
11952 | if (!cb[1]) | |
9360ffd1 | 11953 | goto nla_put_failure; |
d6dc1a38 | 11954 | |
5b97f49d | 11955 | cb[2] = rdev; |
d6dc1a38 | 11956 | |
5b97f49d JB |
11957 | return msg; |
11958 | nla_put_failure: | |
11959 | nlmsg_free(msg); | |
11960 | return NULL; | |
11961 | } | |
11962 | ||
11963 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) | |
11964 | { | |
11965 | void **cb = (void **)msg->cb; | |
11966 | struct cfg80211_registered_device *rdev = cb[2]; | |
11967 | ||
11968 | nla_nest_end(msg, cb[1]); | |
11969 | genlmsg_end(msg, cb[0]); | |
11970 | ||
11971 | memset(msg->cb, 0, sizeof(msg->cb)); | |
d6dc1a38 | 11972 | |
68eb5503 | 11973 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11974 | NL80211_MCGRP_MLME, gfp); |
5b97f49d JB |
11975 | } |
11976 | ||
11977 | void cfg80211_cqm_rssi_notify(struct net_device *dev, | |
11978 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
11979 | gfp_t gfp) | |
11980 | { | |
11981 | struct sk_buff *msg; | |
11982 | ||
11983 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); | |
11984 | ||
98f03342 JB |
11985 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
11986 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) | |
11987 | return; | |
11988 | ||
5b97f49d JB |
11989 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
11990 | if (!msg) | |
11991 | return; | |
11992 | ||
11993 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
11994 | rssi_event)) | |
11995 | goto nla_put_failure; | |
11996 | ||
11997 | cfg80211_send_cqm(msg, gfp); | |
11998 | ||
d6dc1a38 JO |
11999 | return; |
12000 | ||
12001 | nla_put_failure: | |
d6dc1a38 JO |
12002 | nlmsg_free(msg); |
12003 | } | |
947add36 | 12004 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 12005 | |
5b97f49d JB |
12006 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
12007 | const u8 *peer, u32 num_packets, | |
12008 | u32 rate, u32 intvl, gfp_t gfp) | |
12009 | { | |
12010 | struct sk_buff *msg; | |
12011 | ||
12012 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12013 | if (!msg) | |
12014 | return; | |
12015 | ||
12016 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
12017 | goto nla_put_failure; | |
12018 | ||
12019 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
12020 | goto nla_put_failure; | |
12021 | ||
12022 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
12023 | goto nla_put_failure; | |
12024 | ||
12025 | cfg80211_send_cqm(msg, gfp); | |
12026 | return; | |
12027 | ||
12028 | nla_put_failure: | |
12029 | nlmsg_free(msg); | |
12030 | } | |
12031 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); | |
12032 | ||
12033 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, | |
12034 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
12035 | { | |
12036 | struct sk_buff *msg; | |
12037 | ||
12038 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); | |
12039 | ||
12040 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12041 | if (!msg) | |
12042 | return; | |
12043 | ||
12044 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) | |
12045 | goto nla_put_failure; | |
12046 | ||
12047 | cfg80211_send_cqm(msg, gfp); | |
12048 | return; | |
12049 | ||
12050 | nla_put_failure: | |
12051 | nlmsg_free(msg); | |
12052 | } | |
12053 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); | |
12054 | ||
98f03342 JB |
12055 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
12056 | { | |
12057 | struct sk_buff *msg; | |
12058 | ||
12059 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); | |
12060 | if (!msg) | |
12061 | return; | |
12062 | ||
12063 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) | |
12064 | goto nla_put_failure; | |
12065 | ||
12066 | cfg80211_send_cqm(msg, gfp); | |
12067 | return; | |
12068 | ||
12069 | nla_put_failure: | |
12070 | nlmsg_free(msg); | |
12071 | } | |
12072 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); | |
12073 | ||
947add36 JB |
12074 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
12075 | struct net_device *netdev, const u8 *bssid, | |
12076 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
12077 | { |
12078 | struct sk_buff *msg; | |
12079 | struct nlattr *rekey_attr; | |
12080 | void *hdr; | |
12081 | ||
58050fce | 12082 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
12083 | if (!msg) |
12084 | return; | |
12085 | ||
12086 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
12087 | if (!hdr) { | |
12088 | nlmsg_free(msg); | |
12089 | return; | |
12090 | } | |
12091 | ||
9360ffd1 DM |
12092 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12093 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12094 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
12095 | goto nla_put_failure; | |
e5497d76 JB |
12096 | |
12097 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
12098 | if (!rekey_attr) | |
12099 | goto nla_put_failure; | |
12100 | ||
9360ffd1 DM |
12101 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
12102 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
12103 | goto nla_put_failure; | |
e5497d76 JB |
12104 | |
12105 | nla_nest_end(msg, rekey_attr); | |
12106 | ||
3b7b72ee | 12107 | genlmsg_end(msg, hdr); |
e5497d76 | 12108 | |
68eb5503 | 12109 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12110 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
12111 | return; |
12112 | ||
12113 | nla_put_failure: | |
12114 | genlmsg_cancel(msg, hdr); | |
12115 | nlmsg_free(msg); | |
12116 | } | |
12117 | ||
947add36 JB |
12118 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
12119 | const u8 *replay_ctr, gfp_t gfp) | |
12120 | { | |
12121 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12122 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12123 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12124 | |
12125 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
12126 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
12127 | } | |
12128 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
12129 | ||
12130 | static void | |
12131 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
12132 | struct net_device *netdev, int index, | |
12133 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
12134 | { |
12135 | struct sk_buff *msg; | |
12136 | struct nlattr *attr; | |
12137 | void *hdr; | |
12138 | ||
58050fce | 12139 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
12140 | if (!msg) |
12141 | return; | |
12142 | ||
12143 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
12144 | if (!hdr) { | |
12145 | nlmsg_free(msg); | |
12146 | return; | |
12147 | } | |
12148 | ||
9360ffd1 DM |
12149 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12150 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
12151 | goto nla_put_failure; | |
c9df56b4 JM |
12152 | |
12153 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
12154 | if (!attr) | |
12155 | goto nla_put_failure; | |
12156 | ||
9360ffd1 DM |
12157 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
12158 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
12159 | (preauth && | |
12160 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
12161 | goto nla_put_failure; | |
c9df56b4 JM |
12162 | |
12163 | nla_nest_end(msg, attr); | |
12164 | ||
3b7b72ee | 12165 | genlmsg_end(msg, hdr); |
c9df56b4 | 12166 | |
68eb5503 | 12167 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12168 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
12169 | return; |
12170 | ||
12171 | nla_put_failure: | |
12172 | genlmsg_cancel(msg, hdr); | |
12173 | nlmsg_free(msg); | |
12174 | } | |
12175 | ||
947add36 JB |
12176 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
12177 | const u8 *bssid, bool preauth, gfp_t gfp) | |
12178 | { | |
12179 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12180 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12181 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12182 | |
12183 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
12184 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
12185 | } | |
12186 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
12187 | ||
12188 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
12189 | struct net_device *netdev, | |
12190 | struct cfg80211_chan_def *chandef, | |
f8d7552e LC |
12191 | gfp_t gfp, |
12192 | enum nl80211_commands notif, | |
12193 | u8 count) | |
5314526b TP |
12194 | { |
12195 | struct sk_buff *msg; | |
12196 | void *hdr; | |
12197 | ||
58050fce | 12198 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
12199 | if (!msg) |
12200 | return; | |
12201 | ||
f8d7552e | 12202 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
5314526b TP |
12203 | if (!hdr) { |
12204 | nlmsg_free(msg); | |
12205 | return; | |
12206 | } | |
12207 | ||
683b6d3b JB |
12208 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
12209 | goto nla_put_failure; | |
12210 | ||
12211 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 12212 | goto nla_put_failure; |
5314526b | 12213 | |
f8d7552e LC |
12214 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
12215 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) | |
12216 | goto nla_put_failure; | |
12217 | ||
5314526b TP |
12218 | genlmsg_end(msg, hdr); |
12219 | ||
68eb5503 | 12220 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12221 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
12222 | return; |
12223 | ||
12224 | nla_put_failure: | |
12225 | genlmsg_cancel(msg, hdr); | |
12226 | nlmsg_free(msg); | |
12227 | } | |
12228 | ||
947add36 JB |
12229 | void cfg80211_ch_switch_notify(struct net_device *dev, |
12230 | struct cfg80211_chan_def *chandef) | |
84f10708 | 12231 | { |
947add36 JB |
12232 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
12233 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12234 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 12235 | |
e487eaeb | 12236 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 12237 | |
e487eaeb | 12238 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 | 12239 | |
9e0e2961 | 12240 | wdev->chandef = *chandef; |
96f55f12 | 12241 | wdev->preset_chandef = *chandef; |
f8d7552e LC |
12242 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
12243 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); | |
947add36 JB |
12244 | } |
12245 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
12246 | ||
f8d7552e LC |
12247 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
12248 | struct cfg80211_chan_def *chandef, | |
12249 | u8 count) | |
12250 | { | |
12251 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12252 | struct wiphy *wiphy = wdev->wiphy; | |
12253 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
12254 | ||
12255 | trace_cfg80211_ch_switch_started_notify(dev, chandef); | |
12256 | ||
12257 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | |
12258 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); | |
12259 | } | |
12260 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | |
12261 | ||
04f39047 SW |
12262 | void |
12263 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 12264 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
12265 | enum nl80211_radar_event event, |
12266 | struct net_device *netdev, gfp_t gfp) | |
12267 | { | |
12268 | struct sk_buff *msg; | |
12269 | void *hdr; | |
12270 | ||
12271 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12272 | if (!msg) | |
12273 | return; | |
12274 | ||
12275 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
12276 | if (!hdr) { | |
12277 | nlmsg_free(msg); | |
12278 | return; | |
12279 | } | |
12280 | ||
12281 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
12282 | goto nla_put_failure; | |
12283 | ||
12284 | /* NOP and radar events don't need a netdev parameter */ | |
12285 | if (netdev) { | |
12286 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
12287 | ||
12288 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12289 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12290 | goto nla_put_failure; | |
12291 | } | |
12292 | ||
12293 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
12294 | goto nla_put_failure; | |
12295 | ||
12296 | if (nl80211_send_chandef(msg, chandef)) | |
12297 | goto nla_put_failure; | |
12298 | ||
9c90a9f6 | 12299 | genlmsg_end(msg, hdr); |
04f39047 | 12300 | |
68eb5503 | 12301 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12302 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
12303 | return; |
12304 | ||
12305 | nla_put_failure: | |
12306 | genlmsg_cancel(msg, hdr); | |
12307 | nlmsg_free(msg); | |
12308 | } | |
12309 | ||
7f6cf311 JB |
12310 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
12311 | u64 cookie, bool acked, gfp_t gfp) | |
12312 | { | |
12313 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12314 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
12315 | struct sk_buff *msg; |
12316 | void *hdr; | |
7f6cf311 | 12317 | |
4ee3e063 BL |
12318 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
12319 | ||
58050fce | 12320 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 12321 | |
7f6cf311 JB |
12322 | if (!msg) |
12323 | return; | |
12324 | ||
12325 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
12326 | if (!hdr) { | |
12327 | nlmsg_free(msg); | |
12328 | return; | |
12329 | } | |
12330 | ||
9360ffd1 DM |
12331 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12332 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12333 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
12334 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
12335 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
12336 | goto nla_put_failure; | |
7f6cf311 | 12337 | |
9c90a9f6 | 12338 | genlmsg_end(msg, hdr); |
7f6cf311 | 12339 | |
68eb5503 | 12340 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12341 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
12342 | return; |
12343 | ||
12344 | nla_put_failure: | |
12345 | genlmsg_cancel(msg, hdr); | |
12346 | nlmsg_free(msg); | |
12347 | } | |
12348 | EXPORT_SYMBOL(cfg80211_probe_status); | |
12349 | ||
5e760230 JB |
12350 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
12351 | const u8 *frame, size_t len, | |
37c73b5f | 12352 | int freq, int sig_dbm) |
5e760230 | 12353 | { |
f26cbf40 | 12354 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
12355 | struct sk_buff *msg; |
12356 | void *hdr; | |
37c73b5f | 12357 | struct cfg80211_beacon_registration *reg; |
5e760230 | 12358 | |
4ee3e063 BL |
12359 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
12360 | ||
37c73b5f BG |
12361 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12362 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
12363 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
12364 | if (!msg) { | |
12365 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
12366 | return; | |
12367 | } | |
5e760230 | 12368 | |
37c73b5f BG |
12369 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
12370 | if (!hdr) | |
12371 | goto nla_put_failure; | |
5e760230 | 12372 | |
37c73b5f BG |
12373 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12374 | (freq && | |
12375 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
12376 | (sig_dbm && | |
12377 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
12378 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
12379 | goto nla_put_failure; | |
5e760230 | 12380 | |
37c73b5f | 12381 | genlmsg_end(msg, hdr); |
5e760230 | 12382 | |
37c73b5f BG |
12383 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
12384 | } | |
12385 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
12386 | return; |
12387 | ||
12388 | nla_put_failure: | |
37c73b5f BG |
12389 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
12390 | if (hdr) | |
12391 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
12392 | nlmsg_free(msg); |
12393 | } | |
12394 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
12395 | ||
cd8f7cb4 | 12396 | #ifdef CONFIG_PM |
8cd4d456 LC |
12397 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
12398 | struct cfg80211_wowlan_wakeup *wakeup) | |
12399 | { | |
12400 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | |
12401 | struct nlattr *nl_results, *nl_match, *nl_freqs; | |
12402 | int i, j; | |
12403 | ||
12404 | nl_results = nla_nest_start( | |
12405 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | |
12406 | if (!nl_results) | |
12407 | return -EMSGSIZE; | |
12408 | ||
12409 | for (i = 0; i < nd->n_matches; i++) { | |
12410 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | |
12411 | ||
12412 | nl_match = nla_nest_start(msg, i); | |
12413 | if (!nl_match) | |
12414 | break; | |
12415 | ||
12416 | /* The SSID attribute is optional in nl80211, but for | |
12417 | * simplicity reasons it's always present in the | |
12418 | * cfg80211 structure. If a driver can't pass the | |
12419 | * SSID, that needs to be changed. A zero length SSID | |
12420 | * is still a valid SSID (wildcard), so it cannot be | |
12421 | * used for this purpose. | |
12422 | */ | |
12423 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | |
12424 | match->ssid.ssid)) { | |
12425 | nla_nest_cancel(msg, nl_match); | |
12426 | goto out; | |
12427 | } | |
12428 | ||
12429 | if (match->n_channels) { | |
12430 | nl_freqs = nla_nest_start( | |
12431 | msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
12432 | if (!nl_freqs) { | |
12433 | nla_nest_cancel(msg, nl_match); | |
12434 | goto out; | |
12435 | } | |
12436 | ||
12437 | for (j = 0; j < match->n_channels; j++) { | |
12438 | if (nla_put_u32(msg, | |
12439 | NL80211_ATTR_WIPHY_FREQ, | |
12440 | match->channels[j])) { | |
12441 | nla_nest_cancel(msg, nl_freqs); | |
12442 | nla_nest_cancel(msg, nl_match); | |
12443 | goto out; | |
12444 | } | |
12445 | } | |
12446 | ||
12447 | nla_nest_end(msg, nl_freqs); | |
12448 | } | |
12449 | ||
12450 | nla_nest_end(msg, nl_match); | |
12451 | } | |
12452 | ||
12453 | out: | |
12454 | nla_nest_end(msg, nl_results); | |
12455 | return 0; | |
12456 | } | |
12457 | ||
cd8f7cb4 JB |
12458 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
12459 | struct cfg80211_wowlan_wakeup *wakeup, | |
12460 | gfp_t gfp) | |
12461 | { | |
f26cbf40 | 12462 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
12463 | struct sk_buff *msg; |
12464 | void *hdr; | |
9c90a9f6 | 12465 | int size = 200; |
cd8f7cb4 JB |
12466 | |
12467 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
12468 | ||
12469 | if (wakeup) | |
12470 | size += wakeup->packet_present_len; | |
12471 | ||
12472 | msg = nlmsg_new(size, gfp); | |
12473 | if (!msg) | |
12474 | return; | |
12475 | ||
12476 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
12477 | if (!hdr) | |
12478 | goto free_msg; | |
12479 | ||
12480 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12481 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12482 | goto free_msg; | |
12483 | ||
12484 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
12485 | wdev->netdev->ifindex)) | |
12486 | goto free_msg; | |
12487 | ||
12488 | if (wakeup) { | |
12489 | struct nlattr *reasons; | |
12490 | ||
12491 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
12492 | if (!reasons) |
12493 | goto free_msg; | |
cd8f7cb4 JB |
12494 | |
12495 | if (wakeup->disconnect && | |
12496 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
12497 | goto free_msg; | |
12498 | if (wakeup->magic_pkt && | |
12499 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
12500 | goto free_msg; | |
12501 | if (wakeup->gtk_rekey_failure && | |
12502 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
12503 | goto free_msg; | |
12504 | if (wakeup->eap_identity_req && | |
12505 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
12506 | goto free_msg; | |
12507 | if (wakeup->four_way_handshake && | |
12508 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
12509 | goto free_msg; | |
12510 | if (wakeup->rfkill_release && | |
12511 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
12512 | goto free_msg; | |
12513 | ||
12514 | if (wakeup->pattern_idx >= 0 && | |
12515 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
12516 | wakeup->pattern_idx)) | |
12517 | goto free_msg; | |
12518 | ||
ae917c9f JB |
12519 | if (wakeup->tcp_match && |
12520 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
12521 | goto free_msg; | |
2a0e047e | 12522 | |
ae917c9f JB |
12523 | if (wakeup->tcp_connlost && |
12524 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
12525 | goto free_msg; | |
2a0e047e | 12526 | |
ae917c9f JB |
12527 | if (wakeup->tcp_nomoretokens && |
12528 | nla_put_flag(msg, | |
12529 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
12530 | goto free_msg; | |
2a0e047e | 12531 | |
cd8f7cb4 JB |
12532 | if (wakeup->packet) { |
12533 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
12534 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
12535 | ||
12536 | if (!wakeup->packet_80211) { | |
12537 | pkt_attr = | |
12538 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
12539 | len_attr = | |
12540 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
12541 | } | |
12542 | ||
12543 | if (wakeup->packet_len && | |
12544 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
12545 | goto free_msg; | |
12546 | ||
12547 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
12548 | wakeup->packet)) | |
12549 | goto free_msg; | |
12550 | } | |
12551 | ||
8cd4d456 LC |
12552 | if (wakeup->net_detect && |
12553 | cfg80211_net_detect_results(msg, wakeup)) | |
12554 | goto free_msg; | |
12555 | ||
cd8f7cb4 JB |
12556 | nla_nest_end(msg, reasons); |
12557 | } | |
12558 | ||
9c90a9f6 | 12559 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 12560 | |
68eb5503 | 12561 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12562 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
12563 | return; |
12564 | ||
12565 | free_msg: | |
12566 | nlmsg_free(msg); | |
12567 | } | |
12568 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
12569 | #endif | |
12570 | ||
3475b094 JM |
12571 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
12572 | enum nl80211_tdls_operation oper, | |
12573 | u16 reason_code, gfp_t gfp) | |
12574 | { | |
12575 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12576 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
12577 | struct sk_buff *msg; |
12578 | void *hdr; | |
3475b094 JM |
12579 | |
12580 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
12581 | reason_code); | |
12582 | ||
12583 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12584 | if (!msg) | |
12585 | return; | |
12586 | ||
12587 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
12588 | if (!hdr) { | |
12589 | nlmsg_free(msg); | |
12590 | return; | |
12591 | } | |
12592 | ||
12593 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12594 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12595 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
12596 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
12597 | (reason_code > 0 && | |
12598 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
12599 | goto nla_put_failure; | |
12600 | ||
9c90a9f6 | 12601 | genlmsg_end(msg, hdr); |
3475b094 | 12602 | |
68eb5503 | 12603 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12604 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
12605 | return; |
12606 | ||
12607 | nla_put_failure: | |
12608 | genlmsg_cancel(msg, hdr); | |
12609 | nlmsg_free(msg); | |
12610 | } | |
12611 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
12612 | ||
026331c4 JM |
12613 | static int nl80211_netlink_notify(struct notifier_block * nb, |
12614 | unsigned long state, | |
12615 | void *_notify) | |
12616 | { | |
12617 | struct netlink_notify *notify = _notify; | |
12618 | struct cfg80211_registered_device *rdev; | |
12619 | struct wireless_dev *wdev; | |
37c73b5f | 12620 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
12621 | |
12622 | if (state != NETLINK_URELEASE) | |
12623 | return NOTIFY_DONE; | |
12624 | ||
12625 | rcu_read_lock(); | |
12626 | ||
5e760230 | 12627 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
78f22b6a | 12628 | bool schedule_destroy_work = false; |
93a1e86c JR |
12629 | bool schedule_scan_stop = false; |
12630 | struct cfg80211_sched_scan_request *sched_scan_req = | |
12631 | rcu_dereference(rdev->sched_scan_req); | |
12632 | ||
12633 | if (sched_scan_req && notify->portid && | |
12634 | sched_scan_req->owner_nlportid == notify->portid) | |
12635 | schedule_scan_stop = true; | |
78f22b6a JB |
12636 | |
12637 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { | |
15e47304 | 12638 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 12639 | |
78f22b6a JB |
12640 | if (wdev->owner_nlportid == notify->portid) |
12641 | schedule_destroy_work = true; | |
12642 | } | |
12643 | ||
37c73b5f BG |
12644 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12645 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
12646 | list) { | |
12647 | if (reg->nlportid == notify->portid) { | |
12648 | list_del(®->list); | |
12649 | kfree(reg); | |
12650 | break; | |
12651 | } | |
12652 | } | |
12653 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
78f22b6a JB |
12654 | |
12655 | if (schedule_destroy_work) { | |
12656 | struct cfg80211_iface_destroy *destroy; | |
12657 | ||
12658 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | |
12659 | if (destroy) { | |
12660 | destroy->nlportid = notify->portid; | |
12661 | spin_lock(&rdev->destroy_list_lock); | |
12662 | list_add(&destroy->list, &rdev->destroy_list); | |
12663 | spin_unlock(&rdev->destroy_list_lock); | |
12664 | schedule_work(&rdev->destroy_work); | |
12665 | } | |
93a1e86c JR |
12666 | } else if (schedule_scan_stop) { |
12667 | sched_scan_req->owner_nlportid = 0; | |
12668 | ||
12669 | if (rdev->ops->sched_scan_stop && | |
12670 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
12671 | schedule_work(&rdev->sched_scan_stop_wk); | |
78f22b6a | 12672 | } |
5e760230 | 12673 | } |
026331c4 JM |
12674 | |
12675 | rcu_read_unlock(); | |
12676 | ||
6784c7db | 12677 | return NOTIFY_OK; |
026331c4 JM |
12678 | } |
12679 | ||
12680 | static struct notifier_block nl80211_netlink_notifier = { | |
12681 | .notifier_call = nl80211_netlink_notify, | |
12682 | }; | |
12683 | ||
355199e0 JM |
12684 | void cfg80211_ft_event(struct net_device *netdev, |
12685 | struct cfg80211_ft_event_params *ft_event) | |
12686 | { | |
12687 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 12688 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
12689 | struct sk_buff *msg; |
12690 | void *hdr; | |
355199e0 JM |
12691 | |
12692 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
12693 | ||
12694 | if (!ft_event->target_ap) | |
12695 | return; | |
12696 | ||
12697 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12698 | if (!msg) | |
12699 | return; | |
12700 | ||
12701 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
12702 | if (!hdr) |
12703 | goto out; | |
355199e0 | 12704 | |
ae917c9f JB |
12705 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12706 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12707 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
12708 | goto out; | |
355199e0 | 12709 | |
ae917c9f JB |
12710 | if (ft_event->ies && |
12711 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
12712 | goto out; | |
12713 | if (ft_event->ric_ies && | |
12714 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
12715 | ft_event->ric_ies)) | |
12716 | goto out; | |
355199e0 | 12717 | |
9c90a9f6 | 12718 | genlmsg_end(msg, hdr); |
355199e0 | 12719 | |
68eb5503 | 12720 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12721 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
12722 | return; |
12723 | out: | |
12724 | nlmsg_free(msg); | |
355199e0 JM |
12725 | } |
12726 | EXPORT_SYMBOL(cfg80211_ft_event); | |
12727 | ||
5de17984 AS |
12728 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
12729 | { | |
12730 | struct cfg80211_registered_device *rdev; | |
12731 | struct sk_buff *msg; | |
12732 | void *hdr; | |
12733 | u32 nlportid; | |
12734 | ||
f26cbf40 | 12735 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
12736 | if (!rdev->crit_proto_nlportid) |
12737 | return; | |
12738 | ||
12739 | nlportid = rdev->crit_proto_nlportid; | |
12740 | rdev->crit_proto_nlportid = 0; | |
12741 | ||
12742 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12743 | if (!msg) | |
12744 | return; | |
12745 | ||
12746 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
12747 | if (!hdr) | |
12748 | goto nla_put_failure; | |
12749 | ||
12750 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12751 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12752 | goto nla_put_failure; | |
12753 | ||
12754 | genlmsg_end(msg, hdr); | |
12755 | ||
12756 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
12757 | return; | |
12758 | ||
12759 | nla_put_failure: | |
12760 | if (hdr) | |
12761 | genlmsg_cancel(msg, hdr); | |
12762 | nlmsg_free(msg); | |
12763 | ||
12764 | } | |
12765 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
12766 | ||
348baf0e JB |
12767 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
12768 | { | |
12769 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12770 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
12771 | struct sk_buff *msg; |
12772 | void *hdr; | |
12773 | ||
12774 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12775 | if (!msg) | |
12776 | return; | |
12777 | ||
12778 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
12779 | if (!hdr) | |
12780 | goto out; | |
12781 | ||
12782 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12783 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
12784 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12785 | goto out; | |
12786 | ||
12787 | genlmsg_end(msg, hdr); | |
12788 | ||
12789 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
12790 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
12791 | return; | |
12792 | out: | |
12793 | nlmsg_free(msg); | |
12794 | } | |
12795 | ||
55682965 JB |
12796 | /* initialisation/exit functions */ |
12797 | ||
12798 | int nl80211_init(void) | |
12799 | { | |
0d63cbb5 | 12800 | int err; |
55682965 | 12801 | |
2a94fe48 JB |
12802 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
12803 | nl80211_mcgrps); | |
55682965 JB |
12804 | if (err) |
12805 | return err; | |
12806 | ||
026331c4 JM |
12807 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
12808 | if (err) | |
12809 | goto err_out; | |
12810 | ||
55682965 JB |
12811 | return 0; |
12812 | err_out: | |
12813 | genl_unregister_family(&nl80211_fam); | |
12814 | return err; | |
12815 | } | |
12816 | ||
12817 | void nl80211_exit(void) | |
12818 | { | |
026331c4 | 12819 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
12820 | genl_unregister_family(&nl80211_fam); |
12821 | } |