]>
Commit | Line | Data |
---|---|---|
55682965 JB |
1 | /* |
2 | * This is the new netlink-based wireless configuration interface. | |
3 | * | |
026331c4 | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
2740f0cf | 5 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
55682965 JB |
6 | */ |
7 | ||
8 | #include <linux/if.h> | |
9 | #include <linux/module.h> | |
10 | #include <linux/err.h> | |
5a0e3ad6 | 11 | #include <linux/slab.h> |
55682965 JB |
12 | #include <linux/list.h> |
13 | #include <linux/if_ether.h> | |
14 | #include <linux/ieee80211.h> | |
15 | #include <linux/nl80211.h> | |
16 | #include <linux/rtnetlink.h> | |
17 | #include <linux/netlink.h> | |
2a519311 | 18 | #include <linux/etherdevice.h> |
463d0183 | 19 | #include <net/net_namespace.h> |
55682965 JB |
20 | #include <net/genetlink.h> |
21 | #include <net/cfg80211.h> | |
463d0183 | 22 | #include <net/sock.h> |
2a0e047e | 23 | #include <net/inet_connection_sock.h> |
55682965 JB |
24 | #include "core.h" |
25 | #include "nl80211.h" | |
b2e1b302 | 26 | #include "reg.h" |
e35e4d28 | 27 | #include "rdev-ops.h" |
55682965 | 28 | |
5fb628e9 JM |
29 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
30 | struct genl_info *info, | |
31 | struct cfg80211_crypto_settings *settings, | |
32 | int cipher_limit); | |
33 | ||
f84f771d | 34 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 | 35 | struct genl_info *info); |
f84f771d | 36 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
37 | struct genl_info *info); |
38 | ||
55682965 JB |
39 | /* the netlink family */ |
40 | static struct genl_family nl80211_fam = { | |
fb4e1568 MH |
41 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
42 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ | |
43 | .hdrsize = 0, /* no private header */ | |
44 | .version = 1, /* no particular meaning now */ | |
55682965 | 45 | .maxattr = NL80211_ATTR_MAX, |
463d0183 | 46 | .netnsok = true, |
4c476991 JB |
47 | .pre_doit = nl80211_pre_doit, |
48 | .post_doit = nl80211_post_doit, | |
55682965 JB |
49 | }; |
50 | ||
2a94fe48 JB |
51 | /* multicast groups */ |
52 | enum nl80211_multicast_groups { | |
53 | NL80211_MCGRP_CONFIG, | |
54 | NL80211_MCGRP_SCAN, | |
55 | NL80211_MCGRP_REGULATORY, | |
56 | NL80211_MCGRP_MLME, | |
567ffc35 | 57 | NL80211_MCGRP_VENDOR, |
2a94fe48 JB |
58 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
59 | }; | |
60 | ||
61 | static const struct genl_multicast_group nl80211_mcgrps[] = { | |
71b836ec JB |
62 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
63 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, | |
64 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, | |
65 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, | |
66 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, | |
2a94fe48 | 67 | #ifdef CONFIG_NL80211_TESTMODE |
71b836ec | 68 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
2a94fe48 JB |
69 | #endif |
70 | }; | |
71 | ||
89a54e48 JB |
72 | /* returns ERR_PTR values */ |
73 | static struct wireless_dev * | |
74 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 75 | { |
89a54e48 JB |
76 | struct cfg80211_registered_device *rdev; |
77 | struct wireless_dev *result = NULL; | |
78 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
79 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
80 | u64 wdev_id; | |
81 | int wiphy_idx = -1; | |
82 | int ifidx = -1; | |
55682965 | 83 | |
5fe231e8 | 84 | ASSERT_RTNL(); |
55682965 | 85 | |
89a54e48 JB |
86 | if (!have_ifidx && !have_wdev_id) |
87 | return ERR_PTR(-EINVAL); | |
55682965 | 88 | |
89a54e48 JB |
89 | if (have_ifidx) |
90 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
91 | if (have_wdev_id) { | |
92 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
93 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
94 | } |
95 | ||
89a54e48 JB |
96 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
97 | struct wireless_dev *wdev; | |
98 | ||
99 | if (wiphy_net(&rdev->wiphy) != netns) | |
100 | continue; | |
101 | ||
102 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
103 | continue; | |
104 | ||
89a54e48 JB |
105 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
106 | if (have_ifidx && wdev->netdev && | |
107 | wdev->netdev->ifindex == ifidx) { | |
108 | result = wdev; | |
109 | break; | |
110 | } | |
111 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
112 | result = wdev; | |
113 | break; | |
114 | } | |
115 | } | |
89a54e48 JB |
116 | |
117 | if (result) | |
118 | break; | |
119 | } | |
120 | ||
121 | if (result) | |
122 | return result; | |
123 | return ERR_PTR(-ENODEV); | |
55682965 JB |
124 | } |
125 | ||
a9455408 | 126 | static struct cfg80211_registered_device * |
878d9ec7 | 127 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 128 | { |
7fee4778 JB |
129 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
130 | struct net_device *netdev; | |
a9455408 | 131 | |
5fe231e8 | 132 | ASSERT_RTNL(); |
a9455408 | 133 | |
878d9ec7 | 134 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
135 | !attrs[NL80211_ATTR_IFINDEX] && |
136 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
137 | return ERR_PTR(-EINVAL); |
138 | ||
878d9ec7 | 139 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 140 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 141 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 142 | |
89a54e48 JB |
143 | if (attrs[NL80211_ATTR_WDEV]) { |
144 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
145 | struct wireless_dev *wdev; | |
146 | bool found = false; | |
147 | ||
148 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
149 | if (tmp) { | |
150 | /* make sure wdev exists */ | |
89a54e48 JB |
151 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
152 | if (wdev->identifier != (u32)wdev_id) | |
153 | continue; | |
154 | found = true; | |
155 | break; | |
156 | } | |
89a54e48 JB |
157 | |
158 | if (!found) | |
159 | tmp = NULL; | |
160 | ||
161 | if (rdev && tmp != rdev) | |
162 | return ERR_PTR(-EINVAL); | |
163 | rdev = tmp; | |
164 | } | |
165 | } | |
166 | ||
878d9ec7 JB |
167 | if (attrs[NL80211_ATTR_IFINDEX]) { |
168 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
7f2b8562 | 169 | netdev = __dev_get_by_index(netns, ifindex); |
7fee4778 JB |
170 | if (netdev) { |
171 | if (netdev->ieee80211_ptr) | |
f26cbf40 ZG |
172 | tmp = wiphy_to_rdev( |
173 | netdev->ieee80211_ptr->wiphy); | |
7fee4778 JB |
174 | else |
175 | tmp = NULL; | |
176 | ||
7fee4778 JB |
177 | /* not wireless device -- return error */ |
178 | if (!tmp) | |
179 | return ERR_PTR(-EINVAL); | |
180 | ||
181 | /* mismatch -- return error */ | |
182 | if (rdev && tmp != rdev) | |
183 | return ERR_PTR(-EINVAL); | |
184 | ||
185 | rdev = tmp; | |
a9455408 | 186 | } |
a9455408 | 187 | } |
a9455408 | 188 | |
4f7eff10 JB |
189 | if (!rdev) |
190 | return ERR_PTR(-ENODEV); | |
a9455408 | 191 | |
4f7eff10 JB |
192 | if (netns != wiphy_net(&rdev->wiphy)) |
193 | return ERR_PTR(-ENODEV); | |
194 | ||
195 | return rdev; | |
a9455408 JB |
196 | } |
197 | ||
198 | /* | |
199 | * This function returns a pointer to the driver | |
200 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
201 | * |
202 | * The result of this can be a PTR_ERR and hence must | |
203 | * be checked with IS_ERR() for errors. | |
204 | */ | |
205 | static struct cfg80211_registered_device * | |
4f7eff10 | 206 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 207 | { |
5fe231e8 | 208 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
209 | } |
210 | ||
55682965 | 211 | /* policy for the attributes */ |
8cd4d456 | 212 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
55682965 JB |
213 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
214 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 215 | .len = 20-1 }, |
31888487 | 216 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 217 | |
72bdcf34 | 218 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 219 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
220 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
221 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
222 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
223 | ||
b9a5f8ca JM |
224 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
225 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
226 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
227 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 228 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
3057dbfd | 229 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
55682965 JB |
230 | |
231 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
232 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
233 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 234 | |
e007b857 EP |
235 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
236 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 237 | |
b9454e83 | 238 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
239 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
240 | .len = WLAN_MAX_KEY_LEN }, | |
241 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
242 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
243 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 244 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 245 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
246 | |
247 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
248 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
249 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
250 | .len = IEEE80211_MAX_DATA_LEN }, | |
251 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
252 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
253 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
254 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
255 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
256 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
257 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 258 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 259 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 260 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 261 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 262 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 263 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 264 | |
b2e1b302 LR |
265 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
266 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
267 | ||
9f1ba906 JM |
268 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
269 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
270 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
271 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
272 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 273 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 274 | |
24bdd9f4 | 275 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 276 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 277 | |
6c739419 | 278 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
279 | |
280 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
281 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
282 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
283 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
284 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
285 | |
286 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
287 | .len = IEEE80211_MAX_SSID_LEN }, | |
288 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
289 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 290 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 291 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 292 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
293 | [NL80211_ATTR_STA_FLAGS2] = { |
294 | .len = sizeof(struct nl80211_sta_flag_update), | |
295 | }, | |
3f77316c | 296 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
297 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
298 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
299 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
300 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
301 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 302 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 303 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
304 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
305 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
306 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
307 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 308 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
309 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
310 | .len = IEEE80211_MAX_DATA_LEN }, | |
311 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 312 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 313 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 314 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 315 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
316 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
317 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 318 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
319 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
320 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 321 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 322 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 323 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 324 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 325 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 326 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 327 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 328 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 329 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
330 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
331 | .len = IEEE80211_MAX_DATA_LEN }, | |
332 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
333 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 334 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 335 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 336 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
337 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
338 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
339 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
340 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
341 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
31fa97c5 | 342 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
e247bd90 | 343 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
344 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
345 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 346 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
347 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
348 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
349 | .len = NL80211_HT_CAPABILITY_LEN | |
350 | }, | |
1d9d9213 | 351 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 352 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 353 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 354 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 355 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
e39e5b5e | 356 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
f461be3e | 357 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
ed473771 | 358 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
53cabad7 JB |
359 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
360 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | |
77765eaf VT |
361 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
362 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
363 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
364 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 365 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
366 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
367 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
368 | .len = NL80211_VHT_CAPABILITY_LEN, | |
369 | }, | |
355199e0 JM |
370 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
371 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
372 | .len = IEEE80211_MAX_DATA_LEN }, | |
5e4b6f56 | 373 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
16ef1fe2 SW |
374 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
375 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | |
376 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | |
9a774c78 AO |
377 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
378 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, | |
c01fc9ad SD |
379 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
380 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, | |
5336fa88 | 381 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
60f4a7b1 | 382 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
ad7e718c JB |
383 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
384 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, | |
385 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, | |
fa9ffc74 KP |
386 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
387 | .len = IEEE80211_QOS_MAP_LEN_MAX }, | |
1df4a510 JM |
388 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
389 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, | |
df942e7b | 390 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
18e5ca65 | 391 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
34d22ce2 | 392 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
bab5ab7d | 393 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
960d01ac JB |
394 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
395 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, | |
396 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, | |
18998c38 | 397 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
ad2b26ab | 398 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
1bdd716c | 399 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
4b681c82 | 400 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
9c748934 | 401 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
55682965 JB |
402 | }; |
403 | ||
e31b8213 | 404 | /* policy for the key attributes */ |
b54452b0 | 405 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 406 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
407 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
408 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 409 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
410 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
411 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 412 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
413 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
414 | }; | |
415 | ||
416 | /* policy for the key default flags */ | |
417 | static const struct nla_policy | |
418 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
419 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
420 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
421 | }; |
422 | ||
ff1b6e69 JB |
423 | /* policy for WoWLAN attributes */ |
424 | static const struct nla_policy | |
425 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
426 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
427 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
428 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
429 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
430 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
431 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
432 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
433 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e | 434 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
8cd4d456 | 435 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
2a0e047e JB |
436 | }; |
437 | ||
438 | static const struct nla_policy | |
439 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
440 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
441 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
442 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
443 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
444 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
445 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
446 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
447 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
448 | }, | |
449 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
450 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
451 | }, | |
452 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
453 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
454 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
455 | }; |
456 | ||
be29b99a AK |
457 | /* policy for coalesce rule attributes */ |
458 | static const struct nla_policy | |
459 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
460 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
461 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
462 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
463 | }; | |
464 | ||
e5497d76 JB |
465 | /* policy for GTK rekey offload attributes */ |
466 | static const struct nla_policy | |
467 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
468 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
469 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
470 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
471 | }; | |
472 | ||
a1f1c21c LC |
473 | static const struct nla_policy |
474 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 475 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 476 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 477 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
478 | }; |
479 | ||
97990a06 JB |
480 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
481 | struct netlink_callback *cb, | |
482 | struct cfg80211_registered_device **rdev, | |
483 | struct wireless_dev **wdev) | |
a043897a | 484 | { |
97990a06 | 485 | int err; |
a043897a | 486 | |
97990a06 | 487 | rtnl_lock(); |
a043897a | 488 | |
97990a06 JB |
489 | if (!cb->args[0]) { |
490 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
491 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
492 | nl80211_policy); | |
493 | if (err) | |
494 | goto out_unlock; | |
67748893 | 495 | |
97990a06 JB |
496 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
497 | nl80211_fam.attrbuf); | |
498 | if (IS_ERR(*wdev)) { | |
499 | err = PTR_ERR(*wdev); | |
500 | goto out_unlock; | |
501 | } | |
f26cbf40 | 502 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
503 | /* 0 is the first index - add 1 to parse only once */ |
504 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
505 | cb->args[1] = (*wdev)->identifier; |
506 | } else { | |
c319d50b JB |
507 | /* subtract the 1 again here */ |
508 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 509 | struct wireless_dev *tmp; |
67748893 | 510 | |
97990a06 JB |
511 | if (!wiphy) { |
512 | err = -ENODEV; | |
513 | goto out_unlock; | |
514 | } | |
f26cbf40 | 515 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 516 | *wdev = NULL; |
67748893 | 517 | |
97990a06 JB |
518 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
519 | if (tmp->identifier == cb->args[1]) { | |
520 | *wdev = tmp; | |
521 | break; | |
522 | } | |
523 | } | |
67748893 | 524 | |
97990a06 JB |
525 | if (!*wdev) { |
526 | err = -ENODEV; | |
527 | goto out_unlock; | |
528 | } | |
67748893 JB |
529 | } |
530 | ||
67748893 | 531 | return 0; |
97990a06 | 532 | out_unlock: |
67748893 JB |
533 | rtnl_unlock(); |
534 | return err; | |
535 | } | |
536 | ||
97990a06 | 537 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 538 | { |
67748893 JB |
539 | rtnl_unlock(); |
540 | } | |
541 | ||
f4a11bb0 JB |
542 | /* IE validation */ |
543 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
544 | { | |
545 | const u8 *pos; | |
546 | int len; | |
547 | ||
548 | if (!attr) | |
549 | return true; | |
550 | ||
551 | pos = nla_data(attr); | |
552 | len = nla_len(attr); | |
553 | ||
554 | while (len) { | |
555 | u8 elemlen; | |
556 | ||
557 | if (len < 2) | |
558 | return false; | |
559 | len -= 2; | |
560 | ||
561 | elemlen = pos[1]; | |
562 | if (elemlen > len) | |
563 | return false; | |
564 | ||
565 | len -= elemlen; | |
566 | pos += 2 + elemlen; | |
567 | } | |
568 | ||
569 | return true; | |
570 | } | |
571 | ||
55682965 | 572 | /* message building helper */ |
15e47304 | 573 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
574 | int flags, u8 cmd) |
575 | { | |
576 | /* since there is no private header just add the generic one */ | |
15e47304 | 577 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
578 | } |
579 | ||
5dab3b8a | 580 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
581 | struct ieee80211_channel *chan, |
582 | bool large) | |
5dab3b8a | 583 | { |
ea077c1c RL |
584 | /* Some channels must be completely excluded from the |
585 | * list to protect old user-space tools from breaking | |
586 | */ | |
587 | if (!large && chan->flags & | |
588 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
589 | return 0; | |
590 | ||
9360ffd1 DM |
591 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
592 | chan->center_freq)) | |
593 | goto nla_put_failure; | |
5dab3b8a | 594 | |
9360ffd1 DM |
595 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
596 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
597 | goto nla_put_failure; | |
8fe02e16 LR |
598 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
599 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
600 | goto nla_put_failure; | |
601 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
602 | goto nla_put_failure; | |
603 | } | |
cdc89b97 JB |
604 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
605 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
606 | goto nla_put_failure; | |
607 | if (large) { | |
608 | u32 time; | |
609 | ||
610 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
611 | ||
612 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
613 | chan->dfs_state)) | |
614 | goto nla_put_failure; | |
615 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
616 | time)) | |
617 | goto nla_put_failure; | |
089027e5 JD |
618 | if (nla_put_u32(msg, |
619 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
620 | chan->dfs_cac_ms)) | |
621 | goto nla_put_failure; | |
cdc89b97 JB |
622 | } |
623 | } | |
5dab3b8a | 624 | |
fe1abafd JB |
625 | if (large) { |
626 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
627 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
628 | goto nla_put_failure; | |
629 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
630 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
631 | goto nla_put_failure; | |
632 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
633 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
634 | goto nla_put_failure; | |
635 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
636 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
637 | goto nla_put_failure; | |
570dbde1 DS |
638 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
639 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
640 | goto nla_put_failure; | |
641 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && | |
642 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) | |
643 | goto nla_put_failure; | |
ea077c1c RL |
644 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
645 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
646 | goto nla_put_failure; | |
647 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
648 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
649 | goto nla_put_failure; | |
fe1abafd JB |
650 | } |
651 | ||
9360ffd1 DM |
652 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
653 | DBM_TO_MBM(chan->max_power))) | |
654 | goto nla_put_failure; | |
5dab3b8a LR |
655 | |
656 | return 0; | |
657 | ||
658 | nla_put_failure: | |
659 | return -ENOBUFS; | |
660 | } | |
661 | ||
55682965 JB |
662 | /* netlink command implementations */ |
663 | ||
b9454e83 JB |
664 | struct key_parse { |
665 | struct key_params p; | |
666 | int idx; | |
e31b8213 | 667 | int type; |
b9454e83 | 668 | bool def, defmgmt; |
dbd2fd65 | 669 | bool def_uni, def_multi; |
b9454e83 JB |
670 | }; |
671 | ||
672 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
673 | { | |
674 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
675 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
676 | nl80211_key_policy); | |
677 | if (err) | |
678 | return err; | |
679 | ||
680 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
681 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
682 | ||
dbd2fd65 JB |
683 | if (k->def) { |
684 | k->def_uni = true; | |
685 | k->def_multi = true; | |
686 | } | |
687 | if (k->defmgmt) | |
688 | k->def_multi = true; | |
689 | ||
b9454e83 JB |
690 | if (tb[NL80211_KEY_IDX]) |
691 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
692 | ||
693 | if (tb[NL80211_KEY_DATA]) { | |
694 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
695 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
696 | } | |
697 | ||
698 | if (tb[NL80211_KEY_SEQ]) { | |
699 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
700 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
701 | } | |
702 | ||
703 | if (tb[NL80211_KEY_CIPHER]) | |
704 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
705 | ||
e31b8213 JB |
706 | if (tb[NL80211_KEY_TYPE]) { |
707 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
708 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
709 | return -EINVAL; | |
710 | } | |
711 | ||
dbd2fd65 JB |
712 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
713 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
714 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
715 | tb[NL80211_KEY_DEFAULT_TYPES], | |
716 | nl80211_key_default_policy); | |
dbd2fd65 JB |
717 | if (err) |
718 | return err; | |
719 | ||
720 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
721 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
722 | } | |
723 | ||
b9454e83 JB |
724 | return 0; |
725 | } | |
726 | ||
727 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
728 | { | |
729 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
730 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
731 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
732 | } | |
733 | ||
734 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
735 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
736 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
737 | } | |
738 | ||
739 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
740 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
741 | ||
742 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
743 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
744 | ||
745 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
746 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
747 | ||
dbd2fd65 JB |
748 | if (k->def) { |
749 | k->def_uni = true; | |
750 | k->def_multi = true; | |
751 | } | |
752 | if (k->defmgmt) | |
753 | k->def_multi = true; | |
754 | ||
e31b8213 JB |
755 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
756 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
757 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
758 | return -EINVAL; | |
759 | } | |
760 | ||
dbd2fd65 JB |
761 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
762 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
763 | int err = nla_parse_nested( | |
764 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
765 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
766 | nl80211_key_default_policy); | |
767 | if (err) | |
768 | return err; | |
769 | ||
770 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
771 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
772 | } | |
773 | ||
b9454e83 JB |
774 | return 0; |
775 | } | |
776 | ||
777 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
778 | { | |
779 | int err; | |
780 | ||
781 | memset(k, 0, sizeof(*k)); | |
782 | k->idx = -1; | |
e31b8213 | 783 | k->type = -1; |
b9454e83 JB |
784 | |
785 | if (info->attrs[NL80211_ATTR_KEY]) | |
786 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
787 | else | |
788 | err = nl80211_parse_key_old(info, k); | |
789 | ||
790 | if (err) | |
791 | return err; | |
792 | ||
793 | if (k->def && k->defmgmt) | |
794 | return -EINVAL; | |
795 | ||
dbd2fd65 JB |
796 | if (k->defmgmt) { |
797 | if (k->def_uni || !k->def_multi) | |
798 | return -EINVAL; | |
799 | } | |
800 | ||
b9454e83 JB |
801 | if (k->idx != -1) { |
802 | if (k->defmgmt) { | |
803 | if (k->idx < 4 || k->idx > 5) | |
804 | return -EINVAL; | |
805 | } else if (k->def) { | |
806 | if (k->idx < 0 || k->idx > 3) | |
807 | return -EINVAL; | |
808 | } else { | |
809 | if (k->idx < 0 || k->idx > 5) | |
810 | return -EINVAL; | |
811 | } | |
812 | } | |
813 | ||
814 | return 0; | |
815 | } | |
816 | ||
fffd0934 JB |
817 | static struct cfg80211_cached_keys * |
818 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 819 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
820 | { |
821 | struct key_parse parse; | |
822 | struct nlattr *key; | |
823 | struct cfg80211_cached_keys *result; | |
824 | int rem, err, def = 0; | |
825 | ||
826 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
827 | if (!result) | |
828 | return ERR_PTR(-ENOMEM); | |
829 | ||
830 | result->def = -1; | |
831 | result->defmgmt = -1; | |
832 | ||
833 | nla_for_each_nested(key, keys, rem) { | |
834 | memset(&parse, 0, sizeof(parse)); | |
835 | parse.idx = -1; | |
836 | ||
837 | err = nl80211_parse_key_new(key, &parse); | |
838 | if (err) | |
839 | goto error; | |
840 | err = -EINVAL; | |
841 | if (!parse.p.key) | |
842 | goto error; | |
843 | if (parse.idx < 0 || parse.idx > 4) | |
844 | goto error; | |
845 | if (parse.def) { | |
846 | if (def) | |
847 | goto error; | |
848 | def = 1; | |
849 | result->def = parse.idx; | |
dbd2fd65 JB |
850 | if (!parse.def_uni || !parse.def_multi) |
851 | goto error; | |
fffd0934 JB |
852 | } else if (parse.defmgmt) |
853 | goto error; | |
854 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 855 | parse.idx, false, NULL); |
fffd0934 JB |
856 | if (err) |
857 | goto error; | |
858 | result->params[parse.idx].cipher = parse.p.cipher; | |
859 | result->params[parse.idx].key_len = parse.p.key_len; | |
860 | result->params[parse.idx].key = result->data[parse.idx]; | |
861 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
862 | |
863 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
864 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
865 | if (no_ht) | |
866 | *no_ht = true; | |
867 | } | |
fffd0934 JB |
868 | } |
869 | ||
870 | return result; | |
871 | error: | |
872 | kfree(result); | |
873 | return ERR_PTR(err); | |
874 | } | |
875 | ||
876 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
877 | { | |
878 | ASSERT_WDEV_LOCK(wdev); | |
879 | ||
fffd0934 JB |
880 | switch (wdev->iftype) { |
881 | case NL80211_IFTYPE_AP: | |
882 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 883 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 884 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
885 | break; |
886 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 887 | case NL80211_IFTYPE_STATION: |
074ac8df | 888 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 889 | if (!wdev->current_bss) |
fffd0934 JB |
890 | return -ENOLINK; |
891 | break; | |
de4fcbad | 892 | case NL80211_IFTYPE_UNSPECIFIED: |
6e0bd6c3 | 893 | case NL80211_IFTYPE_OCB: |
de4fcbad JB |
894 | case NL80211_IFTYPE_MONITOR: |
895 | case NL80211_IFTYPE_P2P_DEVICE: | |
896 | case NL80211_IFTYPE_WDS: | |
897 | case NUM_NL80211_IFTYPES: | |
fffd0934 JB |
898 | return -EINVAL; |
899 | } | |
900 | ||
901 | return 0; | |
902 | } | |
903 | ||
664834de JM |
904 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
905 | struct nlattr *tb) | |
906 | { | |
907 | struct ieee80211_channel *chan; | |
908 | ||
909 | if (tb == NULL) | |
910 | return NULL; | |
911 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
912 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
913 | return NULL; | |
914 | return chan; | |
915 | } | |
916 | ||
7527a782 JB |
917 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
918 | { | |
919 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
920 | int i; | |
921 | ||
922 | if (!nl_modes) | |
923 | goto nla_put_failure; | |
924 | ||
925 | i = 0; | |
926 | while (ifmodes) { | |
9360ffd1 DM |
927 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
928 | goto nla_put_failure; | |
7527a782 JB |
929 | ifmodes >>= 1; |
930 | i++; | |
931 | } | |
932 | ||
933 | nla_nest_end(msg, nl_modes); | |
934 | return 0; | |
935 | ||
936 | nla_put_failure: | |
937 | return -ENOBUFS; | |
938 | } | |
939 | ||
940 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
941 | struct sk_buff *msg, |
942 | bool large) | |
7527a782 JB |
943 | { |
944 | struct nlattr *nl_combis; | |
945 | int i, j; | |
946 | ||
947 | nl_combis = nla_nest_start(msg, | |
948 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
949 | if (!nl_combis) | |
950 | goto nla_put_failure; | |
951 | ||
952 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
953 | const struct ieee80211_iface_combination *c; | |
954 | struct nlattr *nl_combi, *nl_limits; | |
955 | ||
956 | c = &wiphy->iface_combinations[i]; | |
957 | ||
958 | nl_combi = nla_nest_start(msg, i + 1); | |
959 | if (!nl_combi) | |
960 | goto nla_put_failure; | |
961 | ||
962 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
963 | if (!nl_limits) | |
964 | goto nla_put_failure; | |
965 | ||
966 | for (j = 0; j < c->n_limits; j++) { | |
967 | struct nlattr *nl_limit; | |
968 | ||
969 | nl_limit = nla_nest_start(msg, j + 1); | |
970 | if (!nl_limit) | |
971 | goto nla_put_failure; | |
9360ffd1 DM |
972 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
973 | c->limits[j].max)) | |
974 | goto nla_put_failure; | |
7527a782 JB |
975 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
976 | c->limits[j].types)) | |
977 | goto nla_put_failure; | |
978 | nla_nest_end(msg, nl_limit); | |
979 | } | |
980 | ||
981 | nla_nest_end(msg, nl_limits); | |
982 | ||
9360ffd1 DM |
983 | if (c->beacon_int_infra_match && |
984 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
985 | goto nla_put_failure; | |
986 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
987 | c->num_different_channels) || | |
988 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
989 | c->max_interfaces)) | |
990 | goto nla_put_failure; | |
cdc89b97 | 991 | if (large && |
8c48b50a FF |
992 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
993 | c->radar_detect_widths) || | |
994 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
995 | c->radar_detect_regions))) | |
cdc89b97 | 996 | goto nla_put_failure; |
7527a782 JB |
997 | |
998 | nla_nest_end(msg, nl_combi); | |
999 | } | |
1000 | ||
1001 | nla_nest_end(msg, nl_combis); | |
1002 | ||
1003 | return 0; | |
1004 | nla_put_failure: | |
1005 | return -ENOBUFS; | |
1006 | } | |
1007 | ||
3713b4e3 | 1008 | #ifdef CONFIG_PM |
b56cf720 JB |
1009 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
1010 | struct sk_buff *msg) | |
1011 | { | |
964dc9e2 | 1012 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
1013 | struct nlattr *nl_tcp; |
1014 | ||
1015 | if (!tcp) | |
1016 | return 0; | |
1017 | ||
1018 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
1019 | if (!nl_tcp) | |
1020 | return -ENOBUFS; | |
1021 | ||
1022 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1023 | tcp->data_payload_max)) | |
1024 | return -ENOBUFS; | |
1025 | ||
1026 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1027 | tcp->data_payload_max)) | |
1028 | return -ENOBUFS; | |
1029 | ||
1030 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1031 | return -ENOBUFS; | |
1032 | ||
1033 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1034 | sizeof(*tcp->tok), tcp->tok)) | |
1035 | return -ENOBUFS; | |
1036 | ||
1037 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1038 | tcp->data_interval_max)) | |
1039 | return -ENOBUFS; | |
1040 | ||
1041 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1042 | tcp->wake_payload_max)) | |
1043 | return -ENOBUFS; | |
1044 | ||
1045 | nla_nest_end(msg, nl_tcp); | |
1046 | return 0; | |
1047 | } | |
1048 | ||
3713b4e3 | 1049 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1050 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1051 | bool large) |
55682965 | 1052 | { |
3713b4e3 | 1053 | struct nlattr *nl_wowlan; |
55682965 | 1054 | |
1b8ec87a | 1055 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1056 | return 0; |
55682965 | 1057 | |
3713b4e3 JB |
1058 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1059 | if (!nl_wowlan) | |
1060 | return -ENOBUFS; | |
9360ffd1 | 1061 | |
1b8ec87a | 1062 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1063 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1064 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1065 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1066 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1067 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1068 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1069 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1070 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1071 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1072 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1073 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1074 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1075 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1076 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1077 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1078 | return -ENOBUFS; | |
9360ffd1 | 1079 | |
1b8ec87a | 1080 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1081 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1082 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1083 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1084 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1085 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1086 | }; |
9360ffd1 | 1087 | |
3713b4e3 JB |
1088 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1089 | sizeof(pat), &pat)) | |
1090 | return -ENOBUFS; | |
1091 | } | |
9360ffd1 | 1092 | |
75453ccb LC |
1093 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
1094 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, | |
1095 | rdev->wiphy.wowlan->max_nd_match_sets)) | |
1096 | return -ENOBUFS; | |
1097 | ||
1b8ec87a | 1098 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1099 | return -ENOBUFS; |
1100 | ||
8cd4d456 LC |
1101 | /* TODO: send wowlan net detect */ |
1102 | ||
3713b4e3 | 1103 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1104 | |
3713b4e3 JB |
1105 | return 0; |
1106 | } | |
1107 | #endif | |
9360ffd1 | 1108 | |
be29b99a | 1109 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1110 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1111 | { |
1112 | struct nl80211_coalesce_rule_support rule; | |
1113 | ||
1b8ec87a | 1114 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1115 | return 0; |
1116 | ||
1b8ec87a ZG |
1117 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1118 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1119 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1120 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1121 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1122 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1123 | |
1124 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1125 | return -ENOBUFS; | |
1126 | ||
1127 | return 0; | |
1128 | } | |
1129 | ||
3713b4e3 JB |
1130 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1131 | struct ieee80211_supported_band *sband) | |
1132 | { | |
1133 | struct nlattr *nl_rates, *nl_rate; | |
1134 | struct ieee80211_rate *rate; | |
1135 | int i; | |
87bbbe22 | 1136 | |
3713b4e3 JB |
1137 | /* add HT info */ |
1138 | if (sband->ht_cap.ht_supported && | |
1139 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1140 | sizeof(sband->ht_cap.mcs), | |
1141 | &sband->ht_cap.mcs) || | |
1142 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1143 | sband->ht_cap.cap) || | |
1144 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1145 | sband->ht_cap.ampdu_factor) || | |
1146 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1147 | sband->ht_cap.ampdu_density))) | |
1148 | return -ENOBUFS; | |
afe0cbf8 | 1149 | |
3713b4e3 JB |
1150 | /* add VHT info */ |
1151 | if (sband->vht_cap.vht_supported && | |
1152 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1153 | sizeof(sband->vht_cap.vht_mcs), | |
1154 | &sband->vht_cap.vht_mcs) || | |
1155 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1156 | sband->vht_cap.cap))) | |
1157 | return -ENOBUFS; | |
f59ac048 | 1158 | |
3713b4e3 JB |
1159 | /* add bitrates */ |
1160 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1161 | if (!nl_rates) | |
1162 | return -ENOBUFS; | |
ee688b00 | 1163 | |
3713b4e3 JB |
1164 | for (i = 0; i < sband->n_bitrates; i++) { |
1165 | nl_rate = nla_nest_start(msg, i); | |
1166 | if (!nl_rate) | |
1167 | return -ENOBUFS; | |
ee688b00 | 1168 | |
3713b4e3 JB |
1169 | rate = &sband->bitrates[i]; |
1170 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1171 | rate->bitrate)) | |
1172 | return -ENOBUFS; | |
1173 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1174 | nla_put_flag(msg, | |
1175 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1176 | return -ENOBUFS; | |
ee688b00 | 1177 | |
3713b4e3 JB |
1178 | nla_nest_end(msg, nl_rate); |
1179 | } | |
d51626df | 1180 | |
3713b4e3 | 1181 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1182 | |
3713b4e3 JB |
1183 | return 0; |
1184 | } | |
ee688b00 | 1185 | |
3713b4e3 JB |
1186 | static int |
1187 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1188 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1189 | { | |
1190 | u16 stypes; | |
1191 | struct nlattr *nl_ftypes, *nl_ifs; | |
1192 | enum nl80211_iftype ift; | |
1193 | int i; | |
ee688b00 | 1194 | |
3713b4e3 JB |
1195 | if (!mgmt_stypes) |
1196 | return 0; | |
5dab3b8a | 1197 | |
3713b4e3 JB |
1198 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1199 | if (!nl_ifs) | |
1200 | return -ENOBUFS; | |
e2f367f2 | 1201 | |
3713b4e3 JB |
1202 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1203 | nl_ftypes = nla_nest_start(msg, ift); | |
1204 | if (!nl_ftypes) | |
1205 | return -ENOBUFS; | |
1206 | i = 0; | |
1207 | stypes = mgmt_stypes[ift].tx; | |
1208 | while (stypes) { | |
1209 | if ((stypes & 1) && | |
1210 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1211 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1212 | return -ENOBUFS; | |
1213 | stypes >>= 1; | |
1214 | i++; | |
ee688b00 | 1215 | } |
3713b4e3 JB |
1216 | nla_nest_end(msg, nl_ftypes); |
1217 | } | |
ee688b00 | 1218 | |
3713b4e3 | 1219 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1220 | |
3713b4e3 JB |
1221 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1222 | if (!nl_ifs) | |
1223 | return -ENOBUFS; | |
ee688b00 | 1224 | |
3713b4e3 JB |
1225 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1226 | nl_ftypes = nla_nest_start(msg, ift); | |
1227 | if (!nl_ftypes) | |
1228 | return -ENOBUFS; | |
1229 | i = 0; | |
1230 | stypes = mgmt_stypes[ift].rx; | |
1231 | while (stypes) { | |
1232 | if ((stypes & 1) && | |
1233 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1234 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1235 | return -ENOBUFS; | |
1236 | stypes >>= 1; | |
1237 | i++; | |
1238 | } | |
1239 | nla_nest_end(msg, nl_ftypes); | |
1240 | } | |
1241 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1242 | |
3713b4e3 JB |
1243 | return 0; |
1244 | } | |
ee688b00 | 1245 | |
86e8cf98 JB |
1246 | struct nl80211_dump_wiphy_state { |
1247 | s64 filter_wiphy; | |
1248 | long start; | |
1249 | long split_start, band_start, chan_start; | |
1250 | bool split; | |
1251 | }; | |
1252 | ||
1b8ec87a | 1253 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 1254 | enum nl80211_commands cmd, |
3713b4e3 | 1255 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1256 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1257 | { |
1258 | void *hdr; | |
1259 | struct nlattr *nl_bands, *nl_band; | |
1260 | struct nlattr *nl_freqs, *nl_freq; | |
1261 | struct nlattr *nl_cmds; | |
1262 | enum ieee80211_band band; | |
1263 | struct ieee80211_channel *chan; | |
1264 | int i; | |
1265 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1266 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1267 | u32 features; |
ee688b00 | 1268 | |
3bb20556 | 1269 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
1270 | if (!hdr) |
1271 | return -ENOBUFS; | |
ee688b00 | 1272 | |
86e8cf98 JB |
1273 | if (WARN_ON(!state)) |
1274 | return -EINVAL; | |
ee688b00 | 1275 | |
1b8ec87a | 1276 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1277 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1278 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1279 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1280 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1281 | goto nla_put_failure; |
1282 | ||
3bb20556 JB |
1283 | if (cmd != NL80211_CMD_NEW_WIPHY) |
1284 | goto finish; | |
1285 | ||
86e8cf98 | 1286 | switch (state->split_start) { |
3713b4e3 JB |
1287 | case 0: |
1288 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1289 | rdev->wiphy.retry_short) || |
3713b4e3 | 1290 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1291 | rdev->wiphy.retry_long) || |
3713b4e3 | 1292 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1293 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1294 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1295 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1296 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1297 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1298 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1299 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1300 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1301 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1302 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1303 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1304 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1305 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1306 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
1b8ec87a | 1307 | rdev->wiphy.max_match_sets)) |
9360ffd1 | 1308 | goto nla_put_failure; |
3713b4e3 | 1309 | |
1b8ec87a | 1310 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1311 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1312 | goto nla_put_failure; |
1b8ec87a | 1313 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1314 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1315 | goto nla_put_failure; | |
1b8ec87a | 1316 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1317 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1318 | goto nla_put_failure; | |
1b8ec87a | 1319 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1320 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1321 | goto nla_put_failure; | |
1b8ec87a | 1322 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1323 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1324 | goto nla_put_failure; | |
1b8ec87a | 1325 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1326 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1327 | goto nla_put_failure; |
86e8cf98 JB |
1328 | state->split_start++; |
1329 | if (state->split) | |
3713b4e3 JB |
1330 | break; |
1331 | case 1: | |
1332 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1333 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1334 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1335 | goto nla_put_failure; |
4745fc09 | 1336 | |
3713b4e3 | 1337 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1338 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1339 | goto nla_put_failure; |
b23aa676 | 1340 | |
1b8ec87a | 1341 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1342 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1343 | goto nla_put_failure; |
b23aa676 | 1344 | |
3713b4e3 | 1345 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1346 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1347 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1348 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1349 | goto nla_put_failure; |
b23aa676 | 1350 | |
1b8ec87a | 1351 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1352 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1353 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1354 | goto nla_put_failure; |
8fdc621d | 1355 | |
1b8ec87a ZG |
1356 | if ((rdev->wiphy.available_antennas_tx || |
1357 | rdev->wiphy.available_antennas_rx) && | |
1358 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1359 | u32 tx_ant = 0, rx_ant = 0; |
1360 | int res; | |
1b8ec87a | 1361 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1362 | if (!res) { |
1363 | if (nla_put_u32(msg, | |
1364 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1365 | tx_ant) || | |
1366 | nla_put_u32(msg, | |
1367 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1368 | rx_ant)) | |
1369 | goto nla_put_failure; | |
1370 | } | |
1371 | } | |
a293911d | 1372 | |
86e8cf98 JB |
1373 | state->split_start++; |
1374 | if (state->split) | |
3713b4e3 JB |
1375 | break; |
1376 | case 2: | |
1377 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1378 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1379 | goto nla_put_failure; |
86e8cf98 JB |
1380 | state->split_start++; |
1381 | if (state->split) | |
3713b4e3 JB |
1382 | break; |
1383 | case 3: | |
1384 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1385 | if (!nl_bands) | |
1386 | goto nla_put_failure; | |
f7ca38df | 1387 | |
86e8cf98 JB |
1388 | for (band = state->band_start; |
1389 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1390 | struct ieee80211_supported_band *sband; |
2e161f78 | 1391 | |
1b8ec87a | 1392 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1393 | |
3713b4e3 JB |
1394 | if (!sband) |
1395 | continue; | |
1396 | ||
1397 | nl_band = nla_nest_start(msg, band); | |
1398 | if (!nl_band) | |
2e161f78 | 1399 | goto nla_put_failure; |
3713b4e3 | 1400 | |
86e8cf98 | 1401 | switch (state->chan_start) { |
3713b4e3 JB |
1402 | case 0: |
1403 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1404 | goto nla_put_failure; |
86e8cf98 JB |
1405 | state->chan_start++; |
1406 | if (state->split) | |
3713b4e3 JB |
1407 | break; |
1408 | default: | |
1409 | /* add frequencies */ | |
1410 | nl_freqs = nla_nest_start( | |
1411 | msg, NL80211_BAND_ATTR_FREQS); | |
1412 | if (!nl_freqs) | |
1413 | goto nla_put_failure; | |
1414 | ||
86e8cf98 | 1415 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1416 | i < sband->n_channels; |
1417 | i++) { | |
1418 | nl_freq = nla_nest_start(msg, i); | |
1419 | if (!nl_freq) | |
1420 | goto nla_put_failure; | |
1421 | ||
1422 | chan = &sband->channels[i]; | |
1423 | ||
86e8cf98 JB |
1424 | if (nl80211_msg_put_channel( |
1425 | msg, chan, | |
1426 | state->split)) | |
3713b4e3 JB |
1427 | goto nla_put_failure; |
1428 | ||
1429 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1430 | if (state->split) |
3713b4e3 JB |
1431 | break; |
1432 | } | |
1433 | if (i < sband->n_channels) | |
86e8cf98 | 1434 | state->chan_start = i + 2; |
3713b4e3 | 1435 | else |
86e8cf98 | 1436 | state->chan_start = 0; |
3713b4e3 JB |
1437 | nla_nest_end(msg, nl_freqs); |
1438 | } | |
1439 | ||
1440 | nla_nest_end(msg, nl_band); | |
1441 | ||
86e8cf98 | 1442 | if (state->split) { |
3713b4e3 | 1443 | /* start again here */ |
86e8cf98 | 1444 | if (state->chan_start) |
3713b4e3 JB |
1445 | band--; |
1446 | break; | |
2e161f78 | 1447 | } |
2e161f78 | 1448 | } |
3713b4e3 | 1449 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1450 | |
3713b4e3 | 1451 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1452 | state->band_start = band + 1; |
3713b4e3 | 1453 | else |
86e8cf98 | 1454 | state->band_start = 0; |
74b70a4e | 1455 | |
3713b4e3 | 1456 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1457 | if (state->band_start == 0 && state->chan_start == 0) |
1458 | state->split_start++; | |
1459 | if (state->split) | |
3713b4e3 JB |
1460 | break; |
1461 | case 4: | |
1462 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1463 | if (!nl_cmds) | |
2e161f78 JB |
1464 | goto nla_put_failure; |
1465 | ||
3713b4e3 JB |
1466 | i = 0; |
1467 | #define CMD(op, n) \ | |
1468 | do { \ | |
1b8ec87a | 1469 | if (rdev->ops->op) { \ |
3713b4e3 JB |
1470 | i++; \ |
1471 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1472 | goto nla_put_failure; \ | |
1473 | } \ | |
1474 | } while (0) | |
1475 | ||
1476 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1477 | CMD(change_virtual_intf, SET_INTERFACE); | |
1478 | CMD(add_key, NEW_KEY); | |
1479 | CMD(start_ap, START_AP); | |
1480 | CMD(add_station, NEW_STATION); | |
1481 | CMD(add_mpath, NEW_MPATH); | |
1482 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1483 | CMD(change_bss, SET_BSS); | |
1484 | CMD(auth, AUTHENTICATE); | |
1485 | CMD(assoc, ASSOCIATE); | |
1486 | CMD(deauth, DEAUTHENTICATE); | |
1487 | CMD(disassoc, DISASSOCIATE); | |
1488 | CMD(join_ibss, JOIN_IBSS); | |
1489 | CMD(join_mesh, JOIN_MESH); | |
1490 | CMD(set_pmksa, SET_PMKSA); | |
1491 | CMD(del_pmksa, DEL_PMKSA); | |
1492 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1b8ec87a | 1493 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
3713b4e3 JB |
1494 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
1495 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1496 | CMD(mgmt_tx, FRAME); | |
1497 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1b8ec87a | 1498 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
3713b4e3 JB |
1499 | i++; |
1500 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1501 | goto nla_put_failure; |
2e161f78 | 1502 | } |
1b8ec87a ZG |
1503 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
1504 | rdev->ops->join_mesh) { | |
3713b4e3 JB |
1505 | i++; |
1506 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1507 | goto nla_put_failure; | |
1508 | } | |
1509 | CMD(set_wds_peer, SET_WDS_PEER); | |
1b8ec87a | 1510 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
3713b4e3 JB |
1511 | CMD(tdls_mgmt, TDLS_MGMT); |
1512 | CMD(tdls_oper, TDLS_OPER); | |
1513 | } | |
1b8ec87a | 1514 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
3713b4e3 JB |
1515 | CMD(sched_scan_start, START_SCHED_SCAN); |
1516 | CMD(probe_client, PROBE_CLIENT); | |
1517 | CMD(set_noack_map, SET_NOACK_MAP); | |
1b8ec87a | 1518 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
3713b4e3 JB |
1519 | i++; |
1520 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1521 | goto nla_put_failure; | |
1522 | } | |
1523 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1524 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
02df00eb JB |
1525 | #ifdef CONFIG_NL80211_TESTMODE |
1526 | CMD(testmode_cmd, TESTMODE); | |
1527 | #endif | |
86e8cf98 | 1528 | if (state->split) { |
5de17984 AS |
1529 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1530 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 1531 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 1532 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 1533 | CMD(set_qos_map, SET_QOS_MAP); |
723e73ac JB |
1534 | if (rdev->wiphy.features & |
1535 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | |
960d01ac | 1536 | CMD(add_tx_ts, ADD_TX_TS); |
5de17984 | 1537 | } |
02df00eb | 1538 | /* add into the if now */ |
3713b4e3 | 1539 | #undef CMD |
ff1b6e69 | 1540 | |
1b8ec87a | 1541 | if (rdev->ops->connect || rdev->ops->auth) { |
3713b4e3 JB |
1542 | i++; |
1543 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1544 | goto nla_put_failure; |
ff1b6e69 JB |
1545 | } |
1546 | ||
1b8ec87a | 1547 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
3713b4e3 JB |
1548 | i++; |
1549 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1550 | goto nla_put_failure; | |
1551 | } | |
1552 | ||
1553 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1554 | state->split_start++; |
1555 | if (state->split) | |
3713b4e3 JB |
1556 | break; |
1557 | case 5: | |
1b8ec87a ZG |
1558 | if (rdev->ops->remain_on_channel && |
1559 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
1560 | nla_put_u32(msg, |
1561 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 1562 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
1563 | goto nla_put_failure; |
1564 | ||
1b8ec87a | 1565 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
1566 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
1567 | goto nla_put_failure; | |
1568 | ||
1569 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1570 | goto nla_put_failure; | |
86e8cf98 JB |
1571 | state->split_start++; |
1572 | if (state->split) | |
3713b4e3 JB |
1573 | break; |
1574 | case 6: | |
1575 | #ifdef CONFIG_PM | |
1b8ec87a | 1576 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 1577 | goto nla_put_failure; |
86e8cf98 JB |
1578 | state->split_start++; |
1579 | if (state->split) | |
3713b4e3 JB |
1580 | break; |
1581 | #else | |
86e8cf98 | 1582 | state->split_start++; |
dfb89c56 | 1583 | #endif |
3713b4e3 JB |
1584 | case 7: |
1585 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 1586 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 1587 | goto nla_put_failure; |
ff1b6e69 | 1588 | |
1b8ec87a | 1589 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 1590 | state->split)) |
3713b4e3 | 1591 | goto nla_put_failure; |
7527a782 | 1592 | |
86e8cf98 JB |
1593 | state->split_start++; |
1594 | if (state->split) | |
3713b4e3 JB |
1595 | break; |
1596 | case 8: | |
1b8ec87a | 1597 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 1598 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 1599 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 1600 | goto nla_put_failure; |
7527a782 | 1601 | |
1b8ec87a | 1602 | features = rdev->wiphy.features; |
fe1abafd JB |
1603 | /* |
1604 | * We can only add the per-channel limit information if the | |
1605 | * dump is split, otherwise it makes it too big. Therefore | |
1606 | * only advertise it in that case. | |
1607 | */ | |
86e8cf98 | 1608 | if (state->split) |
fe1abafd JB |
1609 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1610 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1611 | goto nla_put_failure; |
562a7480 | 1612 | |
1b8ec87a | 1613 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 1614 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
1615 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
1616 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 1617 | goto nla_put_failure; |
1f074bd8 | 1618 | |
1b8ec87a ZG |
1619 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1620 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 1621 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 1622 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 1623 | goto nla_put_failure; |
7e7c8926 | 1624 | |
3713b4e3 JB |
1625 | /* |
1626 | * Any information below this point is only available to | |
1627 | * applications that can deal with it being split. This | |
1628 | * helps ensure that newly added capabilities don't break | |
1629 | * older tools by overrunning their buffers. | |
1630 | * | |
1631 | * We still increment split_start so that in the split | |
1632 | * case we'll continue with more data in the next round, | |
1633 | * but break unconditionally so unsplit data stops here. | |
1634 | */ | |
86e8cf98 | 1635 | state->split_start++; |
3713b4e3 JB |
1636 | break; |
1637 | case 9: | |
1b8ec87a | 1638 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 1639 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
1640 | rdev->wiphy.extended_capabilities_len, |
1641 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 1642 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
1643 | rdev->wiphy.extended_capabilities_len, |
1644 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 1645 | goto nla_put_failure; |
a50df0c4 | 1646 | |
1b8ec87a | 1647 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 1648 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
1649 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
1650 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
1651 | goto nla_put_failure; |
1652 | ||
be29b99a AK |
1653 | state->split_start++; |
1654 | break; | |
1655 | case 10: | |
1b8ec87a | 1656 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
1657 | goto nla_put_failure; |
1658 | ||
1b8ec87a | 1659 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
1660 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
1661 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1662 | goto nla_put_failure; | |
b43504cf | 1663 | |
1b8ec87a | 1664 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 1665 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 1666 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
1667 | goto nla_put_failure; |
1668 | ||
ad7e718c JB |
1669 | state->split_start++; |
1670 | break; | |
1671 | case 11: | |
1b8ec87a | 1672 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
1673 | const struct nl80211_vendor_cmd_info *info; |
1674 | struct nlattr *nested; | |
1675 | ||
1676 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1677 | if (!nested) | |
1678 | goto nla_put_failure; | |
1679 | ||
1b8ec87a ZG |
1680 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
1681 | info = &rdev->wiphy.vendor_commands[i].info; | |
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 | } | |
1687 | ||
1b8ec87a | 1688 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
1689 | const struct nl80211_vendor_cmd_info *info; |
1690 | struct nlattr *nested; | |
ad7e718c | 1691 | |
567ffc35 JB |
1692 | nested = nla_nest_start(msg, |
1693 | NL80211_ATTR_VENDOR_EVENTS); | |
1694 | if (!nested) | |
ad7e718c | 1695 | goto nla_put_failure; |
567ffc35 | 1696 | |
1b8ec87a ZG |
1697 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
1698 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
1699 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1700 | goto nla_put_failure; | |
1701 | } | |
1702 | nla_nest_end(msg, nested); | |
1703 | } | |
9a774c78 AO |
1704 | state->split_start++; |
1705 | break; | |
1706 | case 12: | |
1707 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
1708 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
1709 | rdev->wiphy.max_num_csa_counters)) | |
1710 | goto nla_put_failure; | |
01e0daa4 | 1711 | |
1bdd716c AN |
1712 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
1713 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
1714 | goto nla_put_failure; | |
1715 | ||
d75bb06b GKS |
1716 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
1717 | sizeof(rdev->wiphy.ext_features), | |
1718 | rdev->wiphy.ext_features)) | |
1719 | goto nla_put_failure; | |
1720 | ||
3713b4e3 | 1721 | /* done */ |
86e8cf98 | 1722 | state->split_start = 0; |
3713b4e3 JB |
1723 | break; |
1724 | } | |
3bb20556 | 1725 | finish: |
55682965 JB |
1726 | return genlmsg_end(msg, hdr); |
1727 | ||
1728 | nla_put_failure: | |
bc3ed28c TG |
1729 | genlmsg_cancel(msg, hdr); |
1730 | return -EMSGSIZE; | |
55682965 JB |
1731 | } |
1732 | ||
86e8cf98 JB |
1733 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1734 | struct netlink_callback *cb, | |
1735 | struct nl80211_dump_wiphy_state *state) | |
1736 | { | |
1737 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1738 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1739 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1740 | /* ignore parse errors for backward compatibility */ | |
1741 | if (ret) | |
1742 | return 0; | |
1743 | ||
1744 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1745 | if (tb[NL80211_ATTR_WIPHY]) | |
1746 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1747 | if (tb[NL80211_ATTR_WDEV]) | |
1748 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1749 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1750 | struct net_device *netdev; | |
1751 | struct cfg80211_registered_device *rdev; | |
1752 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1753 | ||
7f2b8562 | 1754 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1755 | if (!netdev) |
1756 | return -ENODEV; | |
1757 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1758 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1759 | netdev->ieee80211_ptr->wiphy); |
1760 | state->filter_wiphy = rdev->wiphy_idx; | |
1761 | } | |
86e8cf98 JB |
1762 | } |
1763 | ||
1764 | return 0; | |
1765 | } | |
1766 | ||
55682965 JB |
1767 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1768 | { | |
645e77de | 1769 | int idx = 0, ret; |
86e8cf98 | 1770 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1771 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1772 | |
5fe231e8 | 1773 | rtnl_lock(); |
86e8cf98 JB |
1774 | if (!state) { |
1775 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1776 | if (!state) { |
1777 | rtnl_unlock(); | |
86e8cf98 | 1778 | return -ENOMEM; |
3713b4e3 | 1779 | } |
86e8cf98 JB |
1780 | state->filter_wiphy = -1; |
1781 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1782 | if (ret) { | |
1783 | kfree(state); | |
1784 | rtnl_unlock(); | |
1785 | return ret; | |
3713b4e3 | 1786 | } |
86e8cf98 | 1787 | cb->args[0] = (long)state; |
3713b4e3 JB |
1788 | } |
1789 | ||
1b8ec87a ZG |
1790 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1791 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1792 | continue; |
86e8cf98 | 1793 | if (++idx <= state->start) |
55682965 | 1794 | continue; |
86e8cf98 | 1795 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1796 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1797 | continue; |
1798 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1799 | do { | |
3bb20556 JB |
1800 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
1801 | skb, | |
3713b4e3 JB |
1802 | NETLINK_CB(cb->skb).portid, |
1803 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1804 | NLM_F_MULTI, state); |
3713b4e3 JB |
1805 | if (ret < 0) { |
1806 | /* | |
1807 | * If sending the wiphy data didn't fit (ENOBUFS | |
1808 | * or EMSGSIZE returned), this SKB is still | |
1809 | * empty (so it's not too big because another | |
1810 | * wiphy dataset is already in the skb) and | |
1811 | * we've not tried to adjust the dump allocation | |
1812 | * yet ... then adjust the alloc size to be | |
1813 | * bigger, and return 1 but with the empty skb. | |
1814 | * This results in an empty message being RX'ed | |
1815 | * in userspace, but that is ignored. | |
1816 | * | |
1817 | * We can then retry with the larger buffer. | |
1818 | */ | |
1819 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1820 | !skb->len && !state->split && |
3713b4e3 JB |
1821 | cb->min_dump_alloc < 4096) { |
1822 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1823 | state->split_start = 0; |
d98cae64 | 1824 | rtnl_unlock(); |
3713b4e3 JB |
1825 | return 1; |
1826 | } | |
1827 | idx--; | |
1828 | break; | |
645e77de | 1829 | } |
86e8cf98 | 1830 | } while (state->split_start > 0); |
3713b4e3 | 1831 | break; |
55682965 | 1832 | } |
5fe231e8 | 1833 | rtnl_unlock(); |
55682965 | 1834 | |
86e8cf98 | 1835 | state->start = idx; |
55682965 JB |
1836 | |
1837 | return skb->len; | |
1838 | } | |
1839 | ||
86e8cf98 JB |
1840 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1841 | { | |
1842 | kfree((void *)cb->args[0]); | |
1843 | return 0; | |
1844 | } | |
1845 | ||
55682965 JB |
1846 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1847 | { | |
1848 | struct sk_buff *msg; | |
1b8ec87a | 1849 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 1850 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1851 | |
645e77de | 1852 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1853 | if (!msg) |
4c476991 | 1854 | return -ENOMEM; |
55682965 | 1855 | |
3bb20556 JB |
1856 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
1857 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 1858 | &state) < 0) { |
4c476991 JB |
1859 | nlmsg_free(msg); |
1860 | return -ENOBUFS; | |
1861 | } | |
55682965 | 1862 | |
134e6375 | 1863 | return genlmsg_reply(msg, info); |
55682965 JB |
1864 | } |
1865 | ||
31888487 JM |
1866 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1867 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1868 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1869 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1870 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1871 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1872 | }; | |
1873 | ||
1874 | static int parse_txq_params(struct nlattr *tb[], | |
1875 | struct ieee80211_txq_params *txq_params) | |
1876 | { | |
a3304b0a | 1877 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1878 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1879 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1880 | return -EINVAL; | |
1881 | ||
a3304b0a | 1882 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1883 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1884 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1885 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1886 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1887 | ||
a3304b0a JB |
1888 | if (txq_params->ac >= NL80211_NUM_ACS) |
1889 | return -EINVAL; | |
1890 | ||
31888487 JM |
1891 | return 0; |
1892 | } | |
1893 | ||
f444de05 JB |
1894 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1895 | { | |
1896 | /* | |
cc1d2806 JB |
1897 | * You can only set the channel explicitly for WDS interfaces, |
1898 | * all others have their channel managed via their respective | |
1899 | * "establish a connection" command (connect, join, ...) | |
1900 | * | |
1901 | * For AP/GO and mesh mode, the channel can be set with the | |
1902 | * channel userspace API, but is only stored and passed to the | |
1903 | * low-level driver when the AP starts or the mesh is joined. | |
1904 | * This is for backward compatibility, userspace can also give | |
1905 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1906 | * |
1907 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1908 | * whatever else is going on, so they have their own special |
1909 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1910 | */ |
1911 | return !wdev || | |
1912 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1913 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1914 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1915 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1916 | } |
1917 | ||
683b6d3b JB |
1918 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1919 | struct genl_info *info, | |
1920 | struct cfg80211_chan_def *chandef) | |
1921 | { | |
dbeca2ea | 1922 | u32 control_freq; |
683b6d3b JB |
1923 | |
1924 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1925 | return -EINVAL; | |
1926 | ||
1927 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1928 | ||
1929 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1930 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1931 | chandef->center_freq1 = control_freq; | |
1932 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1933 | |
1934 | /* Primary channel not allowed */ | |
1935 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1936 | return -EINVAL; | |
1937 | ||
3d9d1d66 JB |
1938 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1939 | enum nl80211_channel_type chantype; | |
1940 | ||
1941 | chantype = nla_get_u32( | |
1942 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1943 | ||
1944 | switch (chantype) { | |
1945 | case NL80211_CHAN_NO_HT: | |
1946 | case NL80211_CHAN_HT20: | |
1947 | case NL80211_CHAN_HT40PLUS: | |
1948 | case NL80211_CHAN_HT40MINUS: | |
1949 | cfg80211_chandef_create(chandef, chandef->chan, | |
1950 | chantype); | |
1951 | break; | |
1952 | default: | |
1953 | return -EINVAL; | |
1954 | } | |
1955 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1956 | chandef->width = | |
1957 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1958 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1959 | chandef->center_freq1 = | |
1960 | nla_get_u32( | |
1961 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1962 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1963 | chandef->center_freq2 = | |
1964 | nla_get_u32( | |
1965 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1966 | } | |
1967 | ||
9f5e8f6e | 1968 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1969 | return -EINVAL; |
1970 | ||
9f5e8f6e JB |
1971 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1972 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1973 | return -EINVAL; |
1974 | ||
2f301ab2 SW |
1975 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1976 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1977 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1978 | return -EINVAL; | |
1979 | ||
683b6d3b JB |
1980 | return 0; |
1981 | } | |
1982 | ||
f444de05 | 1983 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 1984 | struct net_device *dev, |
f444de05 JB |
1985 | struct genl_info *info) |
1986 | { | |
683b6d3b | 1987 | struct cfg80211_chan_def chandef; |
f444de05 | 1988 | int result; |
e8c9bd5b | 1989 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 1990 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 1991 | |
e16821bc JM |
1992 | if (dev) |
1993 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
1994 | if (!nl80211_can_set_dev_channel(wdev)) |
1995 | return -EOPNOTSUPP; | |
e16821bc JM |
1996 | if (wdev) |
1997 | iftype = wdev->iftype; | |
f444de05 | 1998 | |
683b6d3b JB |
1999 | result = nl80211_parse_chandef(rdev, info, &chandef); |
2000 | if (result) | |
2001 | return result; | |
f444de05 | 2002 | |
e8c9bd5b | 2003 | switch (iftype) { |
aa430da4 JB |
2004 | case NL80211_IFTYPE_AP: |
2005 | case NL80211_IFTYPE_P2P_GO: | |
174e0cd2 | 2006 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
aa430da4 JB |
2007 | result = -EINVAL; |
2008 | break; | |
2009 | } | |
e16821bc JM |
2010 | if (wdev->beacon_interval) { |
2011 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
2012 | !(rdev->wiphy.features & | |
2013 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
2014 | result = -EBUSY; | |
2015 | break; | |
2016 | } | |
2017 | ||
2018 | /* Only allow dynamic channel width changes */ | |
2019 | if (chandef.chan != wdev->preset_chandef.chan) { | |
2020 | result = -EBUSY; | |
2021 | break; | |
2022 | } | |
2023 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
2024 | if (result) | |
2025 | break; | |
2026 | } | |
683b6d3b | 2027 | wdev->preset_chandef = chandef; |
aa430da4 JB |
2028 | result = 0; |
2029 | break; | |
cc1d2806 | 2030 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 2031 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 2032 | break; |
e8c9bd5b | 2033 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 2034 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 2035 | break; |
aa430da4 | 2036 | default: |
e8c9bd5b | 2037 | result = -EINVAL; |
f444de05 | 2038 | } |
f444de05 JB |
2039 | |
2040 | return result; | |
2041 | } | |
2042 | ||
2043 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2044 | { | |
4c476991 JB |
2045 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2046 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2047 | |
e16821bc | 2048 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2049 | } |
2050 | ||
e8347eba BJ |
2051 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2052 | { | |
43b19952 JB |
2053 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2054 | struct net_device *dev = info->user_ptr[1]; | |
2055 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2056 | const u8 *bssid; |
e8347eba BJ |
2057 | |
2058 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2059 | return -EINVAL; | |
2060 | ||
43b19952 JB |
2061 | if (netif_running(dev)) |
2062 | return -EBUSY; | |
e8347eba | 2063 | |
43b19952 JB |
2064 | if (!rdev->ops->set_wds_peer) |
2065 | return -EOPNOTSUPP; | |
e8347eba | 2066 | |
43b19952 JB |
2067 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2068 | return -EOPNOTSUPP; | |
e8347eba BJ |
2069 | |
2070 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2071 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2072 | } |
2073 | ||
2074 | ||
55682965 JB |
2075 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2076 | { | |
2077 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2078 | struct net_device *netdev = NULL; |
2079 | struct wireless_dev *wdev; | |
a1e567c8 | 2080 | int result = 0, rem_txq_params = 0; |
31888487 | 2081 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2082 | u32 changed; |
2083 | u8 retry_short = 0, retry_long = 0; | |
2084 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2085 | u8 coverage_class = 0; |
55682965 | 2086 | |
5fe231e8 JB |
2087 | ASSERT_RTNL(); |
2088 | ||
f444de05 JB |
2089 | /* |
2090 | * Try to find the wiphy and netdev. Normally this | |
2091 | * function shouldn't need the netdev, but this is | |
2092 | * done for backward compatibility -- previously | |
2093 | * setting the channel was done per wiphy, but now | |
2094 | * it is per netdev. Previous userland like hostapd | |
2095 | * also passed a netdev to set_wiphy, so that it is | |
2096 | * possible to let that go to the right netdev! | |
2097 | */ | |
4bbf4d56 | 2098 | |
f444de05 JB |
2099 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2100 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2101 | ||
7f2b8562 | 2102 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2103 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2104 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2105 | else |
f444de05 | 2106 | netdev = NULL; |
4bbf4d56 JB |
2107 | } |
2108 | ||
f444de05 | 2109 | if (!netdev) { |
878d9ec7 JB |
2110 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2111 | info->attrs); | |
5fe231e8 | 2112 | if (IS_ERR(rdev)) |
4c476991 | 2113 | return PTR_ERR(rdev); |
f444de05 JB |
2114 | wdev = NULL; |
2115 | netdev = NULL; | |
2116 | result = 0; | |
71fe96bf | 2117 | } else |
f444de05 | 2118 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2119 | |
2120 | /* | |
2121 | * end workaround code, by now the rdev is available | |
2122 | * and locked, and wdev may or may not be NULL. | |
2123 | */ | |
4bbf4d56 JB |
2124 | |
2125 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2126 | result = cfg80211_dev_rename( |
2127 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2128 | |
4bbf4d56 | 2129 | if (result) |
7f2b8562 | 2130 | return result; |
31888487 JM |
2131 | |
2132 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2133 | struct ieee80211_txq_params txq_params; | |
2134 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2135 | ||
7f2b8562 YX |
2136 | if (!rdev->ops->set_txq_params) |
2137 | return -EOPNOTSUPP; | |
31888487 | 2138 | |
7f2b8562 YX |
2139 | if (!netdev) |
2140 | return -EINVAL; | |
f70f01c2 | 2141 | |
133a3ff2 | 2142 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2143 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2144 | return -EINVAL; | |
133a3ff2 | 2145 | |
7f2b8562 YX |
2146 | if (!netif_running(netdev)) |
2147 | return -ENETDOWN; | |
2b5f8b0b | 2148 | |
31888487 JM |
2149 | nla_for_each_nested(nl_txq_params, |
2150 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2151 | rem_txq_params) { | |
ae811e21 JB |
2152 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2153 | nla_data(nl_txq_params), | |
2154 | nla_len(nl_txq_params), | |
2155 | txq_params_policy); | |
2156 | if (result) | |
2157 | return result; | |
31888487 JM |
2158 | result = parse_txq_params(tb, &txq_params); |
2159 | if (result) | |
7f2b8562 | 2160 | return result; |
31888487 | 2161 | |
e35e4d28 HG |
2162 | result = rdev_set_txq_params(rdev, netdev, |
2163 | &txq_params); | |
31888487 | 2164 | if (result) |
7f2b8562 | 2165 | return result; |
31888487 JM |
2166 | } |
2167 | } | |
55682965 | 2168 | |
72bdcf34 | 2169 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2170 | result = __nl80211_set_channel( |
2171 | rdev, | |
2172 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2173 | info); | |
72bdcf34 | 2174 | if (result) |
7f2b8562 | 2175 | return result; |
72bdcf34 JM |
2176 | } |
2177 | ||
98d2ff8b | 2178 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2179 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2180 | enum nl80211_tx_power_setting type; |
2181 | int idx, mbm = 0; | |
2182 | ||
c8442118 JB |
2183 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2184 | txp_wdev = NULL; | |
2185 | ||
7f2b8562 YX |
2186 | if (!rdev->ops->set_tx_power) |
2187 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2188 | |
2189 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2190 | type = nla_get_u32(info->attrs[idx]); | |
2191 | ||
2192 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2193 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2194 | return -EINVAL; | |
98d2ff8b JO |
2195 | |
2196 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2197 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2198 | mbm = nla_get_u32(info->attrs[idx]); | |
2199 | } | |
2200 | ||
c8442118 | 2201 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2202 | if (result) |
7f2b8562 | 2203 | return result; |
98d2ff8b JO |
2204 | } |
2205 | ||
afe0cbf8 BR |
2206 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2207 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2208 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2209 | if ((!rdev->wiphy.available_antennas_tx && |
2210 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2211 | !rdev->ops->set_antenna) |
2212 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2213 | |
2214 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2215 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2216 | ||
a7ffac95 | 2217 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2218 | * available antenna masks, except for the "all" mask */ |
2219 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2220 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2221 | return -EINVAL; | |
a7ffac95 | 2222 | |
7f531e03 BR |
2223 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2224 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2225 | |
e35e4d28 | 2226 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2227 | if (result) |
7f2b8562 | 2228 | return result; |
afe0cbf8 BR |
2229 | } |
2230 | ||
b9a5f8ca JM |
2231 | changed = 0; |
2232 | ||
2233 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2234 | retry_short = nla_get_u8( | |
2235 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2236 | if (retry_short == 0) |
2237 | return -EINVAL; | |
2238 | ||
b9a5f8ca JM |
2239 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2240 | } | |
2241 | ||
2242 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2243 | retry_long = nla_get_u8( | |
2244 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2245 | if (retry_long == 0) |
2246 | return -EINVAL; | |
2247 | ||
b9a5f8ca JM |
2248 | changed |= WIPHY_PARAM_RETRY_LONG; |
2249 | } | |
2250 | ||
2251 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2252 | frag_threshold = nla_get_u32( | |
2253 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2254 | if (frag_threshold < 256) |
2255 | return -EINVAL; | |
2256 | ||
b9a5f8ca JM |
2257 | if (frag_threshold != (u32) -1) { |
2258 | /* | |
2259 | * Fragments (apart from the last one) are required to | |
2260 | * have even length. Make the fragmentation code | |
2261 | * simpler by stripping LSB should someone try to use | |
2262 | * odd threshold value. | |
2263 | */ | |
2264 | frag_threshold &= ~0x1; | |
2265 | } | |
2266 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2267 | } | |
2268 | ||
2269 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2270 | rts_threshold = nla_get_u32( | |
2271 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2272 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2273 | } | |
2274 | ||
81077e82 | 2275 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
3057dbfd LB |
2276 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
2277 | return -EINVAL; | |
2278 | ||
81077e82 LT |
2279 | coverage_class = nla_get_u8( |
2280 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2281 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2282 | } | |
2283 | ||
3057dbfd LB |
2284 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
2285 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | |
2286 | return -EOPNOTSUPP; | |
2287 | ||
2288 | changed |= WIPHY_PARAM_DYN_ACK; | |
81077e82 LT |
2289 | } |
2290 | ||
b9a5f8ca JM |
2291 | if (changed) { |
2292 | u8 old_retry_short, old_retry_long; | |
2293 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2294 | u8 old_coverage_class; |
b9a5f8ca | 2295 | |
7f2b8562 YX |
2296 | if (!rdev->ops->set_wiphy_params) |
2297 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2298 | |
2299 | old_retry_short = rdev->wiphy.retry_short; | |
2300 | old_retry_long = rdev->wiphy.retry_long; | |
2301 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2302 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2303 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2304 | |
2305 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2306 | rdev->wiphy.retry_short = retry_short; | |
2307 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2308 | rdev->wiphy.retry_long = retry_long; | |
2309 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2310 | rdev->wiphy.frag_threshold = frag_threshold; | |
2311 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2312 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2313 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2314 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2315 | |
e35e4d28 | 2316 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2317 | if (result) { |
2318 | rdev->wiphy.retry_short = old_retry_short; | |
2319 | rdev->wiphy.retry_long = old_retry_long; | |
2320 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2321 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2322 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2323 | } |
2324 | } | |
7f2b8562 | 2325 | return 0; |
55682965 JB |
2326 | } |
2327 | ||
71bbc994 JB |
2328 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2329 | { | |
2330 | return (u64)wdev->identifier | | |
f26cbf40 | 2331 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2332 | } |
55682965 | 2333 | |
683b6d3b | 2334 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2335 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2336 | { |
601555cd JB |
2337 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
2338 | return -EINVAL; | |
3d9d1d66 | 2339 | |
683b6d3b JB |
2340 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2341 | chandef->chan->center_freq)) | |
2342 | return -ENOBUFS; | |
3d9d1d66 JB |
2343 | switch (chandef->width) { |
2344 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2345 | case NL80211_CHAN_WIDTH_20: | |
2346 | case NL80211_CHAN_WIDTH_40: | |
2347 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2348 | cfg80211_get_chandef_type(chandef))) | |
2349 | return -ENOBUFS; | |
2350 | break; | |
2351 | default: | |
2352 | break; | |
2353 | } | |
2354 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2355 | return -ENOBUFS; | |
2356 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2357 | return -ENOBUFS; | |
2358 | if (chandef->center_freq2 && | |
2359 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2360 | return -ENOBUFS; |
2361 | return 0; | |
2362 | } | |
2363 | ||
15e47304 | 2364 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2365 | struct cfg80211_registered_device *rdev, |
8f894be2 | 2366 | struct wireless_dev *wdev, bool removal) |
55682965 | 2367 | { |
72fb2abc | 2368 | struct net_device *dev = wdev->netdev; |
8f894be2 | 2369 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
55682965 JB |
2370 | void *hdr; |
2371 | ||
8f894be2 TB |
2372 | if (removal) |
2373 | cmd = NL80211_CMD_DEL_INTERFACE; | |
2374 | ||
2375 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | |
55682965 JB |
2376 | if (!hdr) |
2377 | return -1; | |
2378 | ||
72fb2abc JB |
2379 | if (dev && |
2380 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2381 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2382 | goto nla_put_failure; |
2383 | ||
2384 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2385 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2386 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2387 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2388 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2389 | rdev->devlist_generation ^ | |
2390 | (cfg80211_rdev_list_generation << 2))) | |
2391 | goto nla_put_failure; | |
f5ea9120 | 2392 | |
5b7ccaf3 | 2393 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2394 | int ret; |
2395 | struct cfg80211_chan_def chandef; | |
2396 | ||
2397 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2398 | if (ret == 0) { | |
2399 | if (nl80211_send_chandef(msg, &chandef)) | |
2400 | goto nla_put_failure; | |
2401 | } | |
d91df0e3 PF |
2402 | } |
2403 | ||
b84e7a05 AQ |
2404 | if (wdev->ssid_len) { |
2405 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2406 | goto nla_put_failure; | |
2407 | } | |
2408 | ||
55682965 JB |
2409 | return genlmsg_end(msg, hdr); |
2410 | ||
2411 | nla_put_failure: | |
bc3ed28c TG |
2412 | genlmsg_cancel(msg, hdr); |
2413 | return -EMSGSIZE; | |
55682965 JB |
2414 | } |
2415 | ||
2416 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2417 | { | |
2418 | int wp_idx = 0; | |
2419 | int if_idx = 0; | |
2420 | int wp_start = cb->args[0]; | |
2421 | int if_start = cb->args[1]; | |
f5ea9120 | 2422 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2423 | struct wireless_dev *wdev; |
2424 | ||
5fe231e8 | 2425 | rtnl_lock(); |
f5ea9120 JB |
2426 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2427 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2428 | continue; |
bba95fef JB |
2429 | if (wp_idx < wp_start) { |
2430 | wp_idx++; | |
55682965 | 2431 | continue; |
bba95fef | 2432 | } |
55682965 JB |
2433 | if_idx = 0; |
2434 | ||
89a54e48 | 2435 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2436 | if (if_idx < if_start) { |
2437 | if_idx++; | |
55682965 | 2438 | continue; |
bba95fef | 2439 | } |
15e47304 | 2440 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2441 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
8f894be2 | 2442 | rdev, wdev, false) < 0) { |
bba95fef JB |
2443 | goto out; |
2444 | } | |
2445 | if_idx++; | |
55682965 | 2446 | } |
bba95fef JB |
2447 | |
2448 | wp_idx++; | |
55682965 | 2449 | } |
bba95fef | 2450 | out: |
5fe231e8 | 2451 | rtnl_unlock(); |
55682965 JB |
2452 | |
2453 | cb->args[0] = wp_idx; | |
2454 | cb->args[1] = if_idx; | |
2455 | ||
2456 | return skb->len; | |
2457 | } | |
2458 | ||
2459 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2460 | { | |
2461 | struct sk_buff *msg; | |
1b8ec87a | 2462 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2463 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2464 | |
fd2120ca | 2465 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2466 | if (!msg) |
4c476991 | 2467 | return -ENOMEM; |
55682965 | 2468 | |
15e47304 | 2469 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2470 | rdev, wdev, false) < 0) { |
4c476991 JB |
2471 | nlmsg_free(msg); |
2472 | return -ENOBUFS; | |
2473 | } | |
55682965 | 2474 | |
134e6375 | 2475 | return genlmsg_reply(msg, info); |
55682965 JB |
2476 | } |
2477 | ||
66f7ac50 MW |
2478 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2479 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2480 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2481 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2482 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2483 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2484 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2485 | }; |
2486 | ||
2487 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2488 | { | |
2489 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2490 | int flag; | |
2491 | ||
2492 | *mntrflags = 0; | |
2493 | ||
2494 | if (!nla) | |
2495 | return -EINVAL; | |
2496 | ||
2497 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2498 | nla, mntr_flags_policy)) | |
2499 | return -EINVAL; | |
2500 | ||
2501 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2502 | if (flags[flag]) | |
2503 | *mntrflags |= (1<<flag); | |
2504 | ||
2505 | return 0; | |
2506 | } | |
2507 | ||
9bc383de | 2508 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2509 | struct net_device *netdev, u8 use_4addr, |
2510 | enum nl80211_iftype iftype) | |
9bc383de | 2511 | { |
ad4bb6f8 | 2512 | if (!use_4addr) { |
f350a0a8 | 2513 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2514 | return -EBUSY; |
9bc383de | 2515 | return 0; |
ad4bb6f8 | 2516 | } |
9bc383de JB |
2517 | |
2518 | switch (iftype) { | |
2519 | case NL80211_IFTYPE_AP_VLAN: | |
2520 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2521 | return 0; | |
2522 | break; | |
2523 | case NL80211_IFTYPE_STATION: | |
2524 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2525 | return 0; | |
2526 | break; | |
2527 | default: | |
2528 | break; | |
2529 | } | |
2530 | ||
2531 | return -EOPNOTSUPP; | |
2532 | } | |
2533 | ||
55682965 JB |
2534 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2535 | { | |
4c476991 | 2536 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2537 | struct vif_params params; |
e36d56b6 | 2538 | int err; |
04a773ad | 2539 | enum nl80211_iftype otype, ntype; |
4c476991 | 2540 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2541 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2542 | bool change = false; |
55682965 | 2543 | |
2ec600d6 LCC |
2544 | memset(¶ms, 0, sizeof(params)); |
2545 | ||
04a773ad | 2546 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2547 | |
723b038d | 2548 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2549 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2550 | if (otype != ntype) |
ac7f9cfa | 2551 | change = true; |
4c476991 JB |
2552 | if (ntype > NL80211_IFTYPE_MAX) |
2553 | return -EINVAL; | |
723b038d JB |
2554 | } |
2555 | ||
92ffe055 | 2556 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2557 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2558 | ||
4c476991 JB |
2559 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2560 | return -EINVAL; | |
29cbe68c JB |
2561 | if (netif_running(dev)) |
2562 | return -EBUSY; | |
2563 | ||
2564 | wdev_lock(wdev); | |
2565 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2566 | IEEE80211_MAX_MESH_ID_LEN); | |
2567 | wdev->mesh_id_up_len = | |
2568 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2569 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2570 | wdev->mesh_id_up_len); | |
2571 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2572 | } |
2573 | ||
8b787643 FF |
2574 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2575 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2576 | change = true; | |
ad4bb6f8 | 2577 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2578 | if (err) |
4c476991 | 2579 | return err; |
8b787643 FF |
2580 | } else { |
2581 | params.use_4addr = -1; | |
2582 | } | |
2583 | ||
92ffe055 | 2584 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2585 | if (ntype != NL80211_IFTYPE_MONITOR) |
2586 | return -EINVAL; | |
92ffe055 JB |
2587 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2588 | &_flags); | |
ac7f9cfa | 2589 | if (err) |
4c476991 | 2590 | return err; |
ac7f9cfa JB |
2591 | |
2592 | flags = &_flags; | |
2593 | change = true; | |
92ffe055 | 2594 | } |
3b85875a | 2595 | |
18003297 | 2596 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2597 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2598 | return -EOPNOTSUPP; | |
2599 | ||
ac7f9cfa | 2600 | if (change) |
3d54d255 | 2601 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2602 | else |
2603 | err = 0; | |
60719ffd | 2604 | |
9bc383de JB |
2605 | if (!err && params.use_4addr != -1) |
2606 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2607 | ||
55682965 JB |
2608 | return err; |
2609 | } | |
2610 | ||
2611 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2612 | { | |
4c476991 | 2613 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2614 | struct vif_params params; |
84efbb84 | 2615 | struct wireless_dev *wdev; |
8f894be2 | 2616 | struct sk_buff *msg, *event; |
55682965 JB |
2617 | int err; |
2618 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2619 | u32 flags; |
55682965 | 2620 | |
78f22b6a JB |
2621 | /* to avoid failing a new interface creation due to pending removal */ |
2622 | cfg80211_destroy_ifaces(rdev); | |
2623 | ||
2ec600d6 LCC |
2624 | memset(¶ms, 0, sizeof(params)); |
2625 | ||
55682965 JB |
2626 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2627 | return -EINVAL; | |
2628 | ||
2629 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2630 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2631 | if (type > NL80211_IFTYPE_MAX) | |
2632 | return -EINVAL; | |
2633 | } | |
2634 | ||
79c97e97 | 2635 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2636 | !(rdev->wiphy.interface_modes & (1 << type))) |
2637 | return -EOPNOTSUPP; | |
55682965 | 2638 | |
e8f479b1 BG |
2639 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
2640 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && | |
2641 | info->attrs[NL80211_ATTR_MAC]) { | |
1c18f145 AS |
2642 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
2643 | ETH_ALEN); | |
2644 | if (!is_valid_ether_addr(params.macaddr)) | |
2645 | return -EADDRNOTAVAIL; | |
2646 | } | |
2647 | ||
9bc383de | 2648 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2649 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2650 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2651 | if (err) |
4c476991 | 2652 | return err; |
9bc383de | 2653 | } |
8b787643 | 2654 | |
1c90f9d4 JB |
2655 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2656 | if (!msg) | |
2657 | return -ENOMEM; | |
2658 | ||
66f7ac50 MW |
2659 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2660 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2661 | &flags); | |
e057d3c3 | 2662 | |
18003297 | 2663 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2664 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2665 | return -EOPNOTSUPP; | |
2666 | ||
e35e4d28 HG |
2667 | wdev = rdev_add_virtual_intf(rdev, |
2668 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2669 | type, err ? NULL : &flags, ¶ms); | |
d687cbb7 RM |
2670 | if (WARN_ON(!wdev)) { |
2671 | nlmsg_free(msg); | |
2672 | return -EPROTO; | |
2673 | } else if (IS_ERR(wdev)) { | |
1c90f9d4 | 2674 | nlmsg_free(msg); |
84efbb84 | 2675 | return PTR_ERR(wdev); |
1c90f9d4 | 2676 | } |
2ec600d6 | 2677 | |
18e5ca65 | 2678 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
78f22b6a JB |
2679 | wdev->owner_nlportid = info->snd_portid; |
2680 | ||
98104fde JB |
2681 | switch (type) { |
2682 | case NL80211_IFTYPE_MESH_POINT: | |
2683 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2684 | break; | |
29cbe68c JB |
2685 | wdev_lock(wdev); |
2686 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2687 | IEEE80211_MAX_MESH_ID_LEN); | |
2688 | wdev->mesh_id_up_len = | |
2689 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2690 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2691 | wdev->mesh_id_up_len); | |
2692 | wdev_unlock(wdev); | |
98104fde JB |
2693 | break; |
2694 | case NL80211_IFTYPE_P2P_DEVICE: | |
2695 | /* | |
2696 | * P2P Device doesn't have a netdev, so doesn't go | |
2697 | * through the netdev notifier and must be added here | |
2698 | */ | |
2699 | mutex_init(&wdev->mtx); | |
2700 | INIT_LIST_HEAD(&wdev->event_list); | |
2701 | spin_lock_init(&wdev->event_lock); | |
2702 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2703 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2704 | ||
98104fde JB |
2705 | wdev->identifier = ++rdev->wdev_id; |
2706 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2707 | rdev->devlist_generation++; | |
98104fde JB |
2708 | break; |
2709 | default: | |
2710 | break; | |
29cbe68c JB |
2711 | } |
2712 | ||
15e47304 | 2713 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2714 | rdev, wdev, false) < 0) { |
1c90f9d4 JB |
2715 | nlmsg_free(msg); |
2716 | return -ENOBUFS; | |
2717 | } | |
2718 | ||
8f894be2 TB |
2719 | event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2720 | if (event) { | |
2721 | if (nl80211_send_iface(event, 0, 0, 0, | |
2722 | rdev, wdev, false) < 0) { | |
2723 | nlmsg_free(event); | |
2724 | goto out; | |
2725 | } | |
2726 | ||
2727 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
2728 | event, 0, NL80211_MCGRP_CONFIG, | |
2729 | GFP_KERNEL); | |
2730 | } | |
2731 | ||
2732 | out: | |
1c90f9d4 | 2733 | return genlmsg_reply(msg, info); |
55682965 JB |
2734 | } |
2735 | ||
2736 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2737 | { | |
4c476991 | 2738 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2739 | struct wireless_dev *wdev = info->user_ptr[1]; |
8f894be2 TB |
2740 | struct sk_buff *msg; |
2741 | int status; | |
55682965 | 2742 | |
4c476991 JB |
2743 | if (!rdev->ops->del_virtual_intf) |
2744 | return -EOPNOTSUPP; | |
55682965 | 2745 | |
8f894be2 TB |
2746 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2747 | if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) { | |
2748 | nlmsg_free(msg); | |
2749 | msg = NULL; | |
2750 | } | |
2751 | ||
84efbb84 JB |
2752 | /* |
2753 | * If we remove a wireless device without a netdev then clear | |
2754 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2755 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2756 | * since the wdev has been freed, unlike with a netdev where | |
2757 | * we need the dev_put() for the netdev to really be freed. | |
2758 | */ | |
2759 | if (!wdev->netdev) | |
2760 | info->user_ptr[1] = NULL; | |
2761 | ||
8f894be2 TB |
2762 | status = rdev_del_virtual_intf(rdev, wdev); |
2763 | if (status >= 0 && msg) | |
2764 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
2765 | msg, 0, NL80211_MCGRP_CONFIG, | |
2766 | GFP_KERNEL); | |
2767 | else | |
2768 | nlmsg_free(msg); | |
2769 | ||
2770 | return status; | |
55682965 JB |
2771 | } |
2772 | ||
1d9d9213 SW |
2773 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2774 | { | |
2775 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2776 | struct net_device *dev = info->user_ptr[1]; | |
2777 | u16 noack_map; | |
2778 | ||
2779 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2780 | return -EINVAL; | |
2781 | ||
2782 | if (!rdev->ops->set_noack_map) | |
2783 | return -EOPNOTSUPP; | |
2784 | ||
2785 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2786 | ||
e35e4d28 | 2787 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2788 | } |
2789 | ||
41ade00f JB |
2790 | struct get_key_cookie { |
2791 | struct sk_buff *msg; | |
2792 | int error; | |
b9454e83 | 2793 | int idx; |
41ade00f JB |
2794 | }; |
2795 | ||
2796 | static void get_key_callback(void *c, struct key_params *params) | |
2797 | { | |
b9454e83 | 2798 | struct nlattr *key; |
41ade00f JB |
2799 | struct get_key_cookie *cookie = c; |
2800 | ||
9360ffd1 DM |
2801 | if ((params->key && |
2802 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2803 | params->key_len, params->key)) || | |
2804 | (params->seq && | |
2805 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2806 | params->seq_len, params->seq)) || | |
2807 | (params->cipher && | |
2808 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2809 | params->cipher))) | |
2810 | goto nla_put_failure; | |
41ade00f | 2811 | |
b9454e83 JB |
2812 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2813 | if (!key) | |
2814 | goto nla_put_failure; | |
2815 | ||
9360ffd1 DM |
2816 | if ((params->key && |
2817 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2818 | params->key_len, params->key)) || | |
2819 | (params->seq && | |
2820 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2821 | params->seq_len, params->seq)) || | |
2822 | (params->cipher && | |
2823 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2824 | params->cipher))) | |
2825 | goto nla_put_failure; | |
b9454e83 | 2826 | |
9360ffd1 DM |
2827 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2828 | goto nla_put_failure; | |
b9454e83 JB |
2829 | |
2830 | nla_nest_end(cookie->msg, key); | |
2831 | ||
41ade00f JB |
2832 | return; |
2833 | nla_put_failure: | |
2834 | cookie->error = 1; | |
2835 | } | |
2836 | ||
2837 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2838 | { | |
4c476991 | 2839 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2840 | int err; |
4c476991 | 2841 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2842 | u8 key_idx = 0; |
e31b8213 JB |
2843 | const u8 *mac_addr = NULL; |
2844 | bool pairwise; | |
41ade00f JB |
2845 | struct get_key_cookie cookie = { |
2846 | .error = 0, | |
2847 | }; | |
2848 | void *hdr; | |
2849 | struct sk_buff *msg; | |
2850 | ||
2851 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2852 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2853 | ||
3cfcf6ac | 2854 | if (key_idx > 5) |
41ade00f JB |
2855 | return -EINVAL; |
2856 | ||
2857 | if (info->attrs[NL80211_ATTR_MAC]) | |
2858 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2859 | ||
e31b8213 JB |
2860 | pairwise = !!mac_addr; |
2861 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2862 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2863 | if (kt >= NUM_NL80211_KEYTYPES) | |
2864 | return -EINVAL; | |
2865 | if (kt != NL80211_KEYTYPE_GROUP && | |
2866 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2867 | return -EINVAL; | |
2868 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2869 | } | |
2870 | ||
4c476991 JB |
2871 | if (!rdev->ops->get_key) |
2872 | return -EOPNOTSUPP; | |
41ade00f | 2873 | |
fd2120ca | 2874 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2875 | if (!msg) |
2876 | return -ENOMEM; | |
41ade00f | 2877 | |
15e47304 | 2878 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2879 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 2880 | if (!hdr) |
9fe271af | 2881 | goto nla_put_failure; |
41ade00f JB |
2882 | |
2883 | cookie.msg = msg; | |
b9454e83 | 2884 | cookie.idx = key_idx; |
41ade00f | 2885 | |
9360ffd1 DM |
2886 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2887 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2888 | goto nla_put_failure; | |
2889 | if (mac_addr && | |
2890 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2891 | goto nla_put_failure; | |
41ade00f | 2892 | |
e31b8213 JB |
2893 | if (pairwise && mac_addr && |
2894 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2895 | return -ENOENT; | |
2896 | ||
e35e4d28 HG |
2897 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2898 | get_key_callback); | |
41ade00f JB |
2899 | |
2900 | if (err) | |
6c95e2a2 | 2901 | goto free_msg; |
41ade00f JB |
2902 | |
2903 | if (cookie.error) | |
2904 | goto nla_put_failure; | |
2905 | ||
2906 | genlmsg_end(msg, hdr); | |
4c476991 | 2907 | return genlmsg_reply(msg, info); |
41ade00f JB |
2908 | |
2909 | nla_put_failure: | |
2910 | err = -ENOBUFS; | |
6c95e2a2 | 2911 | free_msg: |
41ade00f | 2912 | nlmsg_free(msg); |
41ade00f JB |
2913 | return err; |
2914 | } | |
2915 | ||
2916 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2917 | { | |
4c476991 | 2918 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2919 | struct key_parse key; |
41ade00f | 2920 | int err; |
4c476991 | 2921 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2922 | |
b9454e83 JB |
2923 | err = nl80211_parse_key(info, &key); |
2924 | if (err) | |
2925 | return err; | |
41ade00f | 2926 | |
b9454e83 | 2927 | if (key.idx < 0) |
41ade00f JB |
2928 | return -EINVAL; |
2929 | ||
b9454e83 JB |
2930 | /* only support setting default key */ |
2931 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2932 | return -EINVAL; |
2933 | ||
dbd2fd65 | 2934 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2935 | |
dbd2fd65 JB |
2936 | if (key.def) { |
2937 | if (!rdev->ops->set_default_key) { | |
2938 | err = -EOPNOTSUPP; | |
2939 | goto out; | |
2940 | } | |
41ade00f | 2941 | |
dbd2fd65 JB |
2942 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2943 | if (err) | |
2944 | goto out; | |
2945 | ||
e35e4d28 | 2946 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2947 | key.def_uni, key.def_multi); |
2948 | ||
2949 | if (err) | |
2950 | goto out; | |
fffd0934 | 2951 | |
3d23e349 | 2952 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2953 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2954 | #endif | |
2955 | } else { | |
2956 | if (key.def_uni || !key.def_multi) { | |
2957 | err = -EINVAL; | |
2958 | goto out; | |
2959 | } | |
2960 | ||
2961 | if (!rdev->ops->set_default_mgmt_key) { | |
2962 | err = -EOPNOTSUPP; | |
2963 | goto out; | |
2964 | } | |
2965 | ||
2966 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2967 | if (err) | |
2968 | goto out; | |
2969 | ||
e35e4d28 | 2970 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2971 | if (err) |
2972 | goto out; | |
2973 | ||
2974 | #ifdef CONFIG_CFG80211_WEXT | |
2975 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2976 | #endif |
dbd2fd65 JB |
2977 | } |
2978 | ||
2979 | out: | |
fffd0934 | 2980 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2981 | |
41ade00f JB |
2982 | return err; |
2983 | } | |
2984 | ||
2985 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2986 | { | |
4c476991 | 2987 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2988 | int err; |
4c476991 | 2989 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2990 | struct key_parse key; |
e31b8213 | 2991 | const u8 *mac_addr = NULL; |
41ade00f | 2992 | |
b9454e83 JB |
2993 | err = nl80211_parse_key(info, &key); |
2994 | if (err) | |
2995 | return err; | |
41ade00f | 2996 | |
b9454e83 | 2997 | if (!key.p.key) |
41ade00f JB |
2998 | return -EINVAL; |
2999 | ||
41ade00f JB |
3000 | if (info->attrs[NL80211_ATTR_MAC]) |
3001 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3002 | ||
e31b8213 JB |
3003 | if (key.type == -1) { |
3004 | if (mac_addr) | |
3005 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3006 | else | |
3007 | key.type = NL80211_KEYTYPE_GROUP; | |
3008 | } | |
3009 | ||
3010 | /* for now */ | |
3011 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3012 | key.type != NL80211_KEYTYPE_GROUP) | |
3013 | return -EINVAL; | |
3014 | ||
4c476991 JB |
3015 | if (!rdev->ops->add_key) |
3016 | return -EOPNOTSUPP; | |
25e47c18 | 3017 | |
e31b8213 JB |
3018 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
3019 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3020 | mac_addr)) | |
4c476991 | 3021 | return -EINVAL; |
41ade00f | 3022 | |
fffd0934 JB |
3023 | wdev_lock(dev->ieee80211_ptr); |
3024 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3025 | if (!err) | |
e35e4d28 HG |
3026 | err = rdev_add_key(rdev, dev, key.idx, |
3027 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3028 | mac_addr, &key.p); | |
fffd0934 | 3029 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3030 | |
41ade00f JB |
3031 | return err; |
3032 | } | |
3033 | ||
3034 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
3035 | { | |
4c476991 | 3036 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3037 | int err; |
4c476991 | 3038 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3039 | u8 *mac_addr = NULL; |
b9454e83 | 3040 | struct key_parse key; |
41ade00f | 3041 | |
b9454e83 JB |
3042 | err = nl80211_parse_key(info, &key); |
3043 | if (err) | |
3044 | return err; | |
41ade00f JB |
3045 | |
3046 | if (info->attrs[NL80211_ATTR_MAC]) | |
3047 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3048 | ||
e31b8213 JB |
3049 | if (key.type == -1) { |
3050 | if (mac_addr) | |
3051 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3052 | else | |
3053 | key.type = NL80211_KEYTYPE_GROUP; | |
3054 | } | |
3055 | ||
3056 | /* for now */ | |
3057 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3058 | key.type != NL80211_KEYTYPE_GROUP) | |
3059 | return -EINVAL; | |
3060 | ||
4c476991 JB |
3061 | if (!rdev->ops->del_key) |
3062 | return -EOPNOTSUPP; | |
41ade00f | 3063 | |
fffd0934 JB |
3064 | wdev_lock(dev->ieee80211_ptr); |
3065 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
3066 | |
3067 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
3068 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
3069 | err = -ENOENT; | |
3070 | ||
fffd0934 | 3071 | if (!err) |
e35e4d28 HG |
3072 | err = rdev_del_key(rdev, dev, key.idx, |
3073 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3074 | mac_addr); | |
41ade00f | 3075 | |
3d23e349 | 3076 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 3077 | if (!err) { |
b9454e83 | 3078 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 3079 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 3080 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
3081 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
3082 | } | |
3083 | #endif | |
fffd0934 | 3084 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 3085 | |
41ade00f JB |
3086 | return err; |
3087 | } | |
3088 | ||
77765eaf VT |
3089 | /* This function returns an error or the number of nested attributes */ |
3090 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
3091 | { | |
3092 | struct nlattr *attr; | |
3093 | int n_entries = 0, tmp; | |
3094 | ||
3095 | nla_for_each_nested(attr, nl_attr, tmp) { | |
3096 | if (nla_len(attr) != ETH_ALEN) | |
3097 | return -EINVAL; | |
3098 | ||
3099 | n_entries++; | |
3100 | } | |
3101 | ||
3102 | return n_entries; | |
3103 | } | |
3104 | ||
3105 | /* | |
3106 | * This function parses ACL information and allocates memory for ACL data. | |
3107 | * On successful return, the calling function is responsible to free the | |
3108 | * ACL buffer returned by this function. | |
3109 | */ | |
3110 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3111 | struct genl_info *info) | |
3112 | { | |
3113 | enum nl80211_acl_policy acl_policy; | |
3114 | struct nlattr *attr; | |
3115 | struct cfg80211_acl_data *acl; | |
3116 | int i = 0, n_entries, tmp; | |
3117 | ||
3118 | if (!wiphy->max_acl_mac_addrs) | |
3119 | return ERR_PTR(-EOPNOTSUPP); | |
3120 | ||
3121 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3122 | return ERR_PTR(-EINVAL); | |
3123 | ||
3124 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3125 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3126 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3127 | return ERR_PTR(-EINVAL); | |
3128 | ||
3129 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3130 | return ERR_PTR(-EINVAL); | |
3131 | ||
3132 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3133 | if (n_entries < 0) | |
3134 | return ERR_PTR(n_entries); | |
3135 | ||
3136 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3137 | return ERR_PTR(-ENOTSUPP); | |
3138 | ||
3139 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
3140 | GFP_KERNEL); | |
3141 | if (!acl) | |
3142 | return ERR_PTR(-ENOMEM); | |
3143 | ||
3144 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3145 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3146 | i++; | |
3147 | } | |
3148 | ||
3149 | acl->n_acl_entries = n_entries; | |
3150 | acl->acl_policy = acl_policy; | |
3151 | ||
3152 | return acl; | |
3153 | } | |
3154 | ||
3155 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3156 | { | |
3157 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3158 | struct net_device *dev = info->user_ptr[1]; | |
3159 | struct cfg80211_acl_data *acl; | |
3160 | int err; | |
3161 | ||
3162 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3163 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3164 | return -EOPNOTSUPP; | |
3165 | ||
3166 | if (!dev->ieee80211_ptr->beacon_interval) | |
3167 | return -EINVAL; | |
3168 | ||
3169 | acl = parse_acl_data(&rdev->wiphy, info); | |
3170 | if (IS_ERR(acl)) | |
3171 | return PTR_ERR(acl); | |
3172 | ||
3173 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3174 | ||
3175 | kfree(acl); | |
3176 | ||
3177 | return err; | |
3178 | } | |
3179 | ||
a1193be8 | 3180 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3181 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3182 | { |
8860020e | 3183 | bool haveinfo = false; |
ed1b6cc7 | 3184 | |
a1193be8 SW |
3185 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3186 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3187 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3188 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3189 | return -EINVAL; |
3190 | ||
8860020e | 3191 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3192 | |
a1193be8 SW |
3193 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3194 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3195 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3196 | if (!bcn->head_len) |
3197 | return -EINVAL; | |
3198 | haveinfo = true; | |
ed1b6cc7 JB |
3199 | } |
3200 | ||
a1193be8 SW |
3201 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3202 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3203 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3204 | haveinfo = true; |
ed1b6cc7 JB |
3205 | } |
3206 | ||
4c476991 JB |
3207 | if (!haveinfo) |
3208 | return -EINVAL; | |
3b85875a | 3209 | |
a1193be8 SW |
3210 | if (attrs[NL80211_ATTR_IE]) { |
3211 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3212 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3213 | } |
3214 | ||
a1193be8 | 3215 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3216 | bcn->proberesp_ies = |
a1193be8 | 3217 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3218 | bcn->proberesp_ies_len = |
a1193be8 | 3219 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3220 | } |
3221 | ||
a1193be8 | 3222 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3223 | bcn->assocresp_ies = |
a1193be8 | 3224 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3225 | bcn->assocresp_ies_len = |
a1193be8 | 3226 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3227 | } |
3228 | ||
a1193be8 SW |
3229 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3230 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3231 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3232 | } |
3233 | ||
8860020e JB |
3234 | return 0; |
3235 | } | |
3236 | ||
46c1dd0c FF |
3237 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3238 | struct cfg80211_ap_settings *params) | |
3239 | { | |
3240 | struct wireless_dev *wdev; | |
3241 | bool ret = false; | |
3242 | ||
89a54e48 | 3243 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3244 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3245 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3246 | continue; | |
3247 | ||
683b6d3b | 3248 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3249 | continue; |
3250 | ||
683b6d3b | 3251 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3252 | ret = true; |
3253 | break; | |
3254 | } | |
3255 | ||
46c1dd0c FF |
3256 | return ret; |
3257 | } | |
3258 | ||
e39e5b5e JM |
3259 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3260 | enum nl80211_auth_type auth_type, | |
3261 | enum nl80211_commands cmd) | |
3262 | { | |
3263 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3264 | return false; | |
3265 | ||
3266 | switch (cmd) { | |
3267 | case NL80211_CMD_AUTHENTICATE: | |
3268 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3269 | auth_type == NL80211_AUTHTYPE_SAE) | |
3270 | return false; | |
3271 | return true; | |
3272 | case NL80211_CMD_CONNECT: | |
3273 | case NL80211_CMD_START_AP: | |
3274 | /* SAE not supported yet */ | |
3275 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3276 | return false; | |
3277 | return true; | |
3278 | default: | |
3279 | return false; | |
3280 | } | |
3281 | } | |
3282 | ||
8860020e JB |
3283 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3284 | { | |
3285 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3286 | struct net_device *dev = info->user_ptr[1]; | |
3287 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3288 | struct cfg80211_ap_settings params; | |
3289 | int err; | |
3290 | ||
3291 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3292 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3293 | return -EOPNOTSUPP; | |
3294 | ||
3295 | if (!rdev->ops->start_ap) | |
3296 | return -EOPNOTSUPP; | |
3297 | ||
3298 | if (wdev->beacon_interval) | |
3299 | return -EALREADY; | |
3300 | ||
3301 | memset(¶ms, 0, sizeof(params)); | |
3302 | ||
3303 | /* these are required for START_AP */ | |
3304 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3305 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3306 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3307 | return -EINVAL; | |
3308 | ||
a1193be8 | 3309 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3310 | if (err) |
3311 | return err; | |
3312 | ||
3313 | params.beacon_interval = | |
3314 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3315 | params.dtim_period = | |
3316 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3317 | ||
3318 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3319 | if (err) | |
3320 | return err; | |
3321 | ||
3322 | /* | |
3323 | * In theory, some of these attributes should be required here | |
3324 | * but since they were not used when the command was originally | |
3325 | * added, keep them optional for old user space programs to let | |
3326 | * them continue to work with drivers that do not need the | |
3327 | * additional information -- drivers must check! | |
3328 | */ | |
3329 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3330 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3331 | params.ssid_len = | |
3332 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3333 | if (params.ssid_len == 0 || | |
3334 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3335 | return -EINVAL; | |
3336 | } | |
3337 | ||
3338 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3339 | params.hidden_ssid = nla_get_u32( | |
3340 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3341 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3342 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3343 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3344 | return -EINVAL; | |
3345 | } | |
3346 | ||
3347 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3348 | ||
3349 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3350 | params.auth_type = nla_get_u32( | |
3351 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3352 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3353 | NL80211_CMD_START_AP)) | |
8860020e JB |
3354 | return -EINVAL; |
3355 | } else | |
3356 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3357 | ||
3358 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3359 | NL80211_MAX_NR_CIPHER_SUITES); | |
3360 | if (err) | |
3361 | return err; | |
3362 | ||
1b658f11 VT |
3363 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3364 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3365 | return -EOPNOTSUPP; | |
3366 | params.inactivity_timeout = nla_get_u16( | |
3367 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3368 | } | |
3369 | ||
53cabad7 JB |
3370 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3371 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3372 | return -EINVAL; | |
3373 | params.p2p_ctwindow = | |
3374 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3375 | if (params.p2p_ctwindow > 127) | |
3376 | return -EINVAL; | |
3377 | if (params.p2p_ctwindow != 0 && | |
3378 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3379 | return -EINVAL; | |
3380 | } | |
3381 | ||
3382 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3383 | u8 tmp; | |
3384 | ||
3385 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3386 | return -EINVAL; | |
3387 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3388 | if (tmp > 1) | |
3389 | return -EINVAL; | |
3390 | params.p2p_opp_ps = tmp; | |
3391 | if (params.p2p_opp_ps != 0 && | |
3392 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3393 | return -EINVAL; | |
3394 | } | |
3395 | ||
aa430da4 | 3396 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3397 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3398 | if (err) | |
3399 | return err; | |
3400 | } else if (wdev->preset_chandef.chan) { | |
3401 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3402 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3403 | return -EINVAL; |
3404 | ||
174e0cd2 IP |
3405 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
3406 | wdev->iftype)) | |
aa430da4 JB |
3407 | return -EINVAL; |
3408 | ||
77765eaf VT |
3409 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3410 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3411 | if (IS_ERR(params.acl)) | |
3412 | return PTR_ERR(params.acl); | |
3413 | } | |
3414 | ||
18998c38 EP |
3415 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
3416 | params.smps_mode = | |
3417 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); | |
3418 | switch (params.smps_mode) { | |
3419 | case NL80211_SMPS_OFF: | |
3420 | break; | |
3421 | case NL80211_SMPS_STATIC: | |
3422 | if (!(rdev->wiphy.features & | |
3423 | NL80211_FEATURE_STATIC_SMPS)) | |
3424 | return -EINVAL; | |
3425 | break; | |
3426 | case NL80211_SMPS_DYNAMIC: | |
3427 | if (!(rdev->wiphy.features & | |
3428 | NL80211_FEATURE_DYNAMIC_SMPS)) | |
3429 | return -EINVAL; | |
3430 | break; | |
3431 | default: | |
3432 | return -EINVAL; | |
3433 | } | |
3434 | } else { | |
3435 | params.smps_mode = NL80211_SMPS_OFF; | |
3436 | } | |
3437 | ||
c56589ed | 3438 | wdev_lock(wdev); |
e35e4d28 | 3439 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3440 | if (!err) { |
683b6d3b | 3441 | wdev->preset_chandef = params.chandef; |
8860020e | 3442 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 3443 | wdev->chandef = params.chandef; |
06e191e2 AQ |
3444 | wdev->ssid_len = params.ssid_len; |
3445 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3446 | } |
c56589ed | 3447 | wdev_unlock(wdev); |
77765eaf VT |
3448 | |
3449 | kfree(params.acl); | |
3450 | ||
56d1893d | 3451 | return err; |
ed1b6cc7 JB |
3452 | } |
3453 | ||
8860020e JB |
3454 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3455 | { | |
3456 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3457 | struct net_device *dev = info->user_ptr[1]; | |
3458 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3459 | struct cfg80211_beacon_data params; | |
3460 | int err; | |
3461 | ||
3462 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3463 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3464 | return -EOPNOTSUPP; | |
3465 | ||
3466 | if (!rdev->ops->change_beacon) | |
3467 | return -EOPNOTSUPP; | |
3468 | ||
3469 | if (!wdev->beacon_interval) | |
3470 | return -EINVAL; | |
3471 | ||
a1193be8 | 3472 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3473 | if (err) |
3474 | return err; | |
3475 | ||
c56589ed SW |
3476 | wdev_lock(wdev); |
3477 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3478 | wdev_unlock(wdev); | |
3479 | ||
3480 | return err; | |
8860020e JB |
3481 | } |
3482 | ||
3483 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3484 | { |
4c476991 JB |
3485 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3486 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3487 | |
7c8d5e03 | 3488 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
3489 | } |
3490 | ||
5727ef1b JB |
3491 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3492 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3493 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3494 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3495 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3496 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3497 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3498 | }; |
3499 | ||
eccb8e8f | 3500 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3501 | enum nl80211_iftype iftype, |
eccb8e8f | 3502 | struct station_parameters *params) |
5727ef1b JB |
3503 | { |
3504 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3505 | struct nlattr *nla; |
5727ef1b JB |
3506 | int flag; |
3507 | ||
eccb8e8f JB |
3508 | /* |
3509 | * Try parsing the new attribute first so userspace | |
3510 | * can specify both for older kernels. | |
3511 | */ | |
3512 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3513 | if (nla) { | |
3514 | struct nl80211_sta_flag_update *sta_flags; | |
3515 | ||
3516 | sta_flags = nla_data(nla); | |
3517 | params->sta_flags_mask = sta_flags->mask; | |
3518 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3519 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3520 | if ((params->sta_flags_mask | |
3521 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3522 | return -EINVAL; | |
3523 | return 0; | |
3524 | } | |
3525 | ||
3526 | /* if present, parse the old attribute */ | |
5727ef1b | 3527 | |
eccb8e8f | 3528 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3529 | if (!nla) |
3530 | return 0; | |
3531 | ||
3532 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3533 | nla, sta_flags_policy)) | |
3534 | return -EINVAL; | |
3535 | ||
bdd3ae3d JB |
3536 | /* |
3537 | * Only allow certain flags for interface types so that | |
3538 | * other attributes are silently ignored. Remember that | |
3539 | * this is backward compatibility code with old userspace | |
3540 | * and shouldn't be hit in other cases anyway. | |
3541 | */ | |
3542 | switch (iftype) { | |
3543 | case NL80211_IFTYPE_AP: | |
3544 | case NL80211_IFTYPE_AP_VLAN: | |
3545 | case NL80211_IFTYPE_P2P_GO: | |
3546 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3547 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3548 | BIT(NL80211_STA_FLAG_WME) | | |
3549 | BIT(NL80211_STA_FLAG_MFP); | |
3550 | break; | |
3551 | case NL80211_IFTYPE_P2P_CLIENT: | |
3552 | case NL80211_IFTYPE_STATION: | |
3553 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3554 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3555 | break; | |
3556 | case NL80211_IFTYPE_MESH_POINT: | |
3557 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3558 | BIT(NL80211_STA_FLAG_MFP) | | |
3559 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3560 | default: | |
3561 | return -EINVAL; | |
3562 | } | |
5727ef1b | 3563 | |
3383b5a6 JB |
3564 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3565 | if (flags[flag]) { | |
eccb8e8f | 3566 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3567 | |
3383b5a6 JB |
3568 | /* no longer support new API additions in old API */ |
3569 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3570 | return -EINVAL; | |
3571 | } | |
3572 | } | |
3573 | ||
5727ef1b JB |
3574 | return 0; |
3575 | } | |
3576 | ||
c8dcfd8a FF |
3577 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3578 | int attr) | |
3579 | { | |
3580 | struct nlattr *rate; | |
8eb41c8d VK |
3581 | u32 bitrate; |
3582 | u16 bitrate_compat; | |
b51f3bee | 3583 | enum nl80211_attrs rate_flg; |
c8dcfd8a FF |
3584 | |
3585 | rate = nla_nest_start(msg, attr); | |
3586 | if (!rate) | |
db9c64cf | 3587 | return false; |
c8dcfd8a FF |
3588 | |
3589 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3590 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3591 | /* report 16-bit bitrate only if we can */ |
3592 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3593 | if (bitrate > 0 && |
3594 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3595 | return false; | |
3596 | if (bitrate_compat > 0 && | |
3597 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3598 | return false; | |
3599 | ||
b51f3bee JB |
3600 | switch (info->bw) { |
3601 | case RATE_INFO_BW_5: | |
3602 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; | |
3603 | break; | |
3604 | case RATE_INFO_BW_10: | |
3605 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; | |
3606 | break; | |
3607 | default: | |
3608 | WARN_ON(1); | |
3609 | /* fall through */ | |
3610 | case RATE_INFO_BW_20: | |
3611 | rate_flg = 0; | |
3612 | break; | |
3613 | case RATE_INFO_BW_40: | |
3614 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; | |
3615 | break; | |
3616 | case RATE_INFO_BW_80: | |
3617 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; | |
3618 | break; | |
3619 | case RATE_INFO_BW_160: | |
3620 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; | |
3621 | break; | |
3622 | } | |
3623 | ||
3624 | if (rate_flg && nla_put_flag(msg, rate_flg)) | |
3625 | return false; | |
3626 | ||
db9c64cf JB |
3627 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
3628 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3629 | return false; | |
db9c64cf JB |
3630 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
3631 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3632 | return false; | |
3633 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3634 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3635 | return false; | |
3636 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3637 | return false; | |
db9c64cf JB |
3638 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
3639 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3640 | return false; | |
3641 | } | |
c8dcfd8a FF |
3642 | |
3643 | nla_nest_end(msg, rate); | |
3644 | return true; | |
c8dcfd8a FF |
3645 | } |
3646 | ||
119363c7 FF |
3647 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3648 | int id) | |
3649 | { | |
3650 | void *attr; | |
3651 | int i = 0; | |
3652 | ||
3653 | if (!mask) | |
3654 | return true; | |
3655 | ||
3656 | attr = nla_nest_start(msg, id); | |
3657 | if (!attr) | |
3658 | return false; | |
3659 | ||
3660 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3661 | if (!(mask & BIT(i))) | |
3662 | continue; | |
3663 | ||
3664 | if (nla_put_u8(msg, i, signal[i])) | |
3665 | return false; | |
3666 | } | |
3667 | ||
3668 | nla_nest_end(msg, attr); | |
3669 | ||
3670 | return true; | |
3671 | } | |
3672 | ||
cf5ead82 JB |
3673 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
3674 | u32 seq, int flags, | |
66266b3a JL |
3675 | struct cfg80211_registered_device *rdev, |
3676 | struct net_device *dev, | |
98b62183 | 3677 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3678 | { |
3679 | void *hdr; | |
f4263c98 | 3680 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3681 | |
cf5ead82 | 3682 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
fd5b74dc JB |
3683 | if (!hdr) |
3684 | return -1; | |
3685 | ||
9360ffd1 DM |
3686 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3687 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3688 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3689 | goto nla_put_failure; | |
f5ea9120 | 3690 | |
2ec600d6 LCC |
3691 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3692 | if (!sinfoattr) | |
fd5b74dc | 3693 | goto nla_put_failure; |
319090bf JB |
3694 | |
3695 | #define PUT_SINFO(attr, memb, type) do { \ | |
3696 | if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \ | |
3697 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ | |
3698 | sinfo->memb)) \ | |
3699 | goto nla_put_failure; \ | |
3700 | } while (0) | |
3701 | ||
3702 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); | |
3703 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); | |
3704 | ||
3705 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | | |
3706 | BIT(NL80211_STA_INFO_RX_BYTES64)) && | |
9360ffd1 | 3707 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3708 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3709 | goto nla_put_failure; |
319090bf JB |
3710 | |
3711 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | | |
3712 | BIT(NL80211_STA_INFO_TX_BYTES64)) && | |
9360ffd1 | 3713 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3714 | (u32)sinfo->tx_bytes)) |
3715 | goto nla_put_failure; | |
319090bf JB |
3716 | |
3717 | PUT_SINFO(RX_BYTES64, rx_bytes, u64); | |
3718 | PUT_SINFO(TX_BYTES64, tx_bytes, u64); | |
3719 | PUT_SINFO(LLID, llid, u16); | |
3720 | PUT_SINFO(PLID, plid, u16); | |
3721 | PUT_SINFO(PLINK_STATE, plink_state, u8); | |
3722 | ||
66266b3a JL |
3723 | switch (rdev->wiphy.signal_type) { |
3724 | case CFG80211_SIGNAL_TYPE_MBM: | |
319090bf JB |
3725 | PUT_SINFO(SIGNAL, signal, u8); |
3726 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); | |
66266b3a JL |
3727 | break; |
3728 | default: | |
3729 | break; | |
3730 | } | |
319090bf | 3731 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
119363c7 FF |
3732 | if (!nl80211_put_signal(msg, sinfo->chains, |
3733 | sinfo->chain_signal, | |
3734 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3735 | goto nla_put_failure; | |
3736 | } | |
319090bf | 3737 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
119363c7 FF |
3738 | if (!nl80211_put_signal(msg, sinfo->chains, |
3739 | sinfo->chain_signal_avg, | |
3740 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3741 | goto nla_put_failure; | |
3742 | } | |
319090bf | 3743 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
c8dcfd8a FF |
3744 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3745 | NL80211_STA_INFO_TX_BITRATE)) | |
3746 | goto nla_put_failure; | |
3747 | } | |
319090bf | 3748 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
c8dcfd8a FF |
3749 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
3750 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3751 | goto nla_put_failure; |
420e7fab | 3752 | } |
319090bf JB |
3753 | |
3754 | PUT_SINFO(RX_PACKETS, rx_packets, u32); | |
3755 | PUT_SINFO(TX_PACKETS, tx_packets, u32); | |
3756 | PUT_SINFO(TX_RETRIES, tx_retries, u32); | |
3757 | PUT_SINFO(TX_FAILED, tx_failed, u32); | |
3758 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); | |
3759 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); | |
3760 | PUT_SINFO(LOCAL_PM, local_pm, u32); | |
3761 | PUT_SINFO(PEER_PM, peer_pm, u32); | |
3762 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); | |
3763 | ||
3764 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { | |
f4263c98 PS |
3765 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
3766 | if (!bss_param) | |
3767 | goto nla_put_failure; | |
3768 | ||
9360ffd1 DM |
3769 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3770 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3771 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3772 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3773 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3774 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3775 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3776 | sinfo->bss_param.dtim_period) || | |
3777 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3778 | sinfo->bss_param.beacon_interval)) | |
3779 | goto nla_put_failure; | |
f4263c98 PS |
3780 | |
3781 | nla_nest_end(msg, bss_param); | |
3782 | } | |
319090bf | 3783 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
9360ffd1 DM |
3784 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
3785 | sizeof(struct nl80211_sta_flag_update), | |
3786 | &sinfo->sta_flags)) | |
3787 | goto nla_put_failure; | |
319090bf JB |
3788 | |
3789 | PUT_SINFO(T_OFFSET, t_offset, u64); | |
3790 | PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64); | |
a76b1942 JB |
3791 | PUT_SINFO(BEACON_RX, rx_beacon, u64); |
3792 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); | |
319090bf JB |
3793 | |
3794 | #undef PUT_SINFO | |
6de39808 JB |
3795 | |
3796 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { | |
3797 | struct nlattr *tidsattr; | |
3798 | int tid; | |
3799 | ||
3800 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); | |
3801 | if (!tidsattr) | |
3802 | goto nla_put_failure; | |
3803 | ||
3804 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { | |
3805 | struct cfg80211_tid_stats *tidstats; | |
3806 | struct nlattr *tidattr; | |
3807 | ||
3808 | tidstats = &sinfo->pertid[tid]; | |
3809 | ||
3810 | if (!tidstats->filled) | |
3811 | continue; | |
3812 | ||
3813 | tidattr = nla_nest_start(msg, tid + 1); | |
3814 | if (!tidattr) | |
3815 | goto nla_put_failure; | |
3816 | ||
3817 | #define PUT_TIDVAL(attr, memb, type) do { \ | |
3818 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ | |
3819 | nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \ | |
3820 | tidstats->memb)) \ | |
3821 | goto nla_put_failure; \ | |
3822 | } while (0) | |
3823 | ||
3824 | PUT_TIDVAL(RX_MSDU, rx_msdu, u64); | |
3825 | PUT_TIDVAL(TX_MSDU, tx_msdu, u64); | |
3826 | PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64); | |
3827 | PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64); | |
3828 | ||
3829 | #undef PUT_TIDVAL | |
3830 | nla_nest_end(msg, tidattr); | |
3831 | } | |
3832 | ||
3833 | nla_nest_end(msg, tidsattr); | |
3834 | } | |
3835 | ||
2ec600d6 | 3836 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3837 | |
319090bf | 3838 | if (sinfo->assoc_req_ies_len && |
9360ffd1 DM |
3839 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
3840 | sinfo->assoc_req_ies)) | |
3841 | goto nla_put_failure; | |
50d3dfb7 | 3842 | |
fd5b74dc JB |
3843 | return genlmsg_end(msg, hdr); |
3844 | ||
3845 | nla_put_failure: | |
bc3ed28c TG |
3846 | genlmsg_cancel(msg, hdr); |
3847 | return -EMSGSIZE; | |
fd5b74dc JB |
3848 | } |
3849 | ||
2ec600d6 | 3850 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3851 | struct netlink_callback *cb) |
2ec600d6 | 3852 | { |
2ec600d6 | 3853 | struct station_info sinfo; |
1b8ec87a | 3854 | struct cfg80211_registered_device *rdev; |
97990a06 | 3855 | struct wireless_dev *wdev; |
2ec600d6 | 3856 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3857 | int sta_idx = cb->args[2]; |
2ec600d6 | 3858 | int err; |
2ec600d6 | 3859 | |
1b8ec87a | 3860 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
3861 | if (err) |
3862 | return err; | |
bba95fef | 3863 | |
97990a06 JB |
3864 | if (!wdev->netdev) { |
3865 | err = -EINVAL; | |
3866 | goto out_err; | |
3867 | } | |
3868 | ||
1b8ec87a | 3869 | if (!rdev->ops->dump_station) { |
eec60b03 | 3870 | err = -EOPNOTSUPP; |
bba95fef JB |
3871 | goto out_err; |
3872 | } | |
3873 | ||
bba95fef | 3874 | while (1) { |
f612cedf | 3875 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 3876 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
e35e4d28 | 3877 | mac_addr, &sinfo); |
bba95fef JB |
3878 | if (err == -ENOENT) |
3879 | break; | |
3880 | if (err) | |
3b85875a | 3881 | goto out_err; |
bba95fef | 3882 | |
cf5ead82 | 3883 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
15e47304 | 3884 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3885 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 3886 | rdev, wdev->netdev, mac_addr, |
bba95fef JB |
3887 | &sinfo) < 0) |
3888 | goto out; | |
3889 | ||
3890 | sta_idx++; | |
3891 | } | |
3892 | ||
3893 | ||
3894 | out: | |
97990a06 | 3895 | cb->args[2] = sta_idx; |
bba95fef | 3896 | err = skb->len; |
bba95fef | 3897 | out_err: |
1b8ec87a | 3898 | nl80211_finish_wdev_dump(rdev); |
bba95fef JB |
3899 | |
3900 | return err; | |
2ec600d6 | 3901 | } |
fd5b74dc | 3902 | |
5727ef1b JB |
3903 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3904 | { | |
4c476991 JB |
3905 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3906 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3907 | struct station_info sinfo; |
fd5b74dc JB |
3908 | struct sk_buff *msg; |
3909 | u8 *mac_addr = NULL; | |
4c476991 | 3910 | int err; |
fd5b74dc | 3911 | |
2ec600d6 | 3912 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3913 | |
3914 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3915 | return -EINVAL; | |
3916 | ||
3917 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3918 | ||
4c476991 JB |
3919 | if (!rdev->ops->get_station) |
3920 | return -EOPNOTSUPP; | |
3b85875a | 3921 | |
e35e4d28 | 3922 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3923 | if (err) |
4c476991 | 3924 | return err; |
2ec600d6 | 3925 | |
fd2120ca | 3926 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3927 | if (!msg) |
4c476991 | 3928 | return -ENOMEM; |
fd5b74dc | 3929 | |
cf5ead82 JB |
3930 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
3931 | info->snd_portid, info->snd_seq, 0, | |
66266b3a | 3932 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3933 | nlmsg_free(msg); |
3934 | return -ENOBUFS; | |
3935 | } | |
3b85875a | 3936 | |
4c476991 | 3937 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3938 | } |
3939 | ||
77ee7c89 JB |
3940 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3941 | struct station_parameters *params, | |
3942 | enum cfg80211_station_type statype) | |
3943 | { | |
3944 | if (params->listen_interval != -1) | |
3945 | return -EINVAL; | |
c72e1140 AN |
3946 | if (params->aid && |
3947 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
77ee7c89 JB |
3948 | return -EINVAL; |
3949 | ||
3950 | /* When you run into this, adjust the code below for the new flag */ | |
3951 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3952 | ||
3953 | switch (statype) { | |
eef941e6 TP |
3954 | case CFG80211_STA_MESH_PEER_KERNEL: |
3955 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3956 | /* |
3957 | * No ignoring the TDLS flag here -- the userspace mesh | |
3958 | * code doesn't have the bug of including TDLS in the | |
3959 | * mask everywhere. | |
3960 | */ | |
3961 | if (params->sta_flags_mask & | |
3962 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3963 | BIT(NL80211_STA_FLAG_MFP) | | |
3964 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3965 | return -EINVAL; | |
3966 | break; | |
3967 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3968 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3969 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3970 | return -EINVAL; | |
3971 | /* ignore since it can't change */ | |
3972 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3973 | break; | |
3974 | default: | |
3975 | /* disallow mesh-specific things */ | |
3976 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3977 | return -EINVAL; | |
3978 | if (params->local_pm) | |
3979 | return -EINVAL; | |
3980 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3981 | return -EINVAL; | |
3982 | } | |
3983 | ||
3984 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3985 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3986 | /* TDLS can't be set, ... */ | |
3987 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3988 | return -EINVAL; | |
3989 | /* | |
3990 | * ... but don't bother the driver with it. This works around | |
3991 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3992 | * TLDS_PEER flag in the mask even for AP mode. | |
3993 | */ | |
3994 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3995 | } | |
3996 | ||
3997 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3998 | /* reject other things that can't change */ | |
3999 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
4000 | return -EINVAL; | |
4001 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
4002 | return -EINVAL; | |
4003 | if (params->supported_rates) | |
4004 | return -EINVAL; | |
4005 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
4006 | return -EINVAL; | |
4007 | } | |
4008 | ||
4009 | if (statype != CFG80211_STA_AP_CLIENT) { | |
4010 | if (params->vlan) | |
4011 | return -EINVAL; | |
4012 | } | |
4013 | ||
4014 | switch (statype) { | |
4015 | case CFG80211_STA_AP_MLME_CLIENT: | |
4016 | /* Use this only for authorizing/unauthorizing a station */ | |
4017 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
4018 | return -EOPNOTSUPP; | |
4019 | break; | |
4020 | case CFG80211_STA_AP_CLIENT: | |
4021 | /* accept only the listed bits */ | |
4022 | if (params->sta_flags_mask & | |
4023 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4024 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4025 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4026 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
4027 | BIT(NL80211_STA_FLAG_WME) | | |
4028 | BIT(NL80211_STA_FLAG_MFP))) | |
4029 | return -EINVAL; | |
4030 | ||
4031 | /* but authenticated/associated only if driver handles it */ | |
4032 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4033 | params->sta_flags_mask & | |
4034 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4035 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4036 | return -EINVAL; | |
4037 | break; | |
4038 | case CFG80211_STA_IBSS: | |
4039 | case CFG80211_STA_AP_STA: | |
4040 | /* reject any changes other than AUTHORIZED */ | |
4041 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
4042 | return -EINVAL; | |
4043 | break; | |
4044 | case CFG80211_STA_TDLS_PEER_SETUP: | |
4045 | /* reject any changes other than AUTHORIZED or WME */ | |
4046 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4047 | BIT(NL80211_STA_FLAG_WME))) | |
4048 | return -EINVAL; | |
4049 | /* force (at least) rates when authorizing */ | |
4050 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
4051 | !params->supported_rates) | |
4052 | return -EINVAL; | |
4053 | break; | |
4054 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
4055 | /* reject any changes */ | |
4056 | return -EINVAL; | |
eef941e6 | 4057 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
4058 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
4059 | return -EINVAL; | |
4060 | break; | |
eef941e6 | 4061 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
4062 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
4063 | return -EINVAL; | |
4064 | break; | |
4065 | } | |
4066 | ||
4067 | return 0; | |
4068 | } | |
4069 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
4070 | ||
5727ef1b | 4071 | /* |
c258d2de | 4072 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 4073 | */ |
80b99899 JB |
4074 | static struct net_device *get_vlan(struct genl_info *info, |
4075 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 4076 | { |
463d0183 | 4077 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
4078 | struct net_device *v; |
4079 | int ret; | |
4080 | ||
4081 | if (!vlanattr) | |
4082 | return NULL; | |
4083 | ||
4084 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
4085 | if (!v) | |
4086 | return ERR_PTR(-ENODEV); | |
4087 | ||
4088 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
4089 | ret = -EINVAL; | |
4090 | goto error; | |
5727ef1b | 4091 | } |
80b99899 | 4092 | |
77ee7c89 JB |
4093 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
4094 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4095 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
4096 | ret = -EINVAL; | |
4097 | goto error; | |
4098 | } | |
4099 | ||
80b99899 JB |
4100 | if (!netif_running(v)) { |
4101 | ret = -ENETDOWN; | |
4102 | goto error; | |
4103 | } | |
4104 | ||
4105 | return v; | |
4106 | error: | |
4107 | dev_put(v); | |
4108 | return ERR_PTR(ret); | |
5727ef1b JB |
4109 | } |
4110 | ||
94e860f1 JB |
4111 | static const struct nla_policy |
4112 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
4113 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
4114 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
4115 | }; | |
4116 | ||
ff276691 JB |
4117 | static int nl80211_parse_sta_wme(struct genl_info *info, |
4118 | struct station_parameters *params) | |
df881293 | 4119 | { |
df881293 JM |
4120 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
4121 | struct nlattr *nla; | |
4122 | int err; | |
4123 | ||
df881293 JM |
4124 | /* parse WME attributes if present */ |
4125 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
4126 | return 0; | |
4127 | ||
4128 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
4129 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
4130 | nl80211_sta_wme_policy); | |
4131 | if (err) | |
4132 | return err; | |
4133 | ||
4134 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
4135 | params->uapsd_queues = nla_get_u8( | |
4136 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4137 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
4138 | return -EINVAL; | |
4139 | ||
4140 | if (tb[NL80211_STA_WME_MAX_SP]) | |
4141 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4142 | ||
4143 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
4144 | return -EINVAL; | |
4145 | ||
4146 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
4147 | ||
4148 | return 0; | |
4149 | } | |
4150 | ||
c01fc9ad SD |
4151 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4152 | struct station_parameters *params) | |
4153 | { | |
4154 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4155 | params->supported_channels = | |
4156 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4157 | params->supported_channels_len = | |
4158 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4159 | /* | |
4160 | * Need to include at least one (first channel, number of | |
4161 | * channels) tuple for each subband, and must have proper | |
4162 | * tuples for the rest of the data as well. | |
4163 | */ | |
4164 | if (params->supported_channels_len < 2) | |
4165 | return -EINVAL; | |
4166 | if (params->supported_channels_len % 2) | |
4167 | return -EINVAL; | |
4168 | } | |
4169 | ||
4170 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4171 | params->supported_oper_classes = | |
4172 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4173 | params->supported_oper_classes_len = | |
4174 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4175 | /* | |
4176 | * The value of the Length field of the Supported Operating | |
4177 | * Classes element is between 2 and 253. | |
4178 | */ | |
4179 | if (params->supported_oper_classes_len < 2 || | |
4180 | params->supported_oper_classes_len > 253) | |
4181 | return -EINVAL; | |
4182 | } | |
4183 | return 0; | |
4184 | } | |
4185 | ||
ff276691 JB |
4186 | static int nl80211_set_station_tdls(struct genl_info *info, |
4187 | struct station_parameters *params) | |
4188 | { | |
c01fc9ad | 4189 | int err; |
ff276691 | 4190 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4191 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4192 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4193 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4194 | params->ht_capa = | |
4195 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4196 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4197 | params->vht_capa = | |
4198 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4199 | ||
c01fc9ad SD |
4200 | err = nl80211_parse_sta_channel_info(info, params); |
4201 | if (err) | |
4202 | return err; | |
4203 | ||
ff276691 JB |
4204 | return nl80211_parse_sta_wme(info, params); |
4205 | } | |
4206 | ||
5727ef1b JB |
4207 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4208 | { | |
4c476991 | 4209 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4210 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4211 | struct station_parameters params; |
77ee7c89 JB |
4212 | u8 *mac_addr; |
4213 | int err; | |
5727ef1b JB |
4214 | |
4215 | memset(¶ms, 0, sizeof(params)); | |
4216 | ||
4217 | params.listen_interval = -1; | |
4218 | ||
77ee7c89 JB |
4219 | if (!rdev->ops->change_station) |
4220 | return -EOPNOTSUPP; | |
4221 | ||
5727ef1b JB |
4222 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4223 | return -EINVAL; | |
4224 | ||
4225 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4226 | return -EINVAL; | |
4227 | ||
4228 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4229 | ||
4230 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4231 | params.supported_rates = | |
4232 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4233 | params.supported_rates_len = | |
4234 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4235 | } | |
4236 | ||
9d62a986 JM |
4237 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4238 | params.capability = | |
4239 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4240 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4241 | } | |
4242 | ||
4243 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4244 | params.ext_capab = | |
4245 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4246 | params.ext_capab_len = | |
4247 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4248 | } | |
4249 | ||
df881293 | 4250 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 4251 | return -EINVAL; |
36aedc90 | 4252 | |
bdd3ae3d | 4253 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4254 | return -EINVAL; |
4255 | ||
f8bacc21 | 4256 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4257 | params.plink_action = |
f8bacc21 JB |
4258 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4259 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4260 | return -EINVAL; | |
4261 | } | |
2ec600d6 | 4262 | |
f8bacc21 | 4263 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4264 | params.plink_state = |
f8bacc21 JB |
4265 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4266 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4267 | return -EINVAL; | |
4268 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
4269 | } | |
9c3990aa | 4270 | |
3b1c5a53 MP |
4271 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4272 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4273 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4274 | ||
4275 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4276 | pm > NL80211_MESH_POWER_MAX) | |
4277 | return -EINVAL; | |
4278 | ||
4279 | params.local_pm = pm; | |
4280 | } | |
4281 | ||
77ee7c89 JB |
4282 | /* Include parameters for TDLS peer (will check later) */ |
4283 | err = nl80211_set_station_tdls(info, ¶ms); | |
4284 | if (err) | |
4285 | return err; | |
4286 | ||
4287 | params.vlan = get_vlan(info, rdev); | |
4288 | if (IS_ERR(params.vlan)) | |
4289 | return PTR_ERR(params.vlan); | |
4290 | ||
a97f4424 JB |
4291 | switch (dev->ieee80211_ptr->iftype) { |
4292 | case NL80211_IFTYPE_AP: | |
4293 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4294 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4295 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4296 | case NL80211_IFTYPE_STATION: |
267335d6 | 4297 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4298 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4299 | break; |
4300 | default: | |
77ee7c89 JB |
4301 | err = -EOPNOTSUPP; |
4302 | goto out_put_vlan; | |
034d655e JB |
4303 | } |
4304 | ||
77ee7c89 | 4305 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4306 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4307 | |
77ee7c89 | 4308 | out_put_vlan: |
5727ef1b JB |
4309 | if (params.vlan) |
4310 | dev_put(params.vlan); | |
3b85875a | 4311 | |
5727ef1b JB |
4312 | return err; |
4313 | } | |
4314 | ||
4315 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4316 | { | |
4c476991 | 4317 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4318 | int err; |
4c476991 | 4319 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4320 | struct station_parameters params; |
4321 | u8 *mac_addr = NULL; | |
4322 | ||
4323 | memset(¶ms, 0, sizeof(params)); | |
4324 | ||
984c311b JB |
4325 | if (!rdev->ops->add_station) |
4326 | return -EOPNOTSUPP; | |
4327 | ||
5727ef1b JB |
4328 | if (!info->attrs[NL80211_ATTR_MAC]) |
4329 | return -EINVAL; | |
4330 | ||
5727ef1b JB |
4331 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4332 | return -EINVAL; | |
4333 | ||
4334 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4335 | return -EINVAL; | |
4336 | ||
5e4b6f56 JM |
4337 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4338 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4339 | return -EINVAL; |
4340 | ||
5727ef1b JB |
4341 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4342 | params.supported_rates = | |
4343 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4344 | params.supported_rates_len = | |
4345 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4346 | params.listen_interval = | |
4347 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4348 | |
3d124ea2 | 4349 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4350 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4351 | else |
4352 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4353 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4354 | return -EINVAL; | |
51b50fbe | 4355 | |
9d62a986 JM |
4356 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4357 | params.capability = | |
4358 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4359 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4360 | } | |
4361 | ||
4362 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4363 | params.ext_capab = | |
4364 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4365 | params.ext_capab_len = | |
4366 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4367 | } | |
4368 | ||
36aedc90 JM |
4369 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4370 | params.ht_capa = | |
4371 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4372 | |
f461be3e MP |
4373 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4374 | params.vht_capa = | |
4375 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4376 | ||
60f4a7b1 MK |
4377 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4378 | params.opmode_notif_used = true; | |
4379 | params.opmode_notif = | |
4380 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4381 | } | |
4382 | ||
f8bacc21 | 4383 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4384 | params.plink_action = |
f8bacc21 JB |
4385 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4386 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4387 | return -EINVAL; | |
4388 | } | |
96b78dff | 4389 | |
c01fc9ad SD |
4390 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4391 | if (err) | |
4392 | return err; | |
4393 | ||
ff276691 JB |
4394 | err = nl80211_parse_sta_wme(info, ¶ms); |
4395 | if (err) | |
4396 | return err; | |
bdd90d5e | 4397 | |
bdd3ae3d | 4398 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4399 | return -EINVAL; |
4400 | ||
77ee7c89 JB |
4401 | /* When you run into this, adjust the code below for the new flag */ |
4402 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4403 | ||
bdd90d5e JB |
4404 | switch (dev->ieee80211_ptr->iftype) { |
4405 | case NL80211_IFTYPE_AP: | |
4406 | case NL80211_IFTYPE_AP_VLAN: | |
4407 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4408 | /* ignore WME attributes if iface/sta is not capable */ |
4409 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4410 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4411 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4412 | |
bdd90d5e | 4413 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4414 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4415 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4416 | return -EINVAL; |
bdd90d5e JB |
4417 | /* but don't bother the driver with it */ |
4418 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4419 | |
d582cffb JB |
4420 | /* allow authenticated/associated only if driver handles it */ |
4421 | if (!(rdev->wiphy.features & | |
4422 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4423 | params.sta_flags_mask & | |
4424 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4425 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4426 | return -EINVAL; | |
4427 | ||
bdd90d5e JB |
4428 | /* must be last in here for error handling */ |
4429 | params.vlan = get_vlan(info, rdev); | |
4430 | if (IS_ERR(params.vlan)) | |
4431 | return PTR_ERR(params.vlan); | |
4432 | break; | |
4433 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4434 | /* ignore uAPSD data */ |
4435 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4436 | ||
d582cffb JB |
4437 | /* associated is disallowed */ |
4438 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4439 | return -EINVAL; | |
bdd90d5e | 4440 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4441 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4442 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4443 | return -EINVAL; |
4444 | break; | |
4445 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4446 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4447 | /* ignore uAPSD data */ |
4448 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4449 | ||
77ee7c89 JB |
4450 | /* these are disallowed */ |
4451 | if (params.sta_flags_mask & | |
4452 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4453 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4454 | return -EINVAL; |
bdd90d5e JB |
4455 | /* Only TDLS peers can be added */ |
4456 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4457 | return -EINVAL; | |
4458 | /* Can only add if TDLS ... */ | |
4459 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4460 | return -EOPNOTSUPP; | |
4461 | /* ... with external setup is supported */ | |
4462 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4463 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4464 | /* |
4465 | * Older wpa_supplicant versions always mark the TDLS peer | |
4466 | * as authorized, but it shouldn't yet be. | |
4467 | */ | |
4468 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4469 | break; |
4470 | default: | |
4471 | return -EOPNOTSUPP; | |
c75786c9 EP |
4472 | } |
4473 | ||
bdd90d5e | 4474 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4475 | |
e35e4d28 | 4476 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4477 | |
5727ef1b JB |
4478 | if (params.vlan) |
4479 | dev_put(params.vlan); | |
5727ef1b JB |
4480 | return err; |
4481 | } | |
4482 | ||
4483 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4484 | { | |
4c476991 JB |
4485 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4486 | struct net_device *dev = info->user_ptr[1]; | |
89c771e5 JM |
4487 | struct station_del_parameters params; |
4488 | ||
4489 | memset(¶ms, 0, sizeof(params)); | |
5727ef1b JB |
4490 | |
4491 | if (info->attrs[NL80211_ATTR_MAC]) | |
89c771e5 | 4492 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5727ef1b | 4493 | |
e80cf853 | 4494 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4495 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4496 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4497 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4498 | return -EINVAL; | |
5727ef1b | 4499 | |
4c476991 JB |
4500 | if (!rdev->ops->del_station) |
4501 | return -EOPNOTSUPP; | |
3b85875a | 4502 | |
98856866 JM |
4503 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
4504 | params.subtype = | |
4505 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | |
4506 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | |
4507 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | |
4508 | return -EINVAL; | |
4509 | } else { | |
4510 | /* Default to Deauthentication frame */ | |
4511 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | |
4512 | } | |
4513 | ||
4514 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | |
4515 | params.reason_code = | |
4516 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
4517 | if (params.reason_code == 0) | |
4518 | return -EINVAL; /* 0 is reserved */ | |
4519 | } else { | |
4520 | /* Default to reason code 2 */ | |
4521 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | |
4522 | } | |
4523 | ||
89c771e5 | 4524 | return rdev_del_station(rdev, dev, ¶ms); |
5727ef1b JB |
4525 | } |
4526 | ||
15e47304 | 4527 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4528 | int flags, struct net_device *dev, |
4529 | u8 *dst, u8 *next_hop, | |
4530 | struct mpath_info *pinfo) | |
4531 | { | |
4532 | void *hdr; | |
4533 | struct nlattr *pinfoattr; | |
4534 | ||
1ef4c850 | 4535 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
2ec600d6 LCC |
4536 | if (!hdr) |
4537 | return -1; | |
4538 | ||
9360ffd1 DM |
4539 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4540 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4541 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4542 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4543 | goto nla_put_failure; | |
f5ea9120 | 4544 | |
2ec600d6 LCC |
4545 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4546 | if (!pinfoattr) | |
4547 | goto nla_put_failure; | |
9360ffd1 DM |
4548 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4549 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4550 | pinfo->frame_qlen)) | |
4551 | goto nla_put_failure; | |
4552 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4553 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4554 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4555 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4556 | pinfo->metric)) || | |
4557 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4558 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4559 | pinfo->exptime)) || | |
4560 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4561 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4562 | pinfo->flags)) || | |
4563 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4564 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4565 | pinfo->discovery_timeout)) || | |
4566 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4567 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4568 | pinfo->discovery_retries))) | |
4569 | goto nla_put_failure; | |
2ec600d6 LCC |
4570 | |
4571 | nla_nest_end(msg, pinfoattr); | |
4572 | ||
4573 | return genlmsg_end(msg, hdr); | |
4574 | ||
4575 | nla_put_failure: | |
bc3ed28c TG |
4576 | genlmsg_cancel(msg, hdr); |
4577 | return -EMSGSIZE; | |
2ec600d6 LCC |
4578 | } |
4579 | ||
4580 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4581 | struct netlink_callback *cb) |
2ec600d6 | 4582 | { |
2ec600d6 | 4583 | struct mpath_info pinfo; |
1b8ec87a | 4584 | struct cfg80211_registered_device *rdev; |
97990a06 | 4585 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4586 | u8 dst[ETH_ALEN]; |
4587 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4588 | int path_idx = cb->args[2]; |
2ec600d6 | 4589 | int err; |
2ec600d6 | 4590 | |
1b8ec87a | 4591 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
4592 | if (err) |
4593 | return err; | |
bba95fef | 4594 | |
1b8ec87a | 4595 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 4596 | err = -EOPNOTSUPP; |
bba95fef JB |
4597 | goto out_err; |
4598 | } | |
4599 | ||
97990a06 | 4600 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4601 | err = -EOPNOTSUPP; |
0448b5fc | 4602 | goto out_err; |
eec60b03 JM |
4603 | } |
4604 | ||
bba95fef | 4605 | while (1) { |
1b8ec87a | 4606 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 4607 | next_hop, &pinfo); |
bba95fef | 4608 | if (err == -ENOENT) |
2ec600d6 | 4609 | break; |
bba95fef | 4610 | if (err) |
3b85875a | 4611 | goto out_err; |
2ec600d6 | 4612 | |
15e47304 | 4613 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4614 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4615 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4616 | &pinfo) < 0) |
4617 | goto out; | |
2ec600d6 | 4618 | |
bba95fef | 4619 | path_idx++; |
2ec600d6 | 4620 | } |
2ec600d6 | 4621 | |
2ec600d6 | 4622 | |
bba95fef | 4623 | out: |
97990a06 | 4624 | cb->args[2] = path_idx; |
bba95fef | 4625 | err = skb->len; |
bba95fef | 4626 | out_err: |
1b8ec87a | 4627 | nl80211_finish_wdev_dump(rdev); |
bba95fef | 4628 | return err; |
2ec600d6 LCC |
4629 | } |
4630 | ||
4631 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4632 | { | |
4c476991 | 4633 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4634 | int err; |
4c476991 | 4635 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4636 | struct mpath_info pinfo; |
4637 | struct sk_buff *msg; | |
4638 | u8 *dst = NULL; | |
4639 | u8 next_hop[ETH_ALEN]; | |
4640 | ||
4641 | memset(&pinfo, 0, sizeof(pinfo)); | |
4642 | ||
4643 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4644 | return -EINVAL; | |
4645 | ||
4646 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4647 | ||
4c476991 JB |
4648 | if (!rdev->ops->get_mpath) |
4649 | return -EOPNOTSUPP; | |
2ec600d6 | 4650 | |
4c476991 JB |
4651 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4652 | return -EOPNOTSUPP; | |
eec60b03 | 4653 | |
e35e4d28 | 4654 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4655 | if (err) |
4c476991 | 4656 | return err; |
2ec600d6 | 4657 | |
fd2120ca | 4658 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4659 | if (!msg) |
4c476991 | 4660 | return -ENOMEM; |
2ec600d6 | 4661 | |
15e47304 | 4662 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4663 | dev, dst, next_hop, &pinfo) < 0) { |
4664 | nlmsg_free(msg); | |
4665 | return -ENOBUFS; | |
4666 | } | |
3b85875a | 4667 | |
4c476991 | 4668 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4669 | } |
4670 | ||
4671 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4672 | { | |
4c476991 JB |
4673 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4674 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4675 | u8 *dst = NULL; |
4676 | u8 *next_hop = NULL; | |
4677 | ||
4678 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4679 | return -EINVAL; | |
4680 | ||
4681 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4682 | return -EINVAL; | |
4683 | ||
4684 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4685 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4686 | ||
4c476991 JB |
4687 | if (!rdev->ops->change_mpath) |
4688 | return -EOPNOTSUPP; | |
35a8efe1 | 4689 | |
4c476991 JB |
4690 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4691 | return -EOPNOTSUPP; | |
2ec600d6 | 4692 | |
e35e4d28 | 4693 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4694 | } |
4c476991 | 4695 | |
2ec600d6 LCC |
4696 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4697 | { | |
4c476991 JB |
4698 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4699 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4700 | u8 *dst = NULL; |
4701 | u8 *next_hop = NULL; | |
4702 | ||
4703 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4704 | return -EINVAL; | |
4705 | ||
4706 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4707 | return -EINVAL; | |
4708 | ||
4709 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4710 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4711 | ||
4c476991 JB |
4712 | if (!rdev->ops->add_mpath) |
4713 | return -EOPNOTSUPP; | |
35a8efe1 | 4714 | |
4c476991 JB |
4715 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4716 | return -EOPNOTSUPP; | |
2ec600d6 | 4717 | |
e35e4d28 | 4718 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4719 | } |
4720 | ||
4721 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4722 | { | |
4c476991 JB |
4723 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4724 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4725 | u8 *dst = NULL; |
4726 | ||
4727 | if (info->attrs[NL80211_ATTR_MAC]) | |
4728 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4729 | ||
4c476991 JB |
4730 | if (!rdev->ops->del_mpath) |
4731 | return -EOPNOTSUPP; | |
3b85875a | 4732 | |
e35e4d28 | 4733 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4734 | } |
4735 | ||
66be7d2b HR |
4736 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
4737 | { | |
4738 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4739 | int err; | |
4740 | struct net_device *dev = info->user_ptr[1]; | |
4741 | struct mpath_info pinfo; | |
4742 | struct sk_buff *msg; | |
4743 | u8 *dst = NULL; | |
4744 | u8 mpp[ETH_ALEN]; | |
4745 | ||
4746 | memset(&pinfo, 0, sizeof(pinfo)); | |
4747 | ||
4748 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4749 | return -EINVAL; | |
4750 | ||
4751 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4752 | ||
4753 | if (!rdev->ops->get_mpp) | |
4754 | return -EOPNOTSUPP; | |
4755 | ||
4756 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
4757 | return -EOPNOTSUPP; | |
4758 | ||
4759 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | |
4760 | if (err) | |
4761 | return err; | |
4762 | ||
4763 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4764 | if (!msg) | |
4765 | return -ENOMEM; | |
4766 | ||
4767 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | |
4768 | dev, dst, mpp, &pinfo) < 0) { | |
4769 | nlmsg_free(msg); | |
4770 | return -ENOBUFS; | |
4771 | } | |
4772 | ||
4773 | return genlmsg_reply(msg, info); | |
4774 | } | |
4775 | ||
4776 | static int nl80211_dump_mpp(struct sk_buff *skb, | |
4777 | struct netlink_callback *cb) | |
4778 | { | |
4779 | struct mpath_info pinfo; | |
4780 | struct cfg80211_registered_device *rdev; | |
4781 | struct wireless_dev *wdev; | |
4782 | u8 dst[ETH_ALEN]; | |
4783 | u8 mpp[ETH_ALEN]; | |
4784 | int path_idx = cb->args[2]; | |
4785 | int err; | |
4786 | ||
4787 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | |
4788 | if (err) | |
4789 | return err; | |
4790 | ||
4791 | if (!rdev->ops->dump_mpp) { | |
4792 | err = -EOPNOTSUPP; | |
4793 | goto out_err; | |
4794 | } | |
4795 | ||
4796 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | |
4797 | err = -EOPNOTSUPP; | |
4798 | goto out_err; | |
4799 | } | |
4800 | ||
4801 | while (1) { | |
4802 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | |
4803 | mpp, &pinfo); | |
4804 | if (err == -ENOENT) | |
4805 | break; | |
4806 | if (err) | |
4807 | goto out_err; | |
4808 | ||
4809 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | |
4810 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
4811 | wdev->netdev, dst, mpp, | |
4812 | &pinfo) < 0) | |
4813 | goto out; | |
4814 | ||
4815 | path_idx++; | |
4816 | } | |
4817 | ||
4818 | out: | |
4819 | cb->args[2] = path_idx; | |
4820 | err = skb->len; | |
4821 | out_err: | |
4822 | nl80211_finish_wdev_dump(rdev); | |
4823 | return err; | |
4824 | } | |
4825 | ||
9f1ba906 JM |
4826 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4827 | { | |
4c476991 JB |
4828 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4829 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 4830 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 4831 | struct bss_parameters params; |
c56589ed | 4832 | int err; |
9f1ba906 JM |
4833 | |
4834 | memset(¶ms, 0, sizeof(params)); | |
4835 | /* default to not changing parameters */ | |
4836 | params.use_cts_prot = -1; | |
4837 | params.use_short_preamble = -1; | |
4838 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4839 | params.ap_isolate = -1; |
50b12f59 | 4840 | params.ht_opmode = -1; |
53cabad7 JB |
4841 | params.p2p_ctwindow = -1; |
4842 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4843 | |
4844 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4845 | params.use_cts_prot = | |
4846 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4847 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4848 | params.use_short_preamble = | |
4849 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4850 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4851 | params.use_short_slot_time = | |
4852 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4853 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4854 | params.basic_rates = | |
4855 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4856 | params.basic_rates_len = | |
4857 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4858 | } | |
fd8aaaf3 FF |
4859 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4860 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4861 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4862 | params.ht_opmode = | |
4863 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4864 | |
53cabad7 JB |
4865 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4866 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4867 | return -EINVAL; | |
4868 | params.p2p_ctwindow = | |
4869 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4870 | if (params.p2p_ctwindow < 0) | |
4871 | return -EINVAL; | |
4872 | if (params.p2p_ctwindow != 0 && | |
4873 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4874 | return -EINVAL; | |
4875 | } | |
4876 | ||
4877 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4878 | u8 tmp; | |
4879 | ||
4880 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4881 | return -EINVAL; | |
4882 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4883 | if (tmp > 1) | |
4884 | return -EINVAL; | |
4885 | params.p2p_opp_ps = tmp; | |
4886 | if (params.p2p_opp_ps && | |
4887 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4888 | return -EINVAL; | |
4889 | } | |
4890 | ||
4c476991 JB |
4891 | if (!rdev->ops->change_bss) |
4892 | return -EOPNOTSUPP; | |
9f1ba906 | 4893 | |
074ac8df | 4894 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4895 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4896 | return -EOPNOTSUPP; | |
3b85875a | 4897 | |
c56589ed SW |
4898 | wdev_lock(wdev); |
4899 | err = rdev_change_bss(rdev, dev, ¶ms); | |
4900 | wdev_unlock(wdev); | |
4901 | ||
4902 | return err; | |
9f1ba906 JM |
4903 | } |
4904 | ||
b54452b0 | 4905 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4906 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4907 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4908 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4909 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4910 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4911 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
089027e5 | 4912 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
b2e1b302 LR |
4913 | }; |
4914 | ||
4915 | static int parse_reg_rule(struct nlattr *tb[], | |
4916 | struct ieee80211_reg_rule *reg_rule) | |
4917 | { | |
4918 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4919 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4920 | ||
4921 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4922 | return -EINVAL; | |
4923 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4924 | return -EINVAL; | |
4925 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4926 | return -EINVAL; | |
b0dfd2ea JD |
4927 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
4928 | return -EINVAL; | |
b2e1b302 LR |
4929 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
4930 | return -EINVAL; | |
4931 | ||
4932 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4933 | ||
4934 | freq_range->start_freq_khz = | |
4935 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4936 | freq_range->end_freq_khz = | |
4937 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
b0dfd2ea JD |
4938 | freq_range->max_bandwidth_khz = |
4939 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
b2e1b302 LR |
4940 | |
4941 | power_rule->max_eirp = | |
4942 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4943 | ||
4944 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4945 | power_rule->max_antenna_gain = | |
4946 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4947 | ||
089027e5 JD |
4948 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
4949 | reg_rule->dfs_cac_ms = | |
4950 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
4951 | ||
b2e1b302 LR |
4952 | return 0; |
4953 | } | |
4954 | ||
4955 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4956 | { | |
b2e1b302 | 4957 | char *data = NULL; |
57b5ce07 | 4958 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4959 | |
80778f18 LR |
4960 | /* |
4961 | * You should only get this when cfg80211 hasn't yet initialized | |
4962 | * completely when built-in to the kernel right between the time | |
4963 | * window between nl80211_init() and regulatory_init(), if that is | |
4964 | * even possible. | |
4965 | */ | |
458f4f9e | 4966 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4967 | return -EINPROGRESS; |
80778f18 | 4968 | |
57b5ce07 LR |
4969 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4970 | user_reg_hint_type = | |
4971 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4972 | else | |
4973 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4974 | ||
4975 | switch (user_reg_hint_type) { | |
4976 | case NL80211_USER_REG_HINT_USER: | |
4977 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
4978 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4979 | return -EINVAL; | |
4980 | ||
4981 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4982 | return regulatory_hint_user(data, user_reg_hint_type); | |
4983 | case NL80211_USER_REG_HINT_INDOOR: | |
4984 | return regulatory_hint_indoor_user(); | |
57b5ce07 LR |
4985 | default: |
4986 | return -EINVAL; | |
4987 | } | |
b2e1b302 LR |
4988 | } |
4989 | ||
24bdd9f4 | 4990 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4991 | struct genl_info *info) |
93da9cc1 | 4992 | { |
4c476991 | 4993 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4994 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4995 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4996 | struct mesh_config cur_params; | |
4997 | int err = 0; | |
93da9cc1 | 4998 | void *hdr; |
4999 | struct nlattr *pinfoattr; | |
5000 | struct sk_buff *msg; | |
5001 | ||
29cbe68c JB |
5002 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5003 | return -EOPNOTSUPP; | |
5004 | ||
24bdd9f4 | 5005 | if (!rdev->ops->get_mesh_config) |
4c476991 | 5006 | return -EOPNOTSUPP; |
f3f92586 | 5007 | |
29cbe68c JB |
5008 | wdev_lock(wdev); |
5009 | /* If not connected, get default parameters */ | |
5010 | if (!wdev->mesh_id_len) | |
5011 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
5012 | else | |
e35e4d28 | 5013 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
5014 | wdev_unlock(wdev); |
5015 | ||
93da9cc1 | 5016 | if (err) |
4c476991 | 5017 | return err; |
93da9cc1 | 5018 | |
5019 | /* Draw up a netlink message to send back */ | |
fd2120ca | 5020 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
5021 | if (!msg) |
5022 | return -ENOMEM; | |
15e47304 | 5023 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 5024 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 5025 | if (!hdr) |
efe1cf0c | 5026 | goto out; |
24bdd9f4 | 5027 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 5028 | if (!pinfoattr) |
5029 | goto nla_put_failure; | |
9360ffd1 DM |
5030 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5031 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
5032 | cur_params.dot11MeshRetryTimeout) || | |
5033 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
5034 | cur_params.dot11MeshConfirmTimeout) || | |
5035 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
5036 | cur_params.dot11MeshHoldingTimeout) || | |
5037 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
5038 | cur_params.dot11MeshMaxPeerLinks) || | |
5039 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
5040 | cur_params.dot11MeshMaxRetries) || | |
5041 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
5042 | cur_params.dot11MeshTTL) || | |
5043 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
5044 | cur_params.element_ttl) || | |
5045 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
5046 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
5047 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5048 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
5049 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5050 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
5051 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
5052 | cur_params.path_refresh_time) || | |
5053 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
5054 | cur_params.min_discovery_timeout) || | |
5055 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
5056 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
5057 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
5058 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
5059 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
5060 | cur_params.dot11MeshHWMPperrMinInterval) || | |
5061 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
5062 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
5063 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5064 | cur_params.dot11MeshHWMPRootMode) || | |
5065 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
5066 | cur_params.dot11MeshHWMPRannInterval) || | |
5067 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
5068 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
5069 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
5070 | cur_params.dot11MeshForwarding) || | |
5071 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
5072 | cur_params.rssi_threshold) || |
5073 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
5074 | cur_params.ht_opmode) || |
5075 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
5076 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
5077 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
5078 | cur_params.dot11MeshHWMProotInterval) || |
5079 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
5080 | cur_params.dot11MeshHWMPconfirmationInterval) || |
5081 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
5082 | cur_params.power_mode) || | |
5083 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
5084 | cur_params.dot11MeshAwakeWindowDuration) || |
5085 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5086 | cur_params.plink_timeout)) | |
9360ffd1 | 5087 | goto nla_put_failure; |
93da9cc1 | 5088 | nla_nest_end(msg, pinfoattr); |
5089 | genlmsg_end(msg, hdr); | |
4c476991 | 5090 | return genlmsg_reply(msg, info); |
93da9cc1 | 5091 | |
3b85875a | 5092 | nla_put_failure: |
93da9cc1 | 5093 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 5094 | out: |
d080e275 | 5095 | nlmsg_free(msg); |
4c476991 | 5096 | return -ENOBUFS; |
93da9cc1 | 5097 | } |
5098 | ||
b54452b0 | 5099 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 5100 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
5101 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
5102 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
5103 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
5104 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
5105 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 5106 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 5107 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 5108 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 5109 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
5110 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
5111 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
5112 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
5113 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 5114 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 5115 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 5116 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 5117 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 5118 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 5119 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
5120 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
5121 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
5122 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
5123 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 5124 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
5125 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
5126 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 5127 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 5128 | }; |
5129 | ||
c80d545d JC |
5130 | static const struct nla_policy |
5131 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 5132 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
5133 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
5134 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 5135 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 5136 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 5137 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 5138 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 5139 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 5140 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
5141 | }; |
5142 | ||
24bdd9f4 | 5143 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
5144 | struct mesh_config *cfg, |
5145 | u32 *mask_out) | |
93da9cc1 | 5146 | { |
93da9cc1 | 5147 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 5148 | u32 mask = 0; |
93da9cc1 | 5149 | |
ea54fba2 MP |
5150 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
5151 | do { \ | |
5152 | if (tb[attr]) { \ | |
5153 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
5154 | return -EINVAL; \ | |
5155 | cfg->param = fn(tb[attr]); \ | |
5156 | mask |= (1 << (attr - 1)); \ | |
5157 | } \ | |
5158 | } while (0) | |
bd90fdcc JB |
5159 | |
5160 | ||
24bdd9f4 | 5161 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 5162 | return -EINVAL; |
5163 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 5164 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 5165 | nl80211_meshconf_params_policy)) |
93da9cc1 | 5166 | return -EINVAL; |
5167 | ||
93da9cc1 | 5168 | /* This makes sure that there aren't more than 32 mesh config |
5169 | * parameters (otherwise our bitfield scheme would not work.) */ | |
5170 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
5171 | ||
5172 | /* Fill in the params struct */ | |
ea54fba2 | 5173 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
5174 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
5175 | nla_get_u16); | |
ea54fba2 | 5176 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
5177 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
5178 | nla_get_u16); | |
ea54fba2 | 5179 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
5180 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
5181 | nla_get_u16); | |
ea54fba2 | 5182 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
5183 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
5184 | nla_get_u16); | |
ea54fba2 | 5185 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
5186 | mask, NL80211_MESHCONF_MAX_RETRIES, |
5187 | nla_get_u8); | |
ea54fba2 | 5188 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 5189 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 5190 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
5191 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
5192 | nla_get_u8); | |
ea54fba2 | 5193 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
5194 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
5195 | nla_get_u8); | |
ea54fba2 MP |
5196 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
5197 | 1, 255, mask, | |
a4f606ea CYY |
5198 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5199 | nla_get_u32); | |
ea54fba2 | 5200 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
5201 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5202 | nla_get_u8); | |
ea54fba2 | 5203 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
5204 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
5205 | nla_get_u32); | |
ea54fba2 | 5206 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
5207 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
5208 | nla_get_u16); | |
ea54fba2 MP |
5209 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
5210 | 1, 65535, mask, | |
a4f606ea CYY |
5211 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
5212 | nla_get_u32); | |
93da9cc1 | 5213 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
5214 | 1, 65535, mask, |
5215 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 5216 | nla_get_u16); |
dca7e943 | 5217 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
5218 | 1, 65535, mask, |
5219 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 5220 | nla_get_u16); |
93da9cc1 | 5221 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5222 | dot11MeshHWMPnetDiameterTraversalTime, |
5223 | 1, 65535, mask, | |
a4f606ea CYY |
5224 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
5225 | nla_get_u16); | |
ea54fba2 MP |
5226 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
5227 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5228 | nla_get_u8); | |
5229 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
5230 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 5231 | nla_get_u16); |
63c5723b | 5232 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5233 | dot11MeshGateAnnouncementProtocol, 0, 1, |
5234 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 5235 | nla_get_u8); |
ea54fba2 | 5236 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
5237 | mask, NL80211_MESHCONF_FORWARDING, |
5238 | nla_get_u8); | |
83374fe9 | 5239 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 5240 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
83374fe9 | 5241 | nla_get_s32); |
ea54fba2 | 5242 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 5243 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
5244 | nla_get_u16); |
5245 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 5246 | 1, 65535, mask, |
ac1073a6 CYY |
5247 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
5248 | nla_get_u32); | |
ea54fba2 | 5249 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 5250 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
5251 | nla_get_u16); |
5252 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
5253 | dot11MeshHWMPconfirmationInterval, |
5254 | 1, 65535, mask, | |
728b19e5 | 5255 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 5256 | nla_get_u16); |
3b1c5a53 MP |
5257 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
5258 | NL80211_MESH_POWER_ACTIVE, | |
5259 | NL80211_MESH_POWER_MAX, | |
5260 | mask, NL80211_MESHCONF_POWER_MODE, | |
5261 | nla_get_u32); | |
5262 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
5263 | 0, 65535, mask, | |
5264 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
8e7c0538 CT |
5265 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
5266 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5267 | nla_get_u32); | |
bd90fdcc JB |
5268 | if (mask_out) |
5269 | *mask_out = mask; | |
c80d545d | 5270 | |
bd90fdcc JB |
5271 | return 0; |
5272 | ||
5273 | #undef FILL_IN_MESH_PARAM_IF_SET | |
5274 | } | |
5275 | ||
c80d545d JC |
5276 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
5277 | struct mesh_setup *setup) | |
5278 | { | |
bb2798d4 | 5279 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
5280 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
5281 | ||
5282 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
5283 | return -EINVAL; | |
5284 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
5285 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
5286 | nl80211_mesh_setup_params_policy)) | |
5287 | return -EINVAL; | |
5288 | ||
d299a1f2 JC |
5289 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
5290 | setup->sync_method = | |
5291 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
5292 | IEEE80211_SYNC_METHOD_VENDOR : | |
5293 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
5294 | ||
c80d545d JC |
5295 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
5296 | setup->path_sel_proto = | |
5297 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5298 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5299 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5300 | ||
5301 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5302 | setup->path_metric = | |
5303 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5304 | IEEE80211_PATH_METRIC_VENDOR : | |
5305 | IEEE80211_PATH_METRIC_AIRTIME; | |
5306 | ||
581a8b0f JC |
5307 | |
5308 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 5309 | struct nlattr *ieattr = |
581a8b0f | 5310 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5311 | if (!is_valid_ie_attr(ieattr)) |
5312 | return -EINVAL; | |
581a8b0f JC |
5313 | setup->ie = nla_data(ieattr); |
5314 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5315 | } |
bb2798d4 TP |
5316 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5317 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5318 | return -EINVAL; | |
5319 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5320 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5321 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5322 | if (setup->is_secure) |
5323 | setup->user_mpm = true; | |
c80d545d | 5324 | |
6e16d90b CT |
5325 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5326 | if (!setup->user_mpm) | |
5327 | return -EINVAL; | |
5328 | setup->auth_id = | |
5329 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5330 | } | |
5331 | ||
c80d545d JC |
5332 | return 0; |
5333 | } | |
5334 | ||
24bdd9f4 | 5335 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5336 | struct genl_info *info) |
bd90fdcc JB |
5337 | { |
5338 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5339 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5340 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5341 | struct mesh_config cfg; |
5342 | u32 mask; | |
5343 | int err; | |
5344 | ||
29cbe68c JB |
5345 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5346 | return -EOPNOTSUPP; | |
5347 | ||
24bdd9f4 | 5348 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5349 | return -EOPNOTSUPP; |
5350 | ||
24bdd9f4 | 5351 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5352 | if (err) |
5353 | return err; | |
5354 | ||
29cbe68c JB |
5355 | wdev_lock(wdev); |
5356 | if (!wdev->mesh_id_len) | |
5357 | err = -ENOLINK; | |
5358 | ||
5359 | if (!err) | |
e35e4d28 | 5360 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5361 | |
5362 | wdev_unlock(wdev); | |
5363 | ||
5364 | return err; | |
93da9cc1 | 5365 | } |
5366 | ||
ad30ca2c AN |
5367 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
5368 | struct sk_buff *msg) | |
f130347c | 5369 | { |
f130347c LR |
5370 | struct nlattr *nl_reg_rules; |
5371 | unsigned int i; | |
f130347c | 5372 | |
458f4f9e JB |
5373 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
5374 | (regdom->dfs_region && | |
5375 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
ad30ca2c | 5376 | goto nla_put_failure; |
458f4f9e | 5377 | |
f130347c LR |
5378 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5379 | if (!nl_reg_rules) | |
ad30ca2c | 5380 | goto nla_put_failure; |
f130347c | 5381 | |
458f4f9e | 5382 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5383 | struct nlattr *nl_reg_rule; |
5384 | const struct ieee80211_reg_rule *reg_rule; | |
5385 | const struct ieee80211_freq_range *freq_range; | |
5386 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 5387 | unsigned int max_bandwidth_khz; |
f130347c | 5388 | |
458f4f9e | 5389 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5390 | freq_range = ®_rule->freq_range; |
5391 | power_rule = ®_rule->power_rule; | |
5392 | ||
5393 | nl_reg_rule = nla_nest_start(msg, i); | |
5394 | if (!nl_reg_rule) | |
ad30ca2c | 5395 | goto nla_put_failure; |
f130347c | 5396 | |
97524820 JD |
5397 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
5398 | if (!max_bandwidth_khz) | |
5399 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
5400 | reg_rule); | |
5401 | ||
9360ffd1 DM |
5402 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5403 | reg_rule->flags) || | |
5404 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5405 | freq_range->start_freq_khz) || | |
5406 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5407 | freq_range->end_freq_khz) || | |
5408 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 5409 | max_bandwidth_khz) || |
9360ffd1 DM |
5410 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
5411 | power_rule->max_antenna_gain) || | |
5412 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
5413 | power_rule->max_eirp) || |
5414 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
5415 | reg_rule->dfs_cac_ms)) | |
ad30ca2c | 5416 | goto nla_put_failure; |
f130347c LR |
5417 | |
5418 | nla_nest_end(msg, nl_reg_rule); | |
5419 | } | |
5420 | ||
5421 | nla_nest_end(msg, nl_reg_rules); | |
ad30ca2c AN |
5422 | return 0; |
5423 | ||
5424 | nla_put_failure: | |
5425 | return -EMSGSIZE; | |
5426 | } | |
5427 | ||
5428 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) | |
5429 | { | |
5430 | const struct ieee80211_regdomain *regdom = NULL; | |
5431 | struct cfg80211_registered_device *rdev; | |
5432 | struct wiphy *wiphy = NULL; | |
5433 | struct sk_buff *msg; | |
5434 | void *hdr; | |
5435 | ||
5436 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5437 | if (!msg) | |
5438 | return -ENOBUFS; | |
5439 | ||
5440 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
5441 | NL80211_CMD_GET_REG); | |
5442 | if (!hdr) | |
5443 | goto put_failure; | |
5444 | ||
5445 | if (info->attrs[NL80211_ATTR_WIPHY]) { | |
1bdd716c AN |
5446 | bool self_managed; |
5447 | ||
ad30ca2c AN |
5448 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
5449 | if (IS_ERR(rdev)) { | |
5450 | nlmsg_free(msg); | |
5451 | return PTR_ERR(rdev); | |
5452 | } | |
5453 | ||
5454 | wiphy = &rdev->wiphy; | |
1bdd716c AN |
5455 | self_managed = wiphy->regulatory_flags & |
5456 | REGULATORY_WIPHY_SELF_MANAGED; | |
ad30ca2c AN |
5457 | regdom = get_wiphy_regdom(wiphy); |
5458 | ||
1bdd716c AN |
5459 | /* a self-managed-reg device must have a private regdom */ |
5460 | if (WARN_ON(!regdom && self_managed)) { | |
5461 | nlmsg_free(msg); | |
5462 | return -EINVAL; | |
5463 | } | |
5464 | ||
ad30ca2c AN |
5465 | if (regdom && |
5466 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5467 | goto nla_put_failure; | |
5468 | } | |
5469 | ||
5470 | if (!wiphy && reg_last_request_cell_base() && | |
5471 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5472 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5473 | goto nla_put_failure; | |
5474 | ||
5475 | rcu_read_lock(); | |
5476 | ||
5477 | if (!regdom) | |
5478 | regdom = rcu_dereference(cfg80211_regdomain); | |
5479 | ||
5480 | if (nl80211_put_regdom(regdom, msg)) | |
5481 | goto nla_put_failure_rcu; | |
5482 | ||
5483 | rcu_read_unlock(); | |
f130347c LR |
5484 | |
5485 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5486 | return genlmsg_reply(msg, info); |
f130347c | 5487 | |
458f4f9e JB |
5488 | nla_put_failure_rcu: |
5489 | rcu_read_unlock(); | |
f130347c LR |
5490 | nla_put_failure: |
5491 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5492 | put_failure: |
d080e275 | 5493 | nlmsg_free(msg); |
5fe231e8 | 5494 | return -EMSGSIZE; |
f130347c LR |
5495 | } |
5496 | ||
ad30ca2c AN |
5497 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
5498 | u32 seq, int flags, struct wiphy *wiphy, | |
5499 | const struct ieee80211_regdomain *regdom) | |
5500 | { | |
5501 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | |
5502 | NL80211_CMD_GET_REG); | |
5503 | ||
5504 | if (!hdr) | |
5505 | return -1; | |
5506 | ||
5507 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); | |
5508 | ||
5509 | if (nl80211_put_regdom(regdom, msg)) | |
5510 | goto nla_put_failure; | |
5511 | ||
5512 | if (!wiphy && reg_last_request_cell_base() && | |
5513 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5514 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5515 | goto nla_put_failure; | |
5516 | ||
5517 | if (wiphy && | |
5518 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5519 | goto nla_put_failure; | |
5520 | ||
1bdd716c AN |
5521 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
5522 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
5523 | goto nla_put_failure; | |
5524 | ||
ad30ca2c AN |
5525 | return genlmsg_end(msg, hdr); |
5526 | ||
5527 | nla_put_failure: | |
5528 | genlmsg_cancel(msg, hdr); | |
5529 | return -EMSGSIZE; | |
5530 | } | |
5531 | ||
5532 | static int nl80211_get_reg_dump(struct sk_buff *skb, | |
5533 | struct netlink_callback *cb) | |
5534 | { | |
5535 | const struct ieee80211_regdomain *regdom = NULL; | |
5536 | struct cfg80211_registered_device *rdev; | |
5537 | int err, reg_idx, start = cb->args[2]; | |
5538 | ||
5539 | rtnl_lock(); | |
5540 | ||
5541 | if (cfg80211_regdomain && start == 0) { | |
5542 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5543 | NLM_F_MULTI, NULL, | |
5544 | rtnl_dereference(cfg80211_regdomain)); | |
5545 | if (err < 0) | |
5546 | goto out_err; | |
5547 | } | |
5548 | ||
5549 | /* the global regdom is idx 0 */ | |
5550 | reg_idx = 1; | |
5551 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | |
5552 | regdom = get_wiphy_regdom(&rdev->wiphy); | |
5553 | if (!regdom) | |
5554 | continue; | |
5555 | ||
5556 | if (++reg_idx <= start) | |
5557 | continue; | |
5558 | ||
5559 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5560 | NLM_F_MULTI, &rdev->wiphy, regdom); | |
5561 | if (err < 0) { | |
5562 | reg_idx--; | |
5563 | break; | |
5564 | } | |
5565 | } | |
5566 | ||
5567 | cb->args[2] = reg_idx; | |
5568 | err = skb->len; | |
5569 | out_err: | |
5570 | rtnl_unlock(); | |
5571 | return err; | |
5572 | } | |
5573 | ||
b2e1b302 LR |
5574 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5575 | { | |
5576 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5577 | struct nlattr *nl_reg_rule; | |
ea372c54 JB |
5578 | char *alpha2; |
5579 | int rem_reg_rules, r; | |
b2e1b302 | 5580 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
4c7d3982 | 5581 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
ea372c54 | 5582 | struct ieee80211_regdomain *rd; |
b2e1b302 LR |
5583 | |
5584 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5585 | return -EINVAL; | |
5586 | ||
5587 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5588 | return -EINVAL; | |
5589 | ||
5590 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5591 | ||
8b60b078 LR |
5592 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5593 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5594 | ||
b2e1b302 | 5595 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5596 | rem_reg_rules) { |
b2e1b302 LR |
5597 | num_rules++; |
5598 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5599 | return -EINVAL; |
b2e1b302 LR |
5600 | } |
5601 | ||
e438768f LR |
5602 | if (!reg_is_valid_request(alpha2)) |
5603 | return -EINVAL; | |
5604 | ||
b2e1b302 | 5605 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5606 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5607 | |
5608 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5609 | if (!rd) |
5610 | return -ENOMEM; | |
b2e1b302 LR |
5611 | |
5612 | rd->n_reg_rules = num_rules; | |
5613 | rd->alpha2[0] = alpha2[0]; | |
5614 | rd->alpha2[1] = alpha2[1]; | |
5615 | ||
8b60b078 LR |
5616 | /* |
5617 | * Disable DFS master mode if the DFS region was | |
5618 | * not supported or known on this kernel. | |
5619 | */ | |
5620 | if (reg_supported_dfs_region(dfs_region)) | |
5621 | rd->dfs_region = dfs_region; | |
5622 | ||
b2e1b302 | 5623 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5624 | rem_reg_rules) { |
ae811e21 JB |
5625 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
5626 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
5627 | reg_rule_policy); | |
5628 | if (r) | |
5629 | goto bad_reg; | |
b2e1b302 LR |
5630 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5631 | if (r) | |
5632 | goto bad_reg; | |
5633 | ||
5634 | rule_idx++; | |
5635 | ||
d0e18f83 LR |
5636 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5637 | r = -EINVAL; | |
b2e1b302 | 5638 | goto bad_reg; |
d0e18f83 | 5639 | } |
b2e1b302 LR |
5640 | } |
5641 | ||
b2e1b302 | 5642 | r = set_regdom(rd); |
6913b49a | 5643 | /* set_regdom took ownership */ |
1a919318 | 5644 | rd = NULL; |
b2e1b302 | 5645 | |
d2372b31 | 5646 | bad_reg: |
b2e1b302 | 5647 | kfree(rd); |
d0e18f83 | 5648 | return r; |
b2e1b302 LR |
5649 | } |
5650 | ||
83f5e2cf JB |
5651 | static int validate_scan_freqs(struct nlattr *freqs) |
5652 | { | |
5653 | struct nlattr *attr1, *attr2; | |
5654 | int n_channels = 0, tmp1, tmp2; | |
5655 | ||
5656 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5657 | n_channels++; | |
5658 | /* | |
5659 | * Some hardware has a limited channel list for | |
5660 | * scanning, and it is pretty much nonsensical | |
5661 | * to scan for a channel twice, so disallow that | |
5662 | * and don't require drivers to check that the | |
5663 | * channel list they get isn't longer than what | |
5664 | * they can scan, as long as they can scan all | |
5665 | * the channels they registered at once. | |
5666 | */ | |
5667 | nla_for_each_nested(attr2, freqs, tmp2) | |
5668 | if (attr1 != attr2 && | |
5669 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5670 | return 0; | |
5671 | } | |
5672 | ||
5673 | return n_channels; | |
5674 | } | |
5675 | ||
ad2b26ab JB |
5676 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
5677 | u8 *mac_addr, u8 *mac_addr_mask) | |
5678 | { | |
5679 | int i; | |
5680 | ||
5681 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { | |
5682 | memset(mac_addr, 0, ETH_ALEN); | |
5683 | memset(mac_addr_mask, 0, ETH_ALEN); | |
5684 | mac_addr[0] = 0x2; | |
5685 | mac_addr_mask[0] = 0x3; | |
5686 | ||
5687 | return 0; | |
5688 | } | |
5689 | ||
5690 | /* need both or none */ | |
5691 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) | |
5692 | return -EINVAL; | |
5693 | ||
5694 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); | |
5695 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); | |
5696 | ||
5697 | /* don't allow or configure an mcast address */ | |
5698 | if (!is_multicast_ether_addr(mac_addr_mask) || | |
5699 | is_multicast_ether_addr(mac_addr)) | |
5700 | return -EINVAL; | |
5701 | ||
5702 | /* | |
5703 | * allow users to pass a MAC address that has bits set outside | |
5704 | * of the mask, but don't bother drivers with having to deal | |
5705 | * with such bits | |
5706 | */ | |
5707 | for (i = 0; i < ETH_ALEN; i++) | |
5708 | mac_addr[i] &= mac_addr_mask[i]; | |
5709 | ||
5710 | return 0; | |
5711 | } | |
5712 | ||
2a519311 JB |
5713 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5714 | { | |
4c476991 | 5715 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5716 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5717 | struct cfg80211_scan_request *request; |
2a519311 JB |
5718 | struct nlattr *attr; |
5719 | struct wiphy *wiphy; | |
83f5e2cf | 5720 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5721 | size_t ie_len; |
2a519311 | 5722 | |
f4a11bb0 JB |
5723 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5724 | return -EINVAL; | |
5725 | ||
79c97e97 | 5726 | wiphy = &rdev->wiphy; |
2a519311 | 5727 | |
4c476991 JB |
5728 | if (!rdev->ops->scan) |
5729 | return -EOPNOTSUPP; | |
2a519311 | 5730 | |
f9d15d16 | 5731 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
5732 | err = -EBUSY; |
5733 | goto unlock; | |
5734 | } | |
2a519311 JB |
5735 | |
5736 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5737 | n_channels = validate_scan_freqs( |
5738 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5739 | if (!n_channels) { |
5740 | err = -EINVAL; | |
5741 | goto unlock; | |
5742 | } | |
2a519311 | 5743 | } else { |
bdfbec2d | 5744 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
5745 | } |
5746 | ||
5747 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5748 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5749 | n_ssids++; | |
5750 | ||
f9f47529 JB |
5751 | if (n_ssids > wiphy->max_scan_ssids) { |
5752 | err = -EINVAL; | |
5753 | goto unlock; | |
5754 | } | |
2a519311 | 5755 | |
70692ad2 JM |
5756 | if (info->attrs[NL80211_ATTR_IE]) |
5757 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5758 | else | |
5759 | ie_len = 0; | |
5760 | ||
f9f47529 JB |
5761 | if (ie_len > wiphy->max_scan_ie_len) { |
5762 | err = -EINVAL; | |
5763 | goto unlock; | |
5764 | } | |
18a83659 | 5765 | |
2a519311 | 5766 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5767 | + sizeof(*request->ssids) * n_ssids |
5768 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5769 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5770 | if (!request) { |
5771 | err = -ENOMEM; | |
5772 | goto unlock; | |
5773 | } | |
2a519311 | 5774 | |
2a519311 | 5775 | if (n_ssids) |
5ba63533 | 5776 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5777 | request->n_ssids = n_ssids; |
70692ad2 JM |
5778 | if (ie_len) { |
5779 | if (request->ssids) | |
5780 | request->ie = (void *)(request->ssids + n_ssids); | |
5781 | else | |
5782 | request->ie = (void *)(request->channels + n_channels); | |
5783 | } | |
2a519311 | 5784 | |
584991dc | 5785 | i = 0; |
2a519311 JB |
5786 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5787 | /* user specified, bail out if channel not found */ | |
2a519311 | 5788 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5789 | struct ieee80211_channel *chan; |
5790 | ||
5791 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5792 | ||
5793 | if (!chan) { | |
2a519311 JB |
5794 | err = -EINVAL; |
5795 | goto out_free; | |
5796 | } | |
584991dc JB |
5797 | |
5798 | /* ignore disabled channels */ | |
5799 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5800 | continue; | |
5801 | ||
5802 | request->channels[i] = chan; | |
2a519311 JB |
5803 | i++; |
5804 | } | |
5805 | } else { | |
34850ab2 JB |
5806 | enum ieee80211_band band; |
5807 | ||
2a519311 | 5808 | /* all channels */ |
2a519311 JB |
5809 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5810 | int j; | |
5811 | if (!wiphy->bands[band]) | |
5812 | continue; | |
5813 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5814 | struct ieee80211_channel *chan; |
5815 | ||
5816 | chan = &wiphy->bands[band]->channels[j]; | |
5817 | ||
5818 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5819 | continue; | |
5820 | ||
5821 | request->channels[i] = chan; | |
2a519311 JB |
5822 | i++; |
5823 | } | |
5824 | } | |
5825 | } | |
5826 | ||
584991dc JB |
5827 | if (!i) { |
5828 | err = -EINVAL; | |
5829 | goto out_free; | |
5830 | } | |
5831 | ||
5832 | request->n_channels = i; | |
5833 | ||
2a519311 JB |
5834 | i = 0; |
5835 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5836 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5837 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5838 | err = -EINVAL; |
5839 | goto out_free; | |
5840 | } | |
57a27e1d | 5841 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5842 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5843 | i++; |
5844 | } | |
5845 | } | |
5846 | ||
70692ad2 JM |
5847 | if (info->attrs[NL80211_ATTR_IE]) { |
5848 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5849 | memcpy((void *)request->ie, |
5850 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5851 | request->ie_len); |
5852 | } | |
5853 | ||
34850ab2 | 5854 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5855 | if (wiphy->bands[i]) |
5856 | request->rates[i] = | |
5857 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5858 | |
5859 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5860 | nla_for_each_nested(attr, | |
5861 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5862 | tmp) { | |
5863 | enum ieee80211_band band = nla_type(attr); | |
5864 | ||
84404623 | 5865 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5866 | err = -EINVAL; |
5867 | goto out_free; | |
5868 | } | |
1b09cd82 FF |
5869 | |
5870 | if (!wiphy->bands[band]) | |
5871 | continue; | |
5872 | ||
34850ab2 JB |
5873 | err = ieee80211_get_ratemask(wiphy->bands[band], |
5874 | nla_data(attr), | |
5875 | nla_len(attr), | |
5876 | &request->rates[band]); | |
5877 | if (err) | |
5878 | goto out_free; | |
5879 | } | |
5880 | } | |
5881 | ||
46856bbf | 5882 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5883 | request->flags = nla_get_u32( |
5884 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5885 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5886 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5887 | err = -EOPNOTSUPP; |
5888 | goto out_free; | |
5889 | } | |
ad2b26ab JB |
5890 | |
5891 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
5892 | if (!(wiphy->features & | |
5893 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { | |
5894 | err = -EOPNOTSUPP; | |
5895 | goto out_free; | |
5896 | } | |
5897 | ||
5898 | if (wdev->current_bss) { | |
5899 | err = -EOPNOTSUPP; | |
5900 | goto out_free; | |
5901 | } | |
5902 | ||
5903 | err = nl80211_parse_random_mac(info->attrs, | |
5904 | request->mac_addr, | |
5905 | request->mac_addr_mask); | |
5906 | if (err) | |
5907 | goto out_free; | |
5908 | } | |
46856bbf | 5909 | } |
ed473771 | 5910 | |
e9f935e3 RM |
5911 | request->no_cck = |
5912 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5913 | ||
fd014284 | 5914 | request->wdev = wdev; |
79c97e97 | 5915 | request->wiphy = &rdev->wiphy; |
15d6030b | 5916 | request->scan_start = jiffies; |
2a519311 | 5917 | |
79c97e97 | 5918 | rdev->scan_req = request; |
e35e4d28 | 5919 | err = rdev_scan(rdev, request); |
2a519311 | 5920 | |
463d0183 | 5921 | if (!err) { |
fd014284 JB |
5922 | nl80211_send_scan_start(rdev, wdev); |
5923 | if (wdev->netdev) | |
5924 | dev_hold(wdev->netdev); | |
4c476991 | 5925 | } else { |
2a519311 | 5926 | out_free: |
79c97e97 | 5927 | rdev->scan_req = NULL; |
2a519311 JB |
5928 | kfree(request); |
5929 | } | |
3b85875a | 5930 | |
f9f47529 | 5931 | unlock: |
2a519311 JB |
5932 | return err; |
5933 | } | |
5934 | ||
256da02d | 5935 | static struct cfg80211_sched_scan_request * |
ad2b26ab | 5936 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
256da02d | 5937 | struct nlattr **attrs) |
807f8a8c LC |
5938 | { |
5939 | struct cfg80211_sched_scan_request *request; | |
807f8a8c | 5940 | struct nlattr *attr; |
a1f1c21c | 5941 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5942 | u32 interval; |
807f8a8c LC |
5943 | enum ieee80211_band band; |
5944 | size_t ie_len; | |
a1f1c21c | 5945 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 5946 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c | 5947 | |
256da02d LC |
5948 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
5949 | return ERR_PTR(-EINVAL); | |
807f8a8c | 5950 | |
256da02d LC |
5951 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5952 | return ERR_PTR(-EINVAL); | |
bbe6ad6d | 5953 | |
256da02d | 5954 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
bbe6ad6d | 5955 | if (interval == 0) |
256da02d | 5956 | return ERR_PTR(-EINVAL); |
807f8a8c | 5957 | |
256da02d | 5958 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c | 5959 | n_channels = validate_scan_freqs( |
256da02d | 5960 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
807f8a8c | 5961 | if (!n_channels) |
256da02d | 5962 | return ERR_PTR(-EINVAL); |
807f8a8c | 5963 | } else { |
bdfbec2d | 5964 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
5965 | } |
5966 | ||
256da02d LC |
5967 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
5968 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c LC |
5969 | tmp) |
5970 | n_ssids++; | |
5971 | ||
93b6aa69 | 5972 | if (n_ssids > wiphy->max_sched_scan_ssids) |
256da02d | 5973 | return ERR_PTR(-EINVAL); |
807f8a8c | 5974 | |
ea73cbce JB |
5975 | /* |
5976 | * First, count the number of 'real' matchsets. Due to an issue with | |
5977 | * the old implementation, matchsets containing only the RSSI attribute | |
5978 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
5979 | * RSSI for all matchsets, rather than their own matchset for reporting | |
5980 | * all APs with a strong RSSI. This is needed to be compatible with | |
5981 | * older userspace that treated a matchset with only the RSSI as the | |
5982 | * global RSSI for all other matchsets - if there are other matchsets. | |
5983 | */ | |
256da02d | 5984 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 5985 | nla_for_each_nested(attr, |
256da02d | 5986 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
ea73cbce JB |
5987 | tmp) { |
5988 | struct nlattr *rssi; | |
5989 | ||
5990 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5991 | nla_data(attr), nla_len(attr), | |
5992 | nl80211_match_policy); | |
5993 | if (err) | |
256da02d | 5994 | return ERR_PTR(err); |
ea73cbce JB |
5995 | /* add other standalone attributes here */ |
5996 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | |
5997 | n_match_sets++; | |
5998 | continue; | |
5999 | } | |
6000 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6001 | if (rssi) | |
6002 | default_match_rssi = nla_get_s32(rssi); | |
6003 | } | |
6004 | } | |
6005 | ||
6006 | /* However, if there's no other matchset, add the RSSI one */ | |
6007 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
6008 | n_match_sets = 1; | |
a1f1c21c LC |
6009 | |
6010 | if (n_match_sets > wiphy->max_match_sets) | |
256da02d | 6011 | return ERR_PTR(-EINVAL); |
a1f1c21c | 6012 | |
256da02d LC |
6013 | if (attrs[NL80211_ATTR_IE]) |
6014 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); | |
807f8a8c LC |
6015 | else |
6016 | ie_len = 0; | |
6017 | ||
5a865bad | 6018 | if (ie_len > wiphy->max_sched_scan_ie_len) |
256da02d | 6019 | return ERR_PTR(-EINVAL); |
c10841ca | 6020 | |
807f8a8c | 6021 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 6022 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 6023 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 6024 | + sizeof(*request->channels) * n_channels |
807f8a8c | 6025 | + ie_len, GFP_KERNEL); |
256da02d LC |
6026 | if (!request) |
6027 | return ERR_PTR(-ENOMEM); | |
807f8a8c LC |
6028 | |
6029 | if (n_ssids) | |
6030 | request->ssids = (void *)&request->channels[n_channels]; | |
6031 | request->n_ssids = n_ssids; | |
6032 | if (ie_len) { | |
6033 | if (request->ssids) | |
6034 | request->ie = (void *)(request->ssids + n_ssids); | |
6035 | else | |
6036 | request->ie = (void *)(request->channels + n_channels); | |
6037 | } | |
6038 | ||
a1f1c21c LC |
6039 | if (n_match_sets) { |
6040 | if (request->ie) | |
6041 | request->match_sets = (void *)(request->ie + ie_len); | |
6042 | else if (request->ssids) | |
6043 | request->match_sets = | |
6044 | (void *)(request->ssids + n_ssids); | |
6045 | else | |
6046 | request->match_sets = | |
6047 | (void *)(request->channels + n_channels); | |
6048 | } | |
6049 | request->n_match_sets = n_match_sets; | |
6050 | ||
807f8a8c | 6051 | i = 0; |
256da02d | 6052 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c LC |
6053 | /* user specified, bail out if channel not found */ |
6054 | nla_for_each_nested(attr, | |
256da02d | 6055 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
807f8a8c LC |
6056 | tmp) { |
6057 | struct ieee80211_channel *chan; | |
6058 | ||
6059 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
6060 | ||
6061 | if (!chan) { | |
6062 | err = -EINVAL; | |
6063 | goto out_free; | |
6064 | } | |
6065 | ||
6066 | /* ignore disabled channels */ | |
6067 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6068 | continue; | |
6069 | ||
6070 | request->channels[i] = chan; | |
6071 | i++; | |
6072 | } | |
6073 | } else { | |
6074 | /* all channels */ | |
6075 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6076 | int j; | |
6077 | if (!wiphy->bands[band]) | |
6078 | continue; | |
6079 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
6080 | struct ieee80211_channel *chan; | |
6081 | ||
6082 | chan = &wiphy->bands[band]->channels[j]; | |
6083 | ||
6084 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6085 | continue; | |
6086 | ||
6087 | request->channels[i] = chan; | |
6088 | i++; | |
6089 | } | |
6090 | } | |
6091 | } | |
6092 | ||
6093 | if (!i) { | |
6094 | err = -EINVAL; | |
6095 | goto out_free; | |
6096 | } | |
6097 | ||
6098 | request->n_channels = i; | |
6099 | ||
6100 | i = 0; | |
256da02d LC |
6101 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) { |
6102 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c | 6103 | tmp) { |
57a27e1d | 6104 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
6105 | err = -EINVAL; |
6106 | goto out_free; | |
6107 | } | |
57a27e1d | 6108 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
6109 | memcpy(request->ssids[i].ssid, nla_data(attr), |
6110 | nla_len(attr)); | |
807f8a8c LC |
6111 | i++; |
6112 | } | |
6113 | } | |
6114 | ||
a1f1c21c | 6115 | i = 0; |
256da02d | 6116 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 6117 | nla_for_each_nested(attr, |
256da02d | 6118 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
a1f1c21c | 6119 | tmp) { |
88e920b4 | 6120 | struct nlattr *ssid, *rssi; |
a1f1c21c | 6121 | |
ae811e21 JB |
6122 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
6123 | nla_data(attr), nla_len(attr), | |
6124 | nl80211_match_policy); | |
6125 | if (err) | |
6126 | goto out_free; | |
4a4ab0d7 | 6127 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 6128 | if (ssid) { |
ea73cbce JB |
6129 | if (WARN_ON(i >= n_match_sets)) { |
6130 | /* this indicates a programming error, | |
6131 | * the loop above should have verified | |
6132 | * things properly | |
6133 | */ | |
6134 | err = -EINVAL; | |
6135 | goto out_free; | |
6136 | } | |
6137 | ||
a1f1c21c LC |
6138 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
6139 | err = -EINVAL; | |
6140 | goto out_free; | |
6141 | } | |
6142 | memcpy(request->match_sets[i].ssid.ssid, | |
6143 | nla_data(ssid), nla_len(ssid)); | |
6144 | request->match_sets[i].ssid.ssid_len = | |
6145 | nla_len(ssid); | |
ea73cbce JB |
6146 | /* special attribute - old implemenation w/a */ |
6147 | request->match_sets[i].rssi_thold = | |
6148 | default_match_rssi; | |
6149 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6150 | if (rssi) | |
6151 | request->match_sets[i].rssi_thold = | |
6152 | nla_get_s32(rssi); | |
a1f1c21c LC |
6153 | } |
6154 | i++; | |
6155 | } | |
ea73cbce JB |
6156 | |
6157 | /* there was no other matchset, so the RSSI one is alone */ | |
f89f46cf | 6158 | if (i == 0 && n_match_sets) |
ea73cbce JB |
6159 | request->match_sets[0].rssi_thold = default_match_rssi; |
6160 | ||
6161 | request->min_rssi_thold = INT_MAX; | |
6162 | for (i = 0; i < n_match_sets; i++) | |
6163 | request->min_rssi_thold = | |
6164 | min(request->match_sets[i].rssi_thold, | |
6165 | request->min_rssi_thold); | |
6166 | } else { | |
6167 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
6168 | } |
6169 | ||
9900e484 JB |
6170 | if (ie_len) { |
6171 | request->ie_len = ie_len; | |
807f8a8c | 6172 | memcpy((void *)request->ie, |
256da02d | 6173 | nla_data(attrs[NL80211_ATTR_IE]), |
807f8a8c LC |
6174 | request->ie_len); |
6175 | } | |
6176 | ||
256da02d | 6177 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 | 6178 | request->flags = nla_get_u32( |
256da02d | 6179 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
00c3a6ed JB |
6180 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
6181 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
6182 | err = -EOPNOTSUPP; |
6183 | goto out_free; | |
6184 | } | |
ad2b26ab JB |
6185 | |
6186 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
6187 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; | |
6188 | ||
6189 | if (!wdev) /* must be net-detect */ | |
6190 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
6191 | ||
6192 | if (!(wiphy->features & flg)) { | |
6193 | err = -EOPNOTSUPP; | |
6194 | goto out_free; | |
6195 | } | |
6196 | ||
6197 | if (wdev && wdev->current_bss) { | |
6198 | err = -EOPNOTSUPP; | |
6199 | goto out_free; | |
6200 | } | |
6201 | ||
6202 | err = nl80211_parse_random_mac(attrs, request->mac_addr, | |
6203 | request->mac_addr_mask); | |
6204 | if (err) | |
6205 | goto out_free; | |
6206 | } | |
46856bbf | 6207 | } |
ed473771 | 6208 | |
9c748934 LC |
6209 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
6210 | request->delay = | |
6211 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); | |
6212 | ||
bbe6ad6d | 6213 | request->interval = interval; |
15d6030b | 6214 | request->scan_start = jiffies; |
807f8a8c | 6215 | |
256da02d | 6216 | return request; |
807f8a8c LC |
6217 | |
6218 | out_free: | |
6219 | kfree(request); | |
256da02d LC |
6220 | return ERR_PTR(err); |
6221 | } | |
6222 | ||
6223 | static int nl80211_start_sched_scan(struct sk_buff *skb, | |
6224 | struct genl_info *info) | |
6225 | { | |
6226 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6227 | struct net_device *dev = info->user_ptr[1]; | |
ad2b26ab | 6228 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
31a60ed1 | 6229 | struct cfg80211_sched_scan_request *sched_scan_req; |
256da02d LC |
6230 | int err; |
6231 | ||
6232 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6233 | !rdev->ops->sched_scan_start) | |
6234 | return -EOPNOTSUPP; | |
6235 | ||
6236 | if (rdev->sched_scan_req) | |
6237 | return -EINPROGRESS; | |
6238 | ||
31a60ed1 JR |
6239 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
6240 | info->attrs); | |
6241 | ||
6242 | err = PTR_ERR_OR_ZERO(sched_scan_req); | |
256da02d LC |
6243 | if (err) |
6244 | goto out_err; | |
6245 | ||
31a60ed1 | 6246 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
256da02d LC |
6247 | if (err) |
6248 | goto out_free; | |
6249 | ||
31a60ed1 JR |
6250 | sched_scan_req->dev = dev; |
6251 | sched_scan_req->wiphy = &rdev->wiphy; | |
6252 | ||
93a1e86c JR |
6253 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
6254 | sched_scan_req->owner_nlportid = info->snd_portid; | |
6255 | ||
31a60ed1 | 6256 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
256da02d LC |
6257 | |
6258 | nl80211_send_sched_scan(rdev, dev, | |
6259 | NL80211_CMD_START_SCHED_SCAN); | |
6260 | return 0; | |
6261 | ||
6262 | out_free: | |
31a60ed1 | 6263 | kfree(sched_scan_req); |
256da02d | 6264 | out_err: |
807f8a8c LC |
6265 | return err; |
6266 | } | |
6267 | ||
6268 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
6269 | struct genl_info *info) | |
6270 | { | |
6271 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6272 | ||
6273 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6274 | !rdev->ops->sched_scan_stop) | |
6275 | return -EOPNOTSUPP; | |
6276 | ||
5fe231e8 | 6277 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
6278 | } |
6279 | ||
04f39047 SW |
6280 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
6281 | struct genl_info *info) | |
6282 | { | |
6283 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6284 | struct net_device *dev = info->user_ptr[1]; | |
6285 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6286 | struct cfg80211_chan_def chandef; | |
55f7435c | 6287 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 6288 | unsigned int cac_time_ms; |
04f39047 SW |
6289 | int err; |
6290 | ||
55f7435c LR |
6291 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
6292 | if (dfs_region == NL80211_DFS_UNSET) | |
6293 | return -EINVAL; | |
6294 | ||
04f39047 SW |
6295 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6296 | if (err) | |
6297 | return err; | |
6298 | ||
ff311bc1 SW |
6299 | if (netif_carrier_ok(dev)) |
6300 | return -EBUSY; | |
6301 | ||
04f39047 SW |
6302 | if (wdev->cac_started) |
6303 | return -EBUSY; | |
6304 | ||
2beb6dab | 6305 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
00ec75fc | 6306 | wdev->iftype); |
04f39047 SW |
6307 | if (err < 0) |
6308 | return err; | |
6309 | ||
6310 | if (err == 0) | |
6311 | return -EINVAL; | |
6312 | ||
fe7c3a1f | 6313 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
6314 | return -EINVAL; |
6315 | ||
6316 | if (!rdev->ops->start_radar_detection) | |
6317 | return -EOPNOTSUPP; | |
6318 | ||
31559f35 JD |
6319 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
6320 | if (WARN_ON(!cac_time_ms)) | |
6321 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
6322 | ||
6323 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, | |
6324 | cac_time_ms); | |
04f39047 | 6325 | if (!err) { |
9e0e2961 | 6326 | wdev->chandef = chandef; |
04f39047 SW |
6327 | wdev->cac_started = true; |
6328 | wdev->cac_start_time = jiffies; | |
31559f35 | 6329 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 6330 | } |
04f39047 SW |
6331 | return err; |
6332 | } | |
6333 | ||
16ef1fe2 SW |
6334 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
6335 | { | |
6336 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6337 | struct net_device *dev = info->user_ptr[1]; | |
6338 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6339 | struct cfg80211_csa_settings params; | |
6340 | /* csa_attrs is defined static to avoid waste of stack size - this | |
6341 | * function is called under RTNL lock, so this should not be a problem. | |
6342 | */ | |
6343 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
16ef1fe2 | 6344 | int err; |
ee4bc9e7 | 6345 | bool need_new_beacon = false; |
9a774c78 | 6346 | int len, i; |
252e07ca | 6347 | u32 cs_count; |
16ef1fe2 SW |
6348 | |
6349 | if (!rdev->ops->channel_switch || | |
6350 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
6351 | return -EOPNOTSUPP; | |
6352 | ||
ee4bc9e7 SW |
6353 | switch (dev->ieee80211_ptr->iftype) { |
6354 | case NL80211_IFTYPE_AP: | |
6355 | case NL80211_IFTYPE_P2P_GO: | |
6356 | need_new_beacon = true; | |
6357 | ||
6358 | /* useless if AP is not running */ | |
6359 | if (!wdev->beacon_interval) | |
1ff79dfa | 6360 | return -ENOTCONN; |
ee4bc9e7 SW |
6361 | break; |
6362 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
6363 | if (!wdev->ssid_len) |
6364 | return -ENOTCONN; | |
6365 | break; | |
c6da674a | 6366 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
6367 | if (!wdev->mesh_id_len) |
6368 | return -ENOTCONN; | |
ee4bc9e7 SW |
6369 | break; |
6370 | default: | |
16ef1fe2 | 6371 | return -EOPNOTSUPP; |
ee4bc9e7 | 6372 | } |
16ef1fe2 SW |
6373 | |
6374 | memset(¶ms, 0, sizeof(params)); | |
6375 | ||
6376 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6377 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
6378 | return -EINVAL; | |
6379 | ||
6380 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 6381 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
6382 | return -EINVAL; |
6383 | ||
252e07ca LC |
6384 | /* Even though the attribute is u32, the specification says |
6385 | * u8, so let's make sure we don't overflow. | |
6386 | */ | |
6387 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
6388 | if (cs_count > 255) | |
6389 | return -EINVAL; | |
6390 | ||
6391 | params.count = cs_count; | |
16ef1fe2 | 6392 | |
ee4bc9e7 SW |
6393 | if (!need_new_beacon) |
6394 | goto skip_beacons; | |
6395 | ||
16ef1fe2 SW |
6396 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
6397 | if (err) | |
6398 | return err; | |
6399 | ||
6400 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
6401 | info->attrs[NL80211_ATTR_CSA_IES], | |
6402 | nl80211_policy); | |
6403 | if (err) | |
6404 | return err; | |
6405 | ||
6406 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
6407 | if (err) | |
6408 | return err; | |
6409 | ||
6410 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
6411 | return -EINVAL; | |
6412 | ||
9a774c78 AO |
6413 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
6414 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6415 | return -EINVAL; |
6416 | ||
9a774c78 AO |
6417 | params.n_counter_offsets_beacon = len / sizeof(u16); |
6418 | if (rdev->wiphy.max_num_csa_counters && | |
6419 | (params.n_counter_offsets_beacon > | |
6420 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
6421 | return -EINVAL; |
6422 | ||
9a774c78 AO |
6423 | params.counter_offsets_beacon = |
6424 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
6425 | ||
6426 | /* sanity checks - counters should fit and be the same */ | |
6427 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
6428 | u16 offset = params.counter_offsets_beacon[i]; | |
6429 | ||
6430 | if (offset >= params.beacon_csa.tail_len) | |
6431 | return -EINVAL; | |
6432 | ||
6433 | if (params.beacon_csa.tail[offset] != params.count) | |
6434 | return -EINVAL; | |
6435 | } | |
6436 | ||
16ef1fe2 | 6437 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
6438 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
6439 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6440 | return -EINVAL; |
6441 | ||
9a774c78 AO |
6442 | params.n_counter_offsets_presp = len / sizeof(u16); |
6443 | if (rdev->wiphy.max_num_csa_counters && | |
6444 | (params.n_counter_offsets_beacon > | |
6445 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 | 6446 | return -EINVAL; |
9a774c78 AO |
6447 | |
6448 | params.counter_offsets_presp = | |
6449 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
6450 | ||
6451 | /* sanity checks - counters should fit and be the same */ | |
6452 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
6453 | u16 offset = params.counter_offsets_presp[i]; | |
6454 | ||
6455 | if (offset >= params.beacon_csa.probe_resp_len) | |
6456 | return -EINVAL; | |
6457 | ||
6458 | if (params.beacon_csa.probe_resp[offset] != | |
6459 | params.count) | |
6460 | return -EINVAL; | |
6461 | } | |
16ef1fe2 SW |
6462 | } |
6463 | ||
ee4bc9e7 | 6464 | skip_beacons: |
16ef1fe2 SW |
6465 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
6466 | if (err) | |
6467 | return err; | |
6468 | ||
174e0cd2 IP |
6469 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
6470 | wdev->iftype)) | |
16ef1fe2 SW |
6471 | return -EINVAL; |
6472 | ||
2beb6dab LC |
6473 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
6474 | ¶ms.chandef, | |
6475 | wdev->iftype); | |
6476 | if (err < 0) | |
6477 | return err; | |
6478 | ||
dcc6c2f5 | 6479 | if (err > 0) |
2beb6dab | 6480 | params.radar_required = true; |
16ef1fe2 | 6481 | |
16ef1fe2 SW |
6482 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
6483 | params.block_tx = true; | |
6484 | ||
c56589ed SW |
6485 | wdev_lock(wdev); |
6486 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
6487 | wdev_unlock(wdev); | |
6488 | ||
6489 | return err; | |
16ef1fe2 SW |
6490 | } |
6491 | ||
9720bb3a JB |
6492 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
6493 | u32 seq, int flags, | |
2a519311 | 6494 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
6495 | struct wireless_dev *wdev, |
6496 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 6497 | { |
48ab905d | 6498 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 6499 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
6500 | void *hdr; |
6501 | struct nlattr *bss; | |
48ab905d JB |
6502 | |
6503 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 6504 | |
15e47304 | 6505 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
6506 | NL80211_CMD_NEW_SCAN_RESULTS); |
6507 | if (!hdr) | |
6508 | return -1; | |
6509 | ||
9720bb3a JB |
6510 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
6511 | ||
97990a06 JB |
6512 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
6513 | goto nla_put_failure; | |
6514 | if (wdev->netdev && | |
9360ffd1 DM |
6515 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
6516 | goto nla_put_failure; | |
97990a06 JB |
6517 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
6518 | goto nla_put_failure; | |
2a519311 JB |
6519 | |
6520 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
6521 | if (!bss) | |
6522 | goto nla_put_failure; | |
9360ffd1 | 6523 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 6524 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 6525 | goto nla_put_failure; |
9caf0364 JB |
6526 | |
6527 | rcu_read_lock(); | |
0e227084 JB |
6528 | /* indicate whether we have probe response data or not */ |
6529 | if (rcu_access_pointer(res->proberesp_ies) && | |
6530 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
6531 | goto fail_unlock_rcu; | |
6532 | ||
6533 | /* this pointer prefers to be pointed to probe response data | |
6534 | * but is always valid | |
6535 | */ | |
9caf0364 | 6536 | ies = rcu_dereference(res->ies); |
8cef2c9d JB |
6537 | if (ies) { |
6538 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
6539 | goto fail_unlock_rcu; | |
8cef2c9d JB |
6540 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
6541 | ies->len, ies->data)) | |
6542 | goto fail_unlock_rcu; | |
9caf0364 | 6543 | } |
0e227084 JB |
6544 | |
6545 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 6546 | ies = rcu_dereference(res->beacon_ies); |
0e227084 JB |
6547 | if (ies && ies->from_beacon) { |
6548 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) | |
8cef2c9d JB |
6549 | goto fail_unlock_rcu; |
6550 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
6551 | ies->len, ies->data)) | |
6552 | goto fail_unlock_rcu; | |
9caf0364 JB |
6553 | } |
6554 | rcu_read_unlock(); | |
6555 | ||
9360ffd1 DM |
6556 | if (res->beacon_interval && |
6557 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
6558 | goto nla_put_failure; | |
6559 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
6560 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 6561 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
6562 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
6563 | jiffies_to_msecs(jiffies - intbss->ts))) | |
6564 | goto nla_put_failure; | |
2a519311 | 6565 | |
77965c97 | 6566 | switch (rdev->wiphy.signal_type) { |
2a519311 | 6567 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
6568 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
6569 | goto nla_put_failure; | |
2a519311 JB |
6570 | break; |
6571 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
6572 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
6573 | goto nla_put_failure; | |
2a519311 JB |
6574 | break; |
6575 | default: | |
6576 | break; | |
6577 | } | |
6578 | ||
48ab905d | 6579 | switch (wdev->iftype) { |
074ac8df | 6580 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 6581 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
6582 | if (intbss == wdev->current_bss && |
6583 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6584 | NL80211_BSS_STATUS_ASSOCIATED)) | |
6585 | goto nla_put_failure; | |
48ab905d JB |
6586 | break; |
6587 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
6588 | if (intbss == wdev->current_bss && |
6589 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6590 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
6591 | goto nla_put_failure; | |
48ab905d JB |
6592 | break; |
6593 | default: | |
6594 | break; | |
6595 | } | |
6596 | ||
2a519311 JB |
6597 | nla_nest_end(msg, bss); |
6598 | ||
6599 | return genlmsg_end(msg, hdr); | |
6600 | ||
8cef2c9d JB |
6601 | fail_unlock_rcu: |
6602 | rcu_read_unlock(); | |
2a519311 JB |
6603 | nla_put_failure: |
6604 | genlmsg_cancel(msg, hdr); | |
6605 | return -EMSGSIZE; | |
6606 | } | |
6607 | ||
97990a06 | 6608 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 6609 | { |
48ab905d | 6610 | struct cfg80211_registered_device *rdev; |
2a519311 | 6611 | struct cfg80211_internal_bss *scan; |
48ab905d | 6612 | struct wireless_dev *wdev; |
97990a06 | 6613 | int start = cb->args[2], idx = 0; |
2a519311 JB |
6614 | int err; |
6615 | ||
97990a06 | 6616 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6617 | if (err) |
6618 | return err; | |
2a519311 | 6619 | |
48ab905d JB |
6620 | wdev_lock(wdev); |
6621 | spin_lock_bh(&rdev->bss_lock); | |
6622 | cfg80211_bss_expire(rdev); | |
6623 | ||
9720bb3a JB |
6624 | cb->seq = rdev->bss_generation; |
6625 | ||
48ab905d | 6626 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
6627 | if (++idx <= start) |
6628 | continue; | |
9720bb3a | 6629 | if (nl80211_send_bss(skb, cb, |
2a519311 | 6630 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 6631 | rdev, wdev, scan) < 0) { |
2a519311 | 6632 | idx--; |
67748893 | 6633 | break; |
2a519311 JB |
6634 | } |
6635 | } | |
6636 | ||
48ab905d JB |
6637 | spin_unlock_bh(&rdev->bss_lock); |
6638 | wdev_unlock(wdev); | |
2a519311 | 6639 | |
97990a06 JB |
6640 | cb->args[2] = idx; |
6641 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 6642 | |
67748893 | 6643 | return skb->len; |
2a519311 JB |
6644 | } |
6645 | ||
15e47304 | 6646 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
11f78ac3 JB |
6647 | int flags, struct net_device *dev, |
6648 | bool allow_radio_stats, | |
6649 | struct survey_info *survey) | |
61fa713c HS |
6650 | { |
6651 | void *hdr; | |
6652 | struct nlattr *infoattr; | |
6653 | ||
11f78ac3 JB |
6654 | /* skip radio stats if userspace didn't request them */ |
6655 | if (!survey->channel && !allow_radio_stats) | |
6656 | return 0; | |
6657 | ||
15e47304 | 6658 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
6659 | NL80211_CMD_NEW_SURVEY_RESULTS); |
6660 | if (!hdr) | |
6661 | return -ENOMEM; | |
6662 | ||
9360ffd1 DM |
6663 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
6664 | goto nla_put_failure; | |
61fa713c HS |
6665 | |
6666 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
6667 | if (!infoattr) | |
6668 | goto nla_put_failure; | |
6669 | ||
11f78ac3 JB |
6670 | if (survey->channel && |
6671 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
9360ffd1 DM |
6672 | survey->channel->center_freq)) |
6673 | goto nla_put_failure; | |
6674 | ||
6675 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
6676 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
6677 | goto nla_put_failure; | |
6678 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
6679 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
6680 | goto nla_put_failure; | |
4ed20beb JB |
6681 | if ((survey->filled & SURVEY_INFO_TIME) && |
6682 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME, | |
6683 | survey->time)) | |
9360ffd1 | 6684 | goto nla_put_failure; |
4ed20beb JB |
6685 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
6686 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY, | |
6687 | survey->time_busy)) | |
9360ffd1 | 6688 | goto nla_put_failure; |
4ed20beb JB |
6689 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
6690 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, | |
6691 | survey->time_ext_busy)) | |
9360ffd1 | 6692 | goto nla_put_failure; |
4ed20beb JB |
6693 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
6694 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX, | |
6695 | survey->time_rx)) | |
9360ffd1 | 6696 | goto nla_put_failure; |
4ed20beb JB |
6697 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
6698 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX, | |
6699 | survey->time_tx)) | |
9360ffd1 | 6700 | goto nla_put_failure; |
052536ab JB |
6701 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
6702 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN, | |
6703 | survey->time_scan)) | |
6704 | goto nla_put_failure; | |
61fa713c HS |
6705 | |
6706 | nla_nest_end(msg, infoattr); | |
6707 | ||
6708 | return genlmsg_end(msg, hdr); | |
6709 | ||
6710 | nla_put_failure: | |
6711 | genlmsg_cancel(msg, hdr); | |
6712 | return -EMSGSIZE; | |
6713 | } | |
6714 | ||
11f78ac3 | 6715 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
61fa713c HS |
6716 | { |
6717 | struct survey_info survey; | |
1b8ec87a | 6718 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
6719 | struct wireless_dev *wdev; |
6720 | int survey_idx = cb->args[2]; | |
61fa713c | 6721 | int res; |
11f78ac3 | 6722 | bool radio_stats; |
61fa713c | 6723 | |
1b8ec87a | 6724 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6725 | if (res) |
6726 | return res; | |
61fa713c | 6727 | |
11f78ac3 JB |
6728 | /* prepare_wdev_dump parsed the attributes */ |
6729 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; | |
6730 | ||
97990a06 JB |
6731 | if (!wdev->netdev) { |
6732 | res = -EINVAL; | |
6733 | goto out_err; | |
6734 | } | |
6735 | ||
1b8ec87a | 6736 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
6737 | res = -EOPNOTSUPP; |
6738 | goto out_err; | |
6739 | } | |
6740 | ||
6741 | while (1) { | |
1b8ec87a | 6742 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
6743 | if (res == -ENOENT) |
6744 | break; | |
6745 | if (res) | |
6746 | goto out_err; | |
6747 | ||
11f78ac3 JB |
6748 | /* don't send disabled channels, but do send non-channel data */ |
6749 | if (survey.channel && | |
6750 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { | |
180cdc79 LR |
6751 | survey_idx++; |
6752 | continue; | |
6753 | } | |
6754 | ||
61fa713c | 6755 | if (nl80211_send_survey(skb, |
15e47304 | 6756 | NETLINK_CB(cb->skb).portid, |
61fa713c | 6757 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
11f78ac3 | 6758 | wdev->netdev, radio_stats, &survey) < 0) |
61fa713c HS |
6759 | goto out; |
6760 | survey_idx++; | |
6761 | } | |
6762 | ||
6763 | out: | |
97990a06 | 6764 | cb->args[2] = survey_idx; |
61fa713c HS |
6765 | res = skb->len; |
6766 | out_err: | |
1b8ec87a | 6767 | nl80211_finish_wdev_dump(rdev); |
61fa713c HS |
6768 | return res; |
6769 | } | |
6770 | ||
b23aa676 SO |
6771 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
6772 | { | |
6773 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
6774 | NL80211_WPA_VERSION_2)); | |
6775 | } | |
6776 | ||
636a5d36 JM |
6777 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
6778 | { | |
4c476991 JB |
6779 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6780 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6781 | struct ieee80211_channel *chan; |
e39e5b5e JM |
6782 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
6783 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 6784 | enum nl80211_auth_type auth_type; |
fffd0934 | 6785 | struct key_parse key; |
d5cdfacb | 6786 | bool local_state_change; |
636a5d36 | 6787 | |
f4a11bb0 JB |
6788 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6789 | return -EINVAL; | |
6790 | ||
6791 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6792 | return -EINVAL; | |
6793 | ||
1778092e JM |
6794 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
6795 | return -EINVAL; | |
6796 | ||
19957bb3 JB |
6797 | if (!info->attrs[NL80211_ATTR_SSID]) |
6798 | return -EINVAL; | |
6799 | ||
6800 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
6801 | return -EINVAL; | |
6802 | ||
fffd0934 JB |
6803 | err = nl80211_parse_key(info, &key); |
6804 | if (err) | |
6805 | return err; | |
6806 | ||
6807 | if (key.idx >= 0) { | |
e31b8213 JB |
6808 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
6809 | return -EINVAL; | |
fffd0934 JB |
6810 | if (!key.p.key || !key.p.key_len) |
6811 | return -EINVAL; | |
6812 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
6813 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
6814 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
6815 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
6816 | return -EINVAL; | |
6817 | if (key.idx > 4) | |
6818 | return -EINVAL; | |
6819 | } else { | |
6820 | key.p.key_len = 0; | |
6821 | key.p.key = NULL; | |
6822 | } | |
6823 | ||
afea0b7a JB |
6824 | if (key.idx >= 0) { |
6825 | int i; | |
6826 | bool ok = false; | |
6827 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
6828 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
6829 | ok = true; | |
6830 | break; | |
6831 | } | |
6832 | } | |
4c476991 JB |
6833 | if (!ok) |
6834 | return -EINVAL; | |
afea0b7a JB |
6835 | } |
6836 | ||
4c476991 JB |
6837 | if (!rdev->ops->auth) |
6838 | return -EOPNOTSUPP; | |
636a5d36 | 6839 | |
074ac8df | 6840 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6841 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6842 | return -EOPNOTSUPP; | |
eec60b03 | 6843 | |
19957bb3 | 6844 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
6845 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6846 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6847 | if (!chan) | |
4c476991 | 6848 | return -EINVAL; |
636a5d36 | 6849 | |
19957bb3 JB |
6850 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6851 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6852 | |
6853 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6854 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6855 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6856 | } |
6857 | ||
19957bb3 | 6858 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 6859 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 6860 | return -EINVAL; |
636a5d36 | 6861 | |
e39e5b5e JM |
6862 | if (auth_type == NL80211_AUTHTYPE_SAE && |
6863 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
6864 | return -EINVAL; | |
6865 | ||
6866 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
6867 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
6868 | return -EINVAL; | |
6869 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6870 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6871 | /* need to include at least Auth Transaction and Status Code */ | |
6872 | if (sae_data_len < 4) | |
6873 | return -EINVAL; | |
6874 | } | |
6875 | ||
d5cdfacb JM |
6876 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6877 | ||
95de817b JB |
6878 | /* |
6879 | * Since we no longer track auth state, ignore | |
6880 | * requests to only change local state. | |
6881 | */ | |
6882 | if (local_state_change) | |
6883 | return 0; | |
6884 | ||
91bf9b26 JB |
6885 | wdev_lock(dev->ieee80211_ptr); |
6886 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
6887 | ssid, ssid_len, ie, ie_len, | |
6888 | key.p.key, key.p.key_len, key.idx, | |
6889 | sae_data, sae_data_len); | |
6890 | wdev_unlock(dev->ieee80211_ptr); | |
6891 | return err; | |
636a5d36 JM |
6892 | } |
6893 | ||
c0692b8f JB |
6894 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6895 | struct genl_info *info, | |
3dc27d25 JB |
6896 | struct cfg80211_crypto_settings *settings, |
6897 | int cipher_limit) | |
b23aa676 | 6898 | { |
c0b2bbd8 JB |
6899 | memset(settings, 0, sizeof(*settings)); |
6900 | ||
b23aa676 SO |
6901 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6902 | ||
c0692b8f JB |
6903 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6904 | u16 proto; | |
6905 | proto = nla_get_u16( | |
6906 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6907 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6908 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6909 | proto != ETH_P_PAE) | |
6910 | return -EINVAL; | |
6911 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6912 | settings->control_port_no_encrypt = true; | |
6913 | } else | |
6914 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6915 | ||
b23aa676 SO |
6916 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6917 | void *data; | |
6918 | int len, i; | |
6919 | ||
6920 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6921 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6922 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6923 | ||
6924 | if (len % sizeof(u32)) | |
6925 | return -EINVAL; | |
6926 | ||
3dc27d25 | 6927 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6928 | return -EINVAL; |
6929 | ||
6930 | memcpy(settings->ciphers_pairwise, data, len); | |
6931 | ||
6932 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6933 | if (!cfg80211_supported_cipher_suite( |
6934 | &rdev->wiphy, | |
b23aa676 SO |
6935 | settings->ciphers_pairwise[i])) |
6936 | return -EINVAL; | |
6937 | } | |
6938 | ||
6939 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6940 | settings->cipher_group = | |
6941 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6942 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6943 | settings->cipher_group)) | |
b23aa676 SO |
6944 | return -EINVAL; |
6945 | } | |
6946 | ||
6947 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6948 | settings->wpa_versions = | |
6949 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6950 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6951 | return -EINVAL; | |
6952 | } | |
6953 | ||
6954 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6955 | void *data; | |
6d30240e | 6956 | int len; |
b23aa676 SO |
6957 | |
6958 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6959 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6960 | settings->n_akm_suites = len / sizeof(u32); | |
6961 | ||
6962 | if (len % sizeof(u32)) | |
6963 | return -EINVAL; | |
6964 | ||
1b9ca027 JM |
6965 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6966 | return -EINVAL; | |
6967 | ||
b23aa676 | 6968 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6969 | } |
6970 | ||
6971 | return 0; | |
6972 | } | |
6973 | ||
636a5d36 JM |
6974 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6975 | { | |
4c476991 JB |
6976 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6977 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6978 | struct ieee80211_channel *chan; |
f62fab73 JB |
6979 | struct cfg80211_assoc_request req = {}; |
6980 | const u8 *bssid, *ssid; | |
6981 | int err, ssid_len = 0; | |
636a5d36 | 6982 | |
f4a11bb0 JB |
6983 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6984 | return -EINVAL; | |
6985 | ||
6986 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6987 | !info->attrs[NL80211_ATTR_SSID] || |
6988 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6989 | return -EINVAL; |
6990 | ||
4c476991 JB |
6991 | if (!rdev->ops->assoc) |
6992 | return -EOPNOTSUPP; | |
636a5d36 | 6993 | |
074ac8df | 6994 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6995 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6996 | return -EOPNOTSUPP; | |
eec60b03 | 6997 | |
19957bb3 | 6998 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6999 | |
664834de JM |
7000 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
7001 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7002 | if (!chan) | |
4c476991 | 7003 | return -EINVAL; |
636a5d36 | 7004 | |
19957bb3 JB |
7005 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7006 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
7007 | |
7008 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
7009 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7010 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7011 | } |
7012 | ||
dc6382ce | 7013 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 7014 | enum nl80211_mfp mfp = |
dc6382ce | 7015 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 7016 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 7017 | req.use_mfp = true; |
4c476991 JB |
7018 | else if (mfp != NL80211_MFP_NO) |
7019 | return -EINVAL; | |
dc6382ce JM |
7020 | } |
7021 | ||
3e5d7649 | 7022 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 7023 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 7024 | |
7e7c8926 | 7025 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 7026 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
7027 | |
7028 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
7029 | memcpy(&req.ht_capa_mask, |
7030 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7031 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
7032 | |
7033 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 7034 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 7035 | return -EINVAL; |
f62fab73 JB |
7036 | memcpy(&req.ht_capa, |
7037 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7038 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
7039 | } |
7040 | ||
ee2aca34 | 7041 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 7042 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
7043 | |
7044 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
7045 | memcpy(&req.vht_capa_mask, |
7046 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7047 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
7048 | |
7049 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 7050 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 7051 | return -EINVAL; |
f62fab73 JB |
7052 | memcpy(&req.vht_capa, |
7053 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7054 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
7055 | } |
7056 | ||
bab5ab7d AK |
7057 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7058 | if (!(rdev->wiphy.features & | |
7059 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7060 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7061 | return -EINVAL; | |
7062 | req.flags |= ASSOC_REQ_USE_RRM; | |
7063 | } | |
7064 | ||
f62fab73 | 7065 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
7066 | if (!err) { |
7067 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
7068 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
7069 | ssid, ssid_len, &req); | |
91bf9b26 JB |
7070 | wdev_unlock(dev->ieee80211_ptr); |
7071 | } | |
636a5d36 | 7072 | |
636a5d36 JM |
7073 | return err; |
7074 | } | |
7075 | ||
7076 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
7077 | { | |
4c476991 JB |
7078 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7079 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7080 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7081 | int ie_len = 0, err; |
19957bb3 | 7082 | u16 reason_code; |
d5cdfacb | 7083 | bool local_state_change; |
636a5d36 | 7084 | |
f4a11bb0 JB |
7085 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7086 | return -EINVAL; | |
7087 | ||
7088 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7089 | return -EINVAL; | |
7090 | ||
7091 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7092 | return -EINVAL; | |
7093 | ||
4c476991 JB |
7094 | if (!rdev->ops->deauth) |
7095 | return -EOPNOTSUPP; | |
636a5d36 | 7096 | |
074ac8df | 7097 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7098 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7099 | return -EOPNOTSUPP; | |
eec60b03 | 7100 | |
19957bb3 | 7101 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7102 | |
19957bb3 JB |
7103 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7104 | if (reason_code == 0) { | |
f4a11bb0 | 7105 | /* Reason Code 0 is reserved */ |
4c476991 | 7106 | return -EINVAL; |
255e737e | 7107 | } |
636a5d36 JM |
7108 | |
7109 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7110 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7111 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7112 | } |
7113 | ||
d5cdfacb JM |
7114 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7115 | ||
91bf9b26 JB |
7116 | wdev_lock(dev->ieee80211_ptr); |
7117 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
7118 | local_state_change); | |
7119 | wdev_unlock(dev->ieee80211_ptr); | |
7120 | return err; | |
636a5d36 JM |
7121 | } |
7122 | ||
7123 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
7124 | { | |
4c476991 JB |
7125 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7126 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7127 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7128 | int ie_len = 0, err; |
19957bb3 | 7129 | u16 reason_code; |
d5cdfacb | 7130 | bool local_state_change; |
636a5d36 | 7131 | |
f4a11bb0 JB |
7132 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7133 | return -EINVAL; | |
7134 | ||
7135 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7136 | return -EINVAL; | |
7137 | ||
7138 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7139 | return -EINVAL; | |
7140 | ||
4c476991 JB |
7141 | if (!rdev->ops->disassoc) |
7142 | return -EOPNOTSUPP; | |
636a5d36 | 7143 | |
074ac8df | 7144 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7145 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7146 | return -EOPNOTSUPP; | |
eec60b03 | 7147 | |
19957bb3 | 7148 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7149 | |
19957bb3 JB |
7150 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7151 | if (reason_code == 0) { | |
f4a11bb0 | 7152 | /* Reason Code 0 is reserved */ |
4c476991 | 7153 | return -EINVAL; |
255e737e | 7154 | } |
636a5d36 JM |
7155 | |
7156 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7157 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7158 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7159 | } |
7160 | ||
d5cdfacb JM |
7161 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7162 | ||
91bf9b26 JB |
7163 | wdev_lock(dev->ieee80211_ptr); |
7164 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
7165 | local_state_change); | |
7166 | wdev_unlock(dev->ieee80211_ptr); | |
7167 | return err; | |
636a5d36 JM |
7168 | } |
7169 | ||
dd5b4cc7 FF |
7170 | static bool |
7171 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
7172 | int mcast_rate[IEEE80211_NUM_BANDS], | |
7173 | int rateval) | |
7174 | { | |
7175 | struct wiphy *wiphy = &rdev->wiphy; | |
7176 | bool found = false; | |
7177 | int band, i; | |
7178 | ||
7179 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
7180 | struct ieee80211_supported_band *sband; | |
7181 | ||
7182 | sband = wiphy->bands[band]; | |
7183 | if (!sband) | |
7184 | continue; | |
7185 | ||
7186 | for (i = 0; i < sband->n_bitrates; i++) { | |
7187 | if (sband->bitrates[i].bitrate == rateval) { | |
7188 | mcast_rate[band] = i + 1; | |
7189 | found = true; | |
7190 | break; | |
7191 | } | |
7192 | } | |
7193 | } | |
7194 | ||
7195 | return found; | |
7196 | } | |
7197 | ||
04a773ad JB |
7198 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
7199 | { | |
4c476991 JB |
7200 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7201 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
7202 | struct cfg80211_ibss_params ibss; |
7203 | struct wiphy *wiphy; | |
fffd0934 | 7204 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
7205 | int err; |
7206 | ||
8e30bc55 JB |
7207 | memset(&ibss, 0, sizeof(ibss)); |
7208 | ||
04a773ad JB |
7209 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7210 | return -EINVAL; | |
7211 | ||
683b6d3b | 7212 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
7213 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
7214 | return -EINVAL; | |
7215 | ||
8e30bc55 JB |
7216 | ibss.beacon_interval = 100; |
7217 | ||
7218 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
7219 | ibss.beacon_interval = | |
7220 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7221 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
7222 | return -EINVAL; | |
7223 | } | |
7224 | ||
4c476991 JB |
7225 | if (!rdev->ops->join_ibss) |
7226 | return -EOPNOTSUPP; | |
04a773ad | 7227 | |
4c476991 JB |
7228 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7229 | return -EOPNOTSUPP; | |
04a773ad | 7230 | |
79c97e97 | 7231 | wiphy = &rdev->wiphy; |
04a773ad | 7232 | |
39193498 | 7233 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 7234 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
7235 | |
7236 | if (!is_valid_ether_addr(ibss.bssid)) | |
7237 | return -EINVAL; | |
7238 | } | |
04a773ad JB |
7239 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7240 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7241 | ||
7242 | if (info->attrs[NL80211_ATTR_IE]) { | |
7243 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7244 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7245 | } | |
7246 | ||
683b6d3b JB |
7247 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
7248 | if (err) | |
7249 | return err; | |
04a773ad | 7250 | |
174e0cd2 IP |
7251 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
7252 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
7253 | return -EINVAL; |
7254 | ||
2f301ab2 | 7255 | switch (ibss.chandef.width) { |
bf372645 SW |
7256 | case NL80211_CHAN_WIDTH_5: |
7257 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
7258 | case NL80211_CHAN_WIDTH_20_NOHT: |
7259 | break; | |
7260 | case NL80211_CHAN_WIDTH_20: | |
7261 | case NL80211_CHAN_WIDTH_40: | |
7262 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | |
7263 | break; | |
7264 | default: | |
c04d6150 | 7265 | return -EINVAL; |
2f301ab2 | 7266 | } |
db9c64cf | 7267 | |
04a773ad | 7268 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
7269 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
7270 | ||
fbd2c8dc TP |
7271 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
7272 | u8 *rates = | |
7273 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7274 | int n_rates = | |
7275 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7276 | struct ieee80211_supported_band *sband = | |
683b6d3b | 7277 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 7278 | |
34850ab2 JB |
7279 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
7280 | &ibss.basic_rates); | |
7281 | if (err) | |
7282 | return err; | |
fbd2c8dc | 7283 | } |
dd5b4cc7 | 7284 | |
803768f5 SW |
7285 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7286 | memcpy(&ibss.ht_capa_mask, | |
7287 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7288 | sizeof(ibss.ht_capa_mask)); | |
7289 | ||
7290 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
7291 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7292 | return -EINVAL; | |
7293 | memcpy(&ibss.ht_capa, | |
7294 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7295 | sizeof(ibss.ht_capa)); | |
7296 | } | |
7297 | ||
dd5b4cc7 FF |
7298 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7299 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
7300 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7301 | return -EINVAL; | |
fbd2c8dc | 7302 | |
4c476991 | 7303 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
7304 | bool no_ht = false; |
7305 | ||
4c476991 | 7306 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
7307 | info->attrs[NL80211_ATTR_KEYS], |
7308 | &no_ht); | |
4c476991 JB |
7309 | if (IS_ERR(connkeys)) |
7310 | return PTR_ERR(connkeys); | |
de7044ee | 7311 | |
3d9d1d66 JB |
7312 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
7313 | no_ht) { | |
de7044ee SM |
7314 | kfree(connkeys); |
7315 | return -EINVAL; | |
7316 | } | |
4c476991 | 7317 | } |
04a773ad | 7318 | |
267335d6 AQ |
7319 | ibss.control_port = |
7320 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
7321 | ||
5336fa88 SW |
7322 | ibss.userspace_handles_dfs = |
7323 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
7324 | ||
4c476991 | 7325 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 | 7326 | if (err) |
b47f610b | 7327 | kzfree(connkeys); |
04a773ad JB |
7328 | return err; |
7329 | } | |
7330 | ||
7331 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
7332 | { | |
4c476991 JB |
7333 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7334 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 7335 | |
4c476991 JB |
7336 | if (!rdev->ops->leave_ibss) |
7337 | return -EOPNOTSUPP; | |
04a773ad | 7338 | |
4c476991 JB |
7339 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7340 | return -EOPNOTSUPP; | |
04a773ad | 7341 | |
4c476991 | 7342 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
7343 | } |
7344 | ||
f4e583c8 AQ |
7345 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
7346 | { | |
7347 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7348 | struct net_device *dev = info->user_ptr[1]; | |
7349 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
7350 | u32 nla_rate; | |
7351 | int err; | |
7352 | ||
7353 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
7354 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
7355 | return -EOPNOTSUPP; | |
7356 | ||
7357 | if (!rdev->ops->set_mcast_rate) | |
7358 | return -EOPNOTSUPP; | |
7359 | ||
7360 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
7361 | ||
7362 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
7363 | return -EINVAL; | |
7364 | ||
7365 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
7366 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
7367 | return -EINVAL; | |
7368 | ||
7369 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
7370 | ||
7371 | return err; | |
7372 | } | |
7373 | ||
ad7e718c JB |
7374 | static struct sk_buff * |
7375 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
7376 | int approxlen, u32 portid, u32 seq, | |
7377 | enum nl80211_commands cmd, | |
567ffc35 JB |
7378 | enum nl80211_attrs attr, |
7379 | const struct nl80211_vendor_cmd_info *info, | |
7380 | gfp_t gfp) | |
ad7e718c JB |
7381 | { |
7382 | struct sk_buff *skb; | |
7383 | void *hdr; | |
7384 | struct nlattr *data; | |
7385 | ||
7386 | skb = nlmsg_new(approxlen + 100, gfp); | |
7387 | if (!skb) | |
7388 | return NULL; | |
7389 | ||
7390 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
7391 | if (!hdr) { | |
7392 | kfree_skb(skb); | |
7393 | return NULL; | |
7394 | } | |
7395 | ||
7396 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
7397 | goto nla_put_failure; | |
567ffc35 JB |
7398 | |
7399 | if (info) { | |
7400 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
7401 | info->vendor_id)) | |
7402 | goto nla_put_failure; | |
7403 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
7404 | info->subcmd)) | |
7405 | goto nla_put_failure; | |
7406 | } | |
7407 | ||
ad7e718c JB |
7408 | data = nla_nest_start(skb, attr); |
7409 | ||
7410 | ((void **)skb->cb)[0] = rdev; | |
7411 | ((void **)skb->cb)[1] = hdr; | |
7412 | ((void **)skb->cb)[2] = data; | |
7413 | ||
7414 | return skb; | |
7415 | ||
7416 | nla_put_failure: | |
7417 | kfree_skb(skb); | |
7418 | return NULL; | |
7419 | } | |
f4e583c8 | 7420 | |
e03ad6ea JB |
7421 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
7422 | enum nl80211_commands cmd, | |
7423 | enum nl80211_attrs attr, | |
7424 | int vendor_event_idx, | |
7425 | int approxlen, gfp_t gfp) | |
7426 | { | |
f26cbf40 | 7427 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
7428 | const struct nl80211_vendor_cmd_info *info; |
7429 | ||
7430 | switch (cmd) { | |
7431 | case NL80211_CMD_TESTMODE: | |
7432 | if (WARN_ON(vendor_event_idx != -1)) | |
7433 | return NULL; | |
7434 | info = NULL; | |
7435 | break; | |
7436 | case NL80211_CMD_VENDOR: | |
7437 | if (WARN_ON(vendor_event_idx < 0 || | |
7438 | vendor_event_idx >= wiphy->n_vendor_events)) | |
7439 | return NULL; | |
7440 | info = &wiphy->vendor_events[vendor_event_idx]; | |
7441 | break; | |
7442 | default: | |
7443 | WARN_ON(1); | |
7444 | return NULL; | |
7445 | } | |
7446 | ||
7447 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, | |
7448 | cmd, attr, info, gfp); | |
7449 | } | |
7450 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
7451 | ||
7452 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
7453 | { | |
7454 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
7455 | void *hdr = ((void **)skb->cb)[1]; | |
7456 | struct nlattr *data = ((void **)skb->cb)[2]; | |
7457 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
7458 | ||
bd8c78e7 JB |
7459 | /* clear CB data for netlink core to own from now on */ |
7460 | memset(skb->cb, 0, sizeof(skb->cb)); | |
7461 | ||
e03ad6ea JB |
7462 | nla_nest_end(skb, data); |
7463 | genlmsg_end(skb, hdr); | |
7464 | ||
7465 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
7466 | mcgrp = NL80211_MCGRP_VENDOR; | |
7467 | ||
7468 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
7469 | mcgrp, gfp); | |
7470 | } | |
7471 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
7472 | ||
aff89a9b | 7473 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
7474 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
7475 | { | |
4c476991 | 7476 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
7477 | struct wireless_dev *wdev = |
7478 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
7479 | int err; |
7480 | ||
fc73f11f DS |
7481 | if (!rdev->ops->testmode_cmd) |
7482 | return -EOPNOTSUPP; | |
7483 | ||
7484 | if (IS_ERR(wdev)) { | |
7485 | err = PTR_ERR(wdev); | |
7486 | if (err != -EINVAL) | |
7487 | return err; | |
7488 | wdev = NULL; | |
7489 | } else if (wdev->wiphy != &rdev->wiphy) { | |
7490 | return -EINVAL; | |
7491 | } | |
7492 | ||
aff89a9b JB |
7493 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
7494 | return -EINVAL; | |
7495 | ||
ad7e718c | 7496 | rdev->cur_cmd_info = info; |
fc73f11f | 7497 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
7498 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
7499 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 7500 | rdev->cur_cmd_info = NULL; |
aff89a9b | 7501 | |
aff89a9b JB |
7502 | return err; |
7503 | } | |
7504 | ||
71063f0e WYG |
7505 | static int nl80211_testmode_dump(struct sk_buff *skb, |
7506 | struct netlink_callback *cb) | |
7507 | { | |
00918d33 | 7508 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
7509 | int err; |
7510 | long phy_idx; | |
7511 | void *data = NULL; | |
7512 | int data_len = 0; | |
7513 | ||
5fe231e8 JB |
7514 | rtnl_lock(); |
7515 | ||
71063f0e WYG |
7516 | if (cb->args[0]) { |
7517 | /* | |
7518 | * 0 is a valid index, but not valid for args[0], | |
7519 | * so we need to offset by 1. | |
7520 | */ | |
7521 | phy_idx = cb->args[0] - 1; | |
7522 | } else { | |
7523 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
7524 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
7525 | nl80211_policy); | |
7526 | if (err) | |
5fe231e8 | 7527 | goto out_err; |
00918d33 | 7528 | |
2bd7e35d JB |
7529 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
7530 | nl80211_fam.attrbuf); | |
7531 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
7532 | err = PTR_ERR(rdev); |
7533 | goto out_err; | |
00918d33 | 7534 | } |
2bd7e35d JB |
7535 | phy_idx = rdev->wiphy_idx; |
7536 | rdev = NULL; | |
2bd7e35d | 7537 | |
71063f0e WYG |
7538 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
7539 | cb->args[1] = | |
7540 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
7541 | } | |
7542 | ||
7543 | if (cb->args[1]) { | |
7544 | data = nla_data((void *)cb->args[1]); | |
7545 | data_len = nla_len((void *)cb->args[1]); | |
7546 | } | |
7547 | ||
00918d33 JB |
7548 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
7549 | if (!rdev) { | |
5fe231e8 JB |
7550 | err = -ENOENT; |
7551 | goto out_err; | |
71063f0e | 7552 | } |
71063f0e | 7553 | |
00918d33 | 7554 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
7555 | err = -EOPNOTSUPP; |
7556 | goto out_err; | |
7557 | } | |
7558 | ||
7559 | while (1) { | |
15e47304 | 7560 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
7561 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
7562 | NL80211_CMD_TESTMODE); | |
7563 | struct nlattr *tmdata; | |
7564 | ||
cb35fba3 DC |
7565 | if (!hdr) |
7566 | break; | |
7567 | ||
9360ffd1 | 7568 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
7569 | genlmsg_cancel(skb, hdr); |
7570 | break; | |
7571 | } | |
7572 | ||
7573 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
7574 | if (!tmdata) { | |
7575 | genlmsg_cancel(skb, hdr); | |
7576 | break; | |
7577 | } | |
e35e4d28 | 7578 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
7579 | nla_nest_end(skb, tmdata); |
7580 | ||
7581 | if (err == -ENOBUFS || err == -ENOENT) { | |
7582 | genlmsg_cancel(skb, hdr); | |
7583 | break; | |
7584 | } else if (err) { | |
7585 | genlmsg_cancel(skb, hdr); | |
7586 | goto out_err; | |
7587 | } | |
7588 | ||
7589 | genlmsg_end(skb, hdr); | |
7590 | } | |
7591 | ||
7592 | err = skb->len; | |
7593 | /* see above */ | |
7594 | cb->args[0] = phy_idx + 1; | |
7595 | out_err: | |
5fe231e8 | 7596 | rtnl_unlock(); |
71063f0e WYG |
7597 | return err; |
7598 | } | |
aff89a9b JB |
7599 | #endif |
7600 | ||
b23aa676 SO |
7601 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
7602 | { | |
4c476991 JB |
7603 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7604 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
7605 | struct cfg80211_connect_params connect; |
7606 | struct wiphy *wiphy; | |
fffd0934 | 7607 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
7608 | int err; |
7609 | ||
7610 | memset(&connect, 0, sizeof(connect)); | |
7611 | ||
7612 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
7613 | return -EINVAL; | |
7614 | ||
7615 | if (!info->attrs[NL80211_ATTR_SSID] || | |
7616 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
7617 | return -EINVAL; | |
7618 | ||
7619 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
7620 | connect.auth_type = | |
7621 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
7622 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
7623 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
7624 | return -EINVAL; |
7625 | } else | |
7626 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
7627 | ||
7628 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
7629 | ||
c0692b8f | 7630 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 7631 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
7632 | if (err) |
7633 | return err; | |
b23aa676 | 7634 | |
074ac8df | 7635 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7636 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7637 | return -EOPNOTSUPP; | |
b23aa676 | 7638 | |
79c97e97 | 7639 | wiphy = &rdev->wiphy; |
b23aa676 | 7640 | |
4486ea98 BS |
7641 | connect.bg_scan_period = -1; |
7642 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
7643 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
7644 | connect.bg_scan_period = | |
7645 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
7646 | } | |
7647 | ||
b23aa676 SO |
7648 | if (info->attrs[NL80211_ATTR_MAC]) |
7649 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
7650 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
7651 | connect.bssid_hint = | |
7652 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
7653 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7654 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7655 | ||
7656 | if (info->attrs[NL80211_ATTR_IE]) { | |
7657 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7658 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7659 | } | |
7660 | ||
cee00a95 JM |
7661 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
7662 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
7663 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
7664 | connect.mfp != NL80211_MFP_NO) | |
7665 | return -EINVAL; | |
7666 | } else { | |
7667 | connect.mfp = NL80211_MFP_NO; | |
7668 | } | |
7669 | ||
b23aa676 | 7670 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
7671 | connect.channel = nl80211_get_valid_chan( |
7672 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7673 | if (!connect.channel) | |
1df4a510 JM |
7674 | return -EINVAL; |
7675 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
7676 | connect.channel_hint = nl80211_get_valid_chan( |
7677 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
7678 | if (!connect.channel_hint) | |
4c476991 | 7679 | return -EINVAL; |
b23aa676 SO |
7680 | } |
7681 | ||
fffd0934 JB |
7682 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
7683 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 7684 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
7685 | if (IS_ERR(connkeys)) |
7686 | return PTR_ERR(connkeys); | |
fffd0934 JB |
7687 | } |
7688 | ||
7e7c8926 BG |
7689 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
7690 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
7691 | ||
7692 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7693 | memcpy(&connect.ht_capa_mask, | |
7694 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7695 | sizeof(connect.ht_capa_mask)); | |
7696 | ||
7697 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e | 7698 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
b47f610b | 7699 | kzfree(connkeys); |
7e7c8926 | 7700 | return -EINVAL; |
b4e4f47e | 7701 | } |
7e7c8926 BG |
7702 | memcpy(&connect.ht_capa, |
7703 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7704 | sizeof(connect.ht_capa)); | |
7705 | } | |
7706 | ||
ee2aca34 JB |
7707 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
7708 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
7709 | ||
7710 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
7711 | memcpy(&connect.vht_capa_mask, | |
7712 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7713 | sizeof(connect.vht_capa_mask)); | |
7714 | ||
7715 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
7716 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
b47f610b | 7717 | kzfree(connkeys); |
ee2aca34 JB |
7718 | return -EINVAL; |
7719 | } | |
7720 | memcpy(&connect.vht_capa, | |
7721 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7722 | sizeof(connect.vht_capa)); | |
7723 | } | |
7724 | ||
bab5ab7d AK |
7725 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7726 | if (!(rdev->wiphy.features & | |
7727 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7728 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7729 | return -EINVAL; | |
7730 | connect.flags |= ASSOC_REQ_USE_RRM; | |
7731 | } | |
7732 | ||
83739b03 JB |
7733 | wdev_lock(dev->ieee80211_ptr); |
7734 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
7735 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 | 7736 | if (err) |
b47f610b | 7737 | kzfree(connkeys); |
b23aa676 SO |
7738 | return err; |
7739 | } | |
7740 | ||
7741 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
7742 | { | |
4c476991 JB |
7743 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7744 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 7745 | u16 reason; |
83739b03 | 7746 | int ret; |
b23aa676 SO |
7747 | |
7748 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7749 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
7750 | else | |
7751 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
7752 | ||
7753 | if (reason == 0) | |
7754 | return -EINVAL; | |
7755 | ||
074ac8df | 7756 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7757 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7758 | return -EOPNOTSUPP; | |
b23aa676 | 7759 | |
83739b03 JB |
7760 | wdev_lock(dev->ieee80211_ptr); |
7761 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
7762 | wdev_unlock(dev->ieee80211_ptr); | |
7763 | return ret; | |
b23aa676 SO |
7764 | } |
7765 | ||
463d0183 JB |
7766 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
7767 | { | |
4c476991 | 7768 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
7769 | struct net *net; |
7770 | int err; | |
463d0183 | 7771 | |
4b681c82 VK |
7772 | if (info->attrs[NL80211_ATTR_PID]) { |
7773 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
7774 | ||
7775 | net = get_net_ns_by_pid(pid); | |
7776 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { | |
7777 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); | |
463d0183 | 7778 | |
4b681c82 VK |
7779 | net = get_net_ns_by_fd(fd); |
7780 | } else { | |
7781 | return -EINVAL; | |
7782 | } | |
463d0183 | 7783 | |
4c476991 JB |
7784 | if (IS_ERR(net)) |
7785 | return PTR_ERR(net); | |
463d0183 JB |
7786 | |
7787 | err = 0; | |
7788 | ||
7789 | /* check if anything to do */ | |
4c476991 JB |
7790 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
7791 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 7792 | |
463d0183 | 7793 | put_net(net); |
463d0183 JB |
7794 | return err; |
7795 | } | |
7796 | ||
67fbb16b SO |
7797 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
7798 | { | |
4c476991 | 7799 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
7800 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
7801 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 7802 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
7803 | struct cfg80211_pmksa pmksa; |
7804 | ||
7805 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
7806 | ||
7807 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7808 | return -EINVAL; | |
7809 | ||
7810 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
7811 | return -EINVAL; | |
7812 | ||
67fbb16b SO |
7813 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
7814 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7815 | ||
074ac8df | 7816 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7817 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7818 | return -EOPNOTSUPP; | |
67fbb16b SO |
7819 | |
7820 | switch (info->genlhdr->cmd) { | |
7821 | case NL80211_CMD_SET_PMKSA: | |
7822 | rdev_ops = rdev->ops->set_pmksa; | |
7823 | break; | |
7824 | case NL80211_CMD_DEL_PMKSA: | |
7825 | rdev_ops = rdev->ops->del_pmksa; | |
7826 | break; | |
7827 | default: | |
7828 | WARN_ON(1); | |
7829 | break; | |
7830 | } | |
7831 | ||
4c476991 JB |
7832 | if (!rdev_ops) |
7833 | return -EOPNOTSUPP; | |
67fbb16b | 7834 | |
4c476991 | 7835 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
7836 | } |
7837 | ||
7838 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
7839 | { | |
4c476991 JB |
7840 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7841 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 7842 | |
074ac8df | 7843 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7844 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7845 | return -EOPNOTSUPP; | |
67fbb16b | 7846 | |
4c476991 JB |
7847 | if (!rdev->ops->flush_pmksa) |
7848 | return -EOPNOTSUPP; | |
67fbb16b | 7849 | |
e35e4d28 | 7850 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
7851 | } |
7852 | ||
109086ce AN |
7853 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
7854 | { | |
7855 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7856 | struct net_device *dev = info->user_ptr[1]; | |
7857 | u8 action_code, dialog_token; | |
df942e7b | 7858 | u32 peer_capability = 0; |
109086ce AN |
7859 | u16 status_code; |
7860 | u8 *peer; | |
31fa97c5 | 7861 | bool initiator; |
109086ce AN |
7862 | |
7863 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7864 | !rdev->ops->tdls_mgmt) | |
7865 | return -EOPNOTSUPP; | |
7866 | ||
7867 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
7868 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
7869 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
7870 | !info->attrs[NL80211_ATTR_IE] || | |
7871 | !info->attrs[NL80211_ATTR_MAC]) | |
7872 | return -EINVAL; | |
7873 | ||
7874 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7875 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
7876 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
7877 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 7878 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
7879 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
7880 | peer_capability = | |
7881 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 7882 | |
e35e4d28 | 7883 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 7884 | dialog_token, status_code, peer_capability, |
31fa97c5 | 7885 | initiator, |
e35e4d28 HG |
7886 | nla_data(info->attrs[NL80211_ATTR_IE]), |
7887 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
7888 | } |
7889 | ||
7890 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
7891 | { | |
7892 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7893 | struct net_device *dev = info->user_ptr[1]; | |
7894 | enum nl80211_tdls_operation operation; | |
7895 | u8 *peer; | |
7896 | ||
7897 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7898 | !rdev->ops->tdls_oper) | |
7899 | return -EOPNOTSUPP; | |
7900 | ||
7901 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
7902 | !info->attrs[NL80211_ATTR_MAC]) | |
7903 | return -EINVAL; | |
7904 | ||
7905 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
7906 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7907 | ||
e35e4d28 | 7908 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
7909 | } |
7910 | ||
9588bbd5 JM |
7911 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
7912 | struct genl_info *info) | |
7913 | { | |
4c476991 | 7914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7915 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7916 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
7917 | struct sk_buff *msg; |
7918 | void *hdr; | |
7919 | u64 cookie; | |
683b6d3b | 7920 | u32 duration; |
9588bbd5 JM |
7921 | int err; |
7922 | ||
7923 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7924 | !info->attrs[NL80211_ATTR_DURATION]) | |
7925 | return -EINVAL; | |
7926 | ||
7927 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
7928 | ||
ebf348fc JB |
7929 | if (!rdev->ops->remain_on_channel || |
7930 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
7931 | return -EOPNOTSUPP; | |
7932 | ||
9588bbd5 | 7933 | /* |
ebf348fc JB |
7934 | * We should be on that channel for at least a minimum amount of |
7935 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 7936 | */ |
ebf348fc | 7937 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 7938 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
7939 | return -EINVAL; |
7940 | ||
683b6d3b JB |
7941 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7942 | if (err) | |
7943 | return err; | |
9588bbd5 JM |
7944 | |
7945 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7946 | if (!msg) |
7947 | return -ENOMEM; | |
9588bbd5 | 7948 | |
15e47304 | 7949 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 7950 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
7951 | if (!hdr) { |
7952 | err = -ENOBUFS; | |
9588bbd5 JM |
7953 | goto free_msg; |
7954 | } | |
7955 | ||
683b6d3b JB |
7956 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7957 | duration, &cookie); | |
9588bbd5 JM |
7958 | |
7959 | if (err) | |
7960 | goto free_msg; | |
7961 | ||
9360ffd1 DM |
7962 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7963 | goto nla_put_failure; | |
9588bbd5 JM |
7964 | |
7965 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7966 | |
7967 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7968 | |
7969 | nla_put_failure: | |
7970 | err = -ENOBUFS; | |
7971 | free_msg: | |
7972 | nlmsg_free(msg); | |
9588bbd5 JM |
7973 | return err; |
7974 | } | |
7975 | ||
7976 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
7977 | struct genl_info *info) | |
7978 | { | |
4c476991 | 7979 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7980 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 7981 | u64 cookie; |
9588bbd5 JM |
7982 | |
7983 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7984 | return -EINVAL; | |
7985 | ||
4c476991 JB |
7986 | if (!rdev->ops->cancel_remain_on_channel) |
7987 | return -EOPNOTSUPP; | |
9588bbd5 | 7988 | |
9588bbd5 JM |
7989 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
7990 | ||
e35e4d28 | 7991 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
7992 | } |
7993 | ||
13ae75b1 JM |
7994 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
7995 | u8 *rates, u8 rates_len) | |
7996 | { | |
7997 | u8 i; | |
7998 | u32 mask = 0; | |
7999 | ||
8000 | for (i = 0; i < rates_len; i++) { | |
8001 | int rate = (rates[i] & 0x7f) * 5; | |
8002 | int ridx; | |
8003 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
8004 | struct ieee80211_rate *srate = | |
8005 | &sband->bitrates[ridx]; | |
8006 | if (rate == srate->bitrate) { | |
8007 | mask |= 1 << ridx; | |
8008 | break; | |
8009 | } | |
8010 | } | |
8011 | if (ridx == sband->n_bitrates) | |
8012 | return 0; /* rate not found */ | |
8013 | } | |
8014 | ||
8015 | return mask; | |
8016 | } | |
8017 | ||
24db78c0 SW |
8018 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
8019 | u8 *rates, u8 rates_len, | |
8020 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
8021 | { | |
8022 | u8 i; | |
8023 | ||
8024 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
8025 | ||
8026 | for (i = 0; i < rates_len; i++) { | |
8027 | int ridx, rbit; | |
8028 | ||
8029 | ridx = rates[i] / 8; | |
8030 | rbit = BIT(rates[i] % 8); | |
8031 | ||
8032 | /* check validity */ | |
910570b5 | 8033 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
8034 | return false; |
8035 | ||
8036 | /* check availability */ | |
8037 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
8038 | mcs[ridx] |= rbit; | |
8039 | else | |
8040 | return false; | |
8041 | } | |
8042 | ||
8043 | return true; | |
8044 | } | |
8045 | ||
204e35a9 JD |
8046 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
8047 | { | |
8048 | u16 mcs_mask = 0; | |
8049 | ||
8050 | switch (vht_mcs_map) { | |
8051 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
8052 | break; | |
8053 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
8054 | mcs_mask = 0x00FF; | |
8055 | break; | |
8056 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
8057 | mcs_mask = 0x01FF; | |
8058 | break; | |
8059 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
8060 | mcs_mask = 0x03FF; | |
8061 | break; | |
8062 | default: | |
8063 | break; | |
8064 | } | |
8065 | ||
8066 | return mcs_mask; | |
8067 | } | |
8068 | ||
8069 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
8070 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
8071 | { | |
8072 | u8 nss; | |
8073 | ||
8074 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
8075 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
8076 | vht_mcs_map >>= 2; | |
8077 | } | |
8078 | } | |
8079 | ||
8080 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
8081 | struct nl80211_txrate_vht *txrate, | |
8082 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
8083 | { | |
8084 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8085 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
8086 | u8 i; | |
8087 | ||
8088 | if (!sband->vht_cap.vht_supported) | |
8089 | return false; | |
8090 | ||
8091 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
8092 | ||
8093 | /* Build vht_mcs_mask from VHT capabilities */ | |
8094 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
8095 | ||
8096 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
8097 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
8098 | mcs[i] = txrate->mcs[i]; | |
8099 | else | |
8100 | return false; | |
8101 | } | |
8102 | ||
8103 | return true; | |
8104 | } | |
8105 | ||
b54452b0 | 8106 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
8107 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
8108 | .len = NL80211_MAX_SUPP_RATES }, | |
d1e33e65 JD |
8109 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
8110 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
204e35a9 | 8111 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
0b9323f6 | 8112 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
13ae75b1 JM |
8113 | }; |
8114 | ||
8115 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
8116 | struct genl_info *info) | |
8117 | { | |
8118 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 8119 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 8120 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
8121 | int rem, i; |
8122 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
8123 | struct nlattr *tx_rates; |
8124 | struct ieee80211_supported_band *sband; | |
204e35a9 | 8125 | u16 vht_tx_mcs_map; |
13ae75b1 | 8126 | |
4c476991 JB |
8127 | if (!rdev->ops->set_bitrate_mask) |
8128 | return -EOPNOTSUPP; | |
13ae75b1 JM |
8129 | |
8130 | memset(&mask, 0, sizeof(mask)); | |
8131 | /* Default to all rates enabled */ | |
8132 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
8133 | sband = rdev->wiphy.bands[i]; | |
7869303b JD |
8134 | |
8135 | if (!sband) | |
8136 | continue; | |
8137 | ||
8138 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; | |
d1e33e65 | 8139 | memcpy(mask.control[i].ht_mcs, |
7869303b | 8140 | sband->ht_cap.mcs.rx_mask, |
d1e33e65 | 8141 | sizeof(mask.control[i].ht_mcs)); |
204e35a9 JD |
8142 | |
8143 | if (!sband->vht_cap.vht_supported) | |
8144 | continue; | |
8145 | ||
8146 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8147 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); | |
13ae75b1 JM |
8148 | } |
8149 | ||
b9243ab0 JD |
8150 | /* if no rates are given set it back to the defaults */ |
8151 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
8152 | goto out; | |
8153 | ||
13ae75b1 JM |
8154 | /* |
8155 | * The nested attribute uses enum nl80211_band as the index. This maps | |
8156 | * directly to the enum ieee80211_band values used in cfg80211. | |
8157 | */ | |
24db78c0 | 8158 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
ae811e21 | 8159 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
13ae75b1 | 8160 | enum ieee80211_band band = nla_type(tx_rates); |
ae811e21 JB |
8161 | int err; |
8162 | ||
4c476991 JB |
8163 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
8164 | return -EINVAL; | |
13ae75b1 | 8165 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
8166 | if (sband == NULL) |
8167 | return -EINVAL; | |
ae811e21 JB |
8168 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
8169 | nla_len(tx_rates), nl80211_txattr_policy); | |
8170 | if (err) | |
8171 | return err; | |
13ae75b1 JM |
8172 | if (tb[NL80211_TXRATE_LEGACY]) { |
8173 | mask.control[band].legacy = rateset_to_mask( | |
8174 | sband, | |
8175 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
8176 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
8177 | if ((mask.control[band].legacy == 0) && |
8178 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
8179 | return -EINVAL; | |
24db78c0 | 8180 | } |
d1e33e65 | 8181 | if (tb[NL80211_TXRATE_HT]) { |
24db78c0 SW |
8182 | if (!ht_rateset_to_mask( |
8183 | sband, | |
d1e33e65 JD |
8184 | nla_data(tb[NL80211_TXRATE_HT]), |
8185 | nla_len(tb[NL80211_TXRATE_HT]), | |
8186 | mask.control[band].ht_mcs)) | |
24db78c0 SW |
8187 | return -EINVAL; |
8188 | } | |
204e35a9 JD |
8189 | if (tb[NL80211_TXRATE_VHT]) { |
8190 | if (!vht_set_mcs_mask( | |
8191 | sband, | |
8192 | nla_data(tb[NL80211_TXRATE_VHT]), | |
8193 | mask.control[band].vht_mcs)) | |
8194 | return -EINVAL; | |
8195 | } | |
0b9323f6 JD |
8196 | if (tb[NL80211_TXRATE_GI]) { |
8197 | mask.control[band].gi = | |
8198 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
8199 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
8200 | return -EINVAL; | |
8201 | } | |
24db78c0 SW |
8202 | |
8203 | if (mask.control[band].legacy == 0) { | |
204e35a9 JD |
8204 | /* don't allow empty legacy rates if HT or VHT |
8205 | * are not even supported. | |
8206 | */ | |
8207 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
8208 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
24db78c0 SW |
8209 | return -EINVAL; |
8210 | ||
8211 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
d1e33e65 | 8212 | if (mask.control[band].ht_mcs[i]) |
204e35a9 JD |
8213 | goto out; |
8214 | ||
8215 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
8216 | if (mask.control[band].vht_mcs[i]) | |
8217 | goto out; | |
24db78c0 SW |
8218 | |
8219 | /* legacy and mcs rates may not be both empty */ | |
204e35a9 | 8220 | return -EINVAL; |
13ae75b1 JM |
8221 | } |
8222 | } | |
8223 | ||
b9243ab0 | 8224 | out: |
e35e4d28 | 8225 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
8226 | } |
8227 | ||
2e161f78 | 8228 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8229 | { |
4c476991 | 8230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8231 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 8232 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
8233 | |
8234 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
8235 | return -EINVAL; | |
8236 | ||
2e161f78 JB |
8237 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
8238 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 8239 | |
71bbc994 JB |
8240 | switch (wdev->iftype) { |
8241 | case NL80211_IFTYPE_STATION: | |
8242 | case NL80211_IFTYPE_ADHOC: | |
8243 | case NL80211_IFTYPE_P2P_CLIENT: | |
8244 | case NL80211_IFTYPE_AP: | |
8245 | case NL80211_IFTYPE_AP_VLAN: | |
8246 | case NL80211_IFTYPE_MESH_POINT: | |
8247 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8248 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8249 | break; |
8250 | default: | |
4c476991 | 8251 | return -EOPNOTSUPP; |
71bbc994 | 8252 | } |
026331c4 JM |
8253 | |
8254 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
8255 | if (!rdev->ops->mgmt_tx) |
8256 | return -EOPNOTSUPP; | |
026331c4 | 8257 | |
15e47304 | 8258 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
8259 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
8260 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
8261 | } |
8262 | ||
2e161f78 | 8263 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8264 | { |
4c476991 | 8265 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8266 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 8267 | struct cfg80211_chan_def chandef; |
026331c4 | 8268 | int err; |
d64d373f | 8269 | void *hdr = NULL; |
026331c4 | 8270 | u64 cookie; |
e247bd90 | 8271 | struct sk_buff *msg = NULL; |
b176e629 AO |
8272 | struct cfg80211_mgmt_tx_params params = { |
8273 | .dont_wait_for_ack = | |
8274 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
8275 | }; | |
026331c4 | 8276 | |
683b6d3b | 8277 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
8278 | return -EINVAL; |
8279 | ||
4c476991 JB |
8280 | if (!rdev->ops->mgmt_tx) |
8281 | return -EOPNOTSUPP; | |
026331c4 | 8282 | |
71bbc994 | 8283 | switch (wdev->iftype) { |
ea141b75 AQ |
8284 | case NL80211_IFTYPE_P2P_DEVICE: |
8285 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
8286 | return -EINVAL; | |
71bbc994 JB |
8287 | case NL80211_IFTYPE_STATION: |
8288 | case NL80211_IFTYPE_ADHOC: | |
8289 | case NL80211_IFTYPE_P2P_CLIENT: | |
8290 | case NL80211_IFTYPE_AP: | |
8291 | case NL80211_IFTYPE_AP_VLAN: | |
8292 | case NL80211_IFTYPE_MESH_POINT: | |
8293 | case NL80211_IFTYPE_P2P_GO: | |
8294 | break; | |
8295 | default: | |
4c476991 | 8296 | return -EOPNOTSUPP; |
71bbc994 | 8297 | } |
026331c4 | 8298 | |
f7ca38df | 8299 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 8300 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 8301 | return -EINVAL; |
b176e629 | 8302 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
8303 | |
8304 | /* | |
8305 | * We should wait on the channel for at least a minimum amount | |
8306 | * of time (10ms) but no longer than the driver supports. | |
8307 | */ | |
b176e629 AO |
8308 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
8309 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc JB |
8310 | return -EINVAL; |
8311 | ||
f7ca38df JB |
8312 | } |
8313 | ||
b176e629 | 8314 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 8315 | |
b176e629 | 8316 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
8317 | return -EINVAL; |
8318 | ||
b176e629 | 8319 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 8320 | |
ea141b75 AQ |
8321 | /* get the channel if any has been specified, otherwise pass NULL to |
8322 | * the driver. The latter will use the current one | |
8323 | */ | |
8324 | chandef.chan = NULL; | |
8325 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
8326 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
8327 | if (err) | |
8328 | return err; | |
8329 | } | |
8330 | ||
b176e629 | 8331 | if (!chandef.chan && params.offchan) |
ea141b75 | 8332 | return -EINVAL; |
026331c4 | 8333 | |
34d22ce2 AO |
8334 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
8335 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
8336 | ||
8337 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
8338 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8339 | int i; | |
8340 | ||
8341 | if (len % sizeof(u16)) | |
8342 | return -EINVAL; | |
8343 | ||
8344 | params.n_csa_offsets = len / sizeof(u16); | |
8345 | params.csa_offsets = | |
8346 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8347 | ||
8348 | /* check that all the offsets fit the frame */ | |
8349 | for (i = 0; i < params.n_csa_offsets; i++) { | |
8350 | if (params.csa_offsets[i] >= params.len) | |
8351 | return -EINVAL; | |
8352 | } | |
8353 | } | |
8354 | ||
b176e629 | 8355 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
8356 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
8357 | if (!msg) | |
8358 | return -ENOMEM; | |
026331c4 | 8359 | |
15e47304 | 8360 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 8361 | NL80211_CMD_FRAME); |
cb35fba3 DC |
8362 | if (!hdr) { |
8363 | err = -ENOBUFS; | |
e247bd90 JB |
8364 | goto free_msg; |
8365 | } | |
026331c4 | 8366 | } |
e247bd90 | 8367 | |
b176e629 AO |
8368 | params.chan = chandef.chan; |
8369 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
8370 | if (err) |
8371 | goto free_msg; | |
8372 | ||
e247bd90 | 8373 | if (msg) { |
9360ffd1 DM |
8374 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8375 | goto nla_put_failure; | |
026331c4 | 8376 | |
e247bd90 JB |
8377 | genlmsg_end(msg, hdr); |
8378 | return genlmsg_reply(msg, info); | |
8379 | } | |
8380 | ||
8381 | return 0; | |
026331c4 JM |
8382 | |
8383 | nla_put_failure: | |
8384 | err = -ENOBUFS; | |
8385 | free_msg: | |
8386 | nlmsg_free(msg); | |
026331c4 JM |
8387 | return err; |
8388 | } | |
8389 | ||
f7ca38df JB |
8390 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
8391 | { | |
8392 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 8393 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
8394 | u64 cookie; |
8395 | ||
8396 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8397 | return -EINVAL; | |
8398 | ||
8399 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
8400 | return -EOPNOTSUPP; | |
8401 | ||
71bbc994 JB |
8402 | switch (wdev->iftype) { |
8403 | case NL80211_IFTYPE_STATION: | |
8404 | case NL80211_IFTYPE_ADHOC: | |
8405 | case NL80211_IFTYPE_P2P_CLIENT: | |
8406 | case NL80211_IFTYPE_AP: | |
8407 | case NL80211_IFTYPE_AP_VLAN: | |
8408 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8409 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8410 | break; |
8411 | default: | |
f7ca38df | 8412 | return -EOPNOTSUPP; |
71bbc994 | 8413 | } |
f7ca38df JB |
8414 | |
8415 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
8416 | ||
e35e4d28 | 8417 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
8418 | } |
8419 | ||
ffb9eb3d KV |
8420 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
8421 | { | |
4c476991 | 8422 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 8423 | struct wireless_dev *wdev; |
4c476991 | 8424 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8425 | u8 ps_state; |
8426 | bool state; | |
8427 | int err; | |
8428 | ||
4c476991 JB |
8429 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
8430 | return -EINVAL; | |
ffb9eb3d KV |
8431 | |
8432 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
8433 | ||
4c476991 JB |
8434 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
8435 | return -EINVAL; | |
ffb9eb3d KV |
8436 | |
8437 | wdev = dev->ieee80211_ptr; | |
8438 | ||
4c476991 JB |
8439 | if (!rdev->ops->set_power_mgmt) |
8440 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8441 | |
8442 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
8443 | ||
8444 | if (state == wdev->ps) | |
4c476991 | 8445 | return 0; |
ffb9eb3d | 8446 | |
e35e4d28 | 8447 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
8448 | if (!err) |
8449 | wdev->ps = state; | |
ffb9eb3d KV |
8450 | return err; |
8451 | } | |
8452 | ||
8453 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
8454 | { | |
4c476991 | 8455 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
8456 | enum nl80211_ps_state ps_state; |
8457 | struct wireless_dev *wdev; | |
4c476991 | 8458 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8459 | struct sk_buff *msg; |
8460 | void *hdr; | |
8461 | int err; | |
8462 | ||
ffb9eb3d KV |
8463 | wdev = dev->ieee80211_ptr; |
8464 | ||
4c476991 JB |
8465 | if (!rdev->ops->set_power_mgmt) |
8466 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8467 | |
8468 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
8469 | if (!msg) |
8470 | return -ENOMEM; | |
ffb9eb3d | 8471 | |
15e47304 | 8472 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
8473 | NL80211_CMD_GET_POWER_SAVE); |
8474 | if (!hdr) { | |
4c476991 | 8475 | err = -ENOBUFS; |
ffb9eb3d KV |
8476 | goto free_msg; |
8477 | } | |
8478 | ||
8479 | if (wdev->ps) | |
8480 | ps_state = NL80211_PS_ENABLED; | |
8481 | else | |
8482 | ps_state = NL80211_PS_DISABLED; | |
8483 | ||
9360ffd1 DM |
8484 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
8485 | goto nla_put_failure; | |
ffb9eb3d KV |
8486 | |
8487 | genlmsg_end(msg, hdr); | |
4c476991 | 8488 | return genlmsg_reply(msg, info); |
ffb9eb3d | 8489 | |
4c476991 | 8490 | nla_put_failure: |
ffb9eb3d | 8491 | err = -ENOBUFS; |
4c476991 | 8492 | free_msg: |
ffb9eb3d | 8493 | nlmsg_free(msg); |
ffb9eb3d KV |
8494 | return err; |
8495 | } | |
8496 | ||
94e860f1 JB |
8497 | static const struct nla_policy |
8498 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
8499 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
8500 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
8501 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
8502 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
8503 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
8504 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
8505 | }; |
8506 | ||
84f10708 | 8507 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 8508 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
8509 | { |
8510 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 8511 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8512 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 8513 | |
d9d8b019 | 8514 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
8515 | return -EINVAL; |
8516 | ||
84f10708 TP |
8517 | if (!rdev->ops->set_cqm_txe_config) |
8518 | return -EOPNOTSUPP; | |
8519 | ||
8520 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
8521 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
8522 | return -EOPNOTSUPP; | |
8523 | ||
e35e4d28 | 8524 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
8525 | } |
8526 | ||
d6dc1a38 JO |
8527 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
8528 | s32 threshold, u32 hysteresis) | |
8529 | { | |
4c476991 | 8530 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 8531 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8532 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
8533 | |
8534 | if (threshold > 0) | |
8535 | return -EINVAL; | |
8536 | ||
1da5fcc8 JB |
8537 | /* disabling - hysteresis should also be zero then */ |
8538 | if (threshold == 0) | |
8539 | hysteresis = 0; | |
d6dc1a38 | 8540 | |
4c476991 JB |
8541 | if (!rdev->ops->set_cqm_rssi_config) |
8542 | return -EOPNOTSUPP; | |
d6dc1a38 | 8543 | |
074ac8df | 8544 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8545 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8546 | return -EOPNOTSUPP; | |
d6dc1a38 | 8547 | |
e35e4d28 | 8548 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
8549 | } |
8550 | ||
8551 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
8552 | { | |
8553 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
8554 | struct nlattr *cqm; | |
8555 | int err; | |
8556 | ||
8557 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
8558 | if (!cqm) |
8559 | return -EINVAL; | |
d6dc1a38 JO |
8560 | |
8561 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
8562 | nl80211_attr_cqm_policy); | |
8563 | if (err) | |
1da5fcc8 | 8564 | return err; |
d6dc1a38 JO |
8565 | |
8566 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
8567 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
8568 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
8569 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 8570 | |
1da5fcc8 JB |
8571 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
8572 | } | |
8573 | ||
8574 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
8575 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
8576 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
8577 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
8578 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
8579 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
8580 | ||
8581 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
8582 | } | |
8583 | ||
8584 | return -EINVAL; | |
d6dc1a38 JO |
8585 | } |
8586 | ||
6e0bd6c3 RL |
8587 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
8588 | { | |
8589 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8590 | struct net_device *dev = info->user_ptr[1]; | |
8591 | struct ocb_setup setup = {}; | |
8592 | int err; | |
8593 | ||
8594 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | |
8595 | if (err) | |
8596 | return err; | |
8597 | ||
8598 | return cfg80211_join_ocb(rdev, dev, &setup); | |
8599 | } | |
8600 | ||
8601 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | |
8602 | { | |
8603 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8604 | struct net_device *dev = info->user_ptr[1]; | |
8605 | ||
8606 | return cfg80211_leave_ocb(rdev, dev); | |
8607 | } | |
8608 | ||
29cbe68c JB |
8609 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
8610 | { | |
8611 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8612 | struct net_device *dev = info->user_ptr[1]; | |
8613 | struct mesh_config cfg; | |
c80d545d | 8614 | struct mesh_setup setup; |
29cbe68c JB |
8615 | int err; |
8616 | ||
8617 | /* start with default */ | |
8618 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 8619 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 8620 | |
24bdd9f4 | 8621 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 8622 | /* and parse parameters if given */ |
24bdd9f4 | 8623 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
8624 | if (err) |
8625 | return err; | |
8626 | } | |
8627 | ||
8628 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
8629 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
8630 | return -EINVAL; | |
8631 | ||
c80d545d JC |
8632 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
8633 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
8634 | ||
4bb62344 CYY |
8635 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8636 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
8637 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8638 | return -EINVAL; | |
8639 | ||
9bdbf04d MP |
8640 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
8641 | setup.beacon_interval = | |
8642 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
8643 | if (setup.beacon_interval < 10 || | |
8644 | setup.beacon_interval > 10000) | |
8645 | return -EINVAL; | |
8646 | } | |
8647 | ||
8648 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
8649 | setup.dtim_period = | |
8650 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
8651 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
8652 | return -EINVAL; | |
8653 | } | |
8654 | ||
c80d545d JC |
8655 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
8656 | /* parse additional setup parameters if given */ | |
8657 | err = nl80211_parse_mesh_setup(info, &setup); | |
8658 | if (err) | |
8659 | return err; | |
8660 | } | |
8661 | ||
d37bb18a TP |
8662 | if (setup.user_mpm) |
8663 | cfg.auto_open_plinks = false; | |
8664 | ||
cc1d2806 | 8665 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
8666 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
8667 | if (err) | |
8668 | return err; | |
cc1d2806 JB |
8669 | } else { |
8670 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 8671 | setup.chandef.chan = NULL; |
cc1d2806 JB |
8672 | } |
8673 | ||
ffb3cf30 AN |
8674 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8675 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8676 | int n_rates = | |
8677 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8678 | struct ieee80211_supported_band *sband; | |
8679 | ||
8680 | if (!setup.chandef.chan) | |
8681 | return -EINVAL; | |
8682 | ||
8683 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
8684 | ||
8685 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
8686 | &setup.basic_rates); | |
8687 | if (err) | |
8688 | return err; | |
8689 | } | |
8690 | ||
c80d545d | 8691 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
8692 | } |
8693 | ||
8694 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
8695 | { | |
8696 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8697 | struct net_device *dev = info->user_ptr[1]; | |
8698 | ||
8699 | return cfg80211_leave_mesh(rdev, dev); | |
8700 | } | |
8701 | ||
dfb89c56 | 8702 | #ifdef CONFIG_PM |
bb92d199 AK |
8703 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
8704 | struct cfg80211_registered_device *rdev) | |
8705 | { | |
6abb9cb9 | 8706 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
8707 | struct nlattr *nl_pats, *nl_pat; |
8708 | int i, pat_len; | |
8709 | ||
6abb9cb9 | 8710 | if (!wowlan->n_patterns) |
bb92d199 AK |
8711 | return 0; |
8712 | ||
8713 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
8714 | if (!nl_pats) | |
8715 | return -ENOBUFS; | |
8716 | ||
6abb9cb9 | 8717 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
8718 | nl_pat = nla_nest_start(msg, i + 1); |
8719 | if (!nl_pat) | |
8720 | return -ENOBUFS; | |
6abb9cb9 | 8721 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 8722 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 8723 | wowlan->patterns[i].mask) || |
50ac6607 AK |
8724 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
8725 | wowlan->patterns[i].pattern) || | |
8726 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 8727 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
8728 | return -ENOBUFS; |
8729 | nla_nest_end(msg, nl_pat); | |
8730 | } | |
8731 | nla_nest_end(msg, nl_pats); | |
8732 | ||
8733 | return 0; | |
8734 | } | |
8735 | ||
2a0e047e JB |
8736 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
8737 | struct cfg80211_wowlan_tcp *tcp) | |
8738 | { | |
8739 | struct nlattr *nl_tcp; | |
8740 | ||
8741 | if (!tcp) | |
8742 | return 0; | |
8743 | ||
8744 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
8745 | if (!nl_tcp) | |
8746 | return -ENOBUFS; | |
8747 | ||
8748 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
8749 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
8750 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
8751 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
8752 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
8753 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
8754 | tcp->payload_len, tcp->payload) || | |
8755 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
8756 | tcp->data_interval) || | |
8757 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
8758 | tcp->wake_len, tcp->wake_data) || | |
8759 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
8760 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
8761 | return -ENOBUFS; | |
8762 | ||
8763 | if (tcp->payload_seq.len && | |
8764 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
8765 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
8766 | return -ENOBUFS; | |
8767 | ||
8768 | if (tcp->payload_tok.len && | |
8769 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
8770 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
8771 | &tcp->payload_tok)) | |
8772 | return -ENOBUFS; | |
8773 | ||
e248ad30 JB |
8774 | nla_nest_end(msg, nl_tcp); |
8775 | ||
2a0e047e JB |
8776 | return 0; |
8777 | } | |
8778 | ||
75453ccb LC |
8779 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
8780 | struct cfg80211_sched_scan_request *req) | |
8781 | { | |
8782 | struct nlattr *nd, *freqs, *matches, *match; | |
8783 | int i; | |
8784 | ||
8785 | if (!req) | |
8786 | return 0; | |
8787 | ||
8788 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); | |
8789 | if (!nd) | |
8790 | return -ENOBUFS; | |
8791 | ||
8792 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, req->interval)) | |
8793 | return -ENOBUFS; | |
8794 | ||
8795 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
8796 | if (!freqs) | |
8797 | return -ENOBUFS; | |
8798 | ||
8799 | for (i = 0; i < req->n_channels; i++) | |
8800 | nla_put_u32(msg, i, req->channels[i]->center_freq); | |
8801 | ||
8802 | nla_nest_end(msg, freqs); | |
8803 | ||
8804 | if (req->n_match_sets) { | |
8805 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); | |
8806 | for (i = 0; i < req->n_match_sets; i++) { | |
8807 | match = nla_nest_start(msg, i); | |
8808 | nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, | |
8809 | req->match_sets[i].ssid.ssid_len, | |
8810 | req->match_sets[i].ssid.ssid); | |
8811 | nla_nest_end(msg, match); | |
8812 | } | |
8813 | nla_nest_end(msg, matches); | |
8814 | } | |
8815 | ||
8816 | nla_nest_end(msg, nd); | |
8817 | ||
8818 | return 0; | |
8819 | } | |
8820 | ||
ff1b6e69 JB |
8821 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
8822 | { | |
8823 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8824 | struct sk_buff *msg; | |
8825 | void *hdr; | |
2a0e047e | 8826 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 8827 | |
964dc9e2 | 8828 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
8829 | return -EOPNOTSUPP; |
8830 | ||
6abb9cb9 | 8831 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 8832 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
8833 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
8834 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
8835 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
8836 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
8837 | } |
8838 | ||
8839 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
8840 | if (!msg) |
8841 | return -ENOMEM; | |
8842 | ||
15e47304 | 8843 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
8844 | NL80211_CMD_GET_WOWLAN); |
8845 | if (!hdr) | |
8846 | goto nla_put_failure; | |
8847 | ||
6abb9cb9 | 8848 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
8849 | struct nlattr *nl_wowlan; |
8850 | ||
8851 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
8852 | if (!nl_wowlan) | |
8853 | goto nla_put_failure; | |
8854 | ||
6abb9cb9 | 8855 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 8856 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 8857 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 8858 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 8859 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 8860 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 8861 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 8862 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 8863 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 8864 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 8865 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 8866 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 8867 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
8868 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
8869 | goto nla_put_failure; | |
2a0e047e | 8870 | |
bb92d199 AK |
8871 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
8872 | goto nla_put_failure; | |
2a0e047e | 8873 | |
6abb9cb9 JB |
8874 | if (nl80211_send_wowlan_tcp(msg, |
8875 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e | 8876 | goto nla_put_failure; |
75453ccb LC |
8877 | |
8878 | if (nl80211_send_wowlan_nd( | |
8879 | msg, | |
8880 | rdev->wiphy.wowlan_config->nd_config)) | |
8881 | goto nla_put_failure; | |
2a0e047e | 8882 | |
ff1b6e69 JB |
8883 | nla_nest_end(msg, nl_wowlan); |
8884 | } | |
8885 | ||
8886 | genlmsg_end(msg, hdr); | |
8887 | return genlmsg_reply(msg, info); | |
8888 | ||
8889 | nla_put_failure: | |
8890 | nlmsg_free(msg); | |
8891 | return -ENOBUFS; | |
8892 | } | |
8893 | ||
2a0e047e JB |
8894 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
8895 | struct nlattr *attr, | |
8896 | struct cfg80211_wowlan *trig) | |
8897 | { | |
8898 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
8899 | struct cfg80211_wowlan_tcp *cfg; | |
8900 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
8901 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
8902 | u32 size; | |
8903 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
8904 | int err, port; | |
8905 | ||
964dc9e2 | 8906 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
8907 | return -EINVAL; |
8908 | ||
8909 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
8910 | nla_data(attr), nla_len(attr), | |
8911 | nl80211_wowlan_tcp_policy); | |
8912 | if (err) | |
8913 | return err; | |
8914 | ||
8915 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
8916 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
8917 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
8918 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
8919 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
8920 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
8921 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
8922 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
8923 | return -EINVAL; | |
8924 | ||
8925 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 8926 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
8927 | return -EINVAL; |
8928 | ||
8929 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 8930 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 8931 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
8932 | return -EINVAL; |
8933 | ||
8934 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 8935 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
8936 | return -EINVAL; |
8937 | ||
8938 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
8939 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
8940 | return -EINVAL; | |
8941 | ||
8942 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
8943 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8944 | ||
8945 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8946 | tokens_size = tokln - sizeof(*tok); | |
8947 | ||
8948 | if (!tok->len || tokens_size % tok->len) | |
8949 | return -EINVAL; | |
964dc9e2 | 8950 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 8951 | return -EINVAL; |
964dc9e2 | 8952 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 8953 | return -EINVAL; |
964dc9e2 | 8954 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 8955 | return -EINVAL; |
964dc9e2 | 8956 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
8957 | return -EINVAL; |
8958 | if (tok->offset + tok->len > data_size) | |
8959 | return -EINVAL; | |
8960 | } | |
8961 | ||
8962 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
8963 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 8964 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
8965 | return -EINVAL; |
8966 | if (seq->len == 0 || seq->len > 4) | |
8967 | return -EINVAL; | |
8968 | if (seq->len + seq->offset > data_size) | |
8969 | return -EINVAL; | |
8970 | } | |
8971 | ||
8972 | size = sizeof(*cfg); | |
8973 | size += data_size; | |
8974 | size += wake_size + wake_mask_size; | |
8975 | size += tokens_size; | |
8976 | ||
8977 | cfg = kzalloc(size, GFP_KERNEL); | |
8978 | if (!cfg) | |
8979 | return -ENOMEM; | |
8980 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
8981 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
8982 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
8983 | ETH_ALEN); | |
8984 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
8985 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
8986 | else | |
8987 | port = 0; | |
8988 | #ifdef CONFIG_INET | |
8989 | /* allocate a socket and port for it and use it */ | |
8990 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
8991 | IPPROTO_TCP, &cfg->sock, 1); | |
8992 | if (err) { | |
8993 | kfree(cfg); | |
8994 | return err; | |
8995 | } | |
8996 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
8997 | sock_release(cfg->sock); | |
8998 | kfree(cfg); | |
8999 | return -EADDRINUSE; | |
9000 | } | |
9001 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
9002 | #else | |
9003 | if (!port) { | |
9004 | kfree(cfg); | |
9005 | return -EINVAL; | |
9006 | } | |
9007 | cfg->src_port = port; | |
9008 | #endif | |
9009 | ||
9010 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
9011 | cfg->payload_len = data_size; | |
9012 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
9013 | memcpy((void *)cfg->payload, | |
9014 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
9015 | data_size); | |
9016 | if (seq) | |
9017 | cfg->payload_seq = *seq; | |
9018 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
9019 | cfg->wake_len = wake_size; | |
9020 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
9021 | memcpy((void *)cfg->wake_data, | |
9022 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
9023 | wake_size); | |
9024 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
9025 | data_size + wake_size; | |
9026 | memcpy((void *)cfg->wake_mask, | |
9027 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
9028 | wake_mask_size); | |
9029 | if (tok) { | |
9030 | cfg->tokens_size = tokens_size; | |
9031 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
9032 | } | |
9033 | ||
9034 | trig->tcp = cfg; | |
9035 | ||
9036 | return 0; | |
9037 | } | |
9038 | ||
8cd4d456 LC |
9039 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
9040 | const struct wiphy_wowlan_support *wowlan, | |
9041 | struct nlattr *attr, | |
9042 | struct cfg80211_wowlan *trig) | |
9043 | { | |
9044 | struct nlattr **tb; | |
9045 | int err; | |
9046 | ||
9047 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); | |
9048 | if (!tb) | |
9049 | return -ENOMEM; | |
9050 | ||
9051 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | |
9052 | err = -EOPNOTSUPP; | |
9053 | goto out; | |
9054 | } | |
9055 | ||
9056 | err = nla_parse(tb, NL80211_ATTR_MAX, | |
9057 | nla_data(attr), nla_len(attr), | |
9058 | nl80211_policy); | |
9059 | if (err) | |
9060 | goto out; | |
9061 | ||
ad2b26ab | 9062 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
8cd4d456 LC |
9063 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
9064 | if (err) | |
9065 | trig->nd_config = NULL; | |
9066 | ||
9067 | out: | |
9068 | kfree(tb); | |
9069 | return err; | |
9070 | } | |
9071 | ||
ff1b6e69 JB |
9072 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
9073 | { | |
9074 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9075 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 9076 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 9077 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 9078 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 9079 | int err, i; |
6abb9cb9 | 9080 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 9081 | |
964dc9e2 | 9082 | if (!wowlan) |
ff1b6e69 JB |
9083 | return -EOPNOTSUPP; |
9084 | ||
ae33bd81 JB |
9085 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
9086 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 9087 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
9088 | goto set_wakeup; |
9089 | } | |
ff1b6e69 JB |
9090 | |
9091 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
9092 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9093 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9094 | nl80211_wowlan_policy); | |
9095 | if (err) | |
9096 | return err; | |
9097 | ||
9098 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
9099 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
9100 | return -EINVAL; | |
9101 | new_triggers.any = true; | |
9102 | } | |
9103 | ||
9104 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
9105 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
9106 | return -EINVAL; | |
9107 | new_triggers.disconnect = true; | |
9108 | } | |
9109 | ||
9110 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
9111 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
9112 | return -EINVAL; | |
9113 | new_triggers.magic_pkt = true; | |
9114 | } | |
9115 | ||
77dbbb13 JB |
9116 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
9117 | return -EINVAL; | |
9118 | ||
9119 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
9120 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
9121 | return -EINVAL; | |
9122 | new_triggers.gtk_rekey_failure = true; | |
9123 | } | |
9124 | ||
9125 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
9126 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
9127 | return -EINVAL; | |
9128 | new_triggers.eap_identity_req = true; | |
9129 | } | |
9130 | ||
9131 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
9132 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
9133 | return -EINVAL; | |
9134 | new_triggers.four_way_handshake = true; | |
9135 | } | |
9136 | ||
9137 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
9138 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
9139 | return -EINVAL; | |
9140 | new_triggers.rfkill_release = true; | |
9141 | } | |
9142 | ||
ff1b6e69 JB |
9143 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
9144 | struct nlattr *pat; | |
9145 | int n_patterns = 0; | |
bb92d199 | 9146 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 9147 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 JB |
9148 | |
9149 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9150 | rem) | |
9151 | n_patterns++; | |
9152 | if (n_patterns > wowlan->n_patterns) | |
9153 | return -EINVAL; | |
9154 | ||
9155 | new_triggers.patterns = kcalloc(n_patterns, | |
9156 | sizeof(new_triggers.patterns[0]), | |
9157 | GFP_KERNEL); | |
9158 | if (!new_triggers.patterns) | |
9159 | return -ENOMEM; | |
9160 | ||
9161 | new_triggers.n_patterns = n_patterns; | |
9162 | i = 0; | |
9163 | ||
9164 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9165 | rem) { | |
922bd80f JB |
9166 | u8 *mask_pat; |
9167 | ||
50ac6607 AK |
9168 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9169 | nla_len(pat), NULL); | |
ff1b6e69 | 9170 | err = -EINVAL; |
50ac6607 AK |
9171 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
9172 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 9173 | goto error; |
50ac6607 | 9174 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 9175 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 9176 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
9177 | goto error; |
9178 | if (pat_len > wowlan->pattern_max_len || | |
9179 | pat_len < wowlan->pattern_min_len) | |
9180 | goto error; | |
9181 | ||
50ac6607 | 9182 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
9183 | pkt_offset = 0; |
9184 | else | |
9185 | pkt_offset = nla_get_u32( | |
50ac6607 | 9186 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
9187 | if (pkt_offset > wowlan->max_pkt_offset) |
9188 | goto error; | |
9189 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
9190 | ||
922bd80f JB |
9191 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9192 | if (!mask_pat) { | |
ff1b6e69 JB |
9193 | err = -ENOMEM; |
9194 | goto error; | |
9195 | } | |
922bd80f JB |
9196 | new_triggers.patterns[i].mask = mask_pat; |
9197 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 9198 | mask_len); |
922bd80f JB |
9199 | mask_pat += mask_len; |
9200 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 9201 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 9202 | memcpy(mask_pat, |
50ac6607 | 9203 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
9204 | pat_len); |
9205 | i++; | |
9206 | } | |
9207 | } | |
9208 | ||
2a0e047e JB |
9209 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
9210 | err = nl80211_parse_wowlan_tcp( | |
9211 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
9212 | &new_triggers); | |
9213 | if (err) | |
9214 | goto error; | |
9215 | } | |
9216 | ||
8cd4d456 LC |
9217 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
9218 | err = nl80211_parse_wowlan_nd( | |
9219 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | |
9220 | &new_triggers); | |
9221 | if (err) | |
9222 | goto error; | |
9223 | } | |
9224 | ||
ae33bd81 JB |
9225 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
9226 | if (!ntrig) { | |
9227 | err = -ENOMEM; | |
9228 | goto error; | |
ff1b6e69 | 9229 | } |
ae33bd81 | 9230 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 9231 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 9232 | |
ae33bd81 | 9233 | set_wakeup: |
6abb9cb9 JB |
9234 | if (rdev->ops->set_wakeup && |
9235 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
9236 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 9237 | |
ff1b6e69 JB |
9238 | return 0; |
9239 | error: | |
9240 | for (i = 0; i < new_triggers.n_patterns; i++) | |
9241 | kfree(new_triggers.patterns[i].mask); | |
9242 | kfree(new_triggers.patterns); | |
2a0e047e JB |
9243 | if (new_triggers.tcp && new_triggers.tcp->sock) |
9244 | sock_release(new_triggers.tcp->sock); | |
9245 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
9246 | return err; |
9247 | } | |
dfb89c56 | 9248 | #endif |
ff1b6e69 | 9249 | |
be29b99a AK |
9250 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
9251 | struct cfg80211_registered_device *rdev) | |
9252 | { | |
9253 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
9254 | int i, j, pat_len; | |
9255 | struct cfg80211_coalesce_rules *rule; | |
9256 | ||
9257 | if (!rdev->coalesce->n_rules) | |
9258 | return 0; | |
9259 | ||
9260 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
9261 | if (!nl_rules) | |
9262 | return -ENOBUFS; | |
9263 | ||
9264 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
9265 | nl_rule = nla_nest_start(msg, i + 1); | |
9266 | if (!nl_rule) | |
9267 | return -ENOBUFS; | |
9268 | ||
9269 | rule = &rdev->coalesce->rules[i]; | |
9270 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
9271 | rule->delay)) | |
9272 | return -ENOBUFS; | |
9273 | ||
9274 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
9275 | rule->condition)) | |
9276 | return -ENOBUFS; | |
9277 | ||
9278 | nl_pats = nla_nest_start(msg, | |
9279 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
9280 | if (!nl_pats) | |
9281 | return -ENOBUFS; | |
9282 | ||
9283 | for (j = 0; j < rule->n_patterns; j++) { | |
9284 | nl_pat = nla_nest_start(msg, j + 1); | |
9285 | if (!nl_pat) | |
9286 | return -ENOBUFS; | |
9287 | pat_len = rule->patterns[j].pattern_len; | |
9288 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
9289 | DIV_ROUND_UP(pat_len, 8), | |
9290 | rule->patterns[j].mask) || | |
9291 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
9292 | rule->patterns[j].pattern) || | |
9293 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
9294 | rule->patterns[j].pkt_offset)) | |
9295 | return -ENOBUFS; | |
9296 | nla_nest_end(msg, nl_pat); | |
9297 | } | |
9298 | nla_nest_end(msg, nl_pats); | |
9299 | nla_nest_end(msg, nl_rule); | |
9300 | } | |
9301 | nla_nest_end(msg, nl_rules); | |
9302 | ||
9303 | return 0; | |
9304 | } | |
9305 | ||
9306 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9307 | { | |
9308 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9309 | struct sk_buff *msg; | |
9310 | void *hdr; | |
9311 | ||
9312 | if (!rdev->wiphy.coalesce) | |
9313 | return -EOPNOTSUPP; | |
9314 | ||
9315 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9316 | if (!msg) | |
9317 | return -ENOMEM; | |
9318 | ||
9319 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9320 | NL80211_CMD_GET_COALESCE); | |
9321 | if (!hdr) | |
9322 | goto nla_put_failure; | |
9323 | ||
9324 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
9325 | goto nla_put_failure; | |
9326 | ||
9327 | genlmsg_end(msg, hdr); | |
9328 | return genlmsg_reply(msg, info); | |
9329 | ||
9330 | nla_put_failure: | |
9331 | nlmsg_free(msg); | |
9332 | return -ENOBUFS; | |
9333 | } | |
9334 | ||
9335 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
9336 | { | |
9337 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
9338 | int i, j; | |
9339 | struct cfg80211_coalesce_rules *rule; | |
9340 | ||
9341 | if (!coalesce) | |
9342 | return; | |
9343 | ||
9344 | for (i = 0; i < coalesce->n_rules; i++) { | |
9345 | rule = &coalesce->rules[i]; | |
9346 | for (j = 0; j < rule->n_patterns; j++) | |
9347 | kfree(rule->patterns[j].mask); | |
9348 | kfree(rule->patterns); | |
9349 | } | |
9350 | kfree(coalesce->rules); | |
9351 | kfree(coalesce); | |
9352 | rdev->coalesce = NULL; | |
9353 | } | |
9354 | ||
9355 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
9356 | struct nlattr *rule, | |
9357 | struct cfg80211_coalesce_rules *new_rule) | |
9358 | { | |
9359 | int err, i; | |
9360 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9361 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
9362 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
9363 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
9364 | ||
9365 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
9366 | nla_len(rule), nl80211_coalesce_policy); | |
9367 | if (err) | |
9368 | return err; | |
9369 | ||
9370 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
9371 | new_rule->delay = | |
9372 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
9373 | if (new_rule->delay > coalesce->max_delay) | |
9374 | return -EINVAL; | |
9375 | ||
9376 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
9377 | new_rule->condition = | |
9378 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
9379 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
9380 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
9381 | return -EINVAL; | |
9382 | ||
9383 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
9384 | return -EINVAL; | |
9385 | ||
9386 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9387 | rem) | |
9388 | n_patterns++; | |
9389 | if (n_patterns > coalesce->n_patterns) | |
9390 | return -EINVAL; | |
9391 | ||
9392 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
9393 | GFP_KERNEL); | |
9394 | if (!new_rule->patterns) | |
9395 | return -ENOMEM; | |
9396 | ||
9397 | new_rule->n_patterns = n_patterns; | |
9398 | i = 0; | |
9399 | ||
9400 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9401 | rem) { | |
922bd80f JB |
9402 | u8 *mask_pat; |
9403 | ||
be29b99a AK |
9404 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9405 | nla_len(pat), NULL); | |
9406 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
9407 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
9408 | return -EINVAL; | |
9409 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
9410 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
9411 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
9412 | return -EINVAL; | |
9413 | if (pat_len > coalesce->pattern_max_len || | |
9414 | pat_len < coalesce->pattern_min_len) | |
9415 | return -EINVAL; | |
9416 | ||
9417 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
9418 | pkt_offset = 0; | |
9419 | else | |
9420 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
9421 | if (pkt_offset > coalesce->max_pkt_offset) | |
9422 | return -EINVAL; | |
9423 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
9424 | ||
922bd80f JB |
9425 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9426 | if (!mask_pat) | |
be29b99a | 9427 | return -ENOMEM; |
922bd80f JB |
9428 | |
9429 | new_rule->patterns[i].mask = mask_pat; | |
9430 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
9431 | mask_len); | |
9432 | ||
9433 | mask_pat += mask_len; | |
9434 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 9435 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
9436 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
9437 | pat_len); | |
be29b99a AK |
9438 | i++; |
9439 | } | |
9440 | ||
9441 | return 0; | |
9442 | } | |
9443 | ||
9444 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9445 | { | |
9446 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9447 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9448 | struct cfg80211_coalesce new_coalesce = {}; | |
9449 | struct cfg80211_coalesce *n_coalesce; | |
9450 | int err, rem_rule, n_rules = 0, i, j; | |
9451 | struct nlattr *rule; | |
9452 | struct cfg80211_coalesce_rules *tmp_rule; | |
9453 | ||
9454 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
9455 | return -EOPNOTSUPP; | |
9456 | ||
9457 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
9458 | cfg80211_rdev_free_coalesce(rdev); | |
9459 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
9460 | return 0; | |
9461 | } | |
9462 | ||
9463 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9464 | rem_rule) | |
9465 | n_rules++; | |
9466 | if (n_rules > coalesce->n_rules) | |
9467 | return -EINVAL; | |
9468 | ||
9469 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
9470 | GFP_KERNEL); | |
9471 | if (!new_coalesce.rules) | |
9472 | return -ENOMEM; | |
9473 | ||
9474 | new_coalesce.n_rules = n_rules; | |
9475 | i = 0; | |
9476 | ||
9477 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9478 | rem_rule) { | |
9479 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
9480 | &new_coalesce.rules[i]); | |
9481 | if (err) | |
9482 | goto error; | |
9483 | ||
9484 | i++; | |
9485 | } | |
9486 | ||
9487 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
9488 | if (err) | |
9489 | goto error; | |
9490 | ||
9491 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
9492 | if (!n_coalesce) { | |
9493 | err = -ENOMEM; | |
9494 | goto error; | |
9495 | } | |
9496 | cfg80211_rdev_free_coalesce(rdev); | |
9497 | rdev->coalesce = n_coalesce; | |
9498 | ||
9499 | return 0; | |
9500 | error: | |
9501 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
9502 | tmp_rule = &new_coalesce.rules[i]; | |
9503 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
9504 | kfree(tmp_rule->patterns[j].mask); | |
9505 | kfree(tmp_rule->patterns); | |
9506 | } | |
9507 | kfree(new_coalesce.rules); | |
9508 | ||
9509 | return err; | |
9510 | } | |
9511 | ||
e5497d76 JB |
9512 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
9513 | { | |
9514 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9515 | struct net_device *dev = info->user_ptr[1]; | |
9516 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9517 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
9518 | struct cfg80211_gtk_rekey_data rekey_data; | |
9519 | int err; | |
9520 | ||
9521 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
9522 | return -EINVAL; | |
9523 | ||
9524 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
9525 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9526 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9527 | nl80211_rekey_policy); | |
9528 | if (err) | |
9529 | return err; | |
9530 | ||
9531 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
9532 | return -ERANGE; | |
9533 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
9534 | return -ERANGE; | |
9535 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
9536 | return -ERANGE; | |
9537 | ||
78f686ca JB |
9538 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
9539 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | |
9540 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | |
e5497d76 JB |
9541 | |
9542 | wdev_lock(wdev); | |
9543 | if (!wdev->current_bss) { | |
9544 | err = -ENOTCONN; | |
9545 | goto out; | |
9546 | } | |
9547 | ||
9548 | if (!rdev->ops->set_rekey_data) { | |
9549 | err = -EOPNOTSUPP; | |
9550 | goto out; | |
9551 | } | |
9552 | ||
e35e4d28 | 9553 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
9554 | out: |
9555 | wdev_unlock(wdev); | |
9556 | return err; | |
9557 | } | |
9558 | ||
28946da7 JB |
9559 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
9560 | struct genl_info *info) | |
9561 | { | |
9562 | struct net_device *dev = info->user_ptr[1]; | |
9563 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9564 | ||
9565 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9566 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9567 | return -EINVAL; | |
9568 | ||
15e47304 | 9569 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
9570 | return -EBUSY; |
9571 | ||
15e47304 | 9572 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
9573 | return 0; |
9574 | } | |
9575 | ||
7f6cf311 JB |
9576 | static int nl80211_probe_client(struct sk_buff *skb, |
9577 | struct genl_info *info) | |
9578 | { | |
9579 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9580 | struct net_device *dev = info->user_ptr[1]; | |
9581 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9582 | struct sk_buff *msg; | |
9583 | void *hdr; | |
9584 | const u8 *addr; | |
9585 | u64 cookie; | |
9586 | int err; | |
9587 | ||
9588 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9589 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9590 | return -EOPNOTSUPP; | |
9591 | ||
9592 | if (!info->attrs[NL80211_ATTR_MAC]) | |
9593 | return -EINVAL; | |
9594 | ||
9595 | if (!rdev->ops->probe_client) | |
9596 | return -EOPNOTSUPP; | |
9597 | ||
9598 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9599 | if (!msg) | |
9600 | return -ENOMEM; | |
9601 | ||
15e47304 | 9602 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 9603 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
9604 | if (!hdr) { |
9605 | err = -ENOBUFS; | |
7f6cf311 JB |
9606 | goto free_msg; |
9607 | } | |
9608 | ||
9609 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9610 | ||
e35e4d28 | 9611 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
9612 | if (err) |
9613 | goto free_msg; | |
9614 | ||
9360ffd1 DM |
9615 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9616 | goto nla_put_failure; | |
7f6cf311 JB |
9617 | |
9618 | genlmsg_end(msg, hdr); | |
9619 | ||
9620 | return genlmsg_reply(msg, info); | |
9621 | ||
9622 | nla_put_failure: | |
9623 | err = -ENOBUFS; | |
9624 | free_msg: | |
9625 | nlmsg_free(msg); | |
9626 | return err; | |
9627 | } | |
9628 | ||
5e760230 JB |
9629 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
9630 | { | |
9631 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
9632 | struct cfg80211_beacon_registration *reg, *nreg; |
9633 | int rv; | |
5e760230 JB |
9634 | |
9635 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
9636 | return -EOPNOTSUPP; | |
9637 | ||
37c73b5f BG |
9638 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
9639 | if (!nreg) | |
9640 | return -ENOMEM; | |
9641 | ||
9642 | /* First, check if already registered. */ | |
9643 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
9644 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
9645 | if (reg->nlportid == info->snd_portid) { | |
9646 | rv = -EALREADY; | |
9647 | goto out_err; | |
9648 | } | |
9649 | } | |
9650 | /* Add it to the list */ | |
9651 | nreg->nlportid = info->snd_portid; | |
9652 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 9653 | |
37c73b5f | 9654 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
9655 | |
9656 | return 0; | |
37c73b5f BG |
9657 | out_err: |
9658 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
9659 | kfree(nreg); | |
9660 | return rv; | |
5e760230 JB |
9661 | } |
9662 | ||
98104fde JB |
9663 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
9664 | { | |
9665 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9666 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9667 | int err; | |
9668 | ||
9669 | if (!rdev->ops->start_p2p_device) | |
9670 | return -EOPNOTSUPP; | |
9671 | ||
9672 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9673 | return -EOPNOTSUPP; | |
9674 | ||
9675 | if (wdev->p2p_started) | |
9676 | return 0; | |
9677 | ||
b6a55015 LC |
9678 | if (rfkill_blocked(rdev->rfkill)) |
9679 | return -ERFKILL; | |
98104fde | 9680 | |
eeb126e9 | 9681 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
9682 | if (err) |
9683 | return err; | |
9684 | ||
9685 | wdev->p2p_started = true; | |
98104fde | 9686 | rdev->opencount++; |
98104fde JB |
9687 | |
9688 | return 0; | |
9689 | } | |
9690 | ||
9691 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
9692 | { | |
9693 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9694 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9695 | ||
9696 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9697 | return -EOPNOTSUPP; | |
9698 | ||
9699 | if (!rdev->ops->stop_p2p_device) | |
9700 | return -EOPNOTSUPP; | |
9701 | ||
f9f47529 | 9702 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
9703 | |
9704 | return 0; | |
9705 | } | |
9706 | ||
3713b4e3 JB |
9707 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
9708 | struct genl_info *info) | |
9709 | { | |
9710 | void *hdr; | |
9711 | struct sk_buff *msg; | |
9712 | ||
9713 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9714 | if (!msg) | |
9715 | return -ENOMEM; | |
9716 | ||
9717 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9718 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
9719 | if (!hdr) | |
9720 | goto nla_put_failure; | |
9721 | ||
9722 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
9723 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
9724 | goto nla_put_failure; | |
9725 | ||
9726 | genlmsg_end(msg, hdr); | |
9727 | return genlmsg_reply(msg, info); | |
9728 | ||
9729 | nla_put_failure: | |
9730 | kfree_skb(msg); | |
9731 | return -ENOBUFS; | |
9732 | } | |
9733 | ||
355199e0 JM |
9734 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
9735 | { | |
9736 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9737 | struct cfg80211_update_ft_ies_params ft_params; | |
9738 | struct net_device *dev = info->user_ptr[1]; | |
9739 | ||
9740 | if (!rdev->ops->update_ft_ies) | |
9741 | return -EOPNOTSUPP; | |
9742 | ||
9743 | if (!info->attrs[NL80211_ATTR_MDID] || | |
9744 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
9745 | return -EINVAL; | |
9746 | ||
9747 | memset(&ft_params, 0, sizeof(ft_params)); | |
9748 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
9749 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
9750 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9751 | ||
9752 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
9753 | } | |
9754 | ||
5de17984 AS |
9755 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
9756 | struct genl_info *info) | |
9757 | { | |
9758 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9759 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9760 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
9761 | u16 duration; | |
9762 | int ret; | |
9763 | ||
9764 | if (!rdev->ops->crit_proto_start) | |
9765 | return -EOPNOTSUPP; | |
9766 | ||
9767 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
9768 | return -EINVAL; | |
9769 | ||
9770 | if (rdev->crit_proto_nlportid) | |
9771 | return -EBUSY; | |
9772 | ||
9773 | /* determine protocol if provided */ | |
9774 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
9775 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
9776 | ||
9777 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
9778 | return -EINVAL; | |
9779 | ||
9780 | /* timeout must be provided */ | |
9781 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
9782 | return -EINVAL; | |
9783 | ||
9784 | duration = | |
9785 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
9786 | ||
9787 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
9788 | return -ERANGE; | |
9789 | ||
9790 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
9791 | if (!ret) | |
9792 | rdev->crit_proto_nlportid = info->snd_portid; | |
9793 | ||
9794 | return ret; | |
9795 | } | |
9796 | ||
9797 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
9798 | struct genl_info *info) | |
9799 | { | |
9800 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9801 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9802 | ||
9803 | if (!rdev->ops->crit_proto_stop) | |
9804 | return -EOPNOTSUPP; | |
9805 | ||
9806 | if (rdev->crit_proto_nlportid) { | |
9807 | rdev->crit_proto_nlportid = 0; | |
9808 | rdev_crit_proto_stop(rdev, wdev); | |
9809 | } | |
9810 | return 0; | |
9811 | } | |
9812 | ||
ad7e718c JB |
9813 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
9814 | { | |
9815 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9816 | struct wireless_dev *wdev = | |
9817 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
9818 | int i, err; | |
9819 | u32 vid, subcmd; | |
9820 | ||
9821 | if (!rdev->wiphy.vendor_commands) | |
9822 | return -EOPNOTSUPP; | |
9823 | ||
9824 | if (IS_ERR(wdev)) { | |
9825 | err = PTR_ERR(wdev); | |
9826 | if (err != -EINVAL) | |
9827 | return err; | |
9828 | wdev = NULL; | |
9829 | } else if (wdev->wiphy != &rdev->wiphy) { | |
9830 | return -EINVAL; | |
9831 | } | |
9832 | ||
9833 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
9834 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
9835 | return -EINVAL; | |
9836 | ||
9837 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
9838 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
9839 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
9840 | const struct wiphy_vendor_command *vcmd; | |
9841 | void *data = NULL; | |
9842 | int len = 0; | |
9843 | ||
9844 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
9845 | ||
9846 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
9847 | continue; | |
9848 | ||
9849 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
9850 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
9851 | if (!wdev) | |
9852 | return -EINVAL; | |
9853 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
9854 | !wdev->netdev) | |
9855 | return -EINVAL; | |
9856 | ||
9857 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
9858 | if (wdev->netdev && | |
9859 | !netif_running(wdev->netdev)) | |
9860 | return -ENETDOWN; | |
9861 | if (!wdev->netdev && !wdev->p2p_started) | |
9862 | return -ENETDOWN; | |
9863 | } | |
9864 | } else { | |
9865 | wdev = NULL; | |
9866 | } | |
9867 | ||
9868 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
9869 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9870 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9871 | } | |
9872 | ||
9873 | rdev->cur_cmd_info = info; | |
9874 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
9875 | data, len); | |
9876 | rdev->cur_cmd_info = NULL; | |
9877 | return err; | |
9878 | } | |
9879 | ||
9880 | return -EOPNOTSUPP; | |
9881 | } | |
9882 | ||
9883 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | |
9884 | enum nl80211_commands cmd, | |
9885 | enum nl80211_attrs attr, | |
9886 | int approxlen) | |
9887 | { | |
f26cbf40 | 9888 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
9889 | |
9890 | if (WARN_ON(!rdev->cur_cmd_info)) | |
9891 | return NULL; | |
9892 | ||
9893 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, | |
9894 | rdev->cur_cmd_info->snd_portid, | |
9895 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 9896 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
9897 | } |
9898 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
9899 | ||
9900 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
9901 | { | |
9902 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
9903 | void *hdr = ((void **)skb->cb)[1]; | |
9904 | struct nlattr *data = ((void **)skb->cb)[2]; | |
9905 | ||
bd8c78e7 JB |
9906 | /* clear CB data for netlink core to own from now on */ |
9907 | memset(skb->cb, 0, sizeof(skb->cb)); | |
9908 | ||
ad7e718c JB |
9909 | if (WARN_ON(!rdev->cur_cmd_info)) { |
9910 | kfree_skb(skb); | |
9911 | return -EINVAL; | |
9912 | } | |
9913 | ||
9914 | nla_nest_end(skb, data); | |
9915 | genlmsg_end(skb, hdr); | |
9916 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
9917 | } | |
9918 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
9919 | ||
9920 | ||
fa9ffc74 KP |
9921 | static int nl80211_set_qos_map(struct sk_buff *skb, |
9922 | struct genl_info *info) | |
9923 | { | |
9924 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9925 | struct cfg80211_qos_map *qos_map = NULL; | |
9926 | struct net_device *dev = info->user_ptr[1]; | |
9927 | u8 *pos, len, num_des, des_len, des; | |
9928 | int ret; | |
9929 | ||
9930 | if (!rdev->ops->set_qos_map) | |
9931 | return -EOPNOTSUPP; | |
9932 | ||
9933 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
9934 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9935 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9936 | ||
9937 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
9938 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
9939 | return -EINVAL; | |
9940 | ||
9941 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
9942 | if (!qos_map) | |
9943 | return -ENOMEM; | |
9944 | ||
9945 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
9946 | if (num_des) { | |
9947 | des_len = num_des * | |
9948 | sizeof(struct cfg80211_dscp_exception); | |
9949 | memcpy(qos_map->dscp_exception, pos, des_len); | |
9950 | qos_map->num_des = num_des; | |
9951 | for (des = 0; des < num_des; des++) { | |
9952 | if (qos_map->dscp_exception[des].up > 7) { | |
9953 | kfree(qos_map); | |
9954 | return -EINVAL; | |
9955 | } | |
9956 | } | |
9957 | pos += des_len; | |
9958 | } | |
9959 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
9960 | } | |
9961 | ||
9962 | wdev_lock(dev->ieee80211_ptr); | |
9963 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
9964 | if (!ret) | |
9965 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
9966 | wdev_unlock(dev->ieee80211_ptr); | |
9967 | ||
9968 | kfree(qos_map); | |
9969 | return ret; | |
9970 | } | |
9971 | ||
960d01ac JB |
9972 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
9973 | { | |
9974 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9975 | struct net_device *dev = info->user_ptr[1]; | |
9976 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9977 | const u8 *peer; | |
9978 | u8 tsid, up; | |
9979 | u16 admitted_time = 0; | |
9980 | int err; | |
9981 | ||
723e73ac | 9982 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
960d01ac JB |
9983 | return -EOPNOTSUPP; |
9984 | ||
9985 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | |
9986 | !info->attrs[NL80211_ATTR_USER_PRIO]) | |
9987 | return -EINVAL; | |
9988 | ||
9989 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
9990 | if (tsid >= IEEE80211_NUM_TIDS) | |
9991 | return -EINVAL; | |
9992 | ||
9993 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); | |
9994 | if (up >= IEEE80211_NUM_UPS) | |
9995 | return -EINVAL; | |
9996 | ||
9997 | /* WMM uses TIDs 0-7 even for TSPEC */ | |
723e73ac | 9998 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
960d01ac | 9999 | /* TODO: handle 802.11 TSPEC/admission control |
723e73ac JB |
10000 | * need more attributes for that (e.g. BA session requirement); |
10001 | * change the WMM adminssion test above to allow both then | |
960d01ac JB |
10002 | */ |
10003 | return -EINVAL; | |
10004 | } | |
10005 | ||
10006 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10007 | ||
10008 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | |
10009 | admitted_time = | |
10010 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | |
10011 | if (!admitted_time) | |
10012 | return -EINVAL; | |
10013 | } | |
10014 | ||
10015 | wdev_lock(wdev); | |
10016 | switch (wdev->iftype) { | |
10017 | case NL80211_IFTYPE_STATION: | |
10018 | case NL80211_IFTYPE_P2P_CLIENT: | |
10019 | if (wdev->current_bss) | |
10020 | break; | |
10021 | err = -ENOTCONN; | |
10022 | goto out; | |
10023 | default: | |
10024 | err = -EOPNOTSUPP; | |
10025 | goto out; | |
10026 | } | |
10027 | ||
10028 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | |
10029 | ||
10030 | out: | |
10031 | wdev_unlock(wdev); | |
10032 | return err; | |
10033 | } | |
10034 | ||
10035 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | |
10036 | { | |
10037 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10038 | struct net_device *dev = info->user_ptr[1]; | |
10039 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10040 | const u8 *peer; | |
10041 | u8 tsid; | |
10042 | int err; | |
10043 | ||
10044 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | |
10045 | return -EINVAL; | |
10046 | ||
10047 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
10048 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10049 | ||
10050 | wdev_lock(wdev); | |
10051 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | |
10052 | wdev_unlock(wdev); | |
10053 | ||
10054 | return err; | |
10055 | } | |
10056 | ||
1057d35e AN |
10057 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
10058 | struct genl_info *info) | |
10059 | { | |
10060 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10061 | struct net_device *dev = info->user_ptr[1]; | |
10062 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10063 | struct cfg80211_chan_def chandef = {}; | |
10064 | const u8 *addr; | |
10065 | u8 oper_class; | |
10066 | int err; | |
10067 | ||
10068 | if (!rdev->ops->tdls_channel_switch || | |
10069 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
10070 | return -EOPNOTSUPP; | |
10071 | ||
10072 | switch (dev->ieee80211_ptr->iftype) { | |
10073 | case NL80211_IFTYPE_STATION: | |
10074 | case NL80211_IFTYPE_P2P_CLIENT: | |
10075 | break; | |
10076 | default: | |
10077 | return -EOPNOTSUPP; | |
10078 | } | |
10079 | ||
10080 | if (!info->attrs[NL80211_ATTR_MAC] || | |
10081 | !info->attrs[NL80211_ATTR_OPER_CLASS]) | |
10082 | return -EINVAL; | |
10083 | ||
10084 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
10085 | if (err) | |
10086 | return err; | |
10087 | ||
10088 | /* | |
10089 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | |
10090 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | |
10091 | * specification is not defined for them. | |
10092 | */ | |
10093 | if (chandef.chan->band == IEEE80211_BAND_2GHZ && | |
10094 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | |
10095 | chandef.width != NL80211_CHAN_WIDTH_20) | |
10096 | return -EINVAL; | |
10097 | ||
10098 | /* we will be active on the TDLS link */ | |
10099 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype)) | |
10100 | return -EINVAL; | |
10101 | ||
10102 | /* don't allow switching to DFS channels */ | |
10103 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | |
10104 | return -EINVAL; | |
10105 | ||
10106 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10107 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | |
10108 | ||
10109 | wdev_lock(wdev); | |
10110 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | |
10111 | wdev_unlock(wdev); | |
10112 | ||
10113 | return err; | |
10114 | } | |
10115 | ||
10116 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | |
10117 | struct genl_info *info) | |
10118 | { | |
10119 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10120 | struct net_device *dev = info->user_ptr[1]; | |
10121 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10122 | const u8 *addr; | |
10123 | ||
10124 | if (!rdev->ops->tdls_channel_switch || | |
10125 | !rdev->ops->tdls_cancel_channel_switch || | |
10126 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
10127 | return -EOPNOTSUPP; | |
10128 | ||
10129 | switch (dev->ieee80211_ptr->iftype) { | |
10130 | case NL80211_IFTYPE_STATION: | |
10131 | case NL80211_IFTYPE_P2P_CLIENT: | |
10132 | break; | |
10133 | default: | |
10134 | return -EOPNOTSUPP; | |
10135 | } | |
10136 | ||
10137 | if (!info->attrs[NL80211_ATTR_MAC]) | |
10138 | return -EINVAL; | |
10139 | ||
10140 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10141 | ||
10142 | wdev_lock(wdev); | |
10143 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); | |
10144 | wdev_unlock(wdev); | |
10145 | ||
10146 | return 0; | |
10147 | } | |
10148 | ||
4c476991 JB |
10149 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
10150 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
10151 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
10152 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
10153 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
10154 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 10155 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 10156 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
10157 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
10158 | NL80211_FLAG_CHECK_NETDEV_UP) | |
5393b917 | 10159 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
4c476991 | 10160 | |
f84f771d | 10161 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10162 | struct genl_info *info) |
10163 | { | |
10164 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 10165 | struct wireless_dev *wdev; |
4c476991 | 10166 | struct net_device *dev; |
4c476991 JB |
10167 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
10168 | ||
10169 | if (rtnl) | |
10170 | rtnl_lock(); | |
10171 | ||
10172 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 10173 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
10174 | if (IS_ERR(rdev)) { |
10175 | if (rtnl) | |
10176 | rtnl_unlock(); | |
10177 | return PTR_ERR(rdev); | |
10178 | } | |
10179 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
10180 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
10181 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
10182 | ASSERT_RTNL(); |
10183 | ||
89a54e48 JB |
10184 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
10185 | info->attrs); | |
10186 | if (IS_ERR(wdev)) { | |
4c476991 JB |
10187 | if (rtnl) |
10188 | rtnl_unlock(); | |
89a54e48 | 10189 | return PTR_ERR(wdev); |
4c476991 | 10190 | } |
89a54e48 | 10191 | |
89a54e48 | 10192 | dev = wdev->netdev; |
f26cbf40 | 10193 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 10194 | |
1bf614ef JB |
10195 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
10196 | if (!dev) { | |
1bf614ef JB |
10197 | if (rtnl) |
10198 | rtnl_unlock(); | |
10199 | return -EINVAL; | |
10200 | } | |
10201 | ||
10202 | info->user_ptr[1] = dev; | |
10203 | } else { | |
10204 | info->user_ptr[1] = wdev; | |
41265714 | 10205 | } |
1bf614ef JB |
10206 | |
10207 | if (dev) { | |
10208 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
10209 | !netif_running(dev)) { | |
1bf614ef JB |
10210 | if (rtnl) |
10211 | rtnl_unlock(); | |
10212 | return -ENETDOWN; | |
10213 | } | |
10214 | ||
10215 | dev_hold(dev); | |
98104fde JB |
10216 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
10217 | if (!wdev->p2p_started) { | |
98104fde JB |
10218 | if (rtnl) |
10219 | rtnl_unlock(); | |
10220 | return -ENETDOWN; | |
10221 | } | |
41265714 | 10222 | } |
89a54e48 | 10223 | |
4c476991 | 10224 | info->user_ptr[0] = rdev; |
4c476991 JB |
10225 | } |
10226 | ||
10227 | return 0; | |
10228 | } | |
10229 | ||
f84f771d | 10230 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10231 | struct genl_info *info) |
10232 | { | |
1bf614ef JB |
10233 | if (info->user_ptr[1]) { |
10234 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
10235 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10236 | ||
10237 | if (wdev->netdev) | |
10238 | dev_put(wdev->netdev); | |
10239 | } else { | |
10240 | dev_put(info->user_ptr[1]); | |
10241 | } | |
10242 | } | |
5393b917 | 10243 | |
4c476991 JB |
10244 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
10245 | rtnl_unlock(); | |
5393b917 JB |
10246 | |
10247 | /* If needed, clear the netlink message payload from the SKB | |
10248 | * as it might contain key data that shouldn't stick around on | |
10249 | * the heap after the SKB is freed. The netlink message header | |
10250 | * is still needed for further processing, so leave it intact. | |
10251 | */ | |
10252 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | |
10253 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | |
10254 | ||
10255 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | |
10256 | } | |
4c476991 JB |
10257 | } |
10258 | ||
4534de83 | 10259 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
10260 | { |
10261 | .cmd = NL80211_CMD_GET_WIPHY, | |
10262 | .doit = nl80211_get_wiphy, | |
10263 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 10264 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
10265 | .policy = nl80211_policy, |
10266 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10267 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10268 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10269 | }, |
10270 | { | |
10271 | .cmd = NL80211_CMD_SET_WIPHY, | |
10272 | .doit = nl80211_set_wiphy, | |
10273 | .policy = nl80211_policy, | |
10274 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 10275 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
10276 | }, |
10277 | { | |
10278 | .cmd = NL80211_CMD_GET_INTERFACE, | |
10279 | .doit = nl80211_get_interface, | |
10280 | .dumpit = nl80211_dump_interface, | |
10281 | .policy = nl80211_policy, | |
10282 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10283 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
10284 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10285 | }, |
10286 | { | |
10287 | .cmd = NL80211_CMD_SET_INTERFACE, | |
10288 | .doit = nl80211_set_interface, | |
10289 | .policy = nl80211_policy, | |
10290 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10291 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10292 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10293 | }, |
10294 | { | |
10295 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
10296 | .doit = nl80211_new_interface, | |
10297 | .policy = nl80211_policy, | |
10298 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10299 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10300 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10301 | }, |
10302 | { | |
10303 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
10304 | .doit = nl80211_del_interface, | |
10305 | .policy = nl80211_policy, | |
41ade00f | 10306 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 10307 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10308 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10309 | }, |
10310 | { | |
10311 | .cmd = NL80211_CMD_GET_KEY, | |
10312 | .doit = nl80211_get_key, | |
10313 | .policy = nl80211_policy, | |
10314 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10315 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10316 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10317 | }, |
10318 | { | |
10319 | .cmd = NL80211_CMD_SET_KEY, | |
10320 | .doit = nl80211_set_key, | |
10321 | .policy = nl80211_policy, | |
10322 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10323 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10324 | NL80211_FLAG_NEED_RTNL | |
10325 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10326 | }, |
10327 | { | |
10328 | .cmd = NL80211_CMD_NEW_KEY, | |
10329 | .doit = nl80211_new_key, | |
10330 | .policy = nl80211_policy, | |
10331 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10332 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10333 | NL80211_FLAG_NEED_RTNL | |
10334 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10335 | }, |
10336 | { | |
10337 | .cmd = NL80211_CMD_DEL_KEY, | |
10338 | .doit = nl80211_del_key, | |
10339 | .policy = nl80211_policy, | |
55682965 | 10340 | .flags = GENL_ADMIN_PERM, |
41265714 | 10341 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10342 | NL80211_FLAG_NEED_RTNL, |
55682965 | 10343 | }, |
ed1b6cc7 JB |
10344 | { |
10345 | .cmd = NL80211_CMD_SET_BEACON, | |
10346 | .policy = nl80211_policy, | |
10347 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10348 | .doit = nl80211_set_beacon, |
2b5f8b0b | 10349 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10350 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10351 | }, |
10352 | { | |
8860020e | 10353 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
10354 | .policy = nl80211_policy, |
10355 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10356 | .doit = nl80211_start_ap, |
2b5f8b0b | 10357 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10358 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10359 | }, |
10360 | { | |
8860020e | 10361 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
10362 | .policy = nl80211_policy, |
10363 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10364 | .doit = nl80211_stop_ap, |
2b5f8b0b | 10365 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10366 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 10367 | }, |
5727ef1b JB |
10368 | { |
10369 | .cmd = NL80211_CMD_GET_STATION, | |
10370 | .doit = nl80211_get_station, | |
2ec600d6 | 10371 | .dumpit = nl80211_dump_station, |
5727ef1b | 10372 | .policy = nl80211_policy, |
4c476991 JB |
10373 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10374 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
10375 | }, |
10376 | { | |
10377 | .cmd = NL80211_CMD_SET_STATION, | |
10378 | .doit = nl80211_set_station, | |
10379 | .policy = nl80211_policy, | |
10380 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10381 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10382 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10383 | }, |
10384 | { | |
10385 | .cmd = NL80211_CMD_NEW_STATION, | |
10386 | .doit = nl80211_new_station, | |
10387 | .policy = nl80211_policy, | |
10388 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10389 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10390 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10391 | }, |
10392 | { | |
10393 | .cmd = NL80211_CMD_DEL_STATION, | |
10394 | .doit = nl80211_del_station, | |
10395 | .policy = nl80211_policy, | |
2ec600d6 | 10396 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10397 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10398 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10399 | }, |
10400 | { | |
10401 | .cmd = NL80211_CMD_GET_MPATH, | |
10402 | .doit = nl80211_get_mpath, | |
10403 | .dumpit = nl80211_dump_mpath, | |
10404 | .policy = nl80211_policy, | |
10405 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10406 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10407 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 | 10408 | }, |
66be7d2b HR |
10409 | { |
10410 | .cmd = NL80211_CMD_GET_MPP, | |
10411 | .doit = nl80211_get_mpp, | |
10412 | .dumpit = nl80211_dump_mpp, | |
10413 | .policy = nl80211_policy, | |
10414 | .flags = GENL_ADMIN_PERM, | |
10415 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10416 | NL80211_FLAG_NEED_RTNL, | |
10417 | }, | |
2ec600d6 LCC |
10418 | { |
10419 | .cmd = NL80211_CMD_SET_MPATH, | |
10420 | .doit = nl80211_set_mpath, | |
10421 | .policy = nl80211_policy, | |
10422 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10423 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10424 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10425 | }, |
10426 | { | |
10427 | .cmd = NL80211_CMD_NEW_MPATH, | |
10428 | .doit = nl80211_new_mpath, | |
10429 | .policy = nl80211_policy, | |
10430 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10431 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10432 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10433 | }, |
10434 | { | |
10435 | .cmd = NL80211_CMD_DEL_MPATH, | |
10436 | .doit = nl80211_del_mpath, | |
10437 | .policy = nl80211_policy, | |
9f1ba906 | 10438 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10439 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10440 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
10441 | }, |
10442 | { | |
10443 | .cmd = NL80211_CMD_SET_BSS, | |
10444 | .doit = nl80211_set_bss, | |
10445 | .policy = nl80211_policy, | |
b2e1b302 | 10446 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10447 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10448 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 10449 | }, |
f130347c LR |
10450 | { |
10451 | .cmd = NL80211_CMD_GET_REG, | |
ad30ca2c AN |
10452 | .doit = nl80211_get_reg_do, |
10453 | .dumpit = nl80211_get_reg_dump, | |
f130347c | 10454 | .policy = nl80211_policy, |
5fe231e8 | 10455 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
10456 | /* can be retrieved by unprivileged users */ |
10457 | }, | |
b2e1b302 LR |
10458 | { |
10459 | .cmd = NL80211_CMD_SET_REG, | |
10460 | .doit = nl80211_set_reg, | |
10461 | .policy = nl80211_policy, | |
10462 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 10463 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
10464 | }, |
10465 | { | |
10466 | .cmd = NL80211_CMD_REQ_SET_REG, | |
10467 | .doit = nl80211_req_set_reg, | |
10468 | .policy = nl80211_policy, | |
93da9cc1 | 10469 | .flags = GENL_ADMIN_PERM, |
10470 | }, | |
10471 | { | |
24bdd9f4 JC |
10472 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
10473 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 10474 | .policy = nl80211_policy, |
10475 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 10476 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10477 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 10478 | }, |
10479 | { | |
24bdd9f4 JC |
10480 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
10481 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 10482 | .policy = nl80211_policy, |
9aed3cc1 | 10483 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 10484 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10485 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 10486 | }, |
2a519311 JB |
10487 | { |
10488 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
10489 | .doit = nl80211_trigger_scan, | |
10490 | .policy = nl80211_policy, | |
10491 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 10492 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10493 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
10494 | }, |
10495 | { | |
10496 | .cmd = NL80211_CMD_GET_SCAN, | |
10497 | .policy = nl80211_policy, | |
10498 | .dumpit = nl80211_dump_scan, | |
10499 | }, | |
807f8a8c LC |
10500 | { |
10501 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
10502 | .doit = nl80211_start_sched_scan, | |
10503 | .policy = nl80211_policy, | |
10504 | .flags = GENL_ADMIN_PERM, | |
10505 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10506 | NL80211_FLAG_NEED_RTNL, | |
10507 | }, | |
10508 | { | |
10509 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
10510 | .doit = nl80211_stop_sched_scan, | |
10511 | .policy = nl80211_policy, | |
10512 | .flags = GENL_ADMIN_PERM, | |
10513 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10514 | NL80211_FLAG_NEED_RTNL, | |
10515 | }, | |
636a5d36 JM |
10516 | { |
10517 | .cmd = NL80211_CMD_AUTHENTICATE, | |
10518 | .doit = nl80211_authenticate, | |
10519 | .policy = nl80211_policy, | |
10520 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10521 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10522 | NL80211_FLAG_NEED_RTNL | |
10523 | NL80211_FLAG_CLEAR_SKB, | |
636a5d36 JM |
10524 | }, |
10525 | { | |
10526 | .cmd = NL80211_CMD_ASSOCIATE, | |
10527 | .doit = nl80211_associate, | |
10528 | .policy = nl80211_policy, | |
10529 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10530 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10531 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10532 | }, |
10533 | { | |
10534 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
10535 | .doit = nl80211_deauthenticate, | |
10536 | .policy = nl80211_policy, | |
10537 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10538 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10539 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10540 | }, |
10541 | { | |
10542 | .cmd = NL80211_CMD_DISASSOCIATE, | |
10543 | .doit = nl80211_disassociate, | |
10544 | .policy = nl80211_policy, | |
10545 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10546 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10547 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 10548 | }, |
04a773ad JB |
10549 | { |
10550 | .cmd = NL80211_CMD_JOIN_IBSS, | |
10551 | .doit = nl80211_join_ibss, | |
10552 | .policy = nl80211_policy, | |
10553 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10554 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10555 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
10556 | }, |
10557 | { | |
10558 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
10559 | .doit = nl80211_leave_ibss, | |
10560 | .policy = nl80211_policy, | |
10561 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10562 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10563 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 10564 | }, |
aff89a9b JB |
10565 | #ifdef CONFIG_NL80211_TESTMODE |
10566 | { | |
10567 | .cmd = NL80211_CMD_TESTMODE, | |
10568 | .doit = nl80211_testmode_do, | |
71063f0e | 10569 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
10570 | .policy = nl80211_policy, |
10571 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10572 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10573 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
10574 | }, |
10575 | #endif | |
b23aa676 SO |
10576 | { |
10577 | .cmd = NL80211_CMD_CONNECT, | |
10578 | .doit = nl80211_connect, | |
10579 | .policy = nl80211_policy, | |
10580 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10581 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10582 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
10583 | }, |
10584 | { | |
10585 | .cmd = NL80211_CMD_DISCONNECT, | |
10586 | .doit = nl80211_disconnect, | |
10587 | .policy = nl80211_policy, | |
10588 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10589 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10590 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 10591 | }, |
463d0183 JB |
10592 | { |
10593 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
10594 | .doit = nl80211_wiphy_netns, | |
10595 | .policy = nl80211_policy, | |
10596 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10597 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10598 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 10599 | }, |
61fa713c HS |
10600 | { |
10601 | .cmd = NL80211_CMD_GET_SURVEY, | |
10602 | .policy = nl80211_policy, | |
10603 | .dumpit = nl80211_dump_survey, | |
10604 | }, | |
67fbb16b SO |
10605 | { |
10606 | .cmd = NL80211_CMD_SET_PMKSA, | |
10607 | .doit = nl80211_setdel_pmksa, | |
10608 | .policy = nl80211_policy, | |
10609 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10610 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10611 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10612 | }, |
10613 | { | |
10614 | .cmd = NL80211_CMD_DEL_PMKSA, | |
10615 | .doit = nl80211_setdel_pmksa, | |
10616 | .policy = nl80211_policy, | |
10617 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10618 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10619 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10620 | }, |
10621 | { | |
10622 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
10623 | .doit = nl80211_flush_pmksa, | |
10624 | .policy = nl80211_policy, | |
10625 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10626 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10627 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 10628 | }, |
9588bbd5 JM |
10629 | { |
10630 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
10631 | .doit = nl80211_remain_on_channel, | |
10632 | .policy = nl80211_policy, | |
10633 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10634 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10635 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
10636 | }, |
10637 | { | |
10638 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
10639 | .doit = nl80211_cancel_remain_on_channel, | |
10640 | .policy = nl80211_policy, | |
10641 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10642 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10643 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 10644 | }, |
13ae75b1 JM |
10645 | { |
10646 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
10647 | .doit = nl80211_set_tx_bitrate_mask, | |
10648 | .policy = nl80211_policy, | |
10649 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10650 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10651 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 10652 | }, |
026331c4 | 10653 | { |
2e161f78 JB |
10654 | .cmd = NL80211_CMD_REGISTER_FRAME, |
10655 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
10656 | .policy = nl80211_policy, |
10657 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10658 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10659 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
10660 | }, |
10661 | { | |
2e161f78 JB |
10662 | .cmd = NL80211_CMD_FRAME, |
10663 | .doit = nl80211_tx_mgmt, | |
026331c4 | 10664 | .policy = nl80211_policy, |
f7ca38df | 10665 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10666 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
10667 | NL80211_FLAG_NEED_RTNL, |
10668 | }, | |
10669 | { | |
10670 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
10671 | .doit = nl80211_tx_mgmt_cancel_wait, | |
10672 | .policy = nl80211_policy, | |
026331c4 | 10673 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10674 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10675 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 10676 | }, |
ffb9eb3d KV |
10677 | { |
10678 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
10679 | .doit = nl80211_set_power_save, | |
10680 | .policy = nl80211_policy, | |
10681 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10682 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10683 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
10684 | }, |
10685 | { | |
10686 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
10687 | .doit = nl80211_get_power_save, | |
10688 | .policy = nl80211_policy, | |
10689 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
10690 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10691 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 10692 | }, |
d6dc1a38 JO |
10693 | { |
10694 | .cmd = NL80211_CMD_SET_CQM, | |
10695 | .doit = nl80211_set_cqm, | |
10696 | .policy = nl80211_policy, | |
10697 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10698 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10699 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 10700 | }, |
f444de05 JB |
10701 | { |
10702 | .cmd = NL80211_CMD_SET_CHANNEL, | |
10703 | .doit = nl80211_set_channel, | |
10704 | .policy = nl80211_policy, | |
10705 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10706 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10707 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 10708 | }, |
e8347eba BJ |
10709 | { |
10710 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
10711 | .doit = nl80211_set_wds_peer, | |
10712 | .policy = nl80211_policy, | |
10713 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
10714 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10715 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 10716 | }, |
29cbe68c JB |
10717 | { |
10718 | .cmd = NL80211_CMD_JOIN_MESH, | |
10719 | .doit = nl80211_join_mesh, | |
10720 | .policy = nl80211_policy, | |
10721 | .flags = GENL_ADMIN_PERM, | |
10722 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10723 | NL80211_FLAG_NEED_RTNL, | |
10724 | }, | |
10725 | { | |
10726 | .cmd = NL80211_CMD_LEAVE_MESH, | |
10727 | .doit = nl80211_leave_mesh, | |
10728 | .policy = nl80211_policy, | |
10729 | .flags = GENL_ADMIN_PERM, | |
10730 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10731 | NL80211_FLAG_NEED_RTNL, | |
10732 | }, | |
6e0bd6c3 RL |
10733 | { |
10734 | .cmd = NL80211_CMD_JOIN_OCB, | |
10735 | .doit = nl80211_join_ocb, | |
10736 | .policy = nl80211_policy, | |
10737 | .flags = GENL_ADMIN_PERM, | |
10738 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10739 | NL80211_FLAG_NEED_RTNL, | |
10740 | }, | |
10741 | { | |
10742 | .cmd = NL80211_CMD_LEAVE_OCB, | |
10743 | .doit = nl80211_leave_ocb, | |
10744 | .policy = nl80211_policy, | |
10745 | .flags = GENL_ADMIN_PERM, | |
10746 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10747 | NL80211_FLAG_NEED_RTNL, | |
10748 | }, | |
dfb89c56 | 10749 | #ifdef CONFIG_PM |
ff1b6e69 JB |
10750 | { |
10751 | .cmd = NL80211_CMD_GET_WOWLAN, | |
10752 | .doit = nl80211_get_wowlan, | |
10753 | .policy = nl80211_policy, | |
10754 | /* can be retrieved by unprivileged users */ | |
10755 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10756 | NL80211_FLAG_NEED_RTNL, | |
10757 | }, | |
10758 | { | |
10759 | .cmd = NL80211_CMD_SET_WOWLAN, | |
10760 | .doit = nl80211_set_wowlan, | |
10761 | .policy = nl80211_policy, | |
10762 | .flags = GENL_ADMIN_PERM, | |
10763 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10764 | NL80211_FLAG_NEED_RTNL, | |
10765 | }, | |
dfb89c56 | 10766 | #endif |
e5497d76 JB |
10767 | { |
10768 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
10769 | .doit = nl80211_set_rekey_data, | |
10770 | .policy = nl80211_policy, | |
10771 | .flags = GENL_ADMIN_PERM, | |
10772 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
5393b917 JB |
10773 | NL80211_FLAG_NEED_RTNL | |
10774 | NL80211_FLAG_CLEAR_SKB, | |
e5497d76 | 10775 | }, |
109086ce AN |
10776 | { |
10777 | .cmd = NL80211_CMD_TDLS_MGMT, | |
10778 | .doit = nl80211_tdls_mgmt, | |
10779 | .policy = nl80211_policy, | |
10780 | .flags = GENL_ADMIN_PERM, | |
10781 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10782 | NL80211_FLAG_NEED_RTNL, | |
10783 | }, | |
10784 | { | |
10785 | .cmd = NL80211_CMD_TDLS_OPER, | |
10786 | .doit = nl80211_tdls_oper, | |
10787 | .policy = nl80211_policy, | |
10788 | .flags = GENL_ADMIN_PERM, | |
10789 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10790 | NL80211_FLAG_NEED_RTNL, | |
10791 | }, | |
28946da7 JB |
10792 | { |
10793 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
10794 | .doit = nl80211_register_unexpected_frame, | |
10795 | .policy = nl80211_policy, | |
10796 | .flags = GENL_ADMIN_PERM, | |
10797 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10798 | NL80211_FLAG_NEED_RTNL, | |
10799 | }, | |
7f6cf311 JB |
10800 | { |
10801 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
10802 | .doit = nl80211_probe_client, | |
10803 | .policy = nl80211_policy, | |
10804 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10805 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
10806 | NL80211_FLAG_NEED_RTNL, |
10807 | }, | |
5e760230 JB |
10808 | { |
10809 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
10810 | .doit = nl80211_register_beacons, | |
10811 | .policy = nl80211_policy, | |
10812 | .flags = GENL_ADMIN_PERM, | |
10813 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10814 | NL80211_FLAG_NEED_RTNL, | |
10815 | }, | |
1d9d9213 SW |
10816 | { |
10817 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
10818 | .doit = nl80211_set_noack_map, | |
10819 | .policy = nl80211_policy, | |
10820 | .flags = GENL_ADMIN_PERM, | |
10821 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10822 | NL80211_FLAG_NEED_RTNL, | |
10823 | }, | |
98104fde JB |
10824 | { |
10825 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
10826 | .doit = nl80211_start_p2p_device, | |
10827 | .policy = nl80211_policy, | |
10828 | .flags = GENL_ADMIN_PERM, | |
10829 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
10830 | NL80211_FLAG_NEED_RTNL, | |
10831 | }, | |
10832 | { | |
10833 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
10834 | .doit = nl80211_stop_p2p_device, | |
10835 | .policy = nl80211_policy, | |
10836 | .flags = GENL_ADMIN_PERM, | |
10837 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10838 | NL80211_FLAG_NEED_RTNL, | |
10839 | }, | |
f4e583c8 AQ |
10840 | { |
10841 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
10842 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
10843 | .policy = nl80211_policy, |
10844 | .flags = GENL_ADMIN_PERM, | |
10845 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10846 | NL80211_FLAG_NEED_RTNL, | |
10847 | }, | |
10848 | { | |
10849 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
10850 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
10851 | .policy = nl80211_policy, |
10852 | .flags = GENL_ADMIN_PERM, | |
10853 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10854 | NL80211_FLAG_NEED_RTNL, | |
10855 | }, | |
04f39047 SW |
10856 | { |
10857 | .cmd = NL80211_CMD_RADAR_DETECT, | |
10858 | .doit = nl80211_start_radar_detection, | |
10859 | .policy = nl80211_policy, | |
10860 | .flags = GENL_ADMIN_PERM, | |
10861 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10862 | NL80211_FLAG_NEED_RTNL, | |
10863 | }, | |
3713b4e3 JB |
10864 | { |
10865 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
10866 | .doit = nl80211_get_protocol_features, | |
10867 | .policy = nl80211_policy, | |
10868 | }, | |
355199e0 JM |
10869 | { |
10870 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
10871 | .doit = nl80211_update_ft_ies, | |
10872 | .policy = nl80211_policy, | |
10873 | .flags = GENL_ADMIN_PERM, | |
10874 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10875 | NL80211_FLAG_NEED_RTNL, | |
10876 | }, | |
5de17984 AS |
10877 | { |
10878 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
10879 | .doit = nl80211_crit_protocol_start, | |
10880 | .policy = nl80211_policy, | |
10881 | .flags = GENL_ADMIN_PERM, | |
10882 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10883 | NL80211_FLAG_NEED_RTNL, | |
10884 | }, | |
10885 | { | |
10886 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
10887 | .doit = nl80211_crit_protocol_stop, | |
10888 | .policy = nl80211_policy, | |
10889 | .flags = GENL_ADMIN_PERM, | |
10890 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10891 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
10892 | }, |
10893 | { | |
10894 | .cmd = NL80211_CMD_GET_COALESCE, | |
10895 | .doit = nl80211_get_coalesce, | |
10896 | .policy = nl80211_policy, | |
10897 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10898 | NL80211_FLAG_NEED_RTNL, | |
10899 | }, | |
10900 | { | |
10901 | .cmd = NL80211_CMD_SET_COALESCE, | |
10902 | .doit = nl80211_set_coalesce, | |
10903 | .policy = nl80211_policy, | |
10904 | .flags = GENL_ADMIN_PERM, | |
10905 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10906 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
10907 | }, |
10908 | { | |
10909 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
10910 | .doit = nl80211_channel_switch, | |
10911 | .policy = nl80211_policy, | |
10912 | .flags = GENL_ADMIN_PERM, | |
10913 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10914 | NL80211_FLAG_NEED_RTNL, | |
10915 | }, | |
ad7e718c JB |
10916 | { |
10917 | .cmd = NL80211_CMD_VENDOR, | |
10918 | .doit = nl80211_vendor_cmd, | |
10919 | .policy = nl80211_policy, | |
10920 | .flags = GENL_ADMIN_PERM, | |
10921 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10922 | NL80211_FLAG_NEED_RTNL, | |
10923 | }, | |
fa9ffc74 KP |
10924 | { |
10925 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
10926 | .doit = nl80211_set_qos_map, | |
10927 | .policy = nl80211_policy, | |
10928 | .flags = GENL_ADMIN_PERM, | |
10929 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10930 | NL80211_FLAG_NEED_RTNL, | |
10931 | }, | |
960d01ac JB |
10932 | { |
10933 | .cmd = NL80211_CMD_ADD_TX_TS, | |
10934 | .doit = nl80211_add_tx_ts, | |
10935 | .policy = nl80211_policy, | |
10936 | .flags = GENL_ADMIN_PERM, | |
10937 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10938 | NL80211_FLAG_NEED_RTNL, | |
10939 | }, | |
10940 | { | |
10941 | .cmd = NL80211_CMD_DEL_TX_TS, | |
10942 | .doit = nl80211_del_tx_ts, | |
10943 | .policy = nl80211_policy, | |
10944 | .flags = GENL_ADMIN_PERM, | |
10945 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10946 | NL80211_FLAG_NEED_RTNL, | |
10947 | }, | |
1057d35e AN |
10948 | { |
10949 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | |
10950 | .doit = nl80211_tdls_channel_switch, | |
10951 | .policy = nl80211_policy, | |
10952 | .flags = GENL_ADMIN_PERM, | |
10953 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10954 | NL80211_FLAG_NEED_RTNL, | |
10955 | }, | |
10956 | { | |
10957 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | |
10958 | .doit = nl80211_tdls_cancel_channel_switch, | |
10959 | .policy = nl80211_policy, | |
10960 | .flags = GENL_ADMIN_PERM, | |
10961 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10962 | NL80211_FLAG_NEED_RTNL, | |
10963 | }, | |
55682965 | 10964 | }; |
9588bbd5 | 10965 | |
55682965 JB |
10966 | /* notification functions */ |
10967 | ||
3bb20556 JB |
10968 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
10969 | enum nl80211_commands cmd) | |
55682965 JB |
10970 | { |
10971 | struct sk_buff *msg; | |
86e8cf98 | 10972 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 10973 | |
3bb20556 JB |
10974 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
10975 | cmd != NL80211_CMD_DEL_WIPHY); | |
10976 | ||
fd2120ca | 10977 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
10978 | if (!msg) |
10979 | return; | |
10980 | ||
3bb20556 | 10981 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
10982 | nlmsg_free(msg); |
10983 | return; | |
10984 | } | |
10985 | ||
68eb5503 | 10986 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10987 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
10988 | } |
10989 | ||
362a415d JB |
10990 | static int nl80211_add_scan_req(struct sk_buff *msg, |
10991 | struct cfg80211_registered_device *rdev) | |
10992 | { | |
10993 | struct cfg80211_scan_request *req = rdev->scan_req; | |
10994 | struct nlattr *nest; | |
10995 | int i; | |
10996 | ||
10997 | if (WARN_ON(!req)) | |
10998 | return 0; | |
10999 | ||
11000 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
11001 | if (!nest) | |
11002 | goto nla_put_failure; | |
9360ffd1 DM |
11003 | for (i = 0; i < req->n_ssids; i++) { |
11004 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
11005 | goto nla_put_failure; | |
11006 | } | |
362a415d JB |
11007 | nla_nest_end(msg, nest); |
11008 | ||
11009 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
11010 | if (!nest) | |
11011 | goto nla_put_failure; | |
9360ffd1 DM |
11012 | for (i = 0; i < req->n_channels; i++) { |
11013 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
11014 | goto nla_put_failure; | |
11015 | } | |
362a415d JB |
11016 | nla_nest_end(msg, nest); |
11017 | ||
9360ffd1 DM |
11018 | if (req->ie && |
11019 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
11020 | goto nla_put_failure; | |
362a415d | 11021 | |
ae917c9f JB |
11022 | if (req->flags && |
11023 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
11024 | goto nla_put_failure; | |
ed473771 | 11025 | |
362a415d JB |
11026 | return 0; |
11027 | nla_put_failure: | |
11028 | return -ENOBUFS; | |
11029 | } | |
11030 | ||
a538e2d5 JB |
11031 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
11032 | struct cfg80211_registered_device *rdev, | |
fd014284 | 11033 | struct wireless_dev *wdev, |
15e47304 | 11034 | u32 portid, u32 seq, int flags, |
a538e2d5 | 11035 | u32 cmd) |
2a519311 JB |
11036 | { |
11037 | void *hdr; | |
11038 | ||
15e47304 | 11039 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
11040 | if (!hdr) |
11041 | return -1; | |
11042 | ||
9360ffd1 | 11043 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
11044 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11045 | wdev->netdev->ifindex)) || | |
11046 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 11047 | goto nla_put_failure; |
2a519311 | 11048 | |
362a415d JB |
11049 | /* ignore errors and send incomplete event anyway */ |
11050 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
11051 | |
11052 | return genlmsg_end(msg, hdr); | |
11053 | ||
11054 | nla_put_failure: | |
11055 | genlmsg_cancel(msg, hdr); | |
11056 | return -EMSGSIZE; | |
11057 | } | |
11058 | ||
807f8a8c LC |
11059 | static int |
11060 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
11061 | struct cfg80211_registered_device *rdev, | |
11062 | struct net_device *netdev, | |
15e47304 | 11063 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
11064 | { |
11065 | void *hdr; | |
11066 | ||
15e47304 | 11067 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
11068 | if (!hdr) |
11069 | return -1; | |
11070 | ||
9360ffd1 DM |
11071 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11072 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
11073 | goto nla_put_failure; | |
807f8a8c LC |
11074 | |
11075 | return genlmsg_end(msg, hdr); | |
11076 | ||
11077 | nla_put_failure: | |
11078 | genlmsg_cancel(msg, hdr); | |
11079 | return -EMSGSIZE; | |
11080 | } | |
11081 | ||
a538e2d5 | 11082 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 11083 | struct wireless_dev *wdev) |
a538e2d5 JB |
11084 | { |
11085 | struct sk_buff *msg; | |
11086 | ||
58050fce | 11087 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
11088 | if (!msg) |
11089 | return; | |
11090 | ||
fd014284 | 11091 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
11092 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
11093 | nlmsg_free(msg); | |
11094 | return; | |
11095 | } | |
11096 | ||
68eb5503 | 11097 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11098 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
11099 | } |
11100 | ||
f9d15d16 JB |
11101 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
11102 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
11103 | { |
11104 | struct sk_buff *msg; | |
11105 | ||
fd2120ca | 11106 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 11107 | if (!msg) |
f9d15d16 | 11108 | return NULL; |
2a519311 | 11109 | |
fd014284 | 11110 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
11111 | aborted ? NL80211_CMD_SCAN_ABORTED : |
11112 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 11113 | nlmsg_free(msg); |
f9d15d16 | 11114 | return NULL; |
2a519311 JB |
11115 | } |
11116 | ||
f9d15d16 | 11117 | return msg; |
2a519311 JB |
11118 | } |
11119 | ||
f9d15d16 JB |
11120 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
11121 | struct sk_buff *msg) | |
2a519311 | 11122 | { |
2a519311 JB |
11123 | if (!msg) |
11124 | return; | |
11125 | ||
68eb5503 | 11126 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11127 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
11128 | } |
11129 | ||
807f8a8c LC |
11130 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
11131 | struct net_device *netdev) | |
11132 | { | |
11133 | struct sk_buff *msg; | |
11134 | ||
11135 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11136 | if (!msg) | |
11137 | return; | |
11138 | ||
11139 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
11140 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
11141 | nlmsg_free(msg); | |
11142 | return; | |
11143 | } | |
11144 | ||
68eb5503 | 11145 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11146 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11147 | } |
11148 | ||
11149 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
11150 | struct net_device *netdev, u32 cmd) | |
11151 | { | |
11152 | struct sk_buff *msg; | |
11153 | ||
58050fce | 11154 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
11155 | if (!msg) |
11156 | return; | |
11157 | ||
11158 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
11159 | nlmsg_free(msg); | |
11160 | return; | |
11161 | } | |
11162 | ||
68eb5503 | 11163 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11164 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11165 | } |
11166 | ||
b0d7aa59 JD |
11167 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
11168 | struct regulatory_request *request) | |
73d54c9e | 11169 | { |
73d54c9e | 11170 | /* Userspace can always count this one always being set */ |
9360ffd1 DM |
11171 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
11172 | goto nla_put_failure; | |
11173 | ||
11174 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
11175 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11176 | NL80211_REGDOM_TYPE_WORLD)) | |
11177 | goto nla_put_failure; | |
11178 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
11179 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11180 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
11181 | goto nla_put_failure; | |
11182 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
11183 | request->intersect) { | |
11184 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11185 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
11186 | goto nla_put_failure; | |
11187 | } else { | |
11188 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11189 | NL80211_REGDOM_TYPE_COUNTRY) || | |
11190 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
11191 | request->alpha2)) | |
11192 | goto nla_put_failure; | |
11193 | } | |
11194 | ||
ad30ca2c AN |
11195 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
11196 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); | |
11197 | ||
11198 | if (wiphy && | |
11199 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | |
11200 | goto nla_put_failure; | |
1bdd716c AN |
11201 | |
11202 | if (wiphy && | |
11203 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | |
11204 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
11205 | goto nla_put_failure; | |
ad30ca2c | 11206 | } |
73d54c9e | 11207 | |
b0d7aa59 JD |
11208 | return true; |
11209 | ||
11210 | nla_put_failure: | |
11211 | return false; | |
11212 | } | |
11213 | ||
11214 | /* | |
11215 | * This can happen on global regulatory changes or device specific settings | |
11216 | * based on custom regulatory domains. | |
11217 | */ | |
11218 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, | |
11219 | struct regulatory_request *request) | |
11220 | { | |
11221 | struct sk_buff *msg; | |
11222 | void *hdr; | |
11223 | ||
11224 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11225 | if (!msg) | |
11226 | return; | |
11227 | ||
11228 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); | |
11229 | if (!hdr) { | |
11230 | nlmsg_free(msg); | |
11231 | return; | |
11232 | } | |
11233 | ||
11234 | if (nl80211_reg_change_event_fill(msg, request) == false) | |
11235 | goto nla_put_failure; | |
11236 | ||
3b7b72ee | 11237 | genlmsg_end(msg, hdr); |
73d54c9e | 11238 | |
bc43b28c | 11239 | rcu_read_lock(); |
68eb5503 | 11240 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11241 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 11242 | rcu_read_unlock(); |
73d54c9e LR |
11243 | |
11244 | return; | |
11245 | ||
11246 | nla_put_failure: | |
11247 | genlmsg_cancel(msg, hdr); | |
11248 | nlmsg_free(msg); | |
11249 | } | |
11250 | ||
6039f6d2 JM |
11251 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
11252 | struct net_device *netdev, | |
11253 | const u8 *buf, size_t len, | |
b0b6aa2c EP |
11254 | enum nl80211_commands cmd, gfp_t gfp, |
11255 | int uapsd_queues) | |
6039f6d2 JM |
11256 | { |
11257 | struct sk_buff *msg; | |
11258 | void *hdr; | |
11259 | ||
e6d6e342 | 11260 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
11261 | if (!msg) |
11262 | return; | |
11263 | ||
11264 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11265 | if (!hdr) { | |
11266 | nlmsg_free(msg); | |
11267 | return; | |
11268 | } | |
11269 | ||
9360ffd1 DM |
11270 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11271 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11272 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
11273 | goto nla_put_failure; | |
6039f6d2 | 11274 | |
b0b6aa2c EP |
11275 | if (uapsd_queues >= 0) { |
11276 | struct nlattr *nla_wmm = | |
11277 | nla_nest_start(msg, NL80211_ATTR_STA_WME); | |
11278 | if (!nla_wmm) | |
11279 | goto nla_put_failure; | |
11280 | ||
11281 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
11282 | uapsd_queues)) | |
11283 | goto nla_put_failure; | |
11284 | ||
11285 | nla_nest_end(msg, nla_wmm); | |
11286 | } | |
11287 | ||
3b7b72ee | 11288 | genlmsg_end(msg, hdr); |
6039f6d2 | 11289 | |
68eb5503 | 11290 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11291 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
11292 | return; |
11293 | ||
11294 | nla_put_failure: | |
11295 | genlmsg_cancel(msg, hdr); | |
11296 | nlmsg_free(msg); | |
11297 | } | |
11298 | ||
11299 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11300 | struct net_device *netdev, const u8 *buf, |
11301 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11302 | { |
11303 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11304 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11305 | } |
11306 | ||
11307 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
11308 | struct net_device *netdev, const u8 *buf, | |
b0b6aa2c | 11309 | size_t len, gfp_t gfp, int uapsd_queues) |
6039f6d2 | 11310 | { |
e6d6e342 | 11311 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
b0b6aa2c | 11312 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
6039f6d2 JM |
11313 | } |
11314 | ||
53b46b84 | 11315 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
11316 | struct net_device *netdev, const u8 *buf, |
11317 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11318 | { |
11319 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11320 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11321 | } |
11322 | ||
53b46b84 JM |
11323 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
11324 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 11325 | size_t len, gfp_t gfp) |
6039f6d2 JM |
11326 | { |
11327 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11328 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
6039f6d2 JM |
11329 | } |
11330 | ||
6ff57cf8 JB |
11331 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
11332 | size_t len) | |
cf4e594e | 11333 | { |
947add36 JB |
11334 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11335 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11336 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
11337 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
11338 | u32 cmd; | |
947add36 | 11339 | |
6ff57cf8 JB |
11340 | if (WARN_ON(len < 2)) |
11341 | return; | |
cf4e594e | 11342 | |
6ff57cf8 JB |
11343 | if (ieee80211_is_deauth(mgmt->frame_control)) |
11344 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
11345 | else | |
11346 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 11347 | |
6ff57cf8 | 11348 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
b0b6aa2c | 11349 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
cf4e594e | 11350 | } |
6ff57cf8 | 11351 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 11352 | |
1b06bb40 LR |
11353 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
11354 | struct net_device *netdev, int cmd, | |
e6d6e342 | 11355 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
11356 | { |
11357 | struct sk_buff *msg; | |
11358 | void *hdr; | |
11359 | ||
e6d6e342 | 11360 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
11361 | if (!msg) |
11362 | return; | |
11363 | ||
11364 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11365 | if (!hdr) { | |
11366 | nlmsg_free(msg); | |
11367 | return; | |
11368 | } | |
11369 | ||
9360ffd1 DM |
11370 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11371 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11372 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
11373 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11374 | goto nla_put_failure; | |
1965c853 | 11375 | |
3b7b72ee | 11376 | genlmsg_end(msg, hdr); |
1965c853 | 11377 | |
68eb5503 | 11378 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11379 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
11380 | return; |
11381 | ||
11382 | nla_put_failure: | |
11383 | genlmsg_cancel(msg, hdr); | |
11384 | nlmsg_free(msg); | |
11385 | } | |
11386 | ||
11387 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11388 | struct net_device *netdev, const u8 *addr, |
11389 | gfp_t gfp) | |
1965c853 JM |
11390 | { |
11391 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 11392 | addr, gfp); |
1965c853 JM |
11393 | } |
11394 | ||
11395 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11396 | struct net_device *netdev, const u8 *addr, |
11397 | gfp_t gfp) | |
1965c853 | 11398 | { |
e6d6e342 JB |
11399 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
11400 | addr, gfp); | |
1965c853 JM |
11401 | } |
11402 | ||
b23aa676 SO |
11403 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
11404 | struct net_device *netdev, const u8 *bssid, | |
11405 | const u8 *req_ie, size_t req_ie_len, | |
11406 | const u8 *resp_ie, size_t resp_ie_len, | |
11407 | u16 status, gfp_t gfp) | |
11408 | { | |
11409 | struct sk_buff *msg; | |
11410 | void *hdr; | |
11411 | ||
58050fce | 11412 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
11413 | if (!msg) |
11414 | return; | |
11415 | ||
11416 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
11417 | if (!hdr) { | |
11418 | nlmsg_free(msg); | |
11419 | return; | |
11420 | } | |
11421 | ||
9360ffd1 DM |
11422 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11423 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11424 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
11425 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
11426 | (req_ie && | |
11427 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11428 | (resp_ie && | |
11429 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11430 | goto nla_put_failure; | |
b23aa676 | 11431 | |
3b7b72ee | 11432 | genlmsg_end(msg, hdr); |
b23aa676 | 11433 | |
68eb5503 | 11434 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11435 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11436 | return; |
11437 | ||
11438 | nla_put_failure: | |
11439 | genlmsg_cancel(msg, hdr); | |
11440 | nlmsg_free(msg); | |
11441 | ||
11442 | } | |
11443 | ||
11444 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
11445 | struct net_device *netdev, const u8 *bssid, | |
11446 | const u8 *req_ie, size_t req_ie_len, | |
11447 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
11448 | { | |
11449 | struct sk_buff *msg; | |
11450 | void *hdr; | |
11451 | ||
58050fce | 11452 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
11453 | if (!msg) |
11454 | return; | |
11455 | ||
11456 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
11457 | if (!hdr) { | |
11458 | nlmsg_free(msg); | |
11459 | return; | |
11460 | } | |
11461 | ||
9360ffd1 DM |
11462 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11463 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11464 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
11465 | (req_ie && | |
11466 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11467 | (resp_ie && | |
11468 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11469 | goto nla_put_failure; | |
b23aa676 | 11470 | |
3b7b72ee | 11471 | genlmsg_end(msg, hdr); |
b23aa676 | 11472 | |
68eb5503 | 11473 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11474 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11475 | return; |
11476 | ||
11477 | nla_put_failure: | |
11478 | genlmsg_cancel(msg, hdr); | |
11479 | nlmsg_free(msg); | |
11480 | ||
11481 | } | |
11482 | ||
11483 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
11484 | struct net_device *netdev, u16 reason, | |
667503dd | 11485 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
11486 | { |
11487 | struct sk_buff *msg; | |
11488 | void *hdr; | |
11489 | ||
58050fce | 11490 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
11491 | if (!msg) |
11492 | return; | |
11493 | ||
11494 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
11495 | if (!hdr) { | |
11496 | nlmsg_free(msg); | |
11497 | return; | |
11498 | } | |
11499 | ||
9360ffd1 DM |
11500 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11501 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11502 | (from_ap && reason && | |
11503 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
11504 | (from_ap && | |
11505 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
11506 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
11507 | goto nla_put_failure; | |
b23aa676 | 11508 | |
3b7b72ee | 11509 | genlmsg_end(msg, hdr); |
b23aa676 | 11510 | |
68eb5503 | 11511 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11512 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
11513 | return; |
11514 | ||
11515 | nla_put_failure: | |
11516 | genlmsg_cancel(msg, hdr); | |
11517 | nlmsg_free(msg); | |
11518 | ||
11519 | } | |
11520 | ||
04a773ad JB |
11521 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
11522 | struct net_device *netdev, const u8 *bssid, | |
11523 | gfp_t gfp) | |
11524 | { | |
11525 | struct sk_buff *msg; | |
11526 | void *hdr; | |
11527 | ||
fd2120ca | 11528 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
11529 | if (!msg) |
11530 | return; | |
11531 | ||
11532 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
11533 | if (!hdr) { | |
11534 | nlmsg_free(msg); | |
11535 | return; | |
11536 | } | |
11537 | ||
9360ffd1 DM |
11538 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11539 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11540 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
11541 | goto nla_put_failure; | |
04a773ad | 11542 | |
3b7b72ee | 11543 | genlmsg_end(msg, hdr); |
04a773ad | 11544 | |
68eb5503 | 11545 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11546 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
11547 | return; |
11548 | ||
11549 | nla_put_failure: | |
11550 | genlmsg_cancel(msg, hdr); | |
11551 | nlmsg_free(msg); | |
11552 | } | |
11553 | ||
947add36 JB |
11554 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
11555 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 11556 | { |
947add36 | 11557 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 11558 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
11559 | struct sk_buff *msg; |
11560 | void *hdr; | |
11561 | ||
947add36 JB |
11562 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
11563 | return; | |
11564 | ||
11565 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
11566 | ||
c93b5e71 JC |
11567 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11568 | if (!msg) | |
11569 | return; | |
11570 | ||
11571 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
11572 | if (!hdr) { | |
11573 | nlmsg_free(msg); | |
11574 | return; | |
11575 | } | |
11576 | ||
9360ffd1 | 11577 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
11578 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
11579 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
11580 | (ie_len && ie && |
11581 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
11582 | goto nla_put_failure; | |
c93b5e71 | 11583 | |
3b7b72ee | 11584 | genlmsg_end(msg, hdr); |
c93b5e71 | 11585 | |
68eb5503 | 11586 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11587 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
11588 | return; |
11589 | ||
11590 | nla_put_failure: | |
11591 | genlmsg_cancel(msg, hdr); | |
11592 | nlmsg_free(msg); | |
11593 | } | |
947add36 | 11594 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 11595 | |
a3b8b056 JM |
11596 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
11597 | struct net_device *netdev, const u8 *addr, | |
11598 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 11599 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
11600 | { |
11601 | struct sk_buff *msg; | |
11602 | void *hdr; | |
11603 | ||
e6d6e342 | 11604 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
11605 | if (!msg) |
11606 | return; | |
11607 | ||
11608 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
11609 | if (!hdr) { | |
11610 | nlmsg_free(msg); | |
11611 | return; | |
11612 | } | |
11613 | ||
9360ffd1 DM |
11614 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11615 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11616 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
11617 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
11618 | (key_id != -1 && | |
11619 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
11620 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
11621 | goto nla_put_failure; | |
a3b8b056 | 11622 | |
3b7b72ee | 11623 | genlmsg_end(msg, hdr); |
a3b8b056 | 11624 | |
68eb5503 | 11625 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11626 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
11627 | return; |
11628 | ||
11629 | nla_put_failure: | |
11630 | genlmsg_cancel(msg, hdr); | |
11631 | nlmsg_free(msg); | |
11632 | } | |
11633 | ||
6bad8766 LR |
11634 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
11635 | struct ieee80211_channel *channel_before, | |
11636 | struct ieee80211_channel *channel_after) | |
11637 | { | |
11638 | struct sk_buff *msg; | |
11639 | void *hdr; | |
11640 | struct nlattr *nl_freq; | |
11641 | ||
fd2120ca | 11642 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
11643 | if (!msg) |
11644 | return; | |
11645 | ||
11646 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
11647 | if (!hdr) { | |
11648 | nlmsg_free(msg); | |
11649 | return; | |
11650 | } | |
11651 | ||
11652 | /* | |
11653 | * Since we are applying the beacon hint to a wiphy we know its | |
11654 | * wiphy_idx is valid | |
11655 | */ | |
9360ffd1 DM |
11656 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
11657 | goto nla_put_failure; | |
6bad8766 LR |
11658 | |
11659 | /* Before */ | |
11660 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
11661 | if (!nl_freq) | |
11662 | goto nla_put_failure; | |
cdc89b97 | 11663 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
11664 | goto nla_put_failure; |
11665 | nla_nest_end(msg, nl_freq); | |
11666 | ||
11667 | /* After */ | |
11668 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
11669 | if (!nl_freq) | |
11670 | goto nla_put_failure; | |
cdc89b97 | 11671 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
11672 | goto nla_put_failure; |
11673 | nla_nest_end(msg, nl_freq); | |
11674 | ||
3b7b72ee | 11675 | genlmsg_end(msg, hdr); |
6bad8766 | 11676 | |
463d0183 | 11677 | rcu_read_lock(); |
68eb5503 | 11678 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11679 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 11680 | rcu_read_unlock(); |
6bad8766 LR |
11681 | |
11682 | return; | |
11683 | ||
11684 | nla_put_failure: | |
11685 | genlmsg_cancel(msg, hdr); | |
11686 | nlmsg_free(msg); | |
11687 | } | |
11688 | ||
9588bbd5 JM |
11689 | static void nl80211_send_remain_on_chan_event( |
11690 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 11691 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 11692 | struct ieee80211_channel *chan, |
9588bbd5 JM |
11693 | unsigned int duration, gfp_t gfp) |
11694 | { | |
11695 | struct sk_buff *msg; | |
11696 | void *hdr; | |
11697 | ||
11698 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11699 | if (!msg) | |
11700 | return; | |
11701 | ||
11702 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11703 | if (!hdr) { | |
11704 | nlmsg_free(msg); | |
11705 | return; | |
11706 | } | |
11707 | ||
9360ffd1 | 11708 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11709 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11710 | wdev->netdev->ifindex)) || | |
00f53350 | 11711 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 11712 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
11713 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
11714 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
11715 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
11716 | goto nla_put_failure; | |
9588bbd5 | 11717 | |
9360ffd1 DM |
11718 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
11719 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
11720 | goto nla_put_failure; | |
9588bbd5 | 11721 | |
3b7b72ee | 11722 | genlmsg_end(msg, hdr); |
9588bbd5 | 11723 | |
68eb5503 | 11724 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11725 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
11726 | return; |
11727 | ||
11728 | nla_put_failure: | |
11729 | genlmsg_cancel(msg, hdr); | |
11730 | nlmsg_free(msg); | |
11731 | } | |
11732 | ||
947add36 JB |
11733 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
11734 | struct ieee80211_channel *chan, | |
11735 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 11736 | { |
947add36 | 11737 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11738 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11739 | |
11740 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 11741 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 11742 | rdev, wdev, cookie, chan, |
42d97a59 | 11743 | duration, gfp); |
9588bbd5 | 11744 | } |
947add36 | 11745 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 11746 | |
947add36 JB |
11747 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
11748 | struct ieee80211_channel *chan, | |
11749 | gfp_t gfp) | |
9588bbd5 | 11750 | { |
947add36 | 11751 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11752 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11753 | |
11754 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 11755 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 11756 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 11757 | } |
947add36 | 11758 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 11759 | |
947add36 JB |
11760 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
11761 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 11762 | { |
947add36 | 11763 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11764 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
11765 | struct sk_buff *msg; |
11766 | ||
947add36 JB |
11767 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
11768 | ||
58050fce | 11769 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
11770 | if (!msg) |
11771 | return; | |
11772 | ||
cf5ead82 | 11773 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
66266b3a | 11774 | rdev, dev, mac_addr, sinfo) < 0) { |
98b62183 JB |
11775 | nlmsg_free(msg); |
11776 | return; | |
11777 | } | |
11778 | ||
68eb5503 | 11779 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11780 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 11781 | } |
947add36 | 11782 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 11783 | |
cf5ead82 JB |
11784 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
11785 | struct station_info *sinfo, gfp_t gfp) | |
ec15e68b | 11786 | { |
947add36 | 11787 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11788 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b | 11789 | struct sk_buff *msg; |
cf5ead82 JB |
11790 | struct station_info empty_sinfo = {}; |
11791 | ||
11792 | if (!sinfo) | |
11793 | sinfo = &empty_sinfo; | |
ec15e68b | 11794 | |
947add36 JB |
11795 | trace_cfg80211_del_sta(dev, mac_addr); |
11796 | ||
58050fce | 11797 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
11798 | if (!msg) |
11799 | return; | |
11800 | ||
cf5ead82 | 11801 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
57007121 | 11802 | rdev, dev, mac_addr, sinfo) < 0) { |
ec15e68b JM |
11803 | nlmsg_free(msg); |
11804 | return; | |
11805 | } | |
11806 | ||
68eb5503 | 11807 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11808 | NL80211_MCGRP_MLME, gfp); |
ec15e68b | 11809 | } |
cf5ead82 | 11810 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
ec15e68b | 11811 | |
947add36 JB |
11812 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
11813 | enum nl80211_connect_failed_reason reason, | |
11814 | gfp_t gfp) | |
ed44a951 | 11815 | { |
947add36 | 11816 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11817 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
11818 | struct sk_buff *msg; |
11819 | void *hdr; | |
11820 | ||
11821 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
11822 | if (!msg) | |
11823 | return; | |
11824 | ||
11825 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
11826 | if (!hdr) { | |
11827 | nlmsg_free(msg); | |
11828 | return; | |
11829 | } | |
11830 | ||
11831 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11832 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
11833 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
11834 | goto nla_put_failure; | |
11835 | ||
11836 | genlmsg_end(msg, hdr); | |
11837 | ||
68eb5503 | 11838 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11839 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
11840 | return; |
11841 | ||
11842 | nla_put_failure: | |
11843 | genlmsg_cancel(msg, hdr); | |
11844 | nlmsg_free(msg); | |
11845 | } | |
947add36 | 11846 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 11847 | |
b92ab5d8 JB |
11848 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
11849 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
11850 | { |
11851 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 11852 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
11853 | struct sk_buff *msg; |
11854 | void *hdr; | |
15e47304 | 11855 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 11856 | |
15e47304 | 11857 | if (!nlportid) |
28946da7 JB |
11858 | return false; |
11859 | ||
11860 | msg = nlmsg_new(100, gfp); | |
11861 | if (!msg) | |
11862 | return true; | |
11863 | ||
b92ab5d8 | 11864 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
11865 | if (!hdr) { |
11866 | nlmsg_free(msg); | |
11867 | return true; | |
11868 | } | |
11869 | ||
9360ffd1 DM |
11870 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11871 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11872 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11873 | goto nla_put_failure; | |
28946da7 | 11874 | |
9c90a9f6 | 11875 | genlmsg_end(msg, hdr); |
15e47304 | 11876 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
11877 | return true; |
11878 | ||
11879 | nla_put_failure: | |
11880 | genlmsg_cancel(msg, hdr); | |
11881 | nlmsg_free(msg); | |
11882 | return true; | |
11883 | } | |
11884 | ||
947add36 JB |
11885 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
11886 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11887 | { |
947add36 JB |
11888 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11889 | bool ret; | |
11890 | ||
11891 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
11892 | ||
11893 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11894 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
11895 | trace_cfg80211_return_bool(false); | |
11896 | return false; | |
11897 | } | |
11898 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
11899 | addr, gfp); | |
11900 | trace_cfg80211_return_bool(ret); | |
11901 | return ret; | |
b92ab5d8 | 11902 | } |
947add36 | 11903 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 11904 | |
947add36 JB |
11905 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
11906 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11907 | { |
947add36 JB |
11908 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11909 | bool ret; | |
11910 | ||
11911 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
11912 | ||
11913 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11914 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
11915 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
11916 | trace_cfg80211_return_bool(false); | |
11917 | return false; | |
11918 | } | |
11919 | ret = __nl80211_unexpected_frame(dev, | |
11920 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
11921 | addr, gfp); | |
11922 | trace_cfg80211_return_bool(ret); | |
11923 | return ret; | |
b92ab5d8 | 11924 | } |
947add36 | 11925 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 11926 | |
2e161f78 | 11927 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 11928 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 11929 | int freq, int sig_dbm, |
19504cf5 | 11930 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 11931 | { |
71bbc994 | 11932 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11933 | struct sk_buff *msg; |
11934 | void *hdr; | |
026331c4 JM |
11935 | |
11936 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11937 | if (!msg) | |
11938 | return -ENOMEM; | |
11939 | ||
2e161f78 | 11940 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
11941 | if (!hdr) { |
11942 | nlmsg_free(msg); | |
11943 | return -ENOMEM; | |
11944 | } | |
11945 | ||
9360ffd1 | 11946 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11947 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11948 | netdev->ifindex)) || | |
a838490b | 11949 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11950 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
11951 | (sig_dbm && | |
11952 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
11953 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11954 | (flags && | |
11955 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 11956 | goto nla_put_failure; |
026331c4 | 11957 | |
3b7b72ee | 11958 | genlmsg_end(msg, hdr); |
026331c4 | 11959 | |
15e47304 | 11960 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
11961 | |
11962 | nla_put_failure: | |
11963 | genlmsg_cancel(msg, hdr); | |
11964 | nlmsg_free(msg); | |
11965 | return -ENOBUFS; | |
11966 | } | |
11967 | ||
947add36 JB |
11968 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
11969 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 11970 | { |
947add36 | 11971 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11972 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 11973 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11974 | struct sk_buff *msg; |
11975 | void *hdr; | |
11976 | ||
947add36 JB |
11977 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
11978 | ||
026331c4 JM |
11979 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11980 | if (!msg) | |
11981 | return; | |
11982 | ||
2e161f78 | 11983 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
11984 | if (!hdr) { |
11985 | nlmsg_free(msg); | |
11986 | return; | |
11987 | } | |
11988 | ||
9360ffd1 | 11989 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11990 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11991 | netdev->ifindex)) || | |
a838490b | 11992 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11993 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11994 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
11995 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
11996 | goto nla_put_failure; | |
026331c4 | 11997 | |
3b7b72ee | 11998 | genlmsg_end(msg, hdr); |
026331c4 | 11999 | |
68eb5503 | 12000 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12001 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
12002 | return; |
12003 | ||
12004 | nla_put_failure: | |
12005 | genlmsg_cancel(msg, hdr); | |
12006 | nlmsg_free(msg); | |
12007 | } | |
947add36 | 12008 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 12009 | |
5b97f49d JB |
12010 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
12011 | const char *mac, gfp_t gfp) | |
d6dc1a38 | 12012 | { |
947add36 | 12013 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5b97f49d JB |
12014 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
12015 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12016 | void **cb; | |
947add36 | 12017 | |
d6dc1a38 | 12018 | if (!msg) |
5b97f49d | 12019 | return NULL; |
d6dc1a38 | 12020 | |
5b97f49d JB |
12021 | cb = (void **)msg->cb; |
12022 | ||
12023 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
12024 | if (!cb[0]) { | |
d6dc1a38 | 12025 | nlmsg_free(msg); |
5b97f49d | 12026 | return NULL; |
d6dc1a38 JO |
12027 | } |
12028 | ||
9360ffd1 | 12029 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 12030 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 12031 | goto nla_put_failure; |
d6dc1a38 | 12032 | |
5b97f49d | 12033 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
d6dc1a38 JO |
12034 | goto nla_put_failure; |
12035 | ||
5b97f49d JB |
12036 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
12037 | if (!cb[1]) | |
9360ffd1 | 12038 | goto nla_put_failure; |
d6dc1a38 | 12039 | |
5b97f49d | 12040 | cb[2] = rdev; |
d6dc1a38 | 12041 | |
5b97f49d JB |
12042 | return msg; |
12043 | nla_put_failure: | |
12044 | nlmsg_free(msg); | |
12045 | return NULL; | |
12046 | } | |
12047 | ||
12048 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) | |
12049 | { | |
12050 | void **cb = (void **)msg->cb; | |
12051 | struct cfg80211_registered_device *rdev = cb[2]; | |
12052 | ||
12053 | nla_nest_end(msg, cb[1]); | |
12054 | genlmsg_end(msg, cb[0]); | |
12055 | ||
12056 | memset(msg->cb, 0, sizeof(msg->cb)); | |
d6dc1a38 | 12057 | |
68eb5503 | 12058 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12059 | NL80211_MCGRP_MLME, gfp); |
5b97f49d JB |
12060 | } |
12061 | ||
12062 | void cfg80211_cqm_rssi_notify(struct net_device *dev, | |
12063 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
12064 | gfp_t gfp) | |
12065 | { | |
12066 | struct sk_buff *msg; | |
12067 | ||
12068 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); | |
12069 | ||
98f03342 JB |
12070 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
12071 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) | |
12072 | return; | |
12073 | ||
5b97f49d JB |
12074 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
12075 | if (!msg) | |
12076 | return; | |
12077 | ||
12078 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
12079 | rssi_event)) | |
12080 | goto nla_put_failure; | |
12081 | ||
12082 | cfg80211_send_cqm(msg, gfp); | |
12083 | ||
d6dc1a38 JO |
12084 | return; |
12085 | ||
12086 | nla_put_failure: | |
d6dc1a38 JO |
12087 | nlmsg_free(msg); |
12088 | } | |
947add36 | 12089 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 12090 | |
5b97f49d JB |
12091 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
12092 | const u8 *peer, u32 num_packets, | |
12093 | u32 rate, u32 intvl, gfp_t gfp) | |
12094 | { | |
12095 | struct sk_buff *msg; | |
12096 | ||
12097 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12098 | if (!msg) | |
12099 | return; | |
12100 | ||
12101 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
12102 | goto nla_put_failure; | |
12103 | ||
12104 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
12105 | goto nla_put_failure; | |
12106 | ||
12107 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
12108 | goto nla_put_failure; | |
12109 | ||
12110 | cfg80211_send_cqm(msg, gfp); | |
12111 | return; | |
12112 | ||
12113 | nla_put_failure: | |
12114 | nlmsg_free(msg); | |
12115 | } | |
12116 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); | |
12117 | ||
12118 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, | |
12119 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
12120 | { | |
12121 | struct sk_buff *msg; | |
12122 | ||
12123 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); | |
12124 | ||
12125 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12126 | if (!msg) | |
12127 | return; | |
12128 | ||
12129 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) | |
12130 | goto nla_put_failure; | |
12131 | ||
12132 | cfg80211_send_cqm(msg, gfp); | |
12133 | return; | |
12134 | ||
12135 | nla_put_failure: | |
12136 | nlmsg_free(msg); | |
12137 | } | |
12138 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); | |
12139 | ||
98f03342 JB |
12140 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
12141 | { | |
12142 | struct sk_buff *msg; | |
12143 | ||
12144 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); | |
12145 | if (!msg) | |
12146 | return; | |
12147 | ||
12148 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) | |
12149 | goto nla_put_failure; | |
12150 | ||
12151 | cfg80211_send_cqm(msg, gfp); | |
12152 | return; | |
12153 | ||
12154 | nla_put_failure: | |
12155 | nlmsg_free(msg); | |
12156 | } | |
12157 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); | |
12158 | ||
947add36 JB |
12159 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
12160 | struct net_device *netdev, const u8 *bssid, | |
12161 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
12162 | { |
12163 | struct sk_buff *msg; | |
12164 | struct nlattr *rekey_attr; | |
12165 | void *hdr; | |
12166 | ||
58050fce | 12167 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
12168 | if (!msg) |
12169 | return; | |
12170 | ||
12171 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
12172 | if (!hdr) { | |
12173 | nlmsg_free(msg); | |
12174 | return; | |
12175 | } | |
12176 | ||
9360ffd1 DM |
12177 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12178 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12179 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
12180 | goto nla_put_failure; | |
e5497d76 JB |
12181 | |
12182 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
12183 | if (!rekey_attr) | |
12184 | goto nla_put_failure; | |
12185 | ||
9360ffd1 DM |
12186 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
12187 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
12188 | goto nla_put_failure; | |
e5497d76 JB |
12189 | |
12190 | nla_nest_end(msg, rekey_attr); | |
12191 | ||
3b7b72ee | 12192 | genlmsg_end(msg, hdr); |
e5497d76 | 12193 | |
68eb5503 | 12194 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12195 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
12196 | return; |
12197 | ||
12198 | nla_put_failure: | |
12199 | genlmsg_cancel(msg, hdr); | |
12200 | nlmsg_free(msg); | |
12201 | } | |
12202 | ||
947add36 JB |
12203 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
12204 | const u8 *replay_ctr, gfp_t gfp) | |
12205 | { | |
12206 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12207 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12208 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12209 | |
12210 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
12211 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
12212 | } | |
12213 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
12214 | ||
12215 | static void | |
12216 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
12217 | struct net_device *netdev, int index, | |
12218 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
12219 | { |
12220 | struct sk_buff *msg; | |
12221 | struct nlattr *attr; | |
12222 | void *hdr; | |
12223 | ||
58050fce | 12224 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
12225 | if (!msg) |
12226 | return; | |
12227 | ||
12228 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
12229 | if (!hdr) { | |
12230 | nlmsg_free(msg); | |
12231 | return; | |
12232 | } | |
12233 | ||
9360ffd1 DM |
12234 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12235 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
12236 | goto nla_put_failure; | |
c9df56b4 JM |
12237 | |
12238 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
12239 | if (!attr) | |
12240 | goto nla_put_failure; | |
12241 | ||
9360ffd1 DM |
12242 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
12243 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
12244 | (preauth && | |
12245 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
12246 | goto nla_put_failure; | |
c9df56b4 JM |
12247 | |
12248 | nla_nest_end(msg, attr); | |
12249 | ||
3b7b72ee | 12250 | genlmsg_end(msg, hdr); |
c9df56b4 | 12251 | |
68eb5503 | 12252 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12253 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
12254 | return; |
12255 | ||
12256 | nla_put_failure: | |
12257 | genlmsg_cancel(msg, hdr); | |
12258 | nlmsg_free(msg); | |
12259 | } | |
12260 | ||
947add36 JB |
12261 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
12262 | const u8 *bssid, bool preauth, gfp_t gfp) | |
12263 | { | |
12264 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12265 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12266 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12267 | |
12268 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
12269 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
12270 | } | |
12271 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
12272 | ||
12273 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
12274 | struct net_device *netdev, | |
12275 | struct cfg80211_chan_def *chandef, | |
f8d7552e LC |
12276 | gfp_t gfp, |
12277 | enum nl80211_commands notif, | |
12278 | u8 count) | |
5314526b TP |
12279 | { |
12280 | struct sk_buff *msg; | |
12281 | void *hdr; | |
12282 | ||
58050fce | 12283 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
12284 | if (!msg) |
12285 | return; | |
12286 | ||
f8d7552e | 12287 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
5314526b TP |
12288 | if (!hdr) { |
12289 | nlmsg_free(msg); | |
12290 | return; | |
12291 | } | |
12292 | ||
683b6d3b JB |
12293 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
12294 | goto nla_put_failure; | |
12295 | ||
12296 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 12297 | goto nla_put_failure; |
5314526b | 12298 | |
f8d7552e LC |
12299 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
12300 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) | |
12301 | goto nla_put_failure; | |
12302 | ||
5314526b TP |
12303 | genlmsg_end(msg, hdr); |
12304 | ||
68eb5503 | 12305 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12306 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
12307 | return; |
12308 | ||
12309 | nla_put_failure: | |
12310 | genlmsg_cancel(msg, hdr); | |
12311 | nlmsg_free(msg); | |
12312 | } | |
12313 | ||
947add36 JB |
12314 | void cfg80211_ch_switch_notify(struct net_device *dev, |
12315 | struct cfg80211_chan_def *chandef) | |
84f10708 | 12316 | { |
947add36 JB |
12317 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
12318 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12319 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 12320 | |
e487eaeb | 12321 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 12322 | |
e487eaeb | 12323 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 | 12324 | |
9e0e2961 | 12325 | wdev->chandef = *chandef; |
96f55f12 | 12326 | wdev->preset_chandef = *chandef; |
f8d7552e LC |
12327 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
12328 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); | |
947add36 JB |
12329 | } |
12330 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
12331 | ||
f8d7552e LC |
12332 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
12333 | struct cfg80211_chan_def *chandef, | |
12334 | u8 count) | |
12335 | { | |
12336 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12337 | struct wiphy *wiphy = wdev->wiphy; | |
12338 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
12339 | ||
12340 | trace_cfg80211_ch_switch_started_notify(dev, chandef); | |
12341 | ||
12342 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | |
12343 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); | |
12344 | } | |
12345 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | |
12346 | ||
04f39047 SW |
12347 | void |
12348 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 12349 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
12350 | enum nl80211_radar_event event, |
12351 | struct net_device *netdev, gfp_t gfp) | |
12352 | { | |
12353 | struct sk_buff *msg; | |
12354 | void *hdr; | |
12355 | ||
12356 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12357 | if (!msg) | |
12358 | return; | |
12359 | ||
12360 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
12361 | if (!hdr) { | |
12362 | nlmsg_free(msg); | |
12363 | return; | |
12364 | } | |
12365 | ||
12366 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
12367 | goto nla_put_failure; | |
12368 | ||
12369 | /* NOP and radar events don't need a netdev parameter */ | |
12370 | if (netdev) { | |
12371 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
12372 | ||
12373 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12374 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12375 | goto nla_put_failure; | |
12376 | } | |
12377 | ||
12378 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
12379 | goto nla_put_failure; | |
12380 | ||
12381 | if (nl80211_send_chandef(msg, chandef)) | |
12382 | goto nla_put_failure; | |
12383 | ||
9c90a9f6 | 12384 | genlmsg_end(msg, hdr); |
04f39047 | 12385 | |
68eb5503 | 12386 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12387 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
12388 | return; |
12389 | ||
12390 | nla_put_failure: | |
12391 | genlmsg_cancel(msg, hdr); | |
12392 | nlmsg_free(msg); | |
12393 | } | |
12394 | ||
7f6cf311 JB |
12395 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
12396 | u64 cookie, bool acked, gfp_t gfp) | |
12397 | { | |
12398 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12399 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
12400 | struct sk_buff *msg; |
12401 | void *hdr; | |
7f6cf311 | 12402 | |
4ee3e063 BL |
12403 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
12404 | ||
58050fce | 12405 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 12406 | |
7f6cf311 JB |
12407 | if (!msg) |
12408 | return; | |
12409 | ||
12410 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
12411 | if (!hdr) { | |
12412 | nlmsg_free(msg); | |
12413 | return; | |
12414 | } | |
12415 | ||
9360ffd1 DM |
12416 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12417 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12418 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
12419 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
12420 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
12421 | goto nla_put_failure; | |
7f6cf311 | 12422 | |
9c90a9f6 | 12423 | genlmsg_end(msg, hdr); |
7f6cf311 | 12424 | |
68eb5503 | 12425 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12426 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
12427 | return; |
12428 | ||
12429 | nla_put_failure: | |
12430 | genlmsg_cancel(msg, hdr); | |
12431 | nlmsg_free(msg); | |
12432 | } | |
12433 | EXPORT_SYMBOL(cfg80211_probe_status); | |
12434 | ||
5e760230 JB |
12435 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
12436 | const u8 *frame, size_t len, | |
37c73b5f | 12437 | int freq, int sig_dbm) |
5e760230 | 12438 | { |
f26cbf40 | 12439 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
12440 | struct sk_buff *msg; |
12441 | void *hdr; | |
37c73b5f | 12442 | struct cfg80211_beacon_registration *reg; |
5e760230 | 12443 | |
4ee3e063 BL |
12444 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
12445 | ||
37c73b5f BG |
12446 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12447 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
12448 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
12449 | if (!msg) { | |
12450 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
12451 | return; | |
12452 | } | |
5e760230 | 12453 | |
37c73b5f BG |
12454 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
12455 | if (!hdr) | |
12456 | goto nla_put_failure; | |
5e760230 | 12457 | |
37c73b5f BG |
12458 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12459 | (freq && | |
12460 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
12461 | (sig_dbm && | |
12462 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
12463 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
12464 | goto nla_put_failure; | |
5e760230 | 12465 | |
37c73b5f | 12466 | genlmsg_end(msg, hdr); |
5e760230 | 12467 | |
37c73b5f BG |
12468 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
12469 | } | |
12470 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
12471 | return; |
12472 | ||
12473 | nla_put_failure: | |
37c73b5f BG |
12474 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
12475 | if (hdr) | |
12476 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
12477 | nlmsg_free(msg); |
12478 | } | |
12479 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
12480 | ||
cd8f7cb4 | 12481 | #ifdef CONFIG_PM |
8cd4d456 LC |
12482 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
12483 | struct cfg80211_wowlan_wakeup *wakeup) | |
12484 | { | |
12485 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | |
12486 | struct nlattr *nl_results, *nl_match, *nl_freqs; | |
12487 | int i, j; | |
12488 | ||
12489 | nl_results = nla_nest_start( | |
12490 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | |
12491 | if (!nl_results) | |
12492 | return -EMSGSIZE; | |
12493 | ||
12494 | for (i = 0; i < nd->n_matches; i++) { | |
12495 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | |
12496 | ||
12497 | nl_match = nla_nest_start(msg, i); | |
12498 | if (!nl_match) | |
12499 | break; | |
12500 | ||
12501 | /* The SSID attribute is optional in nl80211, but for | |
12502 | * simplicity reasons it's always present in the | |
12503 | * cfg80211 structure. If a driver can't pass the | |
12504 | * SSID, that needs to be changed. A zero length SSID | |
12505 | * is still a valid SSID (wildcard), so it cannot be | |
12506 | * used for this purpose. | |
12507 | */ | |
12508 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | |
12509 | match->ssid.ssid)) { | |
12510 | nla_nest_cancel(msg, nl_match); | |
12511 | goto out; | |
12512 | } | |
12513 | ||
12514 | if (match->n_channels) { | |
12515 | nl_freqs = nla_nest_start( | |
12516 | msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
12517 | if (!nl_freqs) { | |
12518 | nla_nest_cancel(msg, nl_match); | |
12519 | goto out; | |
12520 | } | |
12521 | ||
12522 | for (j = 0; j < match->n_channels; j++) { | |
12523 | if (nla_put_u32(msg, | |
12524 | NL80211_ATTR_WIPHY_FREQ, | |
12525 | match->channels[j])) { | |
12526 | nla_nest_cancel(msg, nl_freqs); | |
12527 | nla_nest_cancel(msg, nl_match); | |
12528 | goto out; | |
12529 | } | |
12530 | } | |
12531 | ||
12532 | nla_nest_end(msg, nl_freqs); | |
12533 | } | |
12534 | ||
12535 | nla_nest_end(msg, nl_match); | |
12536 | } | |
12537 | ||
12538 | out: | |
12539 | nla_nest_end(msg, nl_results); | |
12540 | return 0; | |
12541 | } | |
12542 | ||
cd8f7cb4 JB |
12543 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
12544 | struct cfg80211_wowlan_wakeup *wakeup, | |
12545 | gfp_t gfp) | |
12546 | { | |
f26cbf40 | 12547 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
12548 | struct sk_buff *msg; |
12549 | void *hdr; | |
9c90a9f6 | 12550 | int size = 200; |
cd8f7cb4 JB |
12551 | |
12552 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
12553 | ||
12554 | if (wakeup) | |
12555 | size += wakeup->packet_present_len; | |
12556 | ||
12557 | msg = nlmsg_new(size, gfp); | |
12558 | if (!msg) | |
12559 | return; | |
12560 | ||
12561 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
12562 | if (!hdr) | |
12563 | goto free_msg; | |
12564 | ||
12565 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12566 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12567 | goto free_msg; | |
12568 | ||
12569 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
12570 | wdev->netdev->ifindex)) | |
12571 | goto free_msg; | |
12572 | ||
12573 | if (wakeup) { | |
12574 | struct nlattr *reasons; | |
12575 | ||
12576 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
12577 | if (!reasons) |
12578 | goto free_msg; | |
cd8f7cb4 JB |
12579 | |
12580 | if (wakeup->disconnect && | |
12581 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
12582 | goto free_msg; | |
12583 | if (wakeup->magic_pkt && | |
12584 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
12585 | goto free_msg; | |
12586 | if (wakeup->gtk_rekey_failure && | |
12587 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
12588 | goto free_msg; | |
12589 | if (wakeup->eap_identity_req && | |
12590 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
12591 | goto free_msg; | |
12592 | if (wakeup->four_way_handshake && | |
12593 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
12594 | goto free_msg; | |
12595 | if (wakeup->rfkill_release && | |
12596 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
12597 | goto free_msg; | |
12598 | ||
12599 | if (wakeup->pattern_idx >= 0 && | |
12600 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
12601 | wakeup->pattern_idx)) | |
12602 | goto free_msg; | |
12603 | ||
ae917c9f JB |
12604 | if (wakeup->tcp_match && |
12605 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
12606 | goto free_msg; | |
2a0e047e | 12607 | |
ae917c9f JB |
12608 | if (wakeup->tcp_connlost && |
12609 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
12610 | goto free_msg; | |
2a0e047e | 12611 | |
ae917c9f JB |
12612 | if (wakeup->tcp_nomoretokens && |
12613 | nla_put_flag(msg, | |
12614 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
12615 | goto free_msg; | |
2a0e047e | 12616 | |
cd8f7cb4 JB |
12617 | if (wakeup->packet) { |
12618 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
12619 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
12620 | ||
12621 | if (!wakeup->packet_80211) { | |
12622 | pkt_attr = | |
12623 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
12624 | len_attr = | |
12625 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
12626 | } | |
12627 | ||
12628 | if (wakeup->packet_len && | |
12629 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
12630 | goto free_msg; | |
12631 | ||
12632 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
12633 | wakeup->packet)) | |
12634 | goto free_msg; | |
12635 | } | |
12636 | ||
8cd4d456 LC |
12637 | if (wakeup->net_detect && |
12638 | cfg80211_net_detect_results(msg, wakeup)) | |
12639 | goto free_msg; | |
12640 | ||
cd8f7cb4 JB |
12641 | nla_nest_end(msg, reasons); |
12642 | } | |
12643 | ||
9c90a9f6 | 12644 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 12645 | |
68eb5503 | 12646 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12647 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
12648 | return; |
12649 | ||
12650 | free_msg: | |
12651 | nlmsg_free(msg); | |
12652 | } | |
12653 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
12654 | #endif | |
12655 | ||
3475b094 JM |
12656 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
12657 | enum nl80211_tdls_operation oper, | |
12658 | u16 reason_code, gfp_t gfp) | |
12659 | { | |
12660 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12661 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
12662 | struct sk_buff *msg; |
12663 | void *hdr; | |
3475b094 JM |
12664 | |
12665 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
12666 | reason_code); | |
12667 | ||
12668 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12669 | if (!msg) | |
12670 | return; | |
12671 | ||
12672 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
12673 | if (!hdr) { | |
12674 | nlmsg_free(msg); | |
12675 | return; | |
12676 | } | |
12677 | ||
12678 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12679 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12680 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
12681 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
12682 | (reason_code > 0 && | |
12683 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
12684 | goto nla_put_failure; | |
12685 | ||
9c90a9f6 | 12686 | genlmsg_end(msg, hdr); |
3475b094 | 12687 | |
68eb5503 | 12688 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12689 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
12690 | return; |
12691 | ||
12692 | nla_put_failure: | |
12693 | genlmsg_cancel(msg, hdr); | |
12694 | nlmsg_free(msg); | |
12695 | } | |
12696 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
12697 | ||
026331c4 JM |
12698 | static int nl80211_netlink_notify(struct notifier_block * nb, |
12699 | unsigned long state, | |
12700 | void *_notify) | |
12701 | { | |
12702 | struct netlink_notify *notify = _notify; | |
12703 | struct cfg80211_registered_device *rdev; | |
12704 | struct wireless_dev *wdev; | |
37c73b5f | 12705 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
12706 | |
12707 | if (state != NETLINK_URELEASE) | |
12708 | return NOTIFY_DONE; | |
12709 | ||
12710 | rcu_read_lock(); | |
12711 | ||
5e760230 | 12712 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
78f22b6a | 12713 | bool schedule_destroy_work = false; |
93a1e86c JR |
12714 | bool schedule_scan_stop = false; |
12715 | struct cfg80211_sched_scan_request *sched_scan_req = | |
12716 | rcu_dereference(rdev->sched_scan_req); | |
12717 | ||
12718 | if (sched_scan_req && notify->portid && | |
12719 | sched_scan_req->owner_nlportid == notify->portid) | |
12720 | schedule_scan_stop = true; | |
78f22b6a JB |
12721 | |
12722 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { | |
15e47304 | 12723 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 12724 | |
78f22b6a JB |
12725 | if (wdev->owner_nlportid == notify->portid) |
12726 | schedule_destroy_work = true; | |
12727 | } | |
12728 | ||
37c73b5f BG |
12729 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12730 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
12731 | list) { | |
12732 | if (reg->nlportid == notify->portid) { | |
12733 | list_del(®->list); | |
12734 | kfree(reg); | |
12735 | break; | |
12736 | } | |
12737 | } | |
12738 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
78f22b6a JB |
12739 | |
12740 | if (schedule_destroy_work) { | |
12741 | struct cfg80211_iface_destroy *destroy; | |
12742 | ||
12743 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | |
12744 | if (destroy) { | |
12745 | destroy->nlportid = notify->portid; | |
12746 | spin_lock(&rdev->destroy_list_lock); | |
12747 | list_add(&destroy->list, &rdev->destroy_list); | |
12748 | spin_unlock(&rdev->destroy_list_lock); | |
12749 | schedule_work(&rdev->destroy_work); | |
12750 | } | |
93a1e86c JR |
12751 | } else if (schedule_scan_stop) { |
12752 | sched_scan_req->owner_nlportid = 0; | |
12753 | ||
12754 | if (rdev->ops->sched_scan_stop && | |
12755 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
12756 | schedule_work(&rdev->sched_scan_stop_wk); | |
78f22b6a | 12757 | } |
5e760230 | 12758 | } |
026331c4 JM |
12759 | |
12760 | rcu_read_unlock(); | |
12761 | ||
6784c7db | 12762 | return NOTIFY_OK; |
026331c4 JM |
12763 | } |
12764 | ||
12765 | static struct notifier_block nl80211_netlink_notifier = { | |
12766 | .notifier_call = nl80211_netlink_notify, | |
12767 | }; | |
12768 | ||
355199e0 JM |
12769 | void cfg80211_ft_event(struct net_device *netdev, |
12770 | struct cfg80211_ft_event_params *ft_event) | |
12771 | { | |
12772 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 12773 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
12774 | struct sk_buff *msg; |
12775 | void *hdr; | |
355199e0 JM |
12776 | |
12777 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
12778 | ||
12779 | if (!ft_event->target_ap) | |
12780 | return; | |
12781 | ||
12782 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12783 | if (!msg) | |
12784 | return; | |
12785 | ||
12786 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
12787 | if (!hdr) |
12788 | goto out; | |
355199e0 | 12789 | |
ae917c9f JB |
12790 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12791 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12792 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
12793 | goto out; | |
355199e0 | 12794 | |
ae917c9f JB |
12795 | if (ft_event->ies && |
12796 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
12797 | goto out; | |
12798 | if (ft_event->ric_ies && | |
12799 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
12800 | ft_event->ric_ies)) | |
12801 | goto out; | |
355199e0 | 12802 | |
9c90a9f6 | 12803 | genlmsg_end(msg, hdr); |
355199e0 | 12804 | |
68eb5503 | 12805 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12806 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
12807 | return; |
12808 | out: | |
12809 | nlmsg_free(msg); | |
355199e0 JM |
12810 | } |
12811 | EXPORT_SYMBOL(cfg80211_ft_event); | |
12812 | ||
5de17984 AS |
12813 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
12814 | { | |
12815 | struct cfg80211_registered_device *rdev; | |
12816 | struct sk_buff *msg; | |
12817 | void *hdr; | |
12818 | u32 nlportid; | |
12819 | ||
f26cbf40 | 12820 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
12821 | if (!rdev->crit_proto_nlportid) |
12822 | return; | |
12823 | ||
12824 | nlportid = rdev->crit_proto_nlportid; | |
12825 | rdev->crit_proto_nlportid = 0; | |
12826 | ||
12827 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12828 | if (!msg) | |
12829 | return; | |
12830 | ||
12831 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
12832 | if (!hdr) | |
12833 | goto nla_put_failure; | |
12834 | ||
12835 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12836 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12837 | goto nla_put_failure; | |
12838 | ||
12839 | genlmsg_end(msg, hdr); | |
12840 | ||
12841 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
12842 | return; | |
12843 | ||
12844 | nla_put_failure: | |
12845 | if (hdr) | |
12846 | genlmsg_cancel(msg, hdr); | |
12847 | nlmsg_free(msg); | |
12848 | ||
12849 | } | |
12850 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
12851 | ||
348baf0e JB |
12852 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
12853 | { | |
12854 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12855 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
12856 | struct sk_buff *msg; |
12857 | void *hdr; | |
12858 | ||
12859 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12860 | if (!msg) | |
12861 | return; | |
12862 | ||
12863 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
12864 | if (!hdr) | |
12865 | goto out; | |
12866 | ||
12867 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12868 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
12869 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12870 | goto out; | |
12871 | ||
12872 | genlmsg_end(msg, hdr); | |
12873 | ||
12874 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
12875 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
12876 | return; | |
12877 | out: | |
12878 | nlmsg_free(msg); | |
12879 | } | |
12880 | ||
55682965 JB |
12881 | /* initialisation/exit functions */ |
12882 | ||
12883 | int nl80211_init(void) | |
12884 | { | |
0d63cbb5 | 12885 | int err; |
55682965 | 12886 | |
2a94fe48 JB |
12887 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
12888 | nl80211_mcgrps); | |
55682965 JB |
12889 | if (err) |
12890 | return err; | |
12891 | ||
026331c4 JM |
12892 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
12893 | if (err) | |
12894 | goto err_out; | |
12895 | ||
55682965 JB |
12896 | return 0; |
12897 | err_out: | |
12898 | genl_unregister_family(&nl80211_fam); | |
12899 | return err; | |
12900 | } | |
12901 | ||
12902 | void nl80211_exit(void) | |
12903 | { | |
026331c4 | 12904 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
12905 | genl_unregister_family(&nl80211_fam); |
12906 | } |