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 */ |
b54452b0 | 212 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
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 JB |
430 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
431 | }; | |
432 | ||
433 | static const struct nla_policy | |
434 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
435 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
436 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
437 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
438 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
439 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
440 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
441 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
442 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
443 | }, | |
444 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
445 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
446 | }, | |
447 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
448 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
449 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
450 | }; |
451 | ||
be29b99a AK |
452 | /* policy for coalesce rule attributes */ |
453 | static const struct nla_policy | |
454 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
455 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
456 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
457 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
458 | }; | |
459 | ||
e5497d76 JB |
460 | /* policy for GTK rekey offload attributes */ |
461 | static const struct nla_policy | |
462 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
463 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
464 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
465 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
466 | }; | |
467 | ||
a1f1c21c LC |
468 | static const struct nla_policy |
469 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 470 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 471 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 472 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
473 | }; |
474 | ||
97990a06 JB |
475 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
476 | struct netlink_callback *cb, | |
477 | struct cfg80211_registered_device **rdev, | |
478 | struct wireless_dev **wdev) | |
a043897a | 479 | { |
97990a06 | 480 | int err; |
a043897a | 481 | |
97990a06 | 482 | rtnl_lock(); |
a043897a | 483 | |
97990a06 JB |
484 | if (!cb->args[0]) { |
485 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
486 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
487 | nl80211_policy); | |
488 | if (err) | |
489 | goto out_unlock; | |
67748893 | 490 | |
97990a06 JB |
491 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
492 | nl80211_fam.attrbuf); | |
493 | if (IS_ERR(*wdev)) { | |
494 | err = PTR_ERR(*wdev); | |
495 | goto out_unlock; | |
496 | } | |
f26cbf40 | 497 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
498 | /* 0 is the first index - add 1 to parse only once */ |
499 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
500 | cb->args[1] = (*wdev)->identifier; |
501 | } else { | |
c319d50b JB |
502 | /* subtract the 1 again here */ |
503 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 504 | struct wireless_dev *tmp; |
67748893 | 505 | |
97990a06 JB |
506 | if (!wiphy) { |
507 | err = -ENODEV; | |
508 | goto out_unlock; | |
509 | } | |
f26cbf40 | 510 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 511 | *wdev = NULL; |
67748893 | 512 | |
97990a06 JB |
513 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
514 | if (tmp->identifier == cb->args[1]) { | |
515 | *wdev = tmp; | |
516 | break; | |
517 | } | |
518 | } | |
67748893 | 519 | |
97990a06 JB |
520 | if (!*wdev) { |
521 | err = -ENODEV; | |
522 | goto out_unlock; | |
523 | } | |
67748893 JB |
524 | } |
525 | ||
67748893 | 526 | return 0; |
97990a06 | 527 | out_unlock: |
67748893 JB |
528 | rtnl_unlock(); |
529 | return err; | |
530 | } | |
531 | ||
97990a06 | 532 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 533 | { |
67748893 JB |
534 | rtnl_unlock(); |
535 | } | |
536 | ||
f4a11bb0 JB |
537 | /* IE validation */ |
538 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
539 | { | |
540 | const u8 *pos; | |
541 | int len; | |
542 | ||
543 | if (!attr) | |
544 | return true; | |
545 | ||
546 | pos = nla_data(attr); | |
547 | len = nla_len(attr); | |
548 | ||
549 | while (len) { | |
550 | u8 elemlen; | |
551 | ||
552 | if (len < 2) | |
553 | return false; | |
554 | len -= 2; | |
555 | ||
556 | elemlen = pos[1]; | |
557 | if (elemlen > len) | |
558 | return false; | |
559 | ||
560 | len -= elemlen; | |
561 | pos += 2 + elemlen; | |
562 | } | |
563 | ||
564 | return true; | |
565 | } | |
566 | ||
55682965 | 567 | /* message building helper */ |
15e47304 | 568 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
569 | int flags, u8 cmd) |
570 | { | |
571 | /* since there is no private header just add the generic one */ | |
15e47304 | 572 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
573 | } |
574 | ||
5dab3b8a | 575 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
576 | struct ieee80211_channel *chan, |
577 | bool large) | |
5dab3b8a | 578 | { |
ea077c1c RL |
579 | /* Some channels must be completely excluded from the |
580 | * list to protect old user-space tools from breaking | |
581 | */ | |
582 | if (!large && chan->flags & | |
583 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
584 | return 0; | |
585 | ||
9360ffd1 DM |
586 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
587 | chan->center_freq)) | |
588 | goto nla_put_failure; | |
5dab3b8a | 589 | |
9360ffd1 DM |
590 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
591 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
592 | goto nla_put_failure; | |
8fe02e16 LR |
593 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
594 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
595 | goto nla_put_failure; | |
596 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
597 | goto nla_put_failure; | |
598 | } | |
cdc89b97 JB |
599 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
600 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
601 | goto nla_put_failure; | |
602 | if (large) { | |
603 | u32 time; | |
604 | ||
605 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
606 | ||
607 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
608 | chan->dfs_state)) | |
609 | goto nla_put_failure; | |
610 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
611 | time)) | |
612 | goto nla_put_failure; | |
089027e5 JD |
613 | if (nla_put_u32(msg, |
614 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
615 | chan->dfs_cac_ms)) | |
616 | goto nla_put_failure; | |
cdc89b97 JB |
617 | } |
618 | } | |
5dab3b8a | 619 | |
fe1abafd JB |
620 | if (large) { |
621 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
622 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
623 | goto nla_put_failure; | |
624 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
625 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
626 | goto nla_put_failure; | |
627 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
628 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
629 | goto nla_put_failure; | |
630 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
631 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
632 | goto nla_put_failure; | |
570dbde1 DS |
633 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
634 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
635 | goto nla_put_failure; | |
636 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && | |
637 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) | |
638 | goto nla_put_failure; | |
ea077c1c RL |
639 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
640 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
641 | goto nla_put_failure; | |
642 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
643 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
644 | goto nla_put_failure; | |
fe1abafd JB |
645 | } |
646 | ||
9360ffd1 DM |
647 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
648 | DBM_TO_MBM(chan->max_power))) | |
649 | goto nla_put_failure; | |
5dab3b8a LR |
650 | |
651 | return 0; | |
652 | ||
653 | nla_put_failure: | |
654 | return -ENOBUFS; | |
655 | } | |
656 | ||
55682965 JB |
657 | /* netlink command implementations */ |
658 | ||
b9454e83 JB |
659 | struct key_parse { |
660 | struct key_params p; | |
661 | int idx; | |
e31b8213 | 662 | int type; |
b9454e83 | 663 | bool def, defmgmt; |
dbd2fd65 | 664 | bool def_uni, def_multi; |
b9454e83 JB |
665 | }; |
666 | ||
667 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
668 | { | |
669 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
670 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
671 | nl80211_key_policy); | |
672 | if (err) | |
673 | return err; | |
674 | ||
675 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
676 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
677 | ||
dbd2fd65 JB |
678 | if (k->def) { |
679 | k->def_uni = true; | |
680 | k->def_multi = true; | |
681 | } | |
682 | if (k->defmgmt) | |
683 | k->def_multi = true; | |
684 | ||
b9454e83 JB |
685 | if (tb[NL80211_KEY_IDX]) |
686 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
687 | ||
688 | if (tb[NL80211_KEY_DATA]) { | |
689 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
690 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
691 | } | |
692 | ||
693 | if (tb[NL80211_KEY_SEQ]) { | |
694 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
695 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
696 | } | |
697 | ||
698 | if (tb[NL80211_KEY_CIPHER]) | |
699 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
700 | ||
e31b8213 JB |
701 | if (tb[NL80211_KEY_TYPE]) { |
702 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
703 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
704 | return -EINVAL; | |
705 | } | |
706 | ||
dbd2fd65 JB |
707 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
708 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
709 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
710 | tb[NL80211_KEY_DEFAULT_TYPES], | |
711 | nl80211_key_default_policy); | |
dbd2fd65 JB |
712 | if (err) |
713 | return err; | |
714 | ||
715 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
716 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
717 | } | |
718 | ||
b9454e83 JB |
719 | return 0; |
720 | } | |
721 | ||
722 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
723 | { | |
724 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
725 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
726 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
727 | } | |
728 | ||
729 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
730 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
731 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
732 | } | |
733 | ||
734 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
735 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
736 | ||
737 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
738 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
739 | ||
740 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
741 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
742 | ||
dbd2fd65 JB |
743 | if (k->def) { |
744 | k->def_uni = true; | |
745 | k->def_multi = true; | |
746 | } | |
747 | if (k->defmgmt) | |
748 | k->def_multi = true; | |
749 | ||
e31b8213 JB |
750 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
751 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
752 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
753 | return -EINVAL; | |
754 | } | |
755 | ||
dbd2fd65 JB |
756 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
757 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
758 | int err = nla_parse_nested( | |
759 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
760 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
761 | nl80211_key_default_policy); | |
762 | if (err) | |
763 | return err; | |
764 | ||
765 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
766 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
767 | } | |
768 | ||
b9454e83 JB |
769 | return 0; |
770 | } | |
771 | ||
772 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
773 | { | |
774 | int err; | |
775 | ||
776 | memset(k, 0, sizeof(*k)); | |
777 | k->idx = -1; | |
e31b8213 | 778 | k->type = -1; |
b9454e83 JB |
779 | |
780 | if (info->attrs[NL80211_ATTR_KEY]) | |
781 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
782 | else | |
783 | err = nl80211_parse_key_old(info, k); | |
784 | ||
785 | if (err) | |
786 | return err; | |
787 | ||
788 | if (k->def && k->defmgmt) | |
789 | return -EINVAL; | |
790 | ||
dbd2fd65 JB |
791 | if (k->defmgmt) { |
792 | if (k->def_uni || !k->def_multi) | |
793 | return -EINVAL; | |
794 | } | |
795 | ||
b9454e83 JB |
796 | if (k->idx != -1) { |
797 | if (k->defmgmt) { | |
798 | if (k->idx < 4 || k->idx > 5) | |
799 | return -EINVAL; | |
800 | } else if (k->def) { | |
801 | if (k->idx < 0 || k->idx > 3) | |
802 | return -EINVAL; | |
803 | } else { | |
804 | if (k->idx < 0 || k->idx > 5) | |
805 | return -EINVAL; | |
806 | } | |
807 | } | |
808 | ||
809 | return 0; | |
810 | } | |
811 | ||
fffd0934 JB |
812 | static struct cfg80211_cached_keys * |
813 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 814 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
815 | { |
816 | struct key_parse parse; | |
817 | struct nlattr *key; | |
818 | struct cfg80211_cached_keys *result; | |
819 | int rem, err, def = 0; | |
820 | ||
821 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
822 | if (!result) | |
823 | return ERR_PTR(-ENOMEM); | |
824 | ||
825 | result->def = -1; | |
826 | result->defmgmt = -1; | |
827 | ||
828 | nla_for_each_nested(key, keys, rem) { | |
829 | memset(&parse, 0, sizeof(parse)); | |
830 | parse.idx = -1; | |
831 | ||
832 | err = nl80211_parse_key_new(key, &parse); | |
833 | if (err) | |
834 | goto error; | |
835 | err = -EINVAL; | |
836 | if (!parse.p.key) | |
837 | goto error; | |
838 | if (parse.idx < 0 || parse.idx > 4) | |
839 | goto error; | |
840 | if (parse.def) { | |
841 | if (def) | |
842 | goto error; | |
843 | def = 1; | |
844 | result->def = parse.idx; | |
dbd2fd65 JB |
845 | if (!parse.def_uni || !parse.def_multi) |
846 | goto error; | |
fffd0934 JB |
847 | } else if (parse.defmgmt) |
848 | goto error; | |
849 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 850 | parse.idx, false, NULL); |
fffd0934 JB |
851 | if (err) |
852 | goto error; | |
853 | result->params[parse.idx].cipher = parse.p.cipher; | |
854 | result->params[parse.idx].key_len = parse.p.key_len; | |
855 | result->params[parse.idx].key = result->data[parse.idx]; | |
856 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
857 | |
858 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
859 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
860 | if (no_ht) | |
861 | *no_ht = true; | |
862 | } | |
fffd0934 JB |
863 | } |
864 | ||
865 | return result; | |
866 | error: | |
867 | kfree(result); | |
868 | return ERR_PTR(err); | |
869 | } | |
870 | ||
871 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
872 | { | |
873 | ASSERT_WDEV_LOCK(wdev); | |
874 | ||
fffd0934 JB |
875 | switch (wdev->iftype) { |
876 | case NL80211_IFTYPE_AP: | |
877 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 878 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 879 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
880 | break; |
881 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 882 | case NL80211_IFTYPE_STATION: |
074ac8df | 883 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 884 | if (!wdev->current_bss) |
fffd0934 JB |
885 | return -ENOLINK; |
886 | break; | |
887 | default: | |
888 | return -EINVAL; | |
889 | } | |
890 | ||
891 | return 0; | |
892 | } | |
893 | ||
664834de JM |
894 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
895 | struct nlattr *tb) | |
896 | { | |
897 | struct ieee80211_channel *chan; | |
898 | ||
899 | if (tb == NULL) | |
900 | return NULL; | |
901 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
902 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
903 | return NULL; | |
904 | return chan; | |
905 | } | |
906 | ||
7527a782 JB |
907 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
908 | { | |
909 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
910 | int i; | |
911 | ||
912 | if (!nl_modes) | |
913 | goto nla_put_failure; | |
914 | ||
915 | i = 0; | |
916 | while (ifmodes) { | |
9360ffd1 DM |
917 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
918 | goto nla_put_failure; | |
7527a782 JB |
919 | ifmodes >>= 1; |
920 | i++; | |
921 | } | |
922 | ||
923 | nla_nest_end(msg, nl_modes); | |
924 | return 0; | |
925 | ||
926 | nla_put_failure: | |
927 | return -ENOBUFS; | |
928 | } | |
929 | ||
930 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
931 | struct sk_buff *msg, |
932 | bool large) | |
7527a782 JB |
933 | { |
934 | struct nlattr *nl_combis; | |
935 | int i, j; | |
936 | ||
937 | nl_combis = nla_nest_start(msg, | |
938 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
939 | if (!nl_combis) | |
940 | goto nla_put_failure; | |
941 | ||
942 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
943 | const struct ieee80211_iface_combination *c; | |
944 | struct nlattr *nl_combi, *nl_limits; | |
945 | ||
946 | c = &wiphy->iface_combinations[i]; | |
947 | ||
948 | nl_combi = nla_nest_start(msg, i + 1); | |
949 | if (!nl_combi) | |
950 | goto nla_put_failure; | |
951 | ||
952 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
953 | if (!nl_limits) | |
954 | goto nla_put_failure; | |
955 | ||
956 | for (j = 0; j < c->n_limits; j++) { | |
957 | struct nlattr *nl_limit; | |
958 | ||
959 | nl_limit = nla_nest_start(msg, j + 1); | |
960 | if (!nl_limit) | |
961 | goto nla_put_failure; | |
9360ffd1 DM |
962 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
963 | c->limits[j].max)) | |
964 | goto nla_put_failure; | |
7527a782 JB |
965 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
966 | c->limits[j].types)) | |
967 | goto nla_put_failure; | |
968 | nla_nest_end(msg, nl_limit); | |
969 | } | |
970 | ||
971 | nla_nest_end(msg, nl_limits); | |
972 | ||
9360ffd1 DM |
973 | if (c->beacon_int_infra_match && |
974 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
975 | goto nla_put_failure; | |
976 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
977 | c->num_different_channels) || | |
978 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
979 | c->max_interfaces)) | |
980 | goto nla_put_failure; | |
cdc89b97 | 981 | if (large && |
8c48b50a FF |
982 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
983 | c->radar_detect_widths) || | |
984 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
985 | c->radar_detect_regions))) | |
cdc89b97 | 986 | goto nla_put_failure; |
7527a782 JB |
987 | |
988 | nla_nest_end(msg, nl_combi); | |
989 | } | |
990 | ||
991 | nla_nest_end(msg, nl_combis); | |
992 | ||
993 | return 0; | |
994 | nla_put_failure: | |
995 | return -ENOBUFS; | |
996 | } | |
997 | ||
3713b4e3 | 998 | #ifdef CONFIG_PM |
b56cf720 JB |
999 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
1000 | struct sk_buff *msg) | |
1001 | { | |
964dc9e2 | 1002 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
1003 | struct nlattr *nl_tcp; |
1004 | ||
1005 | if (!tcp) | |
1006 | return 0; | |
1007 | ||
1008 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
1009 | if (!nl_tcp) | |
1010 | return -ENOBUFS; | |
1011 | ||
1012 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1013 | tcp->data_payload_max)) | |
1014 | return -ENOBUFS; | |
1015 | ||
1016 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1017 | tcp->data_payload_max)) | |
1018 | return -ENOBUFS; | |
1019 | ||
1020 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1021 | return -ENOBUFS; | |
1022 | ||
1023 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1024 | sizeof(*tcp->tok), tcp->tok)) | |
1025 | return -ENOBUFS; | |
1026 | ||
1027 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1028 | tcp->data_interval_max)) | |
1029 | return -ENOBUFS; | |
1030 | ||
1031 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1032 | tcp->wake_payload_max)) | |
1033 | return -ENOBUFS; | |
1034 | ||
1035 | nla_nest_end(msg, nl_tcp); | |
1036 | return 0; | |
1037 | } | |
1038 | ||
3713b4e3 | 1039 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1040 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1041 | bool large) |
55682965 | 1042 | { |
3713b4e3 | 1043 | struct nlattr *nl_wowlan; |
55682965 | 1044 | |
1b8ec87a | 1045 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1046 | return 0; |
55682965 | 1047 | |
3713b4e3 JB |
1048 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1049 | if (!nl_wowlan) | |
1050 | return -ENOBUFS; | |
9360ffd1 | 1051 | |
1b8ec87a | 1052 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1053 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1054 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1055 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1056 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1057 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1058 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1059 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1060 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1061 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1062 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1063 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1064 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1065 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1066 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1067 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1068 | return -ENOBUFS; | |
9360ffd1 | 1069 | |
1b8ec87a | 1070 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1071 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1072 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1073 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1074 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1075 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1076 | }; |
9360ffd1 | 1077 | |
3713b4e3 JB |
1078 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1079 | sizeof(pat), &pat)) | |
1080 | return -ENOBUFS; | |
1081 | } | |
9360ffd1 | 1082 | |
1b8ec87a | 1083 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1084 | return -ENOBUFS; |
1085 | ||
3713b4e3 | 1086 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1087 | |
3713b4e3 JB |
1088 | return 0; |
1089 | } | |
1090 | #endif | |
9360ffd1 | 1091 | |
be29b99a | 1092 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1093 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1094 | { |
1095 | struct nl80211_coalesce_rule_support rule; | |
1096 | ||
1b8ec87a | 1097 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1098 | return 0; |
1099 | ||
1b8ec87a ZG |
1100 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1101 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1102 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1103 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1104 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1105 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1106 | |
1107 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1108 | return -ENOBUFS; | |
1109 | ||
1110 | return 0; | |
1111 | } | |
1112 | ||
3713b4e3 JB |
1113 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1114 | struct ieee80211_supported_band *sband) | |
1115 | { | |
1116 | struct nlattr *nl_rates, *nl_rate; | |
1117 | struct ieee80211_rate *rate; | |
1118 | int i; | |
87bbbe22 | 1119 | |
3713b4e3 JB |
1120 | /* add HT info */ |
1121 | if (sband->ht_cap.ht_supported && | |
1122 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1123 | sizeof(sband->ht_cap.mcs), | |
1124 | &sband->ht_cap.mcs) || | |
1125 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1126 | sband->ht_cap.cap) || | |
1127 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1128 | sband->ht_cap.ampdu_factor) || | |
1129 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1130 | sband->ht_cap.ampdu_density))) | |
1131 | return -ENOBUFS; | |
afe0cbf8 | 1132 | |
3713b4e3 JB |
1133 | /* add VHT info */ |
1134 | if (sband->vht_cap.vht_supported && | |
1135 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1136 | sizeof(sband->vht_cap.vht_mcs), | |
1137 | &sband->vht_cap.vht_mcs) || | |
1138 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1139 | sband->vht_cap.cap))) | |
1140 | return -ENOBUFS; | |
f59ac048 | 1141 | |
3713b4e3 JB |
1142 | /* add bitrates */ |
1143 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1144 | if (!nl_rates) | |
1145 | return -ENOBUFS; | |
ee688b00 | 1146 | |
3713b4e3 JB |
1147 | for (i = 0; i < sband->n_bitrates; i++) { |
1148 | nl_rate = nla_nest_start(msg, i); | |
1149 | if (!nl_rate) | |
1150 | return -ENOBUFS; | |
ee688b00 | 1151 | |
3713b4e3 JB |
1152 | rate = &sband->bitrates[i]; |
1153 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1154 | rate->bitrate)) | |
1155 | return -ENOBUFS; | |
1156 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1157 | nla_put_flag(msg, | |
1158 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1159 | return -ENOBUFS; | |
ee688b00 | 1160 | |
3713b4e3 JB |
1161 | nla_nest_end(msg, nl_rate); |
1162 | } | |
d51626df | 1163 | |
3713b4e3 | 1164 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1165 | |
3713b4e3 JB |
1166 | return 0; |
1167 | } | |
ee688b00 | 1168 | |
3713b4e3 JB |
1169 | static int |
1170 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1171 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1172 | { | |
1173 | u16 stypes; | |
1174 | struct nlattr *nl_ftypes, *nl_ifs; | |
1175 | enum nl80211_iftype ift; | |
1176 | int i; | |
ee688b00 | 1177 | |
3713b4e3 JB |
1178 | if (!mgmt_stypes) |
1179 | return 0; | |
5dab3b8a | 1180 | |
3713b4e3 JB |
1181 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1182 | if (!nl_ifs) | |
1183 | return -ENOBUFS; | |
e2f367f2 | 1184 | |
3713b4e3 JB |
1185 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1186 | nl_ftypes = nla_nest_start(msg, ift); | |
1187 | if (!nl_ftypes) | |
1188 | return -ENOBUFS; | |
1189 | i = 0; | |
1190 | stypes = mgmt_stypes[ift].tx; | |
1191 | while (stypes) { | |
1192 | if ((stypes & 1) && | |
1193 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1194 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1195 | return -ENOBUFS; | |
1196 | stypes >>= 1; | |
1197 | i++; | |
ee688b00 | 1198 | } |
3713b4e3 JB |
1199 | nla_nest_end(msg, nl_ftypes); |
1200 | } | |
ee688b00 | 1201 | |
3713b4e3 | 1202 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1203 | |
3713b4e3 JB |
1204 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1205 | if (!nl_ifs) | |
1206 | return -ENOBUFS; | |
ee688b00 | 1207 | |
3713b4e3 JB |
1208 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1209 | nl_ftypes = nla_nest_start(msg, ift); | |
1210 | if (!nl_ftypes) | |
1211 | return -ENOBUFS; | |
1212 | i = 0; | |
1213 | stypes = mgmt_stypes[ift].rx; | |
1214 | while (stypes) { | |
1215 | if ((stypes & 1) && | |
1216 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1217 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1218 | return -ENOBUFS; | |
1219 | stypes >>= 1; | |
1220 | i++; | |
1221 | } | |
1222 | nla_nest_end(msg, nl_ftypes); | |
1223 | } | |
1224 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1225 | |
3713b4e3 JB |
1226 | return 0; |
1227 | } | |
ee688b00 | 1228 | |
86e8cf98 JB |
1229 | struct nl80211_dump_wiphy_state { |
1230 | s64 filter_wiphy; | |
1231 | long start; | |
1232 | long split_start, band_start, chan_start; | |
1233 | bool split; | |
1234 | }; | |
1235 | ||
1b8ec87a | 1236 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 1237 | enum nl80211_commands cmd, |
3713b4e3 | 1238 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1239 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1240 | { |
1241 | void *hdr; | |
1242 | struct nlattr *nl_bands, *nl_band; | |
1243 | struct nlattr *nl_freqs, *nl_freq; | |
1244 | struct nlattr *nl_cmds; | |
1245 | enum ieee80211_band band; | |
1246 | struct ieee80211_channel *chan; | |
1247 | int i; | |
1248 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1249 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1250 | u32 features; |
ee688b00 | 1251 | |
3bb20556 | 1252 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
1253 | if (!hdr) |
1254 | return -ENOBUFS; | |
ee688b00 | 1255 | |
86e8cf98 JB |
1256 | if (WARN_ON(!state)) |
1257 | return -EINVAL; | |
ee688b00 | 1258 | |
1b8ec87a | 1259 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1260 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1261 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1262 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1263 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1264 | goto nla_put_failure; |
1265 | ||
3bb20556 JB |
1266 | if (cmd != NL80211_CMD_NEW_WIPHY) |
1267 | goto finish; | |
1268 | ||
86e8cf98 | 1269 | switch (state->split_start) { |
3713b4e3 JB |
1270 | case 0: |
1271 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1272 | rdev->wiphy.retry_short) || |
3713b4e3 | 1273 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1274 | rdev->wiphy.retry_long) || |
3713b4e3 | 1275 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1276 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1277 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1278 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1279 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1280 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1281 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1282 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1283 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1284 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1285 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1286 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1287 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1288 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1289 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
1b8ec87a | 1290 | rdev->wiphy.max_match_sets)) |
9360ffd1 | 1291 | goto nla_put_failure; |
3713b4e3 | 1292 | |
1b8ec87a | 1293 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1294 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1295 | goto nla_put_failure; |
1b8ec87a | 1296 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1297 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1298 | goto nla_put_failure; | |
1b8ec87a | 1299 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1300 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1301 | goto nla_put_failure; | |
1b8ec87a | 1302 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1303 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1304 | goto nla_put_failure; | |
1b8ec87a | 1305 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1306 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1307 | goto nla_put_failure; | |
1b8ec87a | 1308 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1309 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1310 | goto nla_put_failure; |
86e8cf98 JB |
1311 | state->split_start++; |
1312 | if (state->split) | |
3713b4e3 JB |
1313 | break; |
1314 | case 1: | |
1315 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1316 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1317 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1318 | goto nla_put_failure; |
4745fc09 | 1319 | |
3713b4e3 | 1320 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1321 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1322 | goto nla_put_failure; |
b23aa676 | 1323 | |
1b8ec87a | 1324 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1325 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1326 | goto nla_put_failure; |
b23aa676 | 1327 | |
3713b4e3 | 1328 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1329 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1330 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1331 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1332 | goto nla_put_failure; |
b23aa676 | 1333 | |
1b8ec87a | 1334 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1335 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1336 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1337 | goto nla_put_failure; |
8fdc621d | 1338 | |
1b8ec87a ZG |
1339 | if ((rdev->wiphy.available_antennas_tx || |
1340 | rdev->wiphy.available_antennas_rx) && | |
1341 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1342 | u32 tx_ant = 0, rx_ant = 0; |
1343 | int res; | |
1b8ec87a | 1344 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1345 | if (!res) { |
1346 | if (nla_put_u32(msg, | |
1347 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1348 | tx_ant) || | |
1349 | nla_put_u32(msg, | |
1350 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1351 | rx_ant)) | |
1352 | goto nla_put_failure; | |
1353 | } | |
1354 | } | |
a293911d | 1355 | |
86e8cf98 JB |
1356 | state->split_start++; |
1357 | if (state->split) | |
3713b4e3 JB |
1358 | break; |
1359 | case 2: | |
1360 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1361 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1362 | goto nla_put_failure; |
86e8cf98 JB |
1363 | state->split_start++; |
1364 | if (state->split) | |
3713b4e3 JB |
1365 | break; |
1366 | case 3: | |
1367 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1368 | if (!nl_bands) | |
1369 | goto nla_put_failure; | |
f7ca38df | 1370 | |
86e8cf98 JB |
1371 | for (band = state->band_start; |
1372 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1373 | struct ieee80211_supported_band *sband; |
2e161f78 | 1374 | |
1b8ec87a | 1375 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1376 | |
3713b4e3 JB |
1377 | if (!sband) |
1378 | continue; | |
1379 | ||
1380 | nl_band = nla_nest_start(msg, band); | |
1381 | if (!nl_band) | |
2e161f78 | 1382 | goto nla_put_failure; |
3713b4e3 | 1383 | |
86e8cf98 | 1384 | switch (state->chan_start) { |
3713b4e3 JB |
1385 | case 0: |
1386 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1387 | goto nla_put_failure; |
86e8cf98 JB |
1388 | state->chan_start++; |
1389 | if (state->split) | |
3713b4e3 JB |
1390 | break; |
1391 | default: | |
1392 | /* add frequencies */ | |
1393 | nl_freqs = nla_nest_start( | |
1394 | msg, NL80211_BAND_ATTR_FREQS); | |
1395 | if (!nl_freqs) | |
1396 | goto nla_put_failure; | |
1397 | ||
86e8cf98 | 1398 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1399 | i < sband->n_channels; |
1400 | i++) { | |
1401 | nl_freq = nla_nest_start(msg, i); | |
1402 | if (!nl_freq) | |
1403 | goto nla_put_failure; | |
1404 | ||
1405 | chan = &sband->channels[i]; | |
1406 | ||
86e8cf98 JB |
1407 | if (nl80211_msg_put_channel( |
1408 | msg, chan, | |
1409 | state->split)) | |
3713b4e3 JB |
1410 | goto nla_put_failure; |
1411 | ||
1412 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1413 | if (state->split) |
3713b4e3 JB |
1414 | break; |
1415 | } | |
1416 | if (i < sband->n_channels) | |
86e8cf98 | 1417 | state->chan_start = i + 2; |
3713b4e3 | 1418 | else |
86e8cf98 | 1419 | state->chan_start = 0; |
3713b4e3 JB |
1420 | nla_nest_end(msg, nl_freqs); |
1421 | } | |
1422 | ||
1423 | nla_nest_end(msg, nl_band); | |
1424 | ||
86e8cf98 | 1425 | if (state->split) { |
3713b4e3 | 1426 | /* start again here */ |
86e8cf98 | 1427 | if (state->chan_start) |
3713b4e3 JB |
1428 | band--; |
1429 | break; | |
2e161f78 | 1430 | } |
2e161f78 | 1431 | } |
3713b4e3 | 1432 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1433 | |
3713b4e3 | 1434 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1435 | state->band_start = band + 1; |
3713b4e3 | 1436 | else |
86e8cf98 | 1437 | state->band_start = 0; |
74b70a4e | 1438 | |
3713b4e3 | 1439 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1440 | if (state->band_start == 0 && state->chan_start == 0) |
1441 | state->split_start++; | |
1442 | if (state->split) | |
3713b4e3 JB |
1443 | break; |
1444 | case 4: | |
1445 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1446 | if (!nl_cmds) | |
2e161f78 JB |
1447 | goto nla_put_failure; |
1448 | ||
3713b4e3 JB |
1449 | i = 0; |
1450 | #define CMD(op, n) \ | |
1451 | do { \ | |
1b8ec87a | 1452 | if (rdev->ops->op) { \ |
3713b4e3 JB |
1453 | i++; \ |
1454 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1455 | goto nla_put_failure; \ | |
1456 | } \ | |
1457 | } while (0) | |
1458 | ||
1459 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1460 | CMD(change_virtual_intf, SET_INTERFACE); | |
1461 | CMD(add_key, NEW_KEY); | |
1462 | CMD(start_ap, START_AP); | |
1463 | CMD(add_station, NEW_STATION); | |
1464 | CMD(add_mpath, NEW_MPATH); | |
1465 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1466 | CMD(change_bss, SET_BSS); | |
1467 | CMD(auth, AUTHENTICATE); | |
1468 | CMD(assoc, ASSOCIATE); | |
1469 | CMD(deauth, DEAUTHENTICATE); | |
1470 | CMD(disassoc, DISASSOCIATE); | |
1471 | CMD(join_ibss, JOIN_IBSS); | |
1472 | CMD(join_mesh, JOIN_MESH); | |
1473 | CMD(set_pmksa, SET_PMKSA); | |
1474 | CMD(del_pmksa, DEL_PMKSA); | |
1475 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1b8ec87a | 1476 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
3713b4e3 JB |
1477 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
1478 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1479 | CMD(mgmt_tx, FRAME); | |
1480 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1b8ec87a | 1481 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
3713b4e3 JB |
1482 | i++; |
1483 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1484 | goto nla_put_failure; |
2e161f78 | 1485 | } |
1b8ec87a ZG |
1486 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
1487 | rdev->ops->join_mesh) { | |
3713b4e3 JB |
1488 | i++; |
1489 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1490 | goto nla_put_failure; | |
1491 | } | |
1492 | CMD(set_wds_peer, SET_WDS_PEER); | |
1b8ec87a | 1493 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
3713b4e3 JB |
1494 | CMD(tdls_mgmt, TDLS_MGMT); |
1495 | CMD(tdls_oper, TDLS_OPER); | |
1496 | } | |
1b8ec87a | 1497 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
3713b4e3 JB |
1498 | CMD(sched_scan_start, START_SCHED_SCAN); |
1499 | CMD(probe_client, PROBE_CLIENT); | |
1500 | CMD(set_noack_map, SET_NOACK_MAP); | |
1b8ec87a | 1501 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
3713b4e3 JB |
1502 | i++; |
1503 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1504 | goto nla_put_failure; | |
1505 | } | |
1506 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1507 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
02df00eb JB |
1508 | #ifdef CONFIG_NL80211_TESTMODE |
1509 | CMD(testmode_cmd, TESTMODE); | |
1510 | #endif | |
86e8cf98 | 1511 | if (state->split) { |
5de17984 AS |
1512 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1513 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 1514 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 1515 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 1516 | CMD(set_qos_map, SET_QOS_MAP); |
723e73ac JB |
1517 | if (rdev->wiphy.features & |
1518 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | |
960d01ac | 1519 | CMD(add_tx_ts, ADD_TX_TS); |
5de17984 | 1520 | } |
02df00eb | 1521 | /* add into the if now */ |
3713b4e3 | 1522 | #undef CMD |
ff1b6e69 | 1523 | |
1b8ec87a | 1524 | if (rdev->ops->connect || rdev->ops->auth) { |
3713b4e3 JB |
1525 | i++; |
1526 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1527 | goto nla_put_failure; |
ff1b6e69 JB |
1528 | } |
1529 | ||
1b8ec87a | 1530 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
3713b4e3 JB |
1531 | i++; |
1532 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1533 | goto nla_put_failure; | |
1534 | } | |
1535 | ||
1536 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1537 | state->split_start++; |
1538 | if (state->split) | |
3713b4e3 JB |
1539 | break; |
1540 | case 5: | |
1b8ec87a ZG |
1541 | if (rdev->ops->remain_on_channel && |
1542 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
1543 | nla_put_u32(msg, |
1544 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 1545 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
1546 | goto nla_put_failure; |
1547 | ||
1b8ec87a | 1548 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
1549 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
1550 | goto nla_put_failure; | |
1551 | ||
1552 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1553 | goto nla_put_failure; | |
86e8cf98 JB |
1554 | state->split_start++; |
1555 | if (state->split) | |
3713b4e3 JB |
1556 | break; |
1557 | case 6: | |
1558 | #ifdef CONFIG_PM | |
1b8ec87a | 1559 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 1560 | goto nla_put_failure; |
86e8cf98 JB |
1561 | state->split_start++; |
1562 | if (state->split) | |
3713b4e3 JB |
1563 | break; |
1564 | #else | |
86e8cf98 | 1565 | state->split_start++; |
dfb89c56 | 1566 | #endif |
3713b4e3 JB |
1567 | case 7: |
1568 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 1569 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 1570 | goto nla_put_failure; |
ff1b6e69 | 1571 | |
1b8ec87a | 1572 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 1573 | state->split)) |
3713b4e3 | 1574 | goto nla_put_failure; |
7527a782 | 1575 | |
86e8cf98 JB |
1576 | state->split_start++; |
1577 | if (state->split) | |
3713b4e3 JB |
1578 | break; |
1579 | case 8: | |
1b8ec87a | 1580 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 1581 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 1582 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 1583 | goto nla_put_failure; |
7527a782 | 1584 | |
1b8ec87a | 1585 | features = rdev->wiphy.features; |
fe1abafd JB |
1586 | /* |
1587 | * We can only add the per-channel limit information if the | |
1588 | * dump is split, otherwise it makes it too big. Therefore | |
1589 | * only advertise it in that case. | |
1590 | */ | |
86e8cf98 | 1591 | if (state->split) |
fe1abafd JB |
1592 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1593 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1594 | goto nla_put_failure; |
562a7480 | 1595 | |
1b8ec87a | 1596 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 1597 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
1598 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
1599 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 1600 | goto nla_put_failure; |
1f074bd8 | 1601 | |
1b8ec87a ZG |
1602 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1603 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 1604 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 1605 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 1606 | goto nla_put_failure; |
7e7c8926 | 1607 | |
3713b4e3 JB |
1608 | /* |
1609 | * Any information below this point is only available to | |
1610 | * applications that can deal with it being split. This | |
1611 | * helps ensure that newly added capabilities don't break | |
1612 | * older tools by overrunning their buffers. | |
1613 | * | |
1614 | * We still increment split_start so that in the split | |
1615 | * case we'll continue with more data in the next round, | |
1616 | * but break unconditionally so unsplit data stops here. | |
1617 | */ | |
86e8cf98 | 1618 | state->split_start++; |
3713b4e3 JB |
1619 | break; |
1620 | case 9: | |
1b8ec87a | 1621 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 1622 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
1623 | rdev->wiphy.extended_capabilities_len, |
1624 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 1625 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
1626 | rdev->wiphy.extended_capabilities_len, |
1627 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 1628 | goto nla_put_failure; |
a50df0c4 | 1629 | |
1b8ec87a | 1630 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 1631 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
1632 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
1633 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
1634 | goto nla_put_failure; |
1635 | ||
be29b99a AK |
1636 | state->split_start++; |
1637 | break; | |
1638 | case 10: | |
1b8ec87a | 1639 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
1640 | goto nla_put_failure; |
1641 | ||
1b8ec87a | 1642 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
1643 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
1644 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1645 | goto nla_put_failure; | |
b43504cf | 1646 | |
1b8ec87a | 1647 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 1648 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 1649 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
1650 | goto nla_put_failure; |
1651 | ||
ad7e718c JB |
1652 | state->split_start++; |
1653 | break; | |
1654 | case 11: | |
1b8ec87a | 1655 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
1656 | const struct nl80211_vendor_cmd_info *info; |
1657 | struct nlattr *nested; | |
1658 | ||
1659 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1660 | if (!nested) | |
1661 | goto nla_put_failure; | |
1662 | ||
1b8ec87a ZG |
1663 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
1664 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
1665 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1666 | goto nla_put_failure; | |
1667 | } | |
1668 | nla_nest_end(msg, nested); | |
1669 | } | |
1670 | ||
1b8ec87a | 1671 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
1672 | const struct nl80211_vendor_cmd_info *info; |
1673 | struct nlattr *nested; | |
ad7e718c | 1674 | |
567ffc35 JB |
1675 | nested = nla_nest_start(msg, |
1676 | NL80211_ATTR_VENDOR_EVENTS); | |
1677 | if (!nested) | |
ad7e718c | 1678 | goto nla_put_failure; |
567ffc35 | 1679 | |
1b8ec87a ZG |
1680 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
1681 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
1682 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1683 | goto nla_put_failure; | |
1684 | } | |
1685 | nla_nest_end(msg, nested); | |
1686 | } | |
9a774c78 AO |
1687 | state->split_start++; |
1688 | break; | |
1689 | case 12: | |
1690 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
1691 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
1692 | rdev->wiphy.max_num_csa_counters)) | |
1693 | goto nla_put_failure; | |
01e0daa4 | 1694 | |
3713b4e3 | 1695 | /* done */ |
86e8cf98 | 1696 | state->split_start = 0; |
3713b4e3 JB |
1697 | break; |
1698 | } | |
3bb20556 | 1699 | finish: |
55682965 JB |
1700 | return genlmsg_end(msg, hdr); |
1701 | ||
1702 | nla_put_failure: | |
bc3ed28c TG |
1703 | genlmsg_cancel(msg, hdr); |
1704 | return -EMSGSIZE; | |
55682965 JB |
1705 | } |
1706 | ||
86e8cf98 JB |
1707 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1708 | struct netlink_callback *cb, | |
1709 | struct nl80211_dump_wiphy_state *state) | |
1710 | { | |
1711 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1712 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1713 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1714 | /* ignore parse errors for backward compatibility */ | |
1715 | if (ret) | |
1716 | return 0; | |
1717 | ||
1718 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1719 | if (tb[NL80211_ATTR_WIPHY]) | |
1720 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1721 | if (tb[NL80211_ATTR_WDEV]) | |
1722 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1723 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1724 | struct net_device *netdev; | |
1725 | struct cfg80211_registered_device *rdev; | |
1726 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1727 | ||
7f2b8562 | 1728 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1729 | if (!netdev) |
1730 | return -ENODEV; | |
1731 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1732 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1733 | netdev->ieee80211_ptr->wiphy); |
1734 | state->filter_wiphy = rdev->wiphy_idx; | |
1735 | } | |
86e8cf98 JB |
1736 | } |
1737 | ||
1738 | return 0; | |
1739 | } | |
1740 | ||
55682965 JB |
1741 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1742 | { | |
645e77de | 1743 | int idx = 0, ret; |
86e8cf98 | 1744 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1745 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1746 | |
5fe231e8 | 1747 | rtnl_lock(); |
86e8cf98 JB |
1748 | if (!state) { |
1749 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1750 | if (!state) { |
1751 | rtnl_unlock(); | |
86e8cf98 | 1752 | return -ENOMEM; |
3713b4e3 | 1753 | } |
86e8cf98 JB |
1754 | state->filter_wiphy = -1; |
1755 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1756 | if (ret) { | |
1757 | kfree(state); | |
1758 | rtnl_unlock(); | |
1759 | return ret; | |
3713b4e3 | 1760 | } |
86e8cf98 | 1761 | cb->args[0] = (long)state; |
3713b4e3 JB |
1762 | } |
1763 | ||
1b8ec87a ZG |
1764 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1765 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1766 | continue; |
86e8cf98 | 1767 | if (++idx <= state->start) |
55682965 | 1768 | continue; |
86e8cf98 | 1769 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1770 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1771 | continue; |
1772 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1773 | do { | |
3bb20556 JB |
1774 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
1775 | skb, | |
3713b4e3 JB |
1776 | NETLINK_CB(cb->skb).portid, |
1777 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1778 | NLM_F_MULTI, state); |
3713b4e3 JB |
1779 | if (ret < 0) { |
1780 | /* | |
1781 | * If sending the wiphy data didn't fit (ENOBUFS | |
1782 | * or EMSGSIZE returned), this SKB is still | |
1783 | * empty (so it's not too big because another | |
1784 | * wiphy dataset is already in the skb) and | |
1785 | * we've not tried to adjust the dump allocation | |
1786 | * yet ... then adjust the alloc size to be | |
1787 | * bigger, and return 1 but with the empty skb. | |
1788 | * This results in an empty message being RX'ed | |
1789 | * in userspace, but that is ignored. | |
1790 | * | |
1791 | * We can then retry with the larger buffer. | |
1792 | */ | |
1793 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1794 | !skb->len && !state->split && |
3713b4e3 JB |
1795 | cb->min_dump_alloc < 4096) { |
1796 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1797 | state->split_start = 0; |
d98cae64 | 1798 | rtnl_unlock(); |
3713b4e3 JB |
1799 | return 1; |
1800 | } | |
1801 | idx--; | |
1802 | break; | |
645e77de | 1803 | } |
86e8cf98 | 1804 | } while (state->split_start > 0); |
3713b4e3 | 1805 | break; |
55682965 | 1806 | } |
5fe231e8 | 1807 | rtnl_unlock(); |
55682965 | 1808 | |
86e8cf98 | 1809 | state->start = idx; |
55682965 JB |
1810 | |
1811 | return skb->len; | |
1812 | } | |
1813 | ||
86e8cf98 JB |
1814 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1815 | { | |
1816 | kfree((void *)cb->args[0]); | |
1817 | return 0; | |
1818 | } | |
1819 | ||
55682965 JB |
1820 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1821 | { | |
1822 | struct sk_buff *msg; | |
1b8ec87a | 1823 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 1824 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1825 | |
645e77de | 1826 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1827 | if (!msg) |
4c476991 | 1828 | return -ENOMEM; |
55682965 | 1829 | |
3bb20556 JB |
1830 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
1831 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 1832 | &state) < 0) { |
4c476991 JB |
1833 | nlmsg_free(msg); |
1834 | return -ENOBUFS; | |
1835 | } | |
55682965 | 1836 | |
134e6375 | 1837 | return genlmsg_reply(msg, info); |
55682965 JB |
1838 | } |
1839 | ||
31888487 JM |
1840 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1841 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1842 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1843 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1844 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1845 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1846 | }; | |
1847 | ||
1848 | static int parse_txq_params(struct nlattr *tb[], | |
1849 | struct ieee80211_txq_params *txq_params) | |
1850 | { | |
a3304b0a | 1851 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1852 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1853 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1854 | return -EINVAL; | |
1855 | ||
a3304b0a | 1856 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1857 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1858 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1859 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1860 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1861 | ||
a3304b0a JB |
1862 | if (txq_params->ac >= NL80211_NUM_ACS) |
1863 | return -EINVAL; | |
1864 | ||
31888487 JM |
1865 | return 0; |
1866 | } | |
1867 | ||
f444de05 JB |
1868 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1869 | { | |
1870 | /* | |
cc1d2806 JB |
1871 | * You can only set the channel explicitly for WDS interfaces, |
1872 | * all others have their channel managed via their respective | |
1873 | * "establish a connection" command (connect, join, ...) | |
1874 | * | |
1875 | * For AP/GO and mesh mode, the channel can be set with the | |
1876 | * channel userspace API, but is only stored and passed to the | |
1877 | * low-level driver when the AP starts or the mesh is joined. | |
1878 | * This is for backward compatibility, userspace can also give | |
1879 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1880 | * |
1881 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1882 | * whatever else is going on, so they have their own special |
1883 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1884 | */ |
1885 | return !wdev || | |
1886 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1887 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1888 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1889 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1890 | } |
1891 | ||
683b6d3b JB |
1892 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1893 | struct genl_info *info, | |
1894 | struct cfg80211_chan_def *chandef) | |
1895 | { | |
dbeca2ea | 1896 | u32 control_freq; |
683b6d3b JB |
1897 | |
1898 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1899 | return -EINVAL; | |
1900 | ||
1901 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1902 | ||
1903 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1904 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1905 | chandef->center_freq1 = control_freq; | |
1906 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1907 | |
1908 | /* Primary channel not allowed */ | |
1909 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1910 | return -EINVAL; | |
1911 | ||
3d9d1d66 JB |
1912 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1913 | enum nl80211_channel_type chantype; | |
1914 | ||
1915 | chantype = nla_get_u32( | |
1916 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1917 | ||
1918 | switch (chantype) { | |
1919 | case NL80211_CHAN_NO_HT: | |
1920 | case NL80211_CHAN_HT20: | |
1921 | case NL80211_CHAN_HT40PLUS: | |
1922 | case NL80211_CHAN_HT40MINUS: | |
1923 | cfg80211_chandef_create(chandef, chandef->chan, | |
1924 | chantype); | |
1925 | break; | |
1926 | default: | |
1927 | return -EINVAL; | |
1928 | } | |
1929 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1930 | chandef->width = | |
1931 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1932 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1933 | chandef->center_freq1 = | |
1934 | nla_get_u32( | |
1935 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1936 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1937 | chandef->center_freq2 = | |
1938 | nla_get_u32( | |
1939 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1940 | } | |
1941 | ||
9f5e8f6e | 1942 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1943 | return -EINVAL; |
1944 | ||
9f5e8f6e JB |
1945 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1946 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1947 | return -EINVAL; |
1948 | ||
2f301ab2 SW |
1949 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1950 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1951 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1952 | return -EINVAL; | |
1953 | ||
683b6d3b JB |
1954 | return 0; |
1955 | } | |
1956 | ||
f444de05 | 1957 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 1958 | struct net_device *dev, |
f444de05 JB |
1959 | struct genl_info *info) |
1960 | { | |
683b6d3b | 1961 | struct cfg80211_chan_def chandef; |
f444de05 | 1962 | int result; |
e8c9bd5b | 1963 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 1964 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 1965 | |
e16821bc JM |
1966 | if (dev) |
1967 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
1968 | if (!nl80211_can_set_dev_channel(wdev)) |
1969 | return -EOPNOTSUPP; | |
e16821bc JM |
1970 | if (wdev) |
1971 | iftype = wdev->iftype; | |
f444de05 | 1972 | |
683b6d3b JB |
1973 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1974 | if (result) | |
1975 | return result; | |
f444de05 | 1976 | |
e8c9bd5b | 1977 | switch (iftype) { |
aa430da4 JB |
1978 | case NL80211_IFTYPE_AP: |
1979 | case NL80211_IFTYPE_P2P_GO: | |
174e0cd2 | 1980 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
aa430da4 JB |
1981 | result = -EINVAL; |
1982 | break; | |
1983 | } | |
e16821bc JM |
1984 | if (wdev->beacon_interval) { |
1985 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
1986 | !(rdev->wiphy.features & | |
1987 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
1988 | result = -EBUSY; | |
1989 | break; | |
1990 | } | |
1991 | ||
1992 | /* Only allow dynamic channel width changes */ | |
1993 | if (chandef.chan != wdev->preset_chandef.chan) { | |
1994 | result = -EBUSY; | |
1995 | break; | |
1996 | } | |
1997 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
1998 | if (result) | |
1999 | break; | |
2000 | } | |
683b6d3b | 2001 | wdev->preset_chandef = chandef; |
aa430da4 JB |
2002 | result = 0; |
2003 | break; | |
cc1d2806 | 2004 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 2005 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 2006 | break; |
e8c9bd5b | 2007 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 2008 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 2009 | break; |
aa430da4 | 2010 | default: |
e8c9bd5b | 2011 | result = -EINVAL; |
f444de05 | 2012 | } |
f444de05 JB |
2013 | |
2014 | return result; | |
2015 | } | |
2016 | ||
2017 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2018 | { | |
4c476991 JB |
2019 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2020 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2021 | |
e16821bc | 2022 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2023 | } |
2024 | ||
e8347eba BJ |
2025 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2026 | { | |
43b19952 JB |
2027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2028 | struct net_device *dev = info->user_ptr[1]; | |
2029 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2030 | const u8 *bssid; |
e8347eba BJ |
2031 | |
2032 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2033 | return -EINVAL; | |
2034 | ||
43b19952 JB |
2035 | if (netif_running(dev)) |
2036 | return -EBUSY; | |
e8347eba | 2037 | |
43b19952 JB |
2038 | if (!rdev->ops->set_wds_peer) |
2039 | return -EOPNOTSUPP; | |
e8347eba | 2040 | |
43b19952 JB |
2041 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2042 | return -EOPNOTSUPP; | |
e8347eba BJ |
2043 | |
2044 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2045 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2046 | } |
2047 | ||
2048 | ||
55682965 JB |
2049 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2050 | { | |
2051 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2052 | struct net_device *netdev = NULL; |
2053 | struct wireless_dev *wdev; | |
a1e567c8 | 2054 | int result = 0, rem_txq_params = 0; |
31888487 | 2055 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2056 | u32 changed; |
2057 | u8 retry_short = 0, retry_long = 0; | |
2058 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2059 | u8 coverage_class = 0; |
55682965 | 2060 | |
5fe231e8 JB |
2061 | ASSERT_RTNL(); |
2062 | ||
f444de05 JB |
2063 | /* |
2064 | * Try to find the wiphy and netdev. Normally this | |
2065 | * function shouldn't need the netdev, but this is | |
2066 | * done for backward compatibility -- previously | |
2067 | * setting the channel was done per wiphy, but now | |
2068 | * it is per netdev. Previous userland like hostapd | |
2069 | * also passed a netdev to set_wiphy, so that it is | |
2070 | * possible to let that go to the right netdev! | |
2071 | */ | |
4bbf4d56 | 2072 | |
f444de05 JB |
2073 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2074 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2075 | ||
7f2b8562 | 2076 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2077 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2078 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2079 | else |
f444de05 | 2080 | netdev = NULL; |
4bbf4d56 JB |
2081 | } |
2082 | ||
f444de05 | 2083 | if (!netdev) { |
878d9ec7 JB |
2084 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2085 | info->attrs); | |
5fe231e8 | 2086 | if (IS_ERR(rdev)) |
4c476991 | 2087 | return PTR_ERR(rdev); |
f444de05 JB |
2088 | wdev = NULL; |
2089 | netdev = NULL; | |
2090 | result = 0; | |
71fe96bf | 2091 | } else |
f444de05 | 2092 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2093 | |
2094 | /* | |
2095 | * end workaround code, by now the rdev is available | |
2096 | * and locked, and wdev may or may not be NULL. | |
2097 | */ | |
4bbf4d56 JB |
2098 | |
2099 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2100 | result = cfg80211_dev_rename( |
2101 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2102 | |
4bbf4d56 | 2103 | if (result) |
7f2b8562 | 2104 | return result; |
31888487 JM |
2105 | |
2106 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2107 | struct ieee80211_txq_params txq_params; | |
2108 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2109 | ||
7f2b8562 YX |
2110 | if (!rdev->ops->set_txq_params) |
2111 | return -EOPNOTSUPP; | |
31888487 | 2112 | |
7f2b8562 YX |
2113 | if (!netdev) |
2114 | return -EINVAL; | |
f70f01c2 | 2115 | |
133a3ff2 | 2116 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2117 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2118 | return -EINVAL; | |
133a3ff2 | 2119 | |
7f2b8562 YX |
2120 | if (!netif_running(netdev)) |
2121 | return -ENETDOWN; | |
2b5f8b0b | 2122 | |
31888487 JM |
2123 | nla_for_each_nested(nl_txq_params, |
2124 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2125 | rem_txq_params) { | |
ae811e21 JB |
2126 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2127 | nla_data(nl_txq_params), | |
2128 | nla_len(nl_txq_params), | |
2129 | txq_params_policy); | |
2130 | if (result) | |
2131 | return result; | |
31888487 JM |
2132 | result = parse_txq_params(tb, &txq_params); |
2133 | if (result) | |
7f2b8562 | 2134 | return result; |
31888487 | 2135 | |
e35e4d28 HG |
2136 | result = rdev_set_txq_params(rdev, netdev, |
2137 | &txq_params); | |
31888487 | 2138 | if (result) |
7f2b8562 | 2139 | return result; |
31888487 JM |
2140 | } |
2141 | } | |
55682965 | 2142 | |
72bdcf34 | 2143 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2144 | result = __nl80211_set_channel( |
2145 | rdev, | |
2146 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2147 | info); | |
72bdcf34 | 2148 | if (result) |
7f2b8562 | 2149 | return result; |
72bdcf34 JM |
2150 | } |
2151 | ||
98d2ff8b | 2152 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2153 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2154 | enum nl80211_tx_power_setting type; |
2155 | int idx, mbm = 0; | |
2156 | ||
c8442118 JB |
2157 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2158 | txp_wdev = NULL; | |
2159 | ||
7f2b8562 YX |
2160 | if (!rdev->ops->set_tx_power) |
2161 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2162 | |
2163 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2164 | type = nla_get_u32(info->attrs[idx]); | |
2165 | ||
2166 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2167 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2168 | return -EINVAL; | |
98d2ff8b JO |
2169 | |
2170 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2171 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2172 | mbm = nla_get_u32(info->attrs[idx]); | |
2173 | } | |
2174 | ||
c8442118 | 2175 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2176 | if (result) |
7f2b8562 | 2177 | return result; |
98d2ff8b JO |
2178 | } |
2179 | ||
afe0cbf8 BR |
2180 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2181 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2182 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2183 | if ((!rdev->wiphy.available_antennas_tx && |
2184 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2185 | !rdev->ops->set_antenna) |
2186 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2187 | |
2188 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2189 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2190 | ||
a7ffac95 | 2191 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2192 | * available antenna masks, except for the "all" mask */ |
2193 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2194 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2195 | return -EINVAL; | |
a7ffac95 | 2196 | |
7f531e03 BR |
2197 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2198 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2199 | |
e35e4d28 | 2200 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2201 | if (result) |
7f2b8562 | 2202 | return result; |
afe0cbf8 BR |
2203 | } |
2204 | ||
b9a5f8ca JM |
2205 | changed = 0; |
2206 | ||
2207 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2208 | retry_short = nla_get_u8( | |
2209 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2210 | if (retry_short == 0) |
2211 | return -EINVAL; | |
2212 | ||
b9a5f8ca JM |
2213 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2214 | } | |
2215 | ||
2216 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2217 | retry_long = nla_get_u8( | |
2218 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2219 | if (retry_long == 0) |
2220 | return -EINVAL; | |
2221 | ||
b9a5f8ca JM |
2222 | changed |= WIPHY_PARAM_RETRY_LONG; |
2223 | } | |
2224 | ||
2225 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2226 | frag_threshold = nla_get_u32( | |
2227 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2228 | if (frag_threshold < 256) |
2229 | return -EINVAL; | |
2230 | ||
b9a5f8ca JM |
2231 | if (frag_threshold != (u32) -1) { |
2232 | /* | |
2233 | * Fragments (apart from the last one) are required to | |
2234 | * have even length. Make the fragmentation code | |
2235 | * simpler by stripping LSB should someone try to use | |
2236 | * odd threshold value. | |
2237 | */ | |
2238 | frag_threshold &= ~0x1; | |
2239 | } | |
2240 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2241 | } | |
2242 | ||
2243 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2244 | rts_threshold = nla_get_u32( | |
2245 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2246 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2247 | } | |
2248 | ||
81077e82 | 2249 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
3057dbfd LB |
2250 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
2251 | return -EINVAL; | |
2252 | ||
81077e82 LT |
2253 | coverage_class = nla_get_u8( |
2254 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2255 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2256 | } | |
2257 | ||
3057dbfd LB |
2258 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
2259 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | |
2260 | return -EOPNOTSUPP; | |
2261 | ||
2262 | changed |= WIPHY_PARAM_DYN_ACK; | |
81077e82 LT |
2263 | } |
2264 | ||
b9a5f8ca JM |
2265 | if (changed) { |
2266 | u8 old_retry_short, old_retry_long; | |
2267 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2268 | u8 old_coverage_class; |
b9a5f8ca | 2269 | |
7f2b8562 YX |
2270 | if (!rdev->ops->set_wiphy_params) |
2271 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2272 | |
2273 | old_retry_short = rdev->wiphy.retry_short; | |
2274 | old_retry_long = rdev->wiphy.retry_long; | |
2275 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2276 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2277 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2278 | |
2279 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2280 | rdev->wiphy.retry_short = retry_short; | |
2281 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2282 | rdev->wiphy.retry_long = retry_long; | |
2283 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2284 | rdev->wiphy.frag_threshold = frag_threshold; | |
2285 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2286 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2287 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2288 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2289 | |
e35e4d28 | 2290 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2291 | if (result) { |
2292 | rdev->wiphy.retry_short = old_retry_short; | |
2293 | rdev->wiphy.retry_long = old_retry_long; | |
2294 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2295 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2296 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2297 | } |
2298 | } | |
7f2b8562 | 2299 | return 0; |
55682965 JB |
2300 | } |
2301 | ||
71bbc994 JB |
2302 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2303 | { | |
2304 | return (u64)wdev->identifier | | |
f26cbf40 | 2305 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2306 | } |
55682965 | 2307 | |
683b6d3b | 2308 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2309 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2310 | { |
9f5e8f6e | 2311 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
3d9d1d66 | 2312 | |
683b6d3b JB |
2313 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2314 | chandef->chan->center_freq)) | |
2315 | return -ENOBUFS; | |
3d9d1d66 JB |
2316 | switch (chandef->width) { |
2317 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2318 | case NL80211_CHAN_WIDTH_20: | |
2319 | case NL80211_CHAN_WIDTH_40: | |
2320 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2321 | cfg80211_get_chandef_type(chandef))) | |
2322 | return -ENOBUFS; | |
2323 | break; | |
2324 | default: | |
2325 | break; | |
2326 | } | |
2327 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2328 | return -ENOBUFS; | |
2329 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2330 | return -ENOBUFS; | |
2331 | if (chandef->center_freq2 && | |
2332 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2333 | return -ENOBUFS; |
2334 | return 0; | |
2335 | } | |
2336 | ||
15e47304 | 2337 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2338 | struct cfg80211_registered_device *rdev, |
72fb2abc | 2339 | struct wireless_dev *wdev) |
55682965 | 2340 | { |
72fb2abc | 2341 | struct net_device *dev = wdev->netdev; |
55682965 JB |
2342 | void *hdr; |
2343 | ||
15e47304 | 2344 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
55682965 JB |
2345 | if (!hdr) |
2346 | return -1; | |
2347 | ||
72fb2abc JB |
2348 | if (dev && |
2349 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2350 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2351 | goto nla_put_failure; |
2352 | ||
2353 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2354 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2355 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2356 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2357 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2358 | rdev->devlist_generation ^ | |
2359 | (cfg80211_rdev_list_generation << 2))) | |
2360 | goto nla_put_failure; | |
f5ea9120 | 2361 | |
5b7ccaf3 | 2362 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2363 | int ret; |
2364 | struct cfg80211_chan_def chandef; | |
2365 | ||
2366 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2367 | if (ret == 0) { | |
2368 | if (nl80211_send_chandef(msg, &chandef)) | |
2369 | goto nla_put_failure; | |
2370 | } | |
d91df0e3 PF |
2371 | } |
2372 | ||
b84e7a05 AQ |
2373 | if (wdev->ssid_len) { |
2374 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2375 | goto nla_put_failure; | |
2376 | } | |
2377 | ||
55682965 JB |
2378 | return genlmsg_end(msg, hdr); |
2379 | ||
2380 | nla_put_failure: | |
bc3ed28c TG |
2381 | genlmsg_cancel(msg, hdr); |
2382 | return -EMSGSIZE; | |
55682965 JB |
2383 | } |
2384 | ||
2385 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2386 | { | |
2387 | int wp_idx = 0; | |
2388 | int if_idx = 0; | |
2389 | int wp_start = cb->args[0]; | |
2390 | int if_start = cb->args[1]; | |
f5ea9120 | 2391 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2392 | struct wireless_dev *wdev; |
2393 | ||
5fe231e8 | 2394 | rtnl_lock(); |
f5ea9120 JB |
2395 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2396 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2397 | continue; |
bba95fef JB |
2398 | if (wp_idx < wp_start) { |
2399 | wp_idx++; | |
55682965 | 2400 | continue; |
bba95fef | 2401 | } |
55682965 JB |
2402 | if_idx = 0; |
2403 | ||
89a54e48 | 2404 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2405 | if (if_idx < if_start) { |
2406 | if_idx++; | |
55682965 | 2407 | continue; |
bba95fef | 2408 | } |
15e47304 | 2409 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2410 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
72fb2abc | 2411 | rdev, wdev) < 0) { |
bba95fef JB |
2412 | goto out; |
2413 | } | |
2414 | if_idx++; | |
55682965 | 2415 | } |
bba95fef JB |
2416 | |
2417 | wp_idx++; | |
55682965 | 2418 | } |
bba95fef | 2419 | out: |
5fe231e8 | 2420 | rtnl_unlock(); |
55682965 JB |
2421 | |
2422 | cb->args[0] = wp_idx; | |
2423 | cb->args[1] = if_idx; | |
2424 | ||
2425 | return skb->len; | |
2426 | } | |
2427 | ||
2428 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2429 | { | |
2430 | struct sk_buff *msg; | |
1b8ec87a | 2431 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2432 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2433 | |
fd2120ca | 2434 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2435 | if (!msg) |
4c476991 | 2436 | return -ENOMEM; |
55682965 | 2437 | |
15e47304 | 2438 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1b8ec87a | 2439 | rdev, wdev) < 0) { |
4c476991 JB |
2440 | nlmsg_free(msg); |
2441 | return -ENOBUFS; | |
2442 | } | |
55682965 | 2443 | |
134e6375 | 2444 | return genlmsg_reply(msg, info); |
55682965 JB |
2445 | } |
2446 | ||
66f7ac50 MW |
2447 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2448 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2449 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2450 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2451 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2452 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2453 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2454 | }; |
2455 | ||
2456 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2457 | { | |
2458 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2459 | int flag; | |
2460 | ||
2461 | *mntrflags = 0; | |
2462 | ||
2463 | if (!nla) | |
2464 | return -EINVAL; | |
2465 | ||
2466 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2467 | nla, mntr_flags_policy)) | |
2468 | return -EINVAL; | |
2469 | ||
2470 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2471 | if (flags[flag]) | |
2472 | *mntrflags |= (1<<flag); | |
2473 | ||
2474 | return 0; | |
2475 | } | |
2476 | ||
9bc383de | 2477 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2478 | struct net_device *netdev, u8 use_4addr, |
2479 | enum nl80211_iftype iftype) | |
9bc383de | 2480 | { |
ad4bb6f8 | 2481 | if (!use_4addr) { |
f350a0a8 | 2482 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2483 | return -EBUSY; |
9bc383de | 2484 | return 0; |
ad4bb6f8 | 2485 | } |
9bc383de JB |
2486 | |
2487 | switch (iftype) { | |
2488 | case NL80211_IFTYPE_AP_VLAN: | |
2489 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2490 | return 0; | |
2491 | break; | |
2492 | case NL80211_IFTYPE_STATION: | |
2493 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2494 | return 0; | |
2495 | break; | |
2496 | default: | |
2497 | break; | |
2498 | } | |
2499 | ||
2500 | return -EOPNOTSUPP; | |
2501 | } | |
2502 | ||
55682965 JB |
2503 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2504 | { | |
4c476991 | 2505 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2506 | struct vif_params params; |
e36d56b6 | 2507 | int err; |
04a773ad | 2508 | enum nl80211_iftype otype, ntype; |
4c476991 | 2509 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2510 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2511 | bool change = false; |
55682965 | 2512 | |
2ec600d6 LCC |
2513 | memset(¶ms, 0, sizeof(params)); |
2514 | ||
04a773ad | 2515 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2516 | |
723b038d | 2517 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2518 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2519 | if (otype != ntype) |
ac7f9cfa | 2520 | change = true; |
4c476991 JB |
2521 | if (ntype > NL80211_IFTYPE_MAX) |
2522 | return -EINVAL; | |
723b038d JB |
2523 | } |
2524 | ||
92ffe055 | 2525 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2526 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2527 | ||
4c476991 JB |
2528 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2529 | return -EINVAL; | |
29cbe68c JB |
2530 | if (netif_running(dev)) |
2531 | return -EBUSY; | |
2532 | ||
2533 | wdev_lock(wdev); | |
2534 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2535 | IEEE80211_MAX_MESH_ID_LEN); | |
2536 | wdev->mesh_id_up_len = | |
2537 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2538 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2539 | wdev->mesh_id_up_len); | |
2540 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2541 | } |
2542 | ||
8b787643 FF |
2543 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2544 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2545 | change = true; | |
ad4bb6f8 | 2546 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2547 | if (err) |
4c476991 | 2548 | return err; |
8b787643 FF |
2549 | } else { |
2550 | params.use_4addr = -1; | |
2551 | } | |
2552 | ||
92ffe055 | 2553 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2554 | if (ntype != NL80211_IFTYPE_MONITOR) |
2555 | return -EINVAL; | |
92ffe055 JB |
2556 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2557 | &_flags); | |
ac7f9cfa | 2558 | if (err) |
4c476991 | 2559 | return err; |
ac7f9cfa JB |
2560 | |
2561 | flags = &_flags; | |
2562 | change = true; | |
92ffe055 | 2563 | } |
3b85875a | 2564 | |
18003297 | 2565 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2566 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2567 | return -EOPNOTSUPP; | |
2568 | ||
ac7f9cfa | 2569 | if (change) |
3d54d255 | 2570 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2571 | else |
2572 | err = 0; | |
60719ffd | 2573 | |
9bc383de JB |
2574 | if (!err && params.use_4addr != -1) |
2575 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2576 | ||
55682965 JB |
2577 | return err; |
2578 | } | |
2579 | ||
2580 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2581 | { | |
4c476991 | 2582 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2583 | struct vif_params params; |
84efbb84 | 2584 | struct wireless_dev *wdev; |
1c90f9d4 | 2585 | struct sk_buff *msg; |
55682965 JB |
2586 | int err; |
2587 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2588 | u32 flags; |
55682965 | 2589 | |
78f22b6a JB |
2590 | /* to avoid failing a new interface creation due to pending removal */ |
2591 | cfg80211_destroy_ifaces(rdev); | |
2592 | ||
2ec600d6 LCC |
2593 | memset(¶ms, 0, sizeof(params)); |
2594 | ||
55682965 JB |
2595 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2596 | return -EINVAL; | |
2597 | ||
2598 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2599 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2600 | if (type > NL80211_IFTYPE_MAX) | |
2601 | return -EINVAL; | |
2602 | } | |
2603 | ||
79c97e97 | 2604 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2605 | !(rdev->wiphy.interface_modes & (1 << type))) |
2606 | return -EOPNOTSUPP; | |
55682965 | 2607 | |
e8f479b1 BG |
2608 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
2609 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && | |
2610 | info->attrs[NL80211_ATTR_MAC]) { | |
1c18f145 AS |
2611 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
2612 | ETH_ALEN); | |
2613 | if (!is_valid_ether_addr(params.macaddr)) | |
2614 | return -EADDRNOTAVAIL; | |
2615 | } | |
2616 | ||
9bc383de | 2617 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2618 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2619 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2620 | if (err) |
4c476991 | 2621 | return err; |
9bc383de | 2622 | } |
8b787643 | 2623 | |
1c90f9d4 JB |
2624 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2625 | if (!msg) | |
2626 | return -ENOMEM; | |
2627 | ||
66f7ac50 MW |
2628 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2629 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2630 | &flags); | |
e057d3c3 | 2631 | |
18003297 | 2632 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2633 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2634 | return -EOPNOTSUPP; | |
2635 | ||
e35e4d28 HG |
2636 | wdev = rdev_add_virtual_intf(rdev, |
2637 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2638 | type, err ? NULL : &flags, ¶ms); | |
1c90f9d4 JB |
2639 | if (IS_ERR(wdev)) { |
2640 | nlmsg_free(msg); | |
84efbb84 | 2641 | return PTR_ERR(wdev); |
1c90f9d4 | 2642 | } |
2ec600d6 | 2643 | |
78f22b6a JB |
2644 | if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER]) |
2645 | wdev->owner_nlportid = info->snd_portid; | |
2646 | ||
98104fde JB |
2647 | switch (type) { |
2648 | case NL80211_IFTYPE_MESH_POINT: | |
2649 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2650 | break; | |
29cbe68c JB |
2651 | wdev_lock(wdev); |
2652 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2653 | IEEE80211_MAX_MESH_ID_LEN); | |
2654 | wdev->mesh_id_up_len = | |
2655 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2656 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2657 | wdev->mesh_id_up_len); | |
2658 | wdev_unlock(wdev); | |
98104fde JB |
2659 | break; |
2660 | case NL80211_IFTYPE_P2P_DEVICE: | |
2661 | /* | |
2662 | * P2P Device doesn't have a netdev, so doesn't go | |
2663 | * through the netdev notifier and must be added here | |
2664 | */ | |
2665 | mutex_init(&wdev->mtx); | |
2666 | INIT_LIST_HEAD(&wdev->event_list); | |
2667 | spin_lock_init(&wdev->event_lock); | |
2668 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2669 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2670 | ||
98104fde JB |
2671 | wdev->identifier = ++rdev->wdev_id; |
2672 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2673 | rdev->devlist_generation++; | |
98104fde JB |
2674 | break; |
2675 | default: | |
2676 | break; | |
29cbe68c JB |
2677 | } |
2678 | ||
15e47304 | 2679 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1c90f9d4 JB |
2680 | rdev, wdev) < 0) { |
2681 | nlmsg_free(msg); | |
2682 | return -ENOBUFS; | |
2683 | } | |
2684 | ||
2685 | return genlmsg_reply(msg, info); | |
55682965 JB |
2686 | } |
2687 | ||
2688 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2689 | { | |
4c476991 | 2690 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2691 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2692 | |
4c476991 JB |
2693 | if (!rdev->ops->del_virtual_intf) |
2694 | return -EOPNOTSUPP; | |
55682965 | 2695 | |
84efbb84 JB |
2696 | /* |
2697 | * If we remove a wireless device without a netdev then clear | |
2698 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2699 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2700 | * since the wdev has been freed, unlike with a netdev where | |
2701 | * we need the dev_put() for the netdev to really be freed. | |
2702 | */ | |
2703 | if (!wdev->netdev) | |
2704 | info->user_ptr[1] = NULL; | |
2705 | ||
e35e4d28 | 2706 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2707 | } |
2708 | ||
1d9d9213 SW |
2709 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2710 | { | |
2711 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2712 | struct net_device *dev = info->user_ptr[1]; | |
2713 | u16 noack_map; | |
2714 | ||
2715 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2716 | return -EINVAL; | |
2717 | ||
2718 | if (!rdev->ops->set_noack_map) | |
2719 | return -EOPNOTSUPP; | |
2720 | ||
2721 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2722 | ||
e35e4d28 | 2723 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2724 | } |
2725 | ||
41ade00f JB |
2726 | struct get_key_cookie { |
2727 | struct sk_buff *msg; | |
2728 | int error; | |
b9454e83 | 2729 | int idx; |
41ade00f JB |
2730 | }; |
2731 | ||
2732 | static void get_key_callback(void *c, struct key_params *params) | |
2733 | { | |
b9454e83 | 2734 | struct nlattr *key; |
41ade00f JB |
2735 | struct get_key_cookie *cookie = c; |
2736 | ||
9360ffd1 DM |
2737 | if ((params->key && |
2738 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2739 | params->key_len, params->key)) || | |
2740 | (params->seq && | |
2741 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2742 | params->seq_len, params->seq)) || | |
2743 | (params->cipher && | |
2744 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2745 | params->cipher))) | |
2746 | goto nla_put_failure; | |
41ade00f | 2747 | |
b9454e83 JB |
2748 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2749 | if (!key) | |
2750 | goto nla_put_failure; | |
2751 | ||
9360ffd1 DM |
2752 | if ((params->key && |
2753 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2754 | params->key_len, params->key)) || | |
2755 | (params->seq && | |
2756 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2757 | params->seq_len, params->seq)) || | |
2758 | (params->cipher && | |
2759 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2760 | params->cipher))) | |
2761 | goto nla_put_failure; | |
b9454e83 | 2762 | |
9360ffd1 DM |
2763 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2764 | goto nla_put_failure; | |
b9454e83 JB |
2765 | |
2766 | nla_nest_end(cookie->msg, key); | |
2767 | ||
41ade00f JB |
2768 | return; |
2769 | nla_put_failure: | |
2770 | cookie->error = 1; | |
2771 | } | |
2772 | ||
2773 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2774 | { | |
4c476991 | 2775 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2776 | int err; |
4c476991 | 2777 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2778 | u8 key_idx = 0; |
e31b8213 JB |
2779 | const u8 *mac_addr = NULL; |
2780 | bool pairwise; | |
41ade00f JB |
2781 | struct get_key_cookie cookie = { |
2782 | .error = 0, | |
2783 | }; | |
2784 | void *hdr; | |
2785 | struct sk_buff *msg; | |
2786 | ||
2787 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2788 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2789 | ||
3cfcf6ac | 2790 | if (key_idx > 5) |
41ade00f JB |
2791 | return -EINVAL; |
2792 | ||
2793 | if (info->attrs[NL80211_ATTR_MAC]) | |
2794 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2795 | ||
e31b8213 JB |
2796 | pairwise = !!mac_addr; |
2797 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2798 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2799 | if (kt >= NUM_NL80211_KEYTYPES) | |
2800 | return -EINVAL; | |
2801 | if (kt != NL80211_KEYTYPE_GROUP && | |
2802 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2803 | return -EINVAL; | |
2804 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2805 | } | |
2806 | ||
4c476991 JB |
2807 | if (!rdev->ops->get_key) |
2808 | return -EOPNOTSUPP; | |
41ade00f | 2809 | |
fd2120ca | 2810 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2811 | if (!msg) |
2812 | return -ENOMEM; | |
41ade00f | 2813 | |
15e47304 | 2814 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2815 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 2816 | if (!hdr) |
9fe271af | 2817 | goto nla_put_failure; |
41ade00f JB |
2818 | |
2819 | cookie.msg = msg; | |
b9454e83 | 2820 | cookie.idx = key_idx; |
41ade00f | 2821 | |
9360ffd1 DM |
2822 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2823 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2824 | goto nla_put_failure; | |
2825 | if (mac_addr && | |
2826 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2827 | goto nla_put_failure; | |
41ade00f | 2828 | |
e31b8213 JB |
2829 | if (pairwise && mac_addr && |
2830 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2831 | return -ENOENT; | |
2832 | ||
e35e4d28 HG |
2833 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2834 | get_key_callback); | |
41ade00f JB |
2835 | |
2836 | if (err) | |
6c95e2a2 | 2837 | goto free_msg; |
41ade00f JB |
2838 | |
2839 | if (cookie.error) | |
2840 | goto nla_put_failure; | |
2841 | ||
2842 | genlmsg_end(msg, hdr); | |
4c476991 | 2843 | return genlmsg_reply(msg, info); |
41ade00f JB |
2844 | |
2845 | nla_put_failure: | |
2846 | err = -ENOBUFS; | |
6c95e2a2 | 2847 | free_msg: |
41ade00f | 2848 | nlmsg_free(msg); |
41ade00f JB |
2849 | return err; |
2850 | } | |
2851 | ||
2852 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2853 | { | |
4c476991 | 2854 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2855 | struct key_parse key; |
41ade00f | 2856 | int err; |
4c476991 | 2857 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2858 | |
b9454e83 JB |
2859 | err = nl80211_parse_key(info, &key); |
2860 | if (err) | |
2861 | return err; | |
41ade00f | 2862 | |
b9454e83 | 2863 | if (key.idx < 0) |
41ade00f JB |
2864 | return -EINVAL; |
2865 | ||
b9454e83 JB |
2866 | /* only support setting default key */ |
2867 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2868 | return -EINVAL; |
2869 | ||
dbd2fd65 | 2870 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2871 | |
dbd2fd65 JB |
2872 | if (key.def) { |
2873 | if (!rdev->ops->set_default_key) { | |
2874 | err = -EOPNOTSUPP; | |
2875 | goto out; | |
2876 | } | |
41ade00f | 2877 | |
dbd2fd65 JB |
2878 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2879 | if (err) | |
2880 | goto out; | |
2881 | ||
e35e4d28 | 2882 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2883 | key.def_uni, key.def_multi); |
2884 | ||
2885 | if (err) | |
2886 | goto out; | |
fffd0934 | 2887 | |
3d23e349 | 2888 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2889 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2890 | #endif | |
2891 | } else { | |
2892 | if (key.def_uni || !key.def_multi) { | |
2893 | err = -EINVAL; | |
2894 | goto out; | |
2895 | } | |
2896 | ||
2897 | if (!rdev->ops->set_default_mgmt_key) { | |
2898 | err = -EOPNOTSUPP; | |
2899 | goto out; | |
2900 | } | |
2901 | ||
2902 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2903 | if (err) | |
2904 | goto out; | |
2905 | ||
e35e4d28 | 2906 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2907 | if (err) |
2908 | goto out; | |
2909 | ||
2910 | #ifdef CONFIG_CFG80211_WEXT | |
2911 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2912 | #endif |
dbd2fd65 JB |
2913 | } |
2914 | ||
2915 | out: | |
fffd0934 | 2916 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2917 | |
41ade00f JB |
2918 | return err; |
2919 | } | |
2920 | ||
2921 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2922 | { | |
4c476991 | 2923 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2924 | int err; |
4c476991 | 2925 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2926 | struct key_parse key; |
e31b8213 | 2927 | const u8 *mac_addr = NULL; |
41ade00f | 2928 | |
b9454e83 JB |
2929 | err = nl80211_parse_key(info, &key); |
2930 | if (err) | |
2931 | return err; | |
41ade00f | 2932 | |
b9454e83 | 2933 | if (!key.p.key) |
41ade00f JB |
2934 | return -EINVAL; |
2935 | ||
41ade00f JB |
2936 | if (info->attrs[NL80211_ATTR_MAC]) |
2937 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2938 | ||
e31b8213 JB |
2939 | if (key.type == -1) { |
2940 | if (mac_addr) | |
2941 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2942 | else | |
2943 | key.type = NL80211_KEYTYPE_GROUP; | |
2944 | } | |
2945 | ||
2946 | /* for now */ | |
2947 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2948 | key.type != NL80211_KEYTYPE_GROUP) | |
2949 | return -EINVAL; | |
2950 | ||
4c476991 JB |
2951 | if (!rdev->ops->add_key) |
2952 | return -EOPNOTSUPP; | |
25e47c18 | 2953 | |
e31b8213 JB |
2954 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2955 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2956 | mac_addr)) | |
4c476991 | 2957 | return -EINVAL; |
41ade00f | 2958 | |
fffd0934 JB |
2959 | wdev_lock(dev->ieee80211_ptr); |
2960 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2961 | if (!err) | |
e35e4d28 HG |
2962 | err = rdev_add_key(rdev, dev, key.idx, |
2963 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2964 | mac_addr, &key.p); | |
fffd0934 | 2965 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2966 | |
41ade00f JB |
2967 | return err; |
2968 | } | |
2969 | ||
2970 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2971 | { | |
4c476991 | 2972 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2973 | int err; |
4c476991 | 2974 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2975 | u8 *mac_addr = NULL; |
b9454e83 | 2976 | struct key_parse key; |
41ade00f | 2977 | |
b9454e83 JB |
2978 | err = nl80211_parse_key(info, &key); |
2979 | if (err) | |
2980 | return err; | |
41ade00f JB |
2981 | |
2982 | if (info->attrs[NL80211_ATTR_MAC]) | |
2983 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2984 | ||
e31b8213 JB |
2985 | if (key.type == -1) { |
2986 | if (mac_addr) | |
2987 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2988 | else | |
2989 | key.type = NL80211_KEYTYPE_GROUP; | |
2990 | } | |
2991 | ||
2992 | /* for now */ | |
2993 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2994 | key.type != NL80211_KEYTYPE_GROUP) | |
2995 | return -EINVAL; | |
2996 | ||
4c476991 JB |
2997 | if (!rdev->ops->del_key) |
2998 | return -EOPNOTSUPP; | |
41ade00f | 2999 | |
fffd0934 JB |
3000 | wdev_lock(dev->ieee80211_ptr); |
3001 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
3002 | |
3003 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
3004 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
3005 | err = -ENOENT; | |
3006 | ||
fffd0934 | 3007 | if (!err) |
e35e4d28 HG |
3008 | err = rdev_del_key(rdev, dev, key.idx, |
3009 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3010 | mac_addr); | |
41ade00f | 3011 | |
3d23e349 | 3012 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 3013 | if (!err) { |
b9454e83 | 3014 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 3015 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 3016 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
3017 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
3018 | } | |
3019 | #endif | |
fffd0934 | 3020 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 3021 | |
41ade00f JB |
3022 | return err; |
3023 | } | |
3024 | ||
77765eaf VT |
3025 | /* This function returns an error or the number of nested attributes */ |
3026 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
3027 | { | |
3028 | struct nlattr *attr; | |
3029 | int n_entries = 0, tmp; | |
3030 | ||
3031 | nla_for_each_nested(attr, nl_attr, tmp) { | |
3032 | if (nla_len(attr) != ETH_ALEN) | |
3033 | return -EINVAL; | |
3034 | ||
3035 | n_entries++; | |
3036 | } | |
3037 | ||
3038 | return n_entries; | |
3039 | } | |
3040 | ||
3041 | /* | |
3042 | * This function parses ACL information and allocates memory for ACL data. | |
3043 | * On successful return, the calling function is responsible to free the | |
3044 | * ACL buffer returned by this function. | |
3045 | */ | |
3046 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3047 | struct genl_info *info) | |
3048 | { | |
3049 | enum nl80211_acl_policy acl_policy; | |
3050 | struct nlattr *attr; | |
3051 | struct cfg80211_acl_data *acl; | |
3052 | int i = 0, n_entries, tmp; | |
3053 | ||
3054 | if (!wiphy->max_acl_mac_addrs) | |
3055 | return ERR_PTR(-EOPNOTSUPP); | |
3056 | ||
3057 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3058 | return ERR_PTR(-EINVAL); | |
3059 | ||
3060 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3061 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3062 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3063 | return ERR_PTR(-EINVAL); | |
3064 | ||
3065 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3066 | return ERR_PTR(-EINVAL); | |
3067 | ||
3068 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3069 | if (n_entries < 0) | |
3070 | return ERR_PTR(n_entries); | |
3071 | ||
3072 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3073 | return ERR_PTR(-ENOTSUPP); | |
3074 | ||
3075 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
3076 | GFP_KERNEL); | |
3077 | if (!acl) | |
3078 | return ERR_PTR(-ENOMEM); | |
3079 | ||
3080 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3081 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3082 | i++; | |
3083 | } | |
3084 | ||
3085 | acl->n_acl_entries = n_entries; | |
3086 | acl->acl_policy = acl_policy; | |
3087 | ||
3088 | return acl; | |
3089 | } | |
3090 | ||
3091 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3092 | { | |
3093 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3094 | struct net_device *dev = info->user_ptr[1]; | |
3095 | struct cfg80211_acl_data *acl; | |
3096 | int err; | |
3097 | ||
3098 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3099 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3100 | return -EOPNOTSUPP; | |
3101 | ||
3102 | if (!dev->ieee80211_ptr->beacon_interval) | |
3103 | return -EINVAL; | |
3104 | ||
3105 | acl = parse_acl_data(&rdev->wiphy, info); | |
3106 | if (IS_ERR(acl)) | |
3107 | return PTR_ERR(acl); | |
3108 | ||
3109 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3110 | ||
3111 | kfree(acl); | |
3112 | ||
3113 | return err; | |
3114 | } | |
3115 | ||
a1193be8 | 3116 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3117 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3118 | { |
8860020e | 3119 | bool haveinfo = false; |
ed1b6cc7 | 3120 | |
a1193be8 SW |
3121 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3122 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3123 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3124 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3125 | return -EINVAL; |
3126 | ||
8860020e | 3127 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3128 | |
a1193be8 SW |
3129 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3130 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3131 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3132 | if (!bcn->head_len) |
3133 | return -EINVAL; | |
3134 | haveinfo = true; | |
ed1b6cc7 JB |
3135 | } |
3136 | ||
a1193be8 SW |
3137 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3138 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3139 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3140 | haveinfo = true; |
ed1b6cc7 JB |
3141 | } |
3142 | ||
4c476991 JB |
3143 | if (!haveinfo) |
3144 | return -EINVAL; | |
3b85875a | 3145 | |
a1193be8 SW |
3146 | if (attrs[NL80211_ATTR_IE]) { |
3147 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3148 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3149 | } |
3150 | ||
a1193be8 | 3151 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3152 | bcn->proberesp_ies = |
a1193be8 | 3153 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3154 | bcn->proberesp_ies_len = |
a1193be8 | 3155 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3156 | } |
3157 | ||
a1193be8 | 3158 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3159 | bcn->assocresp_ies = |
a1193be8 | 3160 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3161 | bcn->assocresp_ies_len = |
a1193be8 | 3162 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3163 | } |
3164 | ||
a1193be8 SW |
3165 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3166 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3167 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3168 | } |
3169 | ||
8860020e JB |
3170 | return 0; |
3171 | } | |
3172 | ||
46c1dd0c FF |
3173 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3174 | struct cfg80211_ap_settings *params) | |
3175 | { | |
3176 | struct wireless_dev *wdev; | |
3177 | bool ret = false; | |
3178 | ||
89a54e48 | 3179 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3180 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3181 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3182 | continue; | |
3183 | ||
683b6d3b | 3184 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3185 | continue; |
3186 | ||
683b6d3b | 3187 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3188 | ret = true; |
3189 | break; | |
3190 | } | |
3191 | ||
46c1dd0c FF |
3192 | return ret; |
3193 | } | |
3194 | ||
e39e5b5e JM |
3195 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3196 | enum nl80211_auth_type auth_type, | |
3197 | enum nl80211_commands cmd) | |
3198 | { | |
3199 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3200 | return false; | |
3201 | ||
3202 | switch (cmd) { | |
3203 | case NL80211_CMD_AUTHENTICATE: | |
3204 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3205 | auth_type == NL80211_AUTHTYPE_SAE) | |
3206 | return false; | |
3207 | return true; | |
3208 | case NL80211_CMD_CONNECT: | |
3209 | case NL80211_CMD_START_AP: | |
3210 | /* SAE not supported yet */ | |
3211 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3212 | return false; | |
3213 | return true; | |
3214 | default: | |
3215 | return false; | |
3216 | } | |
3217 | } | |
3218 | ||
8860020e JB |
3219 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3220 | { | |
3221 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3222 | struct net_device *dev = info->user_ptr[1]; | |
3223 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3224 | struct cfg80211_ap_settings params; | |
3225 | int err; | |
3226 | ||
3227 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3228 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3229 | return -EOPNOTSUPP; | |
3230 | ||
3231 | if (!rdev->ops->start_ap) | |
3232 | return -EOPNOTSUPP; | |
3233 | ||
3234 | if (wdev->beacon_interval) | |
3235 | return -EALREADY; | |
3236 | ||
3237 | memset(¶ms, 0, sizeof(params)); | |
3238 | ||
3239 | /* these are required for START_AP */ | |
3240 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3241 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3242 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3243 | return -EINVAL; | |
3244 | ||
a1193be8 | 3245 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3246 | if (err) |
3247 | return err; | |
3248 | ||
3249 | params.beacon_interval = | |
3250 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3251 | params.dtim_period = | |
3252 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3253 | ||
3254 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3255 | if (err) | |
3256 | return err; | |
3257 | ||
3258 | /* | |
3259 | * In theory, some of these attributes should be required here | |
3260 | * but since they were not used when the command was originally | |
3261 | * added, keep them optional for old user space programs to let | |
3262 | * them continue to work with drivers that do not need the | |
3263 | * additional information -- drivers must check! | |
3264 | */ | |
3265 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3266 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3267 | params.ssid_len = | |
3268 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3269 | if (params.ssid_len == 0 || | |
3270 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3271 | return -EINVAL; | |
3272 | } | |
3273 | ||
3274 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3275 | params.hidden_ssid = nla_get_u32( | |
3276 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3277 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3278 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3279 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3280 | return -EINVAL; | |
3281 | } | |
3282 | ||
3283 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3284 | ||
3285 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3286 | params.auth_type = nla_get_u32( | |
3287 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3288 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3289 | NL80211_CMD_START_AP)) | |
8860020e JB |
3290 | return -EINVAL; |
3291 | } else | |
3292 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3293 | ||
3294 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3295 | NL80211_MAX_NR_CIPHER_SUITES); | |
3296 | if (err) | |
3297 | return err; | |
3298 | ||
1b658f11 VT |
3299 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3300 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3301 | return -EOPNOTSUPP; | |
3302 | params.inactivity_timeout = nla_get_u16( | |
3303 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3304 | } | |
3305 | ||
53cabad7 JB |
3306 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3307 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3308 | return -EINVAL; | |
3309 | params.p2p_ctwindow = | |
3310 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3311 | if (params.p2p_ctwindow > 127) | |
3312 | return -EINVAL; | |
3313 | if (params.p2p_ctwindow != 0 && | |
3314 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3315 | return -EINVAL; | |
3316 | } | |
3317 | ||
3318 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3319 | u8 tmp; | |
3320 | ||
3321 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3322 | return -EINVAL; | |
3323 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3324 | if (tmp > 1) | |
3325 | return -EINVAL; | |
3326 | params.p2p_opp_ps = tmp; | |
3327 | if (params.p2p_opp_ps != 0 && | |
3328 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3329 | return -EINVAL; | |
3330 | } | |
3331 | ||
aa430da4 | 3332 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3333 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3334 | if (err) | |
3335 | return err; | |
3336 | } else if (wdev->preset_chandef.chan) { | |
3337 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3338 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3339 | return -EINVAL; |
3340 | ||
174e0cd2 IP |
3341 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
3342 | wdev->iftype)) | |
aa430da4 JB |
3343 | return -EINVAL; |
3344 | ||
77765eaf VT |
3345 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3346 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3347 | if (IS_ERR(params.acl)) | |
3348 | return PTR_ERR(params.acl); | |
3349 | } | |
3350 | ||
18998c38 EP |
3351 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
3352 | params.smps_mode = | |
3353 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); | |
3354 | switch (params.smps_mode) { | |
3355 | case NL80211_SMPS_OFF: | |
3356 | break; | |
3357 | case NL80211_SMPS_STATIC: | |
3358 | if (!(rdev->wiphy.features & | |
3359 | NL80211_FEATURE_STATIC_SMPS)) | |
3360 | return -EINVAL; | |
3361 | break; | |
3362 | case NL80211_SMPS_DYNAMIC: | |
3363 | if (!(rdev->wiphy.features & | |
3364 | NL80211_FEATURE_DYNAMIC_SMPS)) | |
3365 | return -EINVAL; | |
3366 | break; | |
3367 | default: | |
3368 | return -EINVAL; | |
3369 | } | |
3370 | } else { | |
3371 | params.smps_mode = NL80211_SMPS_OFF; | |
3372 | } | |
3373 | ||
c56589ed | 3374 | wdev_lock(wdev); |
e35e4d28 | 3375 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3376 | if (!err) { |
683b6d3b | 3377 | wdev->preset_chandef = params.chandef; |
8860020e | 3378 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 3379 | wdev->chandef = params.chandef; |
06e191e2 AQ |
3380 | wdev->ssid_len = params.ssid_len; |
3381 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3382 | } |
c56589ed | 3383 | wdev_unlock(wdev); |
77765eaf VT |
3384 | |
3385 | kfree(params.acl); | |
3386 | ||
56d1893d | 3387 | return err; |
ed1b6cc7 JB |
3388 | } |
3389 | ||
8860020e JB |
3390 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3391 | { | |
3392 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3393 | struct net_device *dev = info->user_ptr[1]; | |
3394 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3395 | struct cfg80211_beacon_data params; | |
3396 | int err; | |
3397 | ||
3398 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3399 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3400 | return -EOPNOTSUPP; | |
3401 | ||
3402 | if (!rdev->ops->change_beacon) | |
3403 | return -EOPNOTSUPP; | |
3404 | ||
3405 | if (!wdev->beacon_interval) | |
3406 | return -EINVAL; | |
3407 | ||
a1193be8 | 3408 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3409 | if (err) |
3410 | return err; | |
3411 | ||
c56589ed SW |
3412 | wdev_lock(wdev); |
3413 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3414 | wdev_unlock(wdev); | |
3415 | ||
3416 | return err; | |
8860020e JB |
3417 | } |
3418 | ||
3419 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3420 | { |
4c476991 JB |
3421 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3422 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3423 | |
7c8d5e03 | 3424 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
3425 | } |
3426 | ||
5727ef1b JB |
3427 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3428 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3429 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3430 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3431 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3432 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3433 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3434 | }; |
3435 | ||
eccb8e8f | 3436 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3437 | enum nl80211_iftype iftype, |
eccb8e8f | 3438 | struct station_parameters *params) |
5727ef1b JB |
3439 | { |
3440 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3441 | struct nlattr *nla; |
5727ef1b JB |
3442 | int flag; |
3443 | ||
eccb8e8f JB |
3444 | /* |
3445 | * Try parsing the new attribute first so userspace | |
3446 | * can specify both for older kernels. | |
3447 | */ | |
3448 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3449 | if (nla) { | |
3450 | struct nl80211_sta_flag_update *sta_flags; | |
3451 | ||
3452 | sta_flags = nla_data(nla); | |
3453 | params->sta_flags_mask = sta_flags->mask; | |
3454 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3455 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3456 | if ((params->sta_flags_mask | |
3457 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3458 | return -EINVAL; | |
3459 | return 0; | |
3460 | } | |
3461 | ||
3462 | /* if present, parse the old attribute */ | |
5727ef1b | 3463 | |
eccb8e8f | 3464 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3465 | if (!nla) |
3466 | return 0; | |
3467 | ||
3468 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3469 | nla, sta_flags_policy)) | |
3470 | return -EINVAL; | |
3471 | ||
bdd3ae3d JB |
3472 | /* |
3473 | * Only allow certain flags for interface types so that | |
3474 | * other attributes are silently ignored. Remember that | |
3475 | * this is backward compatibility code with old userspace | |
3476 | * and shouldn't be hit in other cases anyway. | |
3477 | */ | |
3478 | switch (iftype) { | |
3479 | case NL80211_IFTYPE_AP: | |
3480 | case NL80211_IFTYPE_AP_VLAN: | |
3481 | case NL80211_IFTYPE_P2P_GO: | |
3482 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3483 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3484 | BIT(NL80211_STA_FLAG_WME) | | |
3485 | BIT(NL80211_STA_FLAG_MFP); | |
3486 | break; | |
3487 | case NL80211_IFTYPE_P2P_CLIENT: | |
3488 | case NL80211_IFTYPE_STATION: | |
3489 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3490 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3491 | break; | |
3492 | case NL80211_IFTYPE_MESH_POINT: | |
3493 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3494 | BIT(NL80211_STA_FLAG_MFP) | | |
3495 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3496 | default: | |
3497 | return -EINVAL; | |
3498 | } | |
5727ef1b | 3499 | |
3383b5a6 JB |
3500 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3501 | if (flags[flag]) { | |
eccb8e8f | 3502 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3503 | |
3383b5a6 JB |
3504 | /* no longer support new API additions in old API */ |
3505 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3506 | return -EINVAL; | |
3507 | } | |
3508 | } | |
3509 | ||
5727ef1b JB |
3510 | return 0; |
3511 | } | |
3512 | ||
c8dcfd8a FF |
3513 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3514 | int attr) | |
3515 | { | |
3516 | struct nlattr *rate; | |
8eb41c8d VK |
3517 | u32 bitrate; |
3518 | u16 bitrate_compat; | |
c8dcfd8a FF |
3519 | |
3520 | rate = nla_nest_start(msg, attr); | |
3521 | if (!rate) | |
db9c64cf | 3522 | return false; |
c8dcfd8a FF |
3523 | |
3524 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3525 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3526 | /* report 16-bit bitrate only if we can */ |
3527 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3528 | if (bitrate > 0 && |
3529 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3530 | return false; | |
3531 | if (bitrate_compat > 0 && | |
3532 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3533 | return false; | |
3534 | ||
3535 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3536 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3537 | return false; | |
3538 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3539 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3540 | return false; | |
3541 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3542 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3543 | return false; | |
3544 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3545 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3546 | return false; | |
3547 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3548 | return false; | |
3549 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3550 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3551 | return false; | |
3552 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3553 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3554 | return false; | |
3555 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3556 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3557 | return false; | |
3558 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3559 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3560 | return false; | |
3561 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3562 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3563 | return false; | |
3564 | } | |
c8dcfd8a FF |
3565 | |
3566 | nla_nest_end(msg, rate); | |
3567 | return true; | |
c8dcfd8a FF |
3568 | } |
3569 | ||
119363c7 FF |
3570 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3571 | int id) | |
3572 | { | |
3573 | void *attr; | |
3574 | int i = 0; | |
3575 | ||
3576 | if (!mask) | |
3577 | return true; | |
3578 | ||
3579 | attr = nla_nest_start(msg, id); | |
3580 | if (!attr) | |
3581 | return false; | |
3582 | ||
3583 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3584 | if (!(mask & BIT(i))) | |
3585 | continue; | |
3586 | ||
3587 | if (nla_put_u8(msg, i, signal[i])) | |
3588 | return false; | |
3589 | } | |
3590 | ||
3591 | nla_nest_end(msg, attr); | |
3592 | ||
3593 | return true; | |
3594 | } | |
3595 | ||
15e47304 | 3596 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3597 | int flags, |
3598 | struct cfg80211_registered_device *rdev, | |
3599 | struct net_device *dev, | |
98b62183 | 3600 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3601 | { |
3602 | void *hdr; | |
f4263c98 | 3603 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3604 | |
15e47304 | 3605 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3606 | if (!hdr) |
3607 | return -1; | |
3608 | ||
9360ffd1 DM |
3609 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3610 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3611 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3612 | goto nla_put_failure; | |
f5ea9120 | 3613 | |
2ec600d6 LCC |
3614 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3615 | if (!sinfoattr) | |
fd5b74dc | 3616 | goto nla_put_failure; |
9360ffd1 DM |
3617 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3618 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3619 | sinfo->connected_time)) | |
3620 | goto nla_put_failure; | |
3621 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3622 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3623 | sinfo->inactive_time)) | |
3624 | goto nla_put_failure; | |
42745e03 VK |
3625 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3626 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3627 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3628 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3629 | goto nla_put_failure; |
42745e03 | 3630 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
4325d724 | 3631 | STATION_INFO_TX_BYTES64)) && |
9360ffd1 | 3632 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3633 | (u32)sinfo->tx_bytes)) |
3634 | goto nla_put_failure; | |
3635 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3636 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3637 | sinfo->rx_bytes)) | |
3638 | goto nla_put_failure; | |
3639 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3640 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3641 | sinfo->tx_bytes)) |
3642 | goto nla_put_failure; | |
3643 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3644 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3645 | goto nla_put_failure; | |
3646 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3647 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3648 | goto nla_put_failure; | |
3649 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3650 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3651 | sinfo->plink_state)) | |
3652 | goto nla_put_failure; | |
66266b3a JL |
3653 | switch (rdev->wiphy.signal_type) { |
3654 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3655 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3656 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3657 | sinfo->signal)) | |
3658 | goto nla_put_failure; | |
3659 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3660 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3661 | sinfo->signal_avg)) | |
3662 | goto nla_put_failure; | |
66266b3a JL |
3663 | break; |
3664 | default: | |
3665 | break; | |
3666 | } | |
119363c7 FF |
3667 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
3668 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3669 | sinfo->chain_signal, | |
3670 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3671 | goto nla_put_failure; | |
3672 | } | |
3673 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { | |
3674 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3675 | sinfo->chain_signal_avg, | |
3676 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3677 | goto nla_put_failure; | |
3678 | } | |
420e7fab | 3679 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3680 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3681 | NL80211_STA_INFO_TX_BITRATE)) | |
3682 | goto nla_put_failure; | |
3683 | } | |
3684 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3685 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3686 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3687 | goto nla_put_failure; |
420e7fab | 3688 | } |
9360ffd1 DM |
3689 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3690 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3691 | sinfo->rx_packets)) | |
3692 | goto nla_put_failure; | |
3693 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3694 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3695 | sinfo->tx_packets)) | |
3696 | goto nla_put_failure; | |
3697 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3698 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3699 | sinfo->tx_retries)) | |
3700 | goto nla_put_failure; | |
3701 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3702 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3703 | sinfo->tx_failed)) | |
3704 | goto nla_put_failure; | |
867d849f AQ |
3705 | if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) && |
3706 | nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT, | |
3707 | sinfo->expected_throughput)) | |
3708 | goto nla_put_failure; | |
9360ffd1 DM |
3709 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
3710 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3711 | sinfo->beacon_loss_count)) | |
3712 | goto nla_put_failure; | |
3b1c5a53 MP |
3713 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3714 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3715 | sinfo->local_pm)) | |
3716 | goto nla_put_failure; | |
3717 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3718 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3719 | sinfo->peer_pm)) | |
3720 | goto nla_put_failure; | |
3721 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3722 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3723 | sinfo->nonpeer_pm)) | |
3724 | goto nla_put_failure; | |
f4263c98 PS |
3725 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3726 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3727 | if (!bss_param) | |
3728 | goto nla_put_failure; | |
3729 | ||
9360ffd1 DM |
3730 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3731 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3732 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3733 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3734 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3735 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3736 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3737 | sinfo->bss_param.dtim_period) || | |
3738 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3739 | sinfo->bss_param.beacon_interval)) | |
3740 | goto nla_put_failure; | |
f4263c98 PS |
3741 | |
3742 | nla_nest_end(msg, bss_param); | |
3743 | } | |
9360ffd1 DM |
3744 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3745 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3746 | sizeof(struct nl80211_sta_flag_update), | |
3747 | &sinfo->sta_flags)) | |
3748 | goto nla_put_failure; | |
7eab0f64 JL |
3749 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3750 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3751 | sinfo->t_offset)) | |
3752 | goto nla_put_failure; | |
2ec600d6 | 3753 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3754 | |
9360ffd1 DM |
3755 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3756 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3757 | sinfo->assoc_req_ies)) | |
3758 | goto nla_put_failure; | |
50d3dfb7 | 3759 | |
fd5b74dc JB |
3760 | return genlmsg_end(msg, hdr); |
3761 | ||
3762 | nla_put_failure: | |
bc3ed28c TG |
3763 | genlmsg_cancel(msg, hdr); |
3764 | return -EMSGSIZE; | |
fd5b74dc JB |
3765 | } |
3766 | ||
2ec600d6 | 3767 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3768 | struct netlink_callback *cb) |
2ec600d6 | 3769 | { |
2ec600d6 | 3770 | struct station_info sinfo; |
1b8ec87a | 3771 | struct cfg80211_registered_device *rdev; |
97990a06 | 3772 | struct wireless_dev *wdev; |
2ec600d6 | 3773 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3774 | int sta_idx = cb->args[2]; |
2ec600d6 | 3775 | int err; |
2ec600d6 | 3776 | |
1b8ec87a | 3777 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
3778 | if (err) |
3779 | return err; | |
bba95fef | 3780 | |
97990a06 JB |
3781 | if (!wdev->netdev) { |
3782 | err = -EINVAL; | |
3783 | goto out_err; | |
3784 | } | |
3785 | ||
1b8ec87a | 3786 | if (!rdev->ops->dump_station) { |
eec60b03 | 3787 | err = -EOPNOTSUPP; |
bba95fef JB |
3788 | goto out_err; |
3789 | } | |
3790 | ||
bba95fef | 3791 | while (1) { |
f612cedf | 3792 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 3793 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
e35e4d28 | 3794 | mac_addr, &sinfo); |
bba95fef JB |
3795 | if (err == -ENOENT) |
3796 | break; | |
3797 | if (err) | |
3b85875a | 3798 | goto out_err; |
bba95fef JB |
3799 | |
3800 | if (nl80211_send_station(skb, | |
15e47304 | 3801 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3802 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 3803 | rdev, wdev->netdev, mac_addr, |
bba95fef JB |
3804 | &sinfo) < 0) |
3805 | goto out; | |
3806 | ||
3807 | sta_idx++; | |
3808 | } | |
3809 | ||
3810 | ||
3811 | out: | |
97990a06 | 3812 | cb->args[2] = sta_idx; |
bba95fef | 3813 | err = skb->len; |
bba95fef | 3814 | out_err: |
1b8ec87a | 3815 | nl80211_finish_wdev_dump(rdev); |
bba95fef JB |
3816 | |
3817 | return err; | |
2ec600d6 | 3818 | } |
fd5b74dc | 3819 | |
5727ef1b JB |
3820 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3821 | { | |
4c476991 JB |
3822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3823 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3824 | struct station_info sinfo; |
fd5b74dc JB |
3825 | struct sk_buff *msg; |
3826 | u8 *mac_addr = NULL; | |
4c476991 | 3827 | int err; |
fd5b74dc | 3828 | |
2ec600d6 | 3829 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3830 | |
3831 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3832 | return -EINVAL; | |
3833 | ||
3834 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3835 | ||
4c476991 JB |
3836 | if (!rdev->ops->get_station) |
3837 | return -EOPNOTSUPP; | |
3b85875a | 3838 | |
e35e4d28 | 3839 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3840 | if (err) |
4c476991 | 3841 | return err; |
2ec600d6 | 3842 | |
fd2120ca | 3843 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3844 | if (!msg) |
4c476991 | 3845 | return -ENOMEM; |
fd5b74dc | 3846 | |
15e47304 | 3847 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3848 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3849 | nlmsg_free(msg); |
3850 | return -ENOBUFS; | |
3851 | } | |
3b85875a | 3852 | |
4c476991 | 3853 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3854 | } |
3855 | ||
77ee7c89 JB |
3856 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3857 | struct station_parameters *params, | |
3858 | enum cfg80211_station_type statype) | |
3859 | { | |
3860 | if (params->listen_interval != -1) | |
3861 | return -EINVAL; | |
c72e1140 AN |
3862 | if (params->aid && |
3863 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
77ee7c89 JB |
3864 | return -EINVAL; |
3865 | ||
3866 | /* When you run into this, adjust the code below for the new flag */ | |
3867 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3868 | ||
3869 | switch (statype) { | |
eef941e6 TP |
3870 | case CFG80211_STA_MESH_PEER_KERNEL: |
3871 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3872 | /* |
3873 | * No ignoring the TDLS flag here -- the userspace mesh | |
3874 | * code doesn't have the bug of including TDLS in the | |
3875 | * mask everywhere. | |
3876 | */ | |
3877 | if (params->sta_flags_mask & | |
3878 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3879 | BIT(NL80211_STA_FLAG_MFP) | | |
3880 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3881 | return -EINVAL; | |
3882 | break; | |
3883 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3884 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3885 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3886 | return -EINVAL; | |
3887 | /* ignore since it can't change */ | |
3888 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3889 | break; | |
3890 | default: | |
3891 | /* disallow mesh-specific things */ | |
3892 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3893 | return -EINVAL; | |
3894 | if (params->local_pm) | |
3895 | return -EINVAL; | |
3896 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3897 | return -EINVAL; | |
3898 | } | |
3899 | ||
3900 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3901 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3902 | /* TDLS can't be set, ... */ | |
3903 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3904 | return -EINVAL; | |
3905 | /* | |
3906 | * ... but don't bother the driver with it. This works around | |
3907 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3908 | * TLDS_PEER flag in the mask even for AP mode. | |
3909 | */ | |
3910 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3911 | } | |
3912 | ||
3913 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3914 | /* reject other things that can't change */ | |
3915 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3916 | return -EINVAL; | |
3917 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3918 | return -EINVAL; | |
3919 | if (params->supported_rates) | |
3920 | return -EINVAL; | |
3921 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3922 | return -EINVAL; | |
3923 | } | |
3924 | ||
3925 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3926 | if (params->vlan) | |
3927 | return -EINVAL; | |
3928 | } | |
3929 | ||
3930 | switch (statype) { | |
3931 | case CFG80211_STA_AP_MLME_CLIENT: | |
3932 | /* Use this only for authorizing/unauthorizing a station */ | |
3933 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3934 | return -EOPNOTSUPP; | |
3935 | break; | |
3936 | case CFG80211_STA_AP_CLIENT: | |
3937 | /* accept only the listed bits */ | |
3938 | if (params->sta_flags_mask & | |
3939 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3940 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3941 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
3942 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3943 | BIT(NL80211_STA_FLAG_WME) | | |
3944 | BIT(NL80211_STA_FLAG_MFP))) | |
3945 | return -EINVAL; | |
3946 | ||
3947 | /* but authenticated/associated only if driver handles it */ | |
3948 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3949 | params->sta_flags_mask & | |
3950 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3951 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3952 | return -EINVAL; | |
3953 | break; | |
3954 | case CFG80211_STA_IBSS: | |
3955 | case CFG80211_STA_AP_STA: | |
3956 | /* reject any changes other than AUTHORIZED */ | |
3957 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3958 | return -EINVAL; | |
3959 | break; | |
3960 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3961 | /* reject any changes other than AUTHORIZED or WME */ | |
3962 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3963 | BIT(NL80211_STA_FLAG_WME))) | |
3964 | return -EINVAL; | |
3965 | /* force (at least) rates when authorizing */ | |
3966 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
3967 | !params->supported_rates) | |
3968 | return -EINVAL; | |
3969 | break; | |
3970 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3971 | /* reject any changes */ | |
3972 | return -EINVAL; | |
eef941e6 | 3973 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
3974 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
3975 | return -EINVAL; | |
3976 | break; | |
eef941e6 | 3977 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
3978 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
3979 | return -EINVAL; | |
3980 | break; | |
3981 | } | |
3982 | ||
3983 | return 0; | |
3984 | } | |
3985 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
3986 | ||
5727ef1b | 3987 | /* |
c258d2de | 3988 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 3989 | */ |
80b99899 JB |
3990 | static struct net_device *get_vlan(struct genl_info *info, |
3991 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 3992 | { |
463d0183 | 3993 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
3994 | struct net_device *v; |
3995 | int ret; | |
3996 | ||
3997 | if (!vlanattr) | |
3998 | return NULL; | |
3999 | ||
4000 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
4001 | if (!v) | |
4002 | return ERR_PTR(-ENODEV); | |
4003 | ||
4004 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
4005 | ret = -EINVAL; | |
4006 | goto error; | |
5727ef1b | 4007 | } |
80b99899 | 4008 | |
77ee7c89 JB |
4009 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
4010 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4011 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
4012 | ret = -EINVAL; | |
4013 | goto error; | |
4014 | } | |
4015 | ||
80b99899 JB |
4016 | if (!netif_running(v)) { |
4017 | ret = -ENETDOWN; | |
4018 | goto error; | |
4019 | } | |
4020 | ||
4021 | return v; | |
4022 | error: | |
4023 | dev_put(v); | |
4024 | return ERR_PTR(ret); | |
5727ef1b JB |
4025 | } |
4026 | ||
94e860f1 JB |
4027 | static const struct nla_policy |
4028 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
4029 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
4030 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
4031 | }; | |
4032 | ||
ff276691 JB |
4033 | static int nl80211_parse_sta_wme(struct genl_info *info, |
4034 | struct station_parameters *params) | |
df881293 | 4035 | { |
df881293 JM |
4036 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
4037 | struct nlattr *nla; | |
4038 | int err; | |
4039 | ||
df881293 JM |
4040 | /* parse WME attributes if present */ |
4041 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
4042 | return 0; | |
4043 | ||
4044 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
4045 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
4046 | nl80211_sta_wme_policy); | |
4047 | if (err) | |
4048 | return err; | |
4049 | ||
4050 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
4051 | params->uapsd_queues = nla_get_u8( | |
4052 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4053 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
4054 | return -EINVAL; | |
4055 | ||
4056 | if (tb[NL80211_STA_WME_MAX_SP]) | |
4057 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4058 | ||
4059 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
4060 | return -EINVAL; | |
4061 | ||
4062 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
4063 | ||
4064 | return 0; | |
4065 | } | |
4066 | ||
c01fc9ad SD |
4067 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4068 | struct station_parameters *params) | |
4069 | { | |
4070 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4071 | params->supported_channels = | |
4072 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4073 | params->supported_channels_len = | |
4074 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4075 | /* | |
4076 | * Need to include at least one (first channel, number of | |
4077 | * channels) tuple for each subband, and must have proper | |
4078 | * tuples for the rest of the data as well. | |
4079 | */ | |
4080 | if (params->supported_channels_len < 2) | |
4081 | return -EINVAL; | |
4082 | if (params->supported_channels_len % 2) | |
4083 | return -EINVAL; | |
4084 | } | |
4085 | ||
4086 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4087 | params->supported_oper_classes = | |
4088 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4089 | params->supported_oper_classes_len = | |
4090 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4091 | /* | |
4092 | * The value of the Length field of the Supported Operating | |
4093 | * Classes element is between 2 and 253. | |
4094 | */ | |
4095 | if (params->supported_oper_classes_len < 2 || | |
4096 | params->supported_oper_classes_len > 253) | |
4097 | return -EINVAL; | |
4098 | } | |
4099 | return 0; | |
4100 | } | |
4101 | ||
ff276691 JB |
4102 | static int nl80211_set_station_tdls(struct genl_info *info, |
4103 | struct station_parameters *params) | |
4104 | { | |
c01fc9ad | 4105 | int err; |
ff276691 | 4106 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4107 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4108 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4109 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4110 | params->ht_capa = | |
4111 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4112 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4113 | params->vht_capa = | |
4114 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4115 | ||
c01fc9ad SD |
4116 | err = nl80211_parse_sta_channel_info(info, params); |
4117 | if (err) | |
4118 | return err; | |
4119 | ||
ff276691 JB |
4120 | return nl80211_parse_sta_wme(info, params); |
4121 | } | |
4122 | ||
5727ef1b JB |
4123 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4124 | { | |
4c476991 | 4125 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4126 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4127 | struct station_parameters params; |
77ee7c89 JB |
4128 | u8 *mac_addr; |
4129 | int err; | |
5727ef1b JB |
4130 | |
4131 | memset(¶ms, 0, sizeof(params)); | |
4132 | ||
4133 | params.listen_interval = -1; | |
4134 | ||
77ee7c89 JB |
4135 | if (!rdev->ops->change_station) |
4136 | return -EOPNOTSUPP; | |
4137 | ||
5727ef1b JB |
4138 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4139 | return -EINVAL; | |
4140 | ||
4141 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4142 | return -EINVAL; | |
4143 | ||
4144 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4145 | ||
4146 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4147 | params.supported_rates = | |
4148 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4149 | params.supported_rates_len = | |
4150 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4151 | } | |
4152 | ||
9d62a986 JM |
4153 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4154 | params.capability = | |
4155 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4156 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4157 | } | |
4158 | ||
4159 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4160 | params.ext_capab = | |
4161 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4162 | params.ext_capab_len = | |
4163 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4164 | } | |
4165 | ||
df881293 | 4166 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 4167 | return -EINVAL; |
36aedc90 | 4168 | |
bdd3ae3d | 4169 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4170 | return -EINVAL; |
4171 | ||
f8bacc21 | 4172 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4173 | params.plink_action = |
f8bacc21 JB |
4174 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4175 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4176 | return -EINVAL; | |
4177 | } | |
2ec600d6 | 4178 | |
f8bacc21 | 4179 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4180 | params.plink_state = |
f8bacc21 JB |
4181 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4182 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4183 | return -EINVAL; | |
4184 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
4185 | } | |
9c3990aa | 4186 | |
3b1c5a53 MP |
4187 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4188 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4189 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4190 | ||
4191 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4192 | pm > NL80211_MESH_POWER_MAX) | |
4193 | return -EINVAL; | |
4194 | ||
4195 | params.local_pm = pm; | |
4196 | } | |
4197 | ||
77ee7c89 JB |
4198 | /* Include parameters for TDLS peer (will check later) */ |
4199 | err = nl80211_set_station_tdls(info, ¶ms); | |
4200 | if (err) | |
4201 | return err; | |
4202 | ||
4203 | params.vlan = get_vlan(info, rdev); | |
4204 | if (IS_ERR(params.vlan)) | |
4205 | return PTR_ERR(params.vlan); | |
4206 | ||
a97f4424 JB |
4207 | switch (dev->ieee80211_ptr->iftype) { |
4208 | case NL80211_IFTYPE_AP: | |
4209 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4210 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4211 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4212 | case NL80211_IFTYPE_STATION: |
267335d6 | 4213 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4214 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4215 | break; |
4216 | default: | |
77ee7c89 JB |
4217 | err = -EOPNOTSUPP; |
4218 | goto out_put_vlan; | |
034d655e JB |
4219 | } |
4220 | ||
77ee7c89 | 4221 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4222 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4223 | |
77ee7c89 | 4224 | out_put_vlan: |
5727ef1b JB |
4225 | if (params.vlan) |
4226 | dev_put(params.vlan); | |
3b85875a | 4227 | |
5727ef1b JB |
4228 | return err; |
4229 | } | |
4230 | ||
4231 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4232 | { | |
4c476991 | 4233 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4234 | int err; |
4c476991 | 4235 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4236 | struct station_parameters params; |
4237 | u8 *mac_addr = NULL; | |
4238 | ||
4239 | memset(¶ms, 0, sizeof(params)); | |
4240 | ||
984c311b JB |
4241 | if (!rdev->ops->add_station) |
4242 | return -EOPNOTSUPP; | |
4243 | ||
5727ef1b JB |
4244 | if (!info->attrs[NL80211_ATTR_MAC]) |
4245 | return -EINVAL; | |
4246 | ||
5727ef1b JB |
4247 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4248 | return -EINVAL; | |
4249 | ||
4250 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4251 | return -EINVAL; | |
4252 | ||
5e4b6f56 JM |
4253 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4254 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4255 | return -EINVAL; |
4256 | ||
5727ef1b JB |
4257 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4258 | params.supported_rates = | |
4259 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4260 | params.supported_rates_len = | |
4261 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4262 | params.listen_interval = | |
4263 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4264 | |
3d124ea2 | 4265 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4266 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4267 | else |
4268 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4269 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4270 | return -EINVAL; | |
51b50fbe | 4271 | |
9d62a986 JM |
4272 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4273 | params.capability = | |
4274 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4275 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4276 | } | |
4277 | ||
4278 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4279 | params.ext_capab = | |
4280 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4281 | params.ext_capab_len = | |
4282 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4283 | } | |
4284 | ||
36aedc90 JM |
4285 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4286 | params.ht_capa = | |
4287 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4288 | |
f461be3e MP |
4289 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4290 | params.vht_capa = | |
4291 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4292 | ||
60f4a7b1 MK |
4293 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4294 | params.opmode_notif_used = true; | |
4295 | params.opmode_notif = | |
4296 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4297 | } | |
4298 | ||
f8bacc21 | 4299 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4300 | params.plink_action = |
f8bacc21 JB |
4301 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4302 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4303 | return -EINVAL; | |
4304 | } | |
96b78dff | 4305 | |
c01fc9ad SD |
4306 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4307 | if (err) | |
4308 | return err; | |
4309 | ||
ff276691 JB |
4310 | err = nl80211_parse_sta_wme(info, ¶ms); |
4311 | if (err) | |
4312 | return err; | |
bdd90d5e | 4313 | |
bdd3ae3d | 4314 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4315 | return -EINVAL; |
4316 | ||
77ee7c89 JB |
4317 | /* When you run into this, adjust the code below for the new flag */ |
4318 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4319 | ||
bdd90d5e JB |
4320 | switch (dev->ieee80211_ptr->iftype) { |
4321 | case NL80211_IFTYPE_AP: | |
4322 | case NL80211_IFTYPE_AP_VLAN: | |
4323 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4324 | /* ignore WME attributes if iface/sta is not capable */ |
4325 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4326 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4327 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4328 | |
bdd90d5e | 4329 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4330 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4331 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4332 | return -EINVAL; |
bdd90d5e JB |
4333 | /* but don't bother the driver with it */ |
4334 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4335 | |
d582cffb JB |
4336 | /* allow authenticated/associated only if driver handles it */ |
4337 | if (!(rdev->wiphy.features & | |
4338 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4339 | params.sta_flags_mask & | |
4340 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4341 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4342 | return -EINVAL; | |
4343 | ||
bdd90d5e JB |
4344 | /* must be last in here for error handling */ |
4345 | params.vlan = get_vlan(info, rdev); | |
4346 | if (IS_ERR(params.vlan)) | |
4347 | return PTR_ERR(params.vlan); | |
4348 | break; | |
4349 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4350 | /* ignore uAPSD data */ |
4351 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4352 | ||
d582cffb JB |
4353 | /* associated is disallowed */ |
4354 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4355 | return -EINVAL; | |
bdd90d5e | 4356 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4357 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4358 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4359 | return -EINVAL; |
4360 | break; | |
4361 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4362 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4363 | /* ignore uAPSD data */ |
4364 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4365 | ||
77ee7c89 JB |
4366 | /* these are disallowed */ |
4367 | if (params.sta_flags_mask & | |
4368 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4369 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4370 | return -EINVAL; |
bdd90d5e JB |
4371 | /* Only TDLS peers can be added */ |
4372 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4373 | return -EINVAL; | |
4374 | /* Can only add if TDLS ... */ | |
4375 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4376 | return -EOPNOTSUPP; | |
4377 | /* ... with external setup is supported */ | |
4378 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4379 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4380 | /* |
4381 | * Older wpa_supplicant versions always mark the TDLS peer | |
4382 | * as authorized, but it shouldn't yet be. | |
4383 | */ | |
4384 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4385 | break; |
4386 | default: | |
4387 | return -EOPNOTSUPP; | |
c75786c9 EP |
4388 | } |
4389 | ||
bdd90d5e | 4390 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4391 | |
e35e4d28 | 4392 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4393 | |
5727ef1b JB |
4394 | if (params.vlan) |
4395 | dev_put(params.vlan); | |
5727ef1b JB |
4396 | return err; |
4397 | } | |
4398 | ||
4399 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4400 | { | |
4c476991 JB |
4401 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4402 | struct net_device *dev = info->user_ptr[1]; | |
89c771e5 JM |
4403 | struct station_del_parameters params; |
4404 | ||
4405 | memset(¶ms, 0, sizeof(params)); | |
5727ef1b JB |
4406 | |
4407 | if (info->attrs[NL80211_ATTR_MAC]) | |
89c771e5 | 4408 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5727ef1b | 4409 | |
e80cf853 | 4410 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4411 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4412 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4413 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4414 | return -EINVAL; | |
5727ef1b | 4415 | |
4c476991 JB |
4416 | if (!rdev->ops->del_station) |
4417 | return -EOPNOTSUPP; | |
3b85875a | 4418 | |
98856866 JM |
4419 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
4420 | params.subtype = | |
4421 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | |
4422 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | |
4423 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | |
4424 | return -EINVAL; | |
4425 | } else { | |
4426 | /* Default to Deauthentication frame */ | |
4427 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | |
4428 | } | |
4429 | ||
4430 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | |
4431 | params.reason_code = | |
4432 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
4433 | if (params.reason_code == 0) | |
4434 | return -EINVAL; /* 0 is reserved */ | |
4435 | } else { | |
4436 | /* Default to reason code 2 */ | |
4437 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | |
4438 | } | |
4439 | ||
89c771e5 | 4440 | return rdev_del_station(rdev, dev, ¶ms); |
5727ef1b JB |
4441 | } |
4442 | ||
15e47304 | 4443 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4444 | int flags, struct net_device *dev, |
4445 | u8 *dst, u8 *next_hop, | |
4446 | struct mpath_info *pinfo) | |
4447 | { | |
4448 | void *hdr; | |
4449 | struct nlattr *pinfoattr; | |
4450 | ||
15e47304 | 4451 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
2ec600d6 LCC |
4452 | if (!hdr) |
4453 | return -1; | |
4454 | ||
9360ffd1 DM |
4455 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4456 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4457 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4458 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4459 | goto nla_put_failure; | |
f5ea9120 | 4460 | |
2ec600d6 LCC |
4461 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4462 | if (!pinfoattr) | |
4463 | goto nla_put_failure; | |
9360ffd1 DM |
4464 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4465 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4466 | pinfo->frame_qlen)) | |
4467 | goto nla_put_failure; | |
4468 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4469 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4470 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4471 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4472 | pinfo->metric)) || | |
4473 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4474 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4475 | pinfo->exptime)) || | |
4476 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4477 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4478 | pinfo->flags)) || | |
4479 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4480 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4481 | pinfo->discovery_timeout)) || | |
4482 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4483 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4484 | pinfo->discovery_retries))) | |
4485 | goto nla_put_failure; | |
2ec600d6 LCC |
4486 | |
4487 | nla_nest_end(msg, pinfoattr); | |
4488 | ||
4489 | return genlmsg_end(msg, hdr); | |
4490 | ||
4491 | nla_put_failure: | |
bc3ed28c TG |
4492 | genlmsg_cancel(msg, hdr); |
4493 | return -EMSGSIZE; | |
2ec600d6 LCC |
4494 | } |
4495 | ||
4496 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4497 | struct netlink_callback *cb) |
2ec600d6 | 4498 | { |
2ec600d6 | 4499 | struct mpath_info pinfo; |
1b8ec87a | 4500 | struct cfg80211_registered_device *rdev; |
97990a06 | 4501 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4502 | u8 dst[ETH_ALEN]; |
4503 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4504 | int path_idx = cb->args[2]; |
2ec600d6 | 4505 | int err; |
2ec600d6 | 4506 | |
1b8ec87a | 4507 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
4508 | if (err) |
4509 | return err; | |
bba95fef | 4510 | |
1b8ec87a | 4511 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 4512 | err = -EOPNOTSUPP; |
bba95fef JB |
4513 | goto out_err; |
4514 | } | |
4515 | ||
97990a06 | 4516 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4517 | err = -EOPNOTSUPP; |
0448b5fc | 4518 | goto out_err; |
eec60b03 JM |
4519 | } |
4520 | ||
bba95fef | 4521 | while (1) { |
1b8ec87a | 4522 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 4523 | next_hop, &pinfo); |
bba95fef | 4524 | if (err == -ENOENT) |
2ec600d6 | 4525 | break; |
bba95fef | 4526 | if (err) |
3b85875a | 4527 | goto out_err; |
2ec600d6 | 4528 | |
15e47304 | 4529 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4530 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4531 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4532 | &pinfo) < 0) |
4533 | goto out; | |
2ec600d6 | 4534 | |
bba95fef | 4535 | path_idx++; |
2ec600d6 | 4536 | } |
2ec600d6 | 4537 | |
2ec600d6 | 4538 | |
bba95fef | 4539 | out: |
97990a06 | 4540 | cb->args[2] = path_idx; |
bba95fef | 4541 | err = skb->len; |
bba95fef | 4542 | out_err: |
1b8ec87a | 4543 | nl80211_finish_wdev_dump(rdev); |
bba95fef | 4544 | return err; |
2ec600d6 LCC |
4545 | } |
4546 | ||
4547 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4548 | { | |
4c476991 | 4549 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4550 | int err; |
4c476991 | 4551 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4552 | struct mpath_info pinfo; |
4553 | struct sk_buff *msg; | |
4554 | u8 *dst = NULL; | |
4555 | u8 next_hop[ETH_ALEN]; | |
4556 | ||
4557 | memset(&pinfo, 0, sizeof(pinfo)); | |
4558 | ||
4559 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4560 | return -EINVAL; | |
4561 | ||
4562 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4563 | ||
4c476991 JB |
4564 | if (!rdev->ops->get_mpath) |
4565 | return -EOPNOTSUPP; | |
2ec600d6 | 4566 | |
4c476991 JB |
4567 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4568 | return -EOPNOTSUPP; | |
eec60b03 | 4569 | |
e35e4d28 | 4570 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4571 | if (err) |
4c476991 | 4572 | return err; |
2ec600d6 | 4573 | |
fd2120ca | 4574 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4575 | if (!msg) |
4c476991 | 4576 | return -ENOMEM; |
2ec600d6 | 4577 | |
15e47304 | 4578 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4579 | dev, dst, next_hop, &pinfo) < 0) { |
4580 | nlmsg_free(msg); | |
4581 | return -ENOBUFS; | |
4582 | } | |
3b85875a | 4583 | |
4c476991 | 4584 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4585 | } |
4586 | ||
4587 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4588 | { | |
4c476991 JB |
4589 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4590 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4591 | u8 *dst = NULL; |
4592 | u8 *next_hop = NULL; | |
4593 | ||
4594 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4595 | return -EINVAL; | |
4596 | ||
4597 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4598 | return -EINVAL; | |
4599 | ||
4600 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4601 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4602 | ||
4c476991 JB |
4603 | if (!rdev->ops->change_mpath) |
4604 | return -EOPNOTSUPP; | |
35a8efe1 | 4605 | |
4c476991 JB |
4606 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4607 | return -EOPNOTSUPP; | |
2ec600d6 | 4608 | |
e35e4d28 | 4609 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4610 | } |
4c476991 | 4611 | |
2ec600d6 LCC |
4612 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4613 | { | |
4c476991 JB |
4614 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4615 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4616 | u8 *dst = NULL; |
4617 | u8 *next_hop = NULL; | |
4618 | ||
4619 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4620 | return -EINVAL; | |
4621 | ||
4622 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4623 | return -EINVAL; | |
4624 | ||
4625 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4626 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4627 | ||
4c476991 JB |
4628 | if (!rdev->ops->add_mpath) |
4629 | return -EOPNOTSUPP; | |
35a8efe1 | 4630 | |
4c476991 JB |
4631 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4632 | return -EOPNOTSUPP; | |
2ec600d6 | 4633 | |
e35e4d28 | 4634 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4635 | } |
4636 | ||
4637 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4638 | { | |
4c476991 JB |
4639 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4640 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4641 | u8 *dst = NULL; |
4642 | ||
4643 | if (info->attrs[NL80211_ATTR_MAC]) | |
4644 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4645 | ||
4c476991 JB |
4646 | if (!rdev->ops->del_mpath) |
4647 | return -EOPNOTSUPP; | |
3b85875a | 4648 | |
e35e4d28 | 4649 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4650 | } |
4651 | ||
66be7d2b HR |
4652 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
4653 | { | |
4654 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4655 | int err; | |
4656 | struct net_device *dev = info->user_ptr[1]; | |
4657 | struct mpath_info pinfo; | |
4658 | struct sk_buff *msg; | |
4659 | u8 *dst = NULL; | |
4660 | u8 mpp[ETH_ALEN]; | |
4661 | ||
4662 | memset(&pinfo, 0, sizeof(pinfo)); | |
4663 | ||
4664 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4665 | return -EINVAL; | |
4666 | ||
4667 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4668 | ||
4669 | if (!rdev->ops->get_mpp) | |
4670 | return -EOPNOTSUPP; | |
4671 | ||
4672 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
4673 | return -EOPNOTSUPP; | |
4674 | ||
4675 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | |
4676 | if (err) | |
4677 | return err; | |
4678 | ||
4679 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4680 | if (!msg) | |
4681 | return -ENOMEM; | |
4682 | ||
4683 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | |
4684 | dev, dst, mpp, &pinfo) < 0) { | |
4685 | nlmsg_free(msg); | |
4686 | return -ENOBUFS; | |
4687 | } | |
4688 | ||
4689 | return genlmsg_reply(msg, info); | |
4690 | } | |
4691 | ||
4692 | static int nl80211_dump_mpp(struct sk_buff *skb, | |
4693 | struct netlink_callback *cb) | |
4694 | { | |
4695 | struct mpath_info pinfo; | |
4696 | struct cfg80211_registered_device *rdev; | |
4697 | struct wireless_dev *wdev; | |
4698 | u8 dst[ETH_ALEN]; | |
4699 | u8 mpp[ETH_ALEN]; | |
4700 | int path_idx = cb->args[2]; | |
4701 | int err; | |
4702 | ||
4703 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | |
4704 | if (err) | |
4705 | return err; | |
4706 | ||
4707 | if (!rdev->ops->dump_mpp) { | |
4708 | err = -EOPNOTSUPP; | |
4709 | goto out_err; | |
4710 | } | |
4711 | ||
4712 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | |
4713 | err = -EOPNOTSUPP; | |
4714 | goto out_err; | |
4715 | } | |
4716 | ||
4717 | while (1) { | |
4718 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | |
4719 | mpp, &pinfo); | |
4720 | if (err == -ENOENT) | |
4721 | break; | |
4722 | if (err) | |
4723 | goto out_err; | |
4724 | ||
4725 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | |
4726 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
4727 | wdev->netdev, dst, mpp, | |
4728 | &pinfo) < 0) | |
4729 | goto out; | |
4730 | ||
4731 | path_idx++; | |
4732 | } | |
4733 | ||
4734 | out: | |
4735 | cb->args[2] = path_idx; | |
4736 | err = skb->len; | |
4737 | out_err: | |
4738 | nl80211_finish_wdev_dump(rdev); | |
4739 | return err; | |
4740 | } | |
4741 | ||
9f1ba906 JM |
4742 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4743 | { | |
4c476991 JB |
4744 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4745 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 4746 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 4747 | struct bss_parameters params; |
c56589ed | 4748 | int err; |
9f1ba906 JM |
4749 | |
4750 | memset(¶ms, 0, sizeof(params)); | |
4751 | /* default to not changing parameters */ | |
4752 | params.use_cts_prot = -1; | |
4753 | params.use_short_preamble = -1; | |
4754 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4755 | params.ap_isolate = -1; |
50b12f59 | 4756 | params.ht_opmode = -1; |
53cabad7 JB |
4757 | params.p2p_ctwindow = -1; |
4758 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4759 | |
4760 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4761 | params.use_cts_prot = | |
4762 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4763 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4764 | params.use_short_preamble = | |
4765 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4766 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4767 | params.use_short_slot_time = | |
4768 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4769 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4770 | params.basic_rates = | |
4771 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4772 | params.basic_rates_len = | |
4773 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4774 | } | |
fd8aaaf3 FF |
4775 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4776 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4777 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4778 | params.ht_opmode = | |
4779 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4780 | |
53cabad7 JB |
4781 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4782 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4783 | return -EINVAL; | |
4784 | params.p2p_ctwindow = | |
4785 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4786 | if (params.p2p_ctwindow < 0) | |
4787 | return -EINVAL; | |
4788 | if (params.p2p_ctwindow != 0 && | |
4789 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4790 | return -EINVAL; | |
4791 | } | |
4792 | ||
4793 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4794 | u8 tmp; | |
4795 | ||
4796 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4797 | return -EINVAL; | |
4798 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4799 | if (tmp > 1) | |
4800 | return -EINVAL; | |
4801 | params.p2p_opp_ps = tmp; | |
4802 | if (params.p2p_opp_ps && | |
4803 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4804 | return -EINVAL; | |
4805 | } | |
4806 | ||
4c476991 JB |
4807 | if (!rdev->ops->change_bss) |
4808 | return -EOPNOTSUPP; | |
9f1ba906 | 4809 | |
074ac8df | 4810 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4811 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4812 | return -EOPNOTSUPP; | |
3b85875a | 4813 | |
c56589ed SW |
4814 | wdev_lock(wdev); |
4815 | err = rdev_change_bss(rdev, dev, ¶ms); | |
4816 | wdev_unlock(wdev); | |
4817 | ||
4818 | return err; | |
9f1ba906 JM |
4819 | } |
4820 | ||
b54452b0 | 4821 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4822 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4823 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4824 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4825 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4826 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4827 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
089027e5 | 4828 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
b2e1b302 LR |
4829 | }; |
4830 | ||
4831 | static int parse_reg_rule(struct nlattr *tb[], | |
4832 | struct ieee80211_reg_rule *reg_rule) | |
4833 | { | |
4834 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4835 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4836 | ||
4837 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4838 | return -EINVAL; | |
4839 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4840 | return -EINVAL; | |
4841 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4842 | return -EINVAL; | |
b0dfd2ea JD |
4843 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
4844 | return -EINVAL; | |
b2e1b302 LR |
4845 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
4846 | return -EINVAL; | |
4847 | ||
4848 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4849 | ||
4850 | freq_range->start_freq_khz = | |
4851 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4852 | freq_range->end_freq_khz = | |
4853 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
b0dfd2ea JD |
4854 | freq_range->max_bandwidth_khz = |
4855 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
b2e1b302 LR |
4856 | |
4857 | power_rule->max_eirp = | |
4858 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4859 | ||
4860 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4861 | power_rule->max_antenna_gain = | |
4862 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4863 | ||
089027e5 JD |
4864 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
4865 | reg_rule->dfs_cac_ms = | |
4866 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
4867 | ||
b2e1b302 LR |
4868 | return 0; |
4869 | } | |
4870 | ||
4871 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4872 | { | |
b2e1b302 | 4873 | char *data = NULL; |
57b5ce07 | 4874 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4875 | |
80778f18 LR |
4876 | /* |
4877 | * You should only get this when cfg80211 hasn't yet initialized | |
4878 | * completely when built-in to the kernel right between the time | |
4879 | * window between nl80211_init() and regulatory_init(), if that is | |
4880 | * even possible. | |
4881 | */ | |
458f4f9e | 4882 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4883 | return -EINPROGRESS; |
80778f18 | 4884 | |
57b5ce07 LR |
4885 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4886 | user_reg_hint_type = | |
4887 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4888 | else | |
4889 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4890 | ||
4891 | switch (user_reg_hint_type) { | |
4892 | case NL80211_USER_REG_HINT_USER: | |
4893 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
4894 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4895 | return -EINVAL; | |
4896 | ||
4897 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4898 | return regulatory_hint_user(data, user_reg_hint_type); | |
4899 | case NL80211_USER_REG_HINT_INDOOR: | |
4900 | return regulatory_hint_indoor_user(); | |
57b5ce07 LR |
4901 | default: |
4902 | return -EINVAL; | |
4903 | } | |
b2e1b302 LR |
4904 | } |
4905 | ||
24bdd9f4 | 4906 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4907 | struct genl_info *info) |
93da9cc1 | 4908 | { |
4c476991 | 4909 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4910 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4911 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4912 | struct mesh_config cur_params; | |
4913 | int err = 0; | |
93da9cc1 | 4914 | void *hdr; |
4915 | struct nlattr *pinfoattr; | |
4916 | struct sk_buff *msg; | |
4917 | ||
29cbe68c JB |
4918 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4919 | return -EOPNOTSUPP; | |
4920 | ||
24bdd9f4 | 4921 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4922 | return -EOPNOTSUPP; |
f3f92586 | 4923 | |
29cbe68c JB |
4924 | wdev_lock(wdev); |
4925 | /* If not connected, get default parameters */ | |
4926 | if (!wdev->mesh_id_len) | |
4927 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4928 | else | |
e35e4d28 | 4929 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4930 | wdev_unlock(wdev); |
4931 | ||
93da9cc1 | 4932 | if (err) |
4c476991 | 4933 | return err; |
93da9cc1 | 4934 | |
4935 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4936 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4937 | if (!msg) |
4938 | return -ENOMEM; | |
15e47304 | 4939 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4940 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4941 | if (!hdr) |
efe1cf0c | 4942 | goto out; |
24bdd9f4 | 4943 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 4944 | if (!pinfoattr) |
4945 | goto nla_put_failure; | |
9360ffd1 DM |
4946 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4947 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
4948 | cur_params.dot11MeshRetryTimeout) || | |
4949 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
4950 | cur_params.dot11MeshConfirmTimeout) || | |
4951 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
4952 | cur_params.dot11MeshHoldingTimeout) || | |
4953 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
4954 | cur_params.dot11MeshMaxPeerLinks) || | |
4955 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
4956 | cur_params.dot11MeshMaxRetries) || | |
4957 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
4958 | cur_params.dot11MeshTTL) || | |
4959 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
4960 | cur_params.element_ttl) || | |
4961 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
4962 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
4963 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4964 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
4965 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4966 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
4967 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
4968 | cur_params.path_refresh_time) || | |
4969 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
4970 | cur_params.min_discovery_timeout) || | |
4971 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
4972 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
4973 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
4974 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
4975 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
4976 | cur_params.dot11MeshHWMPperrMinInterval) || | |
4977 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
4978 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
4979 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4980 | cur_params.dot11MeshHWMPRootMode) || | |
4981 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
4982 | cur_params.dot11MeshHWMPRannInterval) || | |
4983 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
4984 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
4985 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
4986 | cur_params.dot11MeshForwarding) || | |
4987 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
4988 | cur_params.rssi_threshold) || |
4989 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
4990 | cur_params.ht_opmode) || |
4991 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
4992 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
4993 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
4994 | cur_params.dot11MeshHWMProotInterval) || |
4995 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
4996 | cur_params.dot11MeshHWMPconfirmationInterval) || |
4997 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
4998 | cur_params.power_mode) || | |
4999 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
5000 | cur_params.dot11MeshAwakeWindowDuration) || |
5001 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5002 | cur_params.plink_timeout)) | |
9360ffd1 | 5003 | goto nla_put_failure; |
93da9cc1 | 5004 | nla_nest_end(msg, pinfoattr); |
5005 | genlmsg_end(msg, hdr); | |
4c476991 | 5006 | return genlmsg_reply(msg, info); |
93da9cc1 | 5007 | |
3b85875a | 5008 | nla_put_failure: |
93da9cc1 | 5009 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 5010 | out: |
d080e275 | 5011 | nlmsg_free(msg); |
4c476991 | 5012 | return -ENOBUFS; |
93da9cc1 | 5013 | } |
5014 | ||
b54452b0 | 5015 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 5016 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
5017 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
5018 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
5019 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
5020 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
5021 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 5022 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 5023 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 5024 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 5025 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
5026 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
5027 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
5028 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
5029 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 5030 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 5031 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 5032 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 5033 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 5034 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 5035 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
5036 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
5037 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
5038 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
5039 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 5040 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
5041 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
5042 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 5043 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 5044 | }; |
5045 | ||
c80d545d JC |
5046 | static const struct nla_policy |
5047 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 5048 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
5049 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
5050 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 5051 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 5052 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 5053 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 5054 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 5055 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 5056 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
5057 | }; |
5058 | ||
24bdd9f4 | 5059 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
5060 | struct mesh_config *cfg, |
5061 | u32 *mask_out) | |
93da9cc1 | 5062 | { |
93da9cc1 | 5063 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 5064 | u32 mask = 0; |
93da9cc1 | 5065 | |
ea54fba2 MP |
5066 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
5067 | do { \ | |
5068 | if (tb[attr]) { \ | |
5069 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
5070 | return -EINVAL; \ | |
5071 | cfg->param = fn(tb[attr]); \ | |
5072 | mask |= (1 << (attr - 1)); \ | |
5073 | } \ | |
5074 | } while (0) | |
bd90fdcc JB |
5075 | |
5076 | ||
24bdd9f4 | 5077 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 5078 | return -EINVAL; |
5079 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 5080 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 5081 | nl80211_meshconf_params_policy)) |
93da9cc1 | 5082 | return -EINVAL; |
5083 | ||
93da9cc1 | 5084 | /* This makes sure that there aren't more than 32 mesh config |
5085 | * parameters (otherwise our bitfield scheme would not work.) */ | |
5086 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
5087 | ||
5088 | /* Fill in the params struct */ | |
ea54fba2 | 5089 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
5090 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
5091 | nla_get_u16); | |
ea54fba2 | 5092 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
5093 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
5094 | nla_get_u16); | |
ea54fba2 | 5095 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
5096 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
5097 | nla_get_u16); | |
ea54fba2 | 5098 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
5099 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
5100 | nla_get_u16); | |
ea54fba2 | 5101 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
5102 | mask, NL80211_MESHCONF_MAX_RETRIES, |
5103 | nla_get_u8); | |
ea54fba2 | 5104 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 5105 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 5106 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
5107 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
5108 | nla_get_u8); | |
ea54fba2 | 5109 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
5110 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
5111 | nla_get_u8); | |
ea54fba2 MP |
5112 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
5113 | 1, 255, mask, | |
a4f606ea CYY |
5114 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5115 | nla_get_u32); | |
ea54fba2 | 5116 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
5117 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5118 | nla_get_u8); | |
ea54fba2 | 5119 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
5120 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
5121 | nla_get_u32); | |
ea54fba2 | 5122 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
5123 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
5124 | nla_get_u16); | |
ea54fba2 MP |
5125 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
5126 | 1, 65535, mask, | |
a4f606ea CYY |
5127 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
5128 | nla_get_u32); | |
93da9cc1 | 5129 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
5130 | 1, 65535, mask, |
5131 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 5132 | nla_get_u16); |
dca7e943 | 5133 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
5134 | 1, 65535, mask, |
5135 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 5136 | nla_get_u16); |
93da9cc1 | 5137 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5138 | dot11MeshHWMPnetDiameterTraversalTime, |
5139 | 1, 65535, mask, | |
a4f606ea CYY |
5140 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
5141 | nla_get_u16); | |
ea54fba2 MP |
5142 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
5143 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5144 | nla_get_u8); | |
5145 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
5146 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 5147 | nla_get_u16); |
63c5723b | 5148 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5149 | dot11MeshGateAnnouncementProtocol, 0, 1, |
5150 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 5151 | nla_get_u8); |
ea54fba2 | 5152 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
5153 | mask, NL80211_MESHCONF_FORWARDING, |
5154 | nla_get_u8); | |
83374fe9 | 5155 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 5156 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
83374fe9 | 5157 | nla_get_s32); |
ea54fba2 | 5158 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 5159 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
5160 | nla_get_u16); |
5161 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 5162 | 1, 65535, mask, |
ac1073a6 CYY |
5163 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
5164 | nla_get_u32); | |
ea54fba2 | 5165 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 5166 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
5167 | nla_get_u16); |
5168 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
5169 | dot11MeshHWMPconfirmationInterval, |
5170 | 1, 65535, mask, | |
728b19e5 | 5171 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 5172 | nla_get_u16); |
3b1c5a53 MP |
5173 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
5174 | NL80211_MESH_POWER_ACTIVE, | |
5175 | NL80211_MESH_POWER_MAX, | |
5176 | mask, NL80211_MESHCONF_POWER_MODE, | |
5177 | nla_get_u32); | |
5178 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
5179 | 0, 65535, mask, | |
5180 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
8e7c0538 CT |
5181 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
5182 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5183 | nla_get_u32); | |
bd90fdcc JB |
5184 | if (mask_out) |
5185 | *mask_out = mask; | |
c80d545d | 5186 | |
bd90fdcc JB |
5187 | return 0; |
5188 | ||
5189 | #undef FILL_IN_MESH_PARAM_IF_SET | |
5190 | } | |
5191 | ||
c80d545d JC |
5192 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
5193 | struct mesh_setup *setup) | |
5194 | { | |
bb2798d4 | 5195 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
5196 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
5197 | ||
5198 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
5199 | return -EINVAL; | |
5200 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
5201 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
5202 | nl80211_mesh_setup_params_policy)) | |
5203 | return -EINVAL; | |
5204 | ||
d299a1f2 JC |
5205 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
5206 | setup->sync_method = | |
5207 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
5208 | IEEE80211_SYNC_METHOD_VENDOR : | |
5209 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
5210 | ||
c80d545d JC |
5211 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
5212 | setup->path_sel_proto = | |
5213 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5214 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5215 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5216 | ||
5217 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5218 | setup->path_metric = | |
5219 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5220 | IEEE80211_PATH_METRIC_VENDOR : | |
5221 | IEEE80211_PATH_METRIC_AIRTIME; | |
5222 | ||
581a8b0f JC |
5223 | |
5224 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 5225 | struct nlattr *ieattr = |
581a8b0f | 5226 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5227 | if (!is_valid_ie_attr(ieattr)) |
5228 | return -EINVAL; | |
581a8b0f JC |
5229 | setup->ie = nla_data(ieattr); |
5230 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5231 | } |
bb2798d4 TP |
5232 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5233 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5234 | return -EINVAL; | |
5235 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5236 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5237 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5238 | if (setup->is_secure) |
5239 | setup->user_mpm = true; | |
c80d545d | 5240 | |
6e16d90b CT |
5241 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5242 | if (!setup->user_mpm) | |
5243 | return -EINVAL; | |
5244 | setup->auth_id = | |
5245 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5246 | } | |
5247 | ||
c80d545d JC |
5248 | return 0; |
5249 | } | |
5250 | ||
24bdd9f4 | 5251 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5252 | struct genl_info *info) |
bd90fdcc JB |
5253 | { |
5254 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5255 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5256 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5257 | struct mesh_config cfg; |
5258 | u32 mask; | |
5259 | int err; | |
5260 | ||
29cbe68c JB |
5261 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5262 | return -EOPNOTSUPP; | |
5263 | ||
24bdd9f4 | 5264 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5265 | return -EOPNOTSUPP; |
5266 | ||
24bdd9f4 | 5267 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5268 | if (err) |
5269 | return err; | |
5270 | ||
29cbe68c JB |
5271 | wdev_lock(wdev); |
5272 | if (!wdev->mesh_id_len) | |
5273 | err = -ENOLINK; | |
5274 | ||
5275 | if (!err) | |
e35e4d28 | 5276 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5277 | |
5278 | wdev_unlock(wdev); | |
5279 | ||
5280 | return err; | |
93da9cc1 | 5281 | } |
5282 | ||
f130347c LR |
5283 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
5284 | { | |
458f4f9e | 5285 | const struct ieee80211_regdomain *regdom; |
f130347c LR |
5286 | struct sk_buff *msg; |
5287 | void *hdr = NULL; | |
5288 | struct nlattr *nl_reg_rules; | |
5289 | unsigned int i; | |
f130347c LR |
5290 | |
5291 | if (!cfg80211_regdomain) | |
5fe231e8 | 5292 | return -EINVAL; |
f130347c | 5293 | |
fd2120ca | 5294 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
5fe231e8 JB |
5295 | if (!msg) |
5296 | return -ENOBUFS; | |
f130347c | 5297 | |
15e47304 | 5298 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
f130347c LR |
5299 | NL80211_CMD_GET_REG); |
5300 | if (!hdr) | |
efe1cf0c | 5301 | goto put_failure; |
f130347c | 5302 | |
57b5ce07 LR |
5303 | if (reg_last_request_cell_base() && |
5304 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5305 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5306 | goto nla_put_failure; | |
5307 | ||
458f4f9e JB |
5308 | rcu_read_lock(); |
5309 | regdom = rcu_dereference(cfg80211_regdomain); | |
5310 | ||
5311 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | |
5312 | (regdom->dfs_region && | |
5313 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
5314 | goto nla_put_failure_rcu; | |
5315 | ||
f130347c LR |
5316 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5317 | if (!nl_reg_rules) | |
458f4f9e | 5318 | goto nla_put_failure_rcu; |
f130347c | 5319 | |
458f4f9e | 5320 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5321 | struct nlattr *nl_reg_rule; |
5322 | const struct ieee80211_reg_rule *reg_rule; | |
5323 | const struct ieee80211_freq_range *freq_range; | |
5324 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 5325 | unsigned int max_bandwidth_khz; |
f130347c | 5326 | |
458f4f9e | 5327 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5328 | freq_range = ®_rule->freq_range; |
5329 | power_rule = ®_rule->power_rule; | |
5330 | ||
5331 | nl_reg_rule = nla_nest_start(msg, i); | |
5332 | if (!nl_reg_rule) | |
458f4f9e | 5333 | goto nla_put_failure_rcu; |
f130347c | 5334 | |
97524820 JD |
5335 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
5336 | if (!max_bandwidth_khz) | |
5337 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
5338 | reg_rule); | |
5339 | ||
9360ffd1 DM |
5340 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5341 | reg_rule->flags) || | |
5342 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5343 | freq_range->start_freq_khz) || | |
5344 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5345 | freq_range->end_freq_khz) || | |
5346 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 5347 | max_bandwidth_khz) || |
9360ffd1 DM |
5348 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
5349 | power_rule->max_antenna_gain) || | |
5350 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
5351 | power_rule->max_eirp) || |
5352 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
5353 | reg_rule->dfs_cac_ms)) | |
458f4f9e | 5354 | goto nla_put_failure_rcu; |
f130347c LR |
5355 | |
5356 | nla_nest_end(msg, nl_reg_rule); | |
5357 | } | |
458f4f9e | 5358 | rcu_read_unlock(); |
f130347c LR |
5359 | |
5360 | nla_nest_end(msg, nl_reg_rules); | |
5361 | ||
5362 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5363 | return genlmsg_reply(msg, info); |
f130347c | 5364 | |
458f4f9e JB |
5365 | nla_put_failure_rcu: |
5366 | rcu_read_unlock(); | |
f130347c LR |
5367 | nla_put_failure: |
5368 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5369 | put_failure: |
d080e275 | 5370 | nlmsg_free(msg); |
5fe231e8 | 5371 | return -EMSGSIZE; |
f130347c LR |
5372 | } |
5373 | ||
b2e1b302 LR |
5374 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5375 | { | |
5376 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5377 | struct nlattr *nl_reg_rule; | |
5378 | char *alpha2 = NULL; | |
5379 | int rem_reg_rules = 0, r = 0; | |
5380 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
4c7d3982 | 5381 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
b2e1b302 LR |
5382 | struct ieee80211_regdomain *rd = NULL; |
5383 | ||
5384 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5385 | return -EINVAL; | |
5386 | ||
5387 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5388 | return -EINVAL; | |
5389 | ||
5390 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5391 | ||
8b60b078 LR |
5392 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5393 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5394 | ||
b2e1b302 | 5395 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5396 | rem_reg_rules) { |
b2e1b302 LR |
5397 | num_rules++; |
5398 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5399 | return -EINVAL; |
b2e1b302 LR |
5400 | } |
5401 | ||
e438768f LR |
5402 | if (!reg_is_valid_request(alpha2)) |
5403 | return -EINVAL; | |
5404 | ||
b2e1b302 | 5405 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5406 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5407 | |
5408 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5409 | if (!rd) |
5410 | return -ENOMEM; | |
b2e1b302 LR |
5411 | |
5412 | rd->n_reg_rules = num_rules; | |
5413 | rd->alpha2[0] = alpha2[0]; | |
5414 | rd->alpha2[1] = alpha2[1]; | |
5415 | ||
8b60b078 LR |
5416 | /* |
5417 | * Disable DFS master mode if the DFS region was | |
5418 | * not supported or known on this kernel. | |
5419 | */ | |
5420 | if (reg_supported_dfs_region(dfs_region)) | |
5421 | rd->dfs_region = dfs_region; | |
5422 | ||
b2e1b302 | 5423 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5424 | rem_reg_rules) { |
ae811e21 JB |
5425 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
5426 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
5427 | reg_rule_policy); | |
5428 | if (r) | |
5429 | goto bad_reg; | |
b2e1b302 LR |
5430 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5431 | if (r) | |
5432 | goto bad_reg; | |
5433 | ||
5434 | rule_idx++; | |
5435 | ||
d0e18f83 LR |
5436 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5437 | r = -EINVAL; | |
b2e1b302 | 5438 | goto bad_reg; |
d0e18f83 | 5439 | } |
b2e1b302 LR |
5440 | } |
5441 | ||
b2e1b302 | 5442 | r = set_regdom(rd); |
6913b49a | 5443 | /* set_regdom took ownership */ |
1a919318 | 5444 | rd = NULL; |
b2e1b302 | 5445 | |
d2372b31 | 5446 | bad_reg: |
b2e1b302 | 5447 | kfree(rd); |
d0e18f83 | 5448 | return r; |
b2e1b302 LR |
5449 | } |
5450 | ||
83f5e2cf JB |
5451 | static int validate_scan_freqs(struct nlattr *freqs) |
5452 | { | |
5453 | struct nlattr *attr1, *attr2; | |
5454 | int n_channels = 0, tmp1, tmp2; | |
5455 | ||
5456 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5457 | n_channels++; | |
5458 | /* | |
5459 | * Some hardware has a limited channel list for | |
5460 | * scanning, and it is pretty much nonsensical | |
5461 | * to scan for a channel twice, so disallow that | |
5462 | * and don't require drivers to check that the | |
5463 | * channel list they get isn't longer than what | |
5464 | * they can scan, as long as they can scan all | |
5465 | * the channels they registered at once. | |
5466 | */ | |
5467 | nla_for_each_nested(attr2, freqs, tmp2) | |
5468 | if (attr1 != attr2 && | |
5469 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5470 | return 0; | |
5471 | } | |
5472 | ||
5473 | return n_channels; | |
5474 | } | |
5475 | ||
2a519311 JB |
5476 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5477 | { | |
4c476991 | 5478 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5479 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5480 | struct cfg80211_scan_request *request; |
2a519311 JB |
5481 | struct nlattr *attr; |
5482 | struct wiphy *wiphy; | |
83f5e2cf | 5483 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5484 | size_t ie_len; |
2a519311 | 5485 | |
f4a11bb0 JB |
5486 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5487 | return -EINVAL; | |
5488 | ||
79c97e97 | 5489 | wiphy = &rdev->wiphy; |
2a519311 | 5490 | |
4c476991 JB |
5491 | if (!rdev->ops->scan) |
5492 | return -EOPNOTSUPP; | |
2a519311 | 5493 | |
f9d15d16 | 5494 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
5495 | err = -EBUSY; |
5496 | goto unlock; | |
5497 | } | |
2a519311 JB |
5498 | |
5499 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5500 | n_channels = validate_scan_freqs( |
5501 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5502 | if (!n_channels) { |
5503 | err = -EINVAL; | |
5504 | goto unlock; | |
5505 | } | |
2a519311 | 5506 | } else { |
bdfbec2d | 5507 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
5508 | } |
5509 | ||
5510 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5511 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5512 | n_ssids++; | |
5513 | ||
f9f47529 JB |
5514 | if (n_ssids > wiphy->max_scan_ssids) { |
5515 | err = -EINVAL; | |
5516 | goto unlock; | |
5517 | } | |
2a519311 | 5518 | |
70692ad2 JM |
5519 | if (info->attrs[NL80211_ATTR_IE]) |
5520 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5521 | else | |
5522 | ie_len = 0; | |
5523 | ||
f9f47529 JB |
5524 | if (ie_len > wiphy->max_scan_ie_len) { |
5525 | err = -EINVAL; | |
5526 | goto unlock; | |
5527 | } | |
18a83659 | 5528 | |
2a519311 | 5529 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5530 | + sizeof(*request->ssids) * n_ssids |
5531 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5532 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5533 | if (!request) { |
5534 | err = -ENOMEM; | |
5535 | goto unlock; | |
5536 | } | |
2a519311 | 5537 | |
2a519311 | 5538 | if (n_ssids) |
5ba63533 | 5539 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5540 | request->n_ssids = n_ssids; |
70692ad2 JM |
5541 | if (ie_len) { |
5542 | if (request->ssids) | |
5543 | request->ie = (void *)(request->ssids + n_ssids); | |
5544 | else | |
5545 | request->ie = (void *)(request->channels + n_channels); | |
5546 | } | |
2a519311 | 5547 | |
584991dc | 5548 | i = 0; |
2a519311 JB |
5549 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5550 | /* user specified, bail out if channel not found */ | |
2a519311 | 5551 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5552 | struct ieee80211_channel *chan; |
5553 | ||
5554 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5555 | ||
5556 | if (!chan) { | |
2a519311 JB |
5557 | err = -EINVAL; |
5558 | goto out_free; | |
5559 | } | |
584991dc JB |
5560 | |
5561 | /* ignore disabled channels */ | |
5562 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5563 | continue; | |
5564 | ||
5565 | request->channels[i] = chan; | |
2a519311 JB |
5566 | i++; |
5567 | } | |
5568 | } else { | |
34850ab2 JB |
5569 | enum ieee80211_band band; |
5570 | ||
2a519311 | 5571 | /* all channels */ |
2a519311 JB |
5572 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5573 | int j; | |
5574 | if (!wiphy->bands[band]) | |
5575 | continue; | |
5576 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5577 | struct ieee80211_channel *chan; |
5578 | ||
5579 | chan = &wiphy->bands[band]->channels[j]; | |
5580 | ||
5581 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5582 | continue; | |
5583 | ||
5584 | request->channels[i] = chan; | |
2a519311 JB |
5585 | i++; |
5586 | } | |
5587 | } | |
5588 | } | |
5589 | ||
584991dc JB |
5590 | if (!i) { |
5591 | err = -EINVAL; | |
5592 | goto out_free; | |
5593 | } | |
5594 | ||
5595 | request->n_channels = i; | |
5596 | ||
2a519311 JB |
5597 | i = 0; |
5598 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5599 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5600 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5601 | err = -EINVAL; |
5602 | goto out_free; | |
5603 | } | |
57a27e1d | 5604 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5605 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5606 | i++; |
5607 | } | |
5608 | } | |
5609 | ||
70692ad2 JM |
5610 | if (info->attrs[NL80211_ATTR_IE]) { |
5611 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5612 | memcpy((void *)request->ie, |
5613 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5614 | request->ie_len); |
5615 | } | |
5616 | ||
34850ab2 | 5617 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5618 | if (wiphy->bands[i]) |
5619 | request->rates[i] = | |
5620 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5621 | |
5622 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5623 | nla_for_each_nested(attr, | |
5624 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5625 | tmp) { | |
5626 | enum ieee80211_band band = nla_type(attr); | |
5627 | ||
84404623 | 5628 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5629 | err = -EINVAL; |
5630 | goto out_free; | |
5631 | } | |
1b09cd82 FF |
5632 | |
5633 | if (!wiphy->bands[band]) | |
5634 | continue; | |
5635 | ||
34850ab2 JB |
5636 | err = ieee80211_get_ratemask(wiphy->bands[band], |
5637 | nla_data(attr), | |
5638 | nla_len(attr), | |
5639 | &request->rates[band]); | |
5640 | if (err) | |
5641 | goto out_free; | |
5642 | } | |
5643 | } | |
5644 | ||
46856bbf | 5645 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5646 | request->flags = nla_get_u32( |
5647 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5648 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5649 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5650 | err = -EOPNOTSUPP; |
5651 | goto out_free; | |
5652 | } | |
5653 | } | |
ed473771 | 5654 | |
e9f935e3 RM |
5655 | request->no_cck = |
5656 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5657 | ||
fd014284 | 5658 | request->wdev = wdev; |
79c97e97 | 5659 | request->wiphy = &rdev->wiphy; |
15d6030b | 5660 | request->scan_start = jiffies; |
2a519311 | 5661 | |
79c97e97 | 5662 | rdev->scan_req = request; |
e35e4d28 | 5663 | err = rdev_scan(rdev, request); |
2a519311 | 5664 | |
463d0183 | 5665 | if (!err) { |
fd014284 JB |
5666 | nl80211_send_scan_start(rdev, wdev); |
5667 | if (wdev->netdev) | |
5668 | dev_hold(wdev->netdev); | |
4c476991 | 5669 | } else { |
2a519311 | 5670 | out_free: |
79c97e97 | 5671 | rdev->scan_req = NULL; |
2a519311 JB |
5672 | kfree(request); |
5673 | } | |
3b85875a | 5674 | |
f9f47529 | 5675 | unlock: |
2a519311 JB |
5676 | return err; |
5677 | } | |
5678 | ||
807f8a8c LC |
5679 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
5680 | struct genl_info *info) | |
5681 | { | |
5682 | struct cfg80211_sched_scan_request *request; | |
5683 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5684 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
5685 | struct nlattr *attr; |
5686 | struct wiphy *wiphy; | |
a1f1c21c | 5687 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5688 | u32 interval; |
807f8a8c LC |
5689 | enum ieee80211_band band; |
5690 | size_t ie_len; | |
a1f1c21c | 5691 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 5692 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c LC |
5693 | |
5694 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5695 | !rdev->ops->sched_scan_start) | |
5696 | return -EOPNOTSUPP; | |
5697 | ||
5698 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
5699 | return -EINVAL; | |
5700 | ||
bbe6ad6d LC |
5701 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5702 | return -EINVAL; | |
5703 | ||
5704 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
5705 | if (interval == 0) | |
5706 | return -EINVAL; | |
5707 | ||
807f8a8c LC |
5708 | wiphy = &rdev->wiphy; |
5709 | ||
5710 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5711 | n_channels = validate_scan_freqs( | |
5712 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
5713 | if (!n_channels) | |
5714 | return -EINVAL; | |
5715 | } else { | |
bdfbec2d | 5716 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
5717 | } |
5718 | ||
5719 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5720 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5721 | tmp) | |
5722 | n_ssids++; | |
5723 | ||
93b6aa69 | 5724 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
5725 | return -EINVAL; |
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 | */ | |
5736 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
a1f1c21c LC |
5737 | nla_for_each_nested(attr, |
5738 | info->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) | |
5746 | return err; | |
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) | |
5763 | return -EINVAL; | |
5764 | ||
807f8a8c LC |
5765 | if (info->attrs[NL80211_ATTR_IE]) |
5766 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5767 | else | |
5768 | ie_len = 0; | |
5769 | ||
5a865bad | 5770 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
5771 | return -EINVAL; |
5772 | ||
c10841ca LC |
5773 | if (rdev->sched_scan_req) { |
5774 | err = -EINPROGRESS; | |
5775 | goto out; | |
5776 | } | |
5777 | ||
807f8a8c | 5778 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 5779 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 5780 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 5781 | + sizeof(*request->channels) * n_channels |
807f8a8c | 5782 | + ie_len, GFP_KERNEL); |
c10841ca LC |
5783 | if (!request) { |
5784 | err = -ENOMEM; | |
5785 | goto out; | |
5786 | } | |
807f8a8c LC |
5787 | |
5788 | if (n_ssids) | |
5789 | request->ssids = (void *)&request->channels[n_channels]; | |
5790 | request->n_ssids = n_ssids; | |
5791 | if (ie_len) { | |
5792 | if (request->ssids) | |
5793 | request->ie = (void *)(request->ssids + n_ssids); | |
5794 | else | |
5795 | request->ie = (void *)(request->channels + n_channels); | |
5796 | } | |
5797 | ||
a1f1c21c LC |
5798 | if (n_match_sets) { |
5799 | if (request->ie) | |
5800 | request->match_sets = (void *)(request->ie + ie_len); | |
5801 | else if (request->ssids) | |
5802 | request->match_sets = | |
5803 | (void *)(request->ssids + n_ssids); | |
5804 | else | |
5805 | request->match_sets = | |
5806 | (void *)(request->channels + n_channels); | |
5807 | } | |
5808 | request->n_match_sets = n_match_sets; | |
5809 | ||
807f8a8c LC |
5810 | i = 0; |
5811 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5812 | /* user specified, bail out if channel not found */ | |
5813 | nla_for_each_nested(attr, | |
5814 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
5815 | tmp) { | |
5816 | struct ieee80211_channel *chan; | |
5817 | ||
5818 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5819 | ||
5820 | if (!chan) { | |
5821 | err = -EINVAL; | |
5822 | goto out_free; | |
5823 | } | |
5824 | ||
5825 | /* ignore disabled channels */ | |
5826 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5827 | continue; | |
5828 | ||
5829 | request->channels[i] = chan; | |
5830 | i++; | |
5831 | } | |
5832 | } else { | |
5833 | /* all channels */ | |
5834 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5835 | int j; | |
5836 | if (!wiphy->bands[band]) | |
5837 | continue; | |
5838 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
5839 | struct ieee80211_channel *chan; | |
5840 | ||
5841 | chan = &wiphy->bands[band]->channels[j]; | |
5842 | ||
5843 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5844 | continue; | |
5845 | ||
5846 | request->channels[i] = chan; | |
5847 | i++; | |
5848 | } | |
5849 | } | |
5850 | } | |
5851 | ||
5852 | if (!i) { | |
5853 | err = -EINVAL; | |
5854 | goto out_free; | |
5855 | } | |
5856 | ||
5857 | request->n_channels = i; | |
5858 | ||
5859 | i = 0; | |
5860 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5861 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5862 | tmp) { | |
57a27e1d | 5863 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
5864 | err = -EINVAL; |
5865 | goto out_free; | |
5866 | } | |
57a27e1d | 5867 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
5868 | memcpy(request->ssids[i].ssid, nla_data(attr), |
5869 | nla_len(attr)); | |
807f8a8c LC |
5870 | i++; |
5871 | } | |
5872 | } | |
5873 | ||
a1f1c21c LC |
5874 | i = 0; |
5875 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
5876 | nla_for_each_nested(attr, | |
5877 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5878 | tmp) { | |
88e920b4 | 5879 | struct nlattr *ssid, *rssi; |
a1f1c21c | 5880 | |
ae811e21 JB |
5881 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
5882 | nla_data(attr), nla_len(attr), | |
5883 | nl80211_match_policy); | |
5884 | if (err) | |
5885 | goto out_free; | |
4a4ab0d7 | 5886 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 5887 | if (ssid) { |
ea73cbce JB |
5888 | if (WARN_ON(i >= n_match_sets)) { |
5889 | /* this indicates a programming error, | |
5890 | * the loop above should have verified | |
5891 | * things properly | |
5892 | */ | |
5893 | err = -EINVAL; | |
5894 | goto out_free; | |
5895 | } | |
5896 | ||
a1f1c21c LC |
5897 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
5898 | err = -EINVAL; | |
5899 | goto out_free; | |
5900 | } | |
5901 | memcpy(request->match_sets[i].ssid.ssid, | |
5902 | nla_data(ssid), nla_len(ssid)); | |
5903 | request->match_sets[i].ssid.ssid_len = | |
5904 | nla_len(ssid); | |
ea73cbce JB |
5905 | /* special attribute - old implemenation w/a */ |
5906 | request->match_sets[i].rssi_thold = | |
5907 | default_match_rssi; | |
5908 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
5909 | if (rssi) | |
5910 | request->match_sets[i].rssi_thold = | |
5911 | nla_get_s32(rssi); | |
a1f1c21c LC |
5912 | } |
5913 | i++; | |
5914 | } | |
ea73cbce JB |
5915 | |
5916 | /* there was no other matchset, so the RSSI one is alone */ | |
5917 | if (i == 0) | |
5918 | request->match_sets[0].rssi_thold = default_match_rssi; | |
5919 | ||
5920 | request->min_rssi_thold = INT_MAX; | |
5921 | for (i = 0; i < n_match_sets; i++) | |
5922 | request->min_rssi_thold = | |
5923 | min(request->match_sets[i].rssi_thold, | |
5924 | request->min_rssi_thold); | |
5925 | } else { | |
5926 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
5927 | } |
5928 | ||
9900e484 JB |
5929 | if (ie_len) { |
5930 | request->ie_len = ie_len; | |
807f8a8c LC |
5931 | memcpy((void *)request->ie, |
5932 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5933 | request->ie_len); | |
5934 | } | |
5935 | ||
46856bbf | 5936 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5937 | request->flags = nla_get_u32( |
5938 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5939 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5940 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5941 | err = -EOPNOTSUPP; |
5942 | goto out_free; | |
5943 | } | |
5944 | } | |
ed473771 | 5945 | |
807f8a8c LC |
5946 | request->dev = dev; |
5947 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 5948 | request->interval = interval; |
15d6030b | 5949 | request->scan_start = jiffies; |
807f8a8c | 5950 | |
e35e4d28 | 5951 | err = rdev_sched_scan_start(rdev, dev, request); |
807f8a8c LC |
5952 | if (!err) { |
5953 | rdev->sched_scan_req = request; | |
5954 | nl80211_send_sched_scan(rdev, dev, | |
5955 | NL80211_CMD_START_SCHED_SCAN); | |
5956 | goto out; | |
5957 | } | |
5958 | ||
5959 | out_free: | |
5960 | kfree(request); | |
5961 | out: | |
5962 | return err; | |
5963 | } | |
5964 | ||
5965 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
5966 | struct genl_info *info) | |
5967 | { | |
5968 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5969 | ||
5970 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5971 | !rdev->ops->sched_scan_stop) | |
5972 | return -EOPNOTSUPP; | |
5973 | ||
5fe231e8 | 5974 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
5975 | } |
5976 | ||
04f39047 SW |
5977 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
5978 | struct genl_info *info) | |
5979 | { | |
5980 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5981 | struct net_device *dev = info->user_ptr[1]; | |
5982 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5983 | struct cfg80211_chan_def chandef; | |
55f7435c | 5984 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 5985 | unsigned int cac_time_ms; |
04f39047 SW |
5986 | int err; |
5987 | ||
55f7435c LR |
5988 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
5989 | if (dfs_region == NL80211_DFS_UNSET) | |
5990 | return -EINVAL; | |
5991 | ||
04f39047 SW |
5992 | err = nl80211_parse_chandef(rdev, info, &chandef); |
5993 | if (err) | |
5994 | return err; | |
5995 | ||
ff311bc1 SW |
5996 | if (netif_carrier_ok(dev)) |
5997 | return -EBUSY; | |
5998 | ||
04f39047 SW |
5999 | if (wdev->cac_started) |
6000 | return -EBUSY; | |
6001 | ||
2beb6dab | 6002 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
00ec75fc | 6003 | wdev->iftype); |
04f39047 SW |
6004 | if (err < 0) |
6005 | return err; | |
6006 | ||
6007 | if (err == 0) | |
6008 | return -EINVAL; | |
6009 | ||
fe7c3a1f | 6010 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
6011 | return -EINVAL; |
6012 | ||
6013 | if (!rdev->ops->start_radar_detection) | |
6014 | return -EOPNOTSUPP; | |
6015 | ||
31559f35 JD |
6016 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
6017 | if (WARN_ON(!cac_time_ms)) | |
6018 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
6019 | ||
6020 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, | |
6021 | cac_time_ms); | |
04f39047 | 6022 | if (!err) { |
9e0e2961 | 6023 | wdev->chandef = chandef; |
04f39047 SW |
6024 | wdev->cac_started = true; |
6025 | wdev->cac_start_time = jiffies; | |
31559f35 | 6026 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 6027 | } |
04f39047 SW |
6028 | return err; |
6029 | } | |
6030 | ||
16ef1fe2 SW |
6031 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
6032 | { | |
6033 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6034 | struct net_device *dev = info->user_ptr[1]; | |
6035 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6036 | struct cfg80211_csa_settings params; | |
6037 | /* csa_attrs is defined static to avoid waste of stack size - this | |
6038 | * function is called under RTNL lock, so this should not be a problem. | |
6039 | */ | |
6040 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
16ef1fe2 | 6041 | int err; |
ee4bc9e7 | 6042 | bool need_new_beacon = false; |
9a774c78 | 6043 | int len, i; |
252e07ca | 6044 | u32 cs_count; |
16ef1fe2 SW |
6045 | |
6046 | if (!rdev->ops->channel_switch || | |
6047 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
6048 | return -EOPNOTSUPP; | |
6049 | ||
ee4bc9e7 SW |
6050 | switch (dev->ieee80211_ptr->iftype) { |
6051 | case NL80211_IFTYPE_AP: | |
6052 | case NL80211_IFTYPE_P2P_GO: | |
6053 | need_new_beacon = true; | |
6054 | ||
6055 | /* useless if AP is not running */ | |
6056 | if (!wdev->beacon_interval) | |
1ff79dfa | 6057 | return -ENOTCONN; |
ee4bc9e7 SW |
6058 | break; |
6059 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
6060 | if (!wdev->ssid_len) |
6061 | return -ENOTCONN; | |
6062 | break; | |
c6da674a | 6063 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
6064 | if (!wdev->mesh_id_len) |
6065 | return -ENOTCONN; | |
ee4bc9e7 SW |
6066 | break; |
6067 | default: | |
16ef1fe2 | 6068 | return -EOPNOTSUPP; |
ee4bc9e7 | 6069 | } |
16ef1fe2 SW |
6070 | |
6071 | memset(¶ms, 0, sizeof(params)); | |
6072 | ||
6073 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6074 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
6075 | return -EINVAL; | |
6076 | ||
6077 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 6078 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
6079 | return -EINVAL; |
6080 | ||
252e07ca LC |
6081 | /* Even though the attribute is u32, the specification says |
6082 | * u8, so let's make sure we don't overflow. | |
6083 | */ | |
6084 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
6085 | if (cs_count > 255) | |
6086 | return -EINVAL; | |
6087 | ||
6088 | params.count = cs_count; | |
16ef1fe2 | 6089 | |
ee4bc9e7 SW |
6090 | if (!need_new_beacon) |
6091 | goto skip_beacons; | |
6092 | ||
16ef1fe2 SW |
6093 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
6094 | if (err) | |
6095 | return err; | |
6096 | ||
6097 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
6098 | info->attrs[NL80211_ATTR_CSA_IES], | |
6099 | nl80211_policy); | |
6100 | if (err) | |
6101 | return err; | |
6102 | ||
6103 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
6104 | if (err) | |
6105 | return err; | |
6106 | ||
6107 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
6108 | return -EINVAL; | |
6109 | ||
9a774c78 AO |
6110 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
6111 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6112 | return -EINVAL; |
6113 | ||
9a774c78 AO |
6114 | params.n_counter_offsets_beacon = len / sizeof(u16); |
6115 | if (rdev->wiphy.max_num_csa_counters && | |
6116 | (params.n_counter_offsets_beacon > | |
6117 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
6118 | return -EINVAL; |
6119 | ||
9a774c78 AO |
6120 | params.counter_offsets_beacon = |
6121 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
6122 | ||
6123 | /* sanity checks - counters should fit and be the same */ | |
6124 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
6125 | u16 offset = params.counter_offsets_beacon[i]; | |
6126 | ||
6127 | if (offset >= params.beacon_csa.tail_len) | |
6128 | return -EINVAL; | |
6129 | ||
6130 | if (params.beacon_csa.tail[offset] != params.count) | |
6131 | return -EINVAL; | |
6132 | } | |
6133 | ||
16ef1fe2 | 6134 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
6135 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
6136 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6137 | return -EINVAL; |
6138 | ||
9a774c78 AO |
6139 | params.n_counter_offsets_presp = len / sizeof(u16); |
6140 | if (rdev->wiphy.max_num_csa_counters && | |
6141 | (params.n_counter_offsets_beacon > | |
6142 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 | 6143 | return -EINVAL; |
9a774c78 AO |
6144 | |
6145 | params.counter_offsets_presp = | |
6146 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
6147 | ||
6148 | /* sanity checks - counters should fit and be the same */ | |
6149 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
6150 | u16 offset = params.counter_offsets_presp[i]; | |
6151 | ||
6152 | if (offset >= params.beacon_csa.probe_resp_len) | |
6153 | return -EINVAL; | |
6154 | ||
6155 | if (params.beacon_csa.probe_resp[offset] != | |
6156 | params.count) | |
6157 | return -EINVAL; | |
6158 | } | |
16ef1fe2 SW |
6159 | } |
6160 | ||
ee4bc9e7 | 6161 | skip_beacons: |
16ef1fe2 SW |
6162 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
6163 | if (err) | |
6164 | return err; | |
6165 | ||
174e0cd2 IP |
6166 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
6167 | wdev->iftype)) | |
16ef1fe2 SW |
6168 | return -EINVAL; |
6169 | ||
2beb6dab LC |
6170 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
6171 | ¶ms.chandef, | |
6172 | wdev->iftype); | |
6173 | if (err < 0) | |
6174 | return err; | |
6175 | ||
dcc6c2f5 | 6176 | if (err > 0) |
2beb6dab | 6177 | params.radar_required = true; |
16ef1fe2 | 6178 | |
16ef1fe2 SW |
6179 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
6180 | params.block_tx = true; | |
6181 | ||
c56589ed SW |
6182 | wdev_lock(wdev); |
6183 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
6184 | wdev_unlock(wdev); | |
6185 | ||
6186 | return err; | |
16ef1fe2 SW |
6187 | } |
6188 | ||
9720bb3a JB |
6189 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
6190 | u32 seq, int flags, | |
2a519311 | 6191 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
6192 | struct wireless_dev *wdev, |
6193 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 6194 | { |
48ab905d | 6195 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 6196 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
6197 | void *hdr; |
6198 | struct nlattr *bss; | |
48ab905d JB |
6199 | |
6200 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 6201 | |
15e47304 | 6202 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
6203 | NL80211_CMD_NEW_SCAN_RESULTS); |
6204 | if (!hdr) | |
6205 | return -1; | |
6206 | ||
9720bb3a JB |
6207 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
6208 | ||
97990a06 JB |
6209 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
6210 | goto nla_put_failure; | |
6211 | if (wdev->netdev && | |
9360ffd1 DM |
6212 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
6213 | goto nla_put_failure; | |
97990a06 JB |
6214 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
6215 | goto nla_put_failure; | |
2a519311 JB |
6216 | |
6217 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
6218 | if (!bss) | |
6219 | goto nla_put_failure; | |
9360ffd1 | 6220 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 6221 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 6222 | goto nla_put_failure; |
9caf0364 JB |
6223 | |
6224 | rcu_read_lock(); | |
0e227084 JB |
6225 | /* indicate whether we have probe response data or not */ |
6226 | if (rcu_access_pointer(res->proberesp_ies) && | |
6227 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
6228 | goto fail_unlock_rcu; | |
6229 | ||
6230 | /* this pointer prefers to be pointed to probe response data | |
6231 | * but is always valid | |
6232 | */ | |
9caf0364 | 6233 | ies = rcu_dereference(res->ies); |
8cef2c9d JB |
6234 | if (ies) { |
6235 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
6236 | goto fail_unlock_rcu; | |
8cef2c9d JB |
6237 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
6238 | ies->len, ies->data)) | |
6239 | goto fail_unlock_rcu; | |
9caf0364 | 6240 | } |
0e227084 JB |
6241 | |
6242 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 6243 | ies = rcu_dereference(res->beacon_ies); |
0e227084 JB |
6244 | if (ies && ies->from_beacon) { |
6245 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) | |
8cef2c9d JB |
6246 | goto fail_unlock_rcu; |
6247 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
6248 | ies->len, ies->data)) | |
6249 | goto fail_unlock_rcu; | |
9caf0364 JB |
6250 | } |
6251 | rcu_read_unlock(); | |
6252 | ||
9360ffd1 DM |
6253 | if (res->beacon_interval && |
6254 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
6255 | goto nla_put_failure; | |
6256 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
6257 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 6258 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
6259 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
6260 | jiffies_to_msecs(jiffies - intbss->ts))) | |
6261 | goto nla_put_failure; | |
2a519311 | 6262 | |
77965c97 | 6263 | switch (rdev->wiphy.signal_type) { |
2a519311 | 6264 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
6265 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
6266 | goto nla_put_failure; | |
2a519311 JB |
6267 | break; |
6268 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
6269 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
6270 | goto nla_put_failure; | |
2a519311 JB |
6271 | break; |
6272 | default: | |
6273 | break; | |
6274 | } | |
6275 | ||
48ab905d | 6276 | switch (wdev->iftype) { |
074ac8df | 6277 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 6278 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
6279 | if (intbss == wdev->current_bss && |
6280 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6281 | NL80211_BSS_STATUS_ASSOCIATED)) | |
6282 | goto nla_put_failure; | |
48ab905d JB |
6283 | break; |
6284 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
6285 | if (intbss == wdev->current_bss && |
6286 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6287 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
6288 | goto nla_put_failure; | |
48ab905d JB |
6289 | break; |
6290 | default: | |
6291 | break; | |
6292 | } | |
6293 | ||
2a519311 JB |
6294 | nla_nest_end(msg, bss); |
6295 | ||
6296 | return genlmsg_end(msg, hdr); | |
6297 | ||
8cef2c9d JB |
6298 | fail_unlock_rcu: |
6299 | rcu_read_unlock(); | |
2a519311 JB |
6300 | nla_put_failure: |
6301 | genlmsg_cancel(msg, hdr); | |
6302 | return -EMSGSIZE; | |
6303 | } | |
6304 | ||
97990a06 | 6305 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 6306 | { |
48ab905d | 6307 | struct cfg80211_registered_device *rdev; |
2a519311 | 6308 | struct cfg80211_internal_bss *scan; |
48ab905d | 6309 | struct wireless_dev *wdev; |
97990a06 | 6310 | int start = cb->args[2], idx = 0; |
2a519311 JB |
6311 | int err; |
6312 | ||
97990a06 | 6313 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6314 | if (err) |
6315 | return err; | |
2a519311 | 6316 | |
48ab905d JB |
6317 | wdev_lock(wdev); |
6318 | spin_lock_bh(&rdev->bss_lock); | |
6319 | cfg80211_bss_expire(rdev); | |
6320 | ||
9720bb3a JB |
6321 | cb->seq = rdev->bss_generation; |
6322 | ||
48ab905d | 6323 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
6324 | if (++idx <= start) |
6325 | continue; | |
9720bb3a | 6326 | if (nl80211_send_bss(skb, cb, |
2a519311 | 6327 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 6328 | rdev, wdev, scan) < 0) { |
2a519311 | 6329 | idx--; |
67748893 | 6330 | break; |
2a519311 JB |
6331 | } |
6332 | } | |
6333 | ||
48ab905d JB |
6334 | spin_unlock_bh(&rdev->bss_lock); |
6335 | wdev_unlock(wdev); | |
2a519311 | 6336 | |
97990a06 JB |
6337 | cb->args[2] = idx; |
6338 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 6339 | |
67748893 | 6340 | return skb->len; |
2a519311 JB |
6341 | } |
6342 | ||
15e47304 | 6343 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
6344 | int flags, struct net_device *dev, |
6345 | struct survey_info *survey) | |
6346 | { | |
6347 | void *hdr; | |
6348 | struct nlattr *infoattr; | |
6349 | ||
15e47304 | 6350 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
6351 | NL80211_CMD_NEW_SURVEY_RESULTS); |
6352 | if (!hdr) | |
6353 | return -ENOMEM; | |
6354 | ||
9360ffd1 DM |
6355 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
6356 | goto nla_put_failure; | |
61fa713c HS |
6357 | |
6358 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
6359 | if (!infoattr) | |
6360 | goto nla_put_failure; | |
6361 | ||
9360ffd1 DM |
6362 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
6363 | survey->channel->center_freq)) | |
6364 | goto nla_put_failure; | |
6365 | ||
6366 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
6367 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
6368 | goto nla_put_failure; | |
6369 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
6370 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
6371 | goto nla_put_failure; | |
6372 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
6373 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
6374 | survey->channel_time)) | |
6375 | goto nla_put_failure; | |
6376 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
6377 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
6378 | survey->channel_time_busy)) | |
6379 | goto nla_put_failure; | |
6380 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
6381 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
6382 | survey->channel_time_ext_busy)) | |
6383 | goto nla_put_failure; | |
6384 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
6385 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
6386 | survey->channel_time_rx)) | |
6387 | goto nla_put_failure; | |
6388 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
6389 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
6390 | survey->channel_time_tx)) | |
6391 | goto nla_put_failure; | |
61fa713c HS |
6392 | |
6393 | nla_nest_end(msg, infoattr); | |
6394 | ||
6395 | return genlmsg_end(msg, hdr); | |
6396 | ||
6397 | nla_put_failure: | |
6398 | genlmsg_cancel(msg, hdr); | |
6399 | return -EMSGSIZE; | |
6400 | } | |
6401 | ||
6402 | static int nl80211_dump_survey(struct sk_buff *skb, | |
6403 | struct netlink_callback *cb) | |
6404 | { | |
6405 | struct survey_info survey; | |
1b8ec87a | 6406 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
6407 | struct wireless_dev *wdev; |
6408 | int survey_idx = cb->args[2]; | |
61fa713c HS |
6409 | int res; |
6410 | ||
1b8ec87a | 6411 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6412 | if (res) |
6413 | return res; | |
61fa713c | 6414 | |
97990a06 JB |
6415 | if (!wdev->netdev) { |
6416 | res = -EINVAL; | |
6417 | goto out_err; | |
6418 | } | |
6419 | ||
1b8ec87a | 6420 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
6421 | res = -EOPNOTSUPP; |
6422 | goto out_err; | |
6423 | } | |
6424 | ||
6425 | while (1) { | |
180cdc79 LR |
6426 | struct ieee80211_channel *chan; |
6427 | ||
1b8ec87a | 6428 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
6429 | if (res == -ENOENT) |
6430 | break; | |
6431 | if (res) | |
6432 | goto out_err; | |
6433 | ||
180cdc79 LR |
6434 | /* Survey without a channel doesn't make sense */ |
6435 | if (!survey.channel) { | |
6436 | res = -EINVAL; | |
6437 | goto out; | |
6438 | } | |
6439 | ||
1b8ec87a | 6440 | chan = ieee80211_get_channel(&rdev->wiphy, |
180cdc79 LR |
6441 | survey.channel->center_freq); |
6442 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
6443 | survey_idx++; | |
6444 | continue; | |
6445 | } | |
6446 | ||
61fa713c | 6447 | if (nl80211_send_survey(skb, |
15e47304 | 6448 | NETLINK_CB(cb->skb).portid, |
61fa713c | 6449 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 6450 | wdev->netdev, &survey) < 0) |
61fa713c HS |
6451 | goto out; |
6452 | survey_idx++; | |
6453 | } | |
6454 | ||
6455 | out: | |
97990a06 | 6456 | cb->args[2] = survey_idx; |
61fa713c HS |
6457 | res = skb->len; |
6458 | out_err: | |
1b8ec87a | 6459 | nl80211_finish_wdev_dump(rdev); |
61fa713c HS |
6460 | return res; |
6461 | } | |
6462 | ||
b23aa676 SO |
6463 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
6464 | { | |
6465 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
6466 | NL80211_WPA_VERSION_2)); | |
6467 | } | |
6468 | ||
636a5d36 JM |
6469 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
6470 | { | |
4c476991 JB |
6471 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6472 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6473 | struct ieee80211_channel *chan; |
e39e5b5e JM |
6474 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
6475 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 6476 | enum nl80211_auth_type auth_type; |
fffd0934 | 6477 | struct key_parse key; |
d5cdfacb | 6478 | bool local_state_change; |
636a5d36 | 6479 | |
f4a11bb0 JB |
6480 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6481 | return -EINVAL; | |
6482 | ||
6483 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6484 | return -EINVAL; | |
6485 | ||
1778092e JM |
6486 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
6487 | return -EINVAL; | |
6488 | ||
19957bb3 JB |
6489 | if (!info->attrs[NL80211_ATTR_SSID]) |
6490 | return -EINVAL; | |
6491 | ||
6492 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
6493 | return -EINVAL; | |
6494 | ||
fffd0934 JB |
6495 | err = nl80211_parse_key(info, &key); |
6496 | if (err) | |
6497 | return err; | |
6498 | ||
6499 | if (key.idx >= 0) { | |
e31b8213 JB |
6500 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
6501 | return -EINVAL; | |
fffd0934 JB |
6502 | if (!key.p.key || !key.p.key_len) |
6503 | return -EINVAL; | |
6504 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
6505 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
6506 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
6507 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
6508 | return -EINVAL; | |
6509 | if (key.idx > 4) | |
6510 | return -EINVAL; | |
6511 | } else { | |
6512 | key.p.key_len = 0; | |
6513 | key.p.key = NULL; | |
6514 | } | |
6515 | ||
afea0b7a JB |
6516 | if (key.idx >= 0) { |
6517 | int i; | |
6518 | bool ok = false; | |
6519 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
6520 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
6521 | ok = true; | |
6522 | break; | |
6523 | } | |
6524 | } | |
4c476991 JB |
6525 | if (!ok) |
6526 | return -EINVAL; | |
afea0b7a JB |
6527 | } |
6528 | ||
4c476991 JB |
6529 | if (!rdev->ops->auth) |
6530 | return -EOPNOTSUPP; | |
636a5d36 | 6531 | |
074ac8df | 6532 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6533 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6534 | return -EOPNOTSUPP; | |
eec60b03 | 6535 | |
19957bb3 | 6536 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
6537 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6538 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6539 | if (!chan) | |
4c476991 | 6540 | return -EINVAL; |
636a5d36 | 6541 | |
19957bb3 JB |
6542 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6543 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6544 | |
6545 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6546 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6547 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6548 | } |
6549 | ||
19957bb3 | 6550 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 6551 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 6552 | return -EINVAL; |
636a5d36 | 6553 | |
e39e5b5e JM |
6554 | if (auth_type == NL80211_AUTHTYPE_SAE && |
6555 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
6556 | return -EINVAL; | |
6557 | ||
6558 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
6559 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
6560 | return -EINVAL; | |
6561 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6562 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6563 | /* need to include at least Auth Transaction and Status Code */ | |
6564 | if (sae_data_len < 4) | |
6565 | return -EINVAL; | |
6566 | } | |
6567 | ||
d5cdfacb JM |
6568 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6569 | ||
95de817b JB |
6570 | /* |
6571 | * Since we no longer track auth state, ignore | |
6572 | * requests to only change local state. | |
6573 | */ | |
6574 | if (local_state_change) | |
6575 | return 0; | |
6576 | ||
91bf9b26 JB |
6577 | wdev_lock(dev->ieee80211_ptr); |
6578 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
6579 | ssid, ssid_len, ie, ie_len, | |
6580 | key.p.key, key.p.key_len, key.idx, | |
6581 | sae_data, sae_data_len); | |
6582 | wdev_unlock(dev->ieee80211_ptr); | |
6583 | return err; | |
636a5d36 JM |
6584 | } |
6585 | ||
c0692b8f JB |
6586 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6587 | struct genl_info *info, | |
3dc27d25 JB |
6588 | struct cfg80211_crypto_settings *settings, |
6589 | int cipher_limit) | |
b23aa676 | 6590 | { |
c0b2bbd8 JB |
6591 | memset(settings, 0, sizeof(*settings)); |
6592 | ||
b23aa676 SO |
6593 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6594 | ||
c0692b8f JB |
6595 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6596 | u16 proto; | |
6597 | proto = nla_get_u16( | |
6598 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6599 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6600 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6601 | proto != ETH_P_PAE) | |
6602 | return -EINVAL; | |
6603 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6604 | settings->control_port_no_encrypt = true; | |
6605 | } else | |
6606 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6607 | ||
b23aa676 SO |
6608 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6609 | void *data; | |
6610 | int len, i; | |
6611 | ||
6612 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6613 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6614 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6615 | ||
6616 | if (len % sizeof(u32)) | |
6617 | return -EINVAL; | |
6618 | ||
3dc27d25 | 6619 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6620 | return -EINVAL; |
6621 | ||
6622 | memcpy(settings->ciphers_pairwise, data, len); | |
6623 | ||
6624 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6625 | if (!cfg80211_supported_cipher_suite( |
6626 | &rdev->wiphy, | |
b23aa676 SO |
6627 | settings->ciphers_pairwise[i])) |
6628 | return -EINVAL; | |
6629 | } | |
6630 | ||
6631 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6632 | settings->cipher_group = | |
6633 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6634 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6635 | settings->cipher_group)) | |
b23aa676 SO |
6636 | return -EINVAL; |
6637 | } | |
6638 | ||
6639 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6640 | settings->wpa_versions = | |
6641 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6642 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6643 | return -EINVAL; | |
6644 | } | |
6645 | ||
6646 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6647 | void *data; | |
6d30240e | 6648 | int len; |
b23aa676 SO |
6649 | |
6650 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6651 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6652 | settings->n_akm_suites = len / sizeof(u32); | |
6653 | ||
6654 | if (len % sizeof(u32)) | |
6655 | return -EINVAL; | |
6656 | ||
1b9ca027 JM |
6657 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6658 | return -EINVAL; | |
6659 | ||
b23aa676 | 6660 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6661 | } |
6662 | ||
6663 | return 0; | |
6664 | } | |
6665 | ||
636a5d36 JM |
6666 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6667 | { | |
4c476991 JB |
6668 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6669 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6670 | struct ieee80211_channel *chan; |
f62fab73 JB |
6671 | struct cfg80211_assoc_request req = {}; |
6672 | const u8 *bssid, *ssid; | |
6673 | int err, ssid_len = 0; | |
636a5d36 | 6674 | |
f4a11bb0 JB |
6675 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6676 | return -EINVAL; | |
6677 | ||
6678 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6679 | !info->attrs[NL80211_ATTR_SSID] || |
6680 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6681 | return -EINVAL; |
6682 | ||
4c476991 JB |
6683 | if (!rdev->ops->assoc) |
6684 | return -EOPNOTSUPP; | |
636a5d36 | 6685 | |
074ac8df | 6686 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6687 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6688 | return -EOPNOTSUPP; | |
eec60b03 | 6689 | |
19957bb3 | 6690 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6691 | |
664834de JM |
6692 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6693 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6694 | if (!chan) | |
4c476991 | 6695 | return -EINVAL; |
636a5d36 | 6696 | |
19957bb3 JB |
6697 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6698 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6699 | |
6700 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6701 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6702 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6703 | } |
6704 | ||
dc6382ce | 6705 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6706 | enum nl80211_mfp mfp = |
dc6382ce | 6707 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6708 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6709 | req.use_mfp = true; |
4c476991 JB |
6710 | else if (mfp != NL80211_MFP_NO) |
6711 | return -EINVAL; | |
dc6382ce JM |
6712 | } |
6713 | ||
3e5d7649 | 6714 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 6715 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 6716 | |
7e7c8926 | 6717 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 6718 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
6719 | |
6720 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
6721 | memcpy(&req.ht_capa_mask, |
6722 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6723 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
6724 | |
6725 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 6726 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 6727 | return -EINVAL; |
f62fab73 JB |
6728 | memcpy(&req.ht_capa, |
6729 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6730 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
6731 | } |
6732 | ||
ee2aca34 | 6733 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 6734 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
6735 | |
6736 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
6737 | memcpy(&req.vht_capa_mask, |
6738 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6739 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
6740 | |
6741 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 6742 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 6743 | return -EINVAL; |
f62fab73 JB |
6744 | memcpy(&req.vht_capa, |
6745 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6746 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
6747 | } |
6748 | ||
bab5ab7d AK |
6749 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
6750 | if (!(rdev->wiphy.features & | |
6751 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
6752 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
6753 | return -EINVAL; | |
6754 | req.flags |= ASSOC_REQ_USE_RRM; | |
6755 | } | |
6756 | ||
f62fab73 | 6757 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
6758 | if (!err) { |
6759 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
6760 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
6761 | ssid, ssid_len, &req); | |
91bf9b26 JB |
6762 | wdev_unlock(dev->ieee80211_ptr); |
6763 | } | |
636a5d36 | 6764 | |
636a5d36 JM |
6765 | return err; |
6766 | } | |
6767 | ||
6768 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
6769 | { | |
4c476991 JB |
6770 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6771 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6772 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6773 | int ie_len = 0, err; |
19957bb3 | 6774 | u16 reason_code; |
d5cdfacb | 6775 | bool local_state_change; |
636a5d36 | 6776 | |
f4a11bb0 JB |
6777 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6778 | return -EINVAL; | |
6779 | ||
6780 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6781 | return -EINVAL; | |
6782 | ||
6783 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6784 | return -EINVAL; | |
6785 | ||
4c476991 JB |
6786 | if (!rdev->ops->deauth) |
6787 | return -EOPNOTSUPP; | |
636a5d36 | 6788 | |
074ac8df | 6789 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6790 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6791 | return -EOPNOTSUPP; | |
eec60b03 | 6792 | |
19957bb3 | 6793 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6794 | |
19957bb3 JB |
6795 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6796 | if (reason_code == 0) { | |
f4a11bb0 | 6797 | /* Reason Code 0 is reserved */ |
4c476991 | 6798 | return -EINVAL; |
255e737e | 6799 | } |
636a5d36 JM |
6800 | |
6801 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6802 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6803 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6804 | } |
6805 | ||
d5cdfacb JM |
6806 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6807 | ||
91bf9b26 JB |
6808 | wdev_lock(dev->ieee80211_ptr); |
6809 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
6810 | local_state_change); | |
6811 | wdev_unlock(dev->ieee80211_ptr); | |
6812 | return err; | |
636a5d36 JM |
6813 | } |
6814 | ||
6815 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
6816 | { | |
4c476991 JB |
6817 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6818 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6819 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6820 | int ie_len = 0, err; |
19957bb3 | 6821 | u16 reason_code; |
d5cdfacb | 6822 | bool local_state_change; |
636a5d36 | 6823 | |
f4a11bb0 JB |
6824 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6825 | return -EINVAL; | |
6826 | ||
6827 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6828 | return -EINVAL; | |
6829 | ||
6830 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6831 | return -EINVAL; | |
6832 | ||
4c476991 JB |
6833 | if (!rdev->ops->disassoc) |
6834 | return -EOPNOTSUPP; | |
636a5d36 | 6835 | |
074ac8df | 6836 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6837 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6838 | return -EOPNOTSUPP; | |
eec60b03 | 6839 | |
19957bb3 | 6840 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6841 | |
19957bb3 JB |
6842 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6843 | if (reason_code == 0) { | |
f4a11bb0 | 6844 | /* Reason Code 0 is reserved */ |
4c476991 | 6845 | return -EINVAL; |
255e737e | 6846 | } |
636a5d36 JM |
6847 | |
6848 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6849 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6850 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6851 | } |
6852 | ||
d5cdfacb JM |
6853 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6854 | ||
91bf9b26 JB |
6855 | wdev_lock(dev->ieee80211_ptr); |
6856 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
6857 | local_state_change); | |
6858 | wdev_unlock(dev->ieee80211_ptr); | |
6859 | return err; | |
636a5d36 JM |
6860 | } |
6861 | ||
dd5b4cc7 FF |
6862 | static bool |
6863 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
6864 | int mcast_rate[IEEE80211_NUM_BANDS], | |
6865 | int rateval) | |
6866 | { | |
6867 | struct wiphy *wiphy = &rdev->wiphy; | |
6868 | bool found = false; | |
6869 | int band, i; | |
6870 | ||
6871 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6872 | struct ieee80211_supported_band *sband; | |
6873 | ||
6874 | sband = wiphy->bands[band]; | |
6875 | if (!sband) | |
6876 | continue; | |
6877 | ||
6878 | for (i = 0; i < sband->n_bitrates; i++) { | |
6879 | if (sband->bitrates[i].bitrate == rateval) { | |
6880 | mcast_rate[band] = i + 1; | |
6881 | found = true; | |
6882 | break; | |
6883 | } | |
6884 | } | |
6885 | } | |
6886 | ||
6887 | return found; | |
6888 | } | |
6889 | ||
04a773ad JB |
6890 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
6891 | { | |
4c476991 JB |
6892 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6893 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
6894 | struct cfg80211_ibss_params ibss; |
6895 | struct wiphy *wiphy; | |
fffd0934 | 6896 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
6897 | int err; |
6898 | ||
8e30bc55 JB |
6899 | memset(&ibss, 0, sizeof(ibss)); |
6900 | ||
04a773ad JB |
6901 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6902 | return -EINVAL; | |
6903 | ||
683b6d3b | 6904 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
6905 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
6906 | return -EINVAL; | |
6907 | ||
8e30bc55 JB |
6908 | ibss.beacon_interval = 100; |
6909 | ||
6910 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
6911 | ibss.beacon_interval = | |
6912 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
6913 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
6914 | return -EINVAL; | |
6915 | } | |
6916 | ||
4c476991 JB |
6917 | if (!rdev->ops->join_ibss) |
6918 | return -EOPNOTSUPP; | |
04a773ad | 6919 | |
4c476991 JB |
6920 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6921 | return -EOPNOTSUPP; | |
04a773ad | 6922 | |
79c97e97 | 6923 | wiphy = &rdev->wiphy; |
04a773ad | 6924 | |
39193498 | 6925 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 6926 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
6927 | |
6928 | if (!is_valid_ether_addr(ibss.bssid)) | |
6929 | return -EINVAL; | |
6930 | } | |
04a773ad JB |
6931 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6932 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6933 | ||
6934 | if (info->attrs[NL80211_ATTR_IE]) { | |
6935 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6936 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6937 | } | |
6938 | ||
683b6d3b JB |
6939 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
6940 | if (err) | |
6941 | return err; | |
04a773ad | 6942 | |
174e0cd2 IP |
6943 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
6944 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
6945 | return -EINVAL; |
6946 | ||
2f301ab2 | 6947 | switch (ibss.chandef.width) { |
bf372645 SW |
6948 | case NL80211_CHAN_WIDTH_5: |
6949 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
6950 | case NL80211_CHAN_WIDTH_20_NOHT: |
6951 | break; | |
6952 | case NL80211_CHAN_WIDTH_20: | |
6953 | case NL80211_CHAN_WIDTH_40: | |
6954 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | |
6955 | break; | |
6956 | default: | |
c04d6150 | 6957 | return -EINVAL; |
2f301ab2 | 6958 | } |
db9c64cf | 6959 | |
04a773ad | 6960 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
6961 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
6962 | ||
fbd2c8dc TP |
6963 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6964 | u8 *rates = | |
6965 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6966 | int n_rates = | |
6967 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6968 | struct ieee80211_supported_band *sband = | |
683b6d3b | 6969 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 6970 | |
34850ab2 JB |
6971 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
6972 | &ibss.basic_rates); | |
6973 | if (err) | |
6974 | return err; | |
fbd2c8dc | 6975 | } |
dd5b4cc7 | 6976 | |
803768f5 SW |
6977 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
6978 | memcpy(&ibss.ht_capa_mask, | |
6979 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6980 | sizeof(ibss.ht_capa_mask)); | |
6981 | ||
6982 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
6983 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6984 | return -EINVAL; | |
6985 | memcpy(&ibss.ht_capa, | |
6986 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6987 | sizeof(ibss.ht_capa)); | |
6988 | } | |
6989 | ||
dd5b4cc7 FF |
6990 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
6991 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
6992 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6993 | return -EINVAL; | |
fbd2c8dc | 6994 | |
4c476991 | 6995 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
6996 | bool no_ht = false; |
6997 | ||
4c476991 | 6998 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
6999 | info->attrs[NL80211_ATTR_KEYS], |
7000 | &no_ht); | |
4c476991 JB |
7001 | if (IS_ERR(connkeys)) |
7002 | return PTR_ERR(connkeys); | |
de7044ee | 7003 | |
3d9d1d66 JB |
7004 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
7005 | no_ht) { | |
de7044ee SM |
7006 | kfree(connkeys); |
7007 | return -EINVAL; | |
7008 | } | |
4c476991 | 7009 | } |
04a773ad | 7010 | |
267335d6 AQ |
7011 | ibss.control_port = |
7012 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
7013 | ||
5336fa88 SW |
7014 | ibss.userspace_handles_dfs = |
7015 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
7016 | ||
4c476991 | 7017 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 | 7018 | if (err) |
b47f610b | 7019 | kzfree(connkeys); |
04a773ad JB |
7020 | return err; |
7021 | } | |
7022 | ||
7023 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
7024 | { | |
4c476991 JB |
7025 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7026 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 7027 | |
4c476991 JB |
7028 | if (!rdev->ops->leave_ibss) |
7029 | return -EOPNOTSUPP; | |
04a773ad | 7030 | |
4c476991 JB |
7031 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7032 | return -EOPNOTSUPP; | |
04a773ad | 7033 | |
4c476991 | 7034 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
7035 | } |
7036 | ||
f4e583c8 AQ |
7037 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
7038 | { | |
7039 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7040 | struct net_device *dev = info->user_ptr[1]; | |
7041 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
7042 | u32 nla_rate; | |
7043 | int err; | |
7044 | ||
7045 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
7046 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
7047 | return -EOPNOTSUPP; | |
7048 | ||
7049 | if (!rdev->ops->set_mcast_rate) | |
7050 | return -EOPNOTSUPP; | |
7051 | ||
7052 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
7053 | ||
7054 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
7055 | return -EINVAL; | |
7056 | ||
7057 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
7058 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
7059 | return -EINVAL; | |
7060 | ||
7061 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
7062 | ||
7063 | return err; | |
7064 | } | |
7065 | ||
ad7e718c JB |
7066 | static struct sk_buff * |
7067 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
7068 | int approxlen, u32 portid, u32 seq, | |
7069 | enum nl80211_commands cmd, | |
567ffc35 JB |
7070 | enum nl80211_attrs attr, |
7071 | const struct nl80211_vendor_cmd_info *info, | |
7072 | gfp_t gfp) | |
ad7e718c JB |
7073 | { |
7074 | struct sk_buff *skb; | |
7075 | void *hdr; | |
7076 | struct nlattr *data; | |
7077 | ||
7078 | skb = nlmsg_new(approxlen + 100, gfp); | |
7079 | if (!skb) | |
7080 | return NULL; | |
7081 | ||
7082 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
7083 | if (!hdr) { | |
7084 | kfree_skb(skb); | |
7085 | return NULL; | |
7086 | } | |
7087 | ||
7088 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
7089 | goto nla_put_failure; | |
567ffc35 JB |
7090 | |
7091 | if (info) { | |
7092 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
7093 | info->vendor_id)) | |
7094 | goto nla_put_failure; | |
7095 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
7096 | info->subcmd)) | |
7097 | goto nla_put_failure; | |
7098 | } | |
7099 | ||
ad7e718c JB |
7100 | data = nla_nest_start(skb, attr); |
7101 | ||
7102 | ((void **)skb->cb)[0] = rdev; | |
7103 | ((void **)skb->cb)[1] = hdr; | |
7104 | ((void **)skb->cb)[2] = data; | |
7105 | ||
7106 | return skb; | |
7107 | ||
7108 | nla_put_failure: | |
7109 | kfree_skb(skb); | |
7110 | return NULL; | |
7111 | } | |
f4e583c8 | 7112 | |
e03ad6ea JB |
7113 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
7114 | enum nl80211_commands cmd, | |
7115 | enum nl80211_attrs attr, | |
7116 | int vendor_event_idx, | |
7117 | int approxlen, gfp_t gfp) | |
7118 | { | |
f26cbf40 | 7119 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
7120 | const struct nl80211_vendor_cmd_info *info; |
7121 | ||
7122 | switch (cmd) { | |
7123 | case NL80211_CMD_TESTMODE: | |
7124 | if (WARN_ON(vendor_event_idx != -1)) | |
7125 | return NULL; | |
7126 | info = NULL; | |
7127 | break; | |
7128 | case NL80211_CMD_VENDOR: | |
7129 | if (WARN_ON(vendor_event_idx < 0 || | |
7130 | vendor_event_idx >= wiphy->n_vendor_events)) | |
7131 | return NULL; | |
7132 | info = &wiphy->vendor_events[vendor_event_idx]; | |
7133 | break; | |
7134 | default: | |
7135 | WARN_ON(1); | |
7136 | return NULL; | |
7137 | } | |
7138 | ||
7139 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, | |
7140 | cmd, attr, info, gfp); | |
7141 | } | |
7142 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
7143 | ||
7144 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
7145 | { | |
7146 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
7147 | void *hdr = ((void **)skb->cb)[1]; | |
7148 | struct nlattr *data = ((void **)skb->cb)[2]; | |
7149 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
7150 | ||
bd8c78e7 JB |
7151 | /* clear CB data for netlink core to own from now on */ |
7152 | memset(skb->cb, 0, sizeof(skb->cb)); | |
7153 | ||
e03ad6ea JB |
7154 | nla_nest_end(skb, data); |
7155 | genlmsg_end(skb, hdr); | |
7156 | ||
7157 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
7158 | mcgrp = NL80211_MCGRP_VENDOR; | |
7159 | ||
7160 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
7161 | mcgrp, gfp); | |
7162 | } | |
7163 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
7164 | ||
aff89a9b | 7165 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
7166 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
7167 | { | |
4c476991 | 7168 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
7169 | struct wireless_dev *wdev = |
7170 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
7171 | int err; |
7172 | ||
fc73f11f DS |
7173 | if (!rdev->ops->testmode_cmd) |
7174 | return -EOPNOTSUPP; | |
7175 | ||
7176 | if (IS_ERR(wdev)) { | |
7177 | err = PTR_ERR(wdev); | |
7178 | if (err != -EINVAL) | |
7179 | return err; | |
7180 | wdev = NULL; | |
7181 | } else if (wdev->wiphy != &rdev->wiphy) { | |
7182 | return -EINVAL; | |
7183 | } | |
7184 | ||
aff89a9b JB |
7185 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
7186 | return -EINVAL; | |
7187 | ||
ad7e718c | 7188 | rdev->cur_cmd_info = info; |
fc73f11f | 7189 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
7190 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
7191 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 7192 | rdev->cur_cmd_info = NULL; |
aff89a9b | 7193 | |
aff89a9b JB |
7194 | return err; |
7195 | } | |
7196 | ||
71063f0e WYG |
7197 | static int nl80211_testmode_dump(struct sk_buff *skb, |
7198 | struct netlink_callback *cb) | |
7199 | { | |
00918d33 | 7200 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
7201 | int err; |
7202 | long phy_idx; | |
7203 | void *data = NULL; | |
7204 | int data_len = 0; | |
7205 | ||
5fe231e8 JB |
7206 | rtnl_lock(); |
7207 | ||
71063f0e WYG |
7208 | if (cb->args[0]) { |
7209 | /* | |
7210 | * 0 is a valid index, but not valid for args[0], | |
7211 | * so we need to offset by 1. | |
7212 | */ | |
7213 | phy_idx = cb->args[0] - 1; | |
7214 | } else { | |
7215 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
7216 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
7217 | nl80211_policy); | |
7218 | if (err) | |
5fe231e8 | 7219 | goto out_err; |
00918d33 | 7220 | |
2bd7e35d JB |
7221 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
7222 | nl80211_fam.attrbuf); | |
7223 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
7224 | err = PTR_ERR(rdev); |
7225 | goto out_err; | |
00918d33 | 7226 | } |
2bd7e35d JB |
7227 | phy_idx = rdev->wiphy_idx; |
7228 | rdev = NULL; | |
2bd7e35d | 7229 | |
71063f0e WYG |
7230 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
7231 | cb->args[1] = | |
7232 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
7233 | } | |
7234 | ||
7235 | if (cb->args[1]) { | |
7236 | data = nla_data((void *)cb->args[1]); | |
7237 | data_len = nla_len((void *)cb->args[1]); | |
7238 | } | |
7239 | ||
00918d33 JB |
7240 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
7241 | if (!rdev) { | |
5fe231e8 JB |
7242 | err = -ENOENT; |
7243 | goto out_err; | |
71063f0e | 7244 | } |
71063f0e | 7245 | |
00918d33 | 7246 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
7247 | err = -EOPNOTSUPP; |
7248 | goto out_err; | |
7249 | } | |
7250 | ||
7251 | while (1) { | |
15e47304 | 7252 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
7253 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
7254 | NL80211_CMD_TESTMODE); | |
7255 | struct nlattr *tmdata; | |
7256 | ||
cb35fba3 DC |
7257 | if (!hdr) |
7258 | break; | |
7259 | ||
9360ffd1 | 7260 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
7261 | genlmsg_cancel(skb, hdr); |
7262 | break; | |
7263 | } | |
7264 | ||
7265 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
7266 | if (!tmdata) { | |
7267 | genlmsg_cancel(skb, hdr); | |
7268 | break; | |
7269 | } | |
e35e4d28 | 7270 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
7271 | nla_nest_end(skb, tmdata); |
7272 | ||
7273 | if (err == -ENOBUFS || err == -ENOENT) { | |
7274 | genlmsg_cancel(skb, hdr); | |
7275 | break; | |
7276 | } else if (err) { | |
7277 | genlmsg_cancel(skb, hdr); | |
7278 | goto out_err; | |
7279 | } | |
7280 | ||
7281 | genlmsg_end(skb, hdr); | |
7282 | } | |
7283 | ||
7284 | err = skb->len; | |
7285 | /* see above */ | |
7286 | cb->args[0] = phy_idx + 1; | |
7287 | out_err: | |
5fe231e8 | 7288 | rtnl_unlock(); |
71063f0e WYG |
7289 | return err; |
7290 | } | |
aff89a9b JB |
7291 | #endif |
7292 | ||
b23aa676 SO |
7293 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
7294 | { | |
4c476991 JB |
7295 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7296 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
7297 | struct cfg80211_connect_params connect; |
7298 | struct wiphy *wiphy; | |
fffd0934 | 7299 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
7300 | int err; |
7301 | ||
7302 | memset(&connect, 0, sizeof(connect)); | |
7303 | ||
7304 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
7305 | return -EINVAL; | |
7306 | ||
7307 | if (!info->attrs[NL80211_ATTR_SSID] || | |
7308 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
7309 | return -EINVAL; | |
7310 | ||
7311 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
7312 | connect.auth_type = | |
7313 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
7314 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
7315 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
7316 | return -EINVAL; |
7317 | } else | |
7318 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
7319 | ||
7320 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
7321 | ||
c0692b8f | 7322 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 7323 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
7324 | if (err) |
7325 | return err; | |
b23aa676 | 7326 | |
074ac8df | 7327 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7328 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7329 | return -EOPNOTSUPP; | |
b23aa676 | 7330 | |
79c97e97 | 7331 | wiphy = &rdev->wiphy; |
b23aa676 | 7332 | |
4486ea98 BS |
7333 | connect.bg_scan_period = -1; |
7334 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
7335 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
7336 | connect.bg_scan_period = | |
7337 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
7338 | } | |
7339 | ||
b23aa676 SO |
7340 | if (info->attrs[NL80211_ATTR_MAC]) |
7341 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
7342 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
7343 | connect.bssid_hint = | |
7344 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
7345 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7346 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7347 | ||
7348 | if (info->attrs[NL80211_ATTR_IE]) { | |
7349 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7350 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7351 | } | |
7352 | ||
cee00a95 JM |
7353 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
7354 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
7355 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
7356 | connect.mfp != NL80211_MFP_NO) | |
7357 | return -EINVAL; | |
7358 | } else { | |
7359 | connect.mfp = NL80211_MFP_NO; | |
7360 | } | |
7361 | ||
b23aa676 | 7362 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
7363 | connect.channel = nl80211_get_valid_chan( |
7364 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7365 | if (!connect.channel) | |
1df4a510 JM |
7366 | return -EINVAL; |
7367 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
7368 | connect.channel_hint = nl80211_get_valid_chan( |
7369 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
7370 | if (!connect.channel_hint) | |
4c476991 | 7371 | return -EINVAL; |
b23aa676 SO |
7372 | } |
7373 | ||
fffd0934 JB |
7374 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
7375 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 7376 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
7377 | if (IS_ERR(connkeys)) |
7378 | return PTR_ERR(connkeys); | |
fffd0934 JB |
7379 | } |
7380 | ||
7e7c8926 BG |
7381 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
7382 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
7383 | ||
7384 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7385 | memcpy(&connect.ht_capa_mask, | |
7386 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7387 | sizeof(connect.ht_capa_mask)); | |
7388 | ||
7389 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e | 7390 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
b47f610b | 7391 | kzfree(connkeys); |
7e7c8926 | 7392 | return -EINVAL; |
b4e4f47e | 7393 | } |
7e7c8926 BG |
7394 | memcpy(&connect.ht_capa, |
7395 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7396 | sizeof(connect.ht_capa)); | |
7397 | } | |
7398 | ||
ee2aca34 JB |
7399 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
7400 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
7401 | ||
7402 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
7403 | memcpy(&connect.vht_capa_mask, | |
7404 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7405 | sizeof(connect.vht_capa_mask)); | |
7406 | ||
7407 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
7408 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
b47f610b | 7409 | kzfree(connkeys); |
ee2aca34 JB |
7410 | return -EINVAL; |
7411 | } | |
7412 | memcpy(&connect.vht_capa, | |
7413 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7414 | sizeof(connect.vht_capa)); | |
7415 | } | |
7416 | ||
bab5ab7d AK |
7417 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7418 | if (!(rdev->wiphy.features & | |
7419 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7420 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7421 | return -EINVAL; | |
7422 | connect.flags |= ASSOC_REQ_USE_RRM; | |
7423 | } | |
7424 | ||
83739b03 JB |
7425 | wdev_lock(dev->ieee80211_ptr); |
7426 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
7427 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 | 7428 | if (err) |
b47f610b | 7429 | kzfree(connkeys); |
b23aa676 SO |
7430 | return err; |
7431 | } | |
7432 | ||
7433 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
7434 | { | |
4c476991 JB |
7435 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7436 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 7437 | u16 reason; |
83739b03 | 7438 | int ret; |
b23aa676 SO |
7439 | |
7440 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7441 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
7442 | else | |
7443 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
7444 | ||
7445 | if (reason == 0) | |
7446 | return -EINVAL; | |
7447 | ||
074ac8df | 7448 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7449 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7450 | return -EOPNOTSUPP; | |
b23aa676 | 7451 | |
83739b03 JB |
7452 | wdev_lock(dev->ieee80211_ptr); |
7453 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
7454 | wdev_unlock(dev->ieee80211_ptr); | |
7455 | return ret; | |
b23aa676 SO |
7456 | } |
7457 | ||
463d0183 JB |
7458 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
7459 | { | |
4c476991 | 7460 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
7461 | struct net *net; |
7462 | int err; | |
7463 | u32 pid; | |
7464 | ||
7465 | if (!info->attrs[NL80211_ATTR_PID]) | |
7466 | return -EINVAL; | |
7467 | ||
7468 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
7469 | ||
463d0183 | 7470 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
7471 | if (IS_ERR(net)) |
7472 | return PTR_ERR(net); | |
463d0183 JB |
7473 | |
7474 | err = 0; | |
7475 | ||
7476 | /* check if anything to do */ | |
4c476991 JB |
7477 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
7478 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 7479 | |
463d0183 | 7480 | put_net(net); |
463d0183 JB |
7481 | return err; |
7482 | } | |
7483 | ||
67fbb16b SO |
7484 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
7485 | { | |
4c476991 | 7486 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
7487 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
7488 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 7489 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
7490 | struct cfg80211_pmksa pmksa; |
7491 | ||
7492 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
7493 | ||
7494 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7495 | return -EINVAL; | |
7496 | ||
7497 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
7498 | return -EINVAL; | |
7499 | ||
67fbb16b SO |
7500 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
7501 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7502 | ||
074ac8df | 7503 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7504 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7505 | return -EOPNOTSUPP; | |
67fbb16b SO |
7506 | |
7507 | switch (info->genlhdr->cmd) { | |
7508 | case NL80211_CMD_SET_PMKSA: | |
7509 | rdev_ops = rdev->ops->set_pmksa; | |
7510 | break; | |
7511 | case NL80211_CMD_DEL_PMKSA: | |
7512 | rdev_ops = rdev->ops->del_pmksa; | |
7513 | break; | |
7514 | default: | |
7515 | WARN_ON(1); | |
7516 | break; | |
7517 | } | |
7518 | ||
4c476991 JB |
7519 | if (!rdev_ops) |
7520 | return -EOPNOTSUPP; | |
67fbb16b | 7521 | |
4c476991 | 7522 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
7523 | } |
7524 | ||
7525 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
7526 | { | |
4c476991 JB |
7527 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7528 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 7529 | |
074ac8df | 7530 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7531 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7532 | return -EOPNOTSUPP; | |
67fbb16b | 7533 | |
4c476991 JB |
7534 | if (!rdev->ops->flush_pmksa) |
7535 | return -EOPNOTSUPP; | |
67fbb16b | 7536 | |
e35e4d28 | 7537 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
7538 | } |
7539 | ||
109086ce AN |
7540 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
7541 | { | |
7542 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7543 | struct net_device *dev = info->user_ptr[1]; | |
7544 | u8 action_code, dialog_token; | |
df942e7b | 7545 | u32 peer_capability = 0; |
109086ce AN |
7546 | u16 status_code; |
7547 | u8 *peer; | |
31fa97c5 | 7548 | bool initiator; |
109086ce AN |
7549 | |
7550 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7551 | !rdev->ops->tdls_mgmt) | |
7552 | return -EOPNOTSUPP; | |
7553 | ||
7554 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
7555 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
7556 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
7557 | !info->attrs[NL80211_ATTR_IE] || | |
7558 | !info->attrs[NL80211_ATTR_MAC]) | |
7559 | return -EINVAL; | |
7560 | ||
7561 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7562 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
7563 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
7564 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 7565 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
7566 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
7567 | peer_capability = | |
7568 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 7569 | |
e35e4d28 | 7570 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 7571 | dialog_token, status_code, peer_capability, |
31fa97c5 | 7572 | initiator, |
e35e4d28 HG |
7573 | nla_data(info->attrs[NL80211_ATTR_IE]), |
7574 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
7575 | } |
7576 | ||
7577 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
7578 | { | |
7579 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7580 | struct net_device *dev = info->user_ptr[1]; | |
7581 | enum nl80211_tdls_operation operation; | |
7582 | u8 *peer; | |
7583 | ||
7584 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7585 | !rdev->ops->tdls_oper) | |
7586 | return -EOPNOTSUPP; | |
7587 | ||
7588 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
7589 | !info->attrs[NL80211_ATTR_MAC]) | |
7590 | return -EINVAL; | |
7591 | ||
7592 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
7593 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7594 | ||
e35e4d28 | 7595 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
7596 | } |
7597 | ||
9588bbd5 JM |
7598 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
7599 | struct genl_info *info) | |
7600 | { | |
4c476991 | 7601 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7602 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7603 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
7604 | struct sk_buff *msg; |
7605 | void *hdr; | |
7606 | u64 cookie; | |
683b6d3b | 7607 | u32 duration; |
9588bbd5 JM |
7608 | int err; |
7609 | ||
7610 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7611 | !info->attrs[NL80211_ATTR_DURATION]) | |
7612 | return -EINVAL; | |
7613 | ||
7614 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
7615 | ||
ebf348fc JB |
7616 | if (!rdev->ops->remain_on_channel || |
7617 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
7618 | return -EOPNOTSUPP; | |
7619 | ||
9588bbd5 | 7620 | /* |
ebf348fc JB |
7621 | * We should be on that channel for at least a minimum amount of |
7622 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 7623 | */ |
ebf348fc | 7624 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 7625 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
7626 | return -EINVAL; |
7627 | ||
683b6d3b JB |
7628 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7629 | if (err) | |
7630 | return err; | |
9588bbd5 JM |
7631 | |
7632 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7633 | if (!msg) |
7634 | return -ENOMEM; | |
9588bbd5 | 7635 | |
15e47304 | 7636 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 7637 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
7638 | if (!hdr) { |
7639 | err = -ENOBUFS; | |
9588bbd5 JM |
7640 | goto free_msg; |
7641 | } | |
7642 | ||
683b6d3b JB |
7643 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7644 | duration, &cookie); | |
9588bbd5 JM |
7645 | |
7646 | if (err) | |
7647 | goto free_msg; | |
7648 | ||
9360ffd1 DM |
7649 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7650 | goto nla_put_failure; | |
9588bbd5 JM |
7651 | |
7652 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7653 | |
7654 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7655 | |
7656 | nla_put_failure: | |
7657 | err = -ENOBUFS; | |
7658 | free_msg: | |
7659 | nlmsg_free(msg); | |
9588bbd5 JM |
7660 | return err; |
7661 | } | |
7662 | ||
7663 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
7664 | struct genl_info *info) | |
7665 | { | |
4c476991 | 7666 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7667 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 7668 | u64 cookie; |
9588bbd5 JM |
7669 | |
7670 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7671 | return -EINVAL; | |
7672 | ||
4c476991 JB |
7673 | if (!rdev->ops->cancel_remain_on_channel) |
7674 | return -EOPNOTSUPP; | |
9588bbd5 | 7675 | |
9588bbd5 JM |
7676 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
7677 | ||
e35e4d28 | 7678 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
7679 | } |
7680 | ||
13ae75b1 JM |
7681 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
7682 | u8 *rates, u8 rates_len) | |
7683 | { | |
7684 | u8 i; | |
7685 | u32 mask = 0; | |
7686 | ||
7687 | for (i = 0; i < rates_len; i++) { | |
7688 | int rate = (rates[i] & 0x7f) * 5; | |
7689 | int ridx; | |
7690 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
7691 | struct ieee80211_rate *srate = | |
7692 | &sband->bitrates[ridx]; | |
7693 | if (rate == srate->bitrate) { | |
7694 | mask |= 1 << ridx; | |
7695 | break; | |
7696 | } | |
7697 | } | |
7698 | if (ridx == sband->n_bitrates) | |
7699 | return 0; /* rate not found */ | |
7700 | } | |
7701 | ||
7702 | return mask; | |
7703 | } | |
7704 | ||
24db78c0 SW |
7705 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
7706 | u8 *rates, u8 rates_len, | |
7707 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
7708 | { | |
7709 | u8 i; | |
7710 | ||
7711 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
7712 | ||
7713 | for (i = 0; i < rates_len; i++) { | |
7714 | int ridx, rbit; | |
7715 | ||
7716 | ridx = rates[i] / 8; | |
7717 | rbit = BIT(rates[i] % 8); | |
7718 | ||
7719 | /* check validity */ | |
910570b5 | 7720 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
7721 | return false; |
7722 | ||
7723 | /* check availability */ | |
7724 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
7725 | mcs[ridx] |= rbit; | |
7726 | else | |
7727 | return false; | |
7728 | } | |
7729 | ||
7730 | return true; | |
7731 | } | |
7732 | ||
204e35a9 JD |
7733 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
7734 | { | |
7735 | u16 mcs_mask = 0; | |
7736 | ||
7737 | switch (vht_mcs_map) { | |
7738 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
7739 | break; | |
7740 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
7741 | mcs_mask = 0x00FF; | |
7742 | break; | |
7743 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
7744 | mcs_mask = 0x01FF; | |
7745 | break; | |
7746 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
7747 | mcs_mask = 0x03FF; | |
7748 | break; | |
7749 | default: | |
7750 | break; | |
7751 | } | |
7752 | ||
7753 | return mcs_mask; | |
7754 | } | |
7755 | ||
7756 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
7757 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
7758 | { | |
7759 | u8 nss; | |
7760 | ||
7761 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
7762 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
7763 | vht_mcs_map >>= 2; | |
7764 | } | |
7765 | } | |
7766 | ||
7767 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
7768 | struct nl80211_txrate_vht *txrate, | |
7769 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
7770 | { | |
7771 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
7772 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
7773 | u8 i; | |
7774 | ||
7775 | if (!sband->vht_cap.vht_supported) | |
7776 | return false; | |
7777 | ||
7778 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
7779 | ||
7780 | /* Build vht_mcs_mask from VHT capabilities */ | |
7781 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
7782 | ||
7783 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
7784 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
7785 | mcs[i] = txrate->mcs[i]; | |
7786 | else | |
7787 | return false; | |
7788 | } | |
7789 | ||
7790 | return true; | |
7791 | } | |
7792 | ||
b54452b0 | 7793 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
7794 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
7795 | .len = NL80211_MAX_SUPP_RATES }, | |
d1e33e65 JD |
7796 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
7797 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
204e35a9 | 7798 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
0b9323f6 | 7799 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
13ae75b1 JM |
7800 | }; |
7801 | ||
7802 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
7803 | struct genl_info *info) | |
7804 | { | |
7805 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 7806 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 7807 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
7808 | int rem, i; |
7809 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
7810 | struct nlattr *tx_rates; |
7811 | struct ieee80211_supported_band *sband; | |
204e35a9 | 7812 | u16 vht_tx_mcs_map; |
13ae75b1 | 7813 | |
4c476991 JB |
7814 | if (!rdev->ops->set_bitrate_mask) |
7815 | return -EOPNOTSUPP; | |
13ae75b1 JM |
7816 | |
7817 | memset(&mask, 0, sizeof(mask)); | |
7818 | /* Default to all rates enabled */ | |
7819 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
7820 | sband = rdev->wiphy.bands[i]; | |
7869303b JD |
7821 | |
7822 | if (!sband) | |
7823 | continue; | |
7824 | ||
7825 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; | |
d1e33e65 | 7826 | memcpy(mask.control[i].ht_mcs, |
7869303b | 7827 | sband->ht_cap.mcs.rx_mask, |
d1e33e65 | 7828 | sizeof(mask.control[i].ht_mcs)); |
204e35a9 JD |
7829 | |
7830 | if (!sband->vht_cap.vht_supported) | |
7831 | continue; | |
7832 | ||
7833 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
7834 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); | |
13ae75b1 JM |
7835 | } |
7836 | ||
b9243ab0 JD |
7837 | /* if no rates are given set it back to the defaults */ |
7838 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
7839 | goto out; | |
7840 | ||
13ae75b1 JM |
7841 | /* |
7842 | * The nested attribute uses enum nl80211_band as the index. This maps | |
7843 | * directly to the enum ieee80211_band values used in cfg80211. | |
7844 | */ | |
24db78c0 | 7845 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
ae811e21 | 7846 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
13ae75b1 | 7847 | enum ieee80211_band band = nla_type(tx_rates); |
ae811e21 JB |
7848 | int err; |
7849 | ||
4c476991 JB |
7850 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
7851 | return -EINVAL; | |
13ae75b1 | 7852 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
7853 | if (sband == NULL) |
7854 | return -EINVAL; | |
ae811e21 JB |
7855 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
7856 | nla_len(tx_rates), nl80211_txattr_policy); | |
7857 | if (err) | |
7858 | return err; | |
13ae75b1 JM |
7859 | if (tb[NL80211_TXRATE_LEGACY]) { |
7860 | mask.control[band].legacy = rateset_to_mask( | |
7861 | sband, | |
7862 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
7863 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
7864 | if ((mask.control[band].legacy == 0) && |
7865 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
7866 | return -EINVAL; | |
24db78c0 | 7867 | } |
d1e33e65 | 7868 | if (tb[NL80211_TXRATE_HT]) { |
24db78c0 SW |
7869 | if (!ht_rateset_to_mask( |
7870 | sband, | |
d1e33e65 JD |
7871 | nla_data(tb[NL80211_TXRATE_HT]), |
7872 | nla_len(tb[NL80211_TXRATE_HT]), | |
7873 | mask.control[band].ht_mcs)) | |
24db78c0 SW |
7874 | return -EINVAL; |
7875 | } | |
204e35a9 JD |
7876 | if (tb[NL80211_TXRATE_VHT]) { |
7877 | if (!vht_set_mcs_mask( | |
7878 | sband, | |
7879 | nla_data(tb[NL80211_TXRATE_VHT]), | |
7880 | mask.control[band].vht_mcs)) | |
7881 | return -EINVAL; | |
7882 | } | |
0b9323f6 JD |
7883 | if (tb[NL80211_TXRATE_GI]) { |
7884 | mask.control[band].gi = | |
7885 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
7886 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
7887 | return -EINVAL; | |
7888 | } | |
24db78c0 SW |
7889 | |
7890 | if (mask.control[band].legacy == 0) { | |
204e35a9 JD |
7891 | /* don't allow empty legacy rates if HT or VHT |
7892 | * are not even supported. | |
7893 | */ | |
7894 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
7895 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
24db78c0 SW |
7896 | return -EINVAL; |
7897 | ||
7898 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
d1e33e65 | 7899 | if (mask.control[band].ht_mcs[i]) |
204e35a9 JD |
7900 | goto out; |
7901 | ||
7902 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
7903 | if (mask.control[band].vht_mcs[i]) | |
7904 | goto out; | |
24db78c0 SW |
7905 | |
7906 | /* legacy and mcs rates may not be both empty */ | |
204e35a9 | 7907 | return -EINVAL; |
13ae75b1 JM |
7908 | } |
7909 | } | |
7910 | ||
b9243ab0 | 7911 | out: |
e35e4d28 | 7912 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
7913 | } |
7914 | ||
2e161f78 | 7915 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7916 | { |
4c476991 | 7917 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7918 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 7919 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
7920 | |
7921 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
7922 | return -EINVAL; | |
7923 | ||
2e161f78 JB |
7924 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
7925 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 7926 | |
71bbc994 JB |
7927 | switch (wdev->iftype) { |
7928 | case NL80211_IFTYPE_STATION: | |
7929 | case NL80211_IFTYPE_ADHOC: | |
7930 | case NL80211_IFTYPE_P2P_CLIENT: | |
7931 | case NL80211_IFTYPE_AP: | |
7932 | case NL80211_IFTYPE_AP_VLAN: | |
7933 | case NL80211_IFTYPE_MESH_POINT: | |
7934 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7935 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7936 | break; |
7937 | default: | |
4c476991 | 7938 | return -EOPNOTSUPP; |
71bbc994 | 7939 | } |
026331c4 JM |
7940 | |
7941 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
7942 | if (!rdev->ops->mgmt_tx) |
7943 | return -EOPNOTSUPP; | |
026331c4 | 7944 | |
15e47304 | 7945 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
7946 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
7947 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
7948 | } |
7949 | ||
2e161f78 | 7950 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7951 | { |
4c476991 | 7952 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7953 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7954 | struct cfg80211_chan_def chandef; |
026331c4 | 7955 | int err; |
d64d373f | 7956 | void *hdr = NULL; |
026331c4 | 7957 | u64 cookie; |
e247bd90 | 7958 | struct sk_buff *msg = NULL; |
b176e629 AO |
7959 | struct cfg80211_mgmt_tx_params params = { |
7960 | .dont_wait_for_ack = | |
7961 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
7962 | }; | |
026331c4 | 7963 | |
683b6d3b | 7964 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
7965 | return -EINVAL; |
7966 | ||
4c476991 JB |
7967 | if (!rdev->ops->mgmt_tx) |
7968 | return -EOPNOTSUPP; | |
026331c4 | 7969 | |
71bbc994 | 7970 | switch (wdev->iftype) { |
ea141b75 AQ |
7971 | case NL80211_IFTYPE_P2P_DEVICE: |
7972 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
7973 | return -EINVAL; | |
71bbc994 JB |
7974 | case NL80211_IFTYPE_STATION: |
7975 | case NL80211_IFTYPE_ADHOC: | |
7976 | case NL80211_IFTYPE_P2P_CLIENT: | |
7977 | case NL80211_IFTYPE_AP: | |
7978 | case NL80211_IFTYPE_AP_VLAN: | |
7979 | case NL80211_IFTYPE_MESH_POINT: | |
7980 | case NL80211_IFTYPE_P2P_GO: | |
7981 | break; | |
7982 | default: | |
4c476991 | 7983 | return -EOPNOTSUPP; |
71bbc994 | 7984 | } |
026331c4 | 7985 | |
f7ca38df | 7986 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 7987 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 7988 | return -EINVAL; |
b176e629 | 7989 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
7990 | |
7991 | /* | |
7992 | * We should wait on the channel for at least a minimum amount | |
7993 | * of time (10ms) but no longer than the driver supports. | |
7994 | */ | |
b176e629 AO |
7995 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
7996 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc JB |
7997 | return -EINVAL; |
7998 | ||
f7ca38df JB |
7999 | } |
8000 | ||
b176e629 | 8001 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 8002 | |
b176e629 | 8003 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
8004 | return -EINVAL; |
8005 | ||
b176e629 | 8006 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 8007 | |
ea141b75 AQ |
8008 | /* get the channel if any has been specified, otherwise pass NULL to |
8009 | * the driver. The latter will use the current one | |
8010 | */ | |
8011 | chandef.chan = NULL; | |
8012 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
8013 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
8014 | if (err) | |
8015 | return err; | |
8016 | } | |
8017 | ||
b176e629 | 8018 | if (!chandef.chan && params.offchan) |
ea141b75 | 8019 | return -EINVAL; |
026331c4 | 8020 | |
34d22ce2 AO |
8021 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
8022 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
8023 | ||
8024 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
8025 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8026 | int i; | |
8027 | ||
8028 | if (len % sizeof(u16)) | |
8029 | return -EINVAL; | |
8030 | ||
8031 | params.n_csa_offsets = len / sizeof(u16); | |
8032 | params.csa_offsets = | |
8033 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8034 | ||
8035 | /* check that all the offsets fit the frame */ | |
8036 | for (i = 0; i < params.n_csa_offsets; i++) { | |
8037 | if (params.csa_offsets[i] >= params.len) | |
8038 | return -EINVAL; | |
8039 | } | |
8040 | } | |
8041 | ||
b176e629 | 8042 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
8043 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
8044 | if (!msg) | |
8045 | return -ENOMEM; | |
026331c4 | 8046 | |
15e47304 | 8047 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 8048 | NL80211_CMD_FRAME); |
cb35fba3 DC |
8049 | if (!hdr) { |
8050 | err = -ENOBUFS; | |
e247bd90 JB |
8051 | goto free_msg; |
8052 | } | |
026331c4 | 8053 | } |
e247bd90 | 8054 | |
b176e629 AO |
8055 | params.chan = chandef.chan; |
8056 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
8057 | if (err) |
8058 | goto free_msg; | |
8059 | ||
e247bd90 | 8060 | if (msg) { |
9360ffd1 DM |
8061 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8062 | goto nla_put_failure; | |
026331c4 | 8063 | |
e247bd90 JB |
8064 | genlmsg_end(msg, hdr); |
8065 | return genlmsg_reply(msg, info); | |
8066 | } | |
8067 | ||
8068 | return 0; | |
026331c4 JM |
8069 | |
8070 | nla_put_failure: | |
8071 | err = -ENOBUFS; | |
8072 | free_msg: | |
8073 | nlmsg_free(msg); | |
026331c4 JM |
8074 | return err; |
8075 | } | |
8076 | ||
f7ca38df JB |
8077 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
8078 | { | |
8079 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 8080 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
8081 | u64 cookie; |
8082 | ||
8083 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8084 | return -EINVAL; | |
8085 | ||
8086 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
8087 | return -EOPNOTSUPP; | |
8088 | ||
71bbc994 JB |
8089 | switch (wdev->iftype) { |
8090 | case NL80211_IFTYPE_STATION: | |
8091 | case NL80211_IFTYPE_ADHOC: | |
8092 | case NL80211_IFTYPE_P2P_CLIENT: | |
8093 | case NL80211_IFTYPE_AP: | |
8094 | case NL80211_IFTYPE_AP_VLAN: | |
8095 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8096 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8097 | break; |
8098 | default: | |
f7ca38df | 8099 | return -EOPNOTSUPP; |
71bbc994 | 8100 | } |
f7ca38df JB |
8101 | |
8102 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
8103 | ||
e35e4d28 | 8104 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
8105 | } |
8106 | ||
ffb9eb3d KV |
8107 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
8108 | { | |
4c476991 | 8109 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 8110 | struct wireless_dev *wdev; |
4c476991 | 8111 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8112 | u8 ps_state; |
8113 | bool state; | |
8114 | int err; | |
8115 | ||
4c476991 JB |
8116 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
8117 | return -EINVAL; | |
ffb9eb3d KV |
8118 | |
8119 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
8120 | ||
4c476991 JB |
8121 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
8122 | return -EINVAL; | |
ffb9eb3d KV |
8123 | |
8124 | wdev = dev->ieee80211_ptr; | |
8125 | ||
4c476991 JB |
8126 | if (!rdev->ops->set_power_mgmt) |
8127 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8128 | |
8129 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
8130 | ||
8131 | if (state == wdev->ps) | |
4c476991 | 8132 | return 0; |
ffb9eb3d | 8133 | |
e35e4d28 | 8134 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
8135 | if (!err) |
8136 | wdev->ps = state; | |
ffb9eb3d KV |
8137 | return err; |
8138 | } | |
8139 | ||
8140 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
8141 | { | |
4c476991 | 8142 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
8143 | enum nl80211_ps_state ps_state; |
8144 | struct wireless_dev *wdev; | |
4c476991 | 8145 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8146 | struct sk_buff *msg; |
8147 | void *hdr; | |
8148 | int err; | |
8149 | ||
ffb9eb3d KV |
8150 | wdev = dev->ieee80211_ptr; |
8151 | ||
4c476991 JB |
8152 | if (!rdev->ops->set_power_mgmt) |
8153 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8154 | |
8155 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
8156 | if (!msg) |
8157 | return -ENOMEM; | |
ffb9eb3d | 8158 | |
15e47304 | 8159 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
8160 | NL80211_CMD_GET_POWER_SAVE); |
8161 | if (!hdr) { | |
4c476991 | 8162 | err = -ENOBUFS; |
ffb9eb3d KV |
8163 | goto free_msg; |
8164 | } | |
8165 | ||
8166 | if (wdev->ps) | |
8167 | ps_state = NL80211_PS_ENABLED; | |
8168 | else | |
8169 | ps_state = NL80211_PS_DISABLED; | |
8170 | ||
9360ffd1 DM |
8171 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
8172 | goto nla_put_failure; | |
ffb9eb3d KV |
8173 | |
8174 | genlmsg_end(msg, hdr); | |
4c476991 | 8175 | return genlmsg_reply(msg, info); |
ffb9eb3d | 8176 | |
4c476991 | 8177 | nla_put_failure: |
ffb9eb3d | 8178 | err = -ENOBUFS; |
4c476991 | 8179 | free_msg: |
ffb9eb3d | 8180 | nlmsg_free(msg); |
ffb9eb3d KV |
8181 | return err; |
8182 | } | |
8183 | ||
94e860f1 JB |
8184 | static const struct nla_policy |
8185 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
8186 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
8187 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
8188 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
8189 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
8190 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
8191 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
8192 | }; |
8193 | ||
84f10708 | 8194 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 8195 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
8196 | { |
8197 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 8198 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8199 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 8200 | |
d9d8b019 | 8201 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
8202 | return -EINVAL; |
8203 | ||
84f10708 TP |
8204 | if (!rdev->ops->set_cqm_txe_config) |
8205 | return -EOPNOTSUPP; | |
8206 | ||
8207 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
8208 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
8209 | return -EOPNOTSUPP; | |
8210 | ||
e35e4d28 | 8211 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
8212 | } |
8213 | ||
d6dc1a38 JO |
8214 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
8215 | s32 threshold, u32 hysteresis) | |
8216 | { | |
4c476991 | 8217 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 8218 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8219 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
8220 | |
8221 | if (threshold > 0) | |
8222 | return -EINVAL; | |
8223 | ||
1da5fcc8 JB |
8224 | /* disabling - hysteresis should also be zero then */ |
8225 | if (threshold == 0) | |
8226 | hysteresis = 0; | |
d6dc1a38 | 8227 | |
4c476991 JB |
8228 | if (!rdev->ops->set_cqm_rssi_config) |
8229 | return -EOPNOTSUPP; | |
d6dc1a38 | 8230 | |
074ac8df | 8231 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8232 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8233 | return -EOPNOTSUPP; | |
d6dc1a38 | 8234 | |
e35e4d28 | 8235 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
8236 | } |
8237 | ||
8238 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
8239 | { | |
8240 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
8241 | struct nlattr *cqm; | |
8242 | int err; | |
8243 | ||
8244 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
8245 | if (!cqm) |
8246 | return -EINVAL; | |
d6dc1a38 JO |
8247 | |
8248 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
8249 | nl80211_attr_cqm_policy); | |
8250 | if (err) | |
1da5fcc8 | 8251 | return err; |
d6dc1a38 JO |
8252 | |
8253 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
8254 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
8255 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
8256 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 8257 | |
1da5fcc8 JB |
8258 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
8259 | } | |
8260 | ||
8261 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
8262 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
8263 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
8264 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
8265 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
8266 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
8267 | ||
8268 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
8269 | } | |
8270 | ||
8271 | return -EINVAL; | |
d6dc1a38 JO |
8272 | } |
8273 | ||
29cbe68c JB |
8274 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
8275 | { | |
8276 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8277 | struct net_device *dev = info->user_ptr[1]; | |
8278 | struct mesh_config cfg; | |
c80d545d | 8279 | struct mesh_setup setup; |
29cbe68c JB |
8280 | int err; |
8281 | ||
8282 | /* start with default */ | |
8283 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 8284 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 8285 | |
24bdd9f4 | 8286 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 8287 | /* and parse parameters if given */ |
24bdd9f4 | 8288 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
8289 | if (err) |
8290 | return err; | |
8291 | } | |
8292 | ||
8293 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
8294 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
8295 | return -EINVAL; | |
8296 | ||
c80d545d JC |
8297 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
8298 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
8299 | ||
4bb62344 CYY |
8300 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8301 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
8302 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8303 | return -EINVAL; | |
8304 | ||
9bdbf04d MP |
8305 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
8306 | setup.beacon_interval = | |
8307 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
8308 | if (setup.beacon_interval < 10 || | |
8309 | setup.beacon_interval > 10000) | |
8310 | return -EINVAL; | |
8311 | } | |
8312 | ||
8313 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
8314 | setup.dtim_period = | |
8315 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
8316 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
8317 | return -EINVAL; | |
8318 | } | |
8319 | ||
c80d545d JC |
8320 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
8321 | /* parse additional setup parameters if given */ | |
8322 | err = nl80211_parse_mesh_setup(info, &setup); | |
8323 | if (err) | |
8324 | return err; | |
8325 | } | |
8326 | ||
d37bb18a TP |
8327 | if (setup.user_mpm) |
8328 | cfg.auto_open_plinks = false; | |
8329 | ||
cc1d2806 | 8330 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
8331 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
8332 | if (err) | |
8333 | return err; | |
cc1d2806 JB |
8334 | } else { |
8335 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 8336 | setup.chandef.chan = NULL; |
cc1d2806 JB |
8337 | } |
8338 | ||
ffb3cf30 AN |
8339 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8340 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8341 | int n_rates = | |
8342 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8343 | struct ieee80211_supported_band *sband; | |
8344 | ||
8345 | if (!setup.chandef.chan) | |
8346 | return -EINVAL; | |
8347 | ||
8348 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
8349 | ||
8350 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
8351 | &setup.basic_rates); | |
8352 | if (err) | |
8353 | return err; | |
8354 | } | |
8355 | ||
c80d545d | 8356 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
8357 | } |
8358 | ||
8359 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
8360 | { | |
8361 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8362 | struct net_device *dev = info->user_ptr[1]; | |
8363 | ||
8364 | return cfg80211_leave_mesh(rdev, dev); | |
8365 | } | |
8366 | ||
dfb89c56 | 8367 | #ifdef CONFIG_PM |
bb92d199 AK |
8368 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
8369 | struct cfg80211_registered_device *rdev) | |
8370 | { | |
6abb9cb9 | 8371 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
8372 | struct nlattr *nl_pats, *nl_pat; |
8373 | int i, pat_len; | |
8374 | ||
6abb9cb9 | 8375 | if (!wowlan->n_patterns) |
bb92d199 AK |
8376 | return 0; |
8377 | ||
8378 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
8379 | if (!nl_pats) | |
8380 | return -ENOBUFS; | |
8381 | ||
6abb9cb9 | 8382 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
8383 | nl_pat = nla_nest_start(msg, i + 1); |
8384 | if (!nl_pat) | |
8385 | return -ENOBUFS; | |
6abb9cb9 | 8386 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 8387 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 8388 | wowlan->patterns[i].mask) || |
50ac6607 AK |
8389 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
8390 | wowlan->patterns[i].pattern) || | |
8391 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 8392 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
8393 | return -ENOBUFS; |
8394 | nla_nest_end(msg, nl_pat); | |
8395 | } | |
8396 | nla_nest_end(msg, nl_pats); | |
8397 | ||
8398 | return 0; | |
8399 | } | |
8400 | ||
2a0e047e JB |
8401 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
8402 | struct cfg80211_wowlan_tcp *tcp) | |
8403 | { | |
8404 | struct nlattr *nl_tcp; | |
8405 | ||
8406 | if (!tcp) | |
8407 | return 0; | |
8408 | ||
8409 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
8410 | if (!nl_tcp) | |
8411 | return -ENOBUFS; | |
8412 | ||
8413 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
8414 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
8415 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
8416 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
8417 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
8418 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
8419 | tcp->payload_len, tcp->payload) || | |
8420 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
8421 | tcp->data_interval) || | |
8422 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
8423 | tcp->wake_len, tcp->wake_data) || | |
8424 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
8425 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
8426 | return -ENOBUFS; | |
8427 | ||
8428 | if (tcp->payload_seq.len && | |
8429 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
8430 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
8431 | return -ENOBUFS; | |
8432 | ||
8433 | if (tcp->payload_tok.len && | |
8434 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
8435 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
8436 | &tcp->payload_tok)) | |
8437 | return -ENOBUFS; | |
8438 | ||
e248ad30 JB |
8439 | nla_nest_end(msg, nl_tcp); |
8440 | ||
2a0e047e JB |
8441 | return 0; |
8442 | } | |
8443 | ||
ff1b6e69 JB |
8444 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
8445 | { | |
8446 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8447 | struct sk_buff *msg; | |
8448 | void *hdr; | |
2a0e047e | 8449 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 8450 | |
964dc9e2 | 8451 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
8452 | return -EOPNOTSUPP; |
8453 | ||
6abb9cb9 | 8454 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 8455 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
8456 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
8457 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
8458 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
8459 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
8460 | } |
8461 | ||
8462 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
8463 | if (!msg) |
8464 | return -ENOMEM; | |
8465 | ||
15e47304 | 8466 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
8467 | NL80211_CMD_GET_WOWLAN); |
8468 | if (!hdr) | |
8469 | goto nla_put_failure; | |
8470 | ||
6abb9cb9 | 8471 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
8472 | struct nlattr *nl_wowlan; |
8473 | ||
8474 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
8475 | if (!nl_wowlan) | |
8476 | goto nla_put_failure; | |
8477 | ||
6abb9cb9 | 8478 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 8479 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 8480 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 8481 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 8482 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 8483 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 8484 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 8485 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 8486 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 8487 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 8488 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 8489 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 8490 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
8491 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
8492 | goto nla_put_failure; | |
2a0e047e | 8493 | |
bb92d199 AK |
8494 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
8495 | goto nla_put_failure; | |
2a0e047e | 8496 | |
6abb9cb9 JB |
8497 | if (nl80211_send_wowlan_tcp(msg, |
8498 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e JB |
8499 | goto nla_put_failure; |
8500 | ||
ff1b6e69 JB |
8501 | nla_nest_end(msg, nl_wowlan); |
8502 | } | |
8503 | ||
8504 | genlmsg_end(msg, hdr); | |
8505 | return genlmsg_reply(msg, info); | |
8506 | ||
8507 | nla_put_failure: | |
8508 | nlmsg_free(msg); | |
8509 | return -ENOBUFS; | |
8510 | } | |
8511 | ||
2a0e047e JB |
8512 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
8513 | struct nlattr *attr, | |
8514 | struct cfg80211_wowlan *trig) | |
8515 | { | |
8516 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
8517 | struct cfg80211_wowlan_tcp *cfg; | |
8518 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
8519 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
8520 | u32 size; | |
8521 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
8522 | int err, port; | |
8523 | ||
964dc9e2 | 8524 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
8525 | return -EINVAL; |
8526 | ||
8527 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
8528 | nla_data(attr), nla_len(attr), | |
8529 | nl80211_wowlan_tcp_policy); | |
8530 | if (err) | |
8531 | return err; | |
8532 | ||
8533 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
8534 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
8535 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
8536 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
8537 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
8538 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
8539 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
8540 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
8541 | return -EINVAL; | |
8542 | ||
8543 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 8544 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
8545 | return -EINVAL; |
8546 | ||
8547 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 8548 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 8549 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
8550 | return -EINVAL; |
8551 | ||
8552 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 8553 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
8554 | return -EINVAL; |
8555 | ||
8556 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
8557 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
8558 | return -EINVAL; | |
8559 | ||
8560 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
8561 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8562 | ||
8563 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8564 | tokens_size = tokln - sizeof(*tok); | |
8565 | ||
8566 | if (!tok->len || tokens_size % tok->len) | |
8567 | return -EINVAL; | |
964dc9e2 | 8568 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 8569 | return -EINVAL; |
964dc9e2 | 8570 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 8571 | return -EINVAL; |
964dc9e2 | 8572 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 8573 | return -EINVAL; |
964dc9e2 | 8574 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
8575 | return -EINVAL; |
8576 | if (tok->offset + tok->len > data_size) | |
8577 | return -EINVAL; | |
8578 | } | |
8579 | ||
8580 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
8581 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 8582 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
8583 | return -EINVAL; |
8584 | if (seq->len == 0 || seq->len > 4) | |
8585 | return -EINVAL; | |
8586 | if (seq->len + seq->offset > data_size) | |
8587 | return -EINVAL; | |
8588 | } | |
8589 | ||
8590 | size = sizeof(*cfg); | |
8591 | size += data_size; | |
8592 | size += wake_size + wake_mask_size; | |
8593 | size += tokens_size; | |
8594 | ||
8595 | cfg = kzalloc(size, GFP_KERNEL); | |
8596 | if (!cfg) | |
8597 | return -ENOMEM; | |
8598 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
8599 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
8600 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
8601 | ETH_ALEN); | |
8602 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
8603 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
8604 | else | |
8605 | port = 0; | |
8606 | #ifdef CONFIG_INET | |
8607 | /* allocate a socket and port for it and use it */ | |
8608 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
8609 | IPPROTO_TCP, &cfg->sock, 1); | |
8610 | if (err) { | |
8611 | kfree(cfg); | |
8612 | return err; | |
8613 | } | |
8614 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
8615 | sock_release(cfg->sock); | |
8616 | kfree(cfg); | |
8617 | return -EADDRINUSE; | |
8618 | } | |
8619 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
8620 | #else | |
8621 | if (!port) { | |
8622 | kfree(cfg); | |
8623 | return -EINVAL; | |
8624 | } | |
8625 | cfg->src_port = port; | |
8626 | #endif | |
8627 | ||
8628 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
8629 | cfg->payload_len = data_size; | |
8630 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
8631 | memcpy((void *)cfg->payload, | |
8632 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
8633 | data_size); | |
8634 | if (seq) | |
8635 | cfg->payload_seq = *seq; | |
8636 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
8637 | cfg->wake_len = wake_size; | |
8638 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
8639 | memcpy((void *)cfg->wake_data, | |
8640 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
8641 | wake_size); | |
8642 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
8643 | data_size + wake_size; | |
8644 | memcpy((void *)cfg->wake_mask, | |
8645 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
8646 | wake_mask_size); | |
8647 | if (tok) { | |
8648 | cfg->tokens_size = tokens_size; | |
8649 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
8650 | } | |
8651 | ||
8652 | trig->tcp = cfg; | |
8653 | ||
8654 | return 0; | |
8655 | } | |
8656 | ||
ff1b6e69 JB |
8657 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
8658 | { | |
8659 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8660 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 8661 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 8662 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 8663 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 8664 | int err, i; |
6abb9cb9 | 8665 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 8666 | |
964dc9e2 | 8667 | if (!wowlan) |
ff1b6e69 JB |
8668 | return -EOPNOTSUPP; |
8669 | ||
ae33bd81 JB |
8670 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
8671 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 8672 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
8673 | goto set_wakeup; |
8674 | } | |
ff1b6e69 JB |
8675 | |
8676 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
8677 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8678 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8679 | nl80211_wowlan_policy); | |
8680 | if (err) | |
8681 | return err; | |
8682 | ||
8683 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
8684 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
8685 | return -EINVAL; | |
8686 | new_triggers.any = true; | |
8687 | } | |
8688 | ||
8689 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
8690 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
8691 | return -EINVAL; | |
8692 | new_triggers.disconnect = true; | |
8693 | } | |
8694 | ||
8695 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
8696 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
8697 | return -EINVAL; | |
8698 | new_triggers.magic_pkt = true; | |
8699 | } | |
8700 | ||
77dbbb13 JB |
8701 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
8702 | return -EINVAL; | |
8703 | ||
8704 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
8705 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
8706 | return -EINVAL; | |
8707 | new_triggers.gtk_rekey_failure = true; | |
8708 | } | |
8709 | ||
8710 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
8711 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
8712 | return -EINVAL; | |
8713 | new_triggers.eap_identity_req = true; | |
8714 | } | |
8715 | ||
8716 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
8717 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
8718 | return -EINVAL; | |
8719 | new_triggers.four_way_handshake = true; | |
8720 | } | |
8721 | ||
8722 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
8723 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
8724 | return -EINVAL; | |
8725 | new_triggers.rfkill_release = true; | |
8726 | } | |
8727 | ||
ff1b6e69 JB |
8728 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
8729 | struct nlattr *pat; | |
8730 | int n_patterns = 0; | |
bb92d199 | 8731 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 8732 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 JB |
8733 | |
8734 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8735 | rem) | |
8736 | n_patterns++; | |
8737 | if (n_patterns > wowlan->n_patterns) | |
8738 | return -EINVAL; | |
8739 | ||
8740 | new_triggers.patterns = kcalloc(n_patterns, | |
8741 | sizeof(new_triggers.patterns[0]), | |
8742 | GFP_KERNEL); | |
8743 | if (!new_triggers.patterns) | |
8744 | return -ENOMEM; | |
8745 | ||
8746 | new_triggers.n_patterns = n_patterns; | |
8747 | i = 0; | |
8748 | ||
8749 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8750 | rem) { | |
922bd80f JB |
8751 | u8 *mask_pat; |
8752 | ||
50ac6607 AK |
8753 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
8754 | nla_len(pat), NULL); | |
ff1b6e69 | 8755 | err = -EINVAL; |
50ac6607 AK |
8756 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
8757 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 8758 | goto error; |
50ac6607 | 8759 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 8760 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 8761 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
8762 | goto error; |
8763 | if (pat_len > wowlan->pattern_max_len || | |
8764 | pat_len < wowlan->pattern_min_len) | |
8765 | goto error; | |
8766 | ||
50ac6607 | 8767 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
8768 | pkt_offset = 0; |
8769 | else | |
8770 | pkt_offset = nla_get_u32( | |
50ac6607 | 8771 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
8772 | if (pkt_offset > wowlan->max_pkt_offset) |
8773 | goto error; | |
8774 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
8775 | ||
922bd80f JB |
8776 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
8777 | if (!mask_pat) { | |
ff1b6e69 JB |
8778 | err = -ENOMEM; |
8779 | goto error; | |
8780 | } | |
922bd80f JB |
8781 | new_triggers.patterns[i].mask = mask_pat; |
8782 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 8783 | mask_len); |
922bd80f JB |
8784 | mask_pat += mask_len; |
8785 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 8786 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 8787 | memcpy(mask_pat, |
50ac6607 | 8788 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
8789 | pat_len); |
8790 | i++; | |
8791 | } | |
8792 | } | |
8793 | ||
2a0e047e JB |
8794 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
8795 | err = nl80211_parse_wowlan_tcp( | |
8796 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
8797 | &new_triggers); | |
8798 | if (err) | |
8799 | goto error; | |
8800 | } | |
8801 | ||
ae33bd81 JB |
8802 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
8803 | if (!ntrig) { | |
8804 | err = -ENOMEM; | |
8805 | goto error; | |
ff1b6e69 | 8806 | } |
ae33bd81 | 8807 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 8808 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 8809 | |
ae33bd81 | 8810 | set_wakeup: |
6abb9cb9 JB |
8811 | if (rdev->ops->set_wakeup && |
8812 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
8813 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 8814 | |
ff1b6e69 JB |
8815 | return 0; |
8816 | error: | |
8817 | for (i = 0; i < new_triggers.n_patterns; i++) | |
8818 | kfree(new_triggers.patterns[i].mask); | |
8819 | kfree(new_triggers.patterns); | |
2a0e047e JB |
8820 | if (new_triggers.tcp && new_triggers.tcp->sock) |
8821 | sock_release(new_triggers.tcp->sock); | |
8822 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
8823 | return err; |
8824 | } | |
dfb89c56 | 8825 | #endif |
ff1b6e69 | 8826 | |
be29b99a AK |
8827 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
8828 | struct cfg80211_registered_device *rdev) | |
8829 | { | |
8830 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
8831 | int i, j, pat_len; | |
8832 | struct cfg80211_coalesce_rules *rule; | |
8833 | ||
8834 | if (!rdev->coalesce->n_rules) | |
8835 | return 0; | |
8836 | ||
8837 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
8838 | if (!nl_rules) | |
8839 | return -ENOBUFS; | |
8840 | ||
8841 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
8842 | nl_rule = nla_nest_start(msg, i + 1); | |
8843 | if (!nl_rule) | |
8844 | return -ENOBUFS; | |
8845 | ||
8846 | rule = &rdev->coalesce->rules[i]; | |
8847 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
8848 | rule->delay)) | |
8849 | return -ENOBUFS; | |
8850 | ||
8851 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
8852 | rule->condition)) | |
8853 | return -ENOBUFS; | |
8854 | ||
8855 | nl_pats = nla_nest_start(msg, | |
8856 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
8857 | if (!nl_pats) | |
8858 | return -ENOBUFS; | |
8859 | ||
8860 | for (j = 0; j < rule->n_patterns; j++) { | |
8861 | nl_pat = nla_nest_start(msg, j + 1); | |
8862 | if (!nl_pat) | |
8863 | return -ENOBUFS; | |
8864 | pat_len = rule->patterns[j].pattern_len; | |
8865 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
8866 | DIV_ROUND_UP(pat_len, 8), | |
8867 | rule->patterns[j].mask) || | |
8868 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
8869 | rule->patterns[j].pattern) || | |
8870 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
8871 | rule->patterns[j].pkt_offset)) | |
8872 | return -ENOBUFS; | |
8873 | nla_nest_end(msg, nl_pat); | |
8874 | } | |
8875 | nla_nest_end(msg, nl_pats); | |
8876 | nla_nest_end(msg, nl_rule); | |
8877 | } | |
8878 | nla_nest_end(msg, nl_rules); | |
8879 | ||
8880 | return 0; | |
8881 | } | |
8882 | ||
8883 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8884 | { | |
8885 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8886 | struct sk_buff *msg; | |
8887 | void *hdr; | |
8888 | ||
8889 | if (!rdev->wiphy.coalesce) | |
8890 | return -EOPNOTSUPP; | |
8891 | ||
8892 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8893 | if (!msg) | |
8894 | return -ENOMEM; | |
8895 | ||
8896 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8897 | NL80211_CMD_GET_COALESCE); | |
8898 | if (!hdr) | |
8899 | goto nla_put_failure; | |
8900 | ||
8901 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
8902 | goto nla_put_failure; | |
8903 | ||
8904 | genlmsg_end(msg, hdr); | |
8905 | return genlmsg_reply(msg, info); | |
8906 | ||
8907 | nla_put_failure: | |
8908 | nlmsg_free(msg); | |
8909 | return -ENOBUFS; | |
8910 | } | |
8911 | ||
8912 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
8913 | { | |
8914 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
8915 | int i, j; | |
8916 | struct cfg80211_coalesce_rules *rule; | |
8917 | ||
8918 | if (!coalesce) | |
8919 | return; | |
8920 | ||
8921 | for (i = 0; i < coalesce->n_rules; i++) { | |
8922 | rule = &coalesce->rules[i]; | |
8923 | for (j = 0; j < rule->n_patterns; j++) | |
8924 | kfree(rule->patterns[j].mask); | |
8925 | kfree(rule->patterns); | |
8926 | } | |
8927 | kfree(coalesce->rules); | |
8928 | kfree(coalesce); | |
8929 | rdev->coalesce = NULL; | |
8930 | } | |
8931 | ||
8932 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
8933 | struct nlattr *rule, | |
8934 | struct cfg80211_coalesce_rules *new_rule) | |
8935 | { | |
8936 | int err, i; | |
8937 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8938 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
8939 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
8940 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
8941 | ||
8942 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
8943 | nla_len(rule), nl80211_coalesce_policy); | |
8944 | if (err) | |
8945 | return err; | |
8946 | ||
8947 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
8948 | new_rule->delay = | |
8949 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
8950 | if (new_rule->delay > coalesce->max_delay) | |
8951 | return -EINVAL; | |
8952 | ||
8953 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
8954 | new_rule->condition = | |
8955 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
8956 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
8957 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
8958 | return -EINVAL; | |
8959 | ||
8960 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
8961 | return -EINVAL; | |
8962 | ||
8963 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8964 | rem) | |
8965 | n_patterns++; | |
8966 | if (n_patterns > coalesce->n_patterns) | |
8967 | return -EINVAL; | |
8968 | ||
8969 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
8970 | GFP_KERNEL); | |
8971 | if (!new_rule->patterns) | |
8972 | return -ENOMEM; | |
8973 | ||
8974 | new_rule->n_patterns = n_patterns; | |
8975 | i = 0; | |
8976 | ||
8977 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8978 | rem) { | |
922bd80f JB |
8979 | u8 *mask_pat; |
8980 | ||
be29b99a AK |
8981 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
8982 | nla_len(pat), NULL); | |
8983 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
8984 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
8985 | return -EINVAL; | |
8986 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
8987 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
8988 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
8989 | return -EINVAL; | |
8990 | if (pat_len > coalesce->pattern_max_len || | |
8991 | pat_len < coalesce->pattern_min_len) | |
8992 | return -EINVAL; | |
8993 | ||
8994 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
8995 | pkt_offset = 0; | |
8996 | else | |
8997 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
8998 | if (pkt_offset > coalesce->max_pkt_offset) | |
8999 | return -EINVAL; | |
9000 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
9001 | ||
922bd80f JB |
9002 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9003 | if (!mask_pat) | |
be29b99a | 9004 | return -ENOMEM; |
922bd80f JB |
9005 | |
9006 | new_rule->patterns[i].mask = mask_pat; | |
9007 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
9008 | mask_len); | |
9009 | ||
9010 | mask_pat += mask_len; | |
9011 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 9012 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
9013 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
9014 | pat_len); | |
be29b99a AK |
9015 | i++; |
9016 | } | |
9017 | ||
9018 | return 0; | |
9019 | } | |
9020 | ||
9021 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9022 | { | |
9023 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9024 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9025 | struct cfg80211_coalesce new_coalesce = {}; | |
9026 | struct cfg80211_coalesce *n_coalesce; | |
9027 | int err, rem_rule, n_rules = 0, i, j; | |
9028 | struct nlattr *rule; | |
9029 | struct cfg80211_coalesce_rules *tmp_rule; | |
9030 | ||
9031 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
9032 | return -EOPNOTSUPP; | |
9033 | ||
9034 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
9035 | cfg80211_rdev_free_coalesce(rdev); | |
9036 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
9037 | return 0; | |
9038 | } | |
9039 | ||
9040 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9041 | rem_rule) | |
9042 | n_rules++; | |
9043 | if (n_rules > coalesce->n_rules) | |
9044 | return -EINVAL; | |
9045 | ||
9046 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
9047 | GFP_KERNEL); | |
9048 | if (!new_coalesce.rules) | |
9049 | return -ENOMEM; | |
9050 | ||
9051 | new_coalesce.n_rules = n_rules; | |
9052 | i = 0; | |
9053 | ||
9054 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9055 | rem_rule) { | |
9056 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
9057 | &new_coalesce.rules[i]); | |
9058 | if (err) | |
9059 | goto error; | |
9060 | ||
9061 | i++; | |
9062 | } | |
9063 | ||
9064 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
9065 | if (err) | |
9066 | goto error; | |
9067 | ||
9068 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
9069 | if (!n_coalesce) { | |
9070 | err = -ENOMEM; | |
9071 | goto error; | |
9072 | } | |
9073 | cfg80211_rdev_free_coalesce(rdev); | |
9074 | rdev->coalesce = n_coalesce; | |
9075 | ||
9076 | return 0; | |
9077 | error: | |
9078 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
9079 | tmp_rule = &new_coalesce.rules[i]; | |
9080 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
9081 | kfree(tmp_rule->patterns[j].mask); | |
9082 | kfree(tmp_rule->patterns); | |
9083 | } | |
9084 | kfree(new_coalesce.rules); | |
9085 | ||
9086 | return err; | |
9087 | } | |
9088 | ||
e5497d76 JB |
9089 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
9090 | { | |
9091 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9092 | struct net_device *dev = info->user_ptr[1]; | |
9093 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9094 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
9095 | struct cfg80211_gtk_rekey_data rekey_data; | |
9096 | int err; | |
9097 | ||
9098 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
9099 | return -EINVAL; | |
9100 | ||
9101 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
9102 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9103 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9104 | nl80211_rekey_policy); | |
9105 | if (err) | |
9106 | return err; | |
9107 | ||
9108 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
9109 | return -ERANGE; | |
9110 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
9111 | return -ERANGE; | |
9112 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
9113 | return -ERANGE; | |
9114 | ||
78f686ca JB |
9115 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
9116 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | |
9117 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | |
e5497d76 JB |
9118 | |
9119 | wdev_lock(wdev); | |
9120 | if (!wdev->current_bss) { | |
9121 | err = -ENOTCONN; | |
9122 | goto out; | |
9123 | } | |
9124 | ||
9125 | if (!rdev->ops->set_rekey_data) { | |
9126 | err = -EOPNOTSUPP; | |
9127 | goto out; | |
9128 | } | |
9129 | ||
e35e4d28 | 9130 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
9131 | out: |
9132 | wdev_unlock(wdev); | |
9133 | return err; | |
9134 | } | |
9135 | ||
28946da7 JB |
9136 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
9137 | struct genl_info *info) | |
9138 | { | |
9139 | struct net_device *dev = info->user_ptr[1]; | |
9140 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9141 | ||
9142 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9143 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9144 | return -EINVAL; | |
9145 | ||
15e47304 | 9146 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
9147 | return -EBUSY; |
9148 | ||
15e47304 | 9149 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
9150 | return 0; |
9151 | } | |
9152 | ||
7f6cf311 JB |
9153 | static int nl80211_probe_client(struct sk_buff *skb, |
9154 | struct genl_info *info) | |
9155 | { | |
9156 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9157 | struct net_device *dev = info->user_ptr[1]; | |
9158 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9159 | struct sk_buff *msg; | |
9160 | void *hdr; | |
9161 | const u8 *addr; | |
9162 | u64 cookie; | |
9163 | int err; | |
9164 | ||
9165 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9166 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9167 | return -EOPNOTSUPP; | |
9168 | ||
9169 | if (!info->attrs[NL80211_ATTR_MAC]) | |
9170 | return -EINVAL; | |
9171 | ||
9172 | if (!rdev->ops->probe_client) | |
9173 | return -EOPNOTSUPP; | |
9174 | ||
9175 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9176 | if (!msg) | |
9177 | return -ENOMEM; | |
9178 | ||
15e47304 | 9179 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 9180 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
9181 | if (!hdr) { |
9182 | err = -ENOBUFS; | |
7f6cf311 JB |
9183 | goto free_msg; |
9184 | } | |
9185 | ||
9186 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9187 | ||
e35e4d28 | 9188 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
9189 | if (err) |
9190 | goto free_msg; | |
9191 | ||
9360ffd1 DM |
9192 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9193 | goto nla_put_failure; | |
7f6cf311 JB |
9194 | |
9195 | genlmsg_end(msg, hdr); | |
9196 | ||
9197 | return genlmsg_reply(msg, info); | |
9198 | ||
9199 | nla_put_failure: | |
9200 | err = -ENOBUFS; | |
9201 | free_msg: | |
9202 | nlmsg_free(msg); | |
9203 | return err; | |
9204 | } | |
9205 | ||
5e760230 JB |
9206 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
9207 | { | |
9208 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
9209 | struct cfg80211_beacon_registration *reg, *nreg; |
9210 | int rv; | |
5e760230 JB |
9211 | |
9212 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
9213 | return -EOPNOTSUPP; | |
9214 | ||
37c73b5f BG |
9215 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
9216 | if (!nreg) | |
9217 | return -ENOMEM; | |
9218 | ||
9219 | /* First, check if already registered. */ | |
9220 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
9221 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
9222 | if (reg->nlportid == info->snd_portid) { | |
9223 | rv = -EALREADY; | |
9224 | goto out_err; | |
9225 | } | |
9226 | } | |
9227 | /* Add it to the list */ | |
9228 | nreg->nlportid = info->snd_portid; | |
9229 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 9230 | |
37c73b5f | 9231 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
9232 | |
9233 | return 0; | |
37c73b5f BG |
9234 | out_err: |
9235 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
9236 | kfree(nreg); | |
9237 | return rv; | |
5e760230 JB |
9238 | } |
9239 | ||
98104fde JB |
9240 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
9241 | { | |
9242 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9243 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9244 | int err; | |
9245 | ||
9246 | if (!rdev->ops->start_p2p_device) | |
9247 | return -EOPNOTSUPP; | |
9248 | ||
9249 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9250 | return -EOPNOTSUPP; | |
9251 | ||
9252 | if (wdev->p2p_started) | |
9253 | return 0; | |
9254 | ||
b6a55015 LC |
9255 | if (rfkill_blocked(rdev->rfkill)) |
9256 | return -ERFKILL; | |
98104fde | 9257 | |
eeb126e9 | 9258 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
9259 | if (err) |
9260 | return err; | |
9261 | ||
9262 | wdev->p2p_started = true; | |
98104fde | 9263 | rdev->opencount++; |
98104fde JB |
9264 | |
9265 | return 0; | |
9266 | } | |
9267 | ||
9268 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
9269 | { | |
9270 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9271 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9272 | ||
9273 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9274 | return -EOPNOTSUPP; | |
9275 | ||
9276 | if (!rdev->ops->stop_p2p_device) | |
9277 | return -EOPNOTSUPP; | |
9278 | ||
f9f47529 | 9279 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
9280 | |
9281 | return 0; | |
9282 | } | |
9283 | ||
3713b4e3 JB |
9284 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
9285 | struct genl_info *info) | |
9286 | { | |
9287 | void *hdr; | |
9288 | struct sk_buff *msg; | |
9289 | ||
9290 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9291 | if (!msg) | |
9292 | return -ENOMEM; | |
9293 | ||
9294 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9295 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
9296 | if (!hdr) | |
9297 | goto nla_put_failure; | |
9298 | ||
9299 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
9300 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
9301 | goto nla_put_failure; | |
9302 | ||
9303 | genlmsg_end(msg, hdr); | |
9304 | return genlmsg_reply(msg, info); | |
9305 | ||
9306 | nla_put_failure: | |
9307 | kfree_skb(msg); | |
9308 | return -ENOBUFS; | |
9309 | } | |
9310 | ||
355199e0 JM |
9311 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
9312 | { | |
9313 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9314 | struct cfg80211_update_ft_ies_params ft_params; | |
9315 | struct net_device *dev = info->user_ptr[1]; | |
9316 | ||
9317 | if (!rdev->ops->update_ft_ies) | |
9318 | return -EOPNOTSUPP; | |
9319 | ||
9320 | if (!info->attrs[NL80211_ATTR_MDID] || | |
9321 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
9322 | return -EINVAL; | |
9323 | ||
9324 | memset(&ft_params, 0, sizeof(ft_params)); | |
9325 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
9326 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
9327 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9328 | ||
9329 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
9330 | } | |
9331 | ||
5de17984 AS |
9332 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
9333 | struct genl_info *info) | |
9334 | { | |
9335 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9336 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9337 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
9338 | u16 duration; | |
9339 | int ret; | |
9340 | ||
9341 | if (!rdev->ops->crit_proto_start) | |
9342 | return -EOPNOTSUPP; | |
9343 | ||
9344 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
9345 | return -EINVAL; | |
9346 | ||
9347 | if (rdev->crit_proto_nlportid) | |
9348 | return -EBUSY; | |
9349 | ||
9350 | /* determine protocol if provided */ | |
9351 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
9352 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
9353 | ||
9354 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
9355 | return -EINVAL; | |
9356 | ||
9357 | /* timeout must be provided */ | |
9358 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
9359 | return -EINVAL; | |
9360 | ||
9361 | duration = | |
9362 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
9363 | ||
9364 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
9365 | return -ERANGE; | |
9366 | ||
9367 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
9368 | if (!ret) | |
9369 | rdev->crit_proto_nlportid = info->snd_portid; | |
9370 | ||
9371 | return ret; | |
9372 | } | |
9373 | ||
9374 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
9375 | struct genl_info *info) | |
9376 | { | |
9377 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9378 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9379 | ||
9380 | if (!rdev->ops->crit_proto_stop) | |
9381 | return -EOPNOTSUPP; | |
9382 | ||
9383 | if (rdev->crit_proto_nlportid) { | |
9384 | rdev->crit_proto_nlportid = 0; | |
9385 | rdev_crit_proto_stop(rdev, wdev); | |
9386 | } | |
9387 | return 0; | |
9388 | } | |
9389 | ||
ad7e718c JB |
9390 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
9391 | { | |
9392 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9393 | struct wireless_dev *wdev = | |
9394 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
9395 | int i, err; | |
9396 | u32 vid, subcmd; | |
9397 | ||
9398 | if (!rdev->wiphy.vendor_commands) | |
9399 | return -EOPNOTSUPP; | |
9400 | ||
9401 | if (IS_ERR(wdev)) { | |
9402 | err = PTR_ERR(wdev); | |
9403 | if (err != -EINVAL) | |
9404 | return err; | |
9405 | wdev = NULL; | |
9406 | } else if (wdev->wiphy != &rdev->wiphy) { | |
9407 | return -EINVAL; | |
9408 | } | |
9409 | ||
9410 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
9411 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
9412 | return -EINVAL; | |
9413 | ||
9414 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
9415 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
9416 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
9417 | const struct wiphy_vendor_command *vcmd; | |
9418 | void *data = NULL; | |
9419 | int len = 0; | |
9420 | ||
9421 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
9422 | ||
9423 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
9424 | continue; | |
9425 | ||
9426 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
9427 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
9428 | if (!wdev) | |
9429 | return -EINVAL; | |
9430 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
9431 | !wdev->netdev) | |
9432 | return -EINVAL; | |
9433 | ||
9434 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
9435 | if (wdev->netdev && | |
9436 | !netif_running(wdev->netdev)) | |
9437 | return -ENETDOWN; | |
9438 | if (!wdev->netdev && !wdev->p2p_started) | |
9439 | return -ENETDOWN; | |
9440 | } | |
9441 | } else { | |
9442 | wdev = NULL; | |
9443 | } | |
9444 | ||
9445 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
9446 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9447 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9448 | } | |
9449 | ||
9450 | rdev->cur_cmd_info = info; | |
9451 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
9452 | data, len); | |
9453 | rdev->cur_cmd_info = NULL; | |
9454 | return err; | |
9455 | } | |
9456 | ||
9457 | return -EOPNOTSUPP; | |
9458 | } | |
9459 | ||
9460 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | |
9461 | enum nl80211_commands cmd, | |
9462 | enum nl80211_attrs attr, | |
9463 | int approxlen) | |
9464 | { | |
f26cbf40 | 9465 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
9466 | |
9467 | if (WARN_ON(!rdev->cur_cmd_info)) | |
9468 | return NULL; | |
9469 | ||
9470 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, | |
9471 | rdev->cur_cmd_info->snd_portid, | |
9472 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 9473 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
9474 | } |
9475 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
9476 | ||
9477 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
9478 | { | |
9479 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
9480 | void *hdr = ((void **)skb->cb)[1]; | |
9481 | struct nlattr *data = ((void **)skb->cb)[2]; | |
9482 | ||
bd8c78e7 JB |
9483 | /* clear CB data for netlink core to own from now on */ |
9484 | memset(skb->cb, 0, sizeof(skb->cb)); | |
9485 | ||
ad7e718c JB |
9486 | if (WARN_ON(!rdev->cur_cmd_info)) { |
9487 | kfree_skb(skb); | |
9488 | return -EINVAL; | |
9489 | } | |
9490 | ||
9491 | nla_nest_end(skb, data); | |
9492 | genlmsg_end(skb, hdr); | |
9493 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
9494 | } | |
9495 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
9496 | ||
9497 | ||
fa9ffc74 KP |
9498 | static int nl80211_set_qos_map(struct sk_buff *skb, |
9499 | struct genl_info *info) | |
9500 | { | |
9501 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9502 | struct cfg80211_qos_map *qos_map = NULL; | |
9503 | struct net_device *dev = info->user_ptr[1]; | |
9504 | u8 *pos, len, num_des, des_len, des; | |
9505 | int ret; | |
9506 | ||
9507 | if (!rdev->ops->set_qos_map) | |
9508 | return -EOPNOTSUPP; | |
9509 | ||
9510 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
9511 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9512 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9513 | ||
9514 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
9515 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
9516 | return -EINVAL; | |
9517 | ||
9518 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
9519 | if (!qos_map) | |
9520 | return -ENOMEM; | |
9521 | ||
9522 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
9523 | if (num_des) { | |
9524 | des_len = num_des * | |
9525 | sizeof(struct cfg80211_dscp_exception); | |
9526 | memcpy(qos_map->dscp_exception, pos, des_len); | |
9527 | qos_map->num_des = num_des; | |
9528 | for (des = 0; des < num_des; des++) { | |
9529 | if (qos_map->dscp_exception[des].up > 7) { | |
9530 | kfree(qos_map); | |
9531 | return -EINVAL; | |
9532 | } | |
9533 | } | |
9534 | pos += des_len; | |
9535 | } | |
9536 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
9537 | } | |
9538 | ||
9539 | wdev_lock(dev->ieee80211_ptr); | |
9540 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
9541 | if (!ret) | |
9542 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
9543 | wdev_unlock(dev->ieee80211_ptr); | |
9544 | ||
9545 | kfree(qos_map); | |
9546 | return ret; | |
9547 | } | |
9548 | ||
960d01ac JB |
9549 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
9550 | { | |
9551 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9552 | struct net_device *dev = info->user_ptr[1]; | |
9553 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9554 | const u8 *peer; | |
9555 | u8 tsid, up; | |
9556 | u16 admitted_time = 0; | |
9557 | int err; | |
9558 | ||
723e73ac | 9559 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
960d01ac JB |
9560 | return -EOPNOTSUPP; |
9561 | ||
9562 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | |
9563 | !info->attrs[NL80211_ATTR_USER_PRIO]) | |
9564 | return -EINVAL; | |
9565 | ||
9566 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
9567 | if (tsid >= IEEE80211_NUM_TIDS) | |
9568 | return -EINVAL; | |
9569 | ||
9570 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); | |
9571 | if (up >= IEEE80211_NUM_UPS) | |
9572 | return -EINVAL; | |
9573 | ||
9574 | /* WMM uses TIDs 0-7 even for TSPEC */ | |
723e73ac | 9575 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
960d01ac | 9576 | /* TODO: handle 802.11 TSPEC/admission control |
723e73ac JB |
9577 | * need more attributes for that (e.g. BA session requirement); |
9578 | * change the WMM adminssion test above to allow both then | |
960d01ac JB |
9579 | */ |
9580 | return -EINVAL; | |
9581 | } | |
9582 | ||
9583 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9584 | ||
9585 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | |
9586 | admitted_time = | |
9587 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | |
9588 | if (!admitted_time) | |
9589 | return -EINVAL; | |
9590 | } | |
9591 | ||
9592 | wdev_lock(wdev); | |
9593 | switch (wdev->iftype) { | |
9594 | case NL80211_IFTYPE_STATION: | |
9595 | case NL80211_IFTYPE_P2P_CLIENT: | |
9596 | if (wdev->current_bss) | |
9597 | break; | |
9598 | err = -ENOTCONN; | |
9599 | goto out; | |
9600 | default: | |
9601 | err = -EOPNOTSUPP; | |
9602 | goto out; | |
9603 | } | |
9604 | ||
9605 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | |
9606 | ||
9607 | out: | |
9608 | wdev_unlock(wdev); | |
9609 | return err; | |
9610 | } | |
9611 | ||
9612 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | |
9613 | { | |
9614 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9615 | struct net_device *dev = info->user_ptr[1]; | |
9616 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9617 | const u8 *peer; | |
9618 | u8 tsid; | |
9619 | int err; | |
9620 | ||
9621 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | |
9622 | return -EINVAL; | |
9623 | ||
9624 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
9625 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9626 | ||
9627 | wdev_lock(wdev); | |
9628 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | |
9629 | wdev_unlock(wdev); | |
9630 | ||
9631 | return err; | |
9632 | } | |
9633 | ||
4c476991 JB |
9634 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
9635 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
9636 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
9637 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
9638 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
9639 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 9640 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 9641 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
9642 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
9643 | NL80211_FLAG_CHECK_NETDEV_UP) | |
5393b917 | 9644 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
4c476991 | 9645 | |
f84f771d | 9646 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
9647 | struct genl_info *info) |
9648 | { | |
9649 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 9650 | struct wireless_dev *wdev; |
4c476991 | 9651 | struct net_device *dev; |
4c476991 JB |
9652 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
9653 | ||
9654 | if (rtnl) | |
9655 | rtnl_lock(); | |
9656 | ||
9657 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 9658 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
9659 | if (IS_ERR(rdev)) { |
9660 | if (rtnl) | |
9661 | rtnl_unlock(); | |
9662 | return PTR_ERR(rdev); | |
9663 | } | |
9664 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
9665 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
9666 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
9667 | ASSERT_RTNL(); |
9668 | ||
89a54e48 JB |
9669 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
9670 | info->attrs); | |
9671 | if (IS_ERR(wdev)) { | |
4c476991 JB |
9672 | if (rtnl) |
9673 | rtnl_unlock(); | |
89a54e48 | 9674 | return PTR_ERR(wdev); |
4c476991 | 9675 | } |
89a54e48 | 9676 | |
89a54e48 | 9677 | dev = wdev->netdev; |
f26cbf40 | 9678 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 9679 | |
1bf614ef JB |
9680 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
9681 | if (!dev) { | |
1bf614ef JB |
9682 | if (rtnl) |
9683 | rtnl_unlock(); | |
9684 | return -EINVAL; | |
9685 | } | |
9686 | ||
9687 | info->user_ptr[1] = dev; | |
9688 | } else { | |
9689 | info->user_ptr[1] = wdev; | |
41265714 | 9690 | } |
1bf614ef JB |
9691 | |
9692 | if (dev) { | |
9693 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
9694 | !netif_running(dev)) { | |
1bf614ef JB |
9695 | if (rtnl) |
9696 | rtnl_unlock(); | |
9697 | return -ENETDOWN; | |
9698 | } | |
9699 | ||
9700 | dev_hold(dev); | |
98104fde JB |
9701 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
9702 | if (!wdev->p2p_started) { | |
98104fde JB |
9703 | if (rtnl) |
9704 | rtnl_unlock(); | |
9705 | return -ENETDOWN; | |
9706 | } | |
41265714 | 9707 | } |
89a54e48 | 9708 | |
4c476991 | 9709 | info->user_ptr[0] = rdev; |
4c476991 JB |
9710 | } |
9711 | ||
9712 | return 0; | |
9713 | } | |
9714 | ||
f84f771d | 9715 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
9716 | struct genl_info *info) |
9717 | { | |
1bf614ef JB |
9718 | if (info->user_ptr[1]) { |
9719 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
9720 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9721 | ||
9722 | if (wdev->netdev) | |
9723 | dev_put(wdev->netdev); | |
9724 | } else { | |
9725 | dev_put(info->user_ptr[1]); | |
9726 | } | |
9727 | } | |
5393b917 | 9728 | |
4c476991 JB |
9729 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
9730 | rtnl_unlock(); | |
5393b917 JB |
9731 | |
9732 | /* If needed, clear the netlink message payload from the SKB | |
9733 | * as it might contain key data that shouldn't stick around on | |
9734 | * the heap after the SKB is freed. The netlink message header | |
9735 | * is still needed for further processing, so leave it intact. | |
9736 | */ | |
9737 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | |
9738 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | |
9739 | ||
9740 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | |
9741 | } | |
4c476991 JB |
9742 | } |
9743 | ||
4534de83 | 9744 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
9745 | { |
9746 | .cmd = NL80211_CMD_GET_WIPHY, | |
9747 | .doit = nl80211_get_wiphy, | |
9748 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 9749 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
9750 | .policy = nl80211_policy, |
9751 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
9752 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9753 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9754 | }, |
9755 | { | |
9756 | .cmd = NL80211_CMD_SET_WIPHY, | |
9757 | .doit = nl80211_set_wiphy, | |
9758 | .policy = nl80211_policy, | |
9759 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 9760 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
9761 | }, |
9762 | { | |
9763 | .cmd = NL80211_CMD_GET_INTERFACE, | |
9764 | .doit = nl80211_get_interface, | |
9765 | .dumpit = nl80211_dump_interface, | |
9766 | .policy = nl80211_policy, | |
9767 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
9768 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
9769 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9770 | }, |
9771 | { | |
9772 | .cmd = NL80211_CMD_SET_INTERFACE, | |
9773 | .doit = nl80211_set_interface, | |
9774 | .policy = nl80211_policy, | |
9775 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9776 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9777 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9778 | }, |
9779 | { | |
9780 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
9781 | .doit = nl80211_new_interface, | |
9782 | .policy = nl80211_policy, | |
9783 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9784 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9785 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9786 | }, |
9787 | { | |
9788 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
9789 | .doit = nl80211_del_interface, | |
9790 | .policy = nl80211_policy, | |
41ade00f | 9791 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 9792 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 9793 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9794 | }, |
9795 | { | |
9796 | .cmd = NL80211_CMD_GET_KEY, | |
9797 | .doit = nl80211_get_key, | |
9798 | .policy = nl80211_policy, | |
9799 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9800 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9801 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9802 | }, |
9803 | { | |
9804 | .cmd = NL80211_CMD_SET_KEY, | |
9805 | .doit = nl80211_set_key, | |
9806 | .policy = nl80211_policy, | |
9807 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9808 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
9809 | NL80211_FLAG_NEED_RTNL | |
9810 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
9811 | }, |
9812 | { | |
9813 | .cmd = NL80211_CMD_NEW_KEY, | |
9814 | .doit = nl80211_new_key, | |
9815 | .policy = nl80211_policy, | |
9816 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9817 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
9818 | NL80211_FLAG_NEED_RTNL | |
9819 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
9820 | }, |
9821 | { | |
9822 | .cmd = NL80211_CMD_DEL_KEY, | |
9823 | .doit = nl80211_del_key, | |
9824 | .policy = nl80211_policy, | |
55682965 | 9825 | .flags = GENL_ADMIN_PERM, |
41265714 | 9826 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9827 | NL80211_FLAG_NEED_RTNL, |
55682965 | 9828 | }, |
ed1b6cc7 JB |
9829 | { |
9830 | .cmd = NL80211_CMD_SET_BEACON, | |
9831 | .policy = nl80211_policy, | |
9832 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9833 | .doit = nl80211_set_beacon, |
2b5f8b0b | 9834 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9835 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
9836 | }, |
9837 | { | |
8860020e | 9838 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
9839 | .policy = nl80211_policy, |
9840 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9841 | .doit = nl80211_start_ap, |
2b5f8b0b | 9842 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9843 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
9844 | }, |
9845 | { | |
8860020e | 9846 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
9847 | .policy = nl80211_policy, |
9848 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9849 | .doit = nl80211_stop_ap, |
2b5f8b0b | 9850 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9851 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 9852 | }, |
5727ef1b JB |
9853 | { |
9854 | .cmd = NL80211_CMD_GET_STATION, | |
9855 | .doit = nl80211_get_station, | |
2ec600d6 | 9856 | .dumpit = nl80211_dump_station, |
5727ef1b | 9857 | .policy = nl80211_policy, |
4c476991 JB |
9858 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9859 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
9860 | }, |
9861 | { | |
9862 | .cmd = NL80211_CMD_SET_STATION, | |
9863 | .doit = nl80211_set_station, | |
9864 | .policy = nl80211_policy, | |
9865 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9866 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9867 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
9868 | }, |
9869 | { | |
9870 | .cmd = NL80211_CMD_NEW_STATION, | |
9871 | .doit = nl80211_new_station, | |
9872 | .policy = nl80211_policy, | |
9873 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9874 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9875 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
9876 | }, |
9877 | { | |
9878 | .cmd = NL80211_CMD_DEL_STATION, | |
9879 | .doit = nl80211_del_station, | |
9880 | .policy = nl80211_policy, | |
2ec600d6 | 9881 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9882 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9883 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9884 | }, |
9885 | { | |
9886 | .cmd = NL80211_CMD_GET_MPATH, | |
9887 | .doit = nl80211_get_mpath, | |
9888 | .dumpit = nl80211_dump_mpath, | |
9889 | .policy = nl80211_policy, | |
9890 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9891 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9892 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 | 9893 | }, |
66be7d2b HR |
9894 | { |
9895 | .cmd = NL80211_CMD_GET_MPP, | |
9896 | .doit = nl80211_get_mpp, | |
9897 | .dumpit = nl80211_dump_mpp, | |
9898 | .policy = nl80211_policy, | |
9899 | .flags = GENL_ADMIN_PERM, | |
9900 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9901 | NL80211_FLAG_NEED_RTNL, | |
9902 | }, | |
2ec600d6 LCC |
9903 | { |
9904 | .cmd = NL80211_CMD_SET_MPATH, | |
9905 | .doit = nl80211_set_mpath, | |
9906 | .policy = nl80211_policy, | |
9907 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9908 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9909 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9910 | }, |
9911 | { | |
9912 | .cmd = NL80211_CMD_NEW_MPATH, | |
9913 | .doit = nl80211_new_mpath, | |
9914 | .policy = nl80211_policy, | |
9915 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9916 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9917 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9918 | }, |
9919 | { | |
9920 | .cmd = NL80211_CMD_DEL_MPATH, | |
9921 | .doit = nl80211_del_mpath, | |
9922 | .policy = nl80211_policy, | |
9f1ba906 | 9923 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9924 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9925 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
9926 | }, |
9927 | { | |
9928 | .cmd = NL80211_CMD_SET_BSS, | |
9929 | .doit = nl80211_set_bss, | |
9930 | .policy = nl80211_policy, | |
b2e1b302 | 9931 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9932 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9933 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 9934 | }, |
f130347c LR |
9935 | { |
9936 | .cmd = NL80211_CMD_GET_REG, | |
9937 | .doit = nl80211_get_reg, | |
9938 | .policy = nl80211_policy, | |
5fe231e8 | 9939 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
9940 | /* can be retrieved by unprivileged users */ |
9941 | }, | |
b2e1b302 LR |
9942 | { |
9943 | .cmd = NL80211_CMD_SET_REG, | |
9944 | .doit = nl80211_set_reg, | |
9945 | .policy = nl80211_policy, | |
9946 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 9947 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
9948 | }, |
9949 | { | |
9950 | .cmd = NL80211_CMD_REQ_SET_REG, | |
9951 | .doit = nl80211_req_set_reg, | |
9952 | .policy = nl80211_policy, | |
93da9cc1 | 9953 | .flags = GENL_ADMIN_PERM, |
9954 | }, | |
9955 | { | |
24bdd9f4 JC |
9956 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
9957 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 9958 | .policy = nl80211_policy, |
9959 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 9960 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9961 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 9962 | }, |
9963 | { | |
24bdd9f4 JC |
9964 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
9965 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 9966 | .policy = nl80211_policy, |
9aed3cc1 | 9967 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 9968 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9969 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 9970 | }, |
2a519311 JB |
9971 | { |
9972 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
9973 | .doit = nl80211_trigger_scan, | |
9974 | .policy = nl80211_policy, | |
9975 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 9976 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9977 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
9978 | }, |
9979 | { | |
9980 | .cmd = NL80211_CMD_GET_SCAN, | |
9981 | .policy = nl80211_policy, | |
9982 | .dumpit = nl80211_dump_scan, | |
9983 | }, | |
807f8a8c LC |
9984 | { |
9985 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
9986 | .doit = nl80211_start_sched_scan, | |
9987 | .policy = nl80211_policy, | |
9988 | .flags = GENL_ADMIN_PERM, | |
9989 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9990 | NL80211_FLAG_NEED_RTNL, | |
9991 | }, | |
9992 | { | |
9993 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
9994 | .doit = nl80211_stop_sched_scan, | |
9995 | .policy = nl80211_policy, | |
9996 | .flags = GENL_ADMIN_PERM, | |
9997 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9998 | NL80211_FLAG_NEED_RTNL, | |
9999 | }, | |
636a5d36 JM |
10000 | { |
10001 | .cmd = NL80211_CMD_AUTHENTICATE, | |
10002 | .doit = nl80211_authenticate, | |
10003 | .policy = nl80211_policy, | |
10004 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10005 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10006 | NL80211_FLAG_NEED_RTNL | |
10007 | NL80211_FLAG_CLEAR_SKB, | |
636a5d36 JM |
10008 | }, |
10009 | { | |
10010 | .cmd = NL80211_CMD_ASSOCIATE, | |
10011 | .doit = nl80211_associate, | |
10012 | .policy = nl80211_policy, | |
10013 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10014 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10015 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10016 | }, |
10017 | { | |
10018 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
10019 | .doit = nl80211_deauthenticate, | |
10020 | .policy = nl80211_policy, | |
10021 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10022 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10023 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10024 | }, |
10025 | { | |
10026 | .cmd = NL80211_CMD_DISASSOCIATE, | |
10027 | .doit = nl80211_disassociate, | |
10028 | .policy = nl80211_policy, | |
10029 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10030 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10031 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 10032 | }, |
04a773ad JB |
10033 | { |
10034 | .cmd = NL80211_CMD_JOIN_IBSS, | |
10035 | .doit = nl80211_join_ibss, | |
10036 | .policy = nl80211_policy, | |
10037 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10038 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10039 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
10040 | }, |
10041 | { | |
10042 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
10043 | .doit = nl80211_leave_ibss, | |
10044 | .policy = nl80211_policy, | |
10045 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10046 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10047 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 10048 | }, |
aff89a9b JB |
10049 | #ifdef CONFIG_NL80211_TESTMODE |
10050 | { | |
10051 | .cmd = NL80211_CMD_TESTMODE, | |
10052 | .doit = nl80211_testmode_do, | |
71063f0e | 10053 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
10054 | .policy = nl80211_policy, |
10055 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10056 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10057 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
10058 | }, |
10059 | #endif | |
b23aa676 SO |
10060 | { |
10061 | .cmd = NL80211_CMD_CONNECT, | |
10062 | .doit = nl80211_connect, | |
10063 | .policy = nl80211_policy, | |
10064 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10065 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10066 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
10067 | }, |
10068 | { | |
10069 | .cmd = NL80211_CMD_DISCONNECT, | |
10070 | .doit = nl80211_disconnect, | |
10071 | .policy = nl80211_policy, | |
10072 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10073 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10074 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 10075 | }, |
463d0183 JB |
10076 | { |
10077 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
10078 | .doit = nl80211_wiphy_netns, | |
10079 | .policy = nl80211_policy, | |
10080 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10081 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10082 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 10083 | }, |
61fa713c HS |
10084 | { |
10085 | .cmd = NL80211_CMD_GET_SURVEY, | |
10086 | .policy = nl80211_policy, | |
10087 | .dumpit = nl80211_dump_survey, | |
10088 | }, | |
67fbb16b SO |
10089 | { |
10090 | .cmd = NL80211_CMD_SET_PMKSA, | |
10091 | .doit = nl80211_setdel_pmksa, | |
10092 | .policy = nl80211_policy, | |
10093 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10094 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10095 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10096 | }, |
10097 | { | |
10098 | .cmd = NL80211_CMD_DEL_PMKSA, | |
10099 | .doit = nl80211_setdel_pmksa, | |
10100 | .policy = nl80211_policy, | |
10101 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10102 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10103 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10104 | }, |
10105 | { | |
10106 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
10107 | .doit = nl80211_flush_pmksa, | |
10108 | .policy = nl80211_policy, | |
10109 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10110 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10111 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 10112 | }, |
9588bbd5 JM |
10113 | { |
10114 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
10115 | .doit = nl80211_remain_on_channel, | |
10116 | .policy = nl80211_policy, | |
10117 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10118 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10119 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
10120 | }, |
10121 | { | |
10122 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
10123 | .doit = nl80211_cancel_remain_on_channel, | |
10124 | .policy = nl80211_policy, | |
10125 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10126 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10127 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 10128 | }, |
13ae75b1 JM |
10129 | { |
10130 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
10131 | .doit = nl80211_set_tx_bitrate_mask, | |
10132 | .policy = nl80211_policy, | |
10133 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10134 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10135 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 10136 | }, |
026331c4 | 10137 | { |
2e161f78 JB |
10138 | .cmd = NL80211_CMD_REGISTER_FRAME, |
10139 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
10140 | .policy = nl80211_policy, |
10141 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10142 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10143 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
10144 | }, |
10145 | { | |
2e161f78 JB |
10146 | .cmd = NL80211_CMD_FRAME, |
10147 | .doit = nl80211_tx_mgmt, | |
026331c4 | 10148 | .policy = nl80211_policy, |
f7ca38df | 10149 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10150 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
10151 | NL80211_FLAG_NEED_RTNL, |
10152 | }, | |
10153 | { | |
10154 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
10155 | .doit = nl80211_tx_mgmt_cancel_wait, | |
10156 | .policy = nl80211_policy, | |
026331c4 | 10157 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10158 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10159 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 10160 | }, |
ffb9eb3d KV |
10161 | { |
10162 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
10163 | .doit = nl80211_set_power_save, | |
10164 | .policy = nl80211_policy, | |
10165 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10166 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10167 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
10168 | }, |
10169 | { | |
10170 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
10171 | .doit = nl80211_get_power_save, | |
10172 | .policy = nl80211_policy, | |
10173 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
10174 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10175 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 10176 | }, |
d6dc1a38 JO |
10177 | { |
10178 | .cmd = NL80211_CMD_SET_CQM, | |
10179 | .doit = nl80211_set_cqm, | |
10180 | .policy = nl80211_policy, | |
10181 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10182 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10183 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 10184 | }, |
f444de05 JB |
10185 | { |
10186 | .cmd = NL80211_CMD_SET_CHANNEL, | |
10187 | .doit = nl80211_set_channel, | |
10188 | .policy = nl80211_policy, | |
10189 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10190 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10191 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 10192 | }, |
e8347eba BJ |
10193 | { |
10194 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
10195 | .doit = nl80211_set_wds_peer, | |
10196 | .policy = nl80211_policy, | |
10197 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
10198 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10199 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 10200 | }, |
29cbe68c JB |
10201 | { |
10202 | .cmd = NL80211_CMD_JOIN_MESH, | |
10203 | .doit = nl80211_join_mesh, | |
10204 | .policy = nl80211_policy, | |
10205 | .flags = GENL_ADMIN_PERM, | |
10206 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10207 | NL80211_FLAG_NEED_RTNL, | |
10208 | }, | |
10209 | { | |
10210 | .cmd = NL80211_CMD_LEAVE_MESH, | |
10211 | .doit = nl80211_leave_mesh, | |
10212 | .policy = nl80211_policy, | |
10213 | .flags = GENL_ADMIN_PERM, | |
10214 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10215 | NL80211_FLAG_NEED_RTNL, | |
10216 | }, | |
dfb89c56 | 10217 | #ifdef CONFIG_PM |
ff1b6e69 JB |
10218 | { |
10219 | .cmd = NL80211_CMD_GET_WOWLAN, | |
10220 | .doit = nl80211_get_wowlan, | |
10221 | .policy = nl80211_policy, | |
10222 | /* can be retrieved by unprivileged users */ | |
10223 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10224 | NL80211_FLAG_NEED_RTNL, | |
10225 | }, | |
10226 | { | |
10227 | .cmd = NL80211_CMD_SET_WOWLAN, | |
10228 | .doit = nl80211_set_wowlan, | |
10229 | .policy = nl80211_policy, | |
10230 | .flags = GENL_ADMIN_PERM, | |
10231 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10232 | NL80211_FLAG_NEED_RTNL, | |
10233 | }, | |
dfb89c56 | 10234 | #endif |
e5497d76 JB |
10235 | { |
10236 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
10237 | .doit = nl80211_set_rekey_data, | |
10238 | .policy = nl80211_policy, | |
10239 | .flags = GENL_ADMIN_PERM, | |
10240 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
5393b917 JB |
10241 | NL80211_FLAG_NEED_RTNL | |
10242 | NL80211_FLAG_CLEAR_SKB, | |
e5497d76 | 10243 | }, |
109086ce AN |
10244 | { |
10245 | .cmd = NL80211_CMD_TDLS_MGMT, | |
10246 | .doit = nl80211_tdls_mgmt, | |
10247 | .policy = nl80211_policy, | |
10248 | .flags = GENL_ADMIN_PERM, | |
10249 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10250 | NL80211_FLAG_NEED_RTNL, | |
10251 | }, | |
10252 | { | |
10253 | .cmd = NL80211_CMD_TDLS_OPER, | |
10254 | .doit = nl80211_tdls_oper, | |
10255 | .policy = nl80211_policy, | |
10256 | .flags = GENL_ADMIN_PERM, | |
10257 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10258 | NL80211_FLAG_NEED_RTNL, | |
10259 | }, | |
28946da7 JB |
10260 | { |
10261 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
10262 | .doit = nl80211_register_unexpected_frame, | |
10263 | .policy = nl80211_policy, | |
10264 | .flags = GENL_ADMIN_PERM, | |
10265 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10266 | NL80211_FLAG_NEED_RTNL, | |
10267 | }, | |
7f6cf311 JB |
10268 | { |
10269 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
10270 | .doit = nl80211_probe_client, | |
10271 | .policy = nl80211_policy, | |
10272 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10273 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
10274 | NL80211_FLAG_NEED_RTNL, |
10275 | }, | |
5e760230 JB |
10276 | { |
10277 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
10278 | .doit = nl80211_register_beacons, | |
10279 | .policy = nl80211_policy, | |
10280 | .flags = GENL_ADMIN_PERM, | |
10281 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10282 | NL80211_FLAG_NEED_RTNL, | |
10283 | }, | |
1d9d9213 SW |
10284 | { |
10285 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
10286 | .doit = nl80211_set_noack_map, | |
10287 | .policy = nl80211_policy, | |
10288 | .flags = GENL_ADMIN_PERM, | |
10289 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10290 | NL80211_FLAG_NEED_RTNL, | |
10291 | }, | |
98104fde JB |
10292 | { |
10293 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
10294 | .doit = nl80211_start_p2p_device, | |
10295 | .policy = nl80211_policy, | |
10296 | .flags = GENL_ADMIN_PERM, | |
10297 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
10298 | NL80211_FLAG_NEED_RTNL, | |
10299 | }, | |
10300 | { | |
10301 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
10302 | .doit = nl80211_stop_p2p_device, | |
10303 | .policy = nl80211_policy, | |
10304 | .flags = GENL_ADMIN_PERM, | |
10305 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10306 | NL80211_FLAG_NEED_RTNL, | |
10307 | }, | |
f4e583c8 AQ |
10308 | { |
10309 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
10310 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
10311 | .policy = nl80211_policy, |
10312 | .flags = GENL_ADMIN_PERM, | |
10313 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10314 | NL80211_FLAG_NEED_RTNL, | |
10315 | }, | |
10316 | { | |
10317 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
10318 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
10319 | .policy = nl80211_policy, |
10320 | .flags = GENL_ADMIN_PERM, | |
10321 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10322 | NL80211_FLAG_NEED_RTNL, | |
10323 | }, | |
04f39047 SW |
10324 | { |
10325 | .cmd = NL80211_CMD_RADAR_DETECT, | |
10326 | .doit = nl80211_start_radar_detection, | |
10327 | .policy = nl80211_policy, | |
10328 | .flags = GENL_ADMIN_PERM, | |
10329 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10330 | NL80211_FLAG_NEED_RTNL, | |
10331 | }, | |
3713b4e3 JB |
10332 | { |
10333 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
10334 | .doit = nl80211_get_protocol_features, | |
10335 | .policy = nl80211_policy, | |
10336 | }, | |
355199e0 JM |
10337 | { |
10338 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
10339 | .doit = nl80211_update_ft_ies, | |
10340 | .policy = nl80211_policy, | |
10341 | .flags = GENL_ADMIN_PERM, | |
10342 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10343 | NL80211_FLAG_NEED_RTNL, | |
10344 | }, | |
5de17984 AS |
10345 | { |
10346 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
10347 | .doit = nl80211_crit_protocol_start, | |
10348 | .policy = nl80211_policy, | |
10349 | .flags = GENL_ADMIN_PERM, | |
10350 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10351 | NL80211_FLAG_NEED_RTNL, | |
10352 | }, | |
10353 | { | |
10354 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
10355 | .doit = nl80211_crit_protocol_stop, | |
10356 | .policy = nl80211_policy, | |
10357 | .flags = GENL_ADMIN_PERM, | |
10358 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10359 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
10360 | }, |
10361 | { | |
10362 | .cmd = NL80211_CMD_GET_COALESCE, | |
10363 | .doit = nl80211_get_coalesce, | |
10364 | .policy = nl80211_policy, | |
10365 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10366 | NL80211_FLAG_NEED_RTNL, | |
10367 | }, | |
10368 | { | |
10369 | .cmd = NL80211_CMD_SET_COALESCE, | |
10370 | .doit = nl80211_set_coalesce, | |
10371 | .policy = nl80211_policy, | |
10372 | .flags = GENL_ADMIN_PERM, | |
10373 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10374 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
10375 | }, |
10376 | { | |
10377 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
10378 | .doit = nl80211_channel_switch, | |
10379 | .policy = nl80211_policy, | |
10380 | .flags = GENL_ADMIN_PERM, | |
10381 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10382 | NL80211_FLAG_NEED_RTNL, | |
10383 | }, | |
ad7e718c JB |
10384 | { |
10385 | .cmd = NL80211_CMD_VENDOR, | |
10386 | .doit = nl80211_vendor_cmd, | |
10387 | .policy = nl80211_policy, | |
10388 | .flags = GENL_ADMIN_PERM, | |
10389 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10390 | NL80211_FLAG_NEED_RTNL, | |
10391 | }, | |
fa9ffc74 KP |
10392 | { |
10393 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
10394 | .doit = nl80211_set_qos_map, | |
10395 | .policy = nl80211_policy, | |
10396 | .flags = GENL_ADMIN_PERM, | |
10397 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10398 | NL80211_FLAG_NEED_RTNL, | |
10399 | }, | |
960d01ac JB |
10400 | { |
10401 | .cmd = NL80211_CMD_ADD_TX_TS, | |
10402 | .doit = nl80211_add_tx_ts, | |
10403 | .policy = nl80211_policy, | |
10404 | .flags = GENL_ADMIN_PERM, | |
10405 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10406 | NL80211_FLAG_NEED_RTNL, | |
10407 | }, | |
10408 | { | |
10409 | .cmd = NL80211_CMD_DEL_TX_TS, | |
10410 | .doit = nl80211_del_tx_ts, | |
10411 | .policy = nl80211_policy, | |
10412 | .flags = GENL_ADMIN_PERM, | |
10413 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10414 | NL80211_FLAG_NEED_RTNL, | |
10415 | }, | |
55682965 | 10416 | }; |
9588bbd5 | 10417 | |
55682965 JB |
10418 | /* notification functions */ |
10419 | ||
3bb20556 JB |
10420 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
10421 | enum nl80211_commands cmd) | |
55682965 JB |
10422 | { |
10423 | struct sk_buff *msg; | |
86e8cf98 | 10424 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 10425 | |
3bb20556 JB |
10426 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
10427 | cmd != NL80211_CMD_DEL_WIPHY); | |
10428 | ||
fd2120ca | 10429 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
10430 | if (!msg) |
10431 | return; | |
10432 | ||
3bb20556 | 10433 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
10434 | nlmsg_free(msg); |
10435 | return; | |
10436 | } | |
10437 | ||
68eb5503 | 10438 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10439 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
10440 | } |
10441 | ||
362a415d JB |
10442 | static int nl80211_add_scan_req(struct sk_buff *msg, |
10443 | struct cfg80211_registered_device *rdev) | |
10444 | { | |
10445 | struct cfg80211_scan_request *req = rdev->scan_req; | |
10446 | struct nlattr *nest; | |
10447 | int i; | |
10448 | ||
10449 | if (WARN_ON(!req)) | |
10450 | return 0; | |
10451 | ||
10452 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
10453 | if (!nest) | |
10454 | goto nla_put_failure; | |
9360ffd1 DM |
10455 | for (i = 0; i < req->n_ssids; i++) { |
10456 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
10457 | goto nla_put_failure; | |
10458 | } | |
362a415d JB |
10459 | nla_nest_end(msg, nest); |
10460 | ||
10461 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
10462 | if (!nest) | |
10463 | goto nla_put_failure; | |
9360ffd1 DM |
10464 | for (i = 0; i < req->n_channels; i++) { |
10465 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
10466 | goto nla_put_failure; | |
10467 | } | |
362a415d JB |
10468 | nla_nest_end(msg, nest); |
10469 | ||
9360ffd1 DM |
10470 | if (req->ie && |
10471 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
10472 | goto nla_put_failure; | |
362a415d | 10473 | |
ae917c9f JB |
10474 | if (req->flags && |
10475 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
10476 | goto nla_put_failure; | |
ed473771 | 10477 | |
362a415d JB |
10478 | return 0; |
10479 | nla_put_failure: | |
10480 | return -ENOBUFS; | |
10481 | } | |
10482 | ||
a538e2d5 JB |
10483 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
10484 | struct cfg80211_registered_device *rdev, | |
fd014284 | 10485 | struct wireless_dev *wdev, |
15e47304 | 10486 | u32 portid, u32 seq, int flags, |
a538e2d5 | 10487 | u32 cmd) |
2a519311 JB |
10488 | { |
10489 | void *hdr; | |
10490 | ||
15e47304 | 10491 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
10492 | if (!hdr) |
10493 | return -1; | |
10494 | ||
9360ffd1 | 10495 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
10496 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10497 | wdev->netdev->ifindex)) || | |
10498 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 10499 | goto nla_put_failure; |
2a519311 | 10500 | |
362a415d JB |
10501 | /* ignore errors and send incomplete event anyway */ |
10502 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
10503 | |
10504 | return genlmsg_end(msg, hdr); | |
10505 | ||
10506 | nla_put_failure: | |
10507 | genlmsg_cancel(msg, hdr); | |
10508 | return -EMSGSIZE; | |
10509 | } | |
10510 | ||
807f8a8c LC |
10511 | static int |
10512 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
10513 | struct cfg80211_registered_device *rdev, | |
10514 | struct net_device *netdev, | |
15e47304 | 10515 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
10516 | { |
10517 | void *hdr; | |
10518 | ||
15e47304 | 10519 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
10520 | if (!hdr) |
10521 | return -1; | |
10522 | ||
9360ffd1 DM |
10523 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10524 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
10525 | goto nla_put_failure; | |
807f8a8c LC |
10526 | |
10527 | return genlmsg_end(msg, hdr); | |
10528 | ||
10529 | nla_put_failure: | |
10530 | genlmsg_cancel(msg, hdr); | |
10531 | return -EMSGSIZE; | |
10532 | } | |
10533 | ||
a538e2d5 | 10534 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 10535 | struct wireless_dev *wdev) |
a538e2d5 JB |
10536 | { |
10537 | struct sk_buff *msg; | |
10538 | ||
58050fce | 10539 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
10540 | if (!msg) |
10541 | return; | |
10542 | ||
fd014284 | 10543 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
10544 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
10545 | nlmsg_free(msg); | |
10546 | return; | |
10547 | } | |
10548 | ||
68eb5503 | 10549 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10550 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
10551 | } |
10552 | ||
f9d15d16 JB |
10553 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
10554 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
10555 | { |
10556 | struct sk_buff *msg; | |
10557 | ||
fd2120ca | 10558 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 10559 | if (!msg) |
f9d15d16 | 10560 | return NULL; |
2a519311 | 10561 | |
fd014284 | 10562 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
10563 | aborted ? NL80211_CMD_SCAN_ABORTED : |
10564 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 10565 | nlmsg_free(msg); |
f9d15d16 | 10566 | return NULL; |
2a519311 JB |
10567 | } |
10568 | ||
f9d15d16 | 10569 | return msg; |
2a519311 JB |
10570 | } |
10571 | ||
f9d15d16 JB |
10572 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
10573 | struct sk_buff *msg) | |
2a519311 | 10574 | { |
2a519311 JB |
10575 | if (!msg) |
10576 | return; | |
10577 | ||
68eb5503 | 10578 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10579 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
10580 | } |
10581 | ||
807f8a8c LC |
10582 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
10583 | struct net_device *netdev) | |
10584 | { | |
10585 | struct sk_buff *msg; | |
10586 | ||
10587 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10588 | if (!msg) | |
10589 | return; | |
10590 | ||
10591 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
10592 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
10593 | nlmsg_free(msg); | |
10594 | return; | |
10595 | } | |
10596 | ||
68eb5503 | 10597 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10598 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
10599 | } |
10600 | ||
10601 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
10602 | struct net_device *netdev, u32 cmd) | |
10603 | { | |
10604 | struct sk_buff *msg; | |
10605 | ||
58050fce | 10606 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
10607 | if (!msg) |
10608 | return; | |
10609 | ||
10610 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
10611 | nlmsg_free(msg); | |
10612 | return; | |
10613 | } | |
10614 | ||
68eb5503 | 10615 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10616 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
10617 | } |
10618 | ||
73d54c9e LR |
10619 | /* |
10620 | * This can happen on global regulatory changes or device specific settings | |
10621 | * based on custom world regulatory domains. | |
10622 | */ | |
10623 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
10624 | { | |
10625 | struct sk_buff *msg; | |
10626 | void *hdr; | |
10627 | ||
fd2120ca | 10628 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
10629 | if (!msg) |
10630 | return; | |
10631 | ||
10632 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
10633 | if (!hdr) { | |
10634 | nlmsg_free(msg); | |
10635 | return; | |
10636 | } | |
10637 | ||
10638 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
10639 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
10640 | goto nla_put_failure; | |
10641 | ||
10642 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
10643 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10644 | NL80211_REGDOM_TYPE_WORLD)) | |
10645 | goto nla_put_failure; | |
10646 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
10647 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10648 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
10649 | goto nla_put_failure; | |
10650 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
10651 | request->intersect) { | |
10652 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10653 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
10654 | goto nla_put_failure; | |
10655 | } else { | |
10656 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10657 | NL80211_REGDOM_TYPE_COUNTRY) || | |
10658 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
10659 | request->alpha2)) | |
10660 | goto nla_put_failure; | |
10661 | } | |
10662 | ||
f4173766 | 10663 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
10664 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
10665 | goto nla_put_failure; | |
73d54c9e | 10666 | |
3b7b72ee | 10667 | genlmsg_end(msg, hdr); |
73d54c9e | 10668 | |
bc43b28c | 10669 | rcu_read_lock(); |
68eb5503 | 10670 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 10671 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 10672 | rcu_read_unlock(); |
73d54c9e LR |
10673 | |
10674 | return; | |
10675 | ||
10676 | nla_put_failure: | |
10677 | genlmsg_cancel(msg, hdr); | |
10678 | nlmsg_free(msg); | |
10679 | } | |
10680 | ||
6039f6d2 JM |
10681 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
10682 | struct net_device *netdev, | |
10683 | const u8 *buf, size_t len, | |
b0b6aa2c EP |
10684 | enum nl80211_commands cmd, gfp_t gfp, |
10685 | int uapsd_queues) | |
6039f6d2 JM |
10686 | { |
10687 | struct sk_buff *msg; | |
10688 | void *hdr; | |
10689 | ||
e6d6e342 | 10690 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
10691 | if (!msg) |
10692 | return; | |
10693 | ||
10694 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10695 | if (!hdr) { | |
10696 | nlmsg_free(msg); | |
10697 | return; | |
10698 | } | |
10699 | ||
9360ffd1 DM |
10700 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10701 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10702 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
10703 | goto nla_put_failure; | |
6039f6d2 | 10704 | |
b0b6aa2c EP |
10705 | if (uapsd_queues >= 0) { |
10706 | struct nlattr *nla_wmm = | |
10707 | nla_nest_start(msg, NL80211_ATTR_STA_WME); | |
10708 | if (!nla_wmm) | |
10709 | goto nla_put_failure; | |
10710 | ||
10711 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
10712 | uapsd_queues)) | |
10713 | goto nla_put_failure; | |
10714 | ||
10715 | nla_nest_end(msg, nla_wmm); | |
10716 | } | |
10717 | ||
3b7b72ee | 10718 | genlmsg_end(msg, hdr); |
6039f6d2 | 10719 | |
68eb5503 | 10720 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10721 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
10722 | return; |
10723 | ||
10724 | nla_put_failure: | |
10725 | genlmsg_cancel(msg, hdr); | |
10726 | nlmsg_free(msg); | |
10727 | } | |
10728 | ||
10729 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10730 | struct net_device *netdev, const u8 *buf, |
10731 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
10732 | { |
10733 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 10734 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
6039f6d2 JM |
10735 | } |
10736 | ||
10737 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
10738 | struct net_device *netdev, const u8 *buf, | |
b0b6aa2c | 10739 | size_t len, gfp_t gfp, int uapsd_queues) |
6039f6d2 | 10740 | { |
e6d6e342 | 10741 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
b0b6aa2c | 10742 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
6039f6d2 JM |
10743 | } |
10744 | ||
53b46b84 | 10745 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
10746 | struct net_device *netdev, const u8 *buf, |
10747 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
10748 | { |
10749 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 10750 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
6039f6d2 JM |
10751 | } |
10752 | ||
53b46b84 JM |
10753 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
10754 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 10755 | size_t len, gfp_t gfp) |
6039f6d2 JM |
10756 | { |
10757 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 10758 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
6039f6d2 JM |
10759 | } |
10760 | ||
6ff57cf8 JB |
10761 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
10762 | size_t len) | |
cf4e594e | 10763 | { |
947add36 JB |
10764 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10765 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 10766 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
10767 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
10768 | u32 cmd; | |
947add36 | 10769 | |
6ff57cf8 JB |
10770 | if (WARN_ON(len < 2)) |
10771 | return; | |
cf4e594e | 10772 | |
6ff57cf8 JB |
10773 | if (ieee80211_is_deauth(mgmt->frame_control)) |
10774 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
10775 | else | |
10776 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 10777 | |
6ff57cf8 | 10778 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
b0b6aa2c | 10779 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
cf4e594e | 10780 | } |
6ff57cf8 | 10781 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 10782 | |
1b06bb40 LR |
10783 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
10784 | struct net_device *netdev, int cmd, | |
e6d6e342 | 10785 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
10786 | { |
10787 | struct sk_buff *msg; | |
10788 | void *hdr; | |
10789 | ||
e6d6e342 | 10790 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
10791 | if (!msg) |
10792 | return; | |
10793 | ||
10794 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10795 | if (!hdr) { | |
10796 | nlmsg_free(msg); | |
10797 | return; | |
10798 | } | |
10799 | ||
9360ffd1 DM |
10800 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10801 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10802 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
10803 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
10804 | goto nla_put_failure; | |
1965c853 | 10805 | |
3b7b72ee | 10806 | genlmsg_end(msg, hdr); |
1965c853 | 10807 | |
68eb5503 | 10808 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10809 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
10810 | return; |
10811 | ||
10812 | nla_put_failure: | |
10813 | genlmsg_cancel(msg, hdr); | |
10814 | nlmsg_free(msg); | |
10815 | } | |
10816 | ||
10817 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10818 | struct net_device *netdev, const u8 *addr, |
10819 | gfp_t gfp) | |
1965c853 JM |
10820 | { |
10821 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 10822 | addr, gfp); |
1965c853 JM |
10823 | } |
10824 | ||
10825 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10826 | struct net_device *netdev, const u8 *addr, |
10827 | gfp_t gfp) | |
1965c853 | 10828 | { |
e6d6e342 JB |
10829 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
10830 | addr, gfp); | |
1965c853 JM |
10831 | } |
10832 | ||
b23aa676 SO |
10833 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
10834 | struct net_device *netdev, const u8 *bssid, | |
10835 | const u8 *req_ie, size_t req_ie_len, | |
10836 | const u8 *resp_ie, size_t resp_ie_len, | |
10837 | u16 status, gfp_t gfp) | |
10838 | { | |
10839 | struct sk_buff *msg; | |
10840 | void *hdr; | |
10841 | ||
58050fce | 10842 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
10843 | if (!msg) |
10844 | return; | |
10845 | ||
10846 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
10847 | if (!hdr) { | |
10848 | nlmsg_free(msg); | |
10849 | return; | |
10850 | } | |
10851 | ||
9360ffd1 DM |
10852 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10853 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10854 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
10855 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
10856 | (req_ie && | |
10857 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
10858 | (resp_ie && | |
10859 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
10860 | goto nla_put_failure; | |
b23aa676 | 10861 | |
3b7b72ee | 10862 | genlmsg_end(msg, hdr); |
b23aa676 | 10863 | |
68eb5503 | 10864 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10865 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
10866 | return; |
10867 | ||
10868 | nla_put_failure: | |
10869 | genlmsg_cancel(msg, hdr); | |
10870 | nlmsg_free(msg); | |
10871 | ||
10872 | } | |
10873 | ||
10874 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
10875 | struct net_device *netdev, const u8 *bssid, | |
10876 | const u8 *req_ie, size_t req_ie_len, | |
10877 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
10878 | { | |
10879 | struct sk_buff *msg; | |
10880 | void *hdr; | |
10881 | ||
58050fce | 10882 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
10883 | if (!msg) |
10884 | return; | |
10885 | ||
10886 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
10887 | if (!hdr) { | |
10888 | nlmsg_free(msg); | |
10889 | return; | |
10890 | } | |
10891 | ||
9360ffd1 DM |
10892 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10893 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10894 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
10895 | (req_ie && | |
10896 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
10897 | (resp_ie && | |
10898 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
10899 | goto nla_put_failure; | |
b23aa676 | 10900 | |
3b7b72ee | 10901 | genlmsg_end(msg, hdr); |
b23aa676 | 10902 | |
68eb5503 | 10903 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10904 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
10905 | return; |
10906 | ||
10907 | nla_put_failure: | |
10908 | genlmsg_cancel(msg, hdr); | |
10909 | nlmsg_free(msg); | |
10910 | ||
10911 | } | |
10912 | ||
10913 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
10914 | struct net_device *netdev, u16 reason, | |
667503dd | 10915 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
10916 | { |
10917 | struct sk_buff *msg; | |
10918 | void *hdr; | |
10919 | ||
58050fce | 10920 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
10921 | if (!msg) |
10922 | return; | |
10923 | ||
10924 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
10925 | if (!hdr) { | |
10926 | nlmsg_free(msg); | |
10927 | return; | |
10928 | } | |
10929 | ||
9360ffd1 DM |
10930 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10931 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10932 | (from_ap && reason && | |
10933 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
10934 | (from_ap && | |
10935 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
10936 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
10937 | goto nla_put_failure; | |
b23aa676 | 10938 | |
3b7b72ee | 10939 | genlmsg_end(msg, hdr); |
b23aa676 | 10940 | |
68eb5503 | 10941 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10942 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
10943 | return; |
10944 | ||
10945 | nla_put_failure: | |
10946 | genlmsg_cancel(msg, hdr); | |
10947 | nlmsg_free(msg); | |
10948 | ||
10949 | } | |
10950 | ||
04a773ad JB |
10951 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
10952 | struct net_device *netdev, const u8 *bssid, | |
10953 | gfp_t gfp) | |
10954 | { | |
10955 | struct sk_buff *msg; | |
10956 | void *hdr; | |
10957 | ||
fd2120ca | 10958 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
10959 | if (!msg) |
10960 | return; | |
10961 | ||
10962 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
10963 | if (!hdr) { | |
10964 | nlmsg_free(msg); | |
10965 | return; | |
10966 | } | |
10967 | ||
9360ffd1 DM |
10968 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10969 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10970 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10971 | goto nla_put_failure; | |
04a773ad | 10972 | |
3b7b72ee | 10973 | genlmsg_end(msg, hdr); |
04a773ad | 10974 | |
68eb5503 | 10975 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10976 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
10977 | return; |
10978 | ||
10979 | nla_put_failure: | |
10980 | genlmsg_cancel(msg, hdr); | |
10981 | nlmsg_free(msg); | |
10982 | } | |
10983 | ||
947add36 JB |
10984 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
10985 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 10986 | { |
947add36 | 10987 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 10988 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
10989 | struct sk_buff *msg; |
10990 | void *hdr; | |
10991 | ||
947add36 JB |
10992 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
10993 | return; | |
10994 | ||
10995 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
10996 | ||
c93b5e71 JC |
10997 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
10998 | if (!msg) | |
10999 | return; | |
11000 | ||
11001 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
11002 | if (!hdr) { | |
11003 | nlmsg_free(msg); | |
11004 | return; | |
11005 | } | |
11006 | ||
9360ffd1 | 11007 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
11008 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
11009 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
11010 | (ie_len && ie && |
11011 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
11012 | goto nla_put_failure; | |
c93b5e71 | 11013 | |
3b7b72ee | 11014 | genlmsg_end(msg, hdr); |
c93b5e71 | 11015 | |
68eb5503 | 11016 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11017 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
11018 | return; |
11019 | ||
11020 | nla_put_failure: | |
11021 | genlmsg_cancel(msg, hdr); | |
11022 | nlmsg_free(msg); | |
11023 | } | |
947add36 | 11024 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 11025 | |
a3b8b056 JM |
11026 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
11027 | struct net_device *netdev, const u8 *addr, | |
11028 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 11029 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
11030 | { |
11031 | struct sk_buff *msg; | |
11032 | void *hdr; | |
11033 | ||
e6d6e342 | 11034 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
11035 | if (!msg) |
11036 | return; | |
11037 | ||
11038 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
11039 | if (!hdr) { | |
11040 | nlmsg_free(msg); | |
11041 | return; | |
11042 | } | |
11043 | ||
9360ffd1 DM |
11044 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11045 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11046 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
11047 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
11048 | (key_id != -1 && | |
11049 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
11050 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
11051 | goto nla_put_failure; | |
a3b8b056 | 11052 | |
3b7b72ee | 11053 | genlmsg_end(msg, hdr); |
a3b8b056 | 11054 | |
68eb5503 | 11055 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11056 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
11057 | return; |
11058 | ||
11059 | nla_put_failure: | |
11060 | genlmsg_cancel(msg, hdr); | |
11061 | nlmsg_free(msg); | |
11062 | } | |
11063 | ||
6bad8766 LR |
11064 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
11065 | struct ieee80211_channel *channel_before, | |
11066 | struct ieee80211_channel *channel_after) | |
11067 | { | |
11068 | struct sk_buff *msg; | |
11069 | void *hdr; | |
11070 | struct nlattr *nl_freq; | |
11071 | ||
fd2120ca | 11072 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
11073 | if (!msg) |
11074 | return; | |
11075 | ||
11076 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
11077 | if (!hdr) { | |
11078 | nlmsg_free(msg); | |
11079 | return; | |
11080 | } | |
11081 | ||
11082 | /* | |
11083 | * Since we are applying the beacon hint to a wiphy we know its | |
11084 | * wiphy_idx is valid | |
11085 | */ | |
9360ffd1 DM |
11086 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
11087 | goto nla_put_failure; | |
6bad8766 LR |
11088 | |
11089 | /* Before */ | |
11090 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
11091 | if (!nl_freq) | |
11092 | goto nla_put_failure; | |
cdc89b97 | 11093 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
11094 | goto nla_put_failure; |
11095 | nla_nest_end(msg, nl_freq); | |
11096 | ||
11097 | /* After */ | |
11098 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
11099 | if (!nl_freq) | |
11100 | goto nla_put_failure; | |
cdc89b97 | 11101 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
11102 | goto nla_put_failure; |
11103 | nla_nest_end(msg, nl_freq); | |
11104 | ||
3b7b72ee | 11105 | genlmsg_end(msg, hdr); |
6bad8766 | 11106 | |
463d0183 | 11107 | rcu_read_lock(); |
68eb5503 | 11108 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11109 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 11110 | rcu_read_unlock(); |
6bad8766 LR |
11111 | |
11112 | return; | |
11113 | ||
11114 | nla_put_failure: | |
11115 | genlmsg_cancel(msg, hdr); | |
11116 | nlmsg_free(msg); | |
11117 | } | |
11118 | ||
9588bbd5 JM |
11119 | static void nl80211_send_remain_on_chan_event( |
11120 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 11121 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 11122 | struct ieee80211_channel *chan, |
9588bbd5 JM |
11123 | unsigned int duration, gfp_t gfp) |
11124 | { | |
11125 | struct sk_buff *msg; | |
11126 | void *hdr; | |
11127 | ||
11128 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11129 | if (!msg) | |
11130 | return; | |
11131 | ||
11132 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11133 | if (!hdr) { | |
11134 | nlmsg_free(msg); | |
11135 | return; | |
11136 | } | |
11137 | ||
9360ffd1 | 11138 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11139 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11140 | wdev->netdev->ifindex)) || | |
00f53350 | 11141 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 11142 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
11143 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
11144 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
11145 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
11146 | goto nla_put_failure; | |
9588bbd5 | 11147 | |
9360ffd1 DM |
11148 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
11149 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
11150 | goto nla_put_failure; | |
9588bbd5 | 11151 | |
3b7b72ee | 11152 | genlmsg_end(msg, hdr); |
9588bbd5 | 11153 | |
68eb5503 | 11154 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11155 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
11156 | return; |
11157 | ||
11158 | nla_put_failure: | |
11159 | genlmsg_cancel(msg, hdr); | |
11160 | nlmsg_free(msg); | |
11161 | } | |
11162 | ||
947add36 JB |
11163 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
11164 | struct ieee80211_channel *chan, | |
11165 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 11166 | { |
947add36 | 11167 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11168 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11169 | |
11170 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 11171 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 11172 | rdev, wdev, cookie, chan, |
42d97a59 | 11173 | duration, gfp); |
9588bbd5 | 11174 | } |
947add36 | 11175 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 11176 | |
947add36 JB |
11177 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
11178 | struct ieee80211_channel *chan, | |
11179 | gfp_t gfp) | |
9588bbd5 | 11180 | { |
947add36 | 11181 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11182 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11183 | |
11184 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 11185 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 11186 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 11187 | } |
947add36 | 11188 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 11189 | |
947add36 JB |
11190 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
11191 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 11192 | { |
947add36 | 11193 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11194 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
11195 | struct sk_buff *msg; |
11196 | ||
947add36 JB |
11197 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
11198 | ||
58050fce | 11199 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
11200 | if (!msg) |
11201 | return; | |
11202 | ||
66266b3a JL |
11203 | if (nl80211_send_station(msg, 0, 0, 0, |
11204 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
11205 | nlmsg_free(msg); |
11206 | return; | |
11207 | } | |
11208 | ||
68eb5503 | 11209 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11210 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 11211 | } |
947add36 | 11212 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 11213 | |
947add36 | 11214 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 11215 | { |
947add36 | 11216 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11217 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b JM |
11218 | struct sk_buff *msg; |
11219 | void *hdr; | |
11220 | ||
947add36 JB |
11221 | trace_cfg80211_del_sta(dev, mac_addr); |
11222 | ||
58050fce | 11223 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
11224 | if (!msg) |
11225 | return; | |
11226 | ||
11227 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
11228 | if (!hdr) { | |
11229 | nlmsg_free(msg); | |
11230 | return; | |
11231 | } | |
11232 | ||
9360ffd1 DM |
11233 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
11234 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
11235 | goto nla_put_failure; | |
ec15e68b | 11236 | |
3b7b72ee | 11237 | genlmsg_end(msg, hdr); |
ec15e68b | 11238 | |
68eb5503 | 11239 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11240 | NL80211_MCGRP_MLME, gfp); |
ec15e68b JM |
11241 | return; |
11242 | ||
11243 | nla_put_failure: | |
11244 | genlmsg_cancel(msg, hdr); | |
11245 | nlmsg_free(msg); | |
11246 | } | |
947add36 | 11247 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 11248 | |
947add36 JB |
11249 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
11250 | enum nl80211_connect_failed_reason reason, | |
11251 | gfp_t gfp) | |
ed44a951 | 11252 | { |
947add36 | 11253 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11254 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
11255 | struct sk_buff *msg; |
11256 | void *hdr; | |
11257 | ||
11258 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
11259 | if (!msg) | |
11260 | return; | |
11261 | ||
11262 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
11263 | if (!hdr) { | |
11264 | nlmsg_free(msg); | |
11265 | return; | |
11266 | } | |
11267 | ||
11268 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11269 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
11270 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
11271 | goto nla_put_failure; | |
11272 | ||
11273 | genlmsg_end(msg, hdr); | |
11274 | ||
68eb5503 | 11275 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11276 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
11277 | return; |
11278 | ||
11279 | nla_put_failure: | |
11280 | genlmsg_cancel(msg, hdr); | |
11281 | nlmsg_free(msg); | |
11282 | } | |
947add36 | 11283 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 11284 | |
b92ab5d8 JB |
11285 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
11286 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
11287 | { |
11288 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 11289 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
11290 | struct sk_buff *msg; |
11291 | void *hdr; | |
15e47304 | 11292 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 11293 | |
15e47304 | 11294 | if (!nlportid) |
28946da7 JB |
11295 | return false; |
11296 | ||
11297 | msg = nlmsg_new(100, gfp); | |
11298 | if (!msg) | |
11299 | return true; | |
11300 | ||
b92ab5d8 | 11301 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
11302 | if (!hdr) { |
11303 | nlmsg_free(msg); | |
11304 | return true; | |
11305 | } | |
11306 | ||
9360ffd1 DM |
11307 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11308 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11309 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11310 | goto nla_put_failure; | |
28946da7 | 11311 | |
9c90a9f6 | 11312 | genlmsg_end(msg, hdr); |
15e47304 | 11313 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
11314 | return true; |
11315 | ||
11316 | nla_put_failure: | |
11317 | genlmsg_cancel(msg, hdr); | |
11318 | nlmsg_free(msg); | |
11319 | return true; | |
11320 | } | |
11321 | ||
947add36 JB |
11322 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
11323 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11324 | { |
947add36 JB |
11325 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11326 | bool ret; | |
11327 | ||
11328 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
11329 | ||
11330 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11331 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
11332 | trace_cfg80211_return_bool(false); | |
11333 | return false; | |
11334 | } | |
11335 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
11336 | addr, gfp); | |
11337 | trace_cfg80211_return_bool(ret); | |
11338 | return ret; | |
b92ab5d8 | 11339 | } |
947add36 | 11340 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 11341 | |
947add36 JB |
11342 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
11343 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11344 | { |
947add36 JB |
11345 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11346 | bool ret; | |
11347 | ||
11348 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
11349 | ||
11350 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11351 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
11352 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
11353 | trace_cfg80211_return_bool(false); | |
11354 | return false; | |
11355 | } | |
11356 | ret = __nl80211_unexpected_frame(dev, | |
11357 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
11358 | addr, gfp); | |
11359 | trace_cfg80211_return_bool(ret); | |
11360 | return ret; | |
b92ab5d8 | 11361 | } |
947add36 | 11362 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 11363 | |
2e161f78 | 11364 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 11365 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 11366 | int freq, int sig_dbm, |
19504cf5 | 11367 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 11368 | { |
71bbc994 | 11369 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11370 | struct sk_buff *msg; |
11371 | void *hdr; | |
026331c4 JM |
11372 | |
11373 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11374 | if (!msg) | |
11375 | return -ENOMEM; | |
11376 | ||
2e161f78 | 11377 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
11378 | if (!hdr) { |
11379 | nlmsg_free(msg); | |
11380 | return -ENOMEM; | |
11381 | } | |
11382 | ||
9360ffd1 | 11383 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11384 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11385 | netdev->ifindex)) || | |
a838490b | 11386 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11387 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
11388 | (sig_dbm && | |
11389 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
11390 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11391 | (flags && | |
11392 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 11393 | goto nla_put_failure; |
026331c4 | 11394 | |
3b7b72ee | 11395 | genlmsg_end(msg, hdr); |
026331c4 | 11396 | |
15e47304 | 11397 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
11398 | |
11399 | nla_put_failure: | |
11400 | genlmsg_cancel(msg, hdr); | |
11401 | nlmsg_free(msg); | |
11402 | return -ENOBUFS; | |
11403 | } | |
11404 | ||
947add36 JB |
11405 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
11406 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 11407 | { |
947add36 | 11408 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11409 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 11410 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11411 | struct sk_buff *msg; |
11412 | void *hdr; | |
11413 | ||
947add36 JB |
11414 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
11415 | ||
026331c4 JM |
11416 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11417 | if (!msg) | |
11418 | return; | |
11419 | ||
2e161f78 | 11420 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
11421 | if (!hdr) { |
11422 | nlmsg_free(msg); | |
11423 | return; | |
11424 | } | |
11425 | ||
9360ffd1 | 11426 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11427 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11428 | netdev->ifindex)) || | |
a838490b | 11429 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11430 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11431 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
11432 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
11433 | goto nla_put_failure; | |
026331c4 | 11434 | |
3b7b72ee | 11435 | genlmsg_end(msg, hdr); |
026331c4 | 11436 | |
68eb5503 | 11437 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11438 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
11439 | return; |
11440 | ||
11441 | nla_put_failure: | |
11442 | genlmsg_cancel(msg, hdr); | |
11443 | nlmsg_free(msg); | |
11444 | } | |
947add36 | 11445 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 11446 | |
947add36 JB |
11447 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
11448 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
11449 | gfp_t gfp) | |
d6dc1a38 | 11450 | { |
947add36 JB |
11451 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11452 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11453 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
d6dc1a38 JO |
11454 | struct sk_buff *msg; |
11455 | struct nlattr *pinfoattr; | |
11456 | void *hdr; | |
11457 | ||
947add36 JB |
11458 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
11459 | ||
58050fce | 11460 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
11461 | if (!msg) |
11462 | return; | |
11463 | ||
11464 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11465 | if (!hdr) { | |
11466 | nlmsg_free(msg); | |
11467 | return; | |
11468 | } | |
11469 | ||
9360ffd1 | 11470 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 11471 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 11472 | goto nla_put_failure; |
d6dc1a38 JO |
11473 | |
11474 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11475 | if (!pinfoattr) | |
11476 | goto nla_put_failure; | |
11477 | ||
9360ffd1 DM |
11478 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
11479 | rssi_event)) | |
11480 | goto nla_put_failure; | |
d6dc1a38 JO |
11481 | |
11482 | nla_nest_end(msg, pinfoattr); | |
11483 | ||
3b7b72ee | 11484 | genlmsg_end(msg, hdr); |
d6dc1a38 | 11485 | |
68eb5503 | 11486 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11487 | NL80211_MCGRP_MLME, gfp); |
d6dc1a38 JO |
11488 | return; |
11489 | ||
11490 | nla_put_failure: | |
11491 | genlmsg_cancel(msg, hdr); | |
11492 | nlmsg_free(msg); | |
11493 | } | |
947add36 | 11494 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 11495 | |
947add36 JB |
11496 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
11497 | struct net_device *netdev, const u8 *bssid, | |
11498 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
11499 | { |
11500 | struct sk_buff *msg; | |
11501 | struct nlattr *rekey_attr; | |
11502 | void *hdr; | |
11503 | ||
58050fce | 11504 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
11505 | if (!msg) |
11506 | return; | |
11507 | ||
11508 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
11509 | if (!hdr) { | |
11510 | nlmsg_free(msg); | |
11511 | return; | |
11512 | } | |
11513 | ||
9360ffd1 DM |
11514 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11515 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11516 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
11517 | goto nla_put_failure; | |
e5497d76 JB |
11518 | |
11519 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
11520 | if (!rekey_attr) | |
11521 | goto nla_put_failure; | |
11522 | ||
9360ffd1 DM |
11523 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
11524 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
11525 | goto nla_put_failure; | |
e5497d76 JB |
11526 | |
11527 | nla_nest_end(msg, rekey_attr); | |
11528 | ||
3b7b72ee | 11529 | genlmsg_end(msg, hdr); |
e5497d76 | 11530 | |
68eb5503 | 11531 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11532 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
11533 | return; |
11534 | ||
11535 | nla_put_failure: | |
11536 | genlmsg_cancel(msg, hdr); | |
11537 | nlmsg_free(msg); | |
11538 | } | |
11539 | ||
947add36 JB |
11540 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
11541 | const u8 *replay_ctr, gfp_t gfp) | |
11542 | { | |
11543 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11544 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11545 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11546 | |
11547 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
11548 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
11549 | } | |
11550 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
11551 | ||
11552 | static void | |
11553 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
11554 | struct net_device *netdev, int index, | |
11555 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
11556 | { |
11557 | struct sk_buff *msg; | |
11558 | struct nlattr *attr; | |
11559 | void *hdr; | |
11560 | ||
58050fce | 11561 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
11562 | if (!msg) |
11563 | return; | |
11564 | ||
11565 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
11566 | if (!hdr) { | |
11567 | nlmsg_free(msg); | |
11568 | return; | |
11569 | } | |
11570 | ||
9360ffd1 DM |
11571 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11572 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
11573 | goto nla_put_failure; | |
c9df56b4 JM |
11574 | |
11575 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
11576 | if (!attr) | |
11577 | goto nla_put_failure; | |
11578 | ||
9360ffd1 DM |
11579 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
11580 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
11581 | (preauth && | |
11582 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
11583 | goto nla_put_failure; | |
c9df56b4 JM |
11584 | |
11585 | nla_nest_end(msg, attr); | |
11586 | ||
3b7b72ee | 11587 | genlmsg_end(msg, hdr); |
c9df56b4 | 11588 | |
68eb5503 | 11589 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11590 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
11591 | return; |
11592 | ||
11593 | nla_put_failure: | |
11594 | genlmsg_cancel(msg, hdr); | |
11595 | nlmsg_free(msg); | |
11596 | } | |
11597 | ||
947add36 JB |
11598 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
11599 | const u8 *bssid, bool preauth, gfp_t gfp) | |
11600 | { | |
11601 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11602 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11603 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11604 | |
11605 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
11606 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
11607 | } | |
11608 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
11609 | ||
11610 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
11611 | struct net_device *netdev, | |
11612 | struct cfg80211_chan_def *chandef, | |
11613 | gfp_t gfp) | |
5314526b TP |
11614 | { |
11615 | struct sk_buff *msg; | |
11616 | void *hdr; | |
11617 | ||
58050fce | 11618 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
11619 | if (!msg) |
11620 | return; | |
11621 | ||
11622 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
11623 | if (!hdr) { | |
11624 | nlmsg_free(msg); | |
11625 | return; | |
11626 | } | |
11627 | ||
683b6d3b JB |
11628 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
11629 | goto nla_put_failure; | |
11630 | ||
11631 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 11632 | goto nla_put_failure; |
5314526b TP |
11633 | |
11634 | genlmsg_end(msg, hdr); | |
11635 | ||
68eb5503 | 11636 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11637 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
11638 | return; |
11639 | ||
11640 | nla_put_failure: | |
11641 | genlmsg_cancel(msg, hdr); | |
11642 | nlmsg_free(msg); | |
11643 | } | |
11644 | ||
947add36 JB |
11645 | void cfg80211_ch_switch_notify(struct net_device *dev, |
11646 | struct cfg80211_chan_def *chandef) | |
84f10708 | 11647 | { |
947add36 JB |
11648 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11649 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11650 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 11651 | |
e487eaeb | 11652 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 11653 | |
e487eaeb | 11654 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 JB |
11655 | |
11656 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
ee4bc9e7 | 11657 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
b8456a14 CYY |
11658 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
11659 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) | |
e487eaeb | 11660 | return; |
947add36 | 11661 | |
9e0e2961 | 11662 | wdev->chandef = *chandef; |
96f55f12 | 11663 | wdev->preset_chandef = *chandef; |
947add36 | 11664 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
947add36 JB |
11665 | } |
11666 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
11667 | ||
11668 | void cfg80211_cqm_txe_notify(struct net_device *dev, | |
11669 | const u8 *peer, u32 num_packets, | |
11670 | u32 rate, u32 intvl, gfp_t gfp) | |
11671 | { | |
11672 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11673 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11674 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
84f10708 TP |
11675 | struct sk_buff *msg; |
11676 | struct nlattr *pinfoattr; | |
11677 | void *hdr; | |
11678 | ||
11679 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
11680 | if (!msg) | |
11681 | return; | |
11682 | ||
11683 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11684 | if (!hdr) { | |
11685 | nlmsg_free(msg); | |
11686 | return; | |
11687 | } | |
11688 | ||
11689 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
947add36 | 11690 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
84f10708 TP |
11691 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
11692 | goto nla_put_failure; | |
11693 | ||
11694 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11695 | if (!pinfoattr) | |
11696 | goto nla_put_failure; | |
11697 | ||
11698 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
11699 | goto nla_put_failure; | |
11700 | ||
11701 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
11702 | goto nla_put_failure; | |
11703 | ||
11704 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
11705 | goto nla_put_failure; | |
11706 | ||
11707 | nla_nest_end(msg, pinfoattr); | |
11708 | ||
11709 | genlmsg_end(msg, hdr); | |
11710 | ||
68eb5503 | 11711 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11712 | NL80211_MCGRP_MLME, gfp); |
84f10708 TP |
11713 | return; |
11714 | ||
11715 | nla_put_failure: | |
11716 | genlmsg_cancel(msg, hdr); | |
11717 | nlmsg_free(msg); | |
11718 | } | |
947add36 | 11719 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
84f10708 | 11720 | |
04f39047 SW |
11721 | void |
11722 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 11723 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
11724 | enum nl80211_radar_event event, |
11725 | struct net_device *netdev, gfp_t gfp) | |
11726 | { | |
11727 | struct sk_buff *msg; | |
11728 | void *hdr; | |
11729 | ||
11730 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11731 | if (!msg) | |
11732 | return; | |
11733 | ||
11734 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
11735 | if (!hdr) { | |
11736 | nlmsg_free(msg); | |
11737 | return; | |
11738 | } | |
11739 | ||
11740 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
11741 | goto nla_put_failure; | |
11742 | ||
11743 | /* NOP and radar events don't need a netdev parameter */ | |
11744 | if (netdev) { | |
11745 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
11746 | ||
11747 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11748 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11749 | goto nla_put_failure; | |
11750 | } | |
11751 | ||
11752 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
11753 | goto nla_put_failure; | |
11754 | ||
11755 | if (nl80211_send_chandef(msg, chandef)) | |
11756 | goto nla_put_failure; | |
11757 | ||
9c90a9f6 | 11758 | genlmsg_end(msg, hdr); |
04f39047 | 11759 | |
68eb5503 | 11760 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11761 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
11762 | return; |
11763 | ||
11764 | nla_put_failure: | |
11765 | genlmsg_cancel(msg, hdr); | |
11766 | nlmsg_free(msg); | |
11767 | } | |
11768 | ||
947add36 JB |
11769 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
11770 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
c063dbf5 | 11771 | { |
947add36 JB |
11772 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11773 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11774 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
c063dbf5 JB |
11775 | struct sk_buff *msg; |
11776 | struct nlattr *pinfoattr; | |
11777 | void *hdr; | |
11778 | ||
947add36 JB |
11779 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
11780 | ||
58050fce | 11781 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
11782 | if (!msg) |
11783 | return; | |
11784 | ||
11785 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11786 | if (!hdr) { | |
11787 | nlmsg_free(msg); | |
11788 | return; | |
11789 | } | |
11790 | ||
9360ffd1 | 11791 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 11792 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9360ffd1 DM |
11793 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
11794 | goto nla_put_failure; | |
c063dbf5 JB |
11795 | |
11796 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11797 | if (!pinfoattr) | |
11798 | goto nla_put_failure; | |
11799 | ||
9360ffd1 DM |
11800 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
11801 | goto nla_put_failure; | |
c063dbf5 JB |
11802 | |
11803 | nla_nest_end(msg, pinfoattr); | |
11804 | ||
3b7b72ee | 11805 | genlmsg_end(msg, hdr); |
c063dbf5 | 11806 | |
68eb5503 | 11807 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11808 | NL80211_MCGRP_MLME, gfp); |
c063dbf5 JB |
11809 | return; |
11810 | ||
11811 | nla_put_failure: | |
11812 | genlmsg_cancel(msg, hdr); | |
11813 | nlmsg_free(msg); | |
11814 | } | |
947add36 | 11815 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
c063dbf5 | 11816 | |
7f6cf311 JB |
11817 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
11818 | u64 cookie, bool acked, gfp_t gfp) | |
11819 | { | |
11820 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 11821 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
11822 | struct sk_buff *msg; |
11823 | void *hdr; | |
7f6cf311 | 11824 | |
4ee3e063 BL |
11825 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
11826 | ||
58050fce | 11827 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 11828 | |
7f6cf311 JB |
11829 | if (!msg) |
11830 | return; | |
11831 | ||
11832 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
11833 | if (!hdr) { | |
11834 | nlmsg_free(msg); | |
11835 | return; | |
11836 | } | |
11837 | ||
9360ffd1 DM |
11838 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11839 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11840 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
11841 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
11842 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
11843 | goto nla_put_failure; | |
7f6cf311 | 11844 | |
9c90a9f6 | 11845 | genlmsg_end(msg, hdr); |
7f6cf311 | 11846 | |
68eb5503 | 11847 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11848 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
11849 | return; |
11850 | ||
11851 | nla_put_failure: | |
11852 | genlmsg_cancel(msg, hdr); | |
11853 | nlmsg_free(msg); | |
11854 | } | |
11855 | EXPORT_SYMBOL(cfg80211_probe_status); | |
11856 | ||
5e760230 JB |
11857 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
11858 | const u8 *frame, size_t len, | |
37c73b5f | 11859 | int freq, int sig_dbm) |
5e760230 | 11860 | { |
f26cbf40 | 11861 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
11862 | struct sk_buff *msg; |
11863 | void *hdr; | |
37c73b5f | 11864 | struct cfg80211_beacon_registration *reg; |
5e760230 | 11865 | |
4ee3e063 BL |
11866 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
11867 | ||
37c73b5f BG |
11868 | spin_lock_bh(&rdev->beacon_registrations_lock); |
11869 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
11870 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
11871 | if (!msg) { | |
11872 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
11873 | return; | |
11874 | } | |
5e760230 | 11875 | |
37c73b5f BG |
11876 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
11877 | if (!hdr) | |
11878 | goto nla_put_failure; | |
5e760230 | 11879 | |
37c73b5f BG |
11880 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11881 | (freq && | |
11882 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
11883 | (sig_dbm && | |
11884 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
11885 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
11886 | goto nla_put_failure; | |
5e760230 | 11887 | |
37c73b5f | 11888 | genlmsg_end(msg, hdr); |
5e760230 | 11889 | |
37c73b5f BG |
11890 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
11891 | } | |
11892 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
11893 | return; |
11894 | ||
11895 | nla_put_failure: | |
37c73b5f BG |
11896 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
11897 | if (hdr) | |
11898 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
11899 | nlmsg_free(msg); |
11900 | } | |
11901 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
11902 | ||
cd8f7cb4 JB |
11903 | #ifdef CONFIG_PM |
11904 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | |
11905 | struct cfg80211_wowlan_wakeup *wakeup, | |
11906 | gfp_t gfp) | |
11907 | { | |
f26cbf40 | 11908 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
11909 | struct sk_buff *msg; |
11910 | void *hdr; | |
9c90a9f6 | 11911 | int size = 200; |
cd8f7cb4 JB |
11912 | |
11913 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
11914 | ||
11915 | if (wakeup) | |
11916 | size += wakeup->packet_present_len; | |
11917 | ||
11918 | msg = nlmsg_new(size, gfp); | |
11919 | if (!msg) | |
11920 | return; | |
11921 | ||
11922 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
11923 | if (!hdr) | |
11924 | goto free_msg; | |
11925 | ||
11926 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11927 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11928 | goto free_msg; | |
11929 | ||
11930 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
11931 | wdev->netdev->ifindex)) | |
11932 | goto free_msg; | |
11933 | ||
11934 | if (wakeup) { | |
11935 | struct nlattr *reasons; | |
11936 | ||
11937 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
11938 | if (!reasons) |
11939 | goto free_msg; | |
cd8f7cb4 JB |
11940 | |
11941 | if (wakeup->disconnect && | |
11942 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
11943 | goto free_msg; | |
11944 | if (wakeup->magic_pkt && | |
11945 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
11946 | goto free_msg; | |
11947 | if (wakeup->gtk_rekey_failure && | |
11948 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
11949 | goto free_msg; | |
11950 | if (wakeup->eap_identity_req && | |
11951 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
11952 | goto free_msg; | |
11953 | if (wakeup->four_way_handshake && | |
11954 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
11955 | goto free_msg; | |
11956 | if (wakeup->rfkill_release && | |
11957 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
11958 | goto free_msg; | |
11959 | ||
11960 | if (wakeup->pattern_idx >= 0 && | |
11961 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
11962 | wakeup->pattern_idx)) | |
11963 | goto free_msg; | |
11964 | ||
ae917c9f JB |
11965 | if (wakeup->tcp_match && |
11966 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
11967 | goto free_msg; | |
2a0e047e | 11968 | |
ae917c9f JB |
11969 | if (wakeup->tcp_connlost && |
11970 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
11971 | goto free_msg; | |
2a0e047e | 11972 | |
ae917c9f JB |
11973 | if (wakeup->tcp_nomoretokens && |
11974 | nla_put_flag(msg, | |
11975 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
11976 | goto free_msg; | |
2a0e047e | 11977 | |
cd8f7cb4 JB |
11978 | if (wakeup->packet) { |
11979 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
11980 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
11981 | ||
11982 | if (!wakeup->packet_80211) { | |
11983 | pkt_attr = | |
11984 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
11985 | len_attr = | |
11986 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
11987 | } | |
11988 | ||
11989 | if (wakeup->packet_len && | |
11990 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
11991 | goto free_msg; | |
11992 | ||
11993 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
11994 | wakeup->packet)) | |
11995 | goto free_msg; | |
11996 | } | |
11997 | ||
11998 | nla_nest_end(msg, reasons); | |
11999 | } | |
12000 | ||
9c90a9f6 | 12001 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 12002 | |
68eb5503 | 12003 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12004 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
12005 | return; |
12006 | ||
12007 | free_msg: | |
12008 | nlmsg_free(msg); | |
12009 | } | |
12010 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
12011 | #endif | |
12012 | ||
3475b094 JM |
12013 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
12014 | enum nl80211_tdls_operation oper, | |
12015 | u16 reason_code, gfp_t gfp) | |
12016 | { | |
12017 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12018 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
12019 | struct sk_buff *msg; |
12020 | void *hdr; | |
3475b094 JM |
12021 | |
12022 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
12023 | reason_code); | |
12024 | ||
12025 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12026 | if (!msg) | |
12027 | return; | |
12028 | ||
12029 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
12030 | if (!hdr) { | |
12031 | nlmsg_free(msg); | |
12032 | return; | |
12033 | } | |
12034 | ||
12035 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12036 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12037 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
12038 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
12039 | (reason_code > 0 && | |
12040 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
12041 | goto nla_put_failure; | |
12042 | ||
9c90a9f6 | 12043 | genlmsg_end(msg, hdr); |
3475b094 | 12044 | |
68eb5503 | 12045 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12046 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
12047 | return; |
12048 | ||
12049 | nla_put_failure: | |
12050 | genlmsg_cancel(msg, hdr); | |
12051 | nlmsg_free(msg); | |
12052 | } | |
12053 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
12054 | ||
026331c4 JM |
12055 | static int nl80211_netlink_notify(struct notifier_block * nb, |
12056 | unsigned long state, | |
12057 | void *_notify) | |
12058 | { | |
12059 | struct netlink_notify *notify = _notify; | |
12060 | struct cfg80211_registered_device *rdev; | |
12061 | struct wireless_dev *wdev; | |
37c73b5f | 12062 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
12063 | |
12064 | if (state != NETLINK_URELEASE) | |
12065 | return NOTIFY_DONE; | |
12066 | ||
12067 | rcu_read_lock(); | |
12068 | ||
5e760230 | 12069 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
78f22b6a JB |
12070 | bool schedule_destroy_work = false; |
12071 | ||
12072 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { | |
15e47304 | 12073 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 12074 | |
78f22b6a JB |
12075 | if (wdev->owner_nlportid == notify->portid) |
12076 | schedule_destroy_work = true; | |
12077 | } | |
12078 | ||
37c73b5f BG |
12079 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12080 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
12081 | list) { | |
12082 | if (reg->nlportid == notify->portid) { | |
12083 | list_del(®->list); | |
12084 | kfree(reg); | |
12085 | break; | |
12086 | } | |
12087 | } | |
12088 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
78f22b6a JB |
12089 | |
12090 | if (schedule_destroy_work) { | |
12091 | struct cfg80211_iface_destroy *destroy; | |
12092 | ||
12093 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | |
12094 | if (destroy) { | |
12095 | destroy->nlportid = notify->portid; | |
12096 | spin_lock(&rdev->destroy_list_lock); | |
12097 | list_add(&destroy->list, &rdev->destroy_list); | |
12098 | spin_unlock(&rdev->destroy_list_lock); | |
12099 | schedule_work(&rdev->destroy_work); | |
12100 | } | |
12101 | } | |
5e760230 | 12102 | } |
026331c4 JM |
12103 | |
12104 | rcu_read_unlock(); | |
12105 | ||
6784c7db | 12106 | return NOTIFY_OK; |
026331c4 JM |
12107 | } |
12108 | ||
12109 | static struct notifier_block nl80211_netlink_notifier = { | |
12110 | .notifier_call = nl80211_netlink_notify, | |
12111 | }; | |
12112 | ||
355199e0 JM |
12113 | void cfg80211_ft_event(struct net_device *netdev, |
12114 | struct cfg80211_ft_event_params *ft_event) | |
12115 | { | |
12116 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 12117 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
12118 | struct sk_buff *msg; |
12119 | void *hdr; | |
355199e0 JM |
12120 | |
12121 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
12122 | ||
12123 | if (!ft_event->target_ap) | |
12124 | return; | |
12125 | ||
12126 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12127 | if (!msg) | |
12128 | return; | |
12129 | ||
12130 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
12131 | if (!hdr) |
12132 | goto out; | |
355199e0 | 12133 | |
ae917c9f JB |
12134 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12135 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12136 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
12137 | goto out; | |
355199e0 | 12138 | |
ae917c9f JB |
12139 | if (ft_event->ies && |
12140 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
12141 | goto out; | |
12142 | if (ft_event->ric_ies && | |
12143 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
12144 | ft_event->ric_ies)) | |
12145 | goto out; | |
355199e0 | 12146 | |
9c90a9f6 | 12147 | genlmsg_end(msg, hdr); |
355199e0 | 12148 | |
68eb5503 | 12149 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12150 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
12151 | return; |
12152 | out: | |
12153 | nlmsg_free(msg); | |
355199e0 JM |
12154 | } |
12155 | EXPORT_SYMBOL(cfg80211_ft_event); | |
12156 | ||
5de17984 AS |
12157 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
12158 | { | |
12159 | struct cfg80211_registered_device *rdev; | |
12160 | struct sk_buff *msg; | |
12161 | void *hdr; | |
12162 | u32 nlportid; | |
12163 | ||
f26cbf40 | 12164 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
12165 | if (!rdev->crit_proto_nlportid) |
12166 | return; | |
12167 | ||
12168 | nlportid = rdev->crit_proto_nlportid; | |
12169 | rdev->crit_proto_nlportid = 0; | |
12170 | ||
12171 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12172 | if (!msg) | |
12173 | return; | |
12174 | ||
12175 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
12176 | if (!hdr) | |
12177 | goto nla_put_failure; | |
12178 | ||
12179 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12180 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12181 | goto nla_put_failure; | |
12182 | ||
12183 | genlmsg_end(msg, hdr); | |
12184 | ||
12185 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
12186 | return; | |
12187 | ||
12188 | nla_put_failure: | |
12189 | if (hdr) | |
12190 | genlmsg_cancel(msg, hdr); | |
12191 | nlmsg_free(msg); | |
12192 | ||
12193 | } | |
12194 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
12195 | ||
348baf0e JB |
12196 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
12197 | { | |
12198 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12199 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
12200 | struct sk_buff *msg; |
12201 | void *hdr; | |
12202 | ||
12203 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12204 | if (!msg) | |
12205 | return; | |
12206 | ||
12207 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
12208 | if (!hdr) | |
12209 | goto out; | |
12210 | ||
12211 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12212 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
12213 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12214 | goto out; | |
12215 | ||
12216 | genlmsg_end(msg, hdr); | |
12217 | ||
12218 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
12219 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
12220 | return; | |
12221 | out: | |
12222 | nlmsg_free(msg); | |
12223 | } | |
12224 | ||
55682965 JB |
12225 | /* initialisation/exit functions */ |
12226 | ||
12227 | int nl80211_init(void) | |
12228 | { | |
0d63cbb5 | 12229 | int err; |
55682965 | 12230 | |
2a94fe48 JB |
12231 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
12232 | nl80211_mcgrps); | |
55682965 JB |
12233 | if (err) |
12234 | return err; | |
12235 | ||
026331c4 JM |
12236 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
12237 | if (err) | |
12238 | goto err_out; | |
12239 | ||
55682965 JB |
12240 | return 0; |
12241 | err_out: | |
12242 | genl_unregister_family(&nl80211_fam); | |
12243 | return err; | |
12244 | } | |
12245 | ||
12246 | void nl80211_exit(void) | |
12247 | { | |
026331c4 | 12248 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
12249 | genl_unregister_family(&nl80211_fam); |
12250 | } |