]>
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 }, |
78f22b6a | 391 | [NL80211_ATTR_IFACE_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 }, |
55682965 JB |
398 | }; |
399 | ||
e31b8213 | 400 | /* policy for the key attributes */ |
b54452b0 | 401 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 402 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
403 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
404 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 405 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
406 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
407 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 408 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
409 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
410 | }; | |
411 | ||
412 | /* policy for the key default flags */ | |
413 | static const struct nla_policy | |
414 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
415 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
416 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
417 | }; |
418 | ||
ff1b6e69 JB |
419 | /* policy for WoWLAN attributes */ |
420 | static const struct nla_policy | |
421 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
422 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
423 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
424 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
425 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
426 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
427 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
428 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
429 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e | 430 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
8cd4d456 | 431 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
2a0e047e JB |
432 | }; |
433 | ||
434 | static const struct nla_policy | |
435 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
436 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
437 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
438 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
439 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
440 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
441 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
442 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
443 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
444 | }, | |
445 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
446 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
447 | }, | |
448 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
449 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
450 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
451 | }; |
452 | ||
be29b99a AK |
453 | /* policy for coalesce rule attributes */ |
454 | static const struct nla_policy | |
455 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
456 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
457 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
458 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
459 | }; | |
460 | ||
e5497d76 JB |
461 | /* policy for GTK rekey offload attributes */ |
462 | static const struct nla_policy | |
463 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
464 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
465 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
466 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
467 | }; | |
468 | ||
a1f1c21c LC |
469 | static const struct nla_policy |
470 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 471 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 472 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 473 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
474 | }; |
475 | ||
97990a06 JB |
476 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
477 | struct netlink_callback *cb, | |
478 | struct cfg80211_registered_device **rdev, | |
479 | struct wireless_dev **wdev) | |
a043897a | 480 | { |
97990a06 | 481 | int err; |
a043897a | 482 | |
97990a06 | 483 | rtnl_lock(); |
a043897a | 484 | |
97990a06 JB |
485 | if (!cb->args[0]) { |
486 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
487 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
488 | nl80211_policy); | |
489 | if (err) | |
490 | goto out_unlock; | |
67748893 | 491 | |
97990a06 JB |
492 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
493 | nl80211_fam.attrbuf); | |
494 | if (IS_ERR(*wdev)) { | |
495 | err = PTR_ERR(*wdev); | |
496 | goto out_unlock; | |
497 | } | |
f26cbf40 | 498 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
499 | /* 0 is the first index - add 1 to parse only once */ |
500 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
501 | cb->args[1] = (*wdev)->identifier; |
502 | } else { | |
c319d50b JB |
503 | /* subtract the 1 again here */ |
504 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 505 | struct wireless_dev *tmp; |
67748893 | 506 | |
97990a06 JB |
507 | if (!wiphy) { |
508 | err = -ENODEV; | |
509 | goto out_unlock; | |
510 | } | |
f26cbf40 | 511 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 512 | *wdev = NULL; |
67748893 | 513 | |
97990a06 JB |
514 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
515 | if (tmp->identifier == cb->args[1]) { | |
516 | *wdev = tmp; | |
517 | break; | |
518 | } | |
519 | } | |
67748893 | 520 | |
97990a06 JB |
521 | if (!*wdev) { |
522 | err = -ENODEV; | |
523 | goto out_unlock; | |
524 | } | |
67748893 JB |
525 | } |
526 | ||
67748893 | 527 | return 0; |
97990a06 | 528 | out_unlock: |
67748893 JB |
529 | rtnl_unlock(); |
530 | return err; | |
531 | } | |
532 | ||
97990a06 | 533 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 534 | { |
67748893 JB |
535 | rtnl_unlock(); |
536 | } | |
537 | ||
f4a11bb0 JB |
538 | /* IE validation */ |
539 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
540 | { | |
541 | const u8 *pos; | |
542 | int len; | |
543 | ||
544 | if (!attr) | |
545 | return true; | |
546 | ||
547 | pos = nla_data(attr); | |
548 | len = nla_len(attr); | |
549 | ||
550 | while (len) { | |
551 | u8 elemlen; | |
552 | ||
553 | if (len < 2) | |
554 | return false; | |
555 | len -= 2; | |
556 | ||
557 | elemlen = pos[1]; | |
558 | if (elemlen > len) | |
559 | return false; | |
560 | ||
561 | len -= elemlen; | |
562 | pos += 2 + elemlen; | |
563 | } | |
564 | ||
565 | return true; | |
566 | } | |
567 | ||
55682965 | 568 | /* message building helper */ |
15e47304 | 569 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
570 | int flags, u8 cmd) |
571 | { | |
572 | /* since there is no private header just add the generic one */ | |
15e47304 | 573 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
574 | } |
575 | ||
5dab3b8a | 576 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
577 | struct ieee80211_channel *chan, |
578 | bool large) | |
5dab3b8a | 579 | { |
ea077c1c RL |
580 | /* Some channels must be completely excluded from the |
581 | * list to protect old user-space tools from breaking | |
582 | */ | |
583 | if (!large && chan->flags & | |
584 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
585 | return 0; | |
586 | ||
9360ffd1 DM |
587 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
588 | chan->center_freq)) | |
589 | goto nla_put_failure; | |
5dab3b8a | 590 | |
9360ffd1 DM |
591 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
592 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
593 | goto nla_put_failure; | |
8fe02e16 LR |
594 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
595 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
596 | goto nla_put_failure; | |
597 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
598 | goto nla_put_failure; | |
599 | } | |
cdc89b97 JB |
600 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
601 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
602 | goto nla_put_failure; | |
603 | if (large) { | |
604 | u32 time; | |
605 | ||
606 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
607 | ||
608 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
609 | chan->dfs_state)) | |
610 | goto nla_put_failure; | |
611 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
612 | time)) | |
613 | goto nla_put_failure; | |
089027e5 JD |
614 | if (nla_put_u32(msg, |
615 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
616 | chan->dfs_cac_ms)) | |
617 | goto nla_put_failure; | |
cdc89b97 JB |
618 | } |
619 | } | |
5dab3b8a | 620 | |
fe1abafd JB |
621 | if (large) { |
622 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
623 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
624 | goto nla_put_failure; | |
625 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
626 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
627 | goto nla_put_failure; | |
628 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
629 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
630 | goto nla_put_failure; | |
631 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
632 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
633 | goto nla_put_failure; | |
570dbde1 DS |
634 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
635 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
636 | goto nla_put_failure; | |
637 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && | |
638 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) | |
639 | goto nla_put_failure; | |
ea077c1c RL |
640 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
641 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
642 | goto nla_put_failure; | |
643 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
644 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
645 | goto nla_put_failure; | |
fe1abafd JB |
646 | } |
647 | ||
9360ffd1 DM |
648 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
649 | DBM_TO_MBM(chan->max_power))) | |
650 | goto nla_put_failure; | |
5dab3b8a LR |
651 | |
652 | return 0; | |
653 | ||
654 | nla_put_failure: | |
655 | return -ENOBUFS; | |
656 | } | |
657 | ||
55682965 JB |
658 | /* netlink command implementations */ |
659 | ||
b9454e83 JB |
660 | struct key_parse { |
661 | struct key_params p; | |
662 | int idx; | |
e31b8213 | 663 | int type; |
b9454e83 | 664 | bool def, defmgmt; |
dbd2fd65 | 665 | bool def_uni, def_multi; |
b9454e83 JB |
666 | }; |
667 | ||
668 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
669 | { | |
670 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
671 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
672 | nl80211_key_policy); | |
673 | if (err) | |
674 | return err; | |
675 | ||
676 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
677 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
678 | ||
dbd2fd65 JB |
679 | if (k->def) { |
680 | k->def_uni = true; | |
681 | k->def_multi = true; | |
682 | } | |
683 | if (k->defmgmt) | |
684 | k->def_multi = true; | |
685 | ||
b9454e83 JB |
686 | if (tb[NL80211_KEY_IDX]) |
687 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
688 | ||
689 | if (tb[NL80211_KEY_DATA]) { | |
690 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
691 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
692 | } | |
693 | ||
694 | if (tb[NL80211_KEY_SEQ]) { | |
695 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
696 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
697 | } | |
698 | ||
699 | if (tb[NL80211_KEY_CIPHER]) | |
700 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
701 | ||
e31b8213 JB |
702 | if (tb[NL80211_KEY_TYPE]) { |
703 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
704 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
705 | return -EINVAL; | |
706 | } | |
707 | ||
dbd2fd65 JB |
708 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
709 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
710 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
711 | tb[NL80211_KEY_DEFAULT_TYPES], | |
712 | nl80211_key_default_policy); | |
dbd2fd65 JB |
713 | if (err) |
714 | return err; | |
715 | ||
716 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
717 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
718 | } | |
719 | ||
b9454e83 JB |
720 | return 0; |
721 | } | |
722 | ||
723 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
724 | { | |
725 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
726 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
727 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
728 | } | |
729 | ||
730 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
731 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
732 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
733 | } | |
734 | ||
735 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
736 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
737 | ||
738 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
739 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
740 | ||
741 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
742 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
743 | ||
dbd2fd65 JB |
744 | if (k->def) { |
745 | k->def_uni = true; | |
746 | k->def_multi = true; | |
747 | } | |
748 | if (k->defmgmt) | |
749 | k->def_multi = true; | |
750 | ||
e31b8213 JB |
751 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
752 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
753 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
754 | return -EINVAL; | |
755 | } | |
756 | ||
dbd2fd65 JB |
757 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
758 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
759 | int err = nla_parse_nested( | |
760 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
761 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
762 | nl80211_key_default_policy); | |
763 | if (err) | |
764 | return err; | |
765 | ||
766 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
767 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
768 | } | |
769 | ||
b9454e83 JB |
770 | return 0; |
771 | } | |
772 | ||
773 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
774 | { | |
775 | int err; | |
776 | ||
777 | memset(k, 0, sizeof(*k)); | |
778 | k->idx = -1; | |
e31b8213 | 779 | k->type = -1; |
b9454e83 JB |
780 | |
781 | if (info->attrs[NL80211_ATTR_KEY]) | |
782 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
783 | else | |
784 | err = nl80211_parse_key_old(info, k); | |
785 | ||
786 | if (err) | |
787 | return err; | |
788 | ||
789 | if (k->def && k->defmgmt) | |
790 | return -EINVAL; | |
791 | ||
dbd2fd65 JB |
792 | if (k->defmgmt) { |
793 | if (k->def_uni || !k->def_multi) | |
794 | return -EINVAL; | |
795 | } | |
796 | ||
b9454e83 JB |
797 | if (k->idx != -1) { |
798 | if (k->defmgmt) { | |
799 | if (k->idx < 4 || k->idx > 5) | |
800 | return -EINVAL; | |
801 | } else if (k->def) { | |
802 | if (k->idx < 0 || k->idx > 3) | |
803 | return -EINVAL; | |
804 | } else { | |
805 | if (k->idx < 0 || k->idx > 5) | |
806 | return -EINVAL; | |
807 | } | |
808 | } | |
809 | ||
810 | return 0; | |
811 | } | |
812 | ||
fffd0934 JB |
813 | static struct cfg80211_cached_keys * |
814 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 815 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
816 | { |
817 | struct key_parse parse; | |
818 | struct nlattr *key; | |
819 | struct cfg80211_cached_keys *result; | |
820 | int rem, err, def = 0; | |
821 | ||
822 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
823 | if (!result) | |
824 | return ERR_PTR(-ENOMEM); | |
825 | ||
826 | result->def = -1; | |
827 | result->defmgmt = -1; | |
828 | ||
829 | nla_for_each_nested(key, keys, rem) { | |
830 | memset(&parse, 0, sizeof(parse)); | |
831 | parse.idx = -1; | |
832 | ||
833 | err = nl80211_parse_key_new(key, &parse); | |
834 | if (err) | |
835 | goto error; | |
836 | err = -EINVAL; | |
837 | if (!parse.p.key) | |
838 | goto error; | |
839 | if (parse.idx < 0 || parse.idx > 4) | |
840 | goto error; | |
841 | if (parse.def) { | |
842 | if (def) | |
843 | goto error; | |
844 | def = 1; | |
845 | result->def = parse.idx; | |
dbd2fd65 JB |
846 | if (!parse.def_uni || !parse.def_multi) |
847 | goto error; | |
fffd0934 JB |
848 | } else if (parse.defmgmt) |
849 | goto error; | |
850 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 851 | parse.idx, false, NULL); |
fffd0934 JB |
852 | if (err) |
853 | goto error; | |
854 | result->params[parse.idx].cipher = parse.p.cipher; | |
855 | result->params[parse.idx].key_len = parse.p.key_len; | |
856 | result->params[parse.idx].key = result->data[parse.idx]; | |
857 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
858 | |
859 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
860 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
861 | if (no_ht) | |
862 | *no_ht = true; | |
863 | } | |
fffd0934 JB |
864 | } |
865 | ||
866 | return result; | |
867 | error: | |
868 | kfree(result); | |
869 | return ERR_PTR(err); | |
870 | } | |
871 | ||
872 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
873 | { | |
874 | ASSERT_WDEV_LOCK(wdev); | |
875 | ||
fffd0934 JB |
876 | switch (wdev->iftype) { |
877 | case NL80211_IFTYPE_AP: | |
878 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 879 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 880 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
881 | break; |
882 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 883 | case NL80211_IFTYPE_STATION: |
074ac8df | 884 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 885 | if (!wdev->current_bss) |
fffd0934 JB |
886 | return -ENOLINK; |
887 | break; | |
de4fcbad | 888 | case NL80211_IFTYPE_UNSPECIFIED: |
6e0bd6c3 | 889 | case NL80211_IFTYPE_OCB: |
de4fcbad JB |
890 | case NL80211_IFTYPE_MONITOR: |
891 | case NL80211_IFTYPE_P2P_DEVICE: | |
892 | case NL80211_IFTYPE_WDS: | |
893 | case NUM_NL80211_IFTYPES: | |
fffd0934 JB |
894 | return -EINVAL; |
895 | } | |
896 | ||
897 | return 0; | |
898 | } | |
899 | ||
664834de JM |
900 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
901 | struct nlattr *tb) | |
902 | { | |
903 | struct ieee80211_channel *chan; | |
904 | ||
905 | if (tb == NULL) | |
906 | return NULL; | |
907 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
908 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
909 | return NULL; | |
910 | return chan; | |
911 | } | |
912 | ||
7527a782 JB |
913 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
914 | { | |
915 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
916 | int i; | |
917 | ||
918 | if (!nl_modes) | |
919 | goto nla_put_failure; | |
920 | ||
921 | i = 0; | |
922 | while (ifmodes) { | |
9360ffd1 DM |
923 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
924 | goto nla_put_failure; | |
7527a782 JB |
925 | ifmodes >>= 1; |
926 | i++; | |
927 | } | |
928 | ||
929 | nla_nest_end(msg, nl_modes); | |
930 | return 0; | |
931 | ||
932 | nla_put_failure: | |
933 | return -ENOBUFS; | |
934 | } | |
935 | ||
936 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
937 | struct sk_buff *msg, |
938 | bool large) | |
7527a782 JB |
939 | { |
940 | struct nlattr *nl_combis; | |
941 | int i, j; | |
942 | ||
943 | nl_combis = nla_nest_start(msg, | |
944 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
945 | if (!nl_combis) | |
946 | goto nla_put_failure; | |
947 | ||
948 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
949 | const struct ieee80211_iface_combination *c; | |
950 | struct nlattr *nl_combi, *nl_limits; | |
951 | ||
952 | c = &wiphy->iface_combinations[i]; | |
953 | ||
954 | nl_combi = nla_nest_start(msg, i + 1); | |
955 | if (!nl_combi) | |
956 | goto nla_put_failure; | |
957 | ||
958 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
959 | if (!nl_limits) | |
960 | goto nla_put_failure; | |
961 | ||
962 | for (j = 0; j < c->n_limits; j++) { | |
963 | struct nlattr *nl_limit; | |
964 | ||
965 | nl_limit = nla_nest_start(msg, j + 1); | |
966 | if (!nl_limit) | |
967 | goto nla_put_failure; | |
9360ffd1 DM |
968 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
969 | c->limits[j].max)) | |
970 | goto nla_put_failure; | |
7527a782 JB |
971 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
972 | c->limits[j].types)) | |
973 | goto nla_put_failure; | |
974 | nla_nest_end(msg, nl_limit); | |
975 | } | |
976 | ||
977 | nla_nest_end(msg, nl_limits); | |
978 | ||
9360ffd1 DM |
979 | if (c->beacon_int_infra_match && |
980 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
981 | goto nla_put_failure; | |
982 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
983 | c->num_different_channels) || | |
984 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
985 | c->max_interfaces)) | |
986 | goto nla_put_failure; | |
cdc89b97 | 987 | if (large && |
8c48b50a FF |
988 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
989 | c->radar_detect_widths) || | |
990 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
991 | c->radar_detect_regions))) | |
cdc89b97 | 992 | goto nla_put_failure; |
7527a782 JB |
993 | |
994 | nla_nest_end(msg, nl_combi); | |
995 | } | |
996 | ||
997 | nla_nest_end(msg, nl_combis); | |
998 | ||
999 | return 0; | |
1000 | nla_put_failure: | |
1001 | return -ENOBUFS; | |
1002 | } | |
1003 | ||
3713b4e3 | 1004 | #ifdef CONFIG_PM |
b56cf720 JB |
1005 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
1006 | struct sk_buff *msg) | |
1007 | { | |
964dc9e2 | 1008 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
1009 | struct nlattr *nl_tcp; |
1010 | ||
1011 | if (!tcp) | |
1012 | return 0; | |
1013 | ||
1014 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
1015 | if (!nl_tcp) | |
1016 | return -ENOBUFS; | |
1017 | ||
1018 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1019 | tcp->data_payload_max)) | |
1020 | return -ENOBUFS; | |
1021 | ||
1022 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1023 | tcp->data_payload_max)) | |
1024 | return -ENOBUFS; | |
1025 | ||
1026 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1027 | return -ENOBUFS; | |
1028 | ||
1029 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1030 | sizeof(*tcp->tok), tcp->tok)) | |
1031 | return -ENOBUFS; | |
1032 | ||
1033 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1034 | tcp->data_interval_max)) | |
1035 | return -ENOBUFS; | |
1036 | ||
1037 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1038 | tcp->wake_payload_max)) | |
1039 | return -ENOBUFS; | |
1040 | ||
1041 | nla_nest_end(msg, nl_tcp); | |
1042 | return 0; | |
1043 | } | |
1044 | ||
3713b4e3 | 1045 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1046 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1047 | bool large) |
55682965 | 1048 | { |
3713b4e3 | 1049 | struct nlattr *nl_wowlan; |
55682965 | 1050 | |
1b8ec87a | 1051 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1052 | return 0; |
55682965 | 1053 | |
3713b4e3 JB |
1054 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1055 | if (!nl_wowlan) | |
1056 | return -ENOBUFS; | |
9360ffd1 | 1057 | |
1b8ec87a | 1058 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1059 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1060 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1061 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1062 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1063 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1064 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1065 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1066 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1067 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1068 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1069 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1070 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1071 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1072 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1073 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1074 | return -ENOBUFS; | |
9360ffd1 | 1075 | |
1b8ec87a | 1076 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1077 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1078 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1079 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1080 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1081 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1082 | }; |
9360ffd1 | 1083 | |
3713b4e3 JB |
1084 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1085 | sizeof(pat), &pat)) | |
1086 | return -ENOBUFS; | |
1087 | } | |
9360ffd1 | 1088 | |
1b8ec87a | 1089 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1090 | return -ENOBUFS; |
1091 | ||
8cd4d456 LC |
1092 | /* TODO: send wowlan net detect */ |
1093 | ||
3713b4e3 | 1094 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1095 | |
3713b4e3 JB |
1096 | return 0; |
1097 | } | |
1098 | #endif | |
9360ffd1 | 1099 | |
be29b99a | 1100 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1101 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1102 | { |
1103 | struct nl80211_coalesce_rule_support rule; | |
1104 | ||
1b8ec87a | 1105 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1106 | return 0; |
1107 | ||
1b8ec87a ZG |
1108 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1109 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1110 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1111 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1112 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1113 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1114 | |
1115 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1116 | return -ENOBUFS; | |
1117 | ||
1118 | return 0; | |
1119 | } | |
1120 | ||
3713b4e3 JB |
1121 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1122 | struct ieee80211_supported_band *sband) | |
1123 | { | |
1124 | struct nlattr *nl_rates, *nl_rate; | |
1125 | struct ieee80211_rate *rate; | |
1126 | int i; | |
87bbbe22 | 1127 | |
3713b4e3 JB |
1128 | /* add HT info */ |
1129 | if (sband->ht_cap.ht_supported && | |
1130 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1131 | sizeof(sband->ht_cap.mcs), | |
1132 | &sband->ht_cap.mcs) || | |
1133 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1134 | sband->ht_cap.cap) || | |
1135 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1136 | sband->ht_cap.ampdu_factor) || | |
1137 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1138 | sband->ht_cap.ampdu_density))) | |
1139 | return -ENOBUFS; | |
afe0cbf8 | 1140 | |
3713b4e3 JB |
1141 | /* add VHT info */ |
1142 | if (sband->vht_cap.vht_supported && | |
1143 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1144 | sizeof(sband->vht_cap.vht_mcs), | |
1145 | &sband->vht_cap.vht_mcs) || | |
1146 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1147 | sband->vht_cap.cap))) | |
1148 | return -ENOBUFS; | |
f59ac048 | 1149 | |
3713b4e3 JB |
1150 | /* add bitrates */ |
1151 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1152 | if (!nl_rates) | |
1153 | return -ENOBUFS; | |
ee688b00 | 1154 | |
3713b4e3 JB |
1155 | for (i = 0; i < sband->n_bitrates; i++) { |
1156 | nl_rate = nla_nest_start(msg, i); | |
1157 | if (!nl_rate) | |
1158 | return -ENOBUFS; | |
ee688b00 | 1159 | |
3713b4e3 JB |
1160 | rate = &sband->bitrates[i]; |
1161 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1162 | rate->bitrate)) | |
1163 | return -ENOBUFS; | |
1164 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1165 | nla_put_flag(msg, | |
1166 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1167 | return -ENOBUFS; | |
ee688b00 | 1168 | |
3713b4e3 JB |
1169 | nla_nest_end(msg, nl_rate); |
1170 | } | |
d51626df | 1171 | |
3713b4e3 | 1172 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1173 | |
3713b4e3 JB |
1174 | return 0; |
1175 | } | |
ee688b00 | 1176 | |
3713b4e3 JB |
1177 | static int |
1178 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1179 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1180 | { | |
1181 | u16 stypes; | |
1182 | struct nlattr *nl_ftypes, *nl_ifs; | |
1183 | enum nl80211_iftype ift; | |
1184 | int i; | |
ee688b00 | 1185 | |
3713b4e3 JB |
1186 | if (!mgmt_stypes) |
1187 | return 0; | |
5dab3b8a | 1188 | |
3713b4e3 JB |
1189 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1190 | if (!nl_ifs) | |
1191 | return -ENOBUFS; | |
e2f367f2 | 1192 | |
3713b4e3 JB |
1193 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1194 | nl_ftypes = nla_nest_start(msg, ift); | |
1195 | if (!nl_ftypes) | |
1196 | return -ENOBUFS; | |
1197 | i = 0; | |
1198 | stypes = mgmt_stypes[ift].tx; | |
1199 | while (stypes) { | |
1200 | if ((stypes & 1) && | |
1201 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1202 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1203 | return -ENOBUFS; | |
1204 | stypes >>= 1; | |
1205 | i++; | |
ee688b00 | 1206 | } |
3713b4e3 JB |
1207 | nla_nest_end(msg, nl_ftypes); |
1208 | } | |
ee688b00 | 1209 | |
3713b4e3 | 1210 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1211 | |
3713b4e3 JB |
1212 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1213 | if (!nl_ifs) | |
1214 | return -ENOBUFS; | |
ee688b00 | 1215 | |
3713b4e3 JB |
1216 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1217 | nl_ftypes = nla_nest_start(msg, ift); | |
1218 | if (!nl_ftypes) | |
1219 | return -ENOBUFS; | |
1220 | i = 0; | |
1221 | stypes = mgmt_stypes[ift].rx; | |
1222 | while (stypes) { | |
1223 | if ((stypes & 1) && | |
1224 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1225 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1226 | return -ENOBUFS; | |
1227 | stypes >>= 1; | |
1228 | i++; | |
1229 | } | |
1230 | nla_nest_end(msg, nl_ftypes); | |
1231 | } | |
1232 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1233 | |
3713b4e3 JB |
1234 | return 0; |
1235 | } | |
ee688b00 | 1236 | |
86e8cf98 JB |
1237 | struct nl80211_dump_wiphy_state { |
1238 | s64 filter_wiphy; | |
1239 | long start; | |
1240 | long split_start, band_start, chan_start; | |
1241 | bool split; | |
1242 | }; | |
1243 | ||
1b8ec87a | 1244 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 1245 | enum nl80211_commands cmd, |
3713b4e3 | 1246 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1247 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1248 | { |
1249 | void *hdr; | |
1250 | struct nlattr *nl_bands, *nl_band; | |
1251 | struct nlattr *nl_freqs, *nl_freq; | |
1252 | struct nlattr *nl_cmds; | |
1253 | enum ieee80211_band band; | |
1254 | struct ieee80211_channel *chan; | |
1255 | int i; | |
1256 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1257 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1258 | u32 features; |
ee688b00 | 1259 | |
3bb20556 | 1260 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
1261 | if (!hdr) |
1262 | return -ENOBUFS; | |
ee688b00 | 1263 | |
86e8cf98 JB |
1264 | if (WARN_ON(!state)) |
1265 | return -EINVAL; | |
ee688b00 | 1266 | |
1b8ec87a | 1267 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1268 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1269 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1270 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1271 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1272 | goto nla_put_failure; |
1273 | ||
3bb20556 JB |
1274 | if (cmd != NL80211_CMD_NEW_WIPHY) |
1275 | goto finish; | |
1276 | ||
86e8cf98 | 1277 | switch (state->split_start) { |
3713b4e3 JB |
1278 | case 0: |
1279 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1280 | rdev->wiphy.retry_short) || |
3713b4e3 | 1281 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1282 | rdev->wiphy.retry_long) || |
3713b4e3 | 1283 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1284 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1285 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1286 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1287 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1288 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1289 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1290 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1291 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1292 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1293 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1294 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1295 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1296 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1297 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
1b8ec87a | 1298 | rdev->wiphy.max_match_sets)) |
9360ffd1 | 1299 | goto nla_put_failure; |
3713b4e3 | 1300 | |
1b8ec87a | 1301 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1302 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1303 | goto nla_put_failure; |
1b8ec87a | 1304 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1305 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1306 | goto nla_put_failure; | |
1b8ec87a | 1307 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1308 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1309 | goto nla_put_failure; | |
1b8ec87a | 1310 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1311 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1312 | goto nla_put_failure; | |
1b8ec87a | 1313 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1314 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1315 | goto nla_put_failure; | |
1b8ec87a | 1316 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1317 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1318 | goto nla_put_failure; |
86e8cf98 JB |
1319 | state->split_start++; |
1320 | if (state->split) | |
3713b4e3 JB |
1321 | break; |
1322 | case 1: | |
1323 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1324 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1325 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1326 | goto nla_put_failure; |
4745fc09 | 1327 | |
3713b4e3 | 1328 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1329 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1330 | goto nla_put_failure; |
b23aa676 | 1331 | |
1b8ec87a | 1332 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1333 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1334 | goto nla_put_failure; |
b23aa676 | 1335 | |
3713b4e3 | 1336 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1337 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1338 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1339 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1340 | goto nla_put_failure; |
b23aa676 | 1341 | |
1b8ec87a | 1342 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1343 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1344 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1345 | goto nla_put_failure; |
8fdc621d | 1346 | |
1b8ec87a ZG |
1347 | if ((rdev->wiphy.available_antennas_tx || |
1348 | rdev->wiphy.available_antennas_rx) && | |
1349 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1350 | u32 tx_ant = 0, rx_ant = 0; |
1351 | int res; | |
1b8ec87a | 1352 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1353 | if (!res) { |
1354 | if (nla_put_u32(msg, | |
1355 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1356 | tx_ant) || | |
1357 | nla_put_u32(msg, | |
1358 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1359 | rx_ant)) | |
1360 | goto nla_put_failure; | |
1361 | } | |
1362 | } | |
a293911d | 1363 | |
86e8cf98 JB |
1364 | state->split_start++; |
1365 | if (state->split) | |
3713b4e3 JB |
1366 | break; |
1367 | case 2: | |
1368 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1369 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1370 | goto nla_put_failure; |
86e8cf98 JB |
1371 | state->split_start++; |
1372 | if (state->split) | |
3713b4e3 JB |
1373 | break; |
1374 | case 3: | |
1375 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1376 | if (!nl_bands) | |
1377 | goto nla_put_failure; | |
f7ca38df | 1378 | |
86e8cf98 JB |
1379 | for (band = state->band_start; |
1380 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1381 | struct ieee80211_supported_band *sband; |
2e161f78 | 1382 | |
1b8ec87a | 1383 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1384 | |
3713b4e3 JB |
1385 | if (!sband) |
1386 | continue; | |
1387 | ||
1388 | nl_band = nla_nest_start(msg, band); | |
1389 | if (!nl_band) | |
2e161f78 | 1390 | goto nla_put_failure; |
3713b4e3 | 1391 | |
86e8cf98 | 1392 | switch (state->chan_start) { |
3713b4e3 JB |
1393 | case 0: |
1394 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1395 | goto nla_put_failure; |
86e8cf98 JB |
1396 | state->chan_start++; |
1397 | if (state->split) | |
3713b4e3 JB |
1398 | break; |
1399 | default: | |
1400 | /* add frequencies */ | |
1401 | nl_freqs = nla_nest_start( | |
1402 | msg, NL80211_BAND_ATTR_FREQS); | |
1403 | if (!nl_freqs) | |
1404 | goto nla_put_failure; | |
1405 | ||
86e8cf98 | 1406 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1407 | i < sband->n_channels; |
1408 | i++) { | |
1409 | nl_freq = nla_nest_start(msg, i); | |
1410 | if (!nl_freq) | |
1411 | goto nla_put_failure; | |
1412 | ||
1413 | chan = &sband->channels[i]; | |
1414 | ||
86e8cf98 JB |
1415 | if (nl80211_msg_put_channel( |
1416 | msg, chan, | |
1417 | state->split)) | |
3713b4e3 JB |
1418 | goto nla_put_failure; |
1419 | ||
1420 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1421 | if (state->split) |
3713b4e3 JB |
1422 | break; |
1423 | } | |
1424 | if (i < sband->n_channels) | |
86e8cf98 | 1425 | state->chan_start = i + 2; |
3713b4e3 | 1426 | else |
86e8cf98 | 1427 | state->chan_start = 0; |
3713b4e3 JB |
1428 | nla_nest_end(msg, nl_freqs); |
1429 | } | |
1430 | ||
1431 | nla_nest_end(msg, nl_band); | |
1432 | ||
86e8cf98 | 1433 | if (state->split) { |
3713b4e3 | 1434 | /* start again here */ |
86e8cf98 | 1435 | if (state->chan_start) |
3713b4e3 JB |
1436 | band--; |
1437 | break; | |
2e161f78 | 1438 | } |
2e161f78 | 1439 | } |
3713b4e3 | 1440 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1441 | |
3713b4e3 | 1442 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1443 | state->band_start = band + 1; |
3713b4e3 | 1444 | else |
86e8cf98 | 1445 | state->band_start = 0; |
74b70a4e | 1446 | |
3713b4e3 | 1447 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1448 | if (state->band_start == 0 && state->chan_start == 0) |
1449 | state->split_start++; | |
1450 | if (state->split) | |
3713b4e3 JB |
1451 | break; |
1452 | case 4: | |
1453 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1454 | if (!nl_cmds) | |
2e161f78 JB |
1455 | goto nla_put_failure; |
1456 | ||
3713b4e3 JB |
1457 | i = 0; |
1458 | #define CMD(op, n) \ | |
1459 | do { \ | |
1b8ec87a | 1460 | if (rdev->ops->op) { \ |
3713b4e3 JB |
1461 | i++; \ |
1462 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1463 | goto nla_put_failure; \ | |
1464 | } \ | |
1465 | } while (0) | |
1466 | ||
1467 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1468 | CMD(change_virtual_intf, SET_INTERFACE); | |
1469 | CMD(add_key, NEW_KEY); | |
1470 | CMD(start_ap, START_AP); | |
1471 | CMD(add_station, NEW_STATION); | |
1472 | CMD(add_mpath, NEW_MPATH); | |
1473 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1474 | CMD(change_bss, SET_BSS); | |
1475 | CMD(auth, AUTHENTICATE); | |
1476 | CMD(assoc, ASSOCIATE); | |
1477 | CMD(deauth, DEAUTHENTICATE); | |
1478 | CMD(disassoc, DISASSOCIATE); | |
1479 | CMD(join_ibss, JOIN_IBSS); | |
1480 | CMD(join_mesh, JOIN_MESH); | |
1481 | CMD(set_pmksa, SET_PMKSA); | |
1482 | CMD(del_pmksa, DEL_PMKSA); | |
1483 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1b8ec87a | 1484 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
3713b4e3 JB |
1485 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
1486 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1487 | CMD(mgmt_tx, FRAME); | |
1488 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1b8ec87a | 1489 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
3713b4e3 JB |
1490 | i++; |
1491 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1492 | goto nla_put_failure; |
2e161f78 | 1493 | } |
1b8ec87a ZG |
1494 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
1495 | rdev->ops->join_mesh) { | |
3713b4e3 JB |
1496 | i++; |
1497 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1498 | goto nla_put_failure; | |
1499 | } | |
1500 | CMD(set_wds_peer, SET_WDS_PEER); | |
1b8ec87a | 1501 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
3713b4e3 JB |
1502 | CMD(tdls_mgmt, TDLS_MGMT); |
1503 | CMD(tdls_oper, TDLS_OPER); | |
1504 | } | |
1b8ec87a | 1505 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
3713b4e3 JB |
1506 | CMD(sched_scan_start, START_SCHED_SCAN); |
1507 | CMD(probe_client, PROBE_CLIENT); | |
1508 | CMD(set_noack_map, SET_NOACK_MAP); | |
1b8ec87a | 1509 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
3713b4e3 JB |
1510 | i++; |
1511 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1512 | goto nla_put_failure; | |
1513 | } | |
1514 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1515 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
02df00eb JB |
1516 | #ifdef CONFIG_NL80211_TESTMODE |
1517 | CMD(testmode_cmd, TESTMODE); | |
1518 | #endif | |
86e8cf98 | 1519 | if (state->split) { |
5de17984 AS |
1520 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1521 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 1522 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 1523 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 1524 | CMD(set_qos_map, SET_QOS_MAP); |
723e73ac JB |
1525 | if (rdev->wiphy.features & |
1526 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | |
960d01ac | 1527 | CMD(add_tx_ts, ADD_TX_TS); |
5de17984 | 1528 | } |
02df00eb | 1529 | /* add into the if now */ |
3713b4e3 | 1530 | #undef CMD |
ff1b6e69 | 1531 | |
1b8ec87a | 1532 | if (rdev->ops->connect || rdev->ops->auth) { |
3713b4e3 JB |
1533 | i++; |
1534 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1535 | goto nla_put_failure; |
ff1b6e69 JB |
1536 | } |
1537 | ||
1b8ec87a | 1538 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
3713b4e3 JB |
1539 | i++; |
1540 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1541 | goto nla_put_failure; | |
1542 | } | |
1543 | ||
1544 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1545 | state->split_start++; |
1546 | if (state->split) | |
3713b4e3 JB |
1547 | break; |
1548 | case 5: | |
1b8ec87a ZG |
1549 | if (rdev->ops->remain_on_channel && |
1550 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
1551 | nla_put_u32(msg, |
1552 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 1553 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
1554 | goto nla_put_failure; |
1555 | ||
1b8ec87a | 1556 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
1557 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
1558 | goto nla_put_failure; | |
1559 | ||
1560 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1561 | goto nla_put_failure; | |
86e8cf98 JB |
1562 | state->split_start++; |
1563 | if (state->split) | |
3713b4e3 JB |
1564 | break; |
1565 | case 6: | |
1566 | #ifdef CONFIG_PM | |
1b8ec87a | 1567 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 1568 | goto nla_put_failure; |
86e8cf98 JB |
1569 | state->split_start++; |
1570 | if (state->split) | |
3713b4e3 JB |
1571 | break; |
1572 | #else | |
86e8cf98 | 1573 | state->split_start++; |
dfb89c56 | 1574 | #endif |
3713b4e3 JB |
1575 | case 7: |
1576 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 1577 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 1578 | goto nla_put_failure; |
ff1b6e69 | 1579 | |
1b8ec87a | 1580 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 1581 | state->split)) |
3713b4e3 | 1582 | goto nla_put_failure; |
7527a782 | 1583 | |
86e8cf98 JB |
1584 | state->split_start++; |
1585 | if (state->split) | |
3713b4e3 JB |
1586 | break; |
1587 | case 8: | |
1b8ec87a | 1588 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 1589 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 1590 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 1591 | goto nla_put_failure; |
7527a782 | 1592 | |
1b8ec87a | 1593 | features = rdev->wiphy.features; |
fe1abafd JB |
1594 | /* |
1595 | * We can only add the per-channel limit information if the | |
1596 | * dump is split, otherwise it makes it too big. Therefore | |
1597 | * only advertise it in that case. | |
1598 | */ | |
86e8cf98 | 1599 | if (state->split) |
fe1abafd JB |
1600 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1601 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1602 | goto nla_put_failure; |
562a7480 | 1603 | |
1b8ec87a | 1604 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 1605 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
1606 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
1607 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 1608 | goto nla_put_failure; |
1f074bd8 | 1609 | |
1b8ec87a ZG |
1610 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1611 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 1612 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 1613 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 1614 | goto nla_put_failure; |
7e7c8926 | 1615 | |
3713b4e3 JB |
1616 | /* |
1617 | * Any information below this point is only available to | |
1618 | * applications that can deal with it being split. This | |
1619 | * helps ensure that newly added capabilities don't break | |
1620 | * older tools by overrunning their buffers. | |
1621 | * | |
1622 | * We still increment split_start so that in the split | |
1623 | * case we'll continue with more data in the next round, | |
1624 | * but break unconditionally so unsplit data stops here. | |
1625 | */ | |
86e8cf98 | 1626 | state->split_start++; |
3713b4e3 JB |
1627 | break; |
1628 | case 9: | |
1b8ec87a | 1629 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 1630 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
1631 | rdev->wiphy.extended_capabilities_len, |
1632 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 1633 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
1634 | rdev->wiphy.extended_capabilities_len, |
1635 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 1636 | goto nla_put_failure; |
a50df0c4 | 1637 | |
1b8ec87a | 1638 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 1639 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
1640 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
1641 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
1642 | goto nla_put_failure; |
1643 | ||
be29b99a AK |
1644 | state->split_start++; |
1645 | break; | |
1646 | case 10: | |
1b8ec87a | 1647 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
1648 | goto nla_put_failure; |
1649 | ||
1b8ec87a | 1650 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
1651 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
1652 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1653 | goto nla_put_failure; | |
b43504cf | 1654 | |
1b8ec87a | 1655 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 1656 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 1657 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
1658 | goto nla_put_failure; |
1659 | ||
ad7e718c JB |
1660 | state->split_start++; |
1661 | break; | |
1662 | case 11: | |
1b8ec87a | 1663 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
1664 | const struct nl80211_vendor_cmd_info *info; |
1665 | struct nlattr *nested; | |
1666 | ||
1667 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1668 | if (!nested) | |
1669 | goto nla_put_failure; | |
1670 | ||
1b8ec87a ZG |
1671 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
1672 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
1673 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1674 | goto nla_put_failure; | |
1675 | } | |
1676 | nla_nest_end(msg, nested); | |
1677 | } | |
1678 | ||
1b8ec87a | 1679 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
1680 | const struct nl80211_vendor_cmd_info *info; |
1681 | struct nlattr *nested; | |
ad7e718c | 1682 | |
567ffc35 JB |
1683 | nested = nla_nest_start(msg, |
1684 | NL80211_ATTR_VENDOR_EVENTS); | |
1685 | if (!nested) | |
ad7e718c | 1686 | goto nla_put_failure; |
567ffc35 | 1687 | |
1b8ec87a ZG |
1688 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
1689 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
1690 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1691 | goto nla_put_failure; | |
1692 | } | |
1693 | nla_nest_end(msg, nested); | |
1694 | } | |
9a774c78 AO |
1695 | state->split_start++; |
1696 | break; | |
1697 | case 12: | |
1698 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
1699 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
1700 | rdev->wiphy.max_num_csa_counters)) | |
1701 | goto nla_put_failure; | |
01e0daa4 | 1702 | |
3713b4e3 | 1703 | /* done */ |
86e8cf98 | 1704 | state->split_start = 0; |
3713b4e3 JB |
1705 | break; |
1706 | } | |
3bb20556 | 1707 | finish: |
55682965 JB |
1708 | return genlmsg_end(msg, hdr); |
1709 | ||
1710 | nla_put_failure: | |
bc3ed28c TG |
1711 | genlmsg_cancel(msg, hdr); |
1712 | return -EMSGSIZE; | |
55682965 JB |
1713 | } |
1714 | ||
86e8cf98 JB |
1715 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1716 | struct netlink_callback *cb, | |
1717 | struct nl80211_dump_wiphy_state *state) | |
1718 | { | |
1719 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1720 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1721 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1722 | /* ignore parse errors for backward compatibility */ | |
1723 | if (ret) | |
1724 | return 0; | |
1725 | ||
1726 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1727 | if (tb[NL80211_ATTR_WIPHY]) | |
1728 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1729 | if (tb[NL80211_ATTR_WDEV]) | |
1730 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1731 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1732 | struct net_device *netdev; | |
1733 | struct cfg80211_registered_device *rdev; | |
1734 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1735 | ||
7f2b8562 | 1736 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1737 | if (!netdev) |
1738 | return -ENODEV; | |
1739 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1740 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1741 | netdev->ieee80211_ptr->wiphy); |
1742 | state->filter_wiphy = rdev->wiphy_idx; | |
1743 | } | |
86e8cf98 JB |
1744 | } |
1745 | ||
1746 | return 0; | |
1747 | } | |
1748 | ||
55682965 JB |
1749 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1750 | { | |
645e77de | 1751 | int idx = 0, ret; |
86e8cf98 | 1752 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1753 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1754 | |
5fe231e8 | 1755 | rtnl_lock(); |
86e8cf98 JB |
1756 | if (!state) { |
1757 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1758 | if (!state) { |
1759 | rtnl_unlock(); | |
86e8cf98 | 1760 | return -ENOMEM; |
3713b4e3 | 1761 | } |
86e8cf98 JB |
1762 | state->filter_wiphy = -1; |
1763 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1764 | if (ret) { | |
1765 | kfree(state); | |
1766 | rtnl_unlock(); | |
1767 | return ret; | |
3713b4e3 | 1768 | } |
86e8cf98 | 1769 | cb->args[0] = (long)state; |
3713b4e3 JB |
1770 | } |
1771 | ||
1b8ec87a ZG |
1772 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1773 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1774 | continue; |
86e8cf98 | 1775 | if (++idx <= state->start) |
55682965 | 1776 | continue; |
86e8cf98 | 1777 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1778 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1779 | continue; |
1780 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1781 | do { | |
3bb20556 JB |
1782 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
1783 | skb, | |
3713b4e3 JB |
1784 | NETLINK_CB(cb->skb).portid, |
1785 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1786 | NLM_F_MULTI, state); |
3713b4e3 JB |
1787 | if (ret < 0) { |
1788 | /* | |
1789 | * If sending the wiphy data didn't fit (ENOBUFS | |
1790 | * or EMSGSIZE returned), this SKB is still | |
1791 | * empty (so it's not too big because another | |
1792 | * wiphy dataset is already in the skb) and | |
1793 | * we've not tried to adjust the dump allocation | |
1794 | * yet ... then adjust the alloc size to be | |
1795 | * bigger, and return 1 but with the empty skb. | |
1796 | * This results in an empty message being RX'ed | |
1797 | * in userspace, but that is ignored. | |
1798 | * | |
1799 | * We can then retry with the larger buffer. | |
1800 | */ | |
1801 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1802 | !skb->len && !state->split && |
3713b4e3 JB |
1803 | cb->min_dump_alloc < 4096) { |
1804 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1805 | state->split_start = 0; |
d98cae64 | 1806 | rtnl_unlock(); |
3713b4e3 JB |
1807 | return 1; |
1808 | } | |
1809 | idx--; | |
1810 | break; | |
645e77de | 1811 | } |
86e8cf98 | 1812 | } while (state->split_start > 0); |
3713b4e3 | 1813 | break; |
55682965 | 1814 | } |
5fe231e8 | 1815 | rtnl_unlock(); |
55682965 | 1816 | |
86e8cf98 | 1817 | state->start = idx; |
55682965 JB |
1818 | |
1819 | return skb->len; | |
1820 | } | |
1821 | ||
86e8cf98 JB |
1822 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1823 | { | |
1824 | kfree((void *)cb->args[0]); | |
1825 | return 0; | |
1826 | } | |
1827 | ||
55682965 JB |
1828 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1829 | { | |
1830 | struct sk_buff *msg; | |
1b8ec87a | 1831 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 1832 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1833 | |
645e77de | 1834 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1835 | if (!msg) |
4c476991 | 1836 | return -ENOMEM; |
55682965 | 1837 | |
3bb20556 JB |
1838 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
1839 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 1840 | &state) < 0) { |
4c476991 JB |
1841 | nlmsg_free(msg); |
1842 | return -ENOBUFS; | |
1843 | } | |
55682965 | 1844 | |
134e6375 | 1845 | return genlmsg_reply(msg, info); |
55682965 JB |
1846 | } |
1847 | ||
31888487 JM |
1848 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1849 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1850 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1851 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1852 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1853 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1854 | }; | |
1855 | ||
1856 | static int parse_txq_params(struct nlattr *tb[], | |
1857 | struct ieee80211_txq_params *txq_params) | |
1858 | { | |
a3304b0a | 1859 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1860 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1861 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1862 | return -EINVAL; | |
1863 | ||
a3304b0a | 1864 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1865 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1866 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1867 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1868 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1869 | ||
a3304b0a JB |
1870 | if (txq_params->ac >= NL80211_NUM_ACS) |
1871 | return -EINVAL; | |
1872 | ||
31888487 JM |
1873 | return 0; |
1874 | } | |
1875 | ||
f444de05 JB |
1876 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1877 | { | |
1878 | /* | |
cc1d2806 JB |
1879 | * You can only set the channel explicitly for WDS interfaces, |
1880 | * all others have their channel managed via their respective | |
1881 | * "establish a connection" command (connect, join, ...) | |
1882 | * | |
1883 | * For AP/GO and mesh mode, the channel can be set with the | |
1884 | * channel userspace API, but is only stored and passed to the | |
1885 | * low-level driver when the AP starts or the mesh is joined. | |
1886 | * This is for backward compatibility, userspace can also give | |
1887 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1888 | * |
1889 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1890 | * whatever else is going on, so they have their own special |
1891 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1892 | */ |
1893 | return !wdev || | |
1894 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1895 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1896 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1897 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1898 | } |
1899 | ||
683b6d3b JB |
1900 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1901 | struct genl_info *info, | |
1902 | struct cfg80211_chan_def *chandef) | |
1903 | { | |
dbeca2ea | 1904 | u32 control_freq; |
683b6d3b JB |
1905 | |
1906 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1907 | return -EINVAL; | |
1908 | ||
1909 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1910 | ||
1911 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1912 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1913 | chandef->center_freq1 = control_freq; | |
1914 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1915 | |
1916 | /* Primary channel not allowed */ | |
1917 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1918 | return -EINVAL; | |
1919 | ||
3d9d1d66 JB |
1920 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1921 | enum nl80211_channel_type chantype; | |
1922 | ||
1923 | chantype = nla_get_u32( | |
1924 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1925 | ||
1926 | switch (chantype) { | |
1927 | case NL80211_CHAN_NO_HT: | |
1928 | case NL80211_CHAN_HT20: | |
1929 | case NL80211_CHAN_HT40PLUS: | |
1930 | case NL80211_CHAN_HT40MINUS: | |
1931 | cfg80211_chandef_create(chandef, chandef->chan, | |
1932 | chantype); | |
1933 | break; | |
1934 | default: | |
1935 | return -EINVAL; | |
1936 | } | |
1937 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1938 | chandef->width = | |
1939 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1940 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1941 | chandef->center_freq1 = | |
1942 | nla_get_u32( | |
1943 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1944 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1945 | chandef->center_freq2 = | |
1946 | nla_get_u32( | |
1947 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1948 | } | |
1949 | ||
9f5e8f6e | 1950 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1951 | return -EINVAL; |
1952 | ||
9f5e8f6e JB |
1953 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1954 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1955 | return -EINVAL; |
1956 | ||
2f301ab2 SW |
1957 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1958 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1959 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1960 | return -EINVAL; | |
1961 | ||
683b6d3b JB |
1962 | return 0; |
1963 | } | |
1964 | ||
f444de05 | 1965 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 1966 | struct net_device *dev, |
f444de05 JB |
1967 | struct genl_info *info) |
1968 | { | |
683b6d3b | 1969 | struct cfg80211_chan_def chandef; |
f444de05 | 1970 | int result; |
e8c9bd5b | 1971 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 1972 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 1973 | |
e16821bc JM |
1974 | if (dev) |
1975 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
1976 | if (!nl80211_can_set_dev_channel(wdev)) |
1977 | return -EOPNOTSUPP; | |
e16821bc JM |
1978 | if (wdev) |
1979 | iftype = wdev->iftype; | |
f444de05 | 1980 | |
683b6d3b JB |
1981 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1982 | if (result) | |
1983 | return result; | |
f444de05 | 1984 | |
e8c9bd5b | 1985 | switch (iftype) { |
aa430da4 JB |
1986 | case NL80211_IFTYPE_AP: |
1987 | case NL80211_IFTYPE_P2P_GO: | |
174e0cd2 | 1988 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
aa430da4 JB |
1989 | result = -EINVAL; |
1990 | break; | |
1991 | } | |
e16821bc JM |
1992 | if (wdev->beacon_interval) { |
1993 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
1994 | !(rdev->wiphy.features & | |
1995 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
1996 | result = -EBUSY; | |
1997 | break; | |
1998 | } | |
1999 | ||
2000 | /* Only allow dynamic channel width changes */ | |
2001 | if (chandef.chan != wdev->preset_chandef.chan) { | |
2002 | result = -EBUSY; | |
2003 | break; | |
2004 | } | |
2005 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
2006 | if (result) | |
2007 | break; | |
2008 | } | |
683b6d3b | 2009 | wdev->preset_chandef = chandef; |
aa430da4 JB |
2010 | result = 0; |
2011 | break; | |
cc1d2806 | 2012 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 2013 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 2014 | break; |
e8c9bd5b | 2015 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 2016 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 2017 | break; |
aa430da4 | 2018 | default: |
e8c9bd5b | 2019 | result = -EINVAL; |
f444de05 | 2020 | } |
f444de05 JB |
2021 | |
2022 | return result; | |
2023 | } | |
2024 | ||
2025 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2026 | { | |
4c476991 JB |
2027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2028 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2029 | |
e16821bc | 2030 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2031 | } |
2032 | ||
e8347eba BJ |
2033 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2034 | { | |
43b19952 JB |
2035 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2036 | struct net_device *dev = info->user_ptr[1]; | |
2037 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2038 | const u8 *bssid; |
e8347eba BJ |
2039 | |
2040 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2041 | return -EINVAL; | |
2042 | ||
43b19952 JB |
2043 | if (netif_running(dev)) |
2044 | return -EBUSY; | |
e8347eba | 2045 | |
43b19952 JB |
2046 | if (!rdev->ops->set_wds_peer) |
2047 | return -EOPNOTSUPP; | |
e8347eba | 2048 | |
43b19952 JB |
2049 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2050 | return -EOPNOTSUPP; | |
e8347eba BJ |
2051 | |
2052 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2053 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2054 | } |
2055 | ||
2056 | ||
55682965 JB |
2057 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2058 | { | |
2059 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2060 | struct net_device *netdev = NULL; |
2061 | struct wireless_dev *wdev; | |
a1e567c8 | 2062 | int result = 0, rem_txq_params = 0; |
31888487 | 2063 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2064 | u32 changed; |
2065 | u8 retry_short = 0, retry_long = 0; | |
2066 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2067 | u8 coverage_class = 0; |
55682965 | 2068 | |
5fe231e8 JB |
2069 | ASSERT_RTNL(); |
2070 | ||
f444de05 JB |
2071 | /* |
2072 | * Try to find the wiphy and netdev. Normally this | |
2073 | * function shouldn't need the netdev, but this is | |
2074 | * done for backward compatibility -- previously | |
2075 | * setting the channel was done per wiphy, but now | |
2076 | * it is per netdev. Previous userland like hostapd | |
2077 | * also passed a netdev to set_wiphy, so that it is | |
2078 | * possible to let that go to the right netdev! | |
2079 | */ | |
4bbf4d56 | 2080 | |
f444de05 JB |
2081 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2082 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2083 | ||
7f2b8562 | 2084 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2085 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2086 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2087 | else |
f444de05 | 2088 | netdev = NULL; |
4bbf4d56 JB |
2089 | } |
2090 | ||
f444de05 | 2091 | if (!netdev) { |
878d9ec7 JB |
2092 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2093 | info->attrs); | |
5fe231e8 | 2094 | if (IS_ERR(rdev)) |
4c476991 | 2095 | return PTR_ERR(rdev); |
f444de05 JB |
2096 | wdev = NULL; |
2097 | netdev = NULL; | |
2098 | result = 0; | |
71fe96bf | 2099 | } else |
f444de05 | 2100 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2101 | |
2102 | /* | |
2103 | * end workaround code, by now the rdev is available | |
2104 | * and locked, and wdev may or may not be NULL. | |
2105 | */ | |
4bbf4d56 JB |
2106 | |
2107 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2108 | result = cfg80211_dev_rename( |
2109 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2110 | |
4bbf4d56 | 2111 | if (result) |
7f2b8562 | 2112 | return result; |
31888487 JM |
2113 | |
2114 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2115 | struct ieee80211_txq_params txq_params; | |
2116 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2117 | ||
7f2b8562 YX |
2118 | if (!rdev->ops->set_txq_params) |
2119 | return -EOPNOTSUPP; | |
31888487 | 2120 | |
7f2b8562 YX |
2121 | if (!netdev) |
2122 | return -EINVAL; | |
f70f01c2 | 2123 | |
133a3ff2 | 2124 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2125 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2126 | return -EINVAL; | |
133a3ff2 | 2127 | |
7f2b8562 YX |
2128 | if (!netif_running(netdev)) |
2129 | return -ENETDOWN; | |
2b5f8b0b | 2130 | |
31888487 JM |
2131 | nla_for_each_nested(nl_txq_params, |
2132 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2133 | rem_txq_params) { | |
ae811e21 JB |
2134 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2135 | nla_data(nl_txq_params), | |
2136 | nla_len(nl_txq_params), | |
2137 | txq_params_policy); | |
2138 | if (result) | |
2139 | return result; | |
31888487 JM |
2140 | result = parse_txq_params(tb, &txq_params); |
2141 | if (result) | |
7f2b8562 | 2142 | return result; |
31888487 | 2143 | |
e35e4d28 HG |
2144 | result = rdev_set_txq_params(rdev, netdev, |
2145 | &txq_params); | |
31888487 | 2146 | if (result) |
7f2b8562 | 2147 | return result; |
31888487 JM |
2148 | } |
2149 | } | |
55682965 | 2150 | |
72bdcf34 | 2151 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2152 | result = __nl80211_set_channel( |
2153 | rdev, | |
2154 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2155 | info); | |
72bdcf34 | 2156 | if (result) |
7f2b8562 | 2157 | return result; |
72bdcf34 JM |
2158 | } |
2159 | ||
98d2ff8b | 2160 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2161 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2162 | enum nl80211_tx_power_setting type; |
2163 | int idx, mbm = 0; | |
2164 | ||
c8442118 JB |
2165 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2166 | txp_wdev = NULL; | |
2167 | ||
7f2b8562 YX |
2168 | if (!rdev->ops->set_tx_power) |
2169 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2170 | |
2171 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2172 | type = nla_get_u32(info->attrs[idx]); | |
2173 | ||
2174 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2175 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2176 | return -EINVAL; | |
98d2ff8b JO |
2177 | |
2178 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2179 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2180 | mbm = nla_get_u32(info->attrs[idx]); | |
2181 | } | |
2182 | ||
c8442118 | 2183 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2184 | if (result) |
7f2b8562 | 2185 | return result; |
98d2ff8b JO |
2186 | } |
2187 | ||
afe0cbf8 BR |
2188 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2189 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2190 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2191 | if ((!rdev->wiphy.available_antennas_tx && |
2192 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2193 | !rdev->ops->set_antenna) |
2194 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2195 | |
2196 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2197 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2198 | ||
a7ffac95 | 2199 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2200 | * available antenna masks, except for the "all" mask */ |
2201 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2202 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2203 | return -EINVAL; | |
a7ffac95 | 2204 | |
7f531e03 BR |
2205 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2206 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2207 | |
e35e4d28 | 2208 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2209 | if (result) |
7f2b8562 | 2210 | return result; |
afe0cbf8 BR |
2211 | } |
2212 | ||
b9a5f8ca JM |
2213 | changed = 0; |
2214 | ||
2215 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2216 | retry_short = nla_get_u8( | |
2217 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2218 | if (retry_short == 0) |
2219 | return -EINVAL; | |
2220 | ||
b9a5f8ca JM |
2221 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2222 | } | |
2223 | ||
2224 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2225 | retry_long = nla_get_u8( | |
2226 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2227 | if (retry_long == 0) |
2228 | return -EINVAL; | |
2229 | ||
b9a5f8ca JM |
2230 | changed |= WIPHY_PARAM_RETRY_LONG; |
2231 | } | |
2232 | ||
2233 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2234 | frag_threshold = nla_get_u32( | |
2235 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2236 | if (frag_threshold < 256) |
2237 | return -EINVAL; | |
2238 | ||
b9a5f8ca JM |
2239 | if (frag_threshold != (u32) -1) { |
2240 | /* | |
2241 | * Fragments (apart from the last one) are required to | |
2242 | * have even length. Make the fragmentation code | |
2243 | * simpler by stripping LSB should someone try to use | |
2244 | * odd threshold value. | |
2245 | */ | |
2246 | frag_threshold &= ~0x1; | |
2247 | } | |
2248 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2249 | } | |
2250 | ||
2251 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2252 | rts_threshold = nla_get_u32( | |
2253 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2254 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2255 | } | |
2256 | ||
81077e82 | 2257 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
3057dbfd LB |
2258 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
2259 | return -EINVAL; | |
2260 | ||
81077e82 LT |
2261 | coverage_class = nla_get_u8( |
2262 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2263 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2264 | } | |
2265 | ||
3057dbfd LB |
2266 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
2267 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | |
2268 | return -EOPNOTSUPP; | |
2269 | ||
2270 | changed |= WIPHY_PARAM_DYN_ACK; | |
81077e82 LT |
2271 | } |
2272 | ||
b9a5f8ca JM |
2273 | if (changed) { |
2274 | u8 old_retry_short, old_retry_long; | |
2275 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2276 | u8 old_coverage_class; |
b9a5f8ca | 2277 | |
7f2b8562 YX |
2278 | if (!rdev->ops->set_wiphy_params) |
2279 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2280 | |
2281 | old_retry_short = rdev->wiphy.retry_short; | |
2282 | old_retry_long = rdev->wiphy.retry_long; | |
2283 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2284 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2285 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2286 | |
2287 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2288 | rdev->wiphy.retry_short = retry_short; | |
2289 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2290 | rdev->wiphy.retry_long = retry_long; | |
2291 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2292 | rdev->wiphy.frag_threshold = frag_threshold; | |
2293 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2294 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2295 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2296 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2297 | |
e35e4d28 | 2298 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2299 | if (result) { |
2300 | rdev->wiphy.retry_short = old_retry_short; | |
2301 | rdev->wiphy.retry_long = old_retry_long; | |
2302 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2303 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2304 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2305 | } |
2306 | } | |
7f2b8562 | 2307 | return 0; |
55682965 JB |
2308 | } |
2309 | ||
71bbc994 JB |
2310 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2311 | { | |
2312 | return (u64)wdev->identifier | | |
f26cbf40 | 2313 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2314 | } |
55682965 | 2315 | |
683b6d3b | 2316 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2317 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2318 | { |
9f5e8f6e | 2319 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
3d9d1d66 | 2320 | |
683b6d3b JB |
2321 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2322 | chandef->chan->center_freq)) | |
2323 | return -ENOBUFS; | |
3d9d1d66 JB |
2324 | switch (chandef->width) { |
2325 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2326 | case NL80211_CHAN_WIDTH_20: | |
2327 | case NL80211_CHAN_WIDTH_40: | |
2328 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2329 | cfg80211_get_chandef_type(chandef))) | |
2330 | return -ENOBUFS; | |
2331 | break; | |
2332 | default: | |
2333 | break; | |
2334 | } | |
2335 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2336 | return -ENOBUFS; | |
2337 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2338 | return -ENOBUFS; | |
2339 | if (chandef->center_freq2 && | |
2340 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2341 | return -ENOBUFS; |
2342 | return 0; | |
2343 | } | |
2344 | ||
15e47304 | 2345 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2346 | struct cfg80211_registered_device *rdev, |
72fb2abc | 2347 | struct wireless_dev *wdev) |
55682965 | 2348 | { |
72fb2abc | 2349 | struct net_device *dev = wdev->netdev; |
55682965 JB |
2350 | void *hdr; |
2351 | ||
15e47304 | 2352 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
55682965 JB |
2353 | if (!hdr) |
2354 | return -1; | |
2355 | ||
72fb2abc JB |
2356 | if (dev && |
2357 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2358 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2359 | goto nla_put_failure; |
2360 | ||
2361 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2362 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2363 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2364 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2365 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2366 | rdev->devlist_generation ^ | |
2367 | (cfg80211_rdev_list_generation << 2))) | |
2368 | goto nla_put_failure; | |
f5ea9120 | 2369 | |
5b7ccaf3 | 2370 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2371 | int ret; |
2372 | struct cfg80211_chan_def chandef; | |
2373 | ||
2374 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2375 | if (ret == 0) { | |
2376 | if (nl80211_send_chandef(msg, &chandef)) | |
2377 | goto nla_put_failure; | |
2378 | } | |
d91df0e3 PF |
2379 | } |
2380 | ||
b84e7a05 AQ |
2381 | if (wdev->ssid_len) { |
2382 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2383 | goto nla_put_failure; | |
2384 | } | |
2385 | ||
55682965 JB |
2386 | return genlmsg_end(msg, hdr); |
2387 | ||
2388 | nla_put_failure: | |
bc3ed28c TG |
2389 | genlmsg_cancel(msg, hdr); |
2390 | return -EMSGSIZE; | |
55682965 JB |
2391 | } |
2392 | ||
2393 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2394 | { | |
2395 | int wp_idx = 0; | |
2396 | int if_idx = 0; | |
2397 | int wp_start = cb->args[0]; | |
2398 | int if_start = cb->args[1]; | |
f5ea9120 | 2399 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2400 | struct wireless_dev *wdev; |
2401 | ||
5fe231e8 | 2402 | rtnl_lock(); |
f5ea9120 JB |
2403 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2404 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2405 | continue; |
bba95fef JB |
2406 | if (wp_idx < wp_start) { |
2407 | wp_idx++; | |
55682965 | 2408 | continue; |
bba95fef | 2409 | } |
55682965 JB |
2410 | if_idx = 0; |
2411 | ||
89a54e48 | 2412 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2413 | if (if_idx < if_start) { |
2414 | if_idx++; | |
55682965 | 2415 | continue; |
bba95fef | 2416 | } |
15e47304 | 2417 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2418 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
72fb2abc | 2419 | rdev, wdev) < 0) { |
bba95fef JB |
2420 | goto out; |
2421 | } | |
2422 | if_idx++; | |
55682965 | 2423 | } |
bba95fef JB |
2424 | |
2425 | wp_idx++; | |
55682965 | 2426 | } |
bba95fef | 2427 | out: |
5fe231e8 | 2428 | rtnl_unlock(); |
55682965 JB |
2429 | |
2430 | cb->args[0] = wp_idx; | |
2431 | cb->args[1] = if_idx; | |
2432 | ||
2433 | return skb->len; | |
2434 | } | |
2435 | ||
2436 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2437 | { | |
2438 | struct sk_buff *msg; | |
1b8ec87a | 2439 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2440 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2441 | |
fd2120ca | 2442 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2443 | if (!msg) |
4c476991 | 2444 | return -ENOMEM; |
55682965 | 2445 | |
15e47304 | 2446 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1b8ec87a | 2447 | rdev, wdev) < 0) { |
4c476991 JB |
2448 | nlmsg_free(msg); |
2449 | return -ENOBUFS; | |
2450 | } | |
55682965 | 2451 | |
134e6375 | 2452 | return genlmsg_reply(msg, info); |
55682965 JB |
2453 | } |
2454 | ||
66f7ac50 MW |
2455 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2456 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2457 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2458 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2459 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2460 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2461 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2462 | }; |
2463 | ||
2464 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2465 | { | |
2466 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2467 | int flag; | |
2468 | ||
2469 | *mntrflags = 0; | |
2470 | ||
2471 | if (!nla) | |
2472 | return -EINVAL; | |
2473 | ||
2474 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2475 | nla, mntr_flags_policy)) | |
2476 | return -EINVAL; | |
2477 | ||
2478 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2479 | if (flags[flag]) | |
2480 | *mntrflags |= (1<<flag); | |
2481 | ||
2482 | return 0; | |
2483 | } | |
2484 | ||
9bc383de | 2485 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2486 | struct net_device *netdev, u8 use_4addr, |
2487 | enum nl80211_iftype iftype) | |
9bc383de | 2488 | { |
ad4bb6f8 | 2489 | if (!use_4addr) { |
f350a0a8 | 2490 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2491 | return -EBUSY; |
9bc383de | 2492 | return 0; |
ad4bb6f8 | 2493 | } |
9bc383de JB |
2494 | |
2495 | switch (iftype) { | |
2496 | case NL80211_IFTYPE_AP_VLAN: | |
2497 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2498 | return 0; | |
2499 | break; | |
2500 | case NL80211_IFTYPE_STATION: | |
2501 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2502 | return 0; | |
2503 | break; | |
2504 | default: | |
2505 | break; | |
2506 | } | |
2507 | ||
2508 | return -EOPNOTSUPP; | |
2509 | } | |
2510 | ||
55682965 JB |
2511 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2512 | { | |
4c476991 | 2513 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2514 | struct vif_params params; |
e36d56b6 | 2515 | int err; |
04a773ad | 2516 | enum nl80211_iftype otype, ntype; |
4c476991 | 2517 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2518 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2519 | bool change = false; |
55682965 | 2520 | |
2ec600d6 LCC |
2521 | memset(¶ms, 0, sizeof(params)); |
2522 | ||
04a773ad | 2523 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2524 | |
723b038d | 2525 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2526 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2527 | if (otype != ntype) |
ac7f9cfa | 2528 | change = true; |
4c476991 JB |
2529 | if (ntype > NL80211_IFTYPE_MAX) |
2530 | return -EINVAL; | |
723b038d JB |
2531 | } |
2532 | ||
92ffe055 | 2533 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2534 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2535 | ||
4c476991 JB |
2536 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2537 | return -EINVAL; | |
29cbe68c JB |
2538 | if (netif_running(dev)) |
2539 | return -EBUSY; | |
2540 | ||
2541 | wdev_lock(wdev); | |
2542 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2543 | IEEE80211_MAX_MESH_ID_LEN); | |
2544 | wdev->mesh_id_up_len = | |
2545 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2546 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2547 | wdev->mesh_id_up_len); | |
2548 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2549 | } |
2550 | ||
8b787643 FF |
2551 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2552 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2553 | change = true; | |
ad4bb6f8 | 2554 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2555 | if (err) |
4c476991 | 2556 | return err; |
8b787643 FF |
2557 | } else { |
2558 | params.use_4addr = -1; | |
2559 | } | |
2560 | ||
92ffe055 | 2561 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2562 | if (ntype != NL80211_IFTYPE_MONITOR) |
2563 | return -EINVAL; | |
92ffe055 JB |
2564 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2565 | &_flags); | |
ac7f9cfa | 2566 | if (err) |
4c476991 | 2567 | return err; |
ac7f9cfa JB |
2568 | |
2569 | flags = &_flags; | |
2570 | change = true; | |
92ffe055 | 2571 | } |
3b85875a | 2572 | |
18003297 | 2573 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2574 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2575 | return -EOPNOTSUPP; | |
2576 | ||
ac7f9cfa | 2577 | if (change) |
3d54d255 | 2578 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2579 | else |
2580 | err = 0; | |
60719ffd | 2581 | |
9bc383de JB |
2582 | if (!err && params.use_4addr != -1) |
2583 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2584 | ||
55682965 JB |
2585 | return err; |
2586 | } | |
2587 | ||
2588 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2589 | { | |
4c476991 | 2590 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2591 | struct vif_params params; |
84efbb84 | 2592 | struct wireless_dev *wdev; |
1c90f9d4 | 2593 | struct sk_buff *msg; |
55682965 JB |
2594 | int err; |
2595 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2596 | u32 flags; |
55682965 | 2597 | |
78f22b6a JB |
2598 | /* to avoid failing a new interface creation due to pending removal */ |
2599 | cfg80211_destroy_ifaces(rdev); | |
2600 | ||
2ec600d6 LCC |
2601 | memset(¶ms, 0, sizeof(params)); |
2602 | ||
55682965 JB |
2603 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2604 | return -EINVAL; | |
2605 | ||
2606 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2607 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2608 | if (type > NL80211_IFTYPE_MAX) | |
2609 | return -EINVAL; | |
2610 | } | |
2611 | ||
79c97e97 | 2612 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2613 | !(rdev->wiphy.interface_modes & (1 << type))) |
2614 | return -EOPNOTSUPP; | |
55682965 | 2615 | |
e8f479b1 BG |
2616 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
2617 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && | |
2618 | info->attrs[NL80211_ATTR_MAC]) { | |
1c18f145 AS |
2619 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
2620 | ETH_ALEN); | |
2621 | if (!is_valid_ether_addr(params.macaddr)) | |
2622 | return -EADDRNOTAVAIL; | |
2623 | } | |
2624 | ||
9bc383de | 2625 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2626 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2627 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2628 | if (err) |
4c476991 | 2629 | return err; |
9bc383de | 2630 | } |
8b787643 | 2631 | |
1c90f9d4 JB |
2632 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2633 | if (!msg) | |
2634 | return -ENOMEM; | |
2635 | ||
66f7ac50 MW |
2636 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2637 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2638 | &flags); | |
e057d3c3 | 2639 | |
18003297 | 2640 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2641 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2642 | return -EOPNOTSUPP; | |
2643 | ||
e35e4d28 HG |
2644 | wdev = rdev_add_virtual_intf(rdev, |
2645 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2646 | type, err ? NULL : &flags, ¶ms); | |
1c90f9d4 JB |
2647 | if (IS_ERR(wdev)) { |
2648 | nlmsg_free(msg); | |
84efbb84 | 2649 | return PTR_ERR(wdev); |
1c90f9d4 | 2650 | } |
2ec600d6 | 2651 | |
78f22b6a JB |
2652 | if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER]) |
2653 | wdev->owner_nlportid = info->snd_portid; | |
2654 | ||
98104fde JB |
2655 | switch (type) { |
2656 | case NL80211_IFTYPE_MESH_POINT: | |
2657 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2658 | break; | |
29cbe68c JB |
2659 | wdev_lock(wdev); |
2660 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2661 | IEEE80211_MAX_MESH_ID_LEN); | |
2662 | wdev->mesh_id_up_len = | |
2663 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2664 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2665 | wdev->mesh_id_up_len); | |
2666 | wdev_unlock(wdev); | |
98104fde JB |
2667 | break; |
2668 | case NL80211_IFTYPE_P2P_DEVICE: | |
2669 | /* | |
2670 | * P2P Device doesn't have a netdev, so doesn't go | |
2671 | * through the netdev notifier and must be added here | |
2672 | */ | |
2673 | mutex_init(&wdev->mtx); | |
2674 | INIT_LIST_HEAD(&wdev->event_list); | |
2675 | spin_lock_init(&wdev->event_lock); | |
2676 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2677 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2678 | ||
98104fde JB |
2679 | wdev->identifier = ++rdev->wdev_id; |
2680 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2681 | rdev->devlist_generation++; | |
98104fde JB |
2682 | break; |
2683 | default: | |
2684 | break; | |
29cbe68c JB |
2685 | } |
2686 | ||
15e47304 | 2687 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1c90f9d4 JB |
2688 | rdev, wdev) < 0) { |
2689 | nlmsg_free(msg); | |
2690 | return -ENOBUFS; | |
2691 | } | |
2692 | ||
2693 | return genlmsg_reply(msg, info); | |
55682965 JB |
2694 | } |
2695 | ||
2696 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2697 | { | |
4c476991 | 2698 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2699 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2700 | |
4c476991 JB |
2701 | if (!rdev->ops->del_virtual_intf) |
2702 | return -EOPNOTSUPP; | |
55682965 | 2703 | |
84efbb84 JB |
2704 | /* |
2705 | * If we remove a wireless device without a netdev then clear | |
2706 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2707 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2708 | * since the wdev has been freed, unlike with a netdev where | |
2709 | * we need the dev_put() for the netdev to really be freed. | |
2710 | */ | |
2711 | if (!wdev->netdev) | |
2712 | info->user_ptr[1] = NULL; | |
2713 | ||
e35e4d28 | 2714 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2715 | } |
2716 | ||
1d9d9213 SW |
2717 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2718 | { | |
2719 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2720 | struct net_device *dev = info->user_ptr[1]; | |
2721 | u16 noack_map; | |
2722 | ||
2723 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2724 | return -EINVAL; | |
2725 | ||
2726 | if (!rdev->ops->set_noack_map) | |
2727 | return -EOPNOTSUPP; | |
2728 | ||
2729 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2730 | ||
e35e4d28 | 2731 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2732 | } |
2733 | ||
41ade00f JB |
2734 | struct get_key_cookie { |
2735 | struct sk_buff *msg; | |
2736 | int error; | |
b9454e83 | 2737 | int idx; |
41ade00f JB |
2738 | }; |
2739 | ||
2740 | static void get_key_callback(void *c, struct key_params *params) | |
2741 | { | |
b9454e83 | 2742 | struct nlattr *key; |
41ade00f JB |
2743 | struct get_key_cookie *cookie = c; |
2744 | ||
9360ffd1 DM |
2745 | if ((params->key && |
2746 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2747 | params->key_len, params->key)) || | |
2748 | (params->seq && | |
2749 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2750 | params->seq_len, params->seq)) || | |
2751 | (params->cipher && | |
2752 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2753 | params->cipher))) | |
2754 | goto nla_put_failure; | |
41ade00f | 2755 | |
b9454e83 JB |
2756 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2757 | if (!key) | |
2758 | goto nla_put_failure; | |
2759 | ||
9360ffd1 DM |
2760 | if ((params->key && |
2761 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2762 | params->key_len, params->key)) || | |
2763 | (params->seq && | |
2764 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2765 | params->seq_len, params->seq)) || | |
2766 | (params->cipher && | |
2767 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2768 | params->cipher))) | |
2769 | goto nla_put_failure; | |
b9454e83 | 2770 | |
9360ffd1 DM |
2771 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2772 | goto nla_put_failure; | |
b9454e83 JB |
2773 | |
2774 | nla_nest_end(cookie->msg, key); | |
2775 | ||
41ade00f JB |
2776 | return; |
2777 | nla_put_failure: | |
2778 | cookie->error = 1; | |
2779 | } | |
2780 | ||
2781 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2782 | { | |
4c476991 | 2783 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2784 | int err; |
4c476991 | 2785 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2786 | u8 key_idx = 0; |
e31b8213 JB |
2787 | const u8 *mac_addr = NULL; |
2788 | bool pairwise; | |
41ade00f JB |
2789 | struct get_key_cookie cookie = { |
2790 | .error = 0, | |
2791 | }; | |
2792 | void *hdr; | |
2793 | struct sk_buff *msg; | |
2794 | ||
2795 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2796 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2797 | ||
3cfcf6ac | 2798 | if (key_idx > 5) |
41ade00f JB |
2799 | return -EINVAL; |
2800 | ||
2801 | if (info->attrs[NL80211_ATTR_MAC]) | |
2802 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2803 | ||
e31b8213 JB |
2804 | pairwise = !!mac_addr; |
2805 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2806 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2807 | if (kt >= NUM_NL80211_KEYTYPES) | |
2808 | return -EINVAL; | |
2809 | if (kt != NL80211_KEYTYPE_GROUP && | |
2810 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2811 | return -EINVAL; | |
2812 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2813 | } | |
2814 | ||
4c476991 JB |
2815 | if (!rdev->ops->get_key) |
2816 | return -EOPNOTSUPP; | |
41ade00f | 2817 | |
fd2120ca | 2818 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2819 | if (!msg) |
2820 | return -ENOMEM; | |
41ade00f | 2821 | |
15e47304 | 2822 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2823 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 2824 | if (!hdr) |
9fe271af | 2825 | goto nla_put_failure; |
41ade00f JB |
2826 | |
2827 | cookie.msg = msg; | |
b9454e83 | 2828 | cookie.idx = key_idx; |
41ade00f | 2829 | |
9360ffd1 DM |
2830 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2831 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2832 | goto nla_put_failure; | |
2833 | if (mac_addr && | |
2834 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2835 | goto nla_put_failure; | |
41ade00f | 2836 | |
e31b8213 JB |
2837 | if (pairwise && mac_addr && |
2838 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2839 | return -ENOENT; | |
2840 | ||
e35e4d28 HG |
2841 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2842 | get_key_callback); | |
41ade00f JB |
2843 | |
2844 | if (err) | |
6c95e2a2 | 2845 | goto free_msg; |
41ade00f JB |
2846 | |
2847 | if (cookie.error) | |
2848 | goto nla_put_failure; | |
2849 | ||
2850 | genlmsg_end(msg, hdr); | |
4c476991 | 2851 | return genlmsg_reply(msg, info); |
41ade00f JB |
2852 | |
2853 | nla_put_failure: | |
2854 | err = -ENOBUFS; | |
6c95e2a2 | 2855 | free_msg: |
41ade00f | 2856 | nlmsg_free(msg); |
41ade00f JB |
2857 | return err; |
2858 | } | |
2859 | ||
2860 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2861 | { | |
4c476991 | 2862 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2863 | struct key_parse key; |
41ade00f | 2864 | int err; |
4c476991 | 2865 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2866 | |
b9454e83 JB |
2867 | err = nl80211_parse_key(info, &key); |
2868 | if (err) | |
2869 | return err; | |
41ade00f | 2870 | |
b9454e83 | 2871 | if (key.idx < 0) |
41ade00f JB |
2872 | return -EINVAL; |
2873 | ||
b9454e83 JB |
2874 | /* only support setting default key */ |
2875 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2876 | return -EINVAL; |
2877 | ||
dbd2fd65 | 2878 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2879 | |
dbd2fd65 JB |
2880 | if (key.def) { |
2881 | if (!rdev->ops->set_default_key) { | |
2882 | err = -EOPNOTSUPP; | |
2883 | goto out; | |
2884 | } | |
41ade00f | 2885 | |
dbd2fd65 JB |
2886 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2887 | if (err) | |
2888 | goto out; | |
2889 | ||
e35e4d28 | 2890 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2891 | key.def_uni, key.def_multi); |
2892 | ||
2893 | if (err) | |
2894 | goto out; | |
fffd0934 | 2895 | |
3d23e349 | 2896 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2897 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2898 | #endif | |
2899 | } else { | |
2900 | if (key.def_uni || !key.def_multi) { | |
2901 | err = -EINVAL; | |
2902 | goto out; | |
2903 | } | |
2904 | ||
2905 | if (!rdev->ops->set_default_mgmt_key) { | |
2906 | err = -EOPNOTSUPP; | |
2907 | goto out; | |
2908 | } | |
2909 | ||
2910 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2911 | if (err) | |
2912 | goto out; | |
2913 | ||
e35e4d28 | 2914 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2915 | if (err) |
2916 | goto out; | |
2917 | ||
2918 | #ifdef CONFIG_CFG80211_WEXT | |
2919 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2920 | #endif |
dbd2fd65 JB |
2921 | } |
2922 | ||
2923 | out: | |
fffd0934 | 2924 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2925 | |
41ade00f JB |
2926 | return err; |
2927 | } | |
2928 | ||
2929 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2930 | { | |
4c476991 | 2931 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2932 | int err; |
4c476991 | 2933 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2934 | struct key_parse key; |
e31b8213 | 2935 | const u8 *mac_addr = NULL; |
41ade00f | 2936 | |
b9454e83 JB |
2937 | err = nl80211_parse_key(info, &key); |
2938 | if (err) | |
2939 | return err; | |
41ade00f | 2940 | |
b9454e83 | 2941 | if (!key.p.key) |
41ade00f JB |
2942 | return -EINVAL; |
2943 | ||
41ade00f JB |
2944 | if (info->attrs[NL80211_ATTR_MAC]) |
2945 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2946 | ||
e31b8213 JB |
2947 | if (key.type == -1) { |
2948 | if (mac_addr) | |
2949 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2950 | else | |
2951 | key.type = NL80211_KEYTYPE_GROUP; | |
2952 | } | |
2953 | ||
2954 | /* for now */ | |
2955 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2956 | key.type != NL80211_KEYTYPE_GROUP) | |
2957 | return -EINVAL; | |
2958 | ||
4c476991 JB |
2959 | if (!rdev->ops->add_key) |
2960 | return -EOPNOTSUPP; | |
25e47c18 | 2961 | |
e31b8213 JB |
2962 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2963 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2964 | mac_addr)) | |
4c476991 | 2965 | return -EINVAL; |
41ade00f | 2966 | |
fffd0934 JB |
2967 | wdev_lock(dev->ieee80211_ptr); |
2968 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2969 | if (!err) | |
e35e4d28 HG |
2970 | err = rdev_add_key(rdev, dev, key.idx, |
2971 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2972 | mac_addr, &key.p); | |
fffd0934 | 2973 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2974 | |
41ade00f JB |
2975 | return err; |
2976 | } | |
2977 | ||
2978 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2979 | { | |
4c476991 | 2980 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2981 | int err; |
4c476991 | 2982 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2983 | u8 *mac_addr = NULL; |
b9454e83 | 2984 | struct key_parse key; |
41ade00f | 2985 | |
b9454e83 JB |
2986 | err = nl80211_parse_key(info, &key); |
2987 | if (err) | |
2988 | return err; | |
41ade00f JB |
2989 | |
2990 | if (info->attrs[NL80211_ATTR_MAC]) | |
2991 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2992 | ||
e31b8213 JB |
2993 | if (key.type == -1) { |
2994 | if (mac_addr) | |
2995 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2996 | else | |
2997 | key.type = NL80211_KEYTYPE_GROUP; | |
2998 | } | |
2999 | ||
3000 | /* for now */ | |
3001 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3002 | key.type != NL80211_KEYTYPE_GROUP) | |
3003 | return -EINVAL; | |
3004 | ||
4c476991 JB |
3005 | if (!rdev->ops->del_key) |
3006 | return -EOPNOTSUPP; | |
41ade00f | 3007 | |
fffd0934 JB |
3008 | wdev_lock(dev->ieee80211_ptr); |
3009 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
3010 | |
3011 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
3012 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
3013 | err = -ENOENT; | |
3014 | ||
fffd0934 | 3015 | if (!err) |
e35e4d28 HG |
3016 | err = rdev_del_key(rdev, dev, key.idx, |
3017 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3018 | mac_addr); | |
41ade00f | 3019 | |
3d23e349 | 3020 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 3021 | if (!err) { |
b9454e83 | 3022 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 3023 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 3024 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
3025 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
3026 | } | |
3027 | #endif | |
fffd0934 | 3028 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 3029 | |
41ade00f JB |
3030 | return err; |
3031 | } | |
3032 | ||
77765eaf VT |
3033 | /* This function returns an error or the number of nested attributes */ |
3034 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
3035 | { | |
3036 | struct nlattr *attr; | |
3037 | int n_entries = 0, tmp; | |
3038 | ||
3039 | nla_for_each_nested(attr, nl_attr, tmp) { | |
3040 | if (nla_len(attr) != ETH_ALEN) | |
3041 | return -EINVAL; | |
3042 | ||
3043 | n_entries++; | |
3044 | } | |
3045 | ||
3046 | return n_entries; | |
3047 | } | |
3048 | ||
3049 | /* | |
3050 | * This function parses ACL information and allocates memory for ACL data. | |
3051 | * On successful return, the calling function is responsible to free the | |
3052 | * ACL buffer returned by this function. | |
3053 | */ | |
3054 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3055 | struct genl_info *info) | |
3056 | { | |
3057 | enum nl80211_acl_policy acl_policy; | |
3058 | struct nlattr *attr; | |
3059 | struct cfg80211_acl_data *acl; | |
3060 | int i = 0, n_entries, tmp; | |
3061 | ||
3062 | if (!wiphy->max_acl_mac_addrs) | |
3063 | return ERR_PTR(-EOPNOTSUPP); | |
3064 | ||
3065 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3066 | return ERR_PTR(-EINVAL); | |
3067 | ||
3068 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3069 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3070 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3071 | return ERR_PTR(-EINVAL); | |
3072 | ||
3073 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3074 | return ERR_PTR(-EINVAL); | |
3075 | ||
3076 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3077 | if (n_entries < 0) | |
3078 | return ERR_PTR(n_entries); | |
3079 | ||
3080 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3081 | return ERR_PTR(-ENOTSUPP); | |
3082 | ||
3083 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
3084 | GFP_KERNEL); | |
3085 | if (!acl) | |
3086 | return ERR_PTR(-ENOMEM); | |
3087 | ||
3088 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3089 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3090 | i++; | |
3091 | } | |
3092 | ||
3093 | acl->n_acl_entries = n_entries; | |
3094 | acl->acl_policy = acl_policy; | |
3095 | ||
3096 | return acl; | |
3097 | } | |
3098 | ||
3099 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3100 | { | |
3101 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3102 | struct net_device *dev = info->user_ptr[1]; | |
3103 | struct cfg80211_acl_data *acl; | |
3104 | int err; | |
3105 | ||
3106 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3107 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3108 | return -EOPNOTSUPP; | |
3109 | ||
3110 | if (!dev->ieee80211_ptr->beacon_interval) | |
3111 | return -EINVAL; | |
3112 | ||
3113 | acl = parse_acl_data(&rdev->wiphy, info); | |
3114 | if (IS_ERR(acl)) | |
3115 | return PTR_ERR(acl); | |
3116 | ||
3117 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3118 | ||
3119 | kfree(acl); | |
3120 | ||
3121 | return err; | |
3122 | } | |
3123 | ||
a1193be8 | 3124 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3125 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3126 | { |
8860020e | 3127 | bool haveinfo = false; |
ed1b6cc7 | 3128 | |
a1193be8 SW |
3129 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3130 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3131 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3132 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3133 | return -EINVAL; |
3134 | ||
8860020e | 3135 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3136 | |
a1193be8 SW |
3137 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3138 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3139 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3140 | if (!bcn->head_len) |
3141 | return -EINVAL; | |
3142 | haveinfo = true; | |
ed1b6cc7 JB |
3143 | } |
3144 | ||
a1193be8 SW |
3145 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3146 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3147 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3148 | haveinfo = true; |
ed1b6cc7 JB |
3149 | } |
3150 | ||
4c476991 JB |
3151 | if (!haveinfo) |
3152 | return -EINVAL; | |
3b85875a | 3153 | |
a1193be8 SW |
3154 | if (attrs[NL80211_ATTR_IE]) { |
3155 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3156 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3157 | } |
3158 | ||
a1193be8 | 3159 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3160 | bcn->proberesp_ies = |
a1193be8 | 3161 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3162 | bcn->proberesp_ies_len = |
a1193be8 | 3163 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3164 | } |
3165 | ||
a1193be8 | 3166 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3167 | bcn->assocresp_ies = |
a1193be8 | 3168 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3169 | bcn->assocresp_ies_len = |
a1193be8 | 3170 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3171 | } |
3172 | ||
a1193be8 SW |
3173 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3174 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3175 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3176 | } |
3177 | ||
8860020e JB |
3178 | return 0; |
3179 | } | |
3180 | ||
46c1dd0c FF |
3181 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3182 | struct cfg80211_ap_settings *params) | |
3183 | { | |
3184 | struct wireless_dev *wdev; | |
3185 | bool ret = false; | |
3186 | ||
89a54e48 | 3187 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3188 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3189 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3190 | continue; | |
3191 | ||
683b6d3b | 3192 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3193 | continue; |
3194 | ||
683b6d3b | 3195 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3196 | ret = true; |
3197 | break; | |
3198 | } | |
3199 | ||
46c1dd0c FF |
3200 | return ret; |
3201 | } | |
3202 | ||
e39e5b5e JM |
3203 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3204 | enum nl80211_auth_type auth_type, | |
3205 | enum nl80211_commands cmd) | |
3206 | { | |
3207 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3208 | return false; | |
3209 | ||
3210 | switch (cmd) { | |
3211 | case NL80211_CMD_AUTHENTICATE: | |
3212 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3213 | auth_type == NL80211_AUTHTYPE_SAE) | |
3214 | return false; | |
3215 | return true; | |
3216 | case NL80211_CMD_CONNECT: | |
3217 | case NL80211_CMD_START_AP: | |
3218 | /* SAE not supported yet */ | |
3219 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3220 | return false; | |
3221 | return true; | |
3222 | default: | |
3223 | return false; | |
3224 | } | |
3225 | } | |
3226 | ||
8860020e JB |
3227 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3228 | { | |
3229 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3230 | struct net_device *dev = info->user_ptr[1]; | |
3231 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3232 | struct cfg80211_ap_settings params; | |
3233 | int err; | |
3234 | ||
3235 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3236 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3237 | return -EOPNOTSUPP; | |
3238 | ||
3239 | if (!rdev->ops->start_ap) | |
3240 | return -EOPNOTSUPP; | |
3241 | ||
3242 | if (wdev->beacon_interval) | |
3243 | return -EALREADY; | |
3244 | ||
3245 | memset(¶ms, 0, sizeof(params)); | |
3246 | ||
3247 | /* these are required for START_AP */ | |
3248 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3249 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3250 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3251 | return -EINVAL; | |
3252 | ||
a1193be8 | 3253 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3254 | if (err) |
3255 | return err; | |
3256 | ||
3257 | params.beacon_interval = | |
3258 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3259 | params.dtim_period = | |
3260 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3261 | ||
3262 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3263 | if (err) | |
3264 | return err; | |
3265 | ||
3266 | /* | |
3267 | * In theory, some of these attributes should be required here | |
3268 | * but since they were not used when the command was originally | |
3269 | * added, keep them optional for old user space programs to let | |
3270 | * them continue to work with drivers that do not need the | |
3271 | * additional information -- drivers must check! | |
3272 | */ | |
3273 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3274 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3275 | params.ssid_len = | |
3276 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3277 | if (params.ssid_len == 0 || | |
3278 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3279 | return -EINVAL; | |
3280 | } | |
3281 | ||
3282 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3283 | params.hidden_ssid = nla_get_u32( | |
3284 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3285 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3286 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3287 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3288 | return -EINVAL; | |
3289 | } | |
3290 | ||
3291 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3292 | ||
3293 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3294 | params.auth_type = nla_get_u32( | |
3295 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3296 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3297 | NL80211_CMD_START_AP)) | |
8860020e JB |
3298 | return -EINVAL; |
3299 | } else | |
3300 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3301 | ||
3302 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3303 | NL80211_MAX_NR_CIPHER_SUITES); | |
3304 | if (err) | |
3305 | return err; | |
3306 | ||
1b658f11 VT |
3307 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3308 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3309 | return -EOPNOTSUPP; | |
3310 | params.inactivity_timeout = nla_get_u16( | |
3311 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3312 | } | |
3313 | ||
53cabad7 JB |
3314 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3315 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3316 | return -EINVAL; | |
3317 | params.p2p_ctwindow = | |
3318 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3319 | if (params.p2p_ctwindow > 127) | |
3320 | return -EINVAL; | |
3321 | if (params.p2p_ctwindow != 0 && | |
3322 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3323 | return -EINVAL; | |
3324 | } | |
3325 | ||
3326 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3327 | u8 tmp; | |
3328 | ||
3329 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3330 | return -EINVAL; | |
3331 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3332 | if (tmp > 1) | |
3333 | return -EINVAL; | |
3334 | params.p2p_opp_ps = tmp; | |
3335 | if (params.p2p_opp_ps != 0 && | |
3336 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3337 | return -EINVAL; | |
3338 | } | |
3339 | ||
aa430da4 | 3340 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3341 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3342 | if (err) | |
3343 | return err; | |
3344 | } else if (wdev->preset_chandef.chan) { | |
3345 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3346 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3347 | return -EINVAL; |
3348 | ||
174e0cd2 IP |
3349 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
3350 | wdev->iftype)) | |
aa430da4 JB |
3351 | return -EINVAL; |
3352 | ||
77765eaf VT |
3353 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3354 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3355 | if (IS_ERR(params.acl)) | |
3356 | return PTR_ERR(params.acl); | |
3357 | } | |
3358 | ||
18998c38 EP |
3359 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
3360 | params.smps_mode = | |
3361 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); | |
3362 | switch (params.smps_mode) { | |
3363 | case NL80211_SMPS_OFF: | |
3364 | break; | |
3365 | case NL80211_SMPS_STATIC: | |
3366 | if (!(rdev->wiphy.features & | |
3367 | NL80211_FEATURE_STATIC_SMPS)) | |
3368 | return -EINVAL; | |
3369 | break; | |
3370 | case NL80211_SMPS_DYNAMIC: | |
3371 | if (!(rdev->wiphy.features & | |
3372 | NL80211_FEATURE_DYNAMIC_SMPS)) | |
3373 | return -EINVAL; | |
3374 | break; | |
3375 | default: | |
3376 | return -EINVAL; | |
3377 | } | |
3378 | } else { | |
3379 | params.smps_mode = NL80211_SMPS_OFF; | |
3380 | } | |
3381 | ||
c56589ed | 3382 | wdev_lock(wdev); |
e35e4d28 | 3383 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3384 | if (!err) { |
683b6d3b | 3385 | wdev->preset_chandef = params.chandef; |
8860020e | 3386 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 3387 | wdev->chandef = params.chandef; |
06e191e2 AQ |
3388 | wdev->ssid_len = params.ssid_len; |
3389 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3390 | } |
c56589ed | 3391 | wdev_unlock(wdev); |
77765eaf VT |
3392 | |
3393 | kfree(params.acl); | |
3394 | ||
56d1893d | 3395 | return err; |
ed1b6cc7 JB |
3396 | } |
3397 | ||
8860020e JB |
3398 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3399 | { | |
3400 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3401 | struct net_device *dev = info->user_ptr[1]; | |
3402 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3403 | struct cfg80211_beacon_data params; | |
3404 | int err; | |
3405 | ||
3406 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3407 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3408 | return -EOPNOTSUPP; | |
3409 | ||
3410 | if (!rdev->ops->change_beacon) | |
3411 | return -EOPNOTSUPP; | |
3412 | ||
3413 | if (!wdev->beacon_interval) | |
3414 | return -EINVAL; | |
3415 | ||
a1193be8 | 3416 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3417 | if (err) |
3418 | return err; | |
3419 | ||
c56589ed SW |
3420 | wdev_lock(wdev); |
3421 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3422 | wdev_unlock(wdev); | |
3423 | ||
3424 | return err; | |
8860020e JB |
3425 | } |
3426 | ||
3427 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3428 | { |
4c476991 JB |
3429 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3430 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3431 | |
7c8d5e03 | 3432 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
3433 | } |
3434 | ||
5727ef1b JB |
3435 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3436 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3437 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3438 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3439 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3440 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3441 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3442 | }; |
3443 | ||
eccb8e8f | 3444 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3445 | enum nl80211_iftype iftype, |
eccb8e8f | 3446 | struct station_parameters *params) |
5727ef1b JB |
3447 | { |
3448 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3449 | struct nlattr *nla; |
5727ef1b JB |
3450 | int flag; |
3451 | ||
eccb8e8f JB |
3452 | /* |
3453 | * Try parsing the new attribute first so userspace | |
3454 | * can specify both for older kernels. | |
3455 | */ | |
3456 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3457 | if (nla) { | |
3458 | struct nl80211_sta_flag_update *sta_flags; | |
3459 | ||
3460 | sta_flags = nla_data(nla); | |
3461 | params->sta_flags_mask = sta_flags->mask; | |
3462 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3463 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3464 | if ((params->sta_flags_mask | |
3465 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3466 | return -EINVAL; | |
3467 | return 0; | |
3468 | } | |
3469 | ||
3470 | /* if present, parse the old attribute */ | |
5727ef1b | 3471 | |
eccb8e8f | 3472 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3473 | if (!nla) |
3474 | return 0; | |
3475 | ||
3476 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3477 | nla, sta_flags_policy)) | |
3478 | return -EINVAL; | |
3479 | ||
bdd3ae3d JB |
3480 | /* |
3481 | * Only allow certain flags for interface types so that | |
3482 | * other attributes are silently ignored. Remember that | |
3483 | * this is backward compatibility code with old userspace | |
3484 | * and shouldn't be hit in other cases anyway. | |
3485 | */ | |
3486 | switch (iftype) { | |
3487 | case NL80211_IFTYPE_AP: | |
3488 | case NL80211_IFTYPE_AP_VLAN: | |
3489 | case NL80211_IFTYPE_P2P_GO: | |
3490 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3491 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3492 | BIT(NL80211_STA_FLAG_WME) | | |
3493 | BIT(NL80211_STA_FLAG_MFP); | |
3494 | break; | |
3495 | case NL80211_IFTYPE_P2P_CLIENT: | |
3496 | case NL80211_IFTYPE_STATION: | |
3497 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3498 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3499 | break; | |
3500 | case NL80211_IFTYPE_MESH_POINT: | |
3501 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3502 | BIT(NL80211_STA_FLAG_MFP) | | |
3503 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3504 | default: | |
3505 | return -EINVAL; | |
3506 | } | |
5727ef1b | 3507 | |
3383b5a6 JB |
3508 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3509 | if (flags[flag]) { | |
eccb8e8f | 3510 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3511 | |
3383b5a6 JB |
3512 | /* no longer support new API additions in old API */ |
3513 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3514 | return -EINVAL; | |
3515 | } | |
3516 | } | |
3517 | ||
5727ef1b JB |
3518 | return 0; |
3519 | } | |
3520 | ||
c8dcfd8a FF |
3521 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3522 | int attr) | |
3523 | { | |
3524 | struct nlattr *rate; | |
8eb41c8d VK |
3525 | u32 bitrate; |
3526 | u16 bitrate_compat; | |
c8dcfd8a FF |
3527 | |
3528 | rate = nla_nest_start(msg, attr); | |
3529 | if (!rate) | |
db9c64cf | 3530 | return false; |
c8dcfd8a FF |
3531 | |
3532 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3533 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3534 | /* report 16-bit bitrate only if we can */ |
3535 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3536 | if (bitrate > 0 && |
3537 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3538 | return false; | |
3539 | if (bitrate_compat > 0 && | |
3540 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3541 | return false; | |
3542 | ||
3543 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3544 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3545 | return false; | |
3546 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3547 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3548 | return false; | |
3549 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3550 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3551 | return false; | |
3552 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3553 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3554 | return false; | |
3555 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3556 | return false; | |
3557 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3558 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3559 | return false; | |
3560 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3561 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3562 | return false; | |
3563 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3564 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3565 | return false; | |
3566 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3567 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3568 | return false; | |
3569 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3570 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3571 | return false; | |
3572 | } | |
c8dcfd8a FF |
3573 | |
3574 | nla_nest_end(msg, rate); | |
3575 | return true; | |
c8dcfd8a FF |
3576 | } |
3577 | ||
119363c7 FF |
3578 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3579 | int id) | |
3580 | { | |
3581 | void *attr; | |
3582 | int i = 0; | |
3583 | ||
3584 | if (!mask) | |
3585 | return true; | |
3586 | ||
3587 | attr = nla_nest_start(msg, id); | |
3588 | if (!attr) | |
3589 | return false; | |
3590 | ||
3591 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3592 | if (!(mask & BIT(i))) | |
3593 | continue; | |
3594 | ||
3595 | if (nla_put_u8(msg, i, signal[i])) | |
3596 | return false; | |
3597 | } | |
3598 | ||
3599 | nla_nest_end(msg, attr); | |
3600 | ||
3601 | return true; | |
3602 | } | |
3603 | ||
15e47304 | 3604 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3605 | int flags, |
3606 | struct cfg80211_registered_device *rdev, | |
3607 | struct net_device *dev, | |
98b62183 | 3608 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3609 | { |
3610 | void *hdr; | |
f4263c98 | 3611 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3612 | |
15e47304 | 3613 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3614 | if (!hdr) |
3615 | return -1; | |
3616 | ||
9360ffd1 DM |
3617 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3618 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3619 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3620 | goto nla_put_failure; | |
f5ea9120 | 3621 | |
2ec600d6 LCC |
3622 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3623 | if (!sinfoattr) | |
fd5b74dc | 3624 | goto nla_put_failure; |
9360ffd1 DM |
3625 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3626 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3627 | sinfo->connected_time)) | |
3628 | goto nla_put_failure; | |
3629 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3630 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3631 | sinfo->inactive_time)) | |
3632 | goto nla_put_failure; | |
42745e03 VK |
3633 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3634 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3635 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3636 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3637 | goto nla_put_failure; |
42745e03 | 3638 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
4325d724 | 3639 | STATION_INFO_TX_BYTES64)) && |
9360ffd1 | 3640 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3641 | (u32)sinfo->tx_bytes)) |
3642 | goto nla_put_failure; | |
3643 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3644 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3645 | sinfo->rx_bytes)) | |
3646 | goto nla_put_failure; | |
3647 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3648 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3649 | sinfo->tx_bytes)) |
3650 | goto nla_put_failure; | |
3651 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3652 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3653 | goto nla_put_failure; | |
3654 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3655 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3656 | goto nla_put_failure; | |
3657 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3658 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3659 | sinfo->plink_state)) | |
3660 | goto nla_put_failure; | |
66266b3a JL |
3661 | switch (rdev->wiphy.signal_type) { |
3662 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3663 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3664 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3665 | sinfo->signal)) | |
3666 | goto nla_put_failure; | |
3667 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3668 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3669 | sinfo->signal_avg)) | |
3670 | goto nla_put_failure; | |
66266b3a JL |
3671 | break; |
3672 | default: | |
3673 | break; | |
3674 | } | |
119363c7 FF |
3675 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
3676 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3677 | sinfo->chain_signal, | |
3678 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3679 | goto nla_put_failure; | |
3680 | } | |
3681 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { | |
3682 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3683 | sinfo->chain_signal_avg, | |
3684 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3685 | goto nla_put_failure; | |
3686 | } | |
420e7fab | 3687 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3688 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3689 | NL80211_STA_INFO_TX_BITRATE)) | |
3690 | goto nla_put_failure; | |
3691 | } | |
3692 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3693 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3694 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3695 | goto nla_put_failure; |
420e7fab | 3696 | } |
9360ffd1 DM |
3697 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3698 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3699 | sinfo->rx_packets)) | |
3700 | goto nla_put_failure; | |
3701 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3702 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3703 | sinfo->tx_packets)) | |
3704 | goto nla_put_failure; | |
3705 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3706 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3707 | sinfo->tx_retries)) | |
3708 | goto nla_put_failure; | |
3709 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3710 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3711 | sinfo->tx_failed)) | |
3712 | goto nla_put_failure; | |
867d849f AQ |
3713 | if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) && |
3714 | nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT, | |
3715 | sinfo->expected_throughput)) | |
3716 | goto nla_put_failure; | |
9360ffd1 DM |
3717 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
3718 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3719 | sinfo->beacon_loss_count)) | |
3720 | goto nla_put_failure; | |
3b1c5a53 MP |
3721 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3722 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3723 | sinfo->local_pm)) | |
3724 | goto nla_put_failure; | |
3725 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3726 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3727 | sinfo->peer_pm)) | |
3728 | goto nla_put_failure; | |
3729 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3730 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3731 | sinfo->nonpeer_pm)) | |
3732 | goto nla_put_failure; | |
f4263c98 PS |
3733 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3734 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3735 | if (!bss_param) | |
3736 | goto nla_put_failure; | |
3737 | ||
9360ffd1 DM |
3738 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3739 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3740 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3741 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3742 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3743 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3744 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3745 | sinfo->bss_param.dtim_period) || | |
3746 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3747 | sinfo->bss_param.beacon_interval)) | |
3748 | goto nla_put_failure; | |
f4263c98 PS |
3749 | |
3750 | nla_nest_end(msg, bss_param); | |
3751 | } | |
9360ffd1 DM |
3752 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3753 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3754 | sizeof(struct nl80211_sta_flag_update), | |
3755 | &sinfo->sta_flags)) | |
3756 | goto nla_put_failure; | |
7eab0f64 JL |
3757 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3758 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3759 | sinfo->t_offset)) | |
3760 | goto nla_put_failure; | |
2ec600d6 | 3761 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3762 | |
9360ffd1 DM |
3763 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3764 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3765 | sinfo->assoc_req_ies)) | |
3766 | goto nla_put_failure; | |
50d3dfb7 | 3767 | |
fd5b74dc JB |
3768 | return genlmsg_end(msg, hdr); |
3769 | ||
3770 | nla_put_failure: | |
bc3ed28c TG |
3771 | genlmsg_cancel(msg, hdr); |
3772 | return -EMSGSIZE; | |
fd5b74dc JB |
3773 | } |
3774 | ||
2ec600d6 | 3775 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3776 | struct netlink_callback *cb) |
2ec600d6 | 3777 | { |
2ec600d6 | 3778 | struct station_info sinfo; |
1b8ec87a | 3779 | struct cfg80211_registered_device *rdev; |
97990a06 | 3780 | struct wireless_dev *wdev; |
2ec600d6 | 3781 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3782 | int sta_idx = cb->args[2]; |
2ec600d6 | 3783 | int err; |
2ec600d6 | 3784 | |
1b8ec87a | 3785 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
3786 | if (err) |
3787 | return err; | |
bba95fef | 3788 | |
97990a06 JB |
3789 | if (!wdev->netdev) { |
3790 | err = -EINVAL; | |
3791 | goto out_err; | |
3792 | } | |
3793 | ||
1b8ec87a | 3794 | if (!rdev->ops->dump_station) { |
eec60b03 | 3795 | err = -EOPNOTSUPP; |
bba95fef JB |
3796 | goto out_err; |
3797 | } | |
3798 | ||
bba95fef | 3799 | while (1) { |
f612cedf | 3800 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 3801 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
e35e4d28 | 3802 | mac_addr, &sinfo); |
bba95fef JB |
3803 | if (err == -ENOENT) |
3804 | break; | |
3805 | if (err) | |
3b85875a | 3806 | goto out_err; |
bba95fef JB |
3807 | |
3808 | if (nl80211_send_station(skb, | |
15e47304 | 3809 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3810 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 3811 | rdev, wdev->netdev, mac_addr, |
bba95fef JB |
3812 | &sinfo) < 0) |
3813 | goto out; | |
3814 | ||
3815 | sta_idx++; | |
3816 | } | |
3817 | ||
3818 | ||
3819 | out: | |
97990a06 | 3820 | cb->args[2] = sta_idx; |
bba95fef | 3821 | err = skb->len; |
bba95fef | 3822 | out_err: |
1b8ec87a | 3823 | nl80211_finish_wdev_dump(rdev); |
bba95fef JB |
3824 | |
3825 | return err; | |
2ec600d6 | 3826 | } |
fd5b74dc | 3827 | |
5727ef1b JB |
3828 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3829 | { | |
4c476991 JB |
3830 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3831 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3832 | struct station_info sinfo; |
fd5b74dc JB |
3833 | struct sk_buff *msg; |
3834 | u8 *mac_addr = NULL; | |
4c476991 | 3835 | int err; |
fd5b74dc | 3836 | |
2ec600d6 | 3837 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3838 | |
3839 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3840 | return -EINVAL; | |
3841 | ||
3842 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3843 | ||
4c476991 JB |
3844 | if (!rdev->ops->get_station) |
3845 | return -EOPNOTSUPP; | |
3b85875a | 3846 | |
e35e4d28 | 3847 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3848 | if (err) |
4c476991 | 3849 | return err; |
2ec600d6 | 3850 | |
fd2120ca | 3851 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3852 | if (!msg) |
4c476991 | 3853 | return -ENOMEM; |
fd5b74dc | 3854 | |
15e47304 | 3855 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3856 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3857 | nlmsg_free(msg); |
3858 | return -ENOBUFS; | |
3859 | } | |
3b85875a | 3860 | |
4c476991 | 3861 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3862 | } |
3863 | ||
77ee7c89 JB |
3864 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3865 | struct station_parameters *params, | |
3866 | enum cfg80211_station_type statype) | |
3867 | { | |
3868 | if (params->listen_interval != -1) | |
3869 | return -EINVAL; | |
c72e1140 AN |
3870 | if (params->aid && |
3871 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
77ee7c89 JB |
3872 | return -EINVAL; |
3873 | ||
3874 | /* When you run into this, adjust the code below for the new flag */ | |
3875 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3876 | ||
3877 | switch (statype) { | |
eef941e6 TP |
3878 | case CFG80211_STA_MESH_PEER_KERNEL: |
3879 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3880 | /* |
3881 | * No ignoring the TDLS flag here -- the userspace mesh | |
3882 | * code doesn't have the bug of including TDLS in the | |
3883 | * mask everywhere. | |
3884 | */ | |
3885 | if (params->sta_flags_mask & | |
3886 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3887 | BIT(NL80211_STA_FLAG_MFP) | | |
3888 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3889 | return -EINVAL; | |
3890 | break; | |
3891 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3892 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3893 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3894 | return -EINVAL; | |
3895 | /* ignore since it can't change */ | |
3896 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3897 | break; | |
3898 | default: | |
3899 | /* disallow mesh-specific things */ | |
3900 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3901 | return -EINVAL; | |
3902 | if (params->local_pm) | |
3903 | return -EINVAL; | |
3904 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3905 | return -EINVAL; | |
3906 | } | |
3907 | ||
3908 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3909 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3910 | /* TDLS can't be set, ... */ | |
3911 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3912 | return -EINVAL; | |
3913 | /* | |
3914 | * ... but don't bother the driver with it. This works around | |
3915 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3916 | * TLDS_PEER flag in the mask even for AP mode. | |
3917 | */ | |
3918 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3919 | } | |
3920 | ||
3921 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3922 | /* reject other things that can't change */ | |
3923 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3924 | return -EINVAL; | |
3925 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3926 | return -EINVAL; | |
3927 | if (params->supported_rates) | |
3928 | return -EINVAL; | |
3929 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3930 | return -EINVAL; | |
3931 | } | |
3932 | ||
3933 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3934 | if (params->vlan) | |
3935 | return -EINVAL; | |
3936 | } | |
3937 | ||
3938 | switch (statype) { | |
3939 | case CFG80211_STA_AP_MLME_CLIENT: | |
3940 | /* Use this only for authorizing/unauthorizing a station */ | |
3941 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3942 | return -EOPNOTSUPP; | |
3943 | break; | |
3944 | case CFG80211_STA_AP_CLIENT: | |
3945 | /* accept only the listed bits */ | |
3946 | if (params->sta_flags_mask & | |
3947 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3948 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3949 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
3950 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3951 | BIT(NL80211_STA_FLAG_WME) | | |
3952 | BIT(NL80211_STA_FLAG_MFP))) | |
3953 | return -EINVAL; | |
3954 | ||
3955 | /* but authenticated/associated only if driver handles it */ | |
3956 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3957 | params->sta_flags_mask & | |
3958 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3959 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3960 | return -EINVAL; | |
3961 | break; | |
3962 | case CFG80211_STA_IBSS: | |
3963 | case CFG80211_STA_AP_STA: | |
3964 | /* reject any changes other than AUTHORIZED */ | |
3965 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3966 | return -EINVAL; | |
3967 | break; | |
3968 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3969 | /* reject any changes other than AUTHORIZED or WME */ | |
3970 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3971 | BIT(NL80211_STA_FLAG_WME))) | |
3972 | return -EINVAL; | |
3973 | /* force (at least) rates when authorizing */ | |
3974 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
3975 | !params->supported_rates) | |
3976 | return -EINVAL; | |
3977 | break; | |
3978 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3979 | /* reject any changes */ | |
3980 | return -EINVAL; | |
eef941e6 | 3981 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
3982 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
3983 | return -EINVAL; | |
3984 | break; | |
eef941e6 | 3985 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
3986 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
3987 | return -EINVAL; | |
3988 | break; | |
3989 | } | |
3990 | ||
3991 | return 0; | |
3992 | } | |
3993 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
3994 | ||
5727ef1b | 3995 | /* |
c258d2de | 3996 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 3997 | */ |
80b99899 JB |
3998 | static struct net_device *get_vlan(struct genl_info *info, |
3999 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 4000 | { |
463d0183 | 4001 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
4002 | struct net_device *v; |
4003 | int ret; | |
4004 | ||
4005 | if (!vlanattr) | |
4006 | return NULL; | |
4007 | ||
4008 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
4009 | if (!v) | |
4010 | return ERR_PTR(-ENODEV); | |
4011 | ||
4012 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
4013 | ret = -EINVAL; | |
4014 | goto error; | |
5727ef1b | 4015 | } |
80b99899 | 4016 | |
77ee7c89 JB |
4017 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
4018 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4019 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
4020 | ret = -EINVAL; | |
4021 | goto error; | |
4022 | } | |
4023 | ||
80b99899 JB |
4024 | if (!netif_running(v)) { |
4025 | ret = -ENETDOWN; | |
4026 | goto error; | |
4027 | } | |
4028 | ||
4029 | return v; | |
4030 | error: | |
4031 | dev_put(v); | |
4032 | return ERR_PTR(ret); | |
5727ef1b JB |
4033 | } |
4034 | ||
94e860f1 JB |
4035 | static const struct nla_policy |
4036 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
4037 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
4038 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
4039 | }; | |
4040 | ||
ff276691 JB |
4041 | static int nl80211_parse_sta_wme(struct genl_info *info, |
4042 | struct station_parameters *params) | |
df881293 | 4043 | { |
df881293 JM |
4044 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
4045 | struct nlattr *nla; | |
4046 | int err; | |
4047 | ||
df881293 JM |
4048 | /* parse WME attributes if present */ |
4049 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
4050 | return 0; | |
4051 | ||
4052 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
4053 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
4054 | nl80211_sta_wme_policy); | |
4055 | if (err) | |
4056 | return err; | |
4057 | ||
4058 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
4059 | params->uapsd_queues = nla_get_u8( | |
4060 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4061 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
4062 | return -EINVAL; | |
4063 | ||
4064 | if (tb[NL80211_STA_WME_MAX_SP]) | |
4065 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4066 | ||
4067 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
4068 | return -EINVAL; | |
4069 | ||
4070 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
4071 | ||
4072 | return 0; | |
4073 | } | |
4074 | ||
c01fc9ad SD |
4075 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4076 | struct station_parameters *params) | |
4077 | { | |
4078 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4079 | params->supported_channels = | |
4080 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4081 | params->supported_channels_len = | |
4082 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4083 | /* | |
4084 | * Need to include at least one (first channel, number of | |
4085 | * channels) tuple for each subband, and must have proper | |
4086 | * tuples for the rest of the data as well. | |
4087 | */ | |
4088 | if (params->supported_channels_len < 2) | |
4089 | return -EINVAL; | |
4090 | if (params->supported_channels_len % 2) | |
4091 | return -EINVAL; | |
4092 | } | |
4093 | ||
4094 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4095 | params->supported_oper_classes = | |
4096 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4097 | params->supported_oper_classes_len = | |
4098 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4099 | /* | |
4100 | * The value of the Length field of the Supported Operating | |
4101 | * Classes element is between 2 and 253. | |
4102 | */ | |
4103 | if (params->supported_oper_classes_len < 2 || | |
4104 | params->supported_oper_classes_len > 253) | |
4105 | return -EINVAL; | |
4106 | } | |
4107 | return 0; | |
4108 | } | |
4109 | ||
ff276691 JB |
4110 | static int nl80211_set_station_tdls(struct genl_info *info, |
4111 | struct station_parameters *params) | |
4112 | { | |
c01fc9ad | 4113 | int err; |
ff276691 | 4114 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4115 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4116 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4117 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4118 | params->ht_capa = | |
4119 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4120 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4121 | params->vht_capa = | |
4122 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4123 | ||
c01fc9ad SD |
4124 | err = nl80211_parse_sta_channel_info(info, params); |
4125 | if (err) | |
4126 | return err; | |
4127 | ||
ff276691 JB |
4128 | return nl80211_parse_sta_wme(info, params); |
4129 | } | |
4130 | ||
5727ef1b JB |
4131 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4132 | { | |
4c476991 | 4133 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4134 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4135 | struct station_parameters params; |
77ee7c89 JB |
4136 | u8 *mac_addr; |
4137 | int err; | |
5727ef1b JB |
4138 | |
4139 | memset(¶ms, 0, sizeof(params)); | |
4140 | ||
4141 | params.listen_interval = -1; | |
4142 | ||
77ee7c89 JB |
4143 | if (!rdev->ops->change_station) |
4144 | return -EOPNOTSUPP; | |
4145 | ||
5727ef1b JB |
4146 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4147 | return -EINVAL; | |
4148 | ||
4149 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4150 | return -EINVAL; | |
4151 | ||
4152 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4153 | ||
4154 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4155 | params.supported_rates = | |
4156 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4157 | params.supported_rates_len = | |
4158 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4159 | } | |
4160 | ||
9d62a986 JM |
4161 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4162 | params.capability = | |
4163 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4164 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4165 | } | |
4166 | ||
4167 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4168 | params.ext_capab = | |
4169 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4170 | params.ext_capab_len = | |
4171 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4172 | } | |
4173 | ||
df881293 | 4174 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 4175 | return -EINVAL; |
36aedc90 | 4176 | |
bdd3ae3d | 4177 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4178 | return -EINVAL; |
4179 | ||
f8bacc21 | 4180 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4181 | params.plink_action = |
f8bacc21 JB |
4182 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4183 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4184 | return -EINVAL; | |
4185 | } | |
2ec600d6 | 4186 | |
f8bacc21 | 4187 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4188 | params.plink_state = |
f8bacc21 JB |
4189 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4190 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4191 | return -EINVAL; | |
4192 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
4193 | } | |
9c3990aa | 4194 | |
3b1c5a53 MP |
4195 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4196 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4197 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4198 | ||
4199 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4200 | pm > NL80211_MESH_POWER_MAX) | |
4201 | return -EINVAL; | |
4202 | ||
4203 | params.local_pm = pm; | |
4204 | } | |
4205 | ||
77ee7c89 JB |
4206 | /* Include parameters for TDLS peer (will check later) */ |
4207 | err = nl80211_set_station_tdls(info, ¶ms); | |
4208 | if (err) | |
4209 | return err; | |
4210 | ||
4211 | params.vlan = get_vlan(info, rdev); | |
4212 | if (IS_ERR(params.vlan)) | |
4213 | return PTR_ERR(params.vlan); | |
4214 | ||
a97f4424 JB |
4215 | switch (dev->ieee80211_ptr->iftype) { |
4216 | case NL80211_IFTYPE_AP: | |
4217 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4218 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4219 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4220 | case NL80211_IFTYPE_STATION: |
267335d6 | 4221 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4222 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4223 | break; |
4224 | default: | |
77ee7c89 JB |
4225 | err = -EOPNOTSUPP; |
4226 | goto out_put_vlan; | |
034d655e JB |
4227 | } |
4228 | ||
77ee7c89 | 4229 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4230 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4231 | |
77ee7c89 | 4232 | out_put_vlan: |
5727ef1b JB |
4233 | if (params.vlan) |
4234 | dev_put(params.vlan); | |
3b85875a | 4235 | |
5727ef1b JB |
4236 | return err; |
4237 | } | |
4238 | ||
4239 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4240 | { | |
4c476991 | 4241 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4242 | int err; |
4c476991 | 4243 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4244 | struct station_parameters params; |
4245 | u8 *mac_addr = NULL; | |
4246 | ||
4247 | memset(¶ms, 0, sizeof(params)); | |
4248 | ||
984c311b JB |
4249 | if (!rdev->ops->add_station) |
4250 | return -EOPNOTSUPP; | |
4251 | ||
5727ef1b JB |
4252 | if (!info->attrs[NL80211_ATTR_MAC]) |
4253 | return -EINVAL; | |
4254 | ||
5727ef1b JB |
4255 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4256 | return -EINVAL; | |
4257 | ||
4258 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4259 | return -EINVAL; | |
4260 | ||
5e4b6f56 JM |
4261 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4262 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4263 | return -EINVAL; |
4264 | ||
5727ef1b JB |
4265 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4266 | params.supported_rates = | |
4267 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4268 | params.supported_rates_len = | |
4269 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4270 | params.listen_interval = | |
4271 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4272 | |
3d124ea2 | 4273 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4274 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4275 | else |
4276 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4277 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4278 | return -EINVAL; | |
51b50fbe | 4279 | |
9d62a986 JM |
4280 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4281 | params.capability = | |
4282 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4283 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4284 | } | |
4285 | ||
4286 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4287 | params.ext_capab = | |
4288 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4289 | params.ext_capab_len = | |
4290 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4291 | } | |
4292 | ||
36aedc90 JM |
4293 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4294 | params.ht_capa = | |
4295 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4296 | |
f461be3e MP |
4297 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4298 | params.vht_capa = | |
4299 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4300 | ||
60f4a7b1 MK |
4301 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4302 | params.opmode_notif_used = true; | |
4303 | params.opmode_notif = | |
4304 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4305 | } | |
4306 | ||
f8bacc21 | 4307 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4308 | params.plink_action = |
f8bacc21 JB |
4309 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4310 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4311 | return -EINVAL; | |
4312 | } | |
96b78dff | 4313 | |
c01fc9ad SD |
4314 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4315 | if (err) | |
4316 | return err; | |
4317 | ||
ff276691 JB |
4318 | err = nl80211_parse_sta_wme(info, ¶ms); |
4319 | if (err) | |
4320 | return err; | |
bdd90d5e | 4321 | |
bdd3ae3d | 4322 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4323 | return -EINVAL; |
4324 | ||
77ee7c89 JB |
4325 | /* When you run into this, adjust the code below for the new flag */ |
4326 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4327 | ||
bdd90d5e JB |
4328 | switch (dev->ieee80211_ptr->iftype) { |
4329 | case NL80211_IFTYPE_AP: | |
4330 | case NL80211_IFTYPE_AP_VLAN: | |
4331 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4332 | /* ignore WME attributes if iface/sta is not capable */ |
4333 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4334 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4335 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4336 | |
bdd90d5e | 4337 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4338 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4339 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4340 | return -EINVAL; |
bdd90d5e JB |
4341 | /* but don't bother the driver with it */ |
4342 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4343 | |
d582cffb JB |
4344 | /* allow authenticated/associated only if driver handles it */ |
4345 | if (!(rdev->wiphy.features & | |
4346 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4347 | params.sta_flags_mask & | |
4348 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4349 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4350 | return -EINVAL; | |
4351 | ||
bdd90d5e JB |
4352 | /* must be last in here for error handling */ |
4353 | params.vlan = get_vlan(info, rdev); | |
4354 | if (IS_ERR(params.vlan)) | |
4355 | return PTR_ERR(params.vlan); | |
4356 | break; | |
4357 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4358 | /* ignore uAPSD data */ |
4359 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4360 | ||
d582cffb JB |
4361 | /* associated is disallowed */ |
4362 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4363 | return -EINVAL; | |
bdd90d5e | 4364 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4365 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4366 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4367 | return -EINVAL; |
4368 | break; | |
4369 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4370 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4371 | /* ignore uAPSD data */ |
4372 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4373 | ||
77ee7c89 JB |
4374 | /* these are disallowed */ |
4375 | if (params.sta_flags_mask & | |
4376 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4377 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4378 | return -EINVAL; |
bdd90d5e JB |
4379 | /* Only TDLS peers can be added */ |
4380 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4381 | return -EINVAL; | |
4382 | /* Can only add if TDLS ... */ | |
4383 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4384 | return -EOPNOTSUPP; | |
4385 | /* ... with external setup is supported */ | |
4386 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4387 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4388 | /* |
4389 | * Older wpa_supplicant versions always mark the TDLS peer | |
4390 | * as authorized, but it shouldn't yet be. | |
4391 | */ | |
4392 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4393 | break; |
4394 | default: | |
4395 | return -EOPNOTSUPP; | |
c75786c9 EP |
4396 | } |
4397 | ||
bdd90d5e | 4398 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4399 | |
e35e4d28 | 4400 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4401 | |
5727ef1b JB |
4402 | if (params.vlan) |
4403 | dev_put(params.vlan); | |
5727ef1b JB |
4404 | return err; |
4405 | } | |
4406 | ||
4407 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4408 | { | |
4c476991 JB |
4409 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4410 | struct net_device *dev = info->user_ptr[1]; | |
89c771e5 JM |
4411 | struct station_del_parameters params; |
4412 | ||
4413 | memset(¶ms, 0, sizeof(params)); | |
5727ef1b JB |
4414 | |
4415 | if (info->attrs[NL80211_ATTR_MAC]) | |
89c771e5 | 4416 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5727ef1b | 4417 | |
e80cf853 | 4418 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4419 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4420 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4421 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4422 | return -EINVAL; | |
5727ef1b | 4423 | |
4c476991 JB |
4424 | if (!rdev->ops->del_station) |
4425 | return -EOPNOTSUPP; | |
3b85875a | 4426 | |
98856866 JM |
4427 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
4428 | params.subtype = | |
4429 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | |
4430 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | |
4431 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | |
4432 | return -EINVAL; | |
4433 | } else { | |
4434 | /* Default to Deauthentication frame */ | |
4435 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | |
4436 | } | |
4437 | ||
4438 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | |
4439 | params.reason_code = | |
4440 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
4441 | if (params.reason_code == 0) | |
4442 | return -EINVAL; /* 0 is reserved */ | |
4443 | } else { | |
4444 | /* Default to reason code 2 */ | |
4445 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | |
4446 | } | |
4447 | ||
89c771e5 | 4448 | return rdev_del_station(rdev, dev, ¶ms); |
5727ef1b JB |
4449 | } |
4450 | ||
15e47304 | 4451 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4452 | int flags, struct net_device *dev, |
4453 | u8 *dst, u8 *next_hop, | |
4454 | struct mpath_info *pinfo) | |
4455 | { | |
4456 | void *hdr; | |
4457 | struct nlattr *pinfoattr; | |
4458 | ||
1ef4c850 | 4459 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
2ec600d6 LCC |
4460 | if (!hdr) |
4461 | return -1; | |
4462 | ||
9360ffd1 DM |
4463 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4464 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4465 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4466 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4467 | goto nla_put_failure; | |
f5ea9120 | 4468 | |
2ec600d6 LCC |
4469 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4470 | if (!pinfoattr) | |
4471 | goto nla_put_failure; | |
9360ffd1 DM |
4472 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4473 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4474 | pinfo->frame_qlen)) | |
4475 | goto nla_put_failure; | |
4476 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4477 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4478 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4479 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4480 | pinfo->metric)) || | |
4481 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4482 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4483 | pinfo->exptime)) || | |
4484 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4485 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4486 | pinfo->flags)) || | |
4487 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4488 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4489 | pinfo->discovery_timeout)) || | |
4490 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4491 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4492 | pinfo->discovery_retries))) | |
4493 | goto nla_put_failure; | |
2ec600d6 LCC |
4494 | |
4495 | nla_nest_end(msg, pinfoattr); | |
4496 | ||
4497 | return genlmsg_end(msg, hdr); | |
4498 | ||
4499 | nla_put_failure: | |
bc3ed28c TG |
4500 | genlmsg_cancel(msg, hdr); |
4501 | return -EMSGSIZE; | |
2ec600d6 LCC |
4502 | } |
4503 | ||
4504 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4505 | struct netlink_callback *cb) |
2ec600d6 | 4506 | { |
2ec600d6 | 4507 | struct mpath_info pinfo; |
1b8ec87a | 4508 | struct cfg80211_registered_device *rdev; |
97990a06 | 4509 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4510 | u8 dst[ETH_ALEN]; |
4511 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4512 | int path_idx = cb->args[2]; |
2ec600d6 | 4513 | int err; |
2ec600d6 | 4514 | |
1b8ec87a | 4515 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
4516 | if (err) |
4517 | return err; | |
bba95fef | 4518 | |
1b8ec87a | 4519 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 4520 | err = -EOPNOTSUPP; |
bba95fef JB |
4521 | goto out_err; |
4522 | } | |
4523 | ||
97990a06 | 4524 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4525 | err = -EOPNOTSUPP; |
0448b5fc | 4526 | goto out_err; |
eec60b03 JM |
4527 | } |
4528 | ||
bba95fef | 4529 | while (1) { |
1b8ec87a | 4530 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 4531 | next_hop, &pinfo); |
bba95fef | 4532 | if (err == -ENOENT) |
2ec600d6 | 4533 | break; |
bba95fef | 4534 | if (err) |
3b85875a | 4535 | goto out_err; |
2ec600d6 | 4536 | |
15e47304 | 4537 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4538 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4539 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4540 | &pinfo) < 0) |
4541 | goto out; | |
2ec600d6 | 4542 | |
bba95fef | 4543 | path_idx++; |
2ec600d6 | 4544 | } |
2ec600d6 | 4545 | |
2ec600d6 | 4546 | |
bba95fef | 4547 | out: |
97990a06 | 4548 | cb->args[2] = path_idx; |
bba95fef | 4549 | err = skb->len; |
bba95fef | 4550 | out_err: |
1b8ec87a | 4551 | nl80211_finish_wdev_dump(rdev); |
bba95fef | 4552 | return err; |
2ec600d6 LCC |
4553 | } |
4554 | ||
4555 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4556 | { | |
4c476991 | 4557 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4558 | int err; |
4c476991 | 4559 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4560 | struct mpath_info pinfo; |
4561 | struct sk_buff *msg; | |
4562 | u8 *dst = NULL; | |
4563 | u8 next_hop[ETH_ALEN]; | |
4564 | ||
4565 | memset(&pinfo, 0, sizeof(pinfo)); | |
4566 | ||
4567 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4568 | return -EINVAL; | |
4569 | ||
4570 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4571 | ||
4c476991 JB |
4572 | if (!rdev->ops->get_mpath) |
4573 | return -EOPNOTSUPP; | |
2ec600d6 | 4574 | |
4c476991 JB |
4575 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4576 | return -EOPNOTSUPP; | |
eec60b03 | 4577 | |
e35e4d28 | 4578 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4579 | if (err) |
4c476991 | 4580 | return err; |
2ec600d6 | 4581 | |
fd2120ca | 4582 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4583 | if (!msg) |
4c476991 | 4584 | return -ENOMEM; |
2ec600d6 | 4585 | |
15e47304 | 4586 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4587 | dev, dst, next_hop, &pinfo) < 0) { |
4588 | nlmsg_free(msg); | |
4589 | return -ENOBUFS; | |
4590 | } | |
3b85875a | 4591 | |
4c476991 | 4592 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4593 | } |
4594 | ||
4595 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4596 | { | |
4c476991 JB |
4597 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4598 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4599 | u8 *dst = NULL; |
4600 | u8 *next_hop = NULL; | |
4601 | ||
4602 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4603 | return -EINVAL; | |
4604 | ||
4605 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4606 | return -EINVAL; | |
4607 | ||
4608 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4609 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4610 | ||
4c476991 JB |
4611 | if (!rdev->ops->change_mpath) |
4612 | return -EOPNOTSUPP; | |
35a8efe1 | 4613 | |
4c476991 JB |
4614 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4615 | return -EOPNOTSUPP; | |
2ec600d6 | 4616 | |
e35e4d28 | 4617 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4618 | } |
4c476991 | 4619 | |
2ec600d6 LCC |
4620 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4621 | { | |
4c476991 JB |
4622 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4623 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4624 | u8 *dst = NULL; |
4625 | u8 *next_hop = NULL; | |
4626 | ||
4627 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4628 | return -EINVAL; | |
4629 | ||
4630 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4631 | return -EINVAL; | |
4632 | ||
4633 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4634 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4635 | ||
4c476991 JB |
4636 | if (!rdev->ops->add_mpath) |
4637 | return -EOPNOTSUPP; | |
35a8efe1 | 4638 | |
4c476991 JB |
4639 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4640 | return -EOPNOTSUPP; | |
2ec600d6 | 4641 | |
e35e4d28 | 4642 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4643 | } |
4644 | ||
4645 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4646 | { | |
4c476991 JB |
4647 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4648 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4649 | u8 *dst = NULL; |
4650 | ||
4651 | if (info->attrs[NL80211_ATTR_MAC]) | |
4652 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4653 | ||
4c476991 JB |
4654 | if (!rdev->ops->del_mpath) |
4655 | return -EOPNOTSUPP; | |
3b85875a | 4656 | |
e35e4d28 | 4657 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4658 | } |
4659 | ||
66be7d2b HR |
4660 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
4661 | { | |
4662 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4663 | int err; | |
4664 | struct net_device *dev = info->user_ptr[1]; | |
4665 | struct mpath_info pinfo; | |
4666 | struct sk_buff *msg; | |
4667 | u8 *dst = NULL; | |
4668 | u8 mpp[ETH_ALEN]; | |
4669 | ||
4670 | memset(&pinfo, 0, sizeof(pinfo)); | |
4671 | ||
4672 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4673 | return -EINVAL; | |
4674 | ||
4675 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4676 | ||
4677 | if (!rdev->ops->get_mpp) | |
4678 | return -EOPNOTSUPP; | |
4679 | ||
4680 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
4681 | return -EOPNOTSUPP; | |
4682 | ||
4683 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | |
4684 | if (err) | |
4685 | return err; | |
4686 | ||
4687 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4688 | if (!msg) | |
4689 | return -ENOMEM; | |
4690 | ||
4691 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | |
4692 | dev, dst, mpp, &pinfo) < 0) { | |
4693 | nlmsg_free(msg); | |
4694 | return -ENOBUFS; | |
4695 | } | |
4696 | ||
4697 | return genlmsg_reply(msg, info); | |
4698 | } | |
4699 | ||
4700 | static int nl80211_dump_mpp(struct sk_buff *skb, | |
4701 | struct netlink_callback *cb) | |
4702 | { | |
4703 | struct mpath_info pinfo; | |
4704 | struct cfg80211_registered_device *rdev; | |
4705 | struct wireless_dev *wdev; | |
4706 | u8 dst[ETH_ALEN]; | |
4707 | u8 mpp[ETH_ALEN]; | |
4708 | int path_idx = cb->args[2]; | |
4709 | int err; | |
4710 | ||
4711 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | |
4712 | if (err) | |
4713 | return err; | |
4714 | ||
4715 | if (!rdev->ops->dump_mpp) { | |
4716 | err = -EOPNOTSUPP; | |
4717 | goto out_err; | |
4718 | } | |
4719 | ||
4720 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | |
4721 | err = -EOPNOTSUPP; | |
4722 | goto out_err; | |
4723 | } | |
4724 | ||
4725 | while (1) { | |
4726 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | |
4727 | mpp, &pinfo); | |
4728 | if (err == -ENOENT) | |
4729 | break; | |
4730 | if (err) | |
4731 | goto out_err; | |
4732 | ||
4733 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | |
4734 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
4735 | wdev->netdev, dst, mpp, | |
4736 | &pinfo) < 0) | |
4737 | goto out; | |
4738 | ||
4739 | path_idx++; | |
4740 | } | |
4741 | ||
4742 | out: | |
4743 | cb->args[2] = path_idx; | |
4744 | err = skb->len; | |
4745 | out_err: | |
4746 | nl80211_finish_wdev_dump(rdev); | |
4747 | return err; | |
4748 | } | |
4749 | ||
9f1ba906 JM |
4750 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4751 | { | |
4c476991 JB |
4752 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4753 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 4754 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 4755 | struct bss_parameters params; |
c56589ed | 4756 | int err; |
9f1ba906 JM |
4757 | |
4758 | memset(¶ms, 0, sizeof(params)); | |
4759 | /* default to not changing parameters */ | |
4760 | params.use_cts_prot = -1; | |
4761 | params.use_short_preamble = -1; | |
4762 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4763 | params.ap_isolate = -1; |
50b12f59 | 4764 | params.ht_opmode = -1; |
53cabad7 JB |
4765 | params.p2p_ctwindow = -1; |
4766 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4767 | |
4768 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4769 | params.use_cts_prot = | |
4770 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4771 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4772 | params.use_short_preamble = | |
4773 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4774 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4775 | params.use_short_slot_time = | |
4776 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4777 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4778 | params.basic_rates = | |
4779 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4780 | params.basic_rates_len = | |
4781 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4782 | } | |
fd8aaaf3 FF |
4783 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4784 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4785 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4786 | params.ht_opmode = | |
4787 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4788 | |
53cabad7 JB |
4789 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4790 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4791 | return -EINVAL; | |
4792 | params.p2p_ctwindow = | |
4793 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4794 | if (params.p2p_ctwindow < 0) | |
4795 | return -EINVAL; | |
4796 | if (params.p2p_ctwindow != 0 && | |
4797 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4798 | return -EINVAL; | |
4799 | } | |
4800 | ||
4801 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4802 | u8 tmp; | |
4803 | ||
4804 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4805 | return -EINVAL; | |
4806 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4807 | if (tmp > 1) | |
4808 | return -EINVAL; | |
4809 | params.p2p_opp_ps = tmp; | |
4810 | if (params.p2p_opp_ps && | |
4811 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4812 | return -EINVAL; | |
4813 | } | |
4814 | ||
4c476991 JB |
4815 | if (!rdev->ops->change_bss) |
4816 | return -EOPNOTSUPP; | |
9f1ba906 | 4817 | |
074ac8df | 4818 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4819 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4820 | return -EOPNOTSUPP; | |
3b85875a | 4821 | |
c56589ed SW |
4822 | wdev_lock(wdev); |
4823 | err = rdev_change_bss(rdev, dev, ¶ms); | |
4824 | wdev_unlock(wdev); | |
4825 | ||
4826 | return err; | |
9f1ba906 JM |
4827 | } |
4828 | ||
b54452b0 | 4829 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4830 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4831 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4832 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4833 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4834 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4835 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
089027e5 | 4836 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
b2e1b302 LR |
4837 | }; |
4838 | ||
4839 | static int parse_reg_rule(struct nlattr *tb[], | |
4840 | struct ieee80211_reg_rule *reg_rule) | |
4841 | { | |
4842 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4843 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4844 | ||
4845 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4846 | return -EINVAL; | |
4847 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4848 | return -EINVAL; | |
4849 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4850 | return -EINVAL; | |
b0dfd2ea JD |
4851 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
4852 | return -EINVAL; | |
b2e1b302 LR |
4853 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
4854 | return -EINVAL; | |
4855 | ||
4856 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4857 | ||
4858 | freq_range->start_freq_khz = | |
4859 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4860 | freq_range->end_freq_khz = | |
4861 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
b0dfd2ea JD |
4862 | freq_range->max_bandwidth_khz = |
4863 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
b2e1b302 LR |
4864 | |
4865 | power_rule->max_eirp = | |
4866 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4867 | ||
4868 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4869 | power_rule->max_antenna_gain = | |
4870 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4871 | ||
089027e5 JD |
4872 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
4873 | reg_rule->dfs_cac_ms = | |
4874 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
4875 | ||
b2e1b302 LR |
4876 | return 0; |
4877 | } | |
4878 | ||
4879 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4880 | { | |
b2e1b302 | 4881 | char *data = NULL; |
57b5ce07 | 4882 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4883 | |
80778f18 LR |
4884 | /* |
4885 | * You should only get this when cfg80211 hasn't yet initialized | |
4886 | * completely when built-in to the kernel right between the time | |
4887 | * window between nl80211_init() and regulatory_init(), if that is | |
4888 | * even possible. | |
4889 | */ | |
458f4f9e | 4890 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4891 | return -EINPROGRESS; |
80778f18 | 4892 | |
57b5ce07 LR |
4893 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4894 | user_reg_hint_type = | |
4895 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4896 | else | |
4897 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4898 | ||
4899 | switch (user_reg_hint_type) { | |
4900 | case NL80211_USER_REG_HINT_USER: | |
4901 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
4902 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4903 | return -EINVAL; | |
4904 | ||
4905 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4906 | return regulatory_hint_user(data, user_reg_hint_type); | |
4907 | case NL80211_USER_REG_HINT_INDOOR: | |
4908 | return regulatory_hint_indoor_user(); | |
57b5ce07 LR |
4909 | default: |
4910 | return -EINVAL; | |
4911 | } | |
b2e1b302 LR |
4912 | } |
4913 | ||
24bdd9f4 | 4914 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4915 | struct genl_info *info) |
93da9cc1 | 4916 | { |
4c476991 | 4917 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4918 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4919 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4920 | struct mesh_config cur_params; | |
4921 | int err = 0; | |
93da9cc1 | 4922 | void *hdr; |
4923 | struct nlattr *pinfoattr; | |
4924 | struct sk_buff *msg; | |
4925 | ||
29cbe68c JB |
4926 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4927 | return -EOPNOTSUPP; | |
4928 | ||
24bdd9f4 | 4929 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4930 | return -EOPNOTSUPP; |
f3f92586 | 4931 | |
29cbe68c JB |
4932 | wdev_lock(wdev); |
4933 | /* If not connected, get default parameters */ | |
4934 | if (!wdev->mesh_id_len) | |
4935 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4936 | else | |
e35e4d28 | 4937 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4938 | wdev_unlock(wdev); |
4939 | ||
93da9cc1 | 4940 | if (err) |
4c476991 | 4941 | return err; |
93da9cc1 | 4942 | |
4943 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4944 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4945 | if (!msg) |
4946 | return -ENOMEM; | |
15e47304 | 4947 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4948 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4949 | if (!hdr) |
efe1cf0c | 4950 | goto out; |
24bdd9f4 | 4951 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 4952 | if (!pinfoattr) |
4953 | goto nla_put_failure; | |
9360ffd1 DM |
4954 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4955 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
4956 | cur_params.dot11MeshRetryTimeout) || | |
4957 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
4958 | cur_params.dot11MeshConfirmTimeout) || | |
4959 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
4960 | cur_params.dot11MeshHoldingTimeout) || | |
4961 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
4962 | cur_params.dot11MeshMaxPeerLinks) || | |
4963 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
4964 | cur_params.dot11MeshMaxRetries) || | |
4965 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
4966 | cur_params.dot11MeshTTL) || | |
4967 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
4968 | cur_params.element_ttl) || | |
4969 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
4970 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
4971 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4972 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
4973 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4974 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
4975 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
4976 | cur_params.path_refresh_time) || | |
4977 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
4978 | cur_params.min_discovery_timeout) || | |
4979 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
4980 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
4981 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
4982 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
4983 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
4984 | cur_params.dot11MeshHWMPperrMinInterval) || | |
4985 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
4986 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
4987 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4988 | cur_params.dot11MeshHWMPRootMode) || | |
4989 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
4990 | cur_params.dot11MeshHWMPRannInterval) || | |
4991 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
4992 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
4993 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
4994 | cur_params.dot11MeshForwarding) || | |
4995 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
4996 | cur_params.rssi_threshold) || |
4997 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
4998 | cur_params.ht_opmode) || |
4999 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
5000 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
5001 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
5002 | cur_params.dot11MeshHWMProotInterval) || |
5003 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
5004 | cur_params.dot11MeshHWMPconfirmationInterval) || |
5005 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
5006 | cur_params.power_mode) || | |
5007 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
5008 | cur_params.dot11MeshAwakeWindowDuration) || |
5009 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5010 | cur_params.plink_timeout)) | |
9360ffd1 | 5011 | goto nla_put_failure; |
93da9cc1 | 5012 | nla_nest_end(msg, pinfoattr); |
5013 | genlmsg_end(msg, hdr); | |
4c476991 | 5014 | return genlmsg_reply(msg, info); |
93da9cc1 | 5015 | |
3b85875a | 5016 | nla_put_failure: |
93da9cc1 | 5017 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 5018 | out: |
d080e275 | 5019 | nlmsg_free(msg); |
4c476991 | 5020 | return -ENOBUFS; |
93da9cc1 | 5021 | } |
5022 | ||
b54452b0 | 5023 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 5024 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
5025 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
5026 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
5027 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
5028 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
5029 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 5030 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 5031 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 5032 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 5033 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
5034 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
5035 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
5036 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
5037 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 5038 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 5039 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 5040 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 5041 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 5042 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 5043 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
5044 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
5045 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
5046 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
5047 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 5048 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
5049 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
5050 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 5051 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 5052 | }; |
5053 | ||
c80d545d JC |
5054 | static const struct nla_policy |
5055 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 5056 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
5057 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
5058 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 5059 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 5060 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 5061 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 5062 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 5063 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 5064 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
5065 | }; |
5066 | ||
24bdd9f4 | 5067 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
5068 | struct mesh_config *cfg, |
5069 | u32 *mask_out) | |
93da9cc1 | 5070 | { |
93da9cc1 | 5071 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 5072 | u32 mask = 0; |
93da9cc1 | 5073 | |
ea54fba2 MP |
5074 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
5075 | do { \ | |
5076 | if (tb[attr]) { \ | |
5077 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
5078 | return -EINVAL; \ | |
5079 | cfg->param = fn(tb[attr]); \ | |
5080 | mask |= (1 << (attr - 1)); \ | |
5081 | } \ | |
5082 | } while (0) | |
bd90fdcc JB |
5083 | |
5084 | ||
24bdd9f4 | 5085 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 5086 | return -EINVAL; |
5087 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 5088 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 5089 | nl80211_meshconf_params_policy)) |
93da9cc1 | 5090 | return -EINVAL; |
5091 | ||
93da9cc1 | 5092 | /* This makes sure that there aren't more than 32 mesh config |
5093 | * parameters (otherwise our bitfield scheme would not work.) */ | |
5094 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
5095 | ||
5096 | /* Fill in the params struct */ | |
ea54fba2 | 5097 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
5098 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
5099 | nla_get_u16); | |
ea54fba2 | 5100 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
5101 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
5102 | nla_get_u16); | |
ea54fba2 | 5103 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
5104 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
5105 | nla_get_u16); | |
ea54fba2 | 5106 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
5107 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
5108 | nla_get_u16); | |
ea54fba2 | 5109 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
5110 | mask, NL80211_MESHCONF_MAX_RETRIES, |
5111 | nla_get_u8); | |
ea54fba2 | 5112 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 5113 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 5114 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
5115 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
5116 | nla_get_u8); | |
ea54fba2 | 5117 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
5118 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
5119 | nla_get_u8); | |
ea54fba2 MP |
5120 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
5121 | 1, 255, mask, | |
a4f606ea CYY |
5122 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5123 | nla_get_u32); | |
ea54fba2 | 5124 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
5125 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5126 | nla_get_u8); | |
ea54fba2 | 5127 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
5128 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
5129 | nla_get_u32); | |
ea54fba2 | 5130 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
5131 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
5132 | nla_get_u16); | |
ea54fba2 MP |
5133 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
5134 | 1, 65535, mask, | |
a4f606ea CYY |
5135 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
5136 | nla_get_u32); | |
93da9cc1 | 5137 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
5138 | 1, 65535, mask, |
5139 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 5140 | nla_get_u16); |
dca7e943 | 5141 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
5142 | 1, 65535, mask, |
5143 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 5144 | nla_get_u16); |
93da9cc1 | 5145 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5146 | dot11MeshHWMPnetDiameterTraversalTime, |
5147 | 1, 65535, mask, | |
a4f606ea CYY |
5148 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
5149 | nla_get_u16); | |
ea54fba2 MP |
5150 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
5151 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5152 | nla_get_u8); | |
5153 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
5154 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 5155 | nla_get_u16); |
63c5723b | 5156 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5157 | dot11MeshGateAnnouncementProtocol, 0, 1, |
5158 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 5159 | nla_get_u8); |
ea54fba2 | 5160 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
5161 | mask, NL80211_MESHCONF_FORWARDING, |
5162 | nla_get_u8); | |
83374fe9 | 5163 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 5164 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
83374fe9 | 5165 | nla_get_s32); |
ea54fba2 | 5166 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 5167 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
5168 | nla_get_u16); |
5169 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 5170 | 1, 65535, mask, |
ac1073a6 CYY |
5171 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
5172 | nla_get_u32); | |
ea54fba2 | 5173 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 5174 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
5175 | nla_get_u16); |
5176 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
5177 | dot11MeshHWMPconfirmationInterval, |
5178 | 1, 65535, mask, | |
728b19e5 | 5179 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 5180 | nla_get_u16); |
3b1c5a53 MP |
5181 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
5182 | NL80211_MESH_POWER_ACTIVE, | |
5183 | NL80211_MESH_POWER_MAX, | |
5184 | mask, NL80211_MESHCONF_POWER_MODE, | |
5185 | nla_get_u32); | |
5186 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
5187 | 0, 65535, mask, | |
5188 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
8e7c0538 CT |
5189 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
5190 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5191 | nla_get_u32); | |
bd90fdcc JB |
5192 | if (mask_out) |
5193 | *mask_out = mask; | |
c80d545d | 5194 | |
bd90fdcc JB |
5195 | return 0; |
5196 | ||
5197 | #undef FILL_IN_MESH_PARAM_IF_SET | |
5198 | } | |
5199 | ||
c80d545d JC |
5200 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
5201 | struct mesh_setup *setup) | |
5202 | { | |
bb2798d4 | 5203 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
5204 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
5205 | ||
5206 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
5207 | return -EINVAL; | |
5208 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
5209 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
5210 | nl80211_mesh_setup_params_policy)) | |
5211 | return -EINVAL; | |
5212 | ||
d299a1f2 JC |
5213 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
5214 | setup->sync_method = | |
5215 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
5216 | IEEE80211_SYNC_METHOD_VENDOR : | |
5217 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
5218 | ||
c80d545d JC |
5219 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
5220 | setup->path_sel_proto = | |
5221 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5222 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5223 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5224 | ||
5225 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5226 | setup->path_metric = | |
5227 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5228 | IEEE80211_PATH_METRIC_VENDOR : | |
5229 | IEEE80211_PATH_METRIC_AIRTIME; | |
5230 | ||
581a8b0f JC |
5231 | |
5232 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 5233 | struct nlattr *ieattr = |
581a8b0f | 5234 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5235 | if (!is_valid_ie_attr(ieattr)) |
5236 | return -EINVAL; | |
581a8b0f JC |
5237 | setup->ie = nla_data(ieattr); |
5238 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5239 | } |
bb2798d4 TP |
5240 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5241 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5242 | return -EINVAL; | |
5243 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5244 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5245 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5246 | if (setup->is_secure) |
5247 | setup->user_mpm = true; | |
c80d545d | 5248 | |
6e16d90b CT |
5249 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5250 | if (!setup->user_mpm) | |
5251 | return -EINVAL; | |
5252 | setup->auth_id = | |
5253 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5254 | } | |
5255 | ||
c80d545d JC |
5256 | return 0; |
5257 | } | |
5258 | ||
24bdd9f4 | 5259 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5260 | struct genl_info *info) |
bd90fdcc JB |
5261 | { |
5262 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5263 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5264 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5265 | struct mesh_config cfg; |
5266 | u32 mask; | |
5267 | int err; | |
5268 | ||
29cbe68c JB |
5269 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5270 | return -EOPNOTSUPP; | |
5271 | ||
24bdd9f4 | 5272 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5273 | return -EOPNOTSUPP; |
5274 | ||
24bdd9f4 | 5275 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5276 | if (err) |
5277 | return err; | |
5278 | ||
29cbe68c JB |
5279 | wdev_lock(wdev); |
5280 | if (!wdev->mesh_id_len) | |
5281 | err = -ENOLINK; | |
5282 | ||
5283 | if (!err) | |
e35e4d28 | 5284 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5285 | |
5286 | wdev_unlock(wdev); | |
5287 | ||
5288 | return err; | |
93da9cc1 | 5289 | } |
5290 | ||
f130347c LR |
5291 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
5292 | { | |
458f4f9e | 5293 | const struct ieee80211_regdomain *regdom; |
f130347c LR |
5294 | struct sk_buff *msg; |
5295 | void *hdr = NULL; | |
5296 | struct nlattr *nl_reg_rules; | |
5297 | unsigned int i; | |
f130347c LR |
5298 | |
5299 | if (!cfg80211_regdomain) | |
5fe231e8 | 5300 | return -EINVAL; |
f130347c | 5301 | |
fd2120ca | 5302 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
5fe231e8 JB |
5303 | if (!msg) |
5304 | return -ENOBUFS; | |
f130347c | 5305 | |
15e47304 | 5306 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
f130347c LR |
5307 | NL80211_CMD_GET_REG); |
5308 | if (!hdr) | |
efe1cf0c | 5309 | goto put_failure; |
f130347c | 5310 | |
57b5ce07 LR |
5311 | if (reg_last_request_cell_base() && |
5312 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5313 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5314 | goto nla_put_failure; | |
5315 | ||
458f4f9e JB |
5316 | rcu_read_lock(); |
5317 | regdom = rcu_dereference(cfg80211_regdomain); | |
5318 | ||
5319 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | |
5320 | (regdom->dfs_region && | |
5321 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
5322 | goto nla_put_failure_rcu; | |
5323 | ||
f130347c LR |
5324 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5325 | if (!nl_reg_rules) | |
458f4f9e | 5326 | goto nla_put_failure_rcu; |
f130347c | 5327 | |
458f4f9e | 5328 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5329 | struct nlattr *nl_reg_rule; |
5330 | const struct ieee80211_reg_rule *reg_rule; | |
5331 | const struct ieee80211_freq_range *freq_range; | |
5332 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 5333 | unsigned int max_bandwidth_khz; |
f130347c | 5334 | |
458f4f9e | 5335 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5336 | freq_range = ®_rule->freq_range; |
5337 | power_rule = ®_rule->power_rule; | |
5338 | ||
5339 | nl_reg_rule = nla_nest_start(msg, i); | |
5340 | if (!nl_reg_rule) | |
458f4f9e | 5341 | goto nla_put_failure_rcu; |
f130347c | 5342 | |
97524820 JD |
5343 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
5344 | if (!max_bandwidth_khz) | |
5345 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
5346 | reg_rule); | |
5347 | ||
9360ffd1 DM |
5348 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5349 | reg_rule->flags) || | |
5350 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5351 | freq_range->start_freq_khz) || | |
5352 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5353 | freq_range->end_freq_khz) || | |
5354 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 5355 | max_bandwidth_khz) || |
9360ffd1 DM |
5356 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
5357 | power_rule->max_antenna_gain) || | |
5358 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
5359 | power_rule->max_eirp) || |
5360 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
5361 | reg_rule->dfs_cac_ms)) | |
458f4f9e | 5362 | goto nla_put_failure_rcu; |
f130347c LR |
5363 | |
5364 | nla_nest_end(msg, nl_reg_rule); | |
5365 | } | |
458f4f9e | 5366 | rcu_read_unlock(); |
f130347c LR |
5367 | |
5368 | nla_nest_end(msg, nl_reg_rules); | |
5369 | ||
5370 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5371 | return genlmsg_reply(msg, info); |
f130347c | 5372 | |
458f4f9e JB |
5373 | nla_put_failure_rcu: |
5374 | rcu_read_unlock(); | |
f130347c LR |
5375 | nla_put_failure: |
5376 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5377 | put_failure: |
d080e275 | 5378 | nlmsg_free(msg); |
5fe231e8 | 5379 | return -EMSGSIZE; |
f130347c LR |
5380 | } |
5381 | ||
b2e1b302 LR |
5382 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5383 | { | |
5384 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5385 | struct nlattr *nl_reg_rule; | |
5386 | char *alpha2 = NULL; | |
5387 | int rem_reg_rules = 0, r = 0; | |
5388 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
4c7d3982 | 5389 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
b2e1b302 LR |
5390 | struct ieee80211_regdomain *rd = NULL; |
5391 | ||
5392 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5393 | return -EINVAL; | |
5394 | ||
5395 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5396 | return -EINVAL; | |
5397 | ||
5398 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5399 | ||
8b60b078 LR |
5400 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5401 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5402 | ||
b2e1b302 | 5403 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5404 | rem_reg_rules) { |
b2e1b302 LR |
5405 | num_rules++; |
5406 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5407 | return -EINVAL; |
b2e1b302 LR |
5408 | } |
5409 | ||
e438768f LR |
5410 | if (!reg_is_valid_request(alpha2)) |
5411 | return -EINVAL; | |
5412 | ||
b2e1b302 | 5413 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5414 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5415 | |
5416 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5417 | if (!rd) |
5418 | return -ENOMEM; | |
b2e1b302 LR |
5419 | |
5420 | rd->n_reg_rules = num_rules; | |
5421 | rd->alpha2[0] = alpha2[0]; | |
5422 | rd->alpha2[1] = alpha2[1]; | |
5423 | ||
8b60b078 LR |
5424 | /* |
5425 | * Disable DFS master mode if the DFS region was | |
5426 | * not supported or known on this kernel. | |
5427 | */ | |
5428 | if (reg_supported_dfs_region(dfs_region)) | |
5429 | rd->dfs_region = dfs_region; | |
5430 | ||
b2e1b302 | 5431 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5432 | rem_reg_rules) { |
ae811e21 JB |
5433 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
5434 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
5435 | reg_rule_policy); | |
5436 | if (r) | |
5437 | goto bad_reg; | |
b2e1b302 LR |
5438 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5439 | if (r) | |
5440 | goto bad_reg; | |
5441 | ||
5442 | rule_idx++; | |
5443 | ||
d0e18f83 LR |
5444 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5445 | r = -EINVAL; | |
b2e1b302 | 5446 | goto bad_reg; |
d0e18f83 | 5447 | } |
b2e1b302 LR |
5448 | } |
5449 | ||
b2e1b302 | 5450 | r = set_regdom(rd); |
6913b49a | 5451 | /* set_regdom took ownership */ |
1a919318 | 5452 | rd = NULL; |
b2e1b302 | 5453 | |
d2372b31 | 5454 | bad_reg: |
b2e1b302 | 5455 | kfree(rd); |
d0e18f83 | 5456 | return r; |
b2e1b302 LR |
5457 | } |
5458 | ||
83f5e2cf JB |
5459 | static int validate_scan_freqs(struct nlattr *freqs) |
5460 | { | |
5461 | struct nlattr *attr1, *attr2; | |
5462 | int n_channels = 0, tmp1, tmp2; | |
5463 | ||
5464 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5465 | n_channels++; | |
5466 | /* | |
5467 | * Some hardware has a limited channel list for | |
5468 | * scanning, and it is pretty much nonsensical | |
5469 | * to scan for a channel twice, so disallow that | |
5470 | * and don't require drivers to check that the | |
5471 | * channel list they get isn't longer than what | |
5472 | * they can scan, as long as they can scan all | |
5473 | * the channels they registered at once. | |
5474 | */ | |
5475 | nla_for_each_nested(attr2, freqs, tmp2) | |
5476 | if (attr1 != attr2 && | |
5477 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5478 | return 0; | |
5479 | } | |
5480 | ||
5481 | return n_channels; | |
5482 | } | |
5483 | ||
2a519311 JB |
5484 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5485 | { | |
4c476991 | 5486 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5487 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5488 | struct cfg80211_scan_request *request; |
2a519311 JB |
5489 | struct nlattr *attr; |
5490 | struct wiphy *wiphy; | |
83f5e2cf | 5491 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5492 | size_t ie_len; |
2a519311 | 5493 | |
f4a11bb0 JB |
5494 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5495 | return -EINVAL; | |
5496 | ||
79c97e97 | 5497 | wiphy = &rdev->wiphy; |
2a519311 | 5498 | |
4c476991 JB |
5499 | if (!rdev->ops->scan) |
5500 | return -EOPNOTSUPP; | |
2a519311 | 5501 | |
f9d15d16 | 5502 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
5503 | err = -EBUSY; |
5504 | goto unlock; | |
5505 | } | |
2a519311 JB |
5506 | |
5507 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5508 | n_channels = validate_scan_freqs( |
5509 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5510 | if (!n_channels) { |
5511 | err = -EINVAL; | |
5512 | goto unlock; | |
5513 | } | |
2a519311 | 5514 | } else { |
bdfbec2d | 5515 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
5516 | } |
5517 | ||
5518 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5519 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5520 | n_ssids++; | |
5521 | ||
f9f47529 JB |
5522 | if (n_ssids > wiphy->max_scan_ssids) { |
5523 | err = -EINVAL; | |
5524 | goto unlock; | |
5525 | } | |
2a519311 | 5526 | |
70692ad2 JM |
5527 | if (info->attrs[NL80211_ATTR_IE]) |
5528 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5529 | else | |
5530 | ie_len = 0; | |
5531 | ||
f9f47529 JB |
5532 | if (ie_len > wiphy->max_scan_ie_len) { |
5533 | err = -EINVAL; | |
5534 | goto unlock; | |
5535 | } | |
18a83659 | 5536 | |
2a519311 | 5537 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5538 | + sizeof(*request->ssids) * n_ssids |
5539 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5540 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5541 | if (!request) { |
5542 | err = -ENOMEM; | |
5543 | goto unlock; | |
5544 | } | |
2a519311 | 5545 | |
2a519311 | 5546 | if (n_ssids) |
5ba63533 | 5547 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5548 | request->n_ssids = n_ssids; |
70692ad2 JM |
5549 | if (ie_len) { |
5550 | if (request->ssids) | |
5551 | request->ie = (void *)(request->ssids + n_ssids); | |
5552 | else | |
5553 | request->ie = (void *)(request->channels + n_channels); | |
5554 | } | |
2a519311 | 5555 | |
584991dc | 5556 | i = 0; |
2a519311 JB |
5557 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5558 | /* user specified, bail out if channel not found */ | |
2a519311 | 5559 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5560 | struct ieee80211_channel *chan; |
5561 | ||
5562 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5563 | ||
5564 | if (!chan) { | |
2a519311 JB |
5565 | err = -EINVAL; |
5566 | goto out_free; | |
5567 | } | |
584991dc JB |
5568 | |
5569 | /* ignore disabled channels */ | |
5570 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5571 | continue; | |
5572 | ||
5573 | request->channels[i] = chan; | |
2a519311 JB |
5574 | i++; |
5575 | } | |
5576 | } else { | |
34850ab2 JB |
5577 | enum ieee80211_band band; |
5578 | ||
2a519311 | 5579 | /* all channels */ |
2a519311 JB |
5580 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5581 | int j; | |
5582 | if (!wiphy->bands[band]) | |
5583 | continue; | |
5584 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5585 | struct ieee80211_channel *chan; |
5586 | ||
5587 | chan = &wiphy->bands[band]->channels[j]; | |
5588 | ||
5589 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5590 | continue; | |
5591 | ||
5592 | request->channels[i] = chan; | |
2a519311 JB |
5593 | i++; |
5594 | } | |
5595 | } | |
5596 | } | |
5597 | ||
584991dc JB |
5598 | if (!i) { |
5599 | err = -EINVAL; | |
5600 | goto out_free; | |
5601 | } | |
5602 | ||
5603 | request->n_channels = i; | |
5604 | ||
2a519311 JB |
5605 | i = 0; |
5606 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5607 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5608 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5609 | err = -EINVAL; |
5610 | goto out_free; | |
5611 | } | |
57a27e1d | 5612 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5613 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5614 | i++; |
5615 | } | |
5616 | } | |
5617 | ||
70692ad2 JM |
5618 | if (info->attrs[NL80211_ATTR_IE]) { |
5619 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5620 | memcpy((void *)request->ie, |
5621 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5622 | request->ie_len); |
5623 | } | |
5624 | ||
34850ab2 | 5625 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5626 | if (wiphy->bands[i]) |
5627 | request->rates[i] = | |
5628 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5629 | |
5630 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5631 | nla_for_each_nested(attr, | |
5632 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5633 | tmp) { | |
5634 | enum ieee80211_band band = nla_type(attr); | |
5635 | ||
84404623 | 5636 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5637 | err = -EINVAL; |
5638 | goto out_free; | |
5639 | } | |
1b09cd82 FF |
5640 | |
5641 | if (!wiphy->bands[band]) | |
5642 | continue; | |
5643 | ||
34850ab2 JB |
5644 | err = ieee80211_get_ratemask(wiphy->bands[band], |
5645 | nla_data(attr), | |
5646 | nla_len(attr), | |
5647 | &request->rates[band]); | |
5648 | if (err) | |
5649 | goto out_free; | |
5650 | } | |
5651 | } | |
5652 | ||
46856bbf | 5653 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5654 | request->flags = nla_get_u32( |
5655 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5656 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5657 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5658 | err = -EOPNOTSUPP; |
5659 | goto out_free; | |
5660 | } | |
5661 | } | |
ed473771 | 5662 | |
e9f935e3 RM |
5663 | request->no_cck = |
5664 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5665 | ||
fd014284 | 5666 | request->wdev = wdev; |
79c97e97 | 5667 | request->wiphy = &rdev->wiphy; |
15d6030b | 5668 | request->scan_start = jiffies; |
2a519311 | 5669 | |
79c97e97 | 5670 | rdev->scan_req = request; |
e35e4d28 | 5671 | err = rdev_scan(rdev, request); |
2a519311 | 5672 | |
463d0183 | 5673 | if (!err) { |
fd014284 JB |
5674 | nl80211_send_scan_start(rdev, wdev); |
5675 | if (wdev->netdev) | |
5676 | dev_hold(wdev->netdev); | |
4c476991 | 5677 | } else { |
2a519311 | 5678 | out_free: |
79c97e97 | 5679 | rdev->scan_req = NULL; |
2a519311 JB |
5680 | kfree(request); |
5681 | } | |
3b85875a | 5682 | |
f9f47529 | 5683 | unlock: |
2a519311 JB |
5684 | return err; |
5685 | } | |
5686 | ||
256da02d LC |
5687 | static struct cfg80211_sched_scan_request * |
5688 | nl80211_parse_sched_scan(struct wiphy *wiphy, | |
5689 | struct nlattr **attrs) | |
807f8a8c LC |
5690 | { |
5691 | struct cfg80211_sched_scan_request *request; | |
807f8a8c | 5692 | struct nlattr *attr; |
a1f1c21c | 5693 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5694 | u32 interval; |
807f8a8c LC |
5695 | enum ieee80211_band band; |
5696 | size_t ie_len; | |
a1f1c21c | 5697 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 5698 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c | 5699 | |
256da02d LC |
5700 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
5701 | return ERR_PTR(-EINVAL); | |
807f8a8c | 5702 | |
256da02d LC |
5703 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5704 | return ERR_PTR(-EINVAL); | |
bbe6ad6d | 5705 | |
256da02d | 5706 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
bbe6ad6d | 5707 | if (interval == 0) |
256da02d | 5708 | return ERR_PTR(-EINVAL); |
807f8a8c | 5709 | |
256da02d | 5710 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c | 5711 | n_channels = validate_scan_freqs( |
256da02d | 5712 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
807f8a8c | 5713 | if (!n_channels) |
256da02d | 5714 | return ERR_PTR(-EINVAL); |
807f8a8c | 5715 | } else { |
bdfbec2d | 5716 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
5717 | } |
5718 | ||
256da02d LC |
5719 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
5720 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c LC |
5721 | tmp) |
5722 | n_ssids++; | |
5723 | ||
93b6aa69 | 5724 | if (n_ssids > wiphy->max_sched_scan_ssids) |
256da02d | 5725 | return ERR_PTR(-EINVAL); |
807f8a8c | 5726 | |
ea73cbce JB |
5727 | /* |
5728 | * First, count the number of 'real' matchsets. Due to an issue with | |
5729 | * the old implementation, matchsets containing only the RSSI attribute | |
5730 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
5731 | * RSSI for all matchsets, rather than their own matchset for reporting | |
5732 | * all APs with a strong RSSI. This is needed to be compatible with | |
5733 | * older userspace that treated a matchset with only the RSSI as the | |
5734 | * global RSSI for all other matchsets - if there are other matchsets. | |
5735 | */ | |
256da02d | 5736 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 5737 | nla_for_each_nested(attr, |
256da02d | 5738 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
ea73cbce JB |
5739 | tmp) { |
5740 | struct nlattr *rssi; | |
5741 | ||
5742 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5743 | nla_data(attr), nla_len(attr), | |
5744 | nl80211_match_policy); | |
5745 | if (err) | |
256da02d | 5746 | return ERR_PTR(err); |
ea73cbce JB |
5747 | /* add other standalone attributes here */ |
5748 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | |
5749 | n_match_sets++; | |
5750 | continue; | |
5751 | } | |
5752 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
5753 | if (rssi) | |
5754 | default_match_rssi = nla_get_s32(rssi); | |
5755 | } | |
5756 | } | |
5757 | ||
5758 | /* However, if there's no other matchset, add the RSSI one */ | |
5759 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
5760 | n_match_sets = 1; | |
a1f1c21c LC |
5761 | |
5762 | if (n_match_sets > wiphy->max_match_sets) | |
256da02d | 5763 | return ERR_PTR(-EINVAL); |
a1f1c21c | 5764 | |
256da02d LC |
5765 | if (attrs[NL80211_ATTR_IE]) |
5766 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); | |
807f8a8c LC |
5767 | else |
5768 | ie_len = 0; | |
5769 | ||
5a865bad | 5770 | if (ie_len > wiphy->max_sched_scan_ie_len) |
256da02d | 5771 | return ERR_PTR(-EINVAL); |
c10841ca | 5772 | |
807f8a8c | 5773 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 5774 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 5775 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 5776 | + sizeof(*request->channels) * n_channels |
807f8a8c | 5777 | + ie_len, GFP_KERNEL); |
256da02d LC |
5778 | if (!request) |
5779 | return ERR_PTR(-ENOMEM); | |
807f8a8c LC |
5780 | |
5781 | if (n_ssids) | |
5782 | request->ssids = (void *)&request->channels[n_channels]; | |
5783 | request->n_ssids = n_ssids; | |
5784 | if (ie_len) { | |
5785 | if (request->ssids) | |
5786 | request->ie = (void *)(request->ssids + n_ssids); | |
5787 | else | |
5788 | request->ie = (void *)(request->channels + n_channels); | |
5789 | } | |
5790 | ||
a1f1c21c LC |
5791 | if (n_match_sets) { |
5792 | if (request->ie) | |
5793 | request->match_sets = (void *)(request->ie + ie_len); | |
5794 | else if (request->ssids) | |
5795 | request->match_sets = | |
5796 | (void *)(request->ssids + n_ssids); | |
5797 | else | |
5798 | request->match_sets = | |
5799 | (void *)(request->channels + n_channels); | |
5800 | } | |
5801 | request->n_match_sets = n_match_sets; | |
5802 | ||
807f8a8c | 5803 | i = 0; |
256da02d | 5804 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c LC |
5805 | /* user specified, bail out if channel not found */ |
5806 | nla_for_each_nested(attr, | |
256da02d | 5807 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
807f8a8c LC |
5808 | tmp) { |
5809 | struct ieee80211_channel *chan; | |
5810 | ||
5811 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5812 | ||
5813 | if (!chan) { | |
5814 | err = -EINVAL; | |
5815 | goto out_free; | |
5816 | } | |
5817 | ||
5818 | /* ignore disabled channels */ | |
5819 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5820 | continue; | |
5821 | ||
5822 | request->channels[i] = chan; | |
5823 | i++; | |
5824 | } | |
5825 | } else { | |
5826 | /* all channels */ | |
5827 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5828 | int j; | |
5829 | if (!wiphy->bands[band]) | |
5830 | continue; | |
5831 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
5832 | struct ieee80211_channel *chan; | |
5833 | ||
5834 | chan = &wiphy->bands[band]->channels[j]; | |
5835 | ||
5836 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5837 | continue; | |
5838 | ||
5839 | request->channels[i] = chan; | |
5840 | i++; | |
5841 | } | |
5842 | } | |
5843 | } | |
5844 | ||
5845 | if (!i) { | |
5846 | err = -EINVAL; | |
5847 | goto out_free; | |
5848 | } | |
5849 | ||
5850 | request->n_channels = i; | |
5851 | ||
5852 | i = 0; | |
256da02d LC |
5853 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) { |
5854 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c | 5855 | tmp) { |
57a27e1d | 5856 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
5857 | err = -EINVAL; |
5858 | goto out_free; | |
5859 | } | |
57a27e1d | 5860 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
5861 | memcpy(request->ssids[i].ssid, nla_data(attr), |
5862 | nla_len(attr)); | |
807f8a8c LC |
5863 | i++; |
5864 | } | |
5865 | } | |
5866 | ||
a1f1c21c | 5867 | i = 0; |
256da02d | 5868 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 5869 | nla_for_each_nested(attr, |
256da02d | 5870 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
a1f1c21c | 5871 | tmp) { |
88e920b4 | 5872 | struct nlattr *ssid, *rssi; |
a1f1c21c | 5873 | |
ae811e21 JB |
5874 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
5875 | nla_data(attr), nla_len(attr), | |
5876 | nl80211_match_policy); | |
5877 | if (err) | |
5878 | goto out_free; | |
4a4ab0d7 | 5879 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 5880 | if (ssid) { |
ea73cbce JB |
5881 | if (WARN_ON(i >= n_match_sets)) { |
5882 | /* this indicates a programming error, | |
5883 | * the loop above should have verified | |
5884 | * things properly | |
5885 | */ | |
5886 | err = -EINVAL; | |
5887 | goto out_free; | |
5888 | } | |
5889 | ||
a1f1c21c LC |
5890 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
5891 | err = -EINVAL; | |
5892 | goto out_free; | |
5893 | } | |
5894 | memcpy(request->match_sets[i].ssid.ssid, | |
5895 | nla_data(ssid), nla_len(ssid)); | |
5896 | request->match_sets[i].ssid.ssid_len = | |
5897 | nla_len(ssid); | |
ea73cbce JB |
5898 | /* special attribute - old implemenation w/a */ |
5899 | request->match_sets[i].rssi_thold = | |
5900 | default_match_rssi; | |
5901 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
5902 | if (rssi) | |
5903 | request->match_sets[i].rssi_thold = | |
5904 | nla_get_s32(rssi); | |
a1f1c21c LC |
5905 | } |
5906 | i++; | |
5907 | } | |
ea73cbce JB |
5908 | |
5909 | /* there was no other matchset, so the RSSI one is alone */ | |
5910 | if (i == 0) | |
5911 | request->match_sets[0].rssi_thold = default_match_rssi; | |
5912 | ||
5913 | request->min_rssi_thold = INT_MAX; | |
5914 | for (i = 0; i < n_match_sets; i++) | |
5915 | request->min_rssi_thold = | |
5916 | min(request->match_sets[i].rssi_thold, | |
5917 | request->min_rssi_thold); | |
5918 | } else { | |
5919 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
5920 | } |
5921 | ||
9900e484 JB |
5922 | if (ie_len) { |
5923 | request->ie_len = ie_len; | |
807f8a8c | 5924 | memcpy((void *)request->ie, |
256da02d | 5925 | nla_data(attrs[NL80211_ATTR_IE]), |
807f8a8c LC |
5926 | request->ie_len); |
5927 | } | |
5928 | ||
256da02d | 5929 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 | 5930 | request->flags = nla_get_u32( |
256da02d | 5931 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
00c3a6ed JB |
5932 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5933 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5934 | err = -EOPNOTSUPP; |
5935 | goto out_free; | |
5936 | } | |
5937 | } | |
ed473771 | 5938 | |
bbe6ad6d | 5939 | request->interval = interval; |
15d6030b | 5940 | request->scan_start = jiffies; |
807f8a8c | 5941 | |
256da02d | 5942 | return request; |
807f8a8c LC |
5943 | |
5944 | out_free: | |
5945 | kfree(request); | |
256da02d LC |
5946 | return ERR_PTR(err); |
5947 | } | |
5948 | ||
5949 | static int nl80211_start_sched_scan(struct sk_buff *skb, | |
5950 | struct genl_info *info) | |
5951 | { | |
5952 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5953 | struct net_device *dev = info->user_ptr[1]; | |
5954 | int err; | |
5955 | ||
5956 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5957 | !rdev->ops->sched_scan_start) | |
5958 | return -EOPNOTSUPP; | |
5959 | ||
5960 | if (rdev->sched_scan_req) | |
5961 | return -EINPROGRESS; | |
5962 | ||
5963 | rdev->sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, | |
5964 | info->attrs); | |
5965 | err = PTR_ERR_OR_ZERO(rdev->sched_scan_req); | |
5966 | if (err) | |
5967 | goto out_err; | |
5968 | ||
5969 | err = rdev_sched_scan_start(rdev, dev, rdev->sched_scan_req); | |
5970 | if (err) | |
5971 | goto out_free; | |
5972 | ||
5973 | rdev->sched_scan_req->dev = dev; | |
5974 | rdev->sched_scan_req->wiphy = &rdev->wiphy; | |
5975 | ||
5976 | nl80211_send_sched_scan(rdev, dev, | |
5977 | NL80211_CMD_START_SCHED_SCAN); | |
5978 | return 0; | |
5979 | ||
5980 | out_free: | |
5981 | kfree(rdev->sched_scan_req); | |
5982 | out_err: | |
5983 | rdev->sched_scan_req = NULL; | |
807f8a8c LC |
5984 | return err; |
5985 | } | |
5986 | ||
5987 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
5988 | struct genl_info *info) | |
5989 | { | |
5990 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5991 | ||
5992 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5993 | !rdev->ops->sched_scan_stop) | |
5994 | return -EOPNOTSUPP; | |
5995 | ||
5fe231e8 | 5996 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
5997 | } |
5998 | ||
04f39047 SW |
5999 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
6000 | struct genl_info *info) | |
6001 | { | |
6002 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6003 | struct net_device *dev = info->user_ptr[1]; | |
6004 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6005 | struct cfg80211_chan_def chandef; | |
55f7435c | 6006 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 6007 | unsigned int cac_time_ms; |
04f39047 SW |
6008 | int err; |
6009 | ||
55f7435c LR |
6010 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
6011 | if (dfs_region == NL80211_DFS_UNSET) | |
6012 | return -EINVAL; | |
6013 | ||
04f39047 SW |
6014 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6015 | if (err) | |
6016 | return err; | |
6017 | ||
ff311bc1 SW |
6018 | if (netif_carrier_ok(dev)) |
6019 | return -EBUSY; | |
6020 | ||
04f39047 SW |
6021 | if (wdev->cac_started) |
6022 | return -EBUSY; | |
6023 | ||
2beb6dab | 6024 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
00ec75fc | 6025 | wdev->iftype); |
04f39047 SW |
6026 | if (err < 0) |
6027 | return err; | |
6028 | ||
6029 | if (err == 0) | |
6030 | return -EINVAL; | |
6031 | ||
fe7c3a1f | 6032 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
6033 | return -EINVAL; |
6034 | ||
6035 | if (!rdev->ops->start_radar_detection) | |
6036 | return -EOPNOTSUPP; | |
6037 | ||
31559f35 JD |
6038 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
6039 | if (WARN_ON(!cac_time_ms)) | |
6040 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
6041 | ||
6042 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, | |
6043 | cac_time_ms); | |
04f39047 | 6044 | if (!err) { |
9e0e2961 | 6045 | wdev->chandef = chandef; |
04f39047 SW |
6046 | wdev->cac_started = true; |
6047 | wdev->cac_start_time = jiffies; | |
31559f35 | 6048 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 6049 | } |
04f39047 SW |
6050 | return err; |
6051 | } | |
6052 | ||
16ef1fe2 SW |
6053 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
6054 | { | |
6055 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6056 | struct net_device *dev = info->user_ptr[1]; | |
6057 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6058 | struct cfg80211_csa_settings params; | |
6059 | /* csa_attrs is defined static to avoid waste of stack size - this | |
6060 | * function is called under RTNL lock, so this should not be a problem. | |
6061 | */ | |
6062 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
16ef1fe2 | 6063 | int err; |
ee4bc9e7 | 6064 | bool need_new_beacon = false; |
9a774c78 | 6065 | int len, i; |
252e07ca | 6066 | u32 cs_count; |
16ef1fe2 SW |
6067 | |
6068 | if (!rdev->ops->channel_switch || | |
6069 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
6070 | return -EOPNOTSUPP; | |
6071 | ||
ee4bc9e7 SW |
6072 | switch (dev->ieee80211_ptr->iftype) { |
6073 | case NL80211_IFTYPE_AP: | |
6074 | case NL80211_IFTYPE_P2P_GO: | |
6075 | need_new_beacon = true; | |
6076 | ||
6077 | /* useless if AP is not running */ | |
6078 | if (!wdev->beacon_interval) | |
1ff79dfa | 6079 | return -ENOTCONN; |
ee4bc9e7 SW |
6080 | break; |
6081 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
6082 | if (!wdev->ssid_len) |
6083 | return -ENOTCONN; | |
6084 | break; | |
c6da674a | 6085 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
6086 | if (!wdev->mesh_id_len) |
6087 | return -ENOTCONN; | |
ee4bc9e7 SW |
6088 | break; |
6089 | default: | |
16ef1fe2 | 6090 | return -EOPNOTSUPP; |
ee4bc9e7 | 6091 | } |
16ef1fe2 SW |
6092 | |
6093 | memset(¶ms, 0, sizeof(params)); | |
6094 | ||
6095 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6096 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
6097 | return -EINVAL; | |
6098 | ||
6099 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 6100 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
6101 | return -EINVAL; |
6102 | ||
252e07ca LC |
6103 | /* Even though the attribute is u32, the specification says |
6104 | * u8, so let's make sure we don't overflow. | |
6105 | */ | |
6106 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
6107 | if (cs_count > 255) | |
6108 | return -EINVAL; | |
6109 | ||
6110 | params.count = cs_count; | |
16ef1fe2 | 6111 | |
ee4bc9e7 SW |
6112 | if (!need_new_beacon) |
6113 | goto skip_beacons; | |
6114 | ||
16ef1fe2 SW |
6115 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
6116 | if (err) | |
6117 | return err; | |
6118 | ||
6119 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
6120 | info->attrs[NL80211_ATTR_CSA_IES], | |
6121 | nl80211_policy); | |
6122 | if (err) | |
6123 | return err; | |
6124 | ||
6125 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
6126 | if (err) | |
6127 | return err; | |
6128 | ||
6129 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
6130 | return -EINVAL; | |
6131 | ||
9a774c78 AO |
6132 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
6133 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6134 | return -EINVAL; |
6135 | ||
9a774c78 AO |
6136 | params.n_counter_offsets_beacon = len / sizeof(u16); |
6137 | if (rdev->wiphy.max_num_csa_counters && | |
6138 | (params.n_counter_offsets_beacon > | |
6139 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
6140 | return -EINVAL; |
6141 | ||
9a774c78 AO |
6142 | params.counter_offsets_beacon = |
6143 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
6144 | ||
6145 | /* sanity checks - counters should fit and be the same */ | |
6146 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
6147 | u16 offset = params.counter_offsets_beacon[i]; | |
6148 | ||
6149 | if (offset >= params.beacon_csa.tail_len) | |
6150 | return -EINVAL; | |
6151 | ||
6152 | if (params.beacon_csa.tail[offset] != params.count) | |
6153 | return -EINVAL; | |
6154 | } | |
6155 | ||
16ef1fe2 | 6156 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
6157 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
6158 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6159 | return -EINVAL; |
6160 | ||
9a774c78 AO |
6161 | params.n_counter_offsets_presp = len / sizeof(u16); |
6162 | if (rdev->wiphy.max_num_csa_counters && | |
6163 | (params.n_counter_offsets_beacon > | |
6164 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 | 6165 | return -EINVAL; |
9a774c78 AO |
6166 | |
6167 | params.counter_offsets_presp = | |
6168 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
6169 | ||
6170 | /* sanity checks - counters should fit and be the same */ | |
6171 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
6172 | u16 offset = params.counter_offsets_presp[i]; | |
6173 | ||
6174 | if (offset >= params.beacon_csa.probe_resp_len) | |
6175 | return -EINVAL; | |
6176 | ||
6177 | if (params.beacon_csa.probe_resp[offset] != | |
6178 | params.count) | |
6179 | return -EINVAL; | |
6180 | } | |
16ef1fe2 SW |
6181 | } |
6182 | ||
ee4bc9e7 | 6183 | skip_beacons: |
16ef1fe2 SW |
6184 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
6185 | if (err) | |
6186 | return err; | |
6187 | ||
174e0cd2 IP |
6188 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
6189 | wdev->iftype)) | |
16ef1fe2 SW |
6190 | return -EINVAL; |
6191 | ||
2beb6dab LC |
6192 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
6193 | ¶ms.chandef, | |
6194 | wdev->iftype); | |
6195 | if (err < 0) | |
6196 | return err; | |
6197 | ||
dcc6c2f5 | 6198 | if (err > 0) |
2beb6dab | 6199 | params.radar_required = true; |
16ef1fe2 | 6200 | |
16ef1fe2 SW |
6201 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
6202 | params.block_tx = true; | |
6203 | ||
c56589ed SW |
6204 | wdev_lock(wdev); |
6205 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
6206 | wdev_unlock(wdev); | |
6207 | ||
6208 | return err; | |
16ef1fe2 SW |
6209 | } |
6210 | ||
9720bb3a JB |
6211 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
6212 | u32 seq, int flags, | |
2a519311 | 6213 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
6214 | struct wireless_dev *wdev, |
6215 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 6216 | { |
48ab905d | 6217 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 6218 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
6219 | void *hdr; |
6220 | struct nlattr *bss; | |
48ab905d JB |
6221 | |
6222 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 6223 | |
15e47304 | 6224 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
6225 | NL80211_CMD_NEW_SCAN_RESULTS); |
6226 | if (!hdr) | |
6227 | return -1; | |
6228 | ||
9720bb3a JB |
6229 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
6230 | ||
97990a06 JB |
6231 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
6232 | goto nla_put_failure; | |
6233 | if (wdev->netdev && | |
9360ffd1 DM |
6234 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
6235 | goto nla_put_failure; | |
97990a06 JB |
6236 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
6237 | goto nla_put_failure; | |
2a519311 JB |
6238 | |
6239 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
6240 | if (!bss) | |
6241 | goto nla_put_failure; | |
9360ffd1 | 6242 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 6243 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 6244 | goto nla_put_failure; |
9caf0364 JB |
6245 | |
6246 | rcu_read_lock(); | |
0e227084 JB |
6247 | /* indicate whether we have probe response data or not */ |
6248 | if (rcu_access_pointer(res->proberesp_ies) && | |
6249 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
6250 | goto fail_unlock_rcu; | |
6251 | ||
6252 | /* this pointer prefers to be pointed to probe response data | |
6253 | * but is always valid | |
6254 | */ | |
9caf0364 | 6255 | ies = rcu_dereference(res->ies); |
8cef2c9d JB |
6256 | if (ies) { |
6257 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
6258 | goto fail_unlock_rcu; | |
8cef2c9d JB |
6259 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
6260 | ies->len, ies->data)) | |
6261 | goto fail_unlock_rcu; | |
9caf0364 | 6262 | } |
0e227084 JB |
6263 | |
6264 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 6265 | ies = rcu_dereference(res->beacon_ies); |
0e227084 JB |
6266 | if (ies && ies->from_beacon) { |
6267 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) | |
8cef2c9d JB |
6268 | goto fail_unlock_rcu; |
6269 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
6270 | ies->len, ies->data)) | |
6271 | goto fail_unlock_rcu; | |
9caf0364 JB |
6272 | } |
6273 | rcu_read_unlock(); | |
6274 | ||
9360ffd1 DM |
6275 | if (res->beacon_interval && |
6276 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
6277 | goto nla_put_failure; | |
6278 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
6279 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 6280 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
6281 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
6282 | jiffies_to_msecs(jiffies - intbss->ts))) | |
6283 | goto nla_put_failure; | |
2a519311 | 6284 | |
77965c97 | 6285 | switch (rdev->wiphy.signal_type) { |
2a519311 | 6286 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
6287 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
6288 | goto nla_put_failure; | |
2a519311 JB |
6289 | break; |
6290 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
6291 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
6292 | goto nla_put_failure; | |
2a519311 JB |
6293 | break; |
6294 | default: | |
6295 | break; | |
6296 | } | |
6297 | ||
48ab905d | 6298 | switch (wdev->iftype) { |
074ac8df | 6299 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 6300 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
6301 | if (intbss == wdev->current_bss && |
6302 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6303 | NL80211_BSS_STATUS_ASSOCIATED)) | |
6304 | goto nla_put_failure; | |
48ab905d JB |
6305 | break; |
6306 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
6307 | if (intbss == wdev->current_bss && |
6308 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6309 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
6310 | goto nla_put_failure; | |
48ab905d JB |
6311 | break; |
6312 | default: | |
6313 | break; | |
6314 | } | |
6315 | ||
2a519311 JB |
6316 | nla_nest_end(msg, bss); |
6317 | ||
6318 | return genlmsg_end(msg, hdr); | |
6319 | ||
8cef2c9d JB |
6320 | fail_unlock_rcu: |
6321 | rcu_read_unlock(); | |
2a519311 JB |
6322 | nla_put_failure: |
6323 | genlmsg_cancel(msg, hdr); | |
6324 | return -EMSGSIZE; | |
6325 | } | |
6326 | ||
97990a06 | 6327 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 6328 | { |
48ab905d | 6329 | struct cfg80211_registered_device *rdev; |
2a519311 | 6330 | struct cfg80211_internal_bss *scan; |
48ab905d | 6331 | struct wireless_dev *wdev; |
97990a06 | 6332 | int start = cb->args[2], idx = 0; |
2a519311 JB |
6333 | int err; |
6334 | ||
97990a06 | 6335 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6336 | if (err) |
6337 | return err; | |
2a519311 | 6338 | |
48ab905d JB |
6339 | wdev_lock(wdev); |
6340 | spin_lock_bh(&rdev->bss_lock); | |
6341 | cfg80211_bss_expire(rdev); | |
6342 | ||
9720bb3a JB |
6343 | cb->seq = rdev->bss_generation; |
6344 | ||
48ab905d | 6345 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
6346 | if (++idx <= start) |
6347 | continue; | |
9720bb3a | 6348 | if (nl80211_send_bss(skb, cb, |
2a519311 | 6349 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 6350 | rdev, wdev, scan) < 0) { |
2a519311 | 6351 | idx--; |
67748893 | 6352 | break; |
2a519311 JB |
6353 | } |
6354 | } | |
6355 | ||
48ab905d JB |
6356 | spin_unlock_bh(&rdev->bss_lock); |
6357 | wdev_unlock(wdev); | |
2a519311 | 6358 | |
97990a06 JB |
6359 | cb->args[2] = idx; |
6360 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 6361 | |
67748893 | 6362 | return skb->len; |
2a519311 JB |
6363 | } |
6364 | ||
15e47304 | 6365 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
6366 | int flags, struct net_device *dev, |
6367 | struct survey_info *survey) | |
6368 | { | |
6369 | void *hdr; | |
6370 | struct nlattr *infoattr; | |
6371 | ||
15e47304 | 6372 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
6373 | NL80211_CMD_NEW_SURVEY_RESULTS); |
6374 | if (!hdr) | |
6375 | return -ENOMEM; | |
6376 | ||
9360ffd1 DM |
6377 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
6378 | goto nla_put_failure; | |
61fa713c HS |
6379 | |
6380 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
6381 | if (!infoattr) | |
6382 | goto nla_put_failure; | |
6383 | ||
9360ffd1 DM |
6384 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
6385 | survey->channel->center_freq)) | |
6386 | goto nla_put_failure; | |
6387 | ||
6388 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
6389 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
6390 | goto nla_put_failure; | |
6391 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
6392 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
6393 | goto nla_put_failure; | |
6394 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
6395 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
6396 | survey->channel_time)) | |
6397 | goto nla_put_failure; | |
6398 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
6399 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
6400 | survey->channel_time_busy)) | |
6401 | goto nla_put_failure; | |
6402 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
6403 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
6404 | survey->channel_time_ext_busy)) | |
6405 | goto nla_put_failure; | |
6406 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
6407 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
6408 | survey->channel_time_rx)) | |
6409 | goto nla_put_failure; | |
6410 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
6411 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
6412 | survey->channel_time_tx)) | |
6413 | goto nla_put_failure; | |
61fa713c HS |
6414 | |
6415 | nla_nest_end(msg, infoattr); | |
6416 | ||
6417 | return genlmsg_end(msg, hdr); | |
6418 | ||
6419 | nla_put_failure: | |
6420 | genlmsg_cancel(msg, hdr); | |
6421 | return -EMSGSIZE; | |
6422 | } | |
6423 | ||
6424 | static int nl80211_dump_survey(struct sk_buff *skb, | |
6425 | struct netlink_callback *cb) | |
6426 | { | |
6427 | struct survey_info survey; | |
1b8ec87a | 6428 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
6429 | struct wireless_dev *wdev; |
6430 | int survey_idx = cb->args[2]; | |
61fa713c HS |
6431 | int res; |
6432 | ||
1b8ec87a | 6433 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6434 | if (res) |
6435 | return res; | |
61fa713c | 6436 | |
97990a06 JB |
6437 | if (!wdev->netdev) { |
6438 | res = -EINVAL; | |
6439 | goto out_err; | |
6440 | } | |
6441 | ||
1b8ec87a | 6442 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
6443 | res = -EOPNOTSUPP; |
6444 | goto out_err; | |
6445 | } | |
6446 | ||
6447 | while (1) { | |
180cdc79 LR |
6448 | struct ieee80211_channel *chan; |
6449 | ||
1b8ec87a | 6450 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
6451 | if (res == -ENOENT) |
6452 | break; | |
6453 | if (res) | |
6454 | goto out_err; | |
6455 | ||
180cdc79 LR |
6456 | /* Survey without a channel doesn't make sense */ |
6457 | if (!survey.channel) { | |
6458 | res = -EINVAL; | |
6459 | goto out; | |
6460 | } | |
6461 | ||
1b8ec87a | 6462 | chan = ieee80211_get_channel(&rdev->wiphy, |
180cdc79 LR |
6463 | survey.channel->center_freq); |
6464 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
6465 | survey_idx++; | |
6466 | continue; | |
6467 | } | |
6468 | ||
61fa713c | 6469 | if (nl80211_send_survey(skb, |
15e47304 | 6470 | NETLINK_CB(cb->skb).portid, |
61fa713c | 6471 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 6472 | wdev->netdev, &survey) < 0) |
61fa713c HS |
6473 | goto out; |
6474 | survey_idx++; | |
6475 | } | |
6476 | ||
6477 | out: | |
97990a06 | 6478 | cb->args[2] = survey_idx; |
61fa713c HS |
6479 | res = skb->len; |
6480 | out_err: | |
1b8ec87a | 6481 | nl80211_finish_wdev_dump(rdev); |
61fa713c HS |
6482 | return res; |
6483 | } | |
6484 | ||
b23aa676 SO |
6485 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
6486 | { | |
6487 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
6488 | NL80211_WPA_VERSION_2)); | |
6489 | } | |
6490 | ||
636a5d36 JM |
6491 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
6492 | { | |
4c476991 JB |
6493 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6494 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6495 | struct ieee80211_channel *chan; |
e39e5b5e JM |
6496 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
6497 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 6498 | enum nl80211_auth_type auth_type; |
fffd0934 | 6499 | struct key_parse key; |
d5cdfacb | 6500 | bool local_state_change; |
636a5d36 | 6501 | |
f4a11bb0 JB |
6502 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6503 | return -EINVAL; | |
6504 | ||
6505 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6506 | return -EINVAL; | |
6507 | ||
1778092e JM |
6508 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
6509 | return -EINVAL; | |
6510 | ||
19957bb3 JB |
6511 | if (!info->attrs[NL80211_ATTR_SSID]) |
6512 | return -EINVAL; | |
6513 | ||
6514 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
6515 | return -EINVAL; | |
6516 | ||
fffd0934 JB |
6517 | err = nl80211_parse_key(info, &key); |
6518 | if (err) | |
6519 | return err; | |
6520 | ||
6521 | if (key.idx >= 0) { | |
e31b8213 JB |
6522 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
6523 | return -EINVAL; | |
fffd0934 JB |
6524 | if (!key.p.key || !key.p.key_len) |
6525 | return -EINVAL; | |
6526 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
6527 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
6528 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
6529 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
6530 | return -EINVAL; | |
6531 | if (key.idx > 4) | |
6532 | return -EINVAL; | |
6533 | } else { | |
6534 | key.p.key_len = 0; | |
6535 | key.p.key = NULL; | |
6536 | } | |
6537 | ||
afea0b7a JB |
6538 | if (key.idx >= 0) { |
6539 | int i; | |
6540 | bool ok = false; | |
6541 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
6542 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
6543 | ok = true; | |
6544 | break; | |
6545 | } | |
6546 | } | |
4c476991 JB |
6547 | if (!ok) |
6548 | return -EINVAL; | |
afea0b7a JB |
6549 | } |
6550 | ||
4c476991 JB |
6551 | if (!rdev->ops->auth) |
6552 | return -EOPNOTSUPP; | |
636a5d36 | 6553 | |
074ac8df | 6554 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6555 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6556 | return -EOPNOTSUPP; | |
eec60b03 | 6557 | |
19957bb3 | 6558 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
6559 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6560 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6561 | if (!chan) | |
4c476991 | 6562 | return -EINVAL; |
636a5d36 | 6563 | |
19957bb3 JB |
6564 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6565 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6566 | |
6567 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6568 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6569 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6570 | } |
6571 | ||
19957bb3 | 6572 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 6573 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 6574 | return -EINVAL; |
636a5d36 | 6575 | |
e39e5b5e JM |
6576 | if (auth_type == NL80211_AUTHTYPE_SAE && |
6577 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
6578 | return -EINVAL; | |
6579 | ||
6580 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
6581 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
6582 | return -EINVAL; | |
6583 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6584 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6585 | /* need to include at least Auth Transaction and Status Code */ | |
6586 | if (sae_data_len < 4) | |
6587 | return -EINVAL; | |
6588 | } | |
6589 | ||
d5cdfacb JM |
6590 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6591 | ||
95de817b JB |
6592 | /* |
6593 | * Since we no longer track auth state, ignore | |
6594 | * requests to only change local state. | |
6595 | */ | |
6596 | if (local_state_change) | |
6597 | return 0; | |
6598 | ||
91bf9b26 JB |
6599 | wdev_lock(dev->ieee80211_ptr); |
6600 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
6601 | ssid, ssid_len, ie, ie_len, | |
6602 | key.p.key, key.p.key_len, key.idx, | |
6603 | sae_data, sae_data_len); | |
6604 | wdev_unlock(dev->ieee80211_ptr); | |
6605 | return err; | |
636a5d36 JM |
6606 | } |
6607 | ||
c0692b8f JB |
6608 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6609 | struct genl_info *info, | |
3dc27d25 JB |
6610 | struct cfg80211_crypto_settings *settings, |
6611 | int cipher_limit) | |
b23aa676 | 6612 | { |
c0b2bbd8 JB |
6613 | memset(settings, 0, sizeof(*settings)); |
6614 | ||
b23aa676 SO |
6615 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6616 | ||
c0692b8f JB |
6617 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6618 | u16 proto; | |
6619 | proto = nla_get_u16( | |
6620 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6621 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6622 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6623 | proto != ETH_P_PAE) | |
6624 | return -EINVAL; | |
6625 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6626 | settings->control_port_no_encrypt = true; | |
6627 | } else | |
6628 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6629 | ||
b23aa676 SO |
6630 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6631 | void *data; | |
6632 | int len, i; | |
6633 | ||
6634 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6635 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6636 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6637 | ||
6638 | if (len % sizeof(u32)) | |
6639 | return -EINVAL; | |
6640 | ||
3dc27d25 | 6641 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6642 | return -EINVAL; |
6643 | ||
6644 | memcpy(settings->ciphers_pairwise, data, len); | |
6645 | ||
6646 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6647 | if (!cfg80211_supported_cipher_suite( |
6648 | &rdev->wiphy, | |
b23aa676 SO |
6649 | settings->ciphers_pairwise[i])) |
6650 | return -EINVAL; | |
6651 | } | |
6652 | ||
6653 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6654 | settings->cipher_group = | |
6655 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6656 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6657 | settings->cipher_group)) | |
b23aa676 SO |
6658 | return -EINVAL; |
6659 | } | |
6660 | ||
6661 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6662 | settings->wpa_versions = | |
6663 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6664 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6665 | return -EINVAL; | |
6666 | } | |
6667 | ||
6668 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6669 | void *data; | |
6d30240e | 6670 | int len; |
b23aa676 SO |
6671 | |
6672 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6673 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6674 | settings->n_akm_suites = len / sizeof(u32); | |
6675 | ||
6676 | if (len % sizeof(u32)) | |
6677 | return -EINVAL; | |
6678 | ||
1b9ca027 JM |
6679 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6680 | return -EINVAL; | |
6681 | ||
b23aa676 | 6682 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6683 | } |
6684 | ||
6685 | return 0; | |
6686 | } | |
6687 | ||
636a5d36 JM |
6688 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6689 | { | |
4c476991 JB |
6690 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6691 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6692 | struct ieee80211_channel *chan; |
f62fab73 JB |
6693 | struct cfg80211_assoc_request req = {}; |
6694 | const u8 *bssid, *ssid; | |
6695 | int err, ssid_len = 0; | |
636a5d36 | 6696 | |
f4a11bb0 JB |
6697 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6698 | return -EINVAL; | |
6699 | ||
6700 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6701 | !info->attrs[NL80211_ATTR_SSID] || |
6702 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6703 | return -EINVAL; |
6704 | ||
4c476991 JB |
6705 | if (!rdev->ops->assoc) |
6706 | return -EOPNOTSUPP; | |
636a5d36 | 6707 | |
074ac8df | 6708 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6709 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6710 | return -EOPNOTSUPP; | |
eec60b03 | 6711 | |
19957bb3 | 6712 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6713 | |
664834de JM |
6714 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6715 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6716 | if (!chan) | |
4c476991 | 6717 | return -EINVAL; |
636a5d36 | 6718 | |
19957bb3 JB |
6719 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6720 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6721 | |
6722 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6723 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6724 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6725 | } |
6726 | ||
dc6382ce | 6727 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6728 | enum nl80211_mfp mfp = |
dc6382ce | 6729 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6730 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6731 | req.use_mfp = true; |
4c476991 JB |
6732 | else if (mfp != NL80211_MFP_NO) |
6733 | return -EINVAL; | |
dc6382ce JM |
6734 | } |
6735 | ||
3e5d7649 | 6736 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 6737 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 6738 | |
7e7c8926 | 6739 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 6740 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
6741 | |
6742 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
6743 | memcpy(&req.ht_capa_mask, |
6744 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6745 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
6746 | |
6747 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 6748 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 6749 | return -EINVAL; |
f62fab73 JB |
6750 | memcpy(&req.ht_capa, |
6751 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6752 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
6753 | } |
6754 | ||
ee2aca34 | 6755 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 6756 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
6757 | |
6758 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
6759 | memcpy(&req.vht_capa_mask, |
6760 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6761 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
6762 | |
6763 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 6764 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 6765 | return -EINVAL; |
f62fab73 JB |
6766 | memcpy(&req.vht_capa, |
6767 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6768 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
6769 | } |
6770 | ||
bab5ab7d AK |
6771 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
6772 | if (!(rdev->wiphy.features & | |
6773 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
6774 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
6775 | return -EINVAL; | |
6776 | req.flags |= ASSOC_REQ_USE_RRM; | |
6777 | } | |
6778 | ||
f62fab73 | 6779 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
6780 | if (!err) { |
6781 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
6782 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
6783 | ssid, ssid_len, &req); | |
91bf9b26 JB |
6784 | wdev_unlock(dev->ieee80211_ptr); |
6785 | } | |
636a5d36 | 6786 | |
636a5d36 JM |
6787 | return err; |
6788 | } | |
6789 | ||
6790 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
6791 | { | |
4c476991 JB |
6792 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6793 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6794 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6795 | int ie_len = 0, err; |
19957bb3 | 6796 | u16 reason_code; |
d5cdfacb | 6797 | bool local_state_change; |
636a5d36 | 6798 | |
f4a11bb0 JB |
6799 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6800 | return -EINVAL; | |
6801 | ||
6802 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6803 | return -EINVAL; | |
6804 | ||
6805 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6806 | return -EINVAL; | |
6807 | ||
4c476991 JB |
6808 | if (!rdev->ops->deauth) |
6809 | return -EOPNOTSUPP; | |
636a5d36 | 6810 | |
074ac8df | 6811 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6812 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6813 | return -EOPNOTSUPP; | |
eec60b03 | 6814 | |
19957bb3 | 6815 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6816 | |
19957bb3 JB |
6817 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6818 | if (reason_code == 0) { | |
f4a11bb0 | 6819 | /* Reason Code 0 is reserved */ |
4c476991 | 6820 | return -EINVAL; |
255e737e | 6821 | } |
636a5d36 JM |
6822 | |
6823 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6824 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6825 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6826 | } |
6827 | ||
d5cdfacb JM |
6828 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6829 | ||
91bf9b26 JB |
6830 | wdev_lock(dev->ieee80211_ptr); |
6831 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
6832 | local_state_change); | |
6833 | wdev_unlock(dev->ieee80211_ptr); | |
6834 | return err; | |
636a5d36 JM |
6835 | } |
6836 | ||
6837 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
6838 | { | |
4c476991 JB |
6839 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6840 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6841 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6842 | int ie_len = 0, err; |
19957bb3 | 6843 | u16 reason_code; |
d5cdfacb | 6844 | bool local_state_change; |
636a5d36 | 6845 | |
f4a11bb0 JB |
6846 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6847 | return -EINVAL; | |
6848 | ||
6849 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6850 | return -EINVAL; | |
6851 | ||
6852 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6853 | return -EINVAL; | |
6854 | ||
4c476991 JB |
6855 | if (!rdev->ops->disassoc) |
6856 | return -EOPNOTSUPP; | |
636a5d36 | 6857 | |
074ac8df | 6858 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6859 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6860 | return -EOPNOTSUPP; | |
eec60b03 | 6861 | |
19957bb3 | 6862 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6863 | |
19957bb3 JB |
6864 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6865 | if (reason_code == 0) { | |
f4a11bb0 | 6866 | /* Reason Code 0 is reserved */ |
4c476991 | 6867 | return -EINVAL; |
255e737e | 6868 | } |
636a5d36 JM |
6869 | |
6870 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6871 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6872 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6873 | } |
6874 | ||
d5cdfacb JM |
6875 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6876 | ||
91bf9b26 JB |
6877 | wdev_lock(dev->ieee80211_ptr); |
6878 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
6879 | local_state_change); | |
6880 | wdev_unlock(dev->ieee80211_ptr); | |
6881 | return err; | |
636a5d36 JM |
6882 | } |
6883 | ||
dd5b4cc7 FF |
6884 | static bool |
6885 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
6886 | int mcast_rate[IEEE80211_NUM_BANDS], | |
6887 | int rateval) | |
6888 | { | |
6889 | struct wiphy *wiphy = &rdev->wiphy; | |
6890 | bool found = false; | |
6891 | int band, i; | |
6892 | ||
6893 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6894 | struct ieee80211_supported_band *sband; | |
6895 | ||
6896 | sband = wiphy->bands[band]; | |
6897 | if (!sband) | |
6898 | continue; | |
6899 | ||
6900 | for (i = 0; i < sband->n_bitrates; i++) { | |
6901 | if (sband->bitrates[i].bitrate == rateval) { | |
6902 | mcast_rate[band] = i + 1; | |
6903 | found = true; | |
6904 | break; | |
6905 | } | |
6906 | } | |
6907 | } | |
6908 | ||
6909 | return found; | |
6910 | } | |
6911 | ||
04a773ad JB |
6912 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
6913 | { | |
4c476991 JB |
6914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6915 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
6916 | struct cfg80211_ibss_params ibss; |
6917 | struct wiphy *wiphy; | |
fffd0934 | 6918 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
6919 | int err; |
6920 | ||
8e30bc55 JB |
6921 | memset(&ibss, 0, sizeof(ibss)); |
6922 | ||
04a773ad JB |
6923 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6924 | return -EINVAL; | |
6925 | ||
683b6d3b | 6926 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
6927 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
6928 | return -EINVAL; | |
6929 | ||
8e30bc55 JB |
6930 | ibss.beacon_interval = 100; |
6931 | ||
6932 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
6933 | ibss.beacon_interval = | |
6934 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
6935 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
6936 | return -EINVAL; | |
6937 | } | |
6938 | ||
4c476991 JB |
6939 | if (!rdev->ops->join_ibss) |
6940 | return -EOPNOTSUPP; | |
04a773ad | 6941 | |
4c476991 JB |
6942 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6943 | return -EOPNOTSUPP; | |
04a773ad | 6944 | |
79c97e97 | 6945 | wiphy = &rdev->wiphy; |
04a773ad | 6946 | |
39193498 | 6947 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 6948 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
6949 | |
6950 | if (!is_valid_ether_addr(ibss.bssid)) | |
6951 | return -EINVAL; | |
6952 | } | |
04a773ad JB |
6953 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6954 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6955 | ||
6956 | if (info->attrs[NL80211_ATTR_IE]) { | |
6957 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6958 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6959 | } | |
6960 | ||
683b6d3b JB |
6961 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
6962 | if (err) | |
6963 | return err; | |
04a773ad | 6964 | |
174e0cd2 IP |
6965 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
6966 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
6967 | return -EINVAL; |
6968 | ||
2f301ab2 | 6969 | switch (ibss.chandef.width) { |
bf372645 SW |
6970 | case NL80211_CHAN_WIDTH_5: |
6971 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
6972 | case NL80211_CHAN_WIDTH_20_NOHT: |
6973 | break; | |
6974 | case NL80211_CHAN_WIDTH_20: | |
6975 | case NL80211_CHAN_WIDTH_40: | |
6976 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | |
6977 | break; | |
6978 | default: | |
c04d6150 | 6979 | return -EINVAL; |
2f301ab2 | 6980 | } |
db9c64cf | 6981 | |
04a773ad | 6982 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
6983 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
6984 | ||
fbd2c8dc TP |
6985 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6986 | u8 *rates = | |
6987 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6988 | int n_rates = | |
6989 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6990 | struct ieee80211_supported_band *sband = | |
683b6d3b | 6991 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 6992 | |
34850ab2 JB |
6993 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
6994 | &ibss.basic_rates); | |
6995 | if (err) | |
6996 | return err; | |
fbd2c8dc | 6997 | } |
dd5b4cc7 | 6998 | |
803768f5 SW |
6999 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7000 | memcpy(&ibss.ht_capa_mask, | |
7001 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7002 | sizeof(ibss.ht_capa_mask)); | |
7003 | ||
7004 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
7005 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7006 | return -EINVAL; | |
7007 | memcpy(&ibss.ht_capa, | |
7008 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7009 | sizeof(ibss.ht_capa)); | |
7010 | } | |
7011 | ||
dd5b4cc7 FF |
7012 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7013 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
7014 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7015 | return -EINVAL; | |
fbd2c8dc | 7016 | |
4c476991 | 7017 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
7018 | bool no_ht = false; |
7019 | ||
4c476991 | 7020 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
7021 | info->attrs[NL80211_ATTR_KEYS], |
7022 | &no_ht); | |
4c476991 JB |
7023 | if (IS_ERR(connkeys)) |
7024 | return PTR_ERR(connkeys); | |
de7044ee | 7025 | |
3d9d1d66 JB |
7026 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
7027 | no_ht) { | |
de7044ee SM |
7028 | kfree(connkeys); |
7029 | return -EINVAL; | |
7030 | } | |
4c476991 | 7031 | } |
04a773ad | 7032 | |
267335d6 AQ |
7033 | ibss.control_port = |
7034 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
7035 | ||
5336fa88 SW |
7036 | ibss.userspace_handles_dfs = |
7037 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
7038 | ||
4c476991 | 7039 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 | 7040 | if (err) |
b47f610b | 7041 | kzfree(connkeys); |
04a773ad JB |
7042 | return err; |
7043 | } | |
7044 | ||
7045 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
7046 | { | |
4c476991 JB |
7047 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7048 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 7049 | |
4c476991 JB |
7050 | if (!rdev->ops->leave_ibss) |
7051 | return -EOPNOTSUPP; | |
04a773ad | 7052 | |
4c476991 JB |
7053 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7054 | return -EOPNOTSUPP; | |
04a773ad | 7055 | |
4c476991 | 7056 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
7057 | } |
7058 | ||
f4e583c8 AQ |
7059 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
7060 | { | |
7061 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7062 | struct net_device *dev = info->user_ptr[1]; | |
7063 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
7064 | u32 nla_rate; | |
7065 | int err; | |
7066 | ||
7067 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
7068 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
7069 | return -EOPNOTSUPP; | |
7070 | ||
7071 | if (!rdev->ops->set_mcast_rate) | |
7072 | return -EOPNOTSUPP; | |
7073 | ||
7074 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
7075 | ||
7076 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
7077 | return -EINVAL; | |
7078 | ||
7079 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
7080 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
7081 | return -EINVAL; | |
7082 | ||
7083 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
7084 | ||
7085 | return err; | |
7086 | } | |
7087 | ||
ad7e718c JB |
7088 | static struct sk_buff * |
7089 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
7090 | int approxlen, u32 portid, u32 seq, | |
7091 | enum nl80211_commands cmd, | |
567ffc35 JB |
7092 | enum nl80211_attrs attr, |
7093 | const struct nl80211_vendor_cmd_info *info, | |
7094 | gfp_t gfp) | |
ad7e718c JB |
7095 | { |
7096 | struct sk_buff *skb; | |
7097 | void *hdr; | |
7098 | struct nlattr *data; | |
7099 | ||
7100 | skb = nlmsg_new(approxlen + 100, gfp); | |
7101 | if (!skb) | |
7102 | return NULL; | |
7103 | ||
7104 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
7105 | if (!hdr) { | |
7106 | kfree_skb(skb); | |
7107 | return NULL; | |
7108 | } | |
7109 | ||
7110 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
7111 | goto nla_put_failure; | |
567ffc35 JB |
7112 | |
7113 | if (info) { | |
7114 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
7115 | info->vendor_id)) | |
7116 | goto nla_put_failure; | |
7117 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
7118 | info->subcmd)) | |
7119 | goto nla_put_failure; | |
7120 | } | |
7121 | ||
ad7e718c JB |
7122 | data = nla_nest_start(skb, attr); |
7123 | ||
7124 | ((void **)skb->cb)[0] = rdev; | |
7125 | ((void **)skb->cb)[1] = hdr; | |
7126 | ((void **)skb->cb)[2] = data; | |
7127 | ||
7128 | return skb; | |
7129 | ||
7130 | nla_put_failure: | |
7131 | kfree_skb(skb); | |
7132 | return NULL; | |
7133 | } | |
f4e583c8 | 7134 | |
e03ad6ea JB |
7135 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
7136 | enum nl80211_commands cmd, | |
7137 | enum nl80211_attrs attr, | |
7138 | int vendor_event_idx, | |
7139 | int approxlen, gfp_t gfp) | |
7140 | { | |
f26cbf40 | 7141 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
7142 | const struct nl80211_vendor_cmd_info *info; |
7143 | ||
7144 | switch (cmd) { | |
7145 | case NL80211_CMD_TESTMODE: | |
7146 | if (WARN_ON(vendor_event_idx != -1)) | |
7147 | return NULL; | |
7148 | info = NULL; | |
7149 | break; | |
7150 | case NL80211_CMD_VENDOR: | |
7151 | if (WARN_ON(vendor_event_idx < 0 || | |
7152 | vendor_event_idx >= wiphy->n_vendor_events)) | |
7153 | return NULL; | |
7154 | info = &wiphy->vendor_events[vendor_event_idx]; | |
7155 | break; | |
7156 | default: | |
7157 | WARN_ON(1); | |
7158 | return NULL; | |
7159 | } | |
7160 | ||
7161 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, | |
7162 | cmd, attr, info, gfp); | |
7163 | } | |
7164 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
7165 | ||
7166 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
7167 | { | |
7168 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
7169 | void *hdr = ((void **)skb->cb)[1]; | |
7170 | struct nlattr *data = ((void **)skb->cb)[2]; | |
7171 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
7172 | ||
bd8c78e7 JB |
7173 | /* clear CB data for netlink core to own from now on */ |
7174 | memset(skb->cb, 0, sizeof(skb->cb)); | |
7175 | ||
e03ad6ea JB |
7176 | nla_nest_end(skb, data); |
7177 | genlmsg_end(skb, hdr); | |
7178 | ||
7179 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
7180 | mcgrp = NL80211_MCGRP_VENDOR; | |
7181 | ||
7182 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
7183 | mcgrp, gfp); | |
7184 | } | |
7185 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
7186 | ||
aff89a9b | 7187 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
7188 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
7189 | { | |
4c476991 | 7190 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
7191 | struct wireless_dev *wdev = |
7192 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
7193 | int err; |
7194 | ||
fc73f11f DS |
7195 | if (!rdev->ops->testmode_cmd) |
7196 | return -EOPNOTSUPP; | |
7197 | ||
7198 | if (IS_ERR(wdev)) { | |
7199 | err = PTR_ERR(wdev); | |
7200 | if (err != -EINVAL) | |
7201 | return err; | |
7202 | wdev = NULL; | |
7203 | } else if (wdev->wiphy != &rdev->wiphy) { | |
7204 | return -EINVAL; | |
7205 | } | |
7206 | ||
aff89a9b JB |
7207 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
7208 | return -EINVAL; | |
7209 | ||
ad7e718c | 7210 | rdev->cur_cmd_info = info; |
fc73f11f | 7211 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
7212 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
7213 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 7214 | rdev->cur_cmd_info = NULL; |
aff89a9b | 7215 | |
aff89a9b JB |
7216 | return err; |
7217 | } | |
7218 | ||
71063f0e WYG |
7219 | static int nl80211_testmode_dump(struct sk_buff *skb, |
7220 | struct netlink_callback *cb) | |
7221 | { | |
00918d33 | 7222 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
7223 | int err; |
7224 | long phy_idx; | |
7225 | void *data = NULL; | |
7226 | int data_len = 0; | |
7227 | ||
5fe231e8 JB |
7228 | rtnl_lock(); |
7229 | ||
71063f0e WYG |
7230 | if (cb->args[0]) { |
7231 | /* | |
7232 | * 0 is a valid index, but not valid for args[0], | |
7233 | * so we need to offset by 1. | |
7234 | */ | |
7235 | phy_idx = cb->args[0] - 1; | |
7236 | } else { | |
7237 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
7238 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
7239 | nl80211_policy); | |
7240 | if (err) | |
5fe231e8 | 7241 | goto out_err; |
00918d33 | 7242 | |
2bd7e35d JB |
7243 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
7244 | nl80211_fam.attrbuf); | |
7245 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
7246 | err = PTR_ERR(rdev); |
7247 | goto out_err; | |
00918d33 | 7248 | } |
2bd7e35d JB |
7249 | phy_idx = rdev->wiphy_idx; |
7250 | rdev = NULL; | |
2bd7e35d | 7251 | |
71063f0e WYG |
7252 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
7253 | cb->args[1] = | |
7254 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
7255 | } | |
7256 | ||
7257 | if (cb->args[1]) { | |
7258 | data = nla_data((void *)cb->args[1]); | |
7259 | data_len = nla_len((void *)cb->args[1]); | |
7260 | } | |
7261 | ||
00918d33 JB |
7262 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
7263 | if (!rdev) { | |
5fe231e8 JB |
7264 | err = -ENOENT; |
7265 | goto out_err; | |
71063f0e | 7266 | } |
71063f0e | 7267 | |
00918d33 | 7268 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
7269 | err = -EOPNOTSUPP; |
7270 | goto out_err; | |
7271 | } | |
7272 | ||
7273 | while (1) { | |
15e47304 | 7274 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
7275 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
7276 | NL80211_CMD_TESTMODE); | |
7277 | struct nlattr *tmdata; | |
7278 | ||
cb35fba3 DC |
7279 | if (!hdr) |
7280 | break; | |
7281 | ||
9360ffd1 | 7282 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
7283 | genlmsg_cancel(skb, hdr); |
7284 | break; | |
7285 | } | |
7286 | ||
7287 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
7288 | if (!tmdata) { | |
7289 | genlmsg_cancel(skb, hdr); | |
7290 | break; | |
7291 | } | |
e35e4d28 | 7292 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
7293 | nla_nest_end(skb, tmdata); |
7294 | ||
7295 | if (err == -ENOBUFS || err == -ENOENT) { | |
7296 | genlmsg_cancel(skb, hdr); | |
7297 | break; | |
7298 | } else if (err) { | |
7299 | genlmsg_cancel(skb, hdr); | |
7300 | goto out_err; | |
7301 | } | |
7302 | ||
7303 | genlmsg_end(skb, hdr); | |
7304 | } | |
7305 | ||
7306 | err = skb->len; | |
7307 | /* see above */ | |
7308 | cb->args[0] = phy_idx + 1; | |
7309 | out_err: | |
5fe231e8 | 7310 | rtnl_unlock(); |
71063f0e WYG |
7311 | return err; |
7312 | } | |
aff89a9b JB |
7313 | #endif |
7314 | ||
b23aa676 SO |
7315 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
7316 | { | |
4c476991 JB |
7317 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7318 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
7319 | struct cfg80211_connect_params connect; |
7320 | struct wiphy *wiphy; | |
fffd0934 | 7321 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
7322 | int err; |
7323 | ||
7324 | memset(&connect, 0, sizeof(connect)); | |
7325 | ||
7326 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
7327 | return -EINVAL; | |
7328 | ||
7329 | if (!info->attrs[NL80211_ATTR_SSID] || | |
7330 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
7331 | return -EINVAL; | |
7332 | ||
7333 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
7334 | connect.auth_type = | |
7335 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
7336 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
7337 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
7338 | return -EINVAL; |
7339 | } else | |
7340 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
7341 | ||
7342 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
7343 | ||
c0692b8f | 7344 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 7345 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
7346 | if (err) |
7347 | return err; | |
b23aa676 | 7348 | |
074ac8df | 7349 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7350 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7351 | return -EOPNOTSUPP; | |
b23aa676 | 7352 | |
79c97e97 | 7353 | wiphy = &rdev->wiphy; |
b23aa676 | 7354 | |
4486ea98 BS |
7355 | connect.bg_scan_period = -1; |
7356 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
7357 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
7358 | connect.bg_scan_period = | |
7359 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
7360 | } | |
7361 | ||
b23aa676 SO |
7362 | if (info->attrs[NL80211_ATTR_MAC]) |
7363 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
7364 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
7365 | connect.bssid_hint = | |
7366 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
7367 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7368 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7369 | ||
7370 | if (info->attrs[NL80211_ATTR_IE]) { | |
7371 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7372 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7373 | } | |
7374 | ||
cee00a95 JM |
7375 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
7376 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
7377 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
7378 | connect.mfp != NL80211_MFP_NO) | |
7379 | return -EINVAL; | |
7380 | } else { | |
7381 | connect.mfp = NL80211_MFP_NO; | |
7382 | } | |
7383 | ||
b23aa676 | 7384 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
7385 | connect.channel = nl80211_get_valid_chan( |
7386 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7387 | if (!connect.channel) | |
1df4a510 JM |
7388 | return -EINVAL; |
7389 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
7390 | connect.channel_hint = nl80211_get_valid_chan( |
7391 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
7392 | if (!connect.channel_hint) | |
4c476991 | 7393 | return -EINVAL; |
b23aa676 SO |
7394 | } |
7395 | ||
fffd0934 JB |
7396 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
7397 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 7398 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
7399 | if (IS_ERR(connkeys)) |
7400 | return PTR_ERR(connkeys); | |
fffd0934 JB |
7401 | } |
7402 | ||
7e7c8926 BG |
7403 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
7404 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
7405 | ||
7406 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7407 | memcpy(&connect.ht_capa_mask, | |
7408 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7409 | sizeof(connect.ht_capa_mask)); | |
7410 | ||
7411 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e | 7412 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
b47f610b | 7413 | kzfree(connkeys); |
7e7c8926 | 7414 | return -EINVAL; |
b4e4f47e | 7415 | } |
7e7c8926 BG |
7416 | memcpy(&connect.ht_capa, |
7417 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7418 | sizeof(connect.ht_capa)); | |
7419 | } | |
7420 | ||
ee2aca34 JB |
7421 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
7422 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
7423 | ||
7424 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
7425 | memcpy(&connect.vht_capa_mask, | |
7426 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7427 | sizeof(connect.vht_capa_mask)); | |
7428 | ||
7429 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
7430 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
b47f610b | 7431 | kzfree(connkeys); |
ee2aca34 JB |
7432 | return -EINVAL; |
7433 | } | |
7434 | memcpy(&connect.vht_capa, | |
7435 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7436 | sizeof(connect.vht_capa)); | |
7437 | } | |
7438 | ||
bab5ab7d AK |
7439 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7440 | if (!(rdev->wiphy.features & | |
7441 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7442 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7443 | return -EINVAL; | |
7444 | connect.flags |= ASSOC_REQ_USE_RRM; | |
7445 | } | |
7446 | ||
83739b03 JB |
7447 | wdev_lock(dev->ieee80211_ptr); |
7448 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
7449 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 | 7450 | if (err) |
b47f610b | 7451 | kzfree(connkeys); |
b23aa676 SO |
7452 | return err; |
7453 | } | |
7454 | ||
7455 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
7456 | { | |
4c476991 JB |
7457 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7458 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 7459 | u16 reason; |
83739b03 | 7460 | int ret; |
b23aa676 SO |
7461 | |
7462 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7463 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
7464 | else | |
7465 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
7466 | ||
7467 | if (reason == 0) | |
7468 | return -EINVAL; | |
7469 | ||
074ac8df | 7470 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7471 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7472 | return -EOPNOTSUPP; | |
b23aa676 | 7473 | |
83739b03 JB |
7474 | wdev_lock(dev->ieee80211_ptr); |
7475 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
7476 | wdev_unlock(dev->ieee80211_ptr); | |
7477 | return ret; | |
b23aa676 SO |
7478 | } |
7479 | ||
463d0183 JB |
7480 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
7481 | { | |
4c476991 | 7482 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
7483 | struct net *net; |
7484 | int err; | |
7485 | u32 pid; | |
7486 | ||
7487 | if (!info->attrs[NL80211_ATTR_PID]) | |
7488 | return -EINVAL; | |
7489 | ||
7490 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
7491 | ||
463d0183 | 7492 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
7493 | if (IS_ERR(net)) |
7494 | return PTR_ERR(net); | |
463d0183 JB |
7495 | |
7496 | err = 0; | |
7497 | ||
7498 | /* check if anything to do */ | |
4c476991 JB |
7499 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
7500 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 7501 | |
463d0183 | 7502 | put_net(net); |
463d0183 JB |
7503 | return err; |
7504 | } | |
7505 | ||
67fbb16b SO |
7506 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
7507 | { | |
4c476991 | 7508 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
7509 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
7510 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 7511 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
7512 | struct cfg80211_pmksa pmksa; |
7513 | ||
7514 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
7515 | ||
7516 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7517 | return -EINVAL; | |
7518 | ||
7519 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
7520 | return -EINVAL; | |
7521 | ||
67fbb16b SO |
7522 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
7523 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7524 | ||
074ac8df | 7525 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7526 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7527 | return -EOPNOTSUPP; | |
67fbb16b SO |
7528 | |
7529 | switch (info->genlhdr->cmd) { | |
7530 | case NL80211_CMD_SET_PMKSA: | |
7531 | rdev_ops = rdev->ops->set_pmksa; | |
7532 | break; | |
7533 | case NL80211_CMD_DEL_PMKSA: | |
7534 | rdev_ops = rdev->ops->del_pmksa; | |
7535 | break; | |
7536 | default: | |
7537 | WARN_ON(1); | |
7538 | break; | |
7539 | } | |
7540 | ||
4c476991 JB |
7541 | if (!rdev_ops) |
7542 | return -EOPNOTSUPP; | |
67fbb16b | 7543 | |
4c476991 | 7544 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
7545 | } |
7546 | ||
7547 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
7548 | { | |
4c476991 JB |
7549 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7550 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 7551 | |
074ac8df | 7552 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7553 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7554 | return -EOPNOTSUPP; | |
67fbb16b | 7555 | |
4c476991 JB |
7556 | if (!rdev->ops->flush_pmksa) |
7557 | return -EOPNOTSUPP; | |
67fbb16b | 7558 | |
e35e4d28 | 7559 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
7560 | } |
7561 | ||
109086ce AN |
7562 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
7563 | { | |
7564 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7565 | struct net_device *dev = info->user_ptr[1]; | |
7566 | u8 action_code, dialog_token; | |
df942e7b | 7567 | u32 peer_capability = 0; |
109086ce AN |
7568 | u16 status_code; |
7569 | u8 *peer; | |
31fa97c5 | 7570 | bool initiator; |
109086ce AN |
7571 | |
7572 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7573 | !rdev->ops->tdls_mgmt) | |
7574 | return -EOPNOTSUPP; | |
7575 | ||
7576 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
7577 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
7578 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
7579 | !info->attrs[NL80211_ATTR_IE] || | |
7580 | !info->attrs[NL80211_ATTR_MAC]) | |
7581 | return -EINVAL; | |
7582 | ||
7583 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7584 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
7585 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
7586 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 7587 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
7588 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
7589 | peer_capability = | |
7590 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 7591 | |
e35e4d28 | 7592 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 7593 | dialog_token, status_code, peer_capability, |
31fa97c5 | 7594 | initiator, |
e35e4d28 HG |
7595 | nla_data(info->attrs[NL80211_ATTR_IE]), |
7596 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
7597 | } |
7598 | ||
7599 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
7600 | { | |
7601 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7602 | struct net_device *dev = info->user_ptr[1]; | |
7603 | enum nl80211_tdls_operation operation; | |
7604 | u8 *peer; | |
7605 | ||
7606 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7607 | !rdev->ops->tdls_oper) | |
7608 | return -EOPNOTSUPP; | |
7609 | ||
7610 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
7611 | !info->attrs[NL80211_ATTR_MAC]) | |
7612 | return -EINVAL; | |
7613 | ||
7614 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
7615 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7616 | ||
e35e4d28 | 7617 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
7618 | } |
7619 | ||
9588bbd5 JM |
7620 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
7621 | struct genl_info *info) | |
7622 | { | |
4c476991 | 7623 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7624 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7625 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
7626 | struct sk_buff *msg; |
7627 | void *hdr; | |
7628 | u64 cookie; | |
683b6d3b | 7629 | u32 duration; |
9588bbd5 JM |
7630 | int err; |
7631 | ||
7632 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7633 | !info->attrs[NL80211_ATTR_DURATION]) | |
7634 | return -EINVAL; | |
7635 | ||
7636 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
7637 | ||
ebf348fc JB |
7638 | if (!rdev->ops->remain_on_channel || |
7639 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
7640 | return -EOPNOTSUPP; | |
7641 | ||
9588bbd5 | 7642 | /* |
ebf348fc JB |
7643 | * We should be on that channel for at least a minimum amount of |
7644 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 7645 | */ |
ebf348fc | 7646 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 7647 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
7648 | return -EINVAL; |
7649 | ||
683b6d3b JB |
7650 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7651 | if (err) | |
7652 | return err; | |
9588bbd5 JM |
7653 | |
7654 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7655 | if (!msg) |
7656 | return -ENOMEM; | |
9588bbd5 | 7657 | |
15e47304 | 7658 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 7659 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
7660 | if (!hdr) { |
7661 | err = -ENOBUFS; | |
9588bbd5 JM |
7662 | goto free_msg; |
7663 | } | |
7664 | ||
683b6d3b JB |
7665 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7666 | duration, &cookie); | |
9588bbd5 JM |
7667 | |
7668 | if (err) | |
7669 | goto free_msg; | |
7670 | ||
9360ffd1 DM |
7671 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7672 | goto nla_put_failure; | |
9588bbd5 JM |
7673 | |
7674 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7675 | |
7676 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7677 | |
7678 | nla_put_failure: | |
7679 | err = -ENOBUFS; | |
7680 | free_msg: | |
7681 | nlmsg_free(msg); | |
9588bbd5 JM |
7682 | return err; |
7683 | } | |
7684 | ||
7685 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
7686 | struct genl_info *info) | |
7687 | { | |
4c476991 | 7688 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7689 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 7690 | u64 cookie; |
9588bbd5 JM |
7691 | |
7692 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7693 | return -EINVAL; | |
7694 | ||
4c476991 JB |
7695 | if (!rdev->ops->cancel_remain_on_channel) |
7696 | return -EOPNOTSUPP; | |
9588bbd5 | 7697 | |
9588bbd5 JM |
7698 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
7699 | ||
e35e4d28 | 7700 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
7701 | } |
7702 | ||
13ae75b1 JM |
7703 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
7704 | u8 *rates, u8 rates_len) | |
7705 | { | |
7706 | u8 i; | |
7707 | u32 mask = 0; | |
7708 | ||
7709 | for (i = 0; i < rates_len; i++) { | |
7710 | int rate = (rates[i] & 0x7f) * 5; | |
7711 | int ridx; | |
7712 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
7713 | struct ieee80211_rate *srate = | |
7714 | &sband->bitrates[ridx]; | |
7715 | if (rate == srate->bitrate) { | |
7716 | mask |= 1 << ridx; | |
7717 | break; | |
7718 | } | |
7719 | } | |
7720 | if (ridx == sband->n_bitrates) | |
7721 | return 0; /* rate not found */ | |
7722 | } | |
7723 | ||
7724 | return mask; | |
7725 | } | |
7726 | ||
24db78c0 SW |
7727 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
7728 | u8 *rates, u8 rates_len, | |
7729 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
7730 | { | |
7731 | u8 i; | |
7732 | ||
7733 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
7734 | ||
7735 | for (i = 0; i < rates_len; i++) { | |
7736 | int ridx, rbit; | |
7737 | ||
7738 | ridx = rates[i] / 8; | |
7739 | rbit = BIT(rates[i] % 8); | |
7740 | ||
7741 | /* check validity */ | |
910570b5 | 7742 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
7743 | return false; |
7744 | ||
7745 | /* check availability */ | |
7746 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
7747 | mcs[ridx] |= rbit; | |
7748 | else | |
7749 | return false; | |
7750 | } | |
7751 | ||
7752 | return true; | |
7753 | } | |
7754 | ||
204e35a9 JD |
7755 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
7756 | { | |
7757 | u16 mcs_mask = 0; | |
7758 | ||
7759 | switch (vht_mcs_map) { | |
7760 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
7761 | break; | |
7762 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
7763 | mcs_mask = 0x00FF; | |
7764 | break; | |
7765 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
7766 | mcs_mask = 0x01FF; | |
7767 | break; | |
7768 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
7769 | mcs_mask = 0x03FF; | |
7770 | break; | |
7771 | default: | |
7772 | break; | |
7773 | } | |
7774 | ||
7775 | return mcs_mask; | |
7776 | } | |
7777 | ||
7778 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
7779 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
7780 | { | |
7781 | u8 nss; | |
7782 | ||
7783 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
7784 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
7785 | vht_mcs_map >>= 2; | |
7786 | } | |
7787 | } | |
7788 | ||
7789 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
7790 | struct nl80211_txrate_vht *txrate, | |
7791 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
7792 | { | |
7793 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
7794 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
7795 | u8 i; | |
7796 | ||
7797 | if (!sband->vht_cap.vht_supported) | |
7798 | return false; | |
7799 | ||
7800 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
7801 | ||
7802 | /* Build vht_mcs_mask from VHT capabilities */ | |
7803 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
7804 | ||
7805 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
7806 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
7807 | mcs[i] = txrate->mcs[i]; | |
7808 | else | |
7809 | return false; | |
7810 | } | |
7811 | ||
7812 | return true; | |
7813 | } | |
7814 | ||
b54452b0 | 7815 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
7816 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
7817 | .len = NL80211_MAX_SUPP_RATES }, | |
d1e33e65 JD |
7818 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
7819 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
204e35a9 | 7820 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
0b9323f6 | 7821 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
13ae75b1 JM |
7822 | }; |
7823 | ||
7824 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
7825 | struct genl_info *info) | |
7826 | { | |
7827 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 7828 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 7829 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
7830 | int rem, i; |
7831 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
7832 | struct nlattr *tx_rates; |
7833 | struct ieee80211_supported_band *sband; | |
204e35a9 | 7834 | u16 vht_tx_mcs_map; |
13ae75b1 | 7835 | |
4c476991 JB |
7836 | if (!rdev->ops->set_bitrate_mask) |
7837 | return -EOPNOTSUPP; | |
13ae75b1 JM |
7838 | |
7839 | memset(&mask, 0, sizeof(mask)); | |
7840 | /* Default to all rates enabled */ | |
7841 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
7842 | sband = rdev->wiphy.bands[i]; | |
7869303b JD |
7843 | |
7844 | if (!sband) | |
7845 | continue; | |
7846 | ||
7847 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; | |
d1e33e65 | 7848 | memcpy(mask.control[i].ht_mcs, |
7869303b | 7849 | sband->ht_cap.mcs.rx_mask, |
d1e33e65 | 7850 | sizeof(mask.control[i].ht_mcs)); |
204e35a9 JD |
7851 | |
7852 | if (!sband->vht_cap.vht_supported) | |
7853 | continue; | |
7854 | ||
7855 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
7856 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); | |
13ae75b1 JM |
7857 | } |
7858 | ||
b9243ab0 JD |
7859 | /* if no rates are given set it back to the defaults */ |
7860 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
7861 | goto out; | |
7862 | ||
13ae75b1 JM |
7863 | /* |
7864 | * The nested attribute uses enum nl80211_band as the index. This maps | |
7865 | * directly to the enum ieee80211_band values used in cfg80211. | |
7866 | */ | |
24db78c0 | 7867 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
ae811e21 | 7868 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
13ae75b1 | 7869 | enum ieee80211_band band = nla_type(tx_rates); |
ae811e21 JB |
7870 | int err; |
7871 | ||
4c476991 JB |
7872 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
7873 | return -EINVAL; | |
13ae75b1 | 7874 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
7875 | if (sband == NULL) |
7876 | return -EINVAL; | |
ae811e21 JB |
7877 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
7878 | nla_len(tx_rates), nl80211_txattr_policy); | |
7879 | if (err) | |
7880 | return err; | |
13ae75b1 JM |
7881 | if (tb[NL80211_TXRATE_LEGACY]) { |
7882 | mask.control[band].legacy = rateset_to_mask( | |
7883 | sband, | |
7884 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
7885 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
7886 | if ((mask.control[band].legacy == 0) && |
7887 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
7888 | return -EINVAL; | |
24db78c0 | 7889 | } |
d1e33e65 | 7890 | if (tb[NL80211_TXRATE_HT]) { |
24db78c0 SW |
7891 | if (!ht_rateset_to_mask( |
7892 | sband, | |
d1e33e65 JD |
7893 | nla_data(tb[NL80211_TXRATE_HT]), |
7894 | nla_len(tb[NL80211_TXRATE_HT]), | |
7895 | mask.control[band].ht_mcs)) | |
24db78c0 SW |
7896 | return -EINVAL; |
7897 | } | |
204e35a9 JD |
7898 | if (tb[NL80211_TXRATE_VHT]) { |
7899 | if (!vht_set_mcs_mask( | |
7900 | sband, | |
7901 | nla_data(tb[NL80211_TXRATE_VHT]), | |
7902 | mask.control[band].vht_mcs)) | |
7903 | return -EINVAL; | |
7904 | } | |
0b9323f6 JD |
7905 | if (tb[NL80211_TXRATE_GI]) { |
7906 | mask.control[band].gi = | |
7907 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
7908 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
7909 | return -EINVAL; | |
7910 | } | |
24db78c0 SW |
7911 | |
7912 | if (mask.control[band].legacy == 0) { | |
204e35a9 JD |
7913 | /* don't allow empty legacy rates if HT or VHT |
7914 | * are not even supported. | |
7915 | */ | |
7916 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
7917 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
24db78c0 SW |
7918 | return -EINVAL; |
7919 | ||
7920 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
d1e33e65 | 7921 | if (mask.control[band].ht_mcs[i]) |
204e35a9 JD |
7922 | goto out; |
7923 | ||
7924 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
7925 | if (mask.control[band].vht_mcs[i]) | |
7926 | goto out; | |
24db78c0 SW |
7927 | |
7928 | /* legacy and mcs rates may not be both empty */ | |
204e35a9 | 7929 | return -EINVAL; |
13ae75b1 JM |
7930 | } |
7931 | } | |
7932 | ||
b9243ab0 | 7933 | out: |
e35e4d28 | 7934 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
7935 | } |
7936 | ||
2e161f78 | 7937 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7938 | { |
4c476991 | 7939 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7940 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 7941 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
7942 | |
7943 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
7944 | return -EINVAL; | |
7945 | ||
2e161f78 JB |
7946 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
7947 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 7948 | |
71bbc994 JB |
7949 | switch (wdev->iftype) { |
7950 | case NL80211_IFTYPE_STATION: | |
7951 | case NL80211_IFTYPE_ADHOC: | |
7952 | case NL80211_IFTYPE_P2P_CLIENT: | |
7953 | case NL80211_IFTYPE_AP: | |
7954 | case NL80211_IFTYPE_AP_VLAN: | |
7955 | case NL80211_IFTYPE_MESH_POINT: | |
7956 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7957 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7958 | break; |
7959 | default: | |
4c476991 | 7960 | return -EOPNOTSUPP; |
71bbc994 | 7961 | } |
026331c4 JM |
7962 | |
7963 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
7964 | if (!rdev->ops->mgmt_tx) |
7965 | return -EOPNOTSUPP; | |
026331c4 | 7966 | |
15e47304 | 7967 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
7968 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
7969 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
7970 | } |
7971 | ||
2e161f78 | 7972 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7973 | { |
4c476991 | 7974 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7975 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7976 | struct cfg80211_chan_def chandef; |
026331c4 | 7977 | int err; |
d64d373f | 7978 | void *hdr = NULL; |
026331c4 | 7979 | u64 cookie; |
e247bd90 | 7980 | struct sk_buff *msg = NULL; |
b176e629 AO |
7981 | struct cfg80211_mgmt_tx_params params = { |
7982 | .dont_wait_for_ack = | |
7983 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
7984 | }; | |
026331c4 | 7985 | |
683b6d3b | 7986 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
7987 | return -EINVAL; |
7988 | ||
4c476991 JB |
7989 | if (!rdev->ops->mgmt_tx) |
7990 | return -EOPNOTSUPP; | |
026331c4 | 7991 | |
71bbc994 | 7992 | switch (wdev->iftype) { |
ea141b75 AQ |
7993 | case NL80211_IFTYPE_P2P_DEVICE: |
7994 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
7995 | return -EINVAL; | |
71bbc994 JB |
7996 | case NL80211_IFTYPE_STATION: |
7997 | case NL80211_IFTYPE_ADHOC: | |
7998 | case NL80211_IFTYPE_P2P_CLIENT: | |
7999 | case NL80211_IFTYPE_AP: | |
8000 | case NL80211_IFTYPE_AP_VLAN: | |
8001 | case NL80211_IFTYPE_MESH_POINT: | |
8002 | case NL80211_IFTYPE_P2P_GO: | |
8003 | break; | |
8004 | default: | |
4c476991 | 8005 | return -EOPNOTSUPP; |
71bbc994 | 8006 | } |
026331c4 | 8007 | |
f7ca38df | 8008 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 8009 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 8010 | return -EINVAL; |
b176e629 | 8011 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
8012 | |
8013 | /* | |
8014 | * We should wait on the channel for at least a minimum amount | |
8015 | * of time (10ms) but no longer than the driver supports. | |
8016 | */ | |
b176e629 AO |
8017 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
8018 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc JB |
8019 | return -EINVAL; |
8020 | ||
f7ca38df JB |
8021 | } |
8022 | ||
b176e629 | 8023 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 8024 | |
b176e629 | 8025 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
8026 | return -EINVAL; |
8027 | ||
b176e629 | 8028 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 8029 | |
ea141b75 AQ |
8030 | /* get the channel if any has been specified, otherwise pass NULL to |
8031 | * the driver. The latter will use the current one | |
8032 | */ | |
8033 | chandef.chan = NULL; | |
8034 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
8035 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
8036 | if (err) | |
8037 | return err; | |
8038 | } | |
8039 | ||
b176e629 | 8040 | if (!chandef.chan && params.offchan) |
ea141b75 | 8041 | return -EINVAL; |
026331c4 | 8042 | |
34d22ce2 AO |
8043 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
8044 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
8045 | ||
8046 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
8047 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8048 | int i; | |
8049 | ||
8050 | if (len % sizeof(u16)) | |
8051 | return -EINVAL; | |
8052 | ||
8053 | params.n_csa_offsets = len / sizeof(u16); | |
8054 | params.csa_offsets = | |
8055 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8056 | ||
8057 | /* check that all the offsets fit the frame */ | |
8058 | for (i = 0; i < params.n_csa_offsets; i++) { | |
8059 | if (params.csa_offsets[i] >= params.len) | |
8060 | return -EINVAL; | |
8061 | } | |
8062 | } | |
8063 | ||
b176e629 | 8064 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
8065 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
8066 | if (!msg) | |
8067 | return -ENOMEM; | |
026331c4 | 8068 | |
15e47304 | 8069 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 8070 | NL80211_CMD_FRAME); |
cb35fba3 DC |
8071 | if (!hdr) { |
8072 | err = -ENOBUFS; | |
e247bd90 JB |
8073 | goto free_msg; |
8074 | } | |
026331c4 | 8075 | } |
e247bd90 | 8076 | |
b176e629 AO |
8077 | params.chan = chandef.chan; |
8078 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
8079 | if (err) |
8080 | goto free_msg; | |
8081 | ||
e247bd90 | 8082 | if (msg) { |
9360ffd1 DM |
8083 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8084 | goto nla_put_failure; | |
026331c4 | 8085 | |
e247bd90 JB |
8086 | genlmsg_end(msg, hdr); |
8087 | return genlmsg_reply(msg, info); | |
8088 | } | |
8089 | ||
8090 | return 0; | |
026331c4 JM |
8091 | |
8092 | nla_put_failure: | |
8093 | err = -ENOBUFS; | |
8094 | free_msg: | |
8095 | nlmsg_free(msg); | |
026331c4 JM |
8096 | return err; |
8097 | } | |
8098 | ||
f7ca38df JB |
8099 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
8100 | { | |
8101 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 8102 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
8103 | u64 cookie; |
8104 | ||
8105 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8106 | return -EINVAL; | |
8107 | ||
8108 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
8109 | return -EOPNOTSUPP; | |
8110 | ||
71bbc994 JB |
8111 | switch (wdev->iftype) { |
8112 | case NL80211_IFTYPE_STATION: | |
8113 | case NL80211_IFTYPE_ADHOC: | |
8114 | case NL80211_IFTYPE_P2P_CLIENT: | |
8115 | case NL80211_IFTYPE_AP: | |
8116 | case NL80211_IFTYPE_AP_VLAN: | |
8117 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8118 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8119 | break; |
8120 | default: | |
f7ca38df | 8121 | return -EOPNOTSUPP; |
71bbc994 | 8122 | } |
f7ca38df JB |
8123 | |
8124 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
8125 | ||
e35e4d28 | 8126 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
8127 | } |
8128 | ||
ffb9eb3d KV |
8129 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
8130 | { | |
4c476991 | 8131 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 8132 | struct wireless_dev *wdev; |
4c476991 | 8133 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8134 | u8 ps_state; |
8135 | bool state; | |
8136 | int err; | |
8137 | ||
4c476991 JB |
8138 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
8139 | return -EINVAL; | |
ffb9eb3d KV |
8140 | |
8141 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
8142 | ||
4c476991 JB |
8143 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
8144 | return -EINVAL; | |
ffb9eb3d KV |
8145 | |
8146 | wdev = dev->ieee80211_ptr; | |
8147 | ||
4c476991 JB |
8148 | if (!rdev->ops->set_power_mgmt) |
8149 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8150 | |
8151 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
8152 | ||
8153 | if (state == wdev->ps) | |
4c476991 | 8154 | return 0; |
ffb9eb3d | 8155 | |
e35e4d28 | 8156 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
8157 | if (!err) |
8158 | wdev->ps = state; | |
ffb9eb3d KV |
8159 | return err; |
8160 | } | |
8161 | ||
8162 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
8163 | { | |
4c476991 | 8164 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
8165 | enum nl80211_ps_state ps_state; |
8166 | struct wireless_dev *wdev; | |
4c476991 | 8167 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8168 | struct sk_buff *msg; |
8169 | void *hdr; | |
8170 | int err; | |
8171 | ||
ffb9eb3d KV |
8172 | wdev = dev->ieee80211_ptr; |
8173 | ||
4c476991 JB |
8174 | if (!rdev->ops->set_power_mgmt) |
8175 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8176 | |
8177 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
8178 | if (!msg) |
8179 | return -ENOMEM; | |
ffb9eb3d | 8180 | |
15e47304 | 8181 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
8182 | NL80211_CMD_GET_POWER_SAVE); |
8183 | if (!hdr) { | |
4c476991 | 8184 | err = -ENOBUFS; |
ffb9eb3d KV |
8185 | goto free_msg; |
8186 | } | |
8187 | ||
8188 | if (wdev->ps) | |
8189 | ps_state = NL80211_PS_ENABLED; | |
8190 | else | |
8191 | ps_state = NL80211_PS_DISABLED; | |
8192 | ||
9360ffd1 DM |
8193 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
8194 | goto nla_put_failure; | |
ffb9eb3d KV |
8195 | |
8196 | genlmsg_end(msg, hdr); | |
4c476991 | 8197 | return genlmsg_reply(msg, info); |
ffb9eb3d | 8198 | |
4c476991 | 8199 | nla_put_failure: |
ffb9eb3d | 8200 | err = -ENOBUFS; |
4c476991 | 8201 | free_msg: |
ffb9eb3d | 8202 | nlmsg_free(msg); |
ffb9eb3d KV |
8203 | return err; |
8204 | } | |
8205 | ||
94e860f1 JB |
8206 | static const struct nla_policy |
8207 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
8208 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
8209 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
8210 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
8211 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
8212 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
8213 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
8214 | }; |
8215 | ||
84f10708 | 8216 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 8217 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
8218 | { |
8219 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 8220 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8221 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 8222 | |
d9d8b019 | 8223 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
8224 | return -EINVAL; |
8225 | ||
84f10708 TP |
8226 | if (!rdev->ops->set_cqm_txe_config) |
8227 | return -EOPNOTSUPP; | |
8228 | ||
8229 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
8230 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
8231 | return -EOPNOTSUPP; | |
8232 | ||
e35e4d28 | 8233 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
8234 | } |
8235 | ||
d6dc1a38 JO |
8236 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
8237 | s32 threshold, u32 hysteresis) | |
8238 | { | |
4c476991 | 8239 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 8240 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8241 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
8242 | |
8243 | if (threshold > 0) | |
8244 | return -EINVAL; | |
8245 | ||
1da5fcc8 JB |
8246 | /* disabling - hysteresis should also be zero then */ |
8247 | if (threshold == 0) | |
8248 | hysteresis = 0; | |
d6dc1a38 | 8249 | |
4c476991 JB |
8250 | if (!rdev->ops->set_cqm_rssi_config) |
8251 | return -EOPNOTSUPP; | |
d6dc1a38 | 8252 | |
074ac8df | 8253 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8254 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8255 | return -EOPNOTSUPP; | |
d6dc1a38 | 8256 | |
e35e4d28 | 8257 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
8258 | } |
8259 | ||
8260 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
8261 | { | |
8262 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
8263 | struct nlattr *cqm; | |
8264 | int err; | |
8265 | ||
8266 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
8267 | if (!cqm) |
8268 | return -EINVAL; | |
d6dc1a38 JO |
8269 | |
8270 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
8271 | nl80211_attr_cqm_policy); | |
8272 | if (err) | |
1da5fcc8 | 8273 | return err; |
d6dc1a38 JO |
8274 | |
8275 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
8276 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
8277 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
8278 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 8279 | |
1da5fcc8 JB |
8280 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
8281 | } | |
8282 | ||
8283 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
8284 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
8285 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
8286 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
8287 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
8288 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
8289 | ||
8290 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
8291 | } | |
8292 | ||
8293 | return -EINVAL; | |
d6dc1a38 JO |
8294 | } |
8295 | ||
6e0bd6c3 RL |
8296 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
8297 | { | |
8298 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8299 | struct net_device *dev = info->user_ptr[1]; | |
8300 | struct ocb_setup setup = {}; | |
8301 | int err; | |
8302 | ||
8303 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | |
8304 | if (err) | |
8305 | return err; | |
8306 | ||
8307 | return cfg80211_join_ocb(rdev, dev, &setup); | |
8308 | } | |
8309 | ||
8310 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | |
8311 | { | |
8312 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8313 | struct net_device *dev = info->user_ptr[1]; | |
8314 | ||
8315 | return cfg80211_leave_ocb(rdev, dev); | |
8316 | } | |
8317 | ||
29cbe68c JB |
8318 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
8319 | { | |
8320 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8321 | struct net_device *dev = info->user_ptr[1]; | |
8322 | struct mesh_config cfg; | |
c80d545d | 8323 | struct mesh_setup setup; |
29cbe68c JB |
8324 | int err; |
8325 | ||
8326 | /* start with default */ | |
8327 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 8328 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 8329 | |
24bdd9f4 | 8330 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 8331 | /* and parse parameters if given */ |
24bdd9f4 | 8332 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
8333 | if (err) |
8334 | return err; | |
8335 | } | |
8336 | ||
8337 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
8338 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
8339 | return -EINVAL; | |
8340 | ||
c80d545d JC |
8341 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
8342 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
8343 | ||
4bb62344 CYY |
8344 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8345 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
8346 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8347 | return -EINVAL; | |
8348 | ||
9bdbf04d MP |
8349 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
8350 | setup.beacon_interval = | |
8351 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
8352 | if (setup.beacon_interval < 10 || | |
8353 | setup.beacon_interval > 10000) | |
8354 | return -EINVAL; | |
8355 | } | |
8356 | ||
8357 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
8358 | setup.dtim_period = | |
8359 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
8360 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
8361 | return -EINVAL; | |
8362 | } | |
8363 | ||
c80d545d JC |
8364 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
8365 | /* parse additional setup parameters if given */ | |
8366 | err = nl80211_parse_mesh_setup(info, &setup); | |
8367 | if (err) | |
8368 | return err; | |
8369 | } | |
8370 | ||
d37bb18a TP |
8371 | if (setup.user_mpm) |
8372 | cfg.auto_open_plinks = false; | |
8373 | ||
cc1d2806 | 8374 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
8375 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
8376 | if (err) | |
8377 | return err; | |
cc1d2806 JB |
8378 | } else { |
8379 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 8380 | setup.chandef.chan = NULL; |
cc1d2806 JB |
8381 | } |
8382 | ||
ffb3cf30 AN |
8383 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8384 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8385 | int n_rates = | |
8386 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8387 | struct ieee80211_supported_band *sband; | |
8388 | ||
8389 | if (!setup.chandef.chan) | |
8390 | return -EINVAL; | |
8391 | ||
8392 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
8393 | ||
8394 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
8395 | &setup.basic_rates); | |
8396 | if (err) | |
8397 | return err; | |
8398 | } | |
8399 | ||
c80d545d | 8400 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
8401 | } |
8402 | ||
8403 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
8404 | { | |
8405 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8406 | struct net_device *dev = info->user_ptr[1]; | |
8407 | ||
8408 | return cfg80211_leave_mesh(rdev, dev); | |
8409 | } | |
8410 | ||
dfb89c56 | 8411 | #ifdef CONFIG_PM |
bb92d199 AK |
8412 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
8413 | struct cfg80211_registered_device *rdev) | |
8414 | { | |
6abb9cb9 | 8415 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
8416 | struct nlattr *nl_pats, *nl_pat; |
8417 | int i, pat_len; | |
8418 | ||
6abb9cb9 | 8419 | if (!wowlan->n_patterns) |
bb92d199 AK |
8420 | return 0; |
8421 | ||
8422 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
8423 | if (!nl_pats) | |
8424 | return -ENOBUFS; | |
8425 | ||
6abb9cb9 | 8426 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
8427 | nl_pat = nla_nest_start(msg, i + 1); |
8428 | if (!nl_pat) | |
8429 | return -ENOBUFS; | |
6abb9cb9 | 8430 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 8431 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 8432 | wowlan->patterns[i].mask) || |
50ac6607 AK |
8433 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
8434 | wowlan->patterns[i].pattern) || | |
8435 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 8436 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
8437 | return -ENOBUFS; |
8438 | nla_nest_end(msg, nl_pat); | |
8439 | } | |
8440 | nla_nest_end(msg, nl_pats); | |
8441 | ||
8442 | return 0; | |
8443 | } | |
8444 | ||
2a0e047e JB |
8445 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
8446 | struct cfg80211_wowlan_tcp *tcp) | |
8447 | { | |
8448 | struct nlattr *nl_tcp; | |
8449 | ||
8450 | if (!tcp) | |
8451 | return 0; | |
8452 | ||
8453 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
8454 | if (!nl_tcp) | |
8455 | return -ENOBUFS; | |
8456 | ||
8457 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
8458 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
8459 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
8460 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
8461 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
8462 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
8463 | tcp->payload_len, tcp->payload) || | |
8464 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
8465 | tcp->data_interval) || | |
8466 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
8467 | tcp->wake_len, tcp->wake_data) || | |
8468 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
8469 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
8470 | return -ENOBUFS; | |
8471 | ||
8472 | if (tcp->payload_seq.len && | |
8473 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
8474 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
8475 | return -ENOBUFS; | |
8476 | ||
8477 | if (tcp->payload_tok.len && | |
8478 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
8479 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
8480 | &tcp->payload_tok)) | |
8481 | return -ENOBUFS; | |
8482 | ||
e248ad30 JB |
8483 | nla_nest_end(msg, nl_tcp); |
8484 | ||
2a0e047e JB |
8485 | return 0; |
8486 | } | |
8487 | ||
ff1b6e69 JB |
8488 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
8489 | { | |
8490 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8491 | struct sk_buff *msg; | |
8492 | void *hdr; | |
2a0e047e | 8493 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 8494 | |
964dc9e2 | 8495 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
8496 | return -EOPNOTSUPP; |
8497 | ||
6abb9cb9 | 8498 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 8499 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
8500 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
8501 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
8502 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
8503 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
8504 | } |
8505 | ||
8506 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
8507 | if (!msg) |
8508 | return -ENOMEM; | |
8509 | ||
15e47304 | 8510 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
8511 | NL80211_CMD_GET_WOWLAN); |
8512 | if (!hdr) | |
8513 | goto nla_put_failure; | |
8514 | ||
6abb9cb9 | 8515 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
8516 | struct nlattr *nl_wowlan; |
8517 | ||
8518 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
8519 | if (!nl_wowlan) | |
8520 | goto nla_put_failure; | |
8521 | ||
6abb9cb9 | 8522 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 8523 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 8524 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 8525 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 8526 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 8527 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 8528 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 8529 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 8530 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 8531 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 8532 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 8533 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 8534 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
8535 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
8536 | goto nla_put_failure; | |
2a0e047e | 8537 | |
bb92d199 AK |
8538 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
8539 | goto nla_put_failure; | |
2a0e047e | 8540 | |
6abb9cb9 JB |
8541 | if (nl80211_send_wowlan_tcp(msg, |
8542 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e JB |
8543 | goto nla_put_failure; |
8544 | ||
ff1b6e69 JB |
8545 | nla_nest_end(msg, nl_wowlan); |
8546 | } | |
8547 | ||
8548 | genlmsg_end(msg, hdr); | |
8549 | return genlmsg_reply(msg, info); | |
8550 | ||
8551 | nla_put_failure: | |
8552 | nlmsg_free(msg); | |
8553 | return -ENOBUFS; | |
8554 | } | |
8555 | ||
2a0e047e JB |
8556 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
8557 | struct nlattr *attr, | |
8558 | struct cfg80211_wowlan *trig) | |
8559 | { | |
8560 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
8561 | struct cfg80211_wowlan_tcp *cfg; | |
8562 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
8563 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
8564 | u32 size; | |
8565 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
8566 | int err, port; | |
8567 | ||
964dc9e2 | 8568 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
8569 | return -EINVAL; |
8570 | ||
8571 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
8572 | nla_data(attr), nla_len(attr), | |
8573 | nl80211_wowlan_tcp_policy); | |
8574 | if (err) | |
8575 | return err; | |
8576 | ||
8577 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
8578 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
8579 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
8580 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
8581 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
8582 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
8583 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
8584 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
8585 | return -EINVAL; | |
8586 | ||
8587 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 8588 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
8589 | return -EINVAL; |
8590 | ||
8591 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 8592 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 8593 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
8594 | return -EINVAL; |
8595 | ||
8596 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 8597 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
8598 | return -EINVAL; |
8599 | ||
8600 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
8601 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
8602 | return -EINVAL; | |
8603 | ||
8604 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
8605 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8606 | ||
8607 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8608 | tokens_size = tokln - sizeof(*tok); | |
8609 | ||
8610 | if (!tok->len || tokens_size % tok->len) | |
8611 | return -EINVAL; | |
964dc9e2 | 8612 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 8613 | return -EINVAL; |
964dc9e2 | 8614 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 8615 | return -EINVAL; |
964dc9e2 | 8616 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 8617 | return -EINVAL; |
964dc9e2 | 8618 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
8619 | return -EINVAL; |
8620 | if (tok->offset + tok->len > data_size) | |
8621 | return -EINVAL; | |
8622 | } | |
8623 | ||
8624 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
8625 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 8626 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
8627 | return -EINVAL; |
8628 | if (seq->len == 0 || seq->len > 4) | |
8629 | return -EINVAL; | |
8630 | if (seq->len + seq->offset > data_size) | |
8631 | return -EINVAL; | |
8632 | } | |
8633 | ||
8634 | size = sizeof(*cfg); | |
8635 | size += data_size; | |
8636 | size += wake_size + wake_mask_size; | |
8637 | size += tokens_size; | |
8638 | ||
8639 | cfg = kzalloc(size, GFP_KERNEL); | |
8640 | if (!cfg) | |
8641 | return -ENOMEM; | |
8642 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
8643 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
8644 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
8645 | ETH_ALEN); | |
8646 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
8647 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
8648 | else | |
8649 | port = 0; | |
8650 | #ifdef CONFIG_INET | |
8651 | /* allocate a socket and port for it and use it */ | |
8652 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
8653 | IPPROTO_TCP, &cfg->sock, 1); | |
8654 | if (err) { | |
8655 | kfree(cfg); | |
8656 | return err; | |
8657 | } | |
8658 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
8659 | sock_release(cfg->sock); | |
8660 | kfree(cfg); | |
8661 | return -EADDRINUSE; | |
8662 | } | |
8663 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
8664 | #else | |
8665 | if (!port) { | |
8666 | kfree(cfg); | |
8667 | return -EINVAL; | |
8668 | } | |
8669 | cfg->src_port = port; | |
8670 | #endif | |
8671 | ||
8672 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
8673 | cfg->payload_len = data_size; | |
8674 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
8675 | memcpy((void *)cfg->payload, | |
8676 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
8677 | data_size); | |
8678 | if (seq) | |
8679 | cfg->payload_seq = *seq; | |
8680 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
8681 | cfg->wake_len = wake_size; | |
8682 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
8683 | memcpy((void *)cfg->wake_data, | |
8684 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
8685 | wake_size); | |
8686 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
8687 | data_size + wake_size; | |
8688 | memcpy((void *)cfg->wake_mask, | |
8689 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
8690 | wake_mask_size); | |
8691 | if (tok) { | |
8692 | cfg->tokens_size = tokens_size; | |
8693 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
8694 | } | |
8695 | ||
8696 | trig->tcp = cfg; | |
8697 | ||
8698 | return 0; | |
8699 | } | |
8700 | ||
8cd4d456 LC |
8701 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
8702 | const struct wiphy_wowlan_support *wowlan, | |
8703 | struct nlattr *attr, | |
8704 | struct cfg80211_wowlan *trig) | |
8705 | { | |
8706 | struct nlattr **tb; | |
8707 | int err; | |
8708 | ||
8709 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); | |
8710 | if (!tb) | |
8711 | return -ENOMEM; | |
8712 | ||
8713 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | |
8714 | err = -EOPNOTSUPP; | |
8715 | goto out; | |
8716 | } | |
8717 | ||
8718 | err = nla_parse(tb, NL80211_ATTR_MAX, | |
8719 | nla_data(attr), nla_len(attr), | |
8720 | nl80211_policy); | |
8721 | if (err) | |
8722 | goto out; | |
8723 | ||
8724 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, tb); | |
8725 | err = PTR_ERR_OR_ZERO(trig->nd_config); | |
8726 | if (err) | |
8727 | trig->nd_config = NULL; | |
8728 | ||
8729 | out: | |
8730 | kfree(tb); | |
8731 | return err; | |
8732 | } | |
8733 | ||
ff1b6e69 JB |
8734 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
8735 | { | |
8736 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8737 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 8738 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 8739 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 8740 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 8741 | int err, i; |
6abb9cb9 | 8742 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 8743 | |
964dc9e2 | 8744 | if (!wowlan) |
ff1b6e69 JB |
8745 | return -EOPNOTSUPP; |
8746 | ||
ae33bd81 JB |
8747 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
8748 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 8749 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
8750 | goto set_wakeup; |
8751 | } | |
ff1b6e69 JB |
8752 | |
8753 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
8754 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8755 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8756 | nl80211_wowlan_policy); | |
8757 | if (err) | |
8758 | return err; | |
8759 | ||
8760 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
8761 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
8762 | return -EINVAL; | |
8763 | new_triggers.any = true; | |
8764 | } | |
8765 | ||
8766 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
8767 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
8768 | return -EINVAL; | |
8769 | new_triggers.disconnect = true; | |
8770 | } | |
8771 | ||
8772 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
8773 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
8774 | return -EINVAL; | |
8775 | new_triggers.magic_pkt = true; | |
8776 | } | |
8777 | ||
77dbbb13 JB |
8778 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
8779 | return -EINVAL; | |
8780 | ||
8781 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
8782 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
8783 | return -EINVAL; | |
8784 | new_triggers.gtk_rekey_failure = true; | |
8785 | } | |
8786 | ||
8787 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
8788 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
8789 | return -EINVAL; | |
8790 | new_triggers.eap_identity_req = true; | |
8791 | } | |
8792 | ||
8793 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
8794 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
8795 | return -EINVAL; | |
8796 | new_triggers.four_way_handshake = true; | |
8797 | } | |
8798 | ||
8799 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
8800 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
8801 | return -EINVAL; | |
8802 | new_triggers.rfkill_release = true; | |
8803 | } | |
8804 | ||
ff1b6e69 JB |
8805 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
8806 | struct nlattr *pat; | |
8807 | int n_patterns = 0; | |
bb92d199 | 8808 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 8809 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 JB |
8810 | |
8811 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8812 | rem) | |
8813 | n_patterns++; | |
8814 | if (n_patterns > wowlan->n_patterns) | |
8815 | return -EINVAL; | |
8816 | ||
8817 | new_triggers.patterns = kcalloc(n_patterns, | |
8818 | sizeof(new_triggers.patterns[0]), | |
8819 | GFP_KERNEL); | |
8820 | if (!new_triggers.patterns) | |
8821 | return -ENOMEM; | |
8822 | ||
8823 | new_triggers.n_patterns = n_patterns; | |
8824 | i = 0; | |
8825 | ||
8826 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8827 | rem) { | |
922bd80f JB |
8828 | u8 *mask_pat; |
8829 | ||
50ac6607 AK |
8830 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
8831 | nla_len(pat), NULL); | |
ff1b6e69 | 8832 | err = -EINVAL; |
50ac6607 AK |
8833 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
8834 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 8835 | goto error; |
50ac6607 | 8836 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 8837 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 8838 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
8839 | goto error; |
8840 | if (pat_len > wowlan->pattern_max_len || | |
8841 | pat_len < wowlan->pattern_min_len) | |
8842 | goto error; | |
8843 | ||
50ac6607 | 8844 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
8845 | pkt_offset = 0; |
8846 | else | |
8847 | pkt_offset = nla_get_u32( | |
50ac6607 | 8848 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
8849 | if (pkt_offset > wowlan->max_pkt_offset) |
8850 | goto error; | |
8851 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
8852 | ||
922bd80f JB |
8853 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
8854 | if (!mask_pat) { | |
ff1b6e69 JB |
8855 | err = -ENOMEM; |
8856 | goto error; | |
8857 | } | |
922bd80f JB |
8858 | new_triggers.patterns[i].mask = mask_pat; |
8859 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 8860 | mask_len); |
922bd80f JB |
8861 | mask_pat += mask_len; |
8862 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 8863 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 8864 | memcpy(mask_pat, |
50ac6607 | 8865 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
8866 | pat_len); |
8867 | i++; | |
8868 | } | |
8869 | } | |
8870 | ||
2a0e047e JB |
8871 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
8872 | err = nl80211_parse_wowlan_tcp( | |
8873 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
8874 | &new_triggers); | |
8875 | if (err) | |
8876 | goto error; | |
8877 | } | |
8878 | ||
8cd4d456 LC |
8879 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
8880 | err = nl80211_parse_wowlan_nd( | |
8881 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | |
8882 | &new_triggers); | |
8883 | if (err) | |
8884 | goto error; | |
8885 | } | |
8886 | ||
ae33bd81 JB |
8887 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
8888 | if (!ntrig) { | |
8889 | err = -ENOMEM; | |
8890 | goto error; | |
ff1b6e69 | 8891 | } |
ae33bd81 | 8892 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 8893 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 8894 | |
ae33bd81 | 8895 | set_wakeup: |
6abb9cb9 JB |
8896 | if (rdev->ops->set_wakeup && |
8897 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
8898 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 8899 | |
ff1b6e69 JB |
8900 | return 0; |
8901 | error: | |
8902 | for (i = 0; i < new_triggers.n_patterns; i++) | |
8903 | kfree(new_triggers.patterns[i].mask); | |
8904 | kfree(new_triggers.patterns); | |
2a0e047e JB |
8905 | if (new_triggers.tcp && new_triggers.tcp->sock) |
8906 | sock_release(new_triggers.tcp->sock); | |
8907 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
8908 | return err; |
8909 | } | |
dfb89c56 | 8910 | #endif |
ff1b6e69 | 8911 | |
be29b99a AK |
8912 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
8913 | struct cfg80211_registered_device *rdev) | |
8914 | { | |
8915 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
8916 | int i, j, pat_len; | |
8917 | struct cfg80211_coalesce_rules *rule; | |
8918 | ||
8919 | if (!rdev->coalesce->n_rules) | |
8920 | return 0; | |
8921 | ||
8922 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
8923 | if (!nl_rules) | |
8924 | return -ENOBUFS; | |
8925 | ||
8926 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
8927 | nl_rule = nla_nest_start(msg, i + 1); | |
8928 | if (!nl_rule) | |
8929 | return -ENOBUFS; | |
8930 | ||
8931 | rule = &rdev->coalesce->rules[i]; | |
8932 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
8933 | rule->delay)) | |
8934 | return -ENOBUFS; | |
8935 | ||
8936 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
8937 | rule->condition)) | |
8938 | return -ENOBUFS; | |
8939 | ||
8940 | nl_pats = nla_nest_start(msg, | |
8941 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
8942 | if (!nl_pats) | |
8943 | return -ENOBUFS; | |
8944 | ||
8945 | for (j = 0; j < rule->n_patterns; j++) { | |
8946 | nl_pat = nla_nest_start(msg, j + 1); | |
8947 | if (!nl_pat) | |
8948 | return -ENOBUFS; | |
8949 | pat_len = rule->patterns[j].pattern_len; | |
8950 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
8951 | DIV_ROUND_UP(pat_len, 8), | |
8952 | rule->patterns[j].mask) || | |
8953 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
8954 | rule->patterns[j].pattern) || | |
8955 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
8956 | rule->patterns[j].pkt_offset)) | |
8957 | return -ENOBUFS; | |
8958 | nla_nest_end(msg, nl_pat); | |
8959 | } | |
8960 | nla_nest_end(msg, nl_pats); | |
8961 | nla_nest_end(msg, nl_rule); | |
8962 | } | |
8963 | nla_nest_end(msg, nl_rules); | |
8964 | ||
8965 | return 0; | |
8966 | } | |
8967 | ||
8968 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8969 | { | |
8970 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8971 | struct sk_buff *msg; | |
8972 | void *hdr; | |
8973 | ||
8974 | if (!rdev->wiphy.coalesce) | |
8975 | return -EOPNOTSUPP; | |
8976 | ||
8977 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8978 | if (!msg) | |
8979 | return -ENOMEM; | |
8980 | ||
8981 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8982 | NL80211_CMD_GET_COALESCE); | |
8983 | if (!hdr) | |
8984 | goto nla_put_failure; | |
8985 | ||
8986 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
8987 | goto nla_put_failure; | |
8988 | ||
8989 | genlmsg_end(msg, hdr); | |
8990 | return genlmsg_reply(msg, info); | |
8991 | ||
8992 | nla_put_failure: | |
8993 | nlmsg_free(msg); | |
8994 | return -ENOBUFS; | |
8995 | } | |
8996 | ||
8997 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
8998 | { | |
8999 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
9000 | int i, j; | |
9001 | struct cfg80211_coalesce_rules *rule; | |
9002 | ||
9003 | if (!coalesce) | |
9004 | return; | |
9005 | ||
9006 | for (i = 0; i < coalesce->n_rules; i++) { | |
9007 | rule = &coalesce->rules[i]; | |
9008 | for (j = 0; j < rule->n_patterns; j++) | |
9009 | kfree(rule->patterns[j].mask); | |
9010 | kfree(rule->patterns); | |
9011 | } | |
9012 | kfree(coalesce->rules); | |
9013 | kfree(coalesce); | |
9014 | rdev->coalesce = NULL; | |
9015 | } | |
9016 | ||
9017 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
9018 | struct nlattr *rule, | |
9019 | struct cfg80211_coalesce_rules *new_rule) | |
9020 | { | |
9021 | int err, i; | |
9022 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9023 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
9024 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
9025 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
9026 | ||
9027 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
9028 | nla_len(rule), nl80211_coalesce_policy); | |
9029 | if (err) | |
9030 | return err; | |
9031 | ||
9032 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
9033 | new_rule->delay = | |
9034 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
9035 | if (new_rule->delay > coalesce->max_delay) | |
9036 | return -EINVAL; | |
9037 | ||
9038 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
9039 | new_rule->condition = | |
9040 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
9041 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
9042 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
9043 | return -EINVAL; | |
9044 | ||
9045 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
9046 | return -EINVAL; | |
9047 | ||
9048 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9049 | rem) | |
9050 | n_patterns++; | |
9051 | if (n_patterns > coalesce->n_patterns) | |
9052 | return -EINVAL; | |
9053 | ||
9054 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
9055 | GFP_KERNEL); | |
9056 | if (!new_rule->patterns) | |
9057 | return -ENOMEM; | |
9058 | ||
9059 | new_rule->n_patterns = n_patterns; | |
9060 | i = 0; | |
9061 | ||
9062 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9063 | rem) { | |
922bd80f JB |
9064 | u8 *mask_pat; |
9065 | ||
be29b99a AK |
9066 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9067 | nla_len(pat), NULL); | |
9068 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
9069 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
9070 | return -EINVAL; | |
9071 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
9072 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
9073 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
9074 | return -EINVAL; | |
9075 | if (pat_len > coalesce->pattern_max_len || | |
9076 | pat_len < coalesce->pattern_min_len) | |
9077 | return -EINVAL; | |
9078 | ||
9079 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
9080 | pkt_offset = 0; | |
9081 | else | |
9082 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
9083 | if (pkt_offset > coalesce->max_pkt_offset) | |
9084 | return -EINVAL; | |
9085 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
9086 | ||
922bd80f JB |
9087 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9088 | if (!mask_pat) | |
be29b99a | 9089 | return -ENOMEM; |
922bd80f JB |
9090 | |
9091 | new_rule->patterns[i].mask = mask_pat; | |
9092 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
9093 | mask_len); | |
9094 | ||
9095 | mask_pat += mask_len; | |
9096 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 9097 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
9098 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
9099 | pat_len); | |
be29b99a AK |
9100 | i++; |
9101 | } | |
9102 | ||
9103 | return 0; | |
9104 | } | |
9105 | ||
9106 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9107 | { | |
9108 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9109 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9110 | struct cfg80211_coalesce new_coalesce = {}; | |
9111 | struct cfg80211_coalesce *n_coalesce; | |
9112 | int err, rem_rule, n_rules = 0, i, j; | |
9113 | struct nlattr *rule; | |
9114 | struct cfg80211_coalesce_rules *tmp_rule; | |
9115 | ||
9116 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
9117 | return -EOPNOTSUPP; | |
9118 | ||
9119 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
9120 | cfg80211_rdev_free_coalesce(rdev); | |
9121 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
9122 | return 0; | |
9123 | } | |
9124 | ||
9125 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9126 | rem_rule) | |
9127 | n_rules++; | |
9128 | if (n_rules > coalesce->n_rules) | |
9129 | return -EINVAL; | |
9130 | ||
9131 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
9132 | GFP_KERNEL); | |
9133 | if (!new_coalesce.rules) | |
9134 | return -ENOMEM; | |
9135 | ||
9136 | new_coalesce.n_rules = n_rules; | |
9137 | i = 0; | |
9138 | ||
9139 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9140 | rem_rule) { | |
9141 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
9142 | &new_coalesce.rules[i]); | |
9143 | if (err) | |
9144 | goto error; | |
9145 | ||
9146 | i++; | |
9147 | } | |
9148 | ||
9149 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
9150 | if (err) | |
9151 | goto error; | |
9152 | ||
9153 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
9154 | if (!n_coalesce) { | |
9155 | err = -ENOMEM; | |
9156 | goto error; | |
9157 | } | |
9158 | cfg80211_rdev_free_coalesce(rdev); | |
9159 | rdev->coalesce = n_coalesce; | |
9160 | ||
9161 | return 0; | |
9162 | error: | |
9163 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
9164 | tmp_rule = &new_coalesce.rules[i]; | |
9165 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
9166 | kfree(tmp_rule->patterns[j].mask); | |
9167 | kfree(tmp_rule->patterns); | |
9168 | } | |
9169 | kfree(new_coalesce.rules); | |
9170 | ||
9171 | return err; | |
9172 | } | |
9173 | ||
e5497d76 JB |
9174 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
9175 | { | |
9176 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9177 | struct net_device *dev = info->user_ptr[1]; | |
9178 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9179 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
9180 | struct cfg80211_gtk_rekey_data rekey_data; | |
9181 | int err; | |
9182 | ||
9183 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
9184 | return -EINVAL; | |
9185 | ||
9186 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
9187 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9188 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9189 | nl80211_rekey_policy); | |
9190 | if (err) | |
9191 | return err; | |
9192 | ||
9193 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
9194 | return -ERANGE; | |
9195 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
9196 | return -ERANGE; | |
9197 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
9198 | return -ERANGE; | |
9199 | ||
78f686ca JB |
9200 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
9201 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | |
9202 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | |
e5497d76 JB |
9203 | |
9204 | wdev_lock(wdev); | |
9205 | if (!wdev->current_bss) { | |
9206 | err = -ENOTCONN; | |
9207 | goto out; | |
9208 | } | |
9209 | ||
9210 | if (!rdev->ops->set_rekey_data) { | |
9211 | err = -EOPNOTSUPP; | |
9212 | goto out; | |
9213 | } | |
9214 | ||
e35e4d28 | 9215 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
9216 | out: |
9217 | wdev_unlock(wdev); | |
9218 | return err; | |
9219 | } | |
9220 | ||
28946da7 JB |
9221 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
9222 | struct genl_info *info) | |
9223 | { | |
9224 | struct net_device *dev = info->user_ptr[1]; | |
9225 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9226 | ||
9227 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9228 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9229 | return -EINVAL; | |
9230 | ||
15e47304 | 9231 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
9232 | return -EBUSY; |
9233 | ||
15e47304 | 9234 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
9235 | return 0; |
9236 | } | |
9237 | ||
7f6cf311 JB |
9238 | static int nl80211_probe_client(struct sk_buff *skb, |
9239 | struct genl_info *info) | |
9240 | { | |
9241 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9242 | struct net_device *dev = info->user_ptr[1]; | |
9243 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9244 | struct sk_buff *msg; | |
9245 | void *hdr; | |
9246 | const u8 *addr; | |
9247 | u64 cookie; | |
9248 | int err; | |
9249 | ||
9250 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9251 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9252 | return -EOPNOTSUPP; | |
9253 | ||
9254 | if (!info->attrs[NL80211_ATTR_MAC]) | |
9255 | return -EINVAL; | |
9256 | ||
9257 | if (!rdev->ops->probe_client) | |
9258 | return -EOPNOTSUPP; | |
9259 | ||
9260 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9261 | if (!msg) | |
9262 | return -ENOMEM; | |
9263 | ||
15e47304 | 9264 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 9265 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
9266 | if (!hdr) { |
9267 | err = -ENOBUFS; | |
7f6cf311 JB |
9268 | goto free_msg; |
9269 | } | |
9270 | ||
9271 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9272 | ||
e35e4d28 | 9273 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
9274 | if (err) |
9275 | goto free_msg; | |
9276 | ||
9360ffd1 DM |
9277 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9278 | goto nla_put_failure; | |
7f6cf311 JB |
9279 | |
9280 | genlmsg_end(msg, hdr); | |
9281 | ||
9282 | return genlmsg_reply(msg, info); | |
9283 | ||
9284 | nla_put_failure: | |
9285 | err = -ENOBUFS; | |
9286 | free_msg: | |
9287 | nlmsg_free(msg); | |
9288 | return err; | |
9289 | } | |
9290 | ||
5e760230 JB |
9291 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
9292 | { | |
9293 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
9294 | struct cfg80211_beacon_registration *reg, *nreg; |
9295 | int rv; | |
5e760230 JB |
9296 | |
9297 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
9298 | return -EOPNOTSUPP; | |
9299 | ||
37c73b5f BG |
9300 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
9301 | if (!nreg) | |
9302 | return -ENOMEM; | |
9303 | ||
9304 | /* First, check if already registered. */ | |
9305 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
9306 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
9307 | if (reg->nlportid == info->snd_portid) { | |
9308 | rv = -EALREADY; | |
9309 | goto out_err; | |
9310 | } | |
9311 | } | |
9312 | /* Add it to the list */ | |
9313 | nreg->nlportid = info->snd_portid; | |
9314 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 9315 | |
37c73b5f | 9316 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
9317 | |
9318 | return 0; | |
37c73b5f BG |
9319 | out_err: |
9320 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
9321 | kfree(nreg); | |
9322 | return rv; | |
5e760230 JB |
9323 | } |
9324 | ||
98104fde JB |
9325 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
9326 | { | |
9327 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9328 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9329 | int err; | |
9330 | ||
9331 | if (!rdev->ops->start_p2p_device) | |
9332 | return -EOPNOTSUPP; | |
9333 | ||
9334 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9335 | return -EOPNOTSUPP; | |
9336 | ||
9337 | if (wdev->p2p_started) | |
9338 | return 0; | |
9339 | ||
b6a55015 LC |
9340 | if (rfkill_blocked(rdev->rfkill)) |
9341 | return -ERFKILL; | |
98104fde | 9342 | |
eeb126e9 | 9343 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
9344 | if (err) |
9345 | return err; | |
9346 | ||
9347 | wdev->p2p_started = true; | |
98104fde | 9348 | rdev->opencount++; |
98104fde JB |
9349 | |
9350 | return 0; | |
9351 | } | |
9352 | ||
9353 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
9354 | { | |
9355 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9356 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9357 | ||
9358 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9359 | return -EOPNOTSUPP; | |
9360 | ||
9361 | if (!rdev->ops->stop_p2p_device) | |
9362 | return -EOPNOTSUPP; | |
9363 | ||
f9f47529 | 9364 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
9365 | |
9366 | return 0; | |
9367 | } | |
9368 | ||
3713b4e3 JB |
9369 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
9370 | struct genl_info *info) | |
9371 | { | |
9372 | void *hdr; | |
9373 | struct sk_buff *msg; | |
9374 | ||
9375 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9376 | if (!msg) | |
9377 | return -ENOMEM; | |
9378 | ||
9379 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9380 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
9381 | if (!hdr) | |
9382 | goto nla_put_failure; | |
9383 | ||
9384 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
9385 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
9386 | goto nla_put_failure; | |
9387 | ||
9388 | genlmsg_end(msg, hdr); | |
9389 | return genlmsg_reply(msg, info); | |
9390 | ||
9391 | nla_put_failure: | |
9392 | kfree_skb(msg); | |
9393 | return -ENOBUFS; | |
9394 | } | |
9395 | ||
355199e0 JM |
9396 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
9397 | { | |
9398 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9399 | struct cfg80211_update_ft_ies_params ft_params; | |
9400 | struct net_device *dev = info->user_ptr[1]; | |
9401 | ||
9402 | if (!rdev->ops->update_ft_ies) | |
9403 | return -EOPNOTSUPP; | |
9404 | ||
9405 | if (!info->attrs[NL80211_ATTR_MDID] || | |
9406 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
9407 | return -EINVAL; | |
9408 | ||
9409 | memset(&ft_params, 0, sizeof(ft_params)); | |
9410 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
9411 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
9412 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9413 | ||
9414 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
9415 | } | |
9416 | ||
5de17984 AS |
9417 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
9418 | struct genl_info *info) | |
9419 | { | |
9420 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9421 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9422 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
9423 | u16 duration; | |
9424 | int ret; | |
9425 | ||
9426 | if (!rdev->ops->crit_proto_start) | |
9427 | return -EOPNOTSUPP; | |
9428 | ||
9429 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
9430 | return -EINVAL; | |
9431 | ||
9432 | if (rdev->crit_proto_nlportid) | |
9433 | return -EBUSY; | |
9434 | ||
9435 | /* determine protocol if provided */ | |
9436 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
9437 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
9438 | ||
9439 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
9440 | return -EINVAL; | |
9441 | ||
9442 | /* timeout must be provided */ | |
9443 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
9444 | return -EINVAL; | |
9445 | ||
9446 | duration = | |
9447 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
9448 | ||
9449 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
9450 | return -ERANGE; | |
9451 | ||
9452 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
9453 | if (!ret) | |
9454 | rdev->crit_proto_nlportid = info->snd_portid; | |
9455 | ||
9456 | return ret; | |
9457 | } | |
9458 | ||
9459 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
9460 | struct genl_info *info) | |
9461 | { | |
9462 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9463 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9464 | ||
9465 | if (!rdev->ops->crit_proto_stop) | |
9466 | return -EOPNOTSUPP; | |
9467 | ||
9468 | if (rdev->crit_proto_nlportid) { | |
9469 | rdev->crit_proto_nlportid = 0; | |
9470 | rdev_crit_proto_stop(rdev, wdev); | |
9471 | } | |
9472 | return 0; | |
9473 | } | |
9474 | ||
ad7e718c JB |
9475 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
9476 | { | |
9477 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9478 | struct wireless_dev *wdev = | |
9479 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
9480 | int i, err; | |
9481 | u32 vid, subcmd; | |
9482 | ||
9483 | if (!rdev->wiphy.vendor_commands) | |
9484 | return -EOPNOTSUPP; | |
9485 | ||
9486 | if (IS_ERR(wdev)) { | |
9487 | err = PTR_ERR(wdev); | |
9488 | if (err != -EINVAL) | |
9489 | return err; | |
9490 | wdev = NULL; | |
9491 | } else if (wdev->wiphy != &rdev->wiphy) { | |
9492 | return -EINVAL; | |
9493 | } | |
9494 | ||
9495 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
9496 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
9497 | return -EINVAL; | |
9498 | ||
9499 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
9500 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
9501 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
9502 | const struct wiphy_vendor_command *vcmd; | |
9503 | void *data = NULL; | |
9504 | int len = 0; | |
9505 | ||
9506 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
9507 | ||
9508 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
9509 | continue; | |
9510 | ||
9511 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
9512 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
9513 | if (!wdev) | |
9514 | return -EINVAL; | |
9515 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
9516 | !wdev->netdev) | |
9517 | return -EINVAL; | |
9518 | ||
9519 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
9520 | if (wdev->netdev && | |
9521 | !netif_running(wdev->netdev)) | |
9522 | return -ENETDOWN; | |
9523 | if (!wdev->netdev && !wdev->p2p_started) | |
9524 | return -ENETDOWN; | |
9525 | } | |
9526 | } else { | |
9527 | wdev = NULL; | |
9528 | } | |
9529 | ||
9530 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
9531 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9532 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9533 | } | |
9534 | ||
9535 | rdev->cur_cmd_info = info; | |
9536 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
9537 | data, len); | |
9538 | rdev->cur_cmd_info = NULL; | |
9539 | return err; | |
9540 | } | |
9541 | ||
9542 | return -EOPNOTSUPP; | |
9543 | } | |
9544 | ||
9545 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | |
9546 | enum nl80211_commands cmd, | |
9547 | enum nl80211_attrs attr, | |
9548 | int approxlen) | |
9549 | { | |
f26cbf40 | 9550 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
9551 | |
9552 | if (WARN_ON(!rdev->cur_cmd_info)) | |
9553 | return NULL; | |
9554 | ||
9555 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, | |
9556 | rdev->cur_cmd_info->snd_portid, | |
9557 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 9558 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
9559 | } |
9560 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
9561 | ||
9562 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
9563 | { | |
9564 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
9565 | void *hdr = ((void **)skb->cb)[1]; | |
9566 | struct nlattr *data = ((void **)skb->cb)[2]; | |
9567 | ||
bd8c78e7 JB |
9568 | /* clear CB data for netlink core to own from now on */ |
9569 | memset(skb->cb, 0, sizeof(skb->cb)); | |
9570 | ||
ad7e718c JB |
9571 | if (WARN_ON(!rdev->cur_cmd_info)) { |
9572 | kfree_skb(skb); | |
9573 | return -EINVAL; | |
9574 | } | |
9575 | ||
9576 | nla_nest_end(skb, data); | |
9577 | genlmsg_end(skb, hdr); | |
9578 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
9579 | } | |
9580 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
9581 | ||
9582 | ||
fa9ffc74 KP |
9583 | static int nl80211_set_qos_map(struct sk_buff *skb, |
9584 | struct genl_info *info) | |
9585 | { | |
9586 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9587 | struct cfg80211_qos_map *qos_map = NULL; | |
9588 | struct net_device *dev = info->user_ptr[1]; | |
9589 | u8 *pos, len, num_des, des_len, des; | |
9590 | int ret; | |
9591 | ||
9592 | if (!rdev->ops->set_qos_map) | |
9593 | return -EOPNOTSUPP; | |
9594 | ||
9595 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
9596 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9597 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9598 | ||
9599 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
9600 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
9601 | return -EINVAL; | |
9602 | ||
9603 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
9604 | if (!qos_map) | |
9605 | return -ENOMEM; | |
9606 | ||
9607 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
9608 | if (num_des) { | |
9609 | des_len = num_des * | |
9610 | sizeof(struct cfg80211_dscp_exception); | |
9611 | memcpy(qos_map->dscp_exception, pos, des_len); | |
9612 | qos_map->num_des = num_des; | |
9613 | for (des = 0; des < num_des; des++) { | |
9614 | if (qos_map->dscp_exception[des].up > 7) { | |
9615 | kfree(qos_map); | |
9616 | return -EINVAL; | |
9617 | } | |
9618 | } | |
9619 | pos += des_len; | |
9620 | } | |
9621 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
9622 | } | |
9623 | ||
9624 | wdev_lock(dev->ieee80211_ptr); | |
9625 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
9626 | if (!ret) | |
9627 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
9628 | wdev_unlock(dev->ieee80211_ptr); | |
9629 | ||
9630 | kfree(qos_map); | |
9631 | return ret; | |
9632 | } | |
9633 | ||
960d01ac JB |
9634 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
9635 | { | |
9636 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9637 | struct net_device *dev = info->user_ptr[1]; | |
9638 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9639 | const u8 *peer; | |
9640 | u8 tsid, up; | |
9641 | u16 admitted_time = 0; | |
9642 | int err; | |
9643 | ||
723e73ac | 9644 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
960d01ac JB |
9645 | return -EOPNOTSUPP; |
9646 | ||
9647 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | |
9648 | !info->attrs[NL80211_ATTR_USER_PRIO]) | |
9649 | return -EINVAL; | |
9650 | ||
9651 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
9652 | if (tsid >= IEEE80211_NUM_TIDS) | |
9653 | return -EINVAL; | |
9654 | ||
9655 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); | |
9656 | if (up >= IEEE80211_NUM_UPS) | |
9657 | return -EINVAL; | |
9658 | ||
9659 | /* WMM uses TIDs 0-7 even for TSPEC */ | |
723e73ac | 9660 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
960d01ac | 9661 | /* TODO: handle 802.11 TSPEC/admission control |
723e73ac JB |
9662 | * need more attributes for that (e.g. BA session requirement); |
9663 | * change the WMM adminssion test above to allow both then | |
960d01ac JB |
9664 | */ |
9665 | return -EINVAL; | |
9666 | } | |
9667 | ||
9668 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9669 | ||
9670 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | |
9671 | admitted_time = | |
9672 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | |
9673 | if (!admitted_time) | |
9674 | return -EINVAL; | |
9675 | } | |
9676 | ||
9677 | wdev_lock(wdev); | |
9678 | switch (wdev->iftype) { | |
9679 | case NL80211_IFTYPE_STATION: | |
9680 | case NL80211_IFTYPE_P2P_CLIENT: | |
9681 | if (wdev->current_bss) | |
9682 | break; | |
9683 | err = -ENOTCONN; | |
9684 | goto out; | |
9685 | default: | |
9686 | err = -EOPNOTSUPP; | |
9687 | goto out; | |
9688 | } | |
9689 | ||
9690 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | |
9691 | ||
9692 | out: | |
9693 | wdev_unlock(wdev); | |
9694 | return err; | |
9695 | } | |
9696 | ||
9697 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | |
9698 | { | |
9699 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9700 | struct net_device *dev = info->user_ptr[1]; | |
9701 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9702 | const u8 *peer; | |
9703 | u8 tsid; | |
9704 | int err; | |
9705 | ||
9706 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | |
9707 | return -EINVAL; | |
9708 | ||
9709 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
9710 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9711 | ||
9712 | wdev_lock(wdev); | |
9713 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | |
9714 | wdev_unlock(wdev); | |
9715 | ||
9716 | return err; | |
9717 | } | |
9718 | ||
1057d35e AN |
9719 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
9720 | struct genl_info *info) | |
9721 | { | |
9722 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9723 | struct net_device *dev = info->user_ptr[1]; | |
9724 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9725 | struct cfg80211_chan_def chandef = {}; | |
9726 | const u8 *addr; | |
9727 | u8 oper_class; | |
9728 | int err; | |
9729 | ||
9730 | if (!rdev->ops->tdls_channel_switch || | |
9731 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
9732 | return -EOPNOTSUPP; | |
9733 | ||
9734 | switch (dev->ieee80211_ptr->iftype) { | |
9735 | case NL80211_IFTYPE_STATION: | |
9736 | case NL80211_IFTYPE_P2P_CLIENT: | |
9737 | break; | |
9738 | default: | |
9739 | return -EOPNOTSUPP; | |
9740 | } | |
9741 | ||
9742 | if (!info->attrs[NL80211_ATTR_MAC] || | |
9743 | !info->attrs[NL80211_ATTR_OPER_CLASS]) | |
9744 | return -EINVAL; | |
9745 | ||
9746 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
9747 | if (err) | |
9748 | return err; | |
9749 | ||
9750 | /* | |
9751 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | |
9752 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | |
9753 | * specification is not defined for them. | |
9754 | */ | |
9755 | if (chandef.chan->band == IEEE80211_BAND_2GHZ && | |
9756 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | |
9757 | chandef.width != NL80211_CHAN_WIDTH_20) | |
9758 | return -EINVAL; | |
9759 | ||
9760 | /* we will be active on the TDLS link */ | |
9761 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype)) | |
9762 | return -EINVAL; | |
9763 | ||
9764 | /* don't allow switching to DFS channels */ | |
9765 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | |
9766 | return -EINVAL; | |
9767 | ||
9768 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9769 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | |
9770 | ||
9771 | wdev_lock(wdev); | |
9772 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | |
9773 | wdev_unlock(wdev); | |
9774 | ||
9775 | return err; | |
9776 | } | |
9777 | ||
9778 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | |
9779 | struct genl_info *info) | |
9780 | { | |
9781 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9782 | struct net_device *dev = info->user_ptr[1]; | |
9783 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9784 | const u8 *addr; | |
9785 | ||
9786 | if (!rdev->ops->tdls_channel_switch || | |
9787 | !rdev->ops->tdls_cancel_channel_switch || | |
9788 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
9789 | return -EOPNOTSUPP; | |
9790 | ||
9791 | switch (dev->ieee80211_ptr->iftype) { | |
9792 | case NL80211_IFTYPE_STATION: | |
9793 | case NL80211_IFTYPE_P2P_CLIENT: | |
9794 | break; | |
9795 | default: | |
9796 | return -EOPNOTSUPP; | |
9797 | } | |
9798 | ||
9799 | if (!info->attrs[NL80211_ATTR_MAC]) | |
9800 | return -EINVAL; | |
9801 | ||
9802 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9803 | ||
9804 | wdev_lock(wdev); | |
9805 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); | |
9806 | wdev_unlock(wdev); | |
9807 | ||
9808 | return 0; | |
9809 | } | |
9810 | ||
4c476991 JB |
9811 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
9812 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
9813 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
9814 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
9815 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
9816 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 9817 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 9818 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
9819 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
9820 | NL80211_FLAG_CHECK_NETDEV_UP) | |
5393b917 | 9821 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
4c476991 | 9822 | |
f84f771d | 9823 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
9824 | struct genl_info *info) |
9825 | { | |
9826 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 9827 | struct wireless_dev *wdev; |
4c476991 | 9828 | struct net_device *dev; |
4c476991 JB |
9829 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
9830 | ||
9831 | if (rtnl) | |
9832 | rtnl_lock(); | |
9833 | ||
9834 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 9835 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
9836 | if (IS_ERR(rdev)) { |
9837 | if (rtnl) | |
9838 | rtnl_unlock(); | |
9839 | return PTR_ERR(rdev); | |
9840 | } | |
9841 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
9842 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
9843 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
9844 | ASSERT_RTNL(); |
9845 | ||
89a54e48 JB |
9846 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
9847 | info->attrs); | |
9848 | if (IS_ERR(wdev)) { | |
4c476991 JB |
9849 | if (rtnl) |
9850 | rtnl_unlock(); | |
89a54e48 | 9851 | return PTR_ERR(wdev); |
4c476991 | 9852 | } |
89a54e48 | 9853 | |
89a54e48 | 9854 | dev = wdev->netdev; |
f26cbf40 | 9855 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 9856 | |
1bf614ef JB |
9857 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
9858 | if (!dev) { | |
1bf614ef JB |
9859 | if (rtnl) |
9860 | rtnl_unlock(); | |
9861 | return -EINVAL; | |
9862 | } | |
9863 | ||
9864 | info->user_ptr[1] = dev; | |
9865 | } else { | |
9866 | info->user_ptr[1] = wdev; | |
41265714 | 9867 | } |
1bf614ef JB |
9868 | |
9869 | if (dev) { | |
9870 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
9871 | !netif_running(dev)) { | |
1bf614ef JB |
9872 | if (rtnl) |
9873 | rtnl_unlock(); | |
9874 | return -ENETDOWN; | |
9875 | } | |
9876 | ||
9877 | dev_hold(dev); | |
98104fde JB |
9878 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
9879 | if (!wdev->p2p_started) { | |
98104fde JB |
9880 | if (rtnl) |
9881 | rtnl_unlock(); | |
9882 | return -ENETDOWN; | |
9883 | } | |
41265714 | 9884 | } |
89a54e48 | 9885 | |
4c476991 | 9886 | info->user_ptr[0] = rdev; |
4c476991 JB |
9887 | } |
9888 | ||
9889 | return 0; | |
9890 | } | |
9891 | ||
f84f771d | 9892 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
9893 | struct genl_info *info) |
9894 | { | |
1bf614ef JB |
9895 | if (info->user_ptr[1]) { |
9896 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
9897 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9898 | ||
9899 | if (wdev->netdev) | |
9900 | dev_put(wdev->netdev); | |
9901 | } else { | |
9902 | dev_put(info->user_ptr[1]); | |
9903 | } | |
9904 | } | |
5393b917 | 9905 | |
4c476991 JB |
9906 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
9907 | rtnl_unlock(); | |
5393b917 JB |
9908 | |
9909 | /* If needed, clear the netlink message payload from the SKB | |
9910 | * as it might contain key data that shouldn't stick around on | |
9911 | * the heap after the SKB is freed. The netlink message header | |
9912 | * is still needed for further processing, so leave it intact. | |
9913 | */ | |
9914 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | |
9915 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | |
9916 | ||
9917 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | |
9918 | } | |
4c476991 JB |
9919 | } |
9920 | ||
4534de83 | 9921 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
9922 | { |
9923 | .cmd = NL80211_CMD_GET_WIPHY, | |
9924 | .doit = nl80211_get_wiphy, | |
9925 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 9926 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
9927 | .policy = nl80211_policy, |
9928 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
9929 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9930 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9931 | }, |
9932 | { | |
9933 | .cmd = NL80211_CMD_SET_WIPHY, | |
9934 | .doit = nl80211_set_wiphy, | |
9935 | .policy = nl80211_policy, | |
9936 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 9937 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
9938 | }, |
9939 | { | |
9940 | .cmd = NL80211_CMD_GET_INTERFACE, | |
9941 | .doit = nl80211_get_interface, | |
9942 | .dumpit = nl80211_dump_interface, | |
9943 | .policy = nl80211_policy, | |
9944 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
9945 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
9946 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9947 | }, |
9948 | { | |
9949 | .cmd = NL80211_CMD_SET_INTERFACE, | |
9950 | .doit = nl80211_set_interface, | |
9951 | .policy = nl80211_policy, | |
9952 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9953 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9954 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9955 | }, |
9956 | { | |
9957 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
9958 | .doit = nl80211_new_interface, | |
9959 | .policy = nl80211_policy, | |
9960 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9961 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9962 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9963 | }, |
9964 | { | |
9965 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
9966 | .doit = nl80211_del_interface, | |
9967 | .policy = nl80211_policy, | |
41ade00f | 9968 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 9969 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 9970 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9971 | }, |
9972 | { | |
9973 | .cmd = NL80211_CMD_GET_KEY, | |
9974 | .doit = nl80211_get_key, | |
9975 | .policy = nl80211_policy, | |
9976 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9977 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9978 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9979 | }, |
9980 | { | |
9981 | .cmd = NL80211_CMD_SET_KEY, | |
9982 | .doit = nl80211_set_key, | |
9983 | .policy = nl80211_policy, | |
9984 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9985 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
9986 | NL80211_FLAG_NEED_RTNL | |
9987 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
9988 | }, |
9989 | { | |
9990 | .cmd = NL80211_CMD_NEW_KEY, | |
9991 | .doit = nl80211_new_key, | |
9992 | .policy = nl80211_policy, | |
9993 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9994 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
9995 | NL80211_FLAG_NEED_RTNL | |
9996 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
9997 | }, |
9998 | { | |
9999 | .cmd = NL80211_CMD_DEL_KEY, | |
10000 | .doit = nl80211_del_key, | |
10001 | .policy = nl80211_policy, | |
55682965 | 10002 | .flags = GENL_ADMIN_PERM, |
41265714 | 10003 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10004 | NL80211_FLAG_NEED_RTNL, |
55682965 | 10005 | }, |
ed1b6cc7 JB |
10006 | { |
10007 | .cmd = NL80211_CMD_SET_BEACON, | |
10008 | .policy = nl80211_policy, | |
10009 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10010 | .doit = nl80211_set_beacon, |
2b5f8b0b | 10011 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10012 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10013 | }, |
10014 | { | |
8860020e | 10015 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
10016 | .policy = nl80211_policy, |
10017 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10018 | .doit = nl80211_start_ap, |
2b5f8b0b | 10019 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10020 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10021 | }, |
10022 | { | |
8860020e | 10023 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
10024 | .policy = nl80211_policy, |
10025 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10026 | .doit = nl80211_stop_ap, |
2b5f8b0b | 10027 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10028 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 10029 | }, |
5727ef1b JB |
10030 | { |
10031 | .cmd = NL80211_CMD_GET_STATION, | |
10032 | .doit = nl80211_get_station, | |
2ec600d6 | 10033 | .dumpit = nl80211_dump_station, |
5727ef1b | 10034 | .policy = nl80211_policy, |
4c476991 JB |
10035 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10036 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
10037 | }, |
10038 | { | |
10039 | .cmd = NL80211_CMD_SET_STATION, | |
10040 | .doit = nl80211_set_station, | |
10041 | .policy = nl80211_policy, | |
10042 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10043 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10044 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10045 | }, |
10046 | { | |
10047 | .cmd = NL80211_CMD_NEW_STATION, | |
10048 | .doit = nl80211_new_station, | |
10049 | .policy = nl80211_policy, | |
10050 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10051 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10052 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10053 | }, |
10054 | { | |
10055 | .cmd = NL80211_CMD_DEL_STATION, | |
10056 | .doit = nl80211_del_station, | |
10057 | .policy = nl80211_policy, | |
2ec600d6 | 10058 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10059 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10060 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10061 | }, |
10062 | { | |
10063 | .cmd = NL80211_CMD_GET_MPATH, | |
10064 | .doit = nl80211_get_mpath, | |
10065 | .dumpit = nl80211_dump_mpath, | |
10066 | .policy = nl80211_policy, | |
10067 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10068 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10069 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 | 10070 | }, |
66be7d2b HR |
10071 | { |
10072 | .cmd = NL80211_CMD_GET_MPP, | |
10073 | .doit = nl80211_get_mpp, | |
10074 | .dumpit = nl80211_dump_mpp, | |
10075 | .policy = nl80211_policy, | |
10076 | .flags = GENL_ADMIN_PERM, | |
10077 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10078 | NL80211_FLAG_NEED_RTNL, | |
10079 | }, | |
2ec600d6 LCC |
10080 | { |
10081 | .cmd = NL80211_CMD_SET_MPATH, | |
10082 | .doit = nl80211_set_mpath, | |
10083 | .policy = nl80211_policy, | |
10084 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10085 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10086 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10087 | }, |
10088 | { | |
10089 | .cmd = NL80211_CMD_NEW_MPATH, | |
10090 | .doit = nl80211_new_mpath, | |
10091 | .policy = nl80211_policy, | |
10092 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10093 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10094 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10095 | }, |
10096 | { | |
10097 | .cmd = NL80211_CMD_DEL_MPATH, | |
10098 | .doit = nl80211_del_mpath, | |
10099 | .policy = nl80211_policy, | |
9f1ba906 | 10100 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10101 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10102 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
10103 | }, |
10104 | { | |
10105 | .cmd = NL80211_CMD_SET_BSS, | |
10106 | .doit = nl80211_set_bss, | |
10107 | .policy = nl80211_policy, | |
b2e1b302 | 10108 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10109 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10110 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 10111 | }, |
f130347c LR |
10112 | { |
10113 | .cmd = NL80211_CMD_GET_REG, | |
10114 | .doit = nl80211_get_reg, | |
10115 | .policy = nl80211_policy, | |
5fe231e8 | 10116 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
10117 | /* can be retrieved by unprivileged users */ |
10118 | }, | |
b2e1b302 LR |
10119 | { |
10120 | .cmd = NL80211_CMD_SET_REG, | |
10121 | .doit = nl80211_set_reg, | |
10122 | .policy = nl80211_policy, | |
10123 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 10124 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
10125 | }, |
10126 | { | |
10127 | .cmd = NL80211_CMD_REQ_SET_REG, | |
10128 | .doit = nl80211_req_set_reg, | |
10129 | .policy = nl80211_policy, | |
93da9cc1 | 10130 | .flags = GENL_ADMIN_PERM, |
10131 | }, | |
10132 | { | |
24bdd9f4 JC |
10133 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
10134 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 10135 | .policy = nl80211_policy, |
10136 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 10137 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10138 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 10139 | }, |
10140 | { | |
24bdd9f4 JC |
10141 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
10142 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 10143 | .policy = nl80211_policy, |
9aed3cc1 | 10144 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 10145 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10146 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 10147 | }, |
2a519311 JB |
10148 | { |
10149 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
10150 | .doit = nl80211_trigger_scan, | |
10151 | .policy = nl80211_policy, | |
10152 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 10153 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10154 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
10155 | }, |
10156 | { | |
10157 | .cmd = NL80211_CMD_GET_SCAN, | |
10158 | .policy = nl80211_policy, | |
10159 | .dumpit = nl80211_dump_scan, | |
10160 | }, | |
807f8a8c LC |
10161 | { |
10162 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
10163 | .doit = nl80211_start_sched_scan, | |
10164 | .policy = nl80211_policy, | |
10165 | .flags = GENL_ADMIN_PERM, | |
10166 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10167 | NL80211_FLAG_NEED_RTNL, | |
10168 | }, | |
10169 | { | |
10170 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
10171 | .doit = nl80211_stop_sched_scan, | |
10172 | .policy = nl80211_policy, | |
10173 | .flags = GENL_ADMIN_PERM, | |
10174 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10175 | NL80211_FLAG_NEED_RTNL, | |
10176 | }, | |
636a5d36 JM |
10177 | { |
10178 | .cmd = NL80211_CMD_AUTHENTICATE, | |
10179 | .doit = nl80211_authenticate, | |
10180 | .policy = nl80211_policy, | |
10181 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10182 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10183 | NL80211_FLAG_NEED_RTNL | |
10184 | NL80211_FLAG_CLEAR_SKB, | |
636a5d36 JM |
10185 | }, |
10186 | { | |
10187 | .cmd = NL80211_CMD_ASSOCIATE, | |
10188 | .doit = nl80211_associate, | |
10189 | .policy = nl80211_policy, | |
10190 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10191 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10192 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10193 | }, |
10194 | { | |
10195 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
10196 | .doit = nl80211_deauthenticate, | |
10197 | .policy = nl80211_policy, | |
10198 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10199 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10200 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10201 | }, |
10202 | { | |
10203 | .cmd = NL80211_CMD_DISASSOCIATE, | |
10204 | .doit = nl80211_disassociate, | |
10205 | .policy = nl80211_policy, | |
10206 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10207 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10208 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 10209 | }, |
04a773ad JB |
10210 | { |
10211 | .cmd = NL80211_CMD_JOIN_IBSS, | |
10212 | .doit = nl80211_join_ibss, | |
10213 | .policy = nl80211_policy, | |
10214 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10215 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10216 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
10217 | }, |
10218 | { | |
10219 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
10220 | .doit = nl80211_leave_ibss, | |
10221 | .policy = nl80211_policy, | |
10222 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10223 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10224 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 10225 | }, |
aff89a9b JB |
10226 | #ifdef CONFIG_NL80211_TESTMODE |
10227 | { | |
10228 | .cmd = NL80211_CMD_TESTMODE, | |
10229 | .doit = nl80211_testmode_do, | |
71063f0e | 10230 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
10231 | .policy = nl80211_policy, |
10232 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10233 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10234 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
10235 | }, |
10236 | #endif | |
b23aa676 SO |
10237 | { |
10238 | .cmd = NL80211_CMD_CONNECT, | |
10239 | .doit = nl80211_connect, | |
10240 | .policy = nl80211_policy, | |
10241 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10242 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10243 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
10244 | }, |
10245 | { | |
10246 | .cmd = NL80211_CMD_DISCONNECT, | |
10247 | .doit = nl80211_disconnect, | |
10248 | .policy = nl80211_policy, | |
10249 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10250 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10251 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 10252 | }, |
463d0183 JB |
10253 | { |
10254 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
10255 | .doit = nl80211_wiphy_netns, | |
10256 | .policy = nl80211_policy, | |
10257 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10258 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10259 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 10260 | }, |
61fa713c HS |
10261 | { |
10262 | .cmd = NL80211_CMD_GET_SURVEY, | |
10263 | .policy = nl80211_policy, | |
10264 | .dumpit = nl80211_dump_survey, | |
10265 | }, | |
67fbb16b SO |
10266 | { |
10267 | .cmd = NL80211_CMD_SET_PMKSA, | |
10268 | .doit = nl80211_setdel_pmksa, | |
10269 | .policy = nl80211_policy, | |
10270 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10271 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10272 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10273 | }, |
10274 | { | |
10275 | .cmd = NL80211_CMD_DEL_PMKSA, | |
10276 | .doit = nl80211_setdel_pmksa, | |
10277 | .policy = nl80211_policy, | |
10278 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10279 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10280 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10281 | }, |
10282 | { | |
10283 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
10284 | .doit = nl80211_flush_pmksa, | |
10285 | .policy = nl80211_policy, | |
10286 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10287 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10288 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 10289 | }, |
9588bbd5 JM |
10290 | { |
10291 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
10292 | .doit = nl80211_remain_on_channel, | |
10293 | .policy = nl80211_policy, | |
10294 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10295 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10296 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
10297 | }, |
10298 | { | |
10299 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
10300 | .doit = nl80211_cancel_remain_on_channel, | |
10301 | .policy = nl80211_policy, | |
10302 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10303 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10304 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 10305 | }, |
13ae75b1 JM |
10306 | { |
10307 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
10308 | .doit = nl80211_set_tx_bitrate_mask, | |
10309 | .policy = nl80211_policy, | |
10310 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10311 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10312 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 10313 | }, |
026331c4 | 10314 | { |
2e161f78 JB |
10315 | .cmd = NL80211_CMD_REGISTER_FRAME, |
10316 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
10317 | .policy = nl80211_policy, |
10318 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10319 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10320 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
10321 | }, |
10322 | { | |
2e161f78 JB |
10323 | .cmd = NL80211_CMD_FRAME, |
10324 | .doit = nl80211_tx_mgmt, | |
026331c4 | 10325 | .policy = nl80211_policy, |
f7ca38df | 10326 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10327 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
10328 | NL80211_FLAG_NEED_RTNL, |
10329 | }, | |
10330 | { | |
10331 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
10332 | .doit = nl80211_tx_mgmt_cancel_wait, | |
10333 | .policy = nl80211_policy, | |
026331c4 | 10334 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10335 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10336 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 10337 | }, |
ffb9eb3d KV |
10338 | { |
10339 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
10340 | .doit = nl80211_set_power_save, | |
10341 | .policy = nl80211_policy, | |
10342 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10343 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10344 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
10345 | }, |
10346 | { | |
10347 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
10348 | .doit = nl80211_get_power_save, | |
10349 | .policy = nl80211_policy, | |
10350 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
10351 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10352 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 10353 | }, |
d6dc1a38 JO |
10354 | { |
10355 | .cmd = NL80211_CMD_SET_CQM, | |
10356 | .doit = nl80211_set_cqm, | |
10357 | .policy = nl80211_policy, | |
10358 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10359 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10360 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 10361 | }, |
f444de05 JB |
10362 | { |
10363 | .cmd = NL80211_CMD_SET_CHANNEL, | |
10364 | .doit = nl80211_set_channel, | |
10365 | .policy = nl80211_policy, | |
10366 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10367 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10368 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 10369 | }, |
e8347eba BJ |
10370 | { |
10371 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
10372 | .doit = nl80211_set_wds_peer, | |
10373 | .policy = nl80211_policy, | |
10374 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
10375 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10376 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 10377 | }, |
29cbe68c JB |
10378 | { |
10379 | .cmd = NL80211_CMD_JOIN_MESH, | |
10380 | .doit = nl80211_join_mesh, | |
10381 | .policy = nl80211_policy, | |
10382 | .flags = GENL_ADMIN_PERM, | |
10383 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10384 | NL80211_FLAG_NEED_RTNL, | |
10385 | }, | |
10386 | { | |
10387 | .cmd = NL80211_CMD_LEAVE_MESH, | |
10388 | .doit = nl80211_leave_mesh, | |
10389 | .policy = nl80211_policy, | |
10390 | .flags = GENL_ADMIN_PERM, | |
10391 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10392 | NL80211_FLAG_NEED_RTNL, | |
10393 | }, | |
6e0bd6c3 RL |
10394 | { |
10395 | .cmd = NL80211_CMD_JOIN_OCB, | |
10396 | .doit = nl80211_join_ocb, | |
10397 | .policy = nl80211_policy, | |
10398 | .flags = GENL_ADMIN_PERM, | |
10399 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10400 | NL80211_FLAG_NEED_RTNL, | |
10401 | }, | |
10402 | { | |
10403 | .cmd = NL80211_CMD_LEAVE_OCB, | |
10404 | .doit = nl80211_leave_ocb, | |
10405 | .policy = nl80211_policy, | |
10406 | .flags = GENL_ADMIN_PERM, | |
10407 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10408 | NL80211_FLAG_NEED_RTNL, | |
10409 | }, | |
dfb89c56 | 10410 | #ifdef CONFIG_PM |
ff1b6e69 JB |
10411 | { |
10412 | .cmd = NL80211_CMD_GET_WOWLAN, | |
10413 | .doit = nl80211_get_wowlan, | |
10414 | .policy = nl80211_policy, | |
10415 | /* can be retrieved by unprivileged users */ | |
10416 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10417 | NL80211_FLAG_NEED_RTNL, | |
10418 | }, | |
10419 | { | |
10420 | .cmd = NL80211_CMD_SET_WOWLAN, | |
10421 | .doit = nl80211_set_wowlan, | |
10422 | .policy = nl80211_policy, | |
10423 | .flags = GENL_ADMIN_PERM, | |
10424 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10425 | NL80211_FLAG_NEED_RTNL, | |
10426 | }, | |
dfb89c56 | 10427 | #endif |
e5497d76 JB |
10428 | { |
10429 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
10430 | .doit = nl80211_set_rekey_data, | |
10431 | .policy = nl80211_policy, | |
10432 | .flags = GENL_ADMIN_PERM, | |
10433 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
5393b917 JB |
10434 | NL80211_FLAG_NEED_RTNL | |
10435 | NL80211_FLAG_CLEAR_SKB, | |
e5497d76 | 10436 | }, |
109086ce AN |
10437 | { |
10438 | .cmd = NL80211_CMD_TDLS_MGMT, | |
10439 | .doit = nl80211_tdls_mgmt, | |
10440 | .policy = nl80211_policy, | |
10441 | .flags = GENL_ADMIN_PERM, | |
10442 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10443 | NL80211_FLAG_NEED_RTNL, | |
10444 | }, | |
10445 | { | |
10446 | .cmd = NL80211_CMD_TDLS_OPER, | |
10447 | .doit = nl80211_tdls_oper, | |
10448 | .policy = nl80211_policy, | |
10449 | .flags = GENL_ADMIN_PERM, | |
10450 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10451 | NL80211_FLAG_NEED_RTNL, | |
10452 | }, | |
28946da7 JB |
10453 | { |
10454 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
10455 | .doit = nl80211_register_unexpected_frame, | |
10456 | .policy = nl80211_policy, | |
10457 | .flags = GENL_ADMIN_PERM, | |
10458 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10459 | NL80211_FLAG_NEED_RTNL, | |
10460 | }, | |
7f6cf311 JB |
10461 | { |
10462 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
10463 | .doit = nl80211_probe_client, | |
10464 | .policy = nl80211_policy, | |
10465 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10466 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
10467 | NL80211_FLAG_NEED_RTNL, |
10468 | }, | |
5e760230 JB |
10469 | { |
10470 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
10471 | .doit = nl80211_register_beacons, | |
10472 | .policy = nl80211_policy, | |
10473 | .flags = GENL_ADMIN_PERM, | |
10474 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10475 | NL80211_FLAG_NEED_RTNL, | |
10476 | }, | |
1d9d9213 SW |
10477 | { |
10478 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
10479 | .doit = nl80211_set_noack_map, | |
10480 | .policy = nl80211_policy, | |
10481 | .flags = GENL_ADMIN_PERM, | |
10482 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10483 | NL80211_FLAG_NEED_RTNL, | |
10484 | }, | |
98104fde JB |
10485 | { |
10486 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
10487 | .doit = nl80211_start_p2p_device, | |
10488 | .policy = nl80211_policy, | |
10489 | .flags = GENL_ADMIN_PERM, | |
10490 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
10491 | NL80211_FLAG_NEED_RTNL, | |
10492 | }, | |
10493 | { | |
10494 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
10495 | .doit = nl80211_stop_p2p_device, | |
10496 | .policy = nl80211_policy, | |
10497 | .flags = GENL_ADMIN_PERM, | |
10498 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10499 | NL80211_FLAG_NEED_RTNL, | |
10500 | }, | |
f4e583c8 AQ |
10501 | { |
10502 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
10503 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
10504 | .policy = nl80211_policy, |
10505 | .flags = GENL_ADMIN_PERM, | |
10506 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10507 | NL80211_FLAG_NEED_RTNL, | |
10508 | }, | |
10509 | { | |
10510 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
10511 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
10512 | .policy = nl80211_policy, |
10513 | .flags = GENL_ADMIN_PERM, | |
10514 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10515 | NL80211_FLAG_NEED_RTNL, | |
10516 | }, | |
04f39047 SW |
10517 | { |
10518 | .cmd = NL80211_CMD_RADAR_DETECT, | |
10519 | .doit = nl80211_start_radar_detection, | |
10520 | .policy = nl80211_policy, | |
10521 | .flags = GENL_ADMIN_PERM, | |
10522 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10523 | NL80211_FLAG_NEED_RTNL, | |
10524 | }, | |
3713b4e3 JB |
10525 | { |
10526 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
10527 | .doit = nl80211_get_protocol_features, | |
10528 | .policy = nl80211_policy, | |
10529 | }, | |
355199e0 JM |
10530 | { |
10531 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
10532 | .doit = nl80211_update_ft_ies, | |
10533 | .policy = nl80211_policy, | |
10534 | .flags = GENL_ADMIN_PERM, | |
10535 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10536 | NL80211_FLAG_NEED_RTNL, | |
10537 | }, | |
5de17984 AS |
10538 | { |
10539 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
10540 | .doit = nl80211_crit_protocol_start, | |
10541 | .policy = nl80211_policy, | |
10542 | .flags = GENL_ADMIN_PERM, | |
10543 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10544 | NL80211_FLAG_NEED_RTNL, | |
10545 | }, | |
10546 | { | |
10547 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
10548 | .doit = nl80211_crit_protocol_stop, | |
10549 | .policy = nl80211_policy, | |
10550 | .flags = GENL_ADMIN_PERM, | |
10551 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10552 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
10553 | }, |
10554 | { | |
10555 | .cmd = NL80211_CMD_GET_COALESCE, | |
10556 | .doit = nl80211_get_coalesce, | |
10557 | .policy = nl80211_policy, | |
10558 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10559 | NL80211_FLAG_NEED_RTNL, | |
10560 | }, | |
10561 | { | |
10562 | .cmd = NL80211_CMD_SET_COALESCE, | |
10563 | .doit = nl80211_set_coalesce, | |
10564 | .policy = nl80211_policy, | |
10565 | .flags = GENL_ADMIN_PERM, | |
10566 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10567 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
10568 | }, |
10569 | { | |
10570 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
10571 | .doit = nl80211_channel_switch, | |
10572 | .policy = nl80211_policy, | |
10573 | .flags = GENL_ADMIN_PERM, | |
10574 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10575 | NL80211_FLAG_NEED_RTNL, | |
10576 | }, | |
ad7e718c JB |
10577 | { |
10578 | .cmd = NL80211_CMD_VENDOR, | |
10579 | .doit = nl80211_vendor_cmd, | |
10580 | .policy = nl80211_policy, | |
10581 | .flags = GENL_ADMIN_PERM, | |
10582 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10583 | NL80211_FLAG_NEED_RTNL, | |
10584 | }, | |
fa9ffc74 KP |
10585 | { |
10586 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
10587 | .doit = nl80211_set_qos_map, | |
10588 | .policy = nl80211_policy, | |
10589 | .flags = GENL_ADMIN_PERM, | |
10590 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10591 | NL80211_FLAG_NEED_RTNL, | |
10592 | }, | |
960d01ac JB |
10593 | { |
10594 | .cmd = NL80211_CMD_ADD_TX_TS, | |
10595 | .doit = nl80211_add_tx_ts, | |
10596 | .policy = nl80211_policy, | |
10597 | .flags = GENL_ADMIN_PERM, | |
10598 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10599 | NL80211_FLAG_NEED_RTNL, | |
10600 | }, | |
10601 | { | |
10602 | .cmd = NL80211_CMD_DEL_TX_TS, | |
10603 | .doit = nl80211_del_tx_ts, | |
10604 | .policy = nl80211_policy, | |
10605 | .flags = GENL_ADMIN_PERM, | |
10606 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10607 | NL80211_FLAG_NEED_RTNL, | |
10608 | }, | |
1057d35e AN |
10609 | { |
10610 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | |
10611 | .doit = nl80211_tdls_channel_switch, | |
10612 | .policy = nl80211_policy, | |
10613 | .flags = GENL_ADMIN_PERM, | |
10614 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10615 | NL80211_FLAG_NEED_RTNL, | |
10616 | }, | |
10617 | { | |
10618 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | |
10619 | .doit = nl80211_tdls_cancel_channel_switch, | |
10620 | .policy = nl80211_policy, | |
10621 | .flags = GENL_ADMIN_PERM, | |
10622 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10623 | NL80211_FLAG_NEED_RTNL, | |
10624 | }, | |
55682965 | 10625 | }; |
9588bbd5 | 10626 | |
55682965 JB |
10627 | /* notification functions */ |
10628 | ||
3bb20556 JB |
10629 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
10630 | enum nl80211_commands cmd) | |
55682965 JB |
10631 | { |
10632 | struct sk_buff *msg; | |
86e8cf98 | 10633 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 10634 | |
3bb20556 JB |
10635 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
10636 | cmd != NL80211_CMD_DEL_WIPHY); | |
10637 | ||
fd2120ca | 10638 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
10639 | if (!msg) |
10640 | return; | |
10641 | ||
3bb20556 | 10642 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
10643 | nlmsg_free(msg); |
10644 | return; | |
10645 | } | |
10646 | ||
68eb5503 | 10647 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10648 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
10649 | } |
10650 | ||
362a415d JB |
10651 | static int nl80211_add_scan_req(struct sk_buff *msg, |
10652 | struct cfg80211_registered_device *rdev) | |
10653 | { | |
10654 | struct cfg80211_scan_request *req = rdev->scan_req; | |
10655 | struct nlattr *nest; | |
10656 | int i; | |
10657 | ||
10658 | if (WARN_ON(!req)) | |
10659 | return 0; | |
10660 | ||
10661 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
10662 | if (!nest) | |
10663 | goto nla_put_failure; | |
9360ffd1 DM |
10664 | for (i = 0; i < req->n_ssids; i++) { |
10665 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
10666 | goto nla_put_failure; | |
10667 | } | |
362a415d JB |
10668 | nla_nest_end(msg, nest); |
10669 | ||
10670 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
10671 | if (!nest) | |
10672 | goto nla_put_failure; | |
9360ffd1 DM |
10673 | for (i = 0; i < req->n_channels; i++) { |
10674 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
10675 | goto nla_put_failure; | |
10676 | } | |
362a415d JB |
10677 | nla_nest_end(msg, nest); |
10678 | ||
9360ffd1 DM |
10679 | if (req->ie && |
10680 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
10681 | goto nla_put_failure; | |
362a415d | 10682 | |
ae917c9f JB |
10683 | if (req->flags && |
10684 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
10685 | goto nla_put_failure; | |
ed473771 | 10686 | |
362a415d JB |
10687 | return 0; |
10688 | nla_put_failure: | |
10689 | return -ENOBUFS; | |
10690 | } | |
10691 | ||
a538e2d5 JB |
10692 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
10693 | struct cfg80211_registered_device *rdev, | |
fd014284 | 10694 | struct wireless_dev *wdev, |
15e47304 | 10695 | u32 portid, u32 seq, int flags, |
a538e2d5 | 10696 | u32 cmd) |
2a519311 JB |
10697 | { |
10698 | void *hdr; | |
10699 | ||
15e47304 | 10700 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
10701 | if (!hdr) |
10702 | return -1; | |
10703 | ||
9360ffd1 | 10704 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
10705 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10706 | wdev->netdev->ifindex)) || | |
10707 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 10708 | goto nla_put_failure; |
2a519311 | 10709 | |
362a415d JB |
10710 | /* ignore errors and send incomplete event anyway */ |
10711 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
10712 | |
10713 | return genlmsg_end(msg, hdr); | |
10714 | ||
10715 | nla_put_failure: | |
10716 | genlmsg_cancel(msg, hdr); | |
10717 | return -EMSGSIZE; | |
10718 | } | |
10719 | ||
807f8a8c LC |
10720 | static int |
10721 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
10722 | struct cfg80211_registered_device *rdev, | |
10723 | struct net_device *netdev, | |
15e47304 | 10724 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
10725 | { |
10726 | void *hdr; | |
10727 | ||
15e47304 | 10728 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
10729 | if (!hdr) |
10730 | return -1; | |
10731 | ||
9360ffd1 DM |
10732 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10733 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
10734 | goto nla_put_failure; | |
807f8a8c LC |
10735 | |
10736 | return genlmsg_end(msg, hdr); | |
10737 | ||
10738 | nla_put_failure: | |
10739 | genlmsg_cancel(msg, hdr); | |
10740 | return -EMSGSIZE; | |
10741 | } | |
10742 | ||
a538e2d5 | 10743 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 10744 | struct wireless_dev *wdev) |
a538e2d5 JB |
10745 | { |
10746 | struct sk_buff *msg; | |
10747 | ||
58050fce | 10748 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
10749 | if (!msg) |
10750 | return; | |
10751 | ||
fd014284 | 10752 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
10753 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
10754 | nlmsg_free(msg); | |
10755 | return; | |
10756 | } | |
10757 | ||
68eb5503 | 10758 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10759 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
10760 | } |
10761 | ||
f9d15d16 JB |
10762 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
10763 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
10764 | { |
10765 | struct sk_buff *msg; | |
10766 | ||
fd2120ca | 10767 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 10768 | if (!msg) |
f9d15d16 | 10769 | return NULL; |
2a519311 | 10770 | |
fd014284 | 10771 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
10772 | aborted ? NL80211_CMD_SCAN_ABORTED : |
10773 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 10774 | nlmsg_free(msg); |
f9d15d16 | 10775 | return NULL; |
2a519311 JB |
10776 | } |
10777 | ||
f9d15d16 | 10778 | return msg; |
2a519311 JB |
10779 | } |
10780 | ||
f9d15d16 JB |
10781 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
10782 | struct sk_buff *msg) | |
2a519311 | 10783 | { |
2a519311 JB |
10784 | if (!msg) |
10785 | return; | |
10786 | ||
68eb5503 | 10787 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10788 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
10789 | } |
10790 | ||
807f8a8c LC |
10791 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
10792 | struct net_device *netdev) | |
10793 | { | |
10794 | struct sk_buff *msg; | |
10795 | ||
10796 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10797 | if (!msg) | |
10798 | return; | |
10799 | ||
10800 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
10801 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
10802 | nlmsg_free(msg); | |
10803 | return; | |
10804 | } | |
10805 | ||
68eb5503 | 10806 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10807 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
10808 | } |
10809 | ||
10810 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
10811 | struct net_device *netdev, u32 cmd) | |
10812 | { | |
10813 | struct sk_buff *msg; | |
10814 | ||
58050fce | 10815 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
10816 | if (!msg) |
10817 | return; | |
10818 | ||
10819 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
10820 | nlmsg_free(msg); | |
10821 | return; | |
10822 | } | |
10823 | ||
68eb5503 | 10824 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10825 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
10826 | } |
10827 | ||
73d54c9e LR |
10828 | /* |
10829 | * This can happen on global regulatory changes or device specific settings | |
10830 | * based on custom world regulatory domains. | |
10831 | */ | |
10832 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
10833 | { | |
10834 | struct sk_buff *msg; | |
10835 | void *hdr; | |
10836 | ||
fd2120ca | 10837 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
10838 | if (!msg) |
10839 | return; | |
10840 | ||
10841 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
10842 | if (!hdr) { | |
10843 | nlmsg_free(msg); | |
10844 | return; | |
10845 | } | |
10846 | ||
10847 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
10848 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
10849 | goto nla_put_failure; | |
10850 | ||
10851 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
10852 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10853 | NL80211_REGDOM_TYPE_WORLD)) | |
10854 | goto nla_put_failure; | |
10855 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
10856 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10857 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
10858 | goto nla_put_failure; | |
10859 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
10860 | request->intersect) { | |
10861 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10862 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
10863 | goto nla_put_failure; | |
10864 | } else { | |
10865 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10866 | NL80211_REGDOM_TYPE_COUNTRY) || | |
10867 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
10868 | request->alpha2)) | |
10869 | goto nla_put_failure; | |
10870 | } | |
10871 | ||
f4173766 | 10872 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
10873 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
10874 | goto nla_put_failure; | |
73d54c9e | 10875 | |
3b7b72ee | 10876 | genlmsg_end(msg, hdr); |
73d54c9e | 10877 | |
bc43b28c | 10878 | rcu_read_lock(); |
68eb5503 | 10879 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 10880 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 10881 | rcu_read_unlock(); |
73d54c9e LR |
10882 | |
10883 | return; | |
10884 | ||
10885 | nla_put_failure: | |
10886 | genlmsg_cancel(msg, hdr); | |
10887 | nlmsg_free(msg); | |
10888 | } | |
10889 | ||
6039f6d2 JM |
10890 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
10891 | struct net_device *netdev, | |
10892 | const u8 *buf, size_t len, | |
b0b6aa2c EP |
10893 | enum nl80211_commands cmd, gfp_t gfp, |
10894 | int uapsd_queues) | |
6039f6d2 JM |
10895 | { |
10896 | struct sk_buff *msg; | |
10897 | void *hdr; | |
10898 | ||
e6d6e342 | 10899 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
10900 | if (!msg) |
10901 | return; | |
10902 | ||
10903 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10904 | if (!hdr) { | |
10905 | nlmsg_free(msg); | |
10906 | return; | |
10907 | } | |
10908 | ||
9360ffd1 DM |
10909 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10910 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10911 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
10912 | goto nla_put_failure; | |
6039f6d2 | 10913 | |
b0b6aa2c EP |
10914 | if (uapsd_queues >= 0) { |
10915 | struct nlattr *nla_wmm = | |
10916 | nla_nest_start(msg, NL80211_ATTR_STA_WME); | |
10917 | if (!nla_wmm) | |
10918 | goto nla_put_failure; | |
10919 | ||
10920 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
10921 | uapsd_queues)) | |
10922 | goto nla_put_failure; | |
10923 | ||
10924 | nla_nest_end(msg, nla_wmm); | |
10925 | } | |
10926 | ||
3b7b72ee | 10927 | genlmsg_end(msg, hdr); |
6039f6d2 | 10928 | |
68eb5503 | 10929 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10930 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
10931 | return; |
10932 | ||
10933 | nla_put_failure: | |
10934 | genlmsg_cancel(msg, hdr); | |
10935 | nlmsg_free(msg); | |
10936 | } | |
10937 | ||
10938 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10939 | struct net_device *netdev, const u8 *buf, |
10940 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
10941 | { |
10942 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 10943 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
6039f6d2 JM |
10944 | } |
10945 | ||
10946 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
10947 | struct net_device *netdev, const u8 *buf, | |
b0b6aa2c | 10948 | size_t len, gfp_t gfp, int uapsd_queues) |
6039f6d2 | 10949 | { |
e6d6e342 | 10950 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
b0b6aa2c | 10951 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
6039f6d2 JM |
10952 | } |
10953 | ||
53b46b84 | 10954 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
10955 | struct net_device *netdev, const u8 *buf, |
10956 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
10957 | { |
10958 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 10959 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
6039f6d2 JM |
10960 | } |
10961 | ||
53b46b84 JM |
10962 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
10963 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 10964 | size_t len, gfp_t gfp) |
6039f6d2 JM |
10965 | { |
10966 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 10967 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
6039f6d2 JM |
10968 | } |
10969 | ||
6ff57cf8 JB |
10970 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
10971 | size_t len) | |
cf4e594e | 10972 | { |
947add36 JB |
10973 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10974 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 10975 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
10976 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
10977 | u32 cmd; | |
947add36 | 10978 | |
6ff57cf8 JB |
10979 | if (WARN_ON(len < 2)) |
10980 | return; | |
cf4e594e | 10981 | |
6ff57cf8 JB |
10982 | if (ieee80211_is_deauth(mgmt->frame_control)) |
10983 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
10984 | else | |
10985 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 10986 | |
6ff57cf8 | 10987 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
b0b6aa2c | 10988 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
cf4e594e | 10989 | } |
6ff57cf8 | 10990 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 10991 | |
1b06bb40 LR |
10992 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
10993 | struct net_device *netdev, int cmd, | |
e6d6e342 | 10994 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
10995 | { |
10996 | struct sk_buff *msg; | |
10997 | void *hdr; | |
10998 | ||
e6d6e342 | 10999 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
11000 | if (!msg) |
11001 | return; | |
11002 | ||
11003 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11004 | if (!hdr) { | |
11005 | nlmsg_free(msg); | |
11006 | return; | |
11007 | } | |
11008 | ||
9360ffd1 DM |
11009 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11010 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11011 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
11012 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11013 | goto nla_put_failure; | |
1965c853 | 11014 | |
3b7b72ee | 11015 | genlmsg_end(msg, hdr); |
1965c853 | 11016 | |
68eb5503 | 11017 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11018 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
11019 | return; |
11020 | ||
11021 | nla_put_failure: | |
11022 | genlmsg_cancel(msg, hdr); | |
11023 | nlmsg_free(msg); | |
11024 | } | |
11025 | ||
11026 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11027 | struct net_device *netdev, const u8 *addr, |
11028 | gfp_t gfp) | |
1965c853 JM |
11029 | { |
11030 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 11031 | addr, gfp); |
1965c853 JM |
11032 | } |
11033 | ||
11034 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11035 | struct net_device *netdev, const u8 *addr, |
11036 | gfp_t gfp) | |
1965c853 | 11037 | { |
e6d6e342 JB |
11038 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
11039 | addr, gfp); | |
1965c853 JM |
11040 | } |
11041 | ||
b23aa676 SO |
11042 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
11043 | struct net_device *netdev, const u8 *bssid, | |
11044 | const u8 *req_ie, size_t req_ie_len, | |
11045 | const u8 *resp_ie, size_t resp_ie_len, | |
11046 | u16 status, gfp_t gfp) | |
11047 | { | |
11048 | struct sk_buff *msg; | |
11049 | void *hdr; | |
11050 | ||
58050fce | 11051 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
11052 | if (!msg) |
11053 | return; | |
11054 | ||
11055 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
11056 | if (!hdr) { | |
11057 | nlmsg_free(msg); | |
11058 | return; | |
11059 | } | |
11060 | ||
9360ffd1 DM |
11061 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11062 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11063 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
11064 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
11065 | (req_ie && | |
11066 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11067 | (resp_ie && | |
11068 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11069 | goto nla_put_failure; | |
b23aa676 | 11070 | |
3b7b72ee | 11071 | genlmsg_end(msg, hdr); |
b23aa676 | 11072 | |
68eb5503 | 11073 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11074 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11075 | return; |
11076 | ||
11077 | nla_put_failure: | |
11078 | genlmsg_cancel(msg, hdr); | |
11079 | nlmsg_free(msg); | |
11080 | ||
11081 | } | |
11082 | ||
11083 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
11084 | struct net_device *netdev, const u8 *bssid, | |
11085 | const u8 *req_ie, size_t req_ie_len, | |
11086 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
11087 | { | |
11088 | struct sk_buff *msg; | |
11089 | void *hdr; | |
11090 | ||
58050fce | 11091 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
11092 | if (!msg) |
11093 | return; | |
11094 | ||
11095 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
11096 | if (!hdr) { | |
11097 | nlmsg_free(msg); | |
11098 | return; | |
11099 | } | |
11100 | ||
9360ffd1 DM |
11101 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11102 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11103 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
11104 | (req_ie && | |
11105 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11106 | (resp_ie && | |
11107 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11108 | goto nla_put_failure; | |
b23aa676 | 11109 | |
3b7b72ee | 11110 | genlmsg_end(msg, hdr); |
b23aa676 | 11111 | |
68eb5503 | 11112 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11113 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11114 | return; |
11115 | ||
11116 | nla_put_failure: | |
11117 | genlmsg_cancel(msg, hdr); | |
11118 | nlmsg_free(msg); | |
11119 | ||
11120 | } | |
11121 | ||
11122 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
11123 | struct net_device *netdev, u16 reason, | |
667503dd | 11124 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
11125 | { |
11126 | struct sk_buff *msg; | |
11127 | void *hdr; | |
11128 | ||
58050fce | 11129 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
11130 | if (!msg) |
11131 | return; | |
11132 | ||
11133 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
11134 | if (!hdr) { | |
11135 | nlmsg_free(msg); | |
11136 | return; | |
11137 | } | |
11138 | ||
9360ffd1 DM |
11139 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11140 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11141 | (from_ap && reason && | |
11142 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
11143 | (from_ap && | |
11144 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
11145 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
11146 | goto nla_put_failure; | |
b23aa676 | 11147 | |
3b7b72ee | 11148 | genlmsg_end(msg, hdr); |
b23aa676 | 11149 | |
68eb5503 | 11150 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11151 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
11152 | return; |
11153 | ||
11154 | nla_put_failure: | |
11155 | genlmsg_cancel(msg, hdr); | |
11156 | nlmsg_free(msg); | |
11157 | ||
11158 | } | |
11159 | ||
04a773ad JB |
11160 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
11161 | struct net_device *netdev, const u8 *bssid, | |
11162 | gfp_t gfp) | |
11163 | { | |
11164 | struct sk_buff *msg; | |
11165 | void *hdr; | |
11166 | ||
fd2120ca | 11167 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
11168 | if (!msg) |
11169 | return; | |
11170 | ||
11171 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
11172 | if (!hdr) { | |
11173 | nlmsg_free(msg); | |
11174 | return; | |
11175 | } | |
11176 | ||
9360ffd1 DM |
11177 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11178 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11179 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
11180 | goto nla_put_failure; | |
04a773ad | 11181 | |
3b7b72ee | 11182 | genlmsg_end(msg, hdr); |
04a773ad | 11183 | |
68eb5503 | 11184 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11185 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
11186 | return; |
11187 | ||
11188 | nla_put_failure: | |
11189 | genlmsg_cancel(msg, hdr); | |
11190 | nlmsg_free(msg); | |
11191 | } | |
11192 | ||
947add36 JB |
11193 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
11194 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 11195 | { |
947add36 | 11196 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 11197 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
11198 | struct sk_buff *msg; |
11199 | void *hdr; | |
11200 | ||
947add36 JB |
11201 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
11202 | return; | |
11203 | ||
11204 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
11205 | ||
c93b5e71 JC |
11206 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11207 | if (!msg) | |
11208 | return; | |
11209 | ||
11210 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
11211 | if (!hdr) { | |
11212 | nlmsg_free(msg); | |
11213 | return; | |
11214 | } | |
11215 | ||
9360ffd1 | 11216 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
11217 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
11218 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
11219 | (ie_len && ie && |
11220 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
11221 | goto nla_put_failure; | |
c93b5e71 | 11222 | |
3b7b72ee | 11223 | genlmsg_end(msg, hdr); |
c93b5e71 | 11224 | |
68eb5503 | 11225 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11226 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
11227 | return; |
11228 | ||
11229 | nla_put_failure: | |
11230 | genlmsg_cancel(msg, hdr); | |
11231 | nlmsg_free(msg); | |
11232 | } | |
947add36 | 11233 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 11234 | |
a3b8b056 JM |
11235 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
11236 | struct net_device *netdev, const u8 *addr, | |
11237 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 11238 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
11239 | { |
11240 | struct sk_buff *msg; | |
11241 | void *hdr; | |
11242 | ||
e6d6e342 | 11243 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
11244 | if (!msg) |
11245 | return; | |
11246 | ||
11247 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
11248 | if (!hdr) { | |
11249 | nlmsg_free(msg); | |
11250 | return; | |
11251 | } | |
11252 | ||
9360ffd1 DM |
11253 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11254 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11255 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
11256 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
11257 | (key_id != -1 && | |
11258 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
11259 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
11260 | goto nla_put_failure; | |
a3b8b056 | 11261 | |
3b7b72ee | 11262 | genlmsg_end(msg, hdr); |
a3b8b056 | 11263 | |
68eb5503 | 11264 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11265 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
11266 | return; |
11267 | ||
11268 | nla_put_failure: | |
11269 | genlmsg_cancel(msg, hdr); | |
11270 | nlmsg_free(msg); | |
11271 | } | |
11272 | ||
6bad8766 LR |
11273 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
11274 | struct ieee80211_channel *channel_before, | |
11275 | struct ieee80211_channel *channel_after) | |
11276 | { | |
11277 | struct sk_buff *msg; | |
11278 | void *hdr; | |
11279 | struct nlattr *nl_freq; | |
11280 | ||
fd2120ca | 11281 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
11282 | if (!msg) |
11283 | return; | |
11284 | ||
11285 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
11286 | if (!hdr) { | |
11287 | nlmsg_free(msg); | |
11288 | return; | |
11289 | } | |
11290 | ||
11291 | /* | |
11292 | * Since we are applying the beacon hint to a wiphy we know its | |
11293 | * wiphy_idx is valid | |
11294 | */ | |
9360ffd1 DM |
11295 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
11296 | goto nla_put_failure; | |
6bad8766 LR |
11297 | |
11298 | /* Before */ | |
11299 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
11300 | if (!nl_freq) | |
11301 | goto nla_put_failure; | |
cdc89b97 | 11302 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
11303 | goto nla_put_failure; |
11304 | nla_nest_end(msg, nl_freq); | |
11305 | ||
11306 | /* After */ | |
11307 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
11308 | if (!nl_freq) | |
11309 | goto nla_put_failure; | |
cdc89b97 | 11310 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
11311 | goto nla_put_failure; |
11312 | nla_nest_end(msg, nl_freq); | |
11313 | ||
3b7b72ee | 11314 | genlmsg_end(msg, hdr); |
6bad8766 | 11315 | |
463d0183 | 11316 | rcu_read_lock(); |
68eb5503 | 11317 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11318 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 11319 | rcu_read_unlock(); |
6bad8766 LR |
11320 | |
11321 | return; | |
11322 | ||
11323 | nla_put_failure: | |
11324 | genlmsg_cancel(msg, hdr); | |
11325 | nlmsg_free(msg); | |
11326 | } | |
11327 | ||
9588bbd5 JM |
11328 | static void nl80211_send_remain_on_chan_event( |
11329 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 11330 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 11331 | struct ieee80211_channel *chan, |
9588bbd5 JM |
11332 | unsigned int duration, gfp_t gfp) |
11333 | { | |
11334 | struct sk_buff *msg; | |
11335 | void *hdr; | |
11336 | ||
11337 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11338 | if (!msg) | |
11339 | return; | |
11340 | ||
11341 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11342 | if (!hdr) { | |
11343 | nlmsg_free(msg); | |
11344 | return; | |
11345 | } | |
11346 | ||
9360ffd1 | 11347 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11348 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11349 | wdev->netdev->ifindex)) || | |
00f53350 | 11350 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 11351 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
11352 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
11353 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
11354 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
11355 | goto nla_put_failure; | |
9588bbd5 | 11356 | |
9360ffd1 DM |
11357 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
11358 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
11359 | goto nla_put_failure; | |
9588bbd5 | 11360 | |
3b7b72ee | 11361 | genlmsg_end(msg, hdr); |
9588bbd5 | 11362 | |
68eb5503 | 11363 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11364 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
11365 | return; |
11366 | ||
11367 | nla_put_failure: | |
11368 | genlmsg_cancel(msg, hdr); | |
11369 | nlmsg_free(msg); | |
11370 | } | |
11371 | ||
947add36 JB |
11372 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
11373 | struct ieee80211_channel *chan, | |
11374 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 11375 | { |
947add36 | 11376 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11377 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11378 | |
11379 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 11380 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 11381 | rdev, wdev, cookie, chan, |
42d97a59 | 11382 | duration, gfp); |
9588bbd5 | 11383 | } |
947add36 | 11384 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 11385 | |
947add36 JB |
11386 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
11387 | struct ieee80211_channel *chan, | |
11388 | gfp_t gfp) | |
9588bbd5 | 11389 | { |
947add36 | 11390 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11391 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11392 | |
11393 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 11394 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 11395 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 11396 | } |
947add36 | 11397 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 11398 | |
947add36 JB |
11399 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
11400 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 11401 | { |
947add36 | 11402 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11403 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
11404 | struct sk_buff *msg; |
11405 | ||
947add36 JB |
11406 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
11407 | ||
58050fce | 11408 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
11409 | if (!msg) |
11410 | return; | |
11411 | ||
66266b3a JL |
11412 | if (nl80211_send_station(msg, 0, 0, 0, |
11413 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
11414 | nlmsg_free(msg); |
11415 | return; | |
11416 | } | |
11417 | ||
68eb5503 | 11418 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11419 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 11420 | } |
947add36 | 11421 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 11422 | |
947add36 | 11423 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 11424 | { |
947add36 | 11425 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11426 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b JM |
11427 | struct sk_buff *msg; |
11428 | void *hdr; | |
11429 | ||
947add36 JB |
11430 | trace_cfg80211_del_sta(dev, mac_addr); |
11431 | ||
58050fce | 11432 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
11433 | if (!msg) |
11434 | return; | |
11435 | ||
11436 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
11437 | if (!hdr) { | |
11438 | nlmsg_free(msg); | |
11439 | return; | |
11440 | } | |
11441 | ||
9360ffd1 DM |
11442 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
11443 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
11444 | goto nla_put_failure; | |
ec15e68b | 11445 | |
3b7b72ee | 11446 | genlmsg_end(msg, hdr); |
ec15e68b | 11447 | |
68eb5503 | 11448 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11449 | NL80211_MCGRP_MLME, gfp); |
ec15e68b JM |
11450 | return; |
11451 | ||
11452 | nla_put_failure: | |
11453 | genlmsg_cancel(msg, hdr); | |
11454 | nlmsg_free(msg); | |
11455 | } | |
947add36 | 11456 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 11457 | |
947add36 JB |
11458 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
11459 | enum nl80211_connect_failed_reason reason, | |
11460 | gfp_t gfp) | |
ed44a951 | 11461 | { |
947add36 | 11462 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11463 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
11464 | struct sk_buff *msg; |
11465 | void *hdr; | |
11466 | ||
11467 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
11468 | if (!msg) | |
11469 | return; | |
11470 | ||
11471 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
11472 | if (!hdr) { | |
11473 | nlmsg_free(msg); | |
11474 | return; | |
11475 | } | |
11476 | ||
11477 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11478 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
11479 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
11480 | goto nla_put_failure; | |
11481 | ||
11482 | genlmsg_end(msg, hdr); | |
11483 | ||
68eb5503 | 11484 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11485 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
11486 | return; |
11487 | ||
11488 | nla_put_failure: | |
11489 | genlmsg_cancel(msg, hdr); | |
11490 | nlmsg_free(msg); | |
11491 | } | |
947add36 | 11492 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 11493 | |
b92ab5d8 JB |
11494 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
11495 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
11496 | { |
11497 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 11498 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
11499 | struct sk_buff *msg; |
11500 | void *hdr; | |
15e47304 | 11501 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 11502 | |
15e47304 | 11503 | if (!nlportid) |
28946da7 JB |
11504 | return false; |
11505 | ||
11506 | msg = nlmsg_new(100, gfp); | |
11507 | if (!msg) | |
11508 | return true; | |
11509 | ||
b92ab5d8 | 11510 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
11511 | if (!hdr) { |
11512 | nlmsg_free(msg); | |
11513 | return true; | |
11514 | } | |
11515 | ||
9360ffd1 DM |
11516 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11517 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11518 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11519 | goto nla_put_failure; | |
28946da7 | 11520 | |
9c90a9f6 | 11521 | genlmsg_end(msg, hdr); |
15e47304 | 11522 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
11523 | return true; |
11524 | ||
11525 | nla_put_failure: | |
11526 | genlmsg_cancel(msg, hdr); | |
11527 | nlmsg_free(msg); | |
11528 | return true; | |
11529 | } | |
11530 | ||
947add36 JB |
11531 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
11532 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11533 | { |
947add36 JB |
11534 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11535 | bool ret; | |
11536 | ||
11537 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
11538 | ||
11539 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11540 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
11541 | trace_cfg80211_return_bool(false); | |
11542 | return false; | |
11543 | } | |
11544 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
11545 | addr, gfp); | |
11546 | trace_cfg80211_return_bool(ret); | |
11547 | return ret; | |
b92ab5d8 | 11548 | } |
947add36 | 11549 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 11550 | |
947add36 JB |
11551 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
11552 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11553 | { |
947add36 JB |
11554 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11555 | bool ret; | |
11556 | ||
11557 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
11558 | ||
11559 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11560 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
11561 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
11562 | trace_cfg80211_return_bool(false); | |
11563 | return false; | |
11564 | } | |
11565 | ret = __nl80211_unexpected_frame(dev, | |
11566 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
11567 | addr, gfp); | |
11568 | trace_cfg80211_return_bool(ret); | |
11569 | return ret; | |
b92ab5d8 | 11570 | } |
947add36 | 11571 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 11572 | |
2e161f78 | 11573 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 11574 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 11575 | int freq, int sig_dbm, |
19504cf5 | 11576 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 11577 | { |
71bbc994 | 11578 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11579 | struct sk_buff *msg; |
11580 | void *hdr; | |
026331c4 JM |
11581 | |
11582 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11583 | if (!msg) | |
11584 | return -ENOMEM; | |
11585 | ||
2e161f78 | 11586 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
11587 | if (!hdr) { |
11588 | nlmsg_free(msg); | |
11589 | return -ENOMEM; | |
11590 | } | |
11591 | ||
9360ffd1 | 11592 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11593 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11594 | netdev->ifindex)) || | |
a838490b | 11595 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11596 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
11597 | (sig_dbm && | |
11598 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
11599 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11600 | (flags && | |
11601 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 11602 | goto nla_put_failure; |
026331c4 | 11603 | |
3b7b72ee | 11604 | genlmsg_end(msg, hdr); |
026331c4 | 11605 | |
15e47304 | 11606 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
11607 | |
11608 | nla_put_failure: | |
11609 | genlmsg_cancel(msg, hdr); | |
11610 | nlmsg_free(msg); | |
11611 | return -ENOBUFS; | |
11612 | } | |
11613 | ||
947add36 JB |
11614 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
11615 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 11616 | { |
947add36 | 11617 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11618 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 11619 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11620 | struct sk_buff *msg; |
11621 | void *hdr; | |
11622 | ||
947add36 JB |
11623 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
11624 | ||
026331c4 JM |
11625 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11626 | if (!msg) | |
11627 | return; | |
11628 | ||
2e161f78 | 11629 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
11630 | if (!hdr) { |
11631 | nlmsg_free(msg); | |
11632 | return; | |
11633 | } | |
11634 | ||
9360ffd1 | 11635 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11636 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11637 | netdev->ifindex)) || | |
a838490b | 11638 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11639 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11640 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
11641 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
11642 | goto nla_put_failure; | |
026331c4 | 11643 | |
3b7b72ee | 11644 | genlmsg_end(msg, hdr); |
026331c4 | 11645 | |
68eb5503 | 11646 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11647 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
11648 | return; |
11649 | ||
11650 | nla_put_failure: | |
11651 | genlmsg_cancel(msg, hdr); | |
11652 | nlmsg_free(msg); | |
11653 | } | |
947add36 | 11654 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 11655 | |
947add36 JB |
11656 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
11657 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
11658 | gfp_t gfp) | |
d6dc1a38 | 11659 | { |
947add36 JB |
11660 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11661 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11662 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
d6dc1a38 JO |
11663 | struct sk_buff *msg; |
11664 | struct nlattr *pinfoattr; | |
11665 | void *hdr; | |
11666 | ||
947add36 JB |
11667 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
11668 | ||
58050fce | 11669 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
11670 | if (!msg) |
11671 | return; | |
11672 | ||
11673 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11674 | if (!hdr) { | |
11675 | nlmsg_free(msg); | |
11676 | return; | |
11677 | } | |
11678 | ||
9360ffd1 | 11679 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 11680 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 11681 | goto nla_put_failure; |
d6dc1a38 JO |
11682 | |
11683 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11684 | if (!pinfoattr) | |
11685 | goto nla_put_failure; | |
11686 | ||
9360ffd1 DM |
11687 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
11688 | rssi_event)) | |
11689 | goto nla_put_failure; | |
d6dc1a38 JO |
11690 | |
11691 | nla_nest_end(msg, pinfoattr); | |
11692 | ||
3b7b72ee | 11693 | genlmsg_end(msg, hdr); |
d6dc1a38 | 11694 | |
68eb5503 | 11695 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11696 | NL80211_MCGRP_MLME, gfp); |
d6dc1a38 JO |
11697 | return; |
11698 | ||
11699 | nla_put_failure: | |
11700 | genlmsg_cancel(msg, hdr); | |
11701 | nlmsg_free(msg); | |
11702 | } | |
947add36 | 11703 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 11704 | |
947add36 JB |
11705 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
11706 | struct net_device *netdev, const u8 *bssid, | |
11707 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
11708 | { |
11709 | struct sk_buff *msg; | |
11710 | struct nlattr *rekey_attr; | |
11711 | void *hdr; | |
11712 | ||
58050fce | 11713 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
11714 | if (!msg) |
11715 | return; | |
11716 | ||
11717 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
11718 | if (!hdr) { | |
11719 | nlmsg_free(msg); | |
11720 | return; | |
11721 | } | |
11722 | ||
9360ffd1 DM |
11723 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11724 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11725 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
11726 | goto nla_put_failure; | |
e5497d76 JB |
11727 | |
11728 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
11729 | if (!rekey_attr) | |
11730 | goto nla_put_failure; | |
11731 | ||
9360ffd1 DM |
11732 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
11733 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
11734 | goto nla_put_failure; | |
e5497d76 JB |
11735 | |
11736 | nla_nest_end(msg, rekey_attr); | |
11737 | ||
3b7b72ee | 11738 | genlmsg_end(msg, hdr); |
e5497d76 | 11739 | |
68eb5503 | 11740 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11741 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
11742 | return; |
11743 | ||
11744 | nla_put_failure: | |
11745 | genlmsg_cancel(msg, hdr); | |
11746 | nlmsg_free(msg); | |
11747 | } | |
11748 | ||
947add36 JB |
11749 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
11750 | const u8 *replay_ctr, gfp_t gfp) | |
11751 | { | |
11752 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11753 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11754 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11755 | |
11756 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
11757 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
11758 | } | |
11759 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
11760 | ||
11761 | static void | |
11762 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
11763 | struct net_device *netdev, int index, | |
11764 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
11765 | { |
11766 | struct sk_buff *msg; | |
11767 | struct nlattr *attr; | |
11768 | void *hdr; | |
11769 | ||
58050fce | 11770 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
11771 | if (!msg) |
11772 | return; | |
11773 | ||
11774 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
11775 | if (!hdr) { | |
11776 | nlmsg_free(msg); | |
11777 | return; | |
11778 | } | |
11779 | ||
9360ffd1 DM |
11780 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11781 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
11782 | goto nla_put_failure; | |
c9df56b4 JM |
11783 | |
11784 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
11785 | if (!attr) | |
11786 | goto nla_put_failure; | |
11787 | ||
9360ffd1 DM |
11788 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
11789 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
11790 | (preauth && | |
11791 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
11792 | goto nla_put_failure; | |
c9df56b4 JM |
11793 | |
11794 | nla_nest_end(msg, attr); | |
11795 | ||
3b7b72ee | 11796 | genlmsg_end(msg, hdr); |
c9df56b4 | 11797 | |
68eb5503 | 11798 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11799 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
11800 | return; |
11801 | ||
11802 | nla_put_failure: | |
11803 | genlmsg_cancel(msg, hdr); | |
11804 | nlmsg_free(msg); | |
11805 | } | |
11806 | ||
947add36 JB |
11807 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
11808 | const u8 *bssid, bool preauth, gfp_t gfp) | |
11809 | { | |
11810 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11811 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11812 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11813 | |
11814 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
11815 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
11816 | } | |
11817 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
11818 | ||
11819 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
11820 | struct net_device *netdev, | |
11821 | struct cfg80211_chan_def *chandef, | |
f8d7552e LC |
11822 | gfp_t gfp, |
11823 | enum nl80211_commands notif, | |
11824 | u8 count) | |
5314526b TP |
11825 | { |
11826 | struct sk_buff *msg; | |
11827 | void *hdr; | |
11828 | ||
58050fce | 11829 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
11830 | if (!msg) |
11831 | return; | |
11832 | ||
f8d7552e | 11833 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
5314526b TP |
11834 | if (!hdr) { |
11835 | nlmsg_free(msg); | |
11836 | return; | |
11837 | } | |
11838 | ||
683b6d3b JB |
11839 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
11840 | goto nla_put_failure; | |
11841 | ||
11842 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 11843 | goto nla_put_failure; |
5314526b | 11844 | |
f8d7552e LC |
11845 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
11846 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) | |
11847 | goto nla_put_failure; | |
11848 | ||
5314526b TP |
11849 | genlmsg_end(msg, hdr); |
11850 | ||
68eb5503 | 11851 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11852 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
11853 | return; |
11854 | ||
11855 | nla_put_failure: | |
11856 | genlmsg_cancel(msg, hdr); | |
11857 | nlmsg_free(msg); | |
11858 | } | |
11859 | ||
947add36 JB |
11860 | void cfg80211_ch_switch_notify(struct net_device *dev, |
11861 | struct cfg80211_chan_def *chandef) | |
84f10708 | 11862 | { |
947add36 JB |
11863 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11864 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11865 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 11866 | |
e487eaeb | 11867 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 11868 | |
e487eaeb | 11869 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 | 11870 | |
9e0e2961 | 11871 | wdev->chandef = *chandef; |
96f55f12 | 11872 | wdev->preset_chandef = *chandef; |
f8d7552e LC |
11873 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
11874 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); | |
947add36 JB |
11875 | } |
11876 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
11877 | ||
f8d7552e LC |
11878 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
11879 | struct cfg80211_chan_def *chandef, | |
11880 | u8 count) | |
11881 | { | |
11882 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11883 | struct wiphy *wiphy = wdev->wiphy; | |
11884 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
11885 | ||
11886 | trace_cfg80211_ch_switch_started_notify(dev, chandef); | |
11887 | ||
11888 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | |
11889 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); | |
11890 | } | |
11891 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | |
11892 | ||
947add36 JB |
11893 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
11894 | const u8 *peer, u32 num_packets, | |
11895 | u32 rate, u32 intvl, gfp_t gfp) | |
11896 | { | |
11897 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11898 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11899 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
84f10708 TP |
11900 | struct sk_buff *msg; |
11901 | struct nlattr *pinfoattr; | |
11902 | void *hdr; | |
11903 | ||
11904 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
11905 | if (!msg) | |
11906 | return; | |
11907 | ||
11908 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11909 | if (!hdr) { | |
11910 | nlmsg_free(msg); | |
11911 | return; | |
11912 | } | |
11913 | ||
11914 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
947add36 | 11915 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
84f10708 TP |
11916 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
11917 | goto nla_put_failure; | |
11918 | ||
11919 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11920 | if (!pinfoattr) | |
11921 | goto nla_put_failure; | |
11922 | ||
11923 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
11924 | goto nla_put_failure; | |
11925 | ||
11926 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
11927 | goto nla_put_failure; | |
11928 | ||
11929 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
11930 | goto nla_put_failure; | |
11931 | ||
11932 | nla_nest_end(msg, pinfoattr); | |
11933 | ||
11934 | genlmsg_end(msg, hdr); | |
11935 | ||
68eb5503 | 11936 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11937 | NL80211_MCGRP_MLME, gfp); |
84f10708 TP |
11938 | return; |
11939 | ||
11940 | nla_put_failure: | |
11941 | genlmsg_cancel(msg, hdr); | |
11942 | nlmsg_free(msg); | |
11943 | } | |
947add36 | 11944 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
84f10708 | 11945 | |
04f39047 SW |
11946 | void |
11947 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 11948 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
11949 | enum nl80211_radar_event event, |
11950 | struct net_device *netdev, gfp_t gfp) | |
11951 | { | |
11952 | struct sk_buff *msg; | |
11953 | void *hdr; | |
11954 | ||
11955 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11956 | if (!msg) | |
11957 | return; | |
11958 | ||
11959 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
11960 | if (!hdr) { | |
11961 | nlmsg_free(msg); | |
11962 | return; | |
11963 | } | |
11964 | ||
11965 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
11966 | goto nla_put_failure; | |
11967 | ||
11968 | /* NOP and radar events don't need a netdev parameter */ | |
11969 | if (netdev) { | |
11970 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
11971 | ||
11972 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11973 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11974 | goto nla_put_failure; | |
11975 | } | |
11976 | ||
11977 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
11978 | goto nla_put_failure; | |
11979 | ||
11980 | if (nl80211_send_chandef(msg, chandef)) | |
11981 | goto nla_put_failure; | |
11982 | ||
9c90a9f6 | 11983 | genlmsg_end(msg, hdr); |
04f39047 | 11984 | |
68eb5503 | 11985 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11986 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
11987 | return; |
11988 | ||
11989 | nla_put_failure: | |
11990 | genlmsg_cancel(msg, hdr); | |
11991 | nlmsg_free(msg); | |
11992 | } | |
11993 | ||
947add36 JB |
11994 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
11995 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
c063dbf5 | 11996 | { |
947add36 JB |
11997 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11998 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11999 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
c063dbf5 JB |
12000 | struct sk_buff *msg; |
12001 | struct nlattr *pinfoattr; | |
12002 | void *hdr; | |
12003 | ||
947add36 JB |
12004 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
12005 | ||
58050fce | 12006 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
12007 | if (!msg) |
12008 | return; | |
12009 | ||
12010 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
12011 | if (!hdr) { | |
12012 | nlmsg_free(msg); | |
12013 | return; | |
12014 | } | |
12015 | ||
9360ffd1 | 12016 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 12017 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9360ffd1 DM |
12018 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
12019 | goto nla_put_failure; | |
c063dbf5 JB |
12020 | |
12021 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
12022 | if (!pinfoattr) | |
12023 | goto nla_put_failure; | |
12024 | ||
9360ffd1 DM |
12025 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
12026 | goto nla_put_failure; | |
c063dbf5 JB |
12027 | |
12028 | nla_nest_end(msg, pinfoattr); | |
12029 | ||
3b7b72ee | 12030 | genlmsg_end(msg, hdr); |
c063dbf5 | 12031 | |
68eb5503 | 12032 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12033 | NL80211_MCGRP_MLME, gfp); |
c063dbf5 JB |
12034 | return; |
12035 | ||
12036 | nla_put_failure: | |
12037 | genlmsg_cancel(msg, hdr); | |
12038 | nlmsg_free(msg); | |
12039 | } | |
947add36 | 12040 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
c063dbf5 | 12041 | |
7f6cf311 JB |
12042 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
12043 | u64 cookie, bool acked, gfp_t gfp) | |
12044 | { | |
12045 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12046 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
12047 | struct sk_buff *msg; |
12048 | void *hdr; | |
7f6cf311 | 12049 | |
4ee3e063 BL |
12050 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
12051 | ||
58050fce | 12052 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 12053 | |
7f6cf311 JB |
12054 | if (!msg) |
12055 | return; | |
12056 | ||
12057 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
12058 | if (!hdr) { | |
12059 | nlmsg_free(msg); | |
12060 | return; | |
12061 | } | |
12062 | ||
9360ffd1 DM |
12063 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12064 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12065 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
12066 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
12067 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
12068 | goto nla_put_failure; | |
7f6cf311 | 12069 | |
9c90a9f6 | 12070 | genlmsg_end(msg, hdr); |
7f6cf311 | 12071 | |
68eb5503 | 12072 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12073 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
12074 | return; |
12075 | ||
12076 | nla_put_failure: | |
12077 | genlmsg_cancel(msg, hdr); | |
12078 | nlmsg_free(msg); | |
12079 | } | |
12080 | EXPORT_SYMBOL(cfg80211_probe_status); | |
12081 | ||
5e760230 JB |
12082 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
12083 | const u8 *frame, size_t len, | |
37c73b5f | 12084 | int freq, int sig_dbm) |
5e760230 | 12085 | { |
f26cbf40 | 12086 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
12087 | struct sk_buff *msg; |
12088 | void *hdr; | |
37c73b5f | 12089 | struct cfg80211_beacon_registration *reg; |
5e760230 | 12090 | |
4ee3e063 BL |
12091 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
12092 | ||
37c73b5f BG |
12093 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12094 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
12095 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
12096 | if (!msg) { | |
12097 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
12098 | return; | |
12099 | } | |
5e760230 | 12100 | |
37c73b5f BG |
12101 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
12102 | if (!hdr) | |
12103 | goto nla_put_failure; | |
5e760230 | 12104 | |
37c73b5f BG |
12105 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12106 | (freq && | |
12107 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
12108 | (sig_dbm && | |
12109 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
12110 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
12111 | goto nla_put_failure; | |
5e760230 | 12112 | |
37c73b5f | 12113 | genlmsg_end(msg, hdr); |
5e760230 | 12114 | |
37c73b5f BG |
12115 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
12116 | } | |
12117 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
12118 | return; |
12119 | ||
12120 | nla_put_failure: | |
37c73b5f BG |
12121 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
12122 | if (hdr) | |
12123 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
12124 | nlmsg_free(msg); |
12125 | } | |
12126 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
12127 | ||
cd8f7cb4 | 12128 | #ifdef CONFIG_PM |
8cd4d456 LC |
12129 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
12130 | struct cfg80211_wowlan_wakeup *wakeup) | |
12131 | { | |
12132 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | |
12133 | struct nlattr *nl_results, *nl_match, *nl_freqs; | |
12134 | int i, j; | |
12135 | ||
12136 | nl_results = nla_nest_start( | |
12137 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | |
12138 | if (!nl_results) | |
12139 | return -EMSGSIZE; | |
12140 | ||
12141 | for (i = 0; i < nd->n_matches; i++) { | |
12142 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | |
12143 | ||
12144 | nl_match = nla_nest_start(msg, i); | |
12145 | if (!nl_match) | |
12146 | break; | |
12147 | ||
12148 | /* The SSID attribute is optional in nl80211, but for | |
12149 | * simplicity reasons it's always present in the | |
12150 | * cfg80211 structure. If a driver can't pass the | |
12151 | * SSID, that needs to be changed. A zero length SSID | |
12152 | * is still a valid SSID (wildcard), so it cannot be | |
12153 | * used for this purpose. | |
12154 | */ | |
12155 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | |
12156 | match->ssid.ssid)) { | |
12157 | nla_nest_cancel(msg, nl_match); | |
12158 | goto out; | |
12159 | } | |
12160 | ||
12161 | if (match->n_channels) { | |
12162 | nl_freqs = nla_nest_start( | |
12163 | msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
12164 | if (!nl_freqs) { | |
12165 | nla_nest_cancel(msg, nl_match); | |
12166 | goto out; | |
12167 | } | |
12168 | ||
12169 | for (j = 0; j < match->n_channels; j++) { | |
12170 | if (nla_put_u32(msg, | |
12171 | NL80211_ATTR_WIPHY_FREQ, | |
12172 | match->channels[j])) { | |
12173 | nla_nest_cancel(msg, nl_freqs); | |
12174 | nla_nest_cancel(msg, nl_match); | |
12175 | goto out; | |
12176 | } | |
12177 | } | |
12178 | ||
12179 | nla_nest_end(msg, nl_freqs); | |
12180 | } | |
12181 | ||
12182 | nla_nest_end(msg, nl_match); | |
12183 | } | |
12184 | ||
12185 | out: | |
12186 | nla_nest_end(msg, nl_results); | |
12187 | return 0; | |
12188 | } | |
12189 | ||
cd8f7cb4 JB |
12190 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
12191 | struct cfg80211_wowlan_wakeup *wakeup, | |
12192 | gfp_t gfp) | |
12193 | { | |
f26cbf40 | 12194 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
12195 | struct sk_buff *msg; |
12196 | void *hdr; | |
9c90a9f6 | 12197 | int size = 200; |
cd8f7cb4 JB |
12198 | |
12199 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
12200 | ||
12201 | if (wakeup) | |
12202 | size += wakeup->packet_present_len; | |
12203 | ||
12204 | msg = nlmsg_new(size, gfp); | |
12205 | if (!msg) | |
12206 | return; | |
12207 | ||
12208 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
12209 | if (!hdr) | |
12210 | goto free_msg; | |
12211 | ||
12212 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12213 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12214 | goto free_msg; | |
12215 | ||
12216 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
12217 | wdev->netdev->ifindex)) | |
12218 | goto free_msg; | |
12219 | ||
12220 | if (wakeup) { | |
12221 | struct nlattr *reasons; | |
12222 | ||
12223 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
12224 | if (!reasons) |
12225 | goto free_msg; | |
cd8f7cb4 JB |
12226 | |
12227 | if (wakeup->disconnect && | |
12228 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
12229 | goto free_msg; | |
12230 | if (wakeup->magic_pkt && | |
12231 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
12232 | goto free_msg; | |
12233 | if (wakeup->gtk_rekey_failure && | |
12234 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
12235 | goto free_msg; | |
12236 | if (wakeup->eap_identity_req && | |
12237 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
12238 | goto free_msg; | |
12239 | if (wakeup->four_way_handshake && | |
12240 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
12241 | goto free_msg; | |
12242 | if (wakeup->rfkill_release && | |
12243 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
12244 | goto free_msg; | |
12245 | ||
12246 | if (wakeup->pattern_idx >= 0 && | |
12247 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
12248 | wakeup->pattern_idx)) | |
12249 | goto free_msg; | |
12250 | ||
ae917c9f JB |
12251 | if (wakeup->tcp_match && |
12252 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
12253 | goto free_msg; | |
2a0e047e | 12254 | |
ae917c9f JB |
12255 | if (wakeup->tcp_connlost && |
12256 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
12257 | goto free_msg; | |
2a0e047e | 12258 | |
ae917c9f JB |
12259 | if (wakeup->tcp_nomoretokens && |
12260 | nla_put_flag(msg, | |
12261 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
12262 | goto free_msg; | |
2a0e047e | 12263 | |
cd8f7cb4 JB |
12264 | if (wakeup->packet) { |
12265 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
12266 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
12267 | ||
12268 | if (!wakeup->packet_80211) { | |
12269 | pkt_attr = | |
12270 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
12271 | len_attr = | |
12272 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
12273 | } | |
12274 | ||
12275 | if (wakeup->packet_len && | |
12276 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
12277 | goto free_msg; | |
12278 | ||
12279 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
12280 | wakeup->packet)) | |
12281 | goto free_msg; | |
12282 | } | |
12283 | ||
8cd4d456 LC |
12284 | if (wakeup->net_detect && |
12285 | cfg80211_net_detect_results(msg, wakeup)) | |
12286 | goto free_msg; | |
12287 | ||
cd8f7cb4 JB |
12288 | nla_nest_end(msg, reasons); |
12289 | } | |
12290 | ||
9c90a9f6 | 12291 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 12292 | |
68eb5503 | 12293 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12294 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
12295 | return; |
12296 | ||
12297 | free_msg: | |
12298 | nlmsg_free(msg); | |
12299 | } | |
12300 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
12301 | #endif | |
12302 | ||
3475b094 JM |
12303 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
12304 | enum nl80211_tdls_operation oper, | |
12305 | u16 reason_code, gfp_t gfp) | |
12306 | { | |
12307 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12308 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
12309 | struct sk_buff *msg; |
12310 | void *hdr; | |
3475b094 JM |
12311 | |
12312 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
12313 | reason_code); | |
12314 | ||
12315 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12316 | if (!msg) | |
12317 | return; | |
12318 | ||
12319 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
12320 | if (!hdr) { | |
12321 | nlmsg_free(msg); | |
12322 | return; | |
12323 | } | |
12324 | ||
12325 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12326 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12327 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
12328 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
12329 | (reason_code > 0 && | |
12330 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
12331 | goto nla_put_failure; | |
12332 | ||
9c90a9f6 | 12333 | genlmsg_end(msg, hdr); |
3475b094 | 12334 | |
68eb5503 | 12335 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12336 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
12337 | return; |
12338 | ||
12339 | nla_put_failure: | |
12340 | genlmsg_cancel(msg, hdr); | |
12341 | nlmsg_free(msg); | |
12342 | } | |
12343 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
12344 | ||
026331c4 JM |
12345 | static int nl80211_netlink_notify(struct notifier_block * nb, |
12346 | unsigned long state, | |
12347 | void *_notify) | |
12348 | { | |
12349 | struct netlink_notify *notify = _notify; | |
12350 | struct cfg80211_registered_device *rdev; | |
12351 | struct wireless_dev *wdev; | |
37c73b5f | 12352 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
12353 | |
12354 | if (state != NETLINK_URELEASE) | |
12355 | return NOTIFY_DONE; | |
12356 | ||
12357 | rcu_read_lock(); | |
12358 | ||
5e760230 | 12359 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
78f22b6a JB |
12360 | bool schedule_destroy_work = false; |
12361 | ||
12362 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { | |
15e47304 | 12363 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 12364 | |
78f22b6a JB |
12365 | if (wdev->owner_nlportid == notify->portid) |
12366 | schedule_destroy_work = true; | |
12367 | } | |
12368 | ||
37c73b5f BG |
12369 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12370 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
12371 | list) { | |
12372 | if (reg->nlportid == notify->portid) { | |
12373 | list_del(®->list); | |
12374 | kfree(reg); | |
12375 | break; | |
12376 | } | |
12377 | } | |
12378 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
78f22b6a JB |
12379 | |
12380 | if (schedule_destroy_work) { | |
12381 | struct cfg80211_iface_destroy *destroy; | |
12382 | ||
12383 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | |
12384 | if (destroy) { | |
12385 | destroy->nlportid = notify->portid; | |
12386 | spin_lock(&rdev->destroy_list_lock); | |
12387 | list_add(&destroy->list, &rdev->destroy_list); | |
12388 | spin_unlock(&rdev->destroy_list_lock); | |
12389 | schedule_work(&rdev->destroy_work); | |
12390 | } | |
12391 | } | |
5e760230 | 12392 | } |
026331c4 JM |
12393 | |
12394 | rcu_read_unlock(); | |
12395 | ||
6784c7db | 12396 | return NOTIFY_OK; |
026331c4 JM |
12397 | } |
12398 | ||
12399 | static struct notifier_block nl80211_netlink_notifier = { | |
12400 | .notifier_call = nl80211_netlink_notify, | |
12401 | }; | |
12402 | ||
355199e0 JM |
12403 | void cfg80211_ft_event(struct net_device *netdev, |
12404 | struct cfg80211_ft_event_params *ft_event) | |
12405 | { | |
12406 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 12407 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
12408 | struct sk_buff *msg; |
12409 | void *hdr; | |
355199e0 JM |
12410 | |
12411 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
12412 | ||
12413 | if (!ft_event->target_ap) | |
12414 | return; | |
12415 | ||
12416 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12417 | if (!msg) | |
12418 | return; | |
12419 | ||
12420 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
12421 | if (!hdr) |
12422 | goto out; | |
355199e0 | 12423 | |
ae917c9f JB |
12424 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12425 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12426 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
12427 | goto out; | |
355199e0 | 12428 | |
ae917c9f JB |
12429 | if (ft_event->ies && |
12430 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
12431 | goto out; | |
12432 | if (ft_event->ric_ies && | |
12433 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
12434 | ft_event->ric_ies)) | |
12435 | goto out; | |
355199e0 | 12436 | |
9c90a9f6 | 12437 | genlmsg_end(msg, hdr); |
355199e0 | 12438 | |
68eb5503 | 12439 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12440 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
12441 | return; |
12442 | out: | |
12443 | nlmsg_free(msg); | |
355199e0 JM |
12444 | } |
12445 | EXPORT_SYMBOL(cfg80211_ft_event); | |
12446 | ||
5de17984 AS |
12447 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
12448 | { | |
12449 | struct cfg80211_registered_device *rdev; | |
12450 | struct sk_buff *msg; | |
12451 | void *hdr; | |
12452 | u32 nlportid; | |
12453 | ||
f26cbf40 | 12454 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
12455 | if (!rdev->crit_proto_nlportid) |
12456 | return; | |
12457 | ||
12458 | nlportid = rdev->crit_proto_nlportid; | |
12459 | rdev->crit_proto_nlportid = 0; | |
12460 | ||
12461 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12462 | if (!msg) | |
12463 | return; | |
12464 | ||
12465 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
12466 | if (!hdr) | |
12467 | goto nla_put_failure; | |
12468 | ||
12469 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12470 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12471 | goto nla_put_failure; | |
12472 | ||
12473 | genlmsg_end(msg, hdr); | |
12474 | ||
12475 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
12476 | return; | |
12477 | ||
12478 | nla_put_failure: | |
12479 | if (hdr) | |
12480 | genlmsg_cancel(msg, hdr); | |
12481 | nlmsg_free(msg); | |
12482 | ||
12483 | } | |
12484 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
12485 | ||
348baf0e JB |
12486 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
12487 | { | |
12488 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12489 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
12490 | struct sk_buff *msg; |
12491 | void *hdr; | |
12492 | ||
12493 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12494 | if (!msg) | |
12495 | return; | |
12496 | ||
12497 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
12498 | if (!hdr) | |
12499 | goto out; | |
12500 | ||
12501 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12502 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
12503 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12504 | goto out; | |
12505 | ||
12506 | genlmsg_end(msg, hdr); | |
12507 | ||
12508 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
12509 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
12510 | return; | |
12511 | out: | |
12512 | nlmsg_free(msg); | |
12513 | } | |
12514 | ||
55682965 JB |
12515 | /* initialisation/exit functions */ |
12516 | ||
12517 | int nl80211_init(void) | |
12518 | { | |
0d63cbb5 | 12519 | int err; |
55682965 | 12520 | |
2a94fe48 JB |
12521 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
12522 | nl80211_mcgrps); | |
55682965 JB |
12523 | if (err) |
12524 | return err; | |
12525 | ||
026331c4 JM |
12526 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
12527 | if (err) | |
12528 | goto err_out; | |
12529 | ||
55682965 JB |
12530 | return 0; |
12531 | err_out: | |
12532 | genl_unregister_family(&nl80211_fam); | |
12533 | return err; | |
12534 | } | |
12535 | ||
12536 | void nl80211_exit(void) | |
12537 | { | |
026331c4 | 12538 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
12539 | genl_unregister_family(&nl80211_fam); |
12540 | } |