]>
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 |
0c9ca11b | 6 | * Copyright 2015-2016 Intel Deutschland GmbH |
55682965 JB |
7 | */ |
8 | ||
9 | #include <linux/if.h> | |
10 | #include <linux/module.h> | |
11 | #include <linux/err.h> | |
5a0e3ad6 | 12 | #include <linux/slab.h> |
55682965 JB |
13 | #include <linux/list.h> |
14 | #include <linux/if_ether.h> | |
15 | #include <linux/ieee80211.h> | |
16 | #include <linux/nl80211.h> | |
17 | #include <linux/rtnetlink.h> | |
18 | #include <linux/netlink.h> | |
2a519311 | 19 | #include <linux/etherdevice.h> |
463d0183 | 20 | #include <net/net_namespace.h> |
55682965 JB |
21 | #include <net/genetlink.h> |
22 | #include <net/cfg80211.h> | |
463d0183 | 23 | #include <net/sock.h> |
2a0e047e | 24 | #include <net/inet_connection_sock.h> |
55682965 JB |
25 | #include "core.h" |
26 | #include "nl80211.h" | |
b2e1b302 | 27 | #include "reg.h" |
e35e4d28 | 28 | #include "rdev-ops.h" |
55682965 | 29 | |
5fb628e9 JM |
30 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
31 | struct genl_info *info, | |
32 | struct cfg80211_crypto_settings *settings, | |
33 | int cipher_limit); | |
34 | ||
f84f771d | 35 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 | 36 | struct genl_info *info); |
f84f771d | 37 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
38 | struct genl_info *info); |
39 | ||
55682965 JB |
40 | /* the netlink family */ |
41 | static struct genl_family nl80211_fam = { | |
fb4e1568 MH |
42 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
43 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ | |
44 | .hdrsize = 0, /* no private header */ | |
45 | .version = 1, /* no particular meaning now */ | |
55682965 | 46 | .maxattr = NL80211_ATTR_MAX, |
463d0183 | 47 | .netnsok = true, |
4c476991 JB |
48 | .pre_doit = nl80211_pre_doit, |
49 | .post_doit = nl80211_post_doit, | |
55682965 JB |
50 | }; |
51 | ||
2a94fe48 JB |
52 | /* multicast groups */ |
53 | enum nl80211_multicast_groups { | |
54 | NL80211_MCGRP_CONFIG, | |
55 | NL80211_MCGRP_SCAN, | |
56 | NL80211_MCGRP_REGULATORY, | |
57 | NL80211_MCGRP_MLME, | |
567ffc35 | 58 | NL80211_MCGRP_VENDOR, |
2a94fe48 JB |
59 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
60 | }; | |
61 | ||
62 | static const struct genl_multicast_group nl80211_mcgrps[] = { | |
71b836ec JB |
63 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
64 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, | |
65 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, | |
66 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, | |
67 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, | |
2a94fe48 | 68 | #ifdef CONFIG_NL80211_TESTMODE |
71b836ec | 69 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
2a94fe48 JB |
70 | #endif |
71 | }; | |
72 | ||
89a54e48 JB |
73 | /* returns ERR_PTR values */ |
74 | static struct wireless_dev * | |
75 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 76 | { |
89a54e48 JB |
77 | struct cfg80211_registered_device *rdev; |
78 | struct wireless_dev *result = NULL; | |
79 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
80 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
81 | u64 wdev_id; | |
82 | int wiphy_idx = -1; | |
83 | int ifidx = -1; | |
55682965 | 84 | |
5fe231e8 | 85 | ASSERT_RTNL(); |
55682965 | 86 | |
89a54e48 JB |
87 | if (!have_ifidx && !have_wdev_id) |
88 | return ERR_PTR(-EINVAL); | |
55682965 | 89 | |
89a54e48 JB |
90 | if (have_ifidx) |
91 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
92 | if (have_wdev_id) { | |
93 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
94 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
95 | } |
96 | ||
89a54e48 JB |
97 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
98 | struct wireless_dev *wdev; | |
99 | ||
100 | if (wiphy_net(&rdev->wiphy) != netns) | |
101 | continue; | |
102 | ||
103 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
104 | continue; | |
105 | ||
89a54e48 JB |
106 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
107 | if (have_ifidx && wdev->netdev && | |
108 | wdev->netdev->ifindex == ifidx) { | |
109 | result = wdev; | |
110 | break; | |
111 | } | |
112 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
113 | result = wdev; | |
114 | break; | |
115 | } | |
116 | } | |
89a54e48 JB |
117 | |
118 | if (result) | |
119 | break; | |
120 | } | |
121 | ||
122 | if (result) | |
123 | return result; | |
124 | return ERR_PTR(-ENODEV); | |
55682965 JB |
125 | } |
126 | ||
a9455408 | 127 | static struct cfg80211_registered_device * |
878d9ec7 | 128 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 129 | { |
7fee4778 JB |
130 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
131 | struct net_device *netdev; | |
a9455408 | 132 | |
5fe231e8 | 133 | ASSERT_RTNL(); |
a9455408 | 134 | |
878d9ec7 | 135 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
136 | !attrs[NL80211_ATTR_IFINDEX] && |
137 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
138 | return ERR_PTR(-EINVAL); |
139 | ||
878d9ec7 | 140 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 141 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 142 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 143 | |
89a54e48 JB |
144 | if (attrs[NL80211_ATTR_WDEV]) { |
145 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
146 | struct wireless_dev *wdev; | |
147 | bool found = false; | |
148 | ||
149 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
150 | if (tmp) { | |
151 | /* make sure wdev exists */ | |
89a54e48 JB |
152 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
153 | if (wdev->identifier != (u32)wdev_id) | |
154 | continue; | |
155 | found = true; | |
156 | break; | |
157 | } | |
89a54e48 JB |
158 | |
159 | if (!found) | |
160 | tmp = NULL; | |
161 | ||
162 | if (rdev && tmp != rdev) | |
163 | return ERR_PTR(-EINVAL); | |
164 | rdev = tmp; | |
165 | } | |
166 | } | |
167 | ||
878d9ec7 JB |
168 | if (attrs[NL80211_ATTR_IFINDEX]) { |
169 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
7f2b8562 | 170 | netdev = __dev_get_by_index(netns, ifindex); |
7fee4778 JB |
171 | if (netdev) { |
172 | if (netdev->ieee80211_ptr) | |
f26cbf40 ZG |
173 | tmp = wiphy_to_rdev( |
174 | netdev->ieee80211_ptr->wiphy); | |
7fee4778 JB |
175 | else |
176 | tmp = NULL; | |
177 | ||
7fee4778 JB |
178 | /* not wireless device -- return error */ |
179 | if (!tmp) | |
180 | return ERR_PTR(-EINVAL); | |
181 | ||
182 | /* mismatch -- return error */ | |
183 | if (rdev && tmp != rdev) | |
184 | return ERR_PTR(-EINVAL); | |
185 | ||
186 | rdev = tmp; | |
a9455408 | 187 | } |
a9455408 | 188 | } |
a9455408 | 189 | |
4f7eff10 JB |
190 | if (!rdev) |
191 | return ERR_PTR(-ENODEV); | |
a9455408 | 192 | |
4f7eff10 JB |
193 | if (netns != wiphy_net(&rdev->wiphy)) |
194 | return ERR_PTR(-ENODEV); | |
195 | ||
196 | return rdev; | |
a9455408 JB |
197 | } |
198 | ||
199 | /* | |
200 | * This function returns a pointer to the driver | |
201 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
202 | * |
203 | * The result of this can be a PTR_ERR and hence must | |
204 | * be checked with IS_ERR() for errors. | |
205 | */ | |
206 | static struct cfg80211_registered_device * | |
4f7eff10 | 207 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 208 | { |
5fe231e8 | 209 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
210 | } |
211 | ||
55682965 | 212 | /* policy for the attributes */ |
8cd4d456 | 213 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
55682965 JB |
214 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
215 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 216 | .len = 20-1 }, |
31888487 | 217 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 218 | |
72bdcf34 | 219 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 220 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
221 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
222 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
223 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
224 | ||
b9a5f8ca JM |
225 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
226 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
227 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
228 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 229 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
3057dbfd | 230 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
55682965 JB |
231 | |
232 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
233 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
234 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 235 | |
e007b857 EP |
236 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
237 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 238 | |
b9454e83 | 239 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
240 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
241 | .len = WLAN_MAX_KEY_LEN }, | |
242 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
243 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
244 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 245 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 246 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
247 | |
248 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
249 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
250 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
251 | .len = IEEE80211_MAX_DATA_LEN }, | |
252 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
253 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
254 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
255 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
256 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
257 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
258 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 259 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 260 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 261 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 262 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 263 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 264 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 265 | |
b2e1b302 LR |
266 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
267 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
268 | ||
9f1ba906 JM |
269 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
270 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
271 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
272 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
273 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 274 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 275 | |
24bdd9f4 | 276 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 277 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 278 | |
6c739419 | 279 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
280 | |
281 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
282 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
283 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
284 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
285 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
286 | |
287 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
288 | .len = IEEE80211_MAX_SSID_LEN }, | |
289 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
290 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 291 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 292 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 293 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
294 | [NL80211_ATTR_STA_FLAGS2] = { |
295 | .len = sizeof(struct nl80211_sta_flag_update), | |
296 | }, | |
3f77316c | 297 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
298 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
299 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
300 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
301 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
302 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 303 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 304 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
305 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
306 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
307 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
308 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 309 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
310 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
311 | .len = IEEE80211_MAX_DATA_LEN }, | |
312 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 313 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 314 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 315 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 316 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
317 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
318 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 319 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
320 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
321 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 322 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 323 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 324 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 325 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 326 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 327 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 328 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 329 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 330 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
331 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
332 | .len = IEEE80211_MAX_DATA_LEN }, | |
333 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
334 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 335 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 336 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 337 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
338 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
339 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
340 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
341 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
342 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
31fa97c5 | 343 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
e247bd90 | 344 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
345 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
346 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 347 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
348 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
349 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
350 | .len = NL80211_HT_CAPABILITY_LEN | |
351 | }, | |
1d9d9213 | 352 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 353 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 354 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 355 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 356 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
e39e5b5e | 357 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
f461be3e | 358 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
ed473771 | 359 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
53cabad7 JB |
360 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
361 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | |
77765eaf VT |
362 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
363 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
364 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
365 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 366 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
367 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
368 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
369 | .len = NL80211_VHT_CAPABILITY_LEN, | |
370 | }, | |
355199e0 JM |
371 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
372 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
373 | .len = IEEE80211_MAX_DATA_LEN }, | |
5e4b6f56 | 374 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
16ef1fe2 SW |
375 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
376 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | |
377 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | |
9a774c78 AO |
378 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
379 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, | |
c01fc9ad SD |
380 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
381 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, | |
5336fa88 | 382 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
60f4a7b1 | 383 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
ad7e718c JB |
384 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
385 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, | |
386 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, | |
fa9ffc74 KP |
387 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
388 | .len = IEEE80211_QOS_MAP_LEN_MAX }, | |
1df4a510 JM |
389 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
390 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, | |
df942e7b | 391 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
18e5ca65 | 392 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
34d22ce2 | 393 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
bab5ab7d | 394 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
960d01ac JB |
395 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
396 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, | |
397 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, | |
18998c38 | 398 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
ad2b26ab | 399 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
1bdd716c | 400 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
4b681c82 | 401 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
9c748934 | 402 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
05050753 | 403 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
34d50519 | 404 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
38de03d2 | 405 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
17b94247 | 406 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 }, |
55682965 JB |
407 | }; |
408 | ||
e31b8213 | 409 | /* policy for the key attributes */ |
b54452b0 | 410 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 411 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
412 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
413 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 414 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
415 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
416 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 417 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
418 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
419 | }; | |
420 | ||
421 | /* policy for the key default flags */ | |
422 | static const struct nla_policy | |
423 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
424 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
425 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
426 | }; |
427 | ||
ff1b6e69 JB |
428 | /* policy for WoWLAN attributes */ |
429 | static const struct nla_policy | |
430 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
431 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
432 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
433 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
434 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
435 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
436 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
437 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
438 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e | 439 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
8cd4d456 | 440 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
2a0e047e JB |
441 | }; |
442 | ||
443 | static const struct nla_policy | |
444 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
445 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
446 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
447 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
448 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
449 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
450 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
451 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
452 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
453 | }, | |
454 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
455 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
456 | }, | |
457 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
458 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
459 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
460 | }; |
461 | ||
be29b99a AK |
462 | /* policy for coalesce rule attributes */ |
463 | static const struct nla_policy | |
464 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
465 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
466 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
467 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
468 | }; | |
469 | ||
e5497d76 JB |
470 | /* policy for GTK rekey offload attributes */ |
471 | static const struct nla_policy | |
472 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
473 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
474 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
475 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
476 | }; | |
477 | ||
a1f1c21c LC |
478 | static const struct nla_policy |
479 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 480 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 481 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 482 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
483 | }; |
484 | ||
3b06d277 AS |
485 | static const struct nla_policy |
486 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { | |
487 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, | |
488 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, | |
489 | }; | |
490 | ||
38de03d2 AS |
491 | static const struct nla_policy |
492 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { | |
493 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, | |
494 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, | |
495 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { | |
496 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) | |
497 | }, | |
498 | }; | |
499 | ||
97990a06 JB |
500 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
501 | struct netlink_callback *cb, | |
502 | struct cfg80211_registered_device **rdev, | |
503 | struct wireless_dev **wdev) | |
a043897a | 504 | { |
97990a06 | 505 | int err; |
a043897a | 506 | |
97990a06 | 507 | rtnl_lock(); |
a043897a | 508 | |
97990a06 JB |
509 | if (!cb->args[0]) { |
510 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
511 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
512 | nl80211_policy); | |
513 | if (err) | |
514 | goto out_unlock; | |
67748893 | 515 | |
97990a06 JB |
516 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
517 | nl80211_fam.attrbuf); | |
518 | if (IS_ERR(*wdev)) { | |
519 | err = PTR_ERR(*wdev); | |
520 | goto out_unlock; | |
521 | } | |
f26cbf40 | 522 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
523 | /* 0 is the first index - add 1 to parse only once */ |
524 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
525 | cb->args[1] = (*wdev)->identifier; |
526 | } else { | |
c319d50b JB |
527 | /* subtract the 1 again here */ |
528 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 529 | struct wireless_dev *tmp; |
67748893 | 530 | |
97990a06 JB |
531 | if (!wiphy) { |
532 | err = -ENODEV; | |
533 | goto out_unlock; | |
534 | } | |
f26cbf40 | 535 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 536 | *wdev = NULL; |
67748893 | 537 | |
97990a06 JB |
538 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
539 | if (tmp->identifier == cb->args[1]) { | |
540 | *wdev = tmp; | |
541 | break; | |
542 | } | |
543 | } | |
67748893 | 544 | |
97990a06 JB |
545 | if (!*wdev) { |
546 | err = -ENODEV; | |
547 | goto out_unlock; | |
548 | } | |
67748893 JB |
549 | } |
550 | ||
67748893 | 551 | return 0; |
97990a06 | 552 | out_unlock: |
67748893 JB |
553 | rtnl_unlock(); |
554 | return err; | |
555 | } | |
556 | ||
97990a06 | 557 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 558 | { |
67748893 JB |
559 | rtnl_unlock(); |
560 | } | |
561 | ||
f4a11bb0 JB |
562 | /* IE validation */ |
563 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
564 | { | |
565 | const u8 *pos; | |
566 | int len; | |
567 | ||
568 | if (!attr) | |
569 | return true; | |
570 | ||
571 | pos = nla_data(attr); | |
572 | len = nla_len(attr); | |
573 | ||
574 | while (len) { | |
575 | u8 elemlen; | |
576 | ||
577 | if (len < 2) | |
578 | return false; | |
579 | len -= 2; | |
580 | ||
581 | elemlen = pos[1]; | |
582 | if (elemlen > len) | |
583 | return false; | |
584 | ||
585 | len -= elemlen; | |
586 | pos += 2 + elemlen; | |
587 | } | |
588 | ||
589 | return true; | |
590 | } | |
591 | ||
55682965 | 592 | /* message building helper */ |
15e47304 | 593 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
594 | int flags, u8 cmd) |
595 | { | |
596 | /* since there is no private header just add the generic one */ | |
15e47304 | 597 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
598 | } |
599 | ||
5dab3b8a | 600 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
601 | struct ieee80211_channel *chan, |
602 | bool large) | |
5dab3b8a | 603 | { |
ea077c1c RL |
604 | /* Some channels must be completely excluded from the |
605 | * list to protect old user-space tools from breaking | |
606 | */ | |
607 | if (!large && chan->flags & | |
608 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
609 | return 0; | |
610 | ||
9360ffd1 DM |
611 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
612 | chan->center_freq)) | |
613 | goto nla_put_failure; | |
5dab3b8a | 614 | |
9360ffd1 DM |
615 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
616 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
617 | goto nla_put_failure; | |
8fe02e16 LR |
618 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
619 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
620 | goto nla_put_failure; | |
621 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
622 | goto nla_put_failure; | |
623 | } | |
cdc89b97 JB |
624 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
625 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
626 | goto nla_put_failure; | |
627 | if (large) { | |
628 | u32 time; | |
629 | ||
630 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
631 | ||
632 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
633 | chan->dfs_state)) | |
634 | goto nla_put_failure; | |
635 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
636 | time)) | |
637 | goto nla_put_failure; | |
089027e5 JD |
638 | if (nla_put_u32(msg, |
639 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
640 | chan->dfs_cac_ms)) | |
641 | goto nla_put_failure; | |
cdc89b97 JB |
642 | } |
643 | } | |
5dab3b8a | 644 | |
fe1abafd JB |
645 | if (large) { |
646 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
647 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
648 | goto nla_put_failure; | |
649 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
650 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
651 | goto nla_put_failure; | |
652 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
653 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
654 | goto nla_put_failure; | |
655 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
656 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
657 | goto nla_put_failure; | |
570dbde1 DS |
658 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
659 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
660 | goto nla_put_failure; | |
06f207fc AN |
661 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
662 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) | |
570dbde1 | 663 | goto nla_put_failure; |
ea077c1c RL |
664 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
665 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
666 | goto nla_put_failure; | |
667 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
668 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
669 | goto nla_put_failure; | |
fe1abafd JB |
670 | } |
671 | ||
9360ffd1 DM |
672 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
673 | DBM_TO_MBM(chan->max_power))) | |
674 | goto nla_put_failure; | |
5dab3b8a LR |
675 | |
676 | return 0; | |
677 | ||
678 | nla_put_failure: | |
679 | return -ENOBUFS; | |
680 | } | |
681 | ||
55682965 JB |
682 | /* netlink command implementations */ |
683 | ||
b9454e83 JB |
684 | struct key_parse { |
685 | struct key_params p; | |
686 | int idx; | |
e31b8213 | 687 | int type; |
b9454e83 | 688 | bool def, defmgmt; |
dbd2fd65 | 689 | bool def_uni, def_multi; |
b9454e83 JB |
690 | }; |
691 | ||
692 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
693 | { | |
694 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
695 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
696 | nl80211_key_policy); | |
697 | if (err) | |
698 | return err; | |
699 | ||
700 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
701 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
702 | ||
dbd2fd65 JB |
703 | if (k->def) { |
704 | k->def_uni = true; | |
705 | k->def_multi = true; | |
706 | } | |
707 | if (k->defmgmt) | |
708 | k->def_multi = true; | |
709 | ||
b9454e83 JB |
710 | if (tb[NL80211_KEY_IDX]) |
711 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
712 | ||
713 | if (tb[NL80211_KEY_DATA]) { | |
714 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
715 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
716 | } | |
717 | ||
718 | if (tb[NL80211_KEY_SEQ]) { | |
719 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
720 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
721 | } | |
722 | ||
723 | if (tb[NL80211_KEY_CIPHER]) | |
724 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
725 | ||
e31b8213 JB |
726 | if (tb[NL80211_KEY_TYPE]) { |
727 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
728 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
729 | return -EINVAL; | |
730 | } | |
731 | ||
dbd2fd65 JB |
732 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
733 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
734 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
735 | tb[NL80211_KEY_DEFAULT_TYPES], | |
736 | nl80211_key_default_policy); | |
dbd2fd65 JB |
737 | if (err) |
738 | return err; | |
739 | ||
740 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
741 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
742 | } | |
743 | ||
b9454e83 JB |
744 | return 0; |
745 | } | |
746 | ||
747 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
748 | { | |
749 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
750 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
751 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
752 | } | |
753 | ||
754 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
755 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
756 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
757 | } | |
758 | ||
759 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
760 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
761 | ||
762 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
763 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
764 | ||
765 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
766 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
767 | ||
dbd2fd65 JB |
768 | if (k->def) { |
769 | k->def_uni = true; | |
770 | k->def_multi = true; | |
771 | } | |
772 | if (k->defmgmt) | |
773 | k->def_multi = true; | |
774 | ||
e31b8213 JB |
775 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
776 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
777 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
778 | return -EINVAL; | |
779 | } | |
780 | ||
dbd2fd65 JB |
781 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
782 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
783 | int err = nla_parse_nested( | |
784 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
785 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
786 | nl80211_key_default_policy); | |
787 | if (err) | |
788 | return err; | |
789 | ||
790 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
791 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
792 | } | |
793 | ||
b9454e83 JB |
794 | return 0; |
795 | } | |
796 | ||
797 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
798 | { | |
799 | int err; | |
800 | ||
801 | memset(k, 0, sizeof(*k)); | |
802 | k->idx = -1; | |
e31b8213 | 803 | k->type = -1; |
b9454e83 JB |
804 | |
805 | if (info->attrs[NL80211_ATTR_KEY]) | |
806 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
807 | else | |
808 | err = nl80211_parse_key_old(info, k); | |
809 | ||
810 | if (err) | |
811 | return err; | |
812 | ||
813 | if (k->def && k->defmgmt) | |
814 | return -EINVAL; | |
815 | ||
dbd2fd65 JB |
816 | if (k->defmgmt) { |
817 | if (k->def_uni || !k->def_multi) | |
818 | return -EINVAL; | |
819 | } | |
820 | ||
b9454e83 JB |
821 | if (k->idx != -1) { |
822 | if (k->defmgmt) { | |
823 | if (k->idx < 4 || k->idx > 5) | |
824 | return -EINVAL; | |
825 | } else if (k->def) { | |
826 | if (k->idx < 0 || k->idx > 3) | |
827 | return -EINVAL; | |
828 | } else { | |
829 | if (k->idx < 0 || k->idx > 5) | |
830 | return -EINVAL; | |
831 | } | |
832 | } | |
833 | ||
834 | return 0; | |
835 | } | |
836 | ||
fffd0934 JB |
837 | static struct cfg80211_cached_keys * |
838 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 839 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
840 | { |
841 | struct key_parse parse; | |
842 | struct nlattr *key; | |
843 | struct cfg80211_cached_keys *result; | |
844 | int rem, err, def = 0; | |
845 | ||
846 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
847 | if (!result) | |
848 | return ERR_PTR(-ENOMEM); | |
849 | ||
850 | result->def = -1; | |
851 | result->defmgmt = -1; | |
852 | ||
853 | nla_for_each_nested(key, keys, rem) { | |
854 | memset(&parse, 0, sizeof(parse)); | |
855 | parse.idx = -1; | |
856 | ||
857 | err = nl80211_parse_key_new(key, &parse); | |
858 | if (err) | |
859 | goto error; | |
860 | err = -EINVAL; | |
861 | if (!parse.p.key) | |
862 | goto error; | |
863 | if (parse.idx < 0 || parse.idx > 4) | |
864 | goto error; | |
865 | if (parse.def) { | |
866 | if (def) | |
867 | goto error; | |
868 | def = 1; | |
869 | result->def = parse.idx; | |
dbd2fd65 JB |
870 | if (!parse.def_uni || !parse.def_multi) |
871 | goto error; | |
fffd0934 JB |
872 | } else if (parse.defmgmt) |
873 | goto error; | |
874 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 875 | parse.idx, false, NULL); |
fffd0934 JB |
876 | if (err) |
877 | goto error; | |
878 | result->params[parse.idx].cipher = parse.p.cipher; | |
879 | result->params[parse.idx].key_len = parse.p.key_len; | |
880 | result->params[parse.idx].key = result->data[parse.idx]; | |
881 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
882 | |
883 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
884 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
885 | if (no_ht) | |
886 | *no_ht = true; | |
887 | } | |
fffd0934 JB |
888 | } |
889 | ||
890 | return result; | |
891 | error: | |
892 | kfree(result); | |
893 | return ERR_PTR(err); | |
894 | } | |
895 | ||
896 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
897 | { | |
898 | ASSERT_WDEV_LOCK(wdev); | |
899 | ||
fffd0934 JB |
900 | switch (wdev->iftype) { |
901 | case NL80211_IFTYPE_AP: | |
902 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 903 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 904 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
905 | break; |
906 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 907 | case NL80211_IFTYPE_STATION: |
074ac8df | 908 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 909 | if (!wdev->current_bss) |
fffd0934 JB |
910 | return -ENOLINK; |
911 | break; | |
de4fcbad | 912 | case NL80211_IFTYPE_UNSPECIFIED: |
6e0bd6c3 | 913 | case NL80211_IFTYPE_OCB: |
de4fcbad JB |
914 | case NL80211_IFTYPE_MONITOR: |
915 | case NL80211_IFTYPE_P2P_DEVICE: | |
916 | case NL80211_IFTYPE_WDS: | |
917 | case NUM_NL80211_IFTYPES: | |
fffd0934 JB |
918 | return -EINVAL; |
919 | } | |
920 | ||
921 | return 0; | |
922 | } | |
923 | ||
664834de JM |
924 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
925 | struct nlattr *tb) | |
926 | { | |
927 | struct ieee80211_channel *chan; | |
928 | ||
929 | if (tb == NULL) | |
930 | return NULL; | |
931 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
932 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
933 | return NULL; | |
934 | return chan; | |
935 | } | |
936 | ||
7527a782 JB |
937 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
938 | { | |
939 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
940 | int i; | |
941 | ||
942 | if (!nl_modes) | |
943 | goto nla_put_failure; | |
944 | ||
945 | i = 0; | |
946 | while (ifmodes) { | |
9360ffd1 DM |
947 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
948 | goto nla_put_failure; | |
7527a782 JB |
949 | ifmodes >>= 1; |
950 | i++; | |
951 | } | |
952 | ||
953 | nla_nest_end(msg, nl_modes); | |
954 | return 0; | |
955 | ||
956 | nla_put_failure: | |
957 | return -ENOBUFS; | |
958 | } | |
959 | ||
960 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
961 | struct sk_buff *msg, |
962 | bool large) | |
7527a782 JB |
963 | { |
964 | struct nlattr *nl_combis; | |
965 | int i, j; | |
966 | ||
967 | nl_combis = nla_nest_start(msg, | |
968 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
969 | if (!nl_combis) | |
970 | goto nla_put_failure; | |
971 | ||
972 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
973 | const struct ieee80211_iface_combination *c; | |
974 | struct nlattr *nl_combi, *nl_limits; | |
975 | ||
976 | c = &wiphy->iface_combinations[i]; | |
977 | ||
978 | nl_combi = nla_nest_start(msg, i + 1); | |
979 | if (!nl_combi) | |
980 | goto nla_put_failure; | |
981 | ||
982 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
983 | if (!nl_limits) | |
984 | goto nla_put_failure; | |
985 | ||
986 | for (j = 0; j < c->n_limits; j++) { | |
987 | struct nlattr *nl_limit; | |
988 | ||
989 | nl_limit = nla_nest_start(msg, j + 1); | |
990 | if (!nl_limit) | |
991 | goto nla_put_failure; | |
9360ffd1 DM |
992 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
993 | c->limits[j].max)) | |
994 | goto nla_put_failure; | |
7527a782 JB |
995 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
996 | c->limits[j].types)) | |
997 | goto nla_put_failure; | |
998 | nla_nest_end(msg, nl_limit); | |
999 | } | |
1000 | ||
1001 | nla_nest_end(msg, nl_limits); | |
1002 | ||
9360ffd1 DM |
1003 | if (c->beacon_int_infra_match && |
1004 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
1005 | goto nla_put_failure; | |
1006 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
1007 | c->num_different_channels) || | |
1008 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
1009 | c->max_interfaces)) | |
1010 | goto nla_put_failure; | |
cdc89b97 | 1011 | if (large && |
8c48b50a FF |
1012 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
1013 | c->radar_detect_widths) || | |
1014 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
1015 | c->radar_detect_regions))) | |
cdc89b97 | 1016 | goto nla_put_failure; |
7527a782 JB |
1017 | |
1018 | nla_nest_end(msg, nl_combi); | |
1019 | } | |
1020 | ||
1021 | nla_nest_end(msg, nl_combis); | |
1022 | ||
1023 | return 0; | |
1024 | nla_put_failure: | |
1025 | return -ENOBUFS; | |
1026 | } | |
1027 | ||
3713b4e3 | 1028 | #ifdef CONFIG_PM |
b56cf720 JB |
1029 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
1030 | struct sk_buff *msg) | |
1031 | { | |
964dc9e2 | 1032 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
1033 | struct nlattr *nl_tcp; |
1034 | ||
1035 | if (!tcp) | |
1036 | return 0; | |
1037 | ||
1038 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
1039 | if (!nl_tcp) | |
1040 | return -ENOBUFS; | |
1041 | ||
1042 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1043 | tcp->data_payload_max)) | |
1044 | return -ENOBUFS; | |
1045 | ||
1046 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1047 | tcp->data_payload_max)) | |
1048 | return -ENOBUFS; | |
1049 | ||
1050 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1051 | return -ENOBUFS; | |
1052 | ||
1053 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1054 | sizeof(*tcp->tok), tcp->tok)) | |
1055 | return -ENOBUFS; | |
1056 | ||
1057 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1058 | tcp->data_interval_max)) | |
1059 | return -ENOBUFS; | |
1060 | ||
1061 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1062 | tcp->wake_payload_max)) | |
1063 | return -ENOBUFS; | |
1064 | ||
1065 | nla_nest_end(msg, nl_tcp); | |
1066 | return 0; | |
1067 | } | |
1068 | ||
3713b4e3 | 1069 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1070 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1071 | bool large) |
55682965 | 1072 | { |
3713b4e3 | 1073 | struct nlattr *nl_wowlan; |
55682965 | 1074 | |
1b8ec87a | 1075 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1076 | return 0; |
55682965 | 1077 | |
3713b4e3 JB |
1078 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1079 | if (!nl_wowlan) | |
1080 | return -ENOBUFS; | |
9360ffd1 | 1081 | |
1b8ec87a | 1082 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1083 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1084 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1085 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1086 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1087 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1088 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1089 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1090 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1091 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1092 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1093 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1094 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1095 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1096 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1097 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1098 | return -ENOBUFS; | |
9360ffd1 | 1099 | |
1b8ec87a | 1100 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1101 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1102 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1103 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1104 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1105 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1106 | }; |
9360ffd1 | 1107 | |
3713b4e3 JB |
1108 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1109 | sizeof(pat), &pat)) | |
1110 | return -ENOBUFS; | |
1111 | } | |
9360ffd1 | 1112 | |
75453ccb LC |
1113 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
1114 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, | |
1115 | rdev->wiphy.wowlan->max_nd_match_sets)) | |
1116 | return -ENOBUFS; | |
1117 | ||
1b8ec87a | 1118 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1119 | return -ENOBUFS; |
1120 | ||
3713b4e3 | 1121 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1122 | |
3713b4e3 JB |
1123 | return 0; |
1124 | } | |
1125 | #endif | |
9360ffd1 | 1126 | |
be29b99a | 1127 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1128 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1129 | { |
1130 | struct nl80211_coalesce_rule_support rule; | |
1131 | ||
1b8ec87a | 1132 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1133 | return 0; |
1134 | ||
1b8ec87a ZG |
1135 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1136 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1137 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1138 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1139 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1140 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1141 | |
1142 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1143 | return -ENOBUFS; | |
1144 | ||
1145 | return 0; | |
1146 | } | |
1147 | ||
3713b4e3 JB |
1148 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1149 | struct ieee80211_supported_band *sband) | |
1150 | { | |
1151 | struct nlattr *nl_rates, *nl_rate; | |
1152 | struct ieee80211_rate *rate; | |
1153 | int i; | |
87bbbe22 | 1154 | |
3713b4e3 JB |
1155 | /* add HT info */ |
1156 | if (sband->ht_cap.ht_supported && | |
1157 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1158 | sizeof(sband->ht_cap.mcs), | |
1159 | &sband->ht_cap.mcs) || | |
1160 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1161 | sband->ht_cap.cap) || | |
1162 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1163 | sband->ht_cap.ampdu_factor) || | |
1164 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1165 | sband->ht_cap.ampdu_density))) | |
1166 | return -ENOBUFS; | |
afe0cbf8 | 1167 | |
3713b4e3 JB |
1168 | /* add VHT info */ |
1169 | if (sband->vht_cap.vht_supported && | |
1170 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1171 | sizeof(sband->vht_cap.vht_mcs), | |
1172 | &sband->vht_cap.vht_mcs) || | |
1173 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1174 | sband->vht_cap.cap))) | |
1175 | return -ENOBUFS; | |
f59ac048 | 1176 | |
3713b4e3 JB |
1177 | /* add bitrates */ |
1178 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1179 | if (!nl_rates) | |
1180 | return -ENOBUFS; | |
ee688b00 | 1181 | |
3713b4e3 JB |
1182 | for (i = 0; i < sband->n_bitrates; i++) { |
1183 | nl_rate = nla_nest_start(msg, i); | |
1184 | if (!nl_rate) | |
1185 | return -ENOBUFS; | |
ee688b00 | 1186 | |
3713b4e3 JB |
1187 | rate = &sband->bitrates[i]; |
1188 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1189 | rate->bitrate)) | |
1190 | return -ENOBUFS; | |
1191 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1192 | nla_put_flag(msg, | |
1193 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1194 | return -ENOBUFS; | |
ee688b00 | 1195 | |
3713b4e3 JB |
1196 | nla_nest_end(msg, nl_rate); |
1197 | } | |
d51626df | 1198 | |
3713b4e3 | 1199 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1200 | |
3713b4e3 JB |
1201 | return 0; |
1202 | } | |
ee688b00 | 1203 | |
3713b4e3 JB |
1204 | static int |
1205 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1206 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1207 | { | |
1208 | u16 stypes; | |
1209 | struct nlattr *nl_ftypes, *nl_ifs; | |
1210 | enum nl80211_iftype ift; | |
1211 | int i; | |
ee688b00 | 1212 | |
3713b4e3 JB |
1213 | if (!mgmt_stypes) |
1214 | return 0; | |
5dab3b8a | 1215 | |
3713b4e3 JB |
1216 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1217 | if (!nl_ifs) | |
1218 | return -ENOBUFS; | |
e2f367f2 | 1219 | |
3713b4e3 JB |
1220 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1221 | nl_ftypes = nla_nest_start(msg, ift); | |
1222 | if (!nl_ftypes) | |
1223 | return -ENOBUFS; | |
1224 | i = 0; | |
1225 | stypes = mgmt_stypes[ift].tx; | |
1226 | while (stypes) { | |
1227 | if ((stypes & 1) && | |
1228 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1229 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1230 | return -ENOBUFS; | |
1231 | stypes >>= 1; | |
1232 | i++; | |
ee688b00 | 1233 | } |
3713b4e3 JB |
1234 | nla_nest_end(msg, nl_ftypes); |
1235 | } | |
ee688b00 | 1236 | |
3713b4e3 | 1237 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1238 | |
3713b4e3 JB |
1239 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1240 | if (!nl_ifs) | |
1241 | return -ENOBUFS; | |
ee688b00 | 1242 | |
3713b4e3 JB |
1243 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1244 | nl_ftypes = nla_nest_start(msg, ift); | |
1245 | if (!nl_ftypes) | |
1246 | return -ENOBUFS; | |
1247 | i = 0; | |
1248 | stypes = mgmt_stypes[ift].rx; | |
1249 | while (stypes) { | |
1250 | if ((stypes & 1) && | |
1251 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1252 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1253 | return -ENOBUFS; | |
1254 | stypes >>= 1; | |
1255 | i++; | |
1256 | } | |
1257 | nla_nest_end(msg, nl_ftypes); | |
1258 | } | |
1259 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1260 | |
3713b4e3 JB |
1261 | return 0; |
1262 | } | |
ee688b00 | 1263 | |
86e8cf98 JB |
1264 | struct nl80211_dump_wiphy_state { |
1265 | s64 filter_wiphy; | |
1266 | long start; | |
1267 | long split_start, band_start, chan_start; | |
1268 | bool split; | |
1269 | }; | |
1270 | ||
1b8ec87a | 1271 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 1272 | enum nl80211_commands cmd, |
3713b4e3 | 1273 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1274 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1275 | { |
1276 | void *hdr; | |
1277 | struct nlattr *nl_bands, *nl_band; | |
1278 | struct nlattr *nl_freqs, *nl_freq; | |
1279 | struct nlattr *nl_cmds; | |
1280 | enum ieee80211_band band; | |
1281 | struct ieee80211_channel *chan; | |
1282 | int i; | |
1283 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1284 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1285 | u32 features; |
ee688b00 | 1286 | |
3bb20556 | 1287 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
1288 | if (!hdr) |
1289 | return -ENOBUFS; | |
ee688b00 | 1290 | |
86e8cf98 JB |
1291 | if (WARN_ON(!state)) |
1292 | return -EINVAL; | |
ee688b00 | 1293 | |
1b8ec87a | 1294 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1295 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1296 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1297 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1298 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1299 | goto nla_put_failure; |
1300 | ||
3bb20556 JB |
1301 | if (cmd != NL80211_CMD_NEW_WIPHY) |
1302 | goto finish; | |
1303 | ||
86e8cf98 | 1304 | switch (state->split_start) { |
3713b4e3 JB |
1305 | case 0: |
1306 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1307 | rdev->wiphy.retry_short) || |
3713b4e3 | 1308 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1309 | rdev->wiphy.retry_long) || |
3713b4e3 | 1310 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1311 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1312 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1313 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1314 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1315 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1316 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1317 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1318 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1319 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1320 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1321 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1322 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1323 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1324 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
3b06d277 AS |
1325 | rdev->wiphy.max_match_sets) || |
1326 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, | |
1327 | rdev->wiphy.max_sched_scan_plans) || | |
1328 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, | |
1329 | rdev->wiphy.max_sched_scan_plan_interval) || | |
1330 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, | |
1331 | rdev->wiphy.max_sched_scan_plan_iterations)) | |
9360ffd1 | 1332 | goto nla_put_failure; |
3713b4e3 | 1333 | |
1b8ec87a | 1334 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1335 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1336 | goto nla_put_failure; |
1b8ec87a | 1337 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1338 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1339 | goto nla_put_failure; | |
1b8ec87a | 1340 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1341 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1342 | goto nla_put_failure; | |
1b8ec87a | 1343 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1344 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1345 | goto nla_put_failure; | |
1b8ec87a | 1346 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1347 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1348 | goto nla_put_failure; | |
1b8ec87a | 1349 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1350 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1351 | goto nla_put_failure; |
86e8cf98 JB |
1352 | state->split_start++; |
1353 | if (state->split) | |
3713b4e3 JB |
1354 | break; |
1355 | case 1: | |
1356 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1357 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1358 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1359 | goto nla_put_failure; |
4745fc09 | 1360 | |
3713b4e3 | 1361 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1362 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1363 | goto nla_put_failure; |
b23aa676 | 1364 | |
1b8ec87a | 1365 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1366 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1367 | goto nla_put_failure; |
b23aa676 | 1368 | |
3713b4e3 | 1369 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1370 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1371 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1372 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1373 | goto nla_put_failure; |
b23aa676 | 1374 | |
1b8ec87a | 1375 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1376 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1377 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1378 | goto nla_put_failure; |
8fdc621d | 1379 | |
1b8ec87a ZG |
1380 | if ((rdev->wiphy.available_antennas_tx || |
1381 | rdev->wiphy.available_antennas_rx) && | |
1382 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1383 | u32 tx_ant = 0, rx_ant = 0; |
1384 | int res; | |
1b8ec87a | 1385 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1386 | if (!res) { |
1387 | if (nla_put_u32(msg, | |
1388 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1389 | tx_ant) || | |
1390 | nla_put_u32(msg, | |
1391 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1392 | rx_ant)) | |
1393 | goto nla_put_failure; | |
1394 | } | |
1395 | } | |
a293911d | 1396 | |
86e8cf98 JB |
1397 | state->split_start++; |
1398 | if (state->split) | |
3713b4e3 JB |
1399 | break; |
1400 | case 2: | |
1401 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1402 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1403 | goto nla_put_failure; |
86e8cf98 JB |
1404 | state->split_start++; |
1405 | if (state->split) | |
3713b4e3 JB |
1406 | break; |
1407 | case 3: | |
1408 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1409 | if (!nl_bands) | |
1410 | goto nla_put_failure; | |
f7ca38df | 1411 | |
86e8cf98 JB |
1412 | for (band = state->band_start; |
1413 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1414 | struct ieee80211_supported_band *sband; |
2e161f78 | 1415 | |
1b8ec87a | 1416 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1417 | |
3713b4e3 JB |
1418 | if (!sband) |
1419 | continue; | |
1420 | ||
1421 | nl_band = nla_nest_start(msg, band); | |
1422 | if (!nl_band) | |
2e161f78 | 1423 | goto nla_put_failure; |
3713b4e3 | 1424 | |
86e8cf98 | 1425 | switch (state->chan_start) { |
3713b4e3 JB |
1426 | case 0: |
1427 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1428 | goto nla_put_failure; |
86e8cf98 JB |
1429 | state->chan_start++; |
1430 | if (state->split) | |
3713b4e3 JB |
1431 | break; |
1432 | default: | |
1433 | /* add frequencies */ | |
1434 | nl_freqs = nla_nest_start( | |
1435 | msg, NL80211_BAND_ATTR_FREQS); | |
1436 | if (!nl_freqs) | |
1437 | goto nla_put_failure; | |
1438 | ||
86e8cf98 | 1439 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1440 | i < sband->n_channels; |
1441 | i++) { | |
1442 | nl_freq = nla_nest_start(msg, i); | |
1443 | if (!nl_freq) | |
1444 | goto nla_put_failure; | |
1445 | ||
1446 | chan = &sband->channels[i]; | |
1447 | ||
86e8cf98 JB |
1448 | if (nl80211_msg_put_channel( |
1449 | msg, chan, | |
1450 | state->split)) | |
3713b4e3 JB |
1451 | goto nla_put_failure; |
1452 | ||
1453 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1454 | if (state->split) |
3713b4e3 JB |
1455 | break; |
1456 | } | |
1457 | if (i < sband->n_channels) | |
86e8cf98 | 1458 | state->chan_start = i + 2; |
3713b4e3 | 1459 | else |
86e8cf98 | 1460 | state->chan_start = 0; |
3713b4e3 JB |
1461 | nla_nest_end(msg, nl_freqs); |
1462 | } | |
1463 | ||
1464 | nla_nest_end(msg, nl_band); | |
1465 | ||
86e8cf98 | 1466 | if (state->split) { |
3713b4e3 | 1467 | /* start again here */ |
86e8cf98 | 1468 | if (state->chan_start) |
3713b4e3 JB |
1469 | band--; |
1470 | break; | |
2e161f78 | 1471 | } |
2e161f78 | 1472 | } |
3713b4e3 | 1473 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1474 | |
3713b4e3 | 1475 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1476 | state->band_start = band + 1; |
3713b4e3 | 1477 | else |
86e8cf98 | 1478 | state->band_start = 0; |
74b70a4e | 1479 | |
3713b4e3 | 1480 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1481 | if (state->band_start == 0 && state->chan_start == 0) |
1482 | state->split_start++; | |
1483 | if (state->split) | |
3713b4e3 JB |
1484 | break; |
1485 | case 4: | |
1486 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1487 | if (!nl_cmds) | |
2e161f78 JB |
1488 | goto nla_put_failure; |
1489 | ||
3713b4e3 JB |
1490 | i = 0; |
1491 | #define CMD(op, n) \ | |
1492 | do { \ | |
1b8ec87a | 1493 | if (rdev->ops->op) { \ |
3713b4e3 JB |
1494 | i++; \ |
1495 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1496 | goto nla_put_failure; \ | |
1497 | } \ | |
1498 | } while (0) | |
1499 | ||
1500 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1501 | CMD(change_virtual_intf, SET_INTERFACE); | |
1502 | CMD(add_key, NEW_KEY); | |
1503 | CMD(start_ap, START_AP); | |
1504 | CMD(add_station, NEW_STATION); | |
1505 | CMD(add_mpath, NEW_MPATH); | |
1506 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1507 | CMD(change_bss, SET_BSS); | |
1508 | CMD(auth, AUTHENTICATE); | |
1509 | CMD(assoc, ASSOCIATE); | |
1510 | CMD(deauth, DEAUTHENTICATE); | |
1511 | CMD(disassoc, DISASSOCIATE); | |
1512 | CMD(join_ibss, JOIN_IBSS); | |
1513 | CMD(join_mesh, JOIN_MESH); | |
1514 | CMD(set_pmksa, SET_PMKSA); | |
1515 | CMD(del_pmksa, DEL_PMKSA); | |
1516 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1b8ec87a | 1517 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
3713b4e3 JB |
1518 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
1519 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1520 | CMD(mgmt_tx, FRAME); | |
1521 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1b8ec87a | 1522 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
3713b4e3 JB |
1523 | i++; |
1524 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1525 | goto nla_put_failure; |
2e161f78 | 1526 | } |
1b8ec87a ZG |
1527 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
1528 | rdev->ops->join_mesh) { | |
3713b4e3 JB |
1529 | i++; |
1530 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1531 | goto nla_put_failure; | |
1532 | } | |
1533 | CMD(set_wds_peer, SET_WDS_PEER); | |
1b8ec87a | 1534 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
3713b4e3 JB |
1535 | CMD(tdls_mgmt, TDLS_MGMT); |
1536 | CMD(tdls_oper, TDLS_OPER); | |
1537 | } | |
1b8ec87a | 1538 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
3713b4e3 JB |
1539 | CMD(sched_scan_start, START_SCHED_SCAN); |
1540 | CMD(probe_client, PROBE_CLIENT); | |
1541 | CMD(set_noack_map, SET_NOACK_MAP); | |
1b8ec87a | 1542 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
3713b4e3 JB |
1543 | i++; |
1544 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1545 | goto nla_put_failure; | |
1546 | } | |
1547 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1548 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
02df00eb JB |
1549 | #ifdef CONFIG_NL80211_TESTMODE |
1550 | CMD(testmode_cmd, TESTMODE); | |
1551 | #endif | |
86e8cf98 | 1552 | if (state->split) { |
5de17984 AS |
1553 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1554 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 1555 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 1556 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 1557 | CMD(set_qos_map, SET_QOS_MAP); |
723e73ac JB |
1558 | if (rdev->wiphy.features & |
1559 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | |
960d01ac | 1560 | CMD(add_tx_ts, ADD_TX_TS); |
5de17984 | 1561 | } |
02df00eb | 1562 | /* add into the if now */ |
3713b4e3 | 1563 | #undef CMD |
ff1b6e69 | 1564 | |
1b8ec87a | 1565 | if (rdev->ops->connect || rdev->ops->auth) { |
3713b4e3 JB |
1566 | i++; |
1567 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1568 | goto nla_put_failure; |
ff1b6e69 JB |
1569 | } |
1570 | ||
1b8ec87a | 1571 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
3713b4e3 JB |
1572 | i++; |
1573 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1574 | goto nla_put_failure; | |
1575 | } | |
1576 | ||
1577 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1578 | state->split_start++; |
1579 | if (state->split) | |
3713b4e3 JB |
1580 | break; |
1581 | case 5: | |
1b8ec87a ZG |
1582 | if (rdev->ops->remain_on_channel && |
1583 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
1584 | nla_put_u32(msg, |
1585 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 1586 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
1587 | goto nla_put_failure; |
1588 | ||
1b8ec87a | 1589 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
1590 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
1591 | goto nla_put_failure; | |
1592 | ||
1593 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1594 | goto nla_put_failure; | |
86e8cf98 JB |
1595 | state->split_start++; |
1596 | if (state->split) | |
3713b4e3 JB |
1597 | break; |
1598 | case 6: | |
1599 | #ifdef CONFIG_PM | |
1b8ec87a | 1600 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 1601 | goto nla_put_failure; |
86e8cf98 JB |
1602 | state->split_start++; |
1603 | if (state->split) | |
3713b4e3 JB |
1604 | break; |
1605 | #else | |
86e8cf98 | 1606 | state->split_start++; |
dfb89c56 | 1607 | #endif |
3713b4e3 JB |
1608 | case 7: |
1609 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 1610 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 1611 | goto nla_put_failure; |
ff1b6e69 | 1612 | |
1b8ec87a | 1613 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 1614 | state->split)) |
3713b4e3 | 1615 | goto nla_put_failure; |
7527a782 | 1616 | |
86e8cf98 JB |
1617 | state->split_start++; |
1618 | if (state->split) | |
3713b4e3 JB |
1619 | break; |
1620 | case 8: | |
1b8ec87a | 1621 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 1622 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 1623 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 1624 | goto nla_put_failure; |
7527a782 | 1625 | |
1b8ec87a | 1626 | features = rdev->wiphy.features; |
fe1abafd JB |
1627 | /* |
1628 | * We can only add the per-channel limit information if the | |
1629 | * dump is split, otherwise it makes it too big. Therefore | |
1630 | * only advertise it in that case. | |
1631 | */ | |
86e8cf98 | 1632 | if (state->split) |
fe1abafd JB |
1633 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1634 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1635 | goto nla_put_failure; |
562a7480 | 1636 | |
1b8ec87a | 1637 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 1638 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
1639 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
1640 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 1641 | goto nla_put_failure; |
1f074bd8 | 1642 | |
1b8ec87a ZG |
1643 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1644 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 1645 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 1646 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 1647 | goto nla_put_failure; |
7e7c8926 | 1648 | |
3713b4e3 JB |
1649 | /* |
1650 | * Any information below this point is only available to | |
1651 | * applications that can deal with it being split. This | |
1652 | * helps ensure that newly added capabilities don't break | |
1653 | * older tools by overrunning their buffers. | |
1654 | * | |
1655 | * We still increment split_start so that in the split | |
1656 | * case we'll continue with more data in the next round, | |
1657 | * but break unconditionally so unsplit data stops here. | |
1658 | */ | |
86e8cf98 | 1659 | state->split_start++; |
3713b4e3 JB |
1660 | break; |
1661 | case 9: | |
1b8ec87a | 1662 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 1663 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
1664 | rdev->wiphy.extended_capabilities_len, |
1665 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 1666 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
1667 | rdev->wiphy.extended_capabilities_len, |
1668 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 1669 | goto nla_put_failure; |
a50df0c4 | 1670 | |
1b8ec87a | 1671 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 1672 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
1673 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
1674 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
1675 | goto nla_put_failure; |
1676 | ||
be29b99a AK |
1677 | state->split_start++; |
1678 | break; | |
1679 | case 10: | |
1b8ec87a | 1680 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
1681 | goto nla_put_failure; |
1682 | ||
1b8ec87a | 1683 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
1684 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
1685 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1686 | goto nla_put_failure; | |
b43504cf | 1687 | |
1b8ec87a | 1688 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 1689 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 1690 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
1691 | goto nla_put_failure; |
1692 | ||
ad7e718c JB |
1693 | state->split_start++; |
1694 | break; | |
1695 | case 11: | |
1b8ec87a | 1696 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
1697 | const struct nl80211_vendor_cmd_info *info; |
1698 | struct nlattr *nested; | |
1699 | ||
1700 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1701 | if (!nested) | |
1702 | goto nla_put_failure; | |
1703 | ||
1b8ec87a ZG |
1704 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
1705 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
1706 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1707 | goto nla_put_failure; | |
1708 | } | |
1709 | nla_nest_end(msg, nested); | |
1710 | } | |
1711 | ||
1b8ec87a | 1712 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
1713 | const struct nl80211_vendor_cmd_info *info; |
1714 | struct nlattr *nested; | |
ad7e718c | 1715 | |
567ffc35 JB |
1716 | nested = nla_nest_start(msg, |
1717 | NL80211_ATTR_VENDOR_EVENTS); | |
1718 | if (!nested) | |
ad7e718c | 1719 | goto nla_put_failure; |
567ffc35 | 1720 | |
1b8ec87a ZG |
1721 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
1722 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
1723 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1724 | goto nla_put_failure; | |
1725 | } | |
1726 | nla_nest_end(msg, nested); | |
1727 | } | |
9a774c78 AO |
1728 | state->split_start++; |
1729 | break; | |
1730 | case 12: | |
1731 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
1732 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
1733 | rdev->wiphy.max_num_csa_counters)) | |
1734 | goto nla_put_failure; | |
01e0daa4 | 1735 | |
1bdd716c AN |
1736 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
1737 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
1738 | goto nla_put_failure; | |
1739 | ||
d75bb06b GKS |
1740 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
1741 | sizeof(rdev->wiphy.ext_features), | |
1742 | rdev->wiphy.ext_features)) | |
1743 | goto nla_put_failure; | |
1744 | ||
38de03d2 AS |
1745 | if (rdev->wiphy.bss_select_support) { |
1746 | struct nlattr *nested; | |
1747 | u32 bss_select_support = rdev->wiphy.bss_select_support; | |
1748 | ||
1749 | nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); | |
1750 | if (!nested) | |
1751 | goto nla_put_failure; | |
1752 | ||
1753 | i = 0; | |
1754 | while (bss_select_support) { | |
1755 | if ((bss_select_support & 1) && | |
1756 | nla_put_flag(msg, i)) | |
1757 | goto nla_put_failure; | |
1758 | i++; | |
1759 | bss_select_support >>= 1; | |
1760 | } | |
1761 | nla_nest_end(msg, nested); | |
1762 | } | |
1763 | ||
3713b4e3 | 1764 | /* done */ |
86e8cf98 | 1765 | state->split_start = 0; |
3713b4e3 JB |
1766 | break; |
1767 | } | |
3bb20556 | 1768 | finish: |
053c095a JB |
1769 | genlmsg_end(msg, hdr); |
1770 | return 0; | |
55682965 JB |
1771 | |
1772 | nla_put_failure: | |
bc3ed28c TG |
1773 | genlmsg_cancel(msg, hdr); |
1774 | return -EMSGSIZE; | |
55682965 JB |
1775 | } |
1776 | ||
86e8cf98 JB |
1777 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1778 | struct netlink_callback *cb, | |
1779 | struct nl80211_dump_wiphy_state *state) | |
1780 | { | |
1781 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1782 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1783 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1784 | /* ignore parse errors for backward compatibility */ | |
1785 | if (ret) | |
1786 | return 0; | |
1787 | ||
1788 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1789 | if (tb[NL80211_ATTR_WIPHY]) | |
1790 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1791 | if (tb[NL80211_ATTR_WDEV]) | |
1792 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1793 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1794 | struct net_device *netdev; | |
1795 | struct cfg80211_registered_device *rdev; | |
1796 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1797 | ||
7f2b8562 | 1798 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1799 | if (!netdev) |
1800 | return -ENODEV; | |
1801 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1802 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1803 | netdev->ieee80211_ptr->wiphy); |
1804 | state->filter_wiphy = rdev->wiphy_idx; | |
1805 | } | |
86e8cf98 JB |
1806 | } |
1807 | ||
1808 | return 0; | |
1809 | } | |
1810 | ||
55682965 JB |
1811 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1812 | { | |
645e77de | 1813 | int idx = 0, ret; |
86e8cf98 | 1814 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1815 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1816 | |
5fe231e8 | 1817 | rtnl_lock(); |
86e8cf98 JB |
1818 | if (!state) { |
1819 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1820 | if (!state) { |
1821 | rtnl_unlock(); | |
86e8cf98 | 1822 | return -ENOMEM; |
3713b4e3 | 1823 | } |
86e8cf98 JB |
1824 | state->filter_wiphy = -1; |
1825 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1826 | if (ret) { | |
1827 | kfree(state); | |
1828 | rtnl_unlock(); | |
1829 | return ret; | |
3713b4e3 | 1830 | } |
86e8cf98 | 1831 | cb->args[0] = (long)state; |
3713b4e3 JB |
1832 | } |
1833 | ||
1b8ec87a ZG |
1834 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1835 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1836 | continue; |
86e8cf98 | 1837 | if (++idx <= state->start) |
55682965 | 1838 | continue; |
86e8cf98 | 1839 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1840 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1841 | continue; |
1842 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1843 | do { | |
3bb20556 JB |
1844 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
1845 | skb, | |
3713b4e3 JB |
1846 | NETLINK_CB(cb->skb).portid, |
1847 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1848 | NLM_F_MULTI, state); |
3713b4e3 JB |
1849 | if (ret < 0) { |
1850 | /* | |
1851 | * If sending the wiphy data didn't fit (ENOBUFS | |
1852 | * or EMSGSIZE returned), this SKB is still | |
1853 | * empty (so it's not too big because another | |
1854 | * wiphy dataset is already in the skb) and | |
1855 | * we've not tried to adjust the dump allocation | |
1856 | * yet ... then adjust the alloc size to be | |
1857 | * bigger, and return 1 but with the empty skb. | |
1858 | * This results in an empty message being RX'ed | |
1859 | * in userspace, but that is ignored. | |
1860 | * | |
1861 | * We can then retry with the larger buffer. | |
1862 | */ | |
1863 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1864 | !skb->len && !state->split && |
3713b4e3 JB |
1865 | cb->min_dump_alloc < 4096) { |
1866 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1867 | state->split_start = 0; |
d98cae64 | 1868 | rtnl_unlock(); |
3713b4e3 JB |
1869 | return 1; |
1870 | } | |
1871 | idx--; | |
1872 | break; | |
645e77de | 1873 | } |
86e8cf98 | 1874 | } while (state->split_start > 0); |
3713b4e3 | 1875 | break; |
55682965 | 1876 | } |
5fe231e8 | 1877 | rtnl_unlock(); |
55682965 | 1878 | |
86e8cf98 | 1879 | state->start = idx; |
55682965 JB |
1880 | |
1881 | return skb->len; | |
1882 | } | |
1883 | ||
86e8cf98 JB |
1884 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1885 | { | |
1886 | kfree((void *)cb->args[0]); | |
1887 | return 0; | |
1888 | } | |
1889 | ||
55682965 JB |
1890 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1891 | { | |
1892 | struct sk_buff *msg; | |
1b8ec87a | 1893 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 1894 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1895 | |
645e77de | 1896 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1897 | if (!msg) |
4c476991 | 1898 | return -ENOMEM; |
55682965 | 1899 | |
3bb20556 JB |
1900 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
1901 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 1902 | &state) < 0) { |
4c476991 JB |
1903 | nlmsg_free(msg); |
1904 | return -ENOBUFS; | |
1905 | } | |
55682965 | 1906 | |
134e6375 | 1907 | return genlmsg_reply(msg, info); |
55682965 JB |
1908 | } |
1909 | ||
31888487 JM |
1910 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1911 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1912 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1913 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1914 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1915 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1916 | }; | |
1917 | ||
1918 | static int parse_txq_params(struct nlattr *tb[], | |
1919 | struct ieee80211_txq_params *txq_params) | |
1920 | { | |
a3304b0a | 1921 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1922 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1923 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1924 | return -EINVAL; | |
1925 | ||
a3304b0a | 1926 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1927 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1928 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1929 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1930 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1931 | ||
a3304b0a JB |
1932 | if (txq_params->ac >= NL80211_NUM_ACS) |
1933 | return -EINVAL; | |
1934 | ||
31888487 JM |
1935 | return 0; |
1936 | } | |
1937 | ||
f444de05 JB |
1938 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1939 | { | |
1940 | /* | |
cc1d2806 JB |
1941 | * You can only set the channel explicitly for WDS interfaces, |
1942 | * all others have their channel managed via their respective | |
1943 | * "establish a connection" command (connect, join, ...) | |
1944 | * | |
1945 | * For AP/GO and mesh mode, the channel can be set with the | |
1946 | * channel userspace API, but is only stored and passed to the | |
1947 | * low-level driver when the AP starts or the mesh is joined. | |
1948 | * This is for backward compatibility, userspace can also give | |
1949 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1950 | * |
1951 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1952 | * whatever else is going on, so they have their own special |
1953 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1954 | */ |
1955 | return !wdev || | |
1956 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1957 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1958 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1959 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1960 | } |
1961 | ||
683b6d3b JB |
1962 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1963 | struct genl_info *info, | |
1964 | struct cfg80211_chan_def *chandef) | |
1965 | { | |
dbeca2ea | 1966 | u32 control_freq; |
683b6d3b JB |
1967 | |
1968 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1969 | return -EINVAL; | |
1970 | ||
1971 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1972 | ||
1973 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1974 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1975 | chandef->center_freq1 = control_freq; | |
1976 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1977 | |
1978 | /* Primary channel not allowed */ | |
1979 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1980 | return -EINVAL; | |
1981 | ||
3d9d1d66 JB |
1982 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1983 | enum nl80211_channel_type chantype; | |
1984 | ||
1985 | chantype = nla_get_u32( | |
1986 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1987 | ||
1988 | switch (chantype) { | |
1989 | case NL80211_CHAN_NO_HT: | |
1990 | case NL80211_CHAN_HT20: | |
1991 | case NL80211_CHAN_HT40PLUS: | |
1992 | case NL80211_CHAN_HT40MINUS: | |
1993 | cfg80211_chandef_create(chandef, chandef->chan, | |
1994 | chantype); | |
1995 | break; | |
1996 | default: | |
1997 | return -EINVAL; | |
1998 | } | |
1999 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
2000 | chandef->width = | |
2001 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
2002 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
2003 | chandef->center_freq1 = | |
2004 | nla_get_u32( | |
2005 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
2006 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
2007 | chandef->center_freq2 = | |
2008 | nla_get_u32( | |
2009 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
2010 | } | |
2011 | ||
9f5e8f6e | 2012 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
2013 | return -EINVAL; |
2014 | ||
9f5e8f6e JB |
2015 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
2016 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
2017 | return -EINVAL; |
2018 | ||
2f301ab2 SW |
2019 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
2020 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
2021 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
2022 | return -EINVAL; | |
2023 | ||
683b6d3b JB |
2024 | return 0; |
2025 | } | |
2026 | ||
f444de05 | 2027 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 2028 | struct net_device *dev, |
f444de05 JB |
2029 | struct genl_info *info) |
2030 | { | |
683b6d3b | 2031 | struct cfg80211_chan_def chandef; |
f444de05 | 2032 | int result; |
e8c9bd5b | 2033 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 2034 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 2035 | |
e16821bc JM |
2036 | if (dev) |
2037 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
2038 | if (!nl80211_can_set_dev_channel(wdev)) |
2039 | return -EOPNOTSUPP; | |
e16821bc JM |
2040 | if (wdev) |
2041 | iftype = wdev->iftype; | |
f444de05 | 2042 | |
683b6d3b JB |
2043 | result = nl80211_parse_chandef(rdev, info, &chandef); |
2044 | if (result) | |
2045 | return result; | |
f444de05 | 2046 | |
e8c9bd5b | 2047 | switch (iftype) { |
aa430da4 JB |
2048 | case NL80211_IFTYPE_AP: |
2049 | case NL80211_IFTYPE_P2P_GO: | |
923b352f AN |
2050 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
2051 | iftype)) { | |
aa430da4 JB |
2052 | result = -EINVAL; |
2053 | break; | |
2054 | } | |
e16821bc JM |
2055 | if (wdev->beacon_interval) { |
2056 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
2057 | !(rdev->wiphy.features & | |
2058 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
2059 | result = -EBUSY; | |
2060 | break; | |
2061 | } | |
2062 | ||
2063 | /* Only allow dynamic channel width changes */ | |
2064 | if (chandef.chan != wdev->preset_chandef.chan) { | |
2065 | result = -EBUSY; | |
2066 | break; | |
2067 | } | |
2068 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
2069 | if (result) | |
2070 | break; | |
2071 | } | |
683b6d3b | 2072 | wdev->preset_chandef = chandef; |
aa430da4 JB |
2073 | result = 0; |
2074 | break; | |
cc1d2806 | 2075 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 2076 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 2077 | break; |
e8c9bd5b | 2078 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 2079 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 2080 | break; |
aa430da4 | 2081 | default: |
e8c9bd5b | 2082 | result = -EINVAL; |
f444de05 | 2083 | } |
f444de05 JB |
2084 | |
2085 | return result; | |
2086 | } | |
2087 | ||
2088 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2089 | { | |
4c476991 JB |
2090 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2091 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2092 | |
e16821bc | 2093 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2094 | } |
2095 | ||
e8347eba BJ |
2096 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2097 | { | |
43b19952 JB |
2098 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2099 | struct net_device *dev = info->user_ptr[1]; | |
2100 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2101 | const u8 *bssid; |
e8347eba BJ |
2102 | |
2103 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2104 | return -EINVAL; | |
2105 | ||
43b19952 JB |
2106 | if (netif_running(dev)) |
2107 | return -EBUSY; | |
e8347eba | 2108 | |
43b19952 JB |
2109 | if (!rdev->ops->set_wds_peer) |
2110 | return -EOPNOTSUPP; | |
e8347eba | 2111 | |
43b19952 JB |
2112 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2113 | return -EOPNOTSUPP; | |
e8347eba BJ |
2114 | |
2115 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2116 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2117 | } |
2118 | ||
2119 | ||
55682965 JB |
2120 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2121 | { | |
2122 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2123 | struct net_device *netdev = NULL; |
2124 | struct wireless_dev *wdev; | |
a1e567c8 | 2125 | int result = 0, rem_txq_params = 0; |
31888487 | 2126 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2127 | u32 changed; |
2128 | u8 retry_short = 0, retry_long = 0; | |
2129 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2130 | u8 coverage_class = 0; |
55682965 | 2131 | |
5fe231e8 JB |
2132 | ASSERT_RTNL(); |
2133 | ||
f444de05 JB |
2134 | /* |
2135 | * Try to find the wiphy and netdev. Normally this | |
2136 | * function shouldn't need the netdev, but this is | |
2137 | * done for backward compatibility -- previously | |
2138 | * setting the channel was done per wiphy, but now | |
2139 | * it is per netdev. Previous userland like hostapd | |
2140 | * also passed a netdev to set_wiphy, so that it is | |
2141 | * possible to let that go to the right netdev! | |
2142 | */ | |
4bbf4d56 | 2143 | |
f444de05 JB |
2144 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2145 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2146 | ||
7f2b8562 | 2147 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2148 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2149 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2150 | else |
f444de05 | 2151 | netdev = NULL; |
4bbf4d56 JB |
2152 | } |
2153 | ||
f444de05 | 2154 | if (!netdev) { |
878d9ec7 JB |
2155 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2156 | info->attrs); | |
5fe231e8 | 2157 | if (IS_ERR(rdev)) |
4c476991 | 2158 | return PTR_ERR(rdev); |
f444de05 JB |
2159 | wdev = NULL; |
2160 | netdev = NULL; | |
2161 | result = 0; | |
71fe96bf | 2162 | } else |
f444de05 | 2163 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2164 | |
2165 | /* | |
2166 | * end workaround code, by now the rdev is available | |
2167 | * and locked, and wdev may or may not be NULL. | |
2168 | */ | |
4bbf4d56 JB |
2169 | |
2170 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2171 | result = cfg80211_dev_rename( |
2172 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2173 | |
4bbf4d56 | 2174 | if (result) |
7f2b8562 | 2175 | return result; |
31888487 JM |
2176 | |
2177 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2178 | struct ieee80211_txq_params txq_params; | |
2179 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2180 | ||
7f2b8562 YX |
2181 | if (!rdev->ops->set_txq_params) |
2182 | return -EOPNOTSUPP; | |
31888487 | 2183 | |
7f2b8562 YX |
2184 | if (!netdev) |
2185 | return -EINVAL; | |
f70f01c2 | 2186 | |
133a3ff2 | 2187 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2188 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2189 | return -EINVAL; | |
133a3ff2 | 2190 | |
7f2b8562 YX |
2191 | if (!netif_running(netdev)) |
2192 | return -ENETDOWN; | |
2b5f8b0b | 2193 | |
31888487 JM |
2194 | nla_for_each_nested(nl_txq_params, |
2195 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2196 | rem_txq_params) { | |
ae811e21 JB |
2197 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2198 | nla_data(nl_txq_params), | |
2199 | nla_len(nl_txq_params), | |
2200 | txq_params_policy); | |
2201 | if (result) | |
2202 | return result; | |
31888487 JM |
2203 | result = parse_txq_params(tb, &txq_params); |
2204 | if (result) | |
7f2b8562 | 2205 | return result; |
31888487 | 2206 | |
e35e4d28 HG |
2207 | result = rdev_set_txq_params(rdev, netdev, |
2208 | &txq_params); | |
31888487 | 2209 | if (result) |
7f2b8562 | 2210 | return result; |
31888487 JM |
2211 | } |
2212 | } | |
55682965 | 2213 | |
72bdcf34 | 2214 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2215 | result = __nl80211_set_channel( |
2216 | rdev, | |
2217 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2218 | info); | |
72bdcf34 | 2219 | if (result) |
7f2b8562 | 2220 | return result; |
72bdcf34 JM |
2221 | } |
2222 | ||
98d2ff8b | 2223 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2224 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2225 | enum nl80211_tx_power_setting type; |
2226 | int idx, mbm = 0; | |
2227 | ||
c8442118 JB |
2228 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2229 | txp_wdev = NULL; | |
2230 | ||
7f2b8562 YX |
2231 | if (!rdev->ops->set_tx_power) |
2232 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2233 | |
2234 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2235 | type = nla_get_u32(info->attrs[idx]); | |
2236 | ||
2237 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2238 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2239 | return -EINVAL; | |
98d2ff8b JO |
2240 | |
2241 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2242 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2243 | mbm = nla_get_u32(info->attrs[idx]); | |
2244 | } | |
2245 | ||
c8442118 | 2246 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2247 | if (result) |
7f2b8562 | 2248 | return result; |
98d2ff8b JO |
2249 | } |
2250 | ||
afe0cbf8 BR |
2251 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2252 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2253 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2254 | if ((!rdev->wiphy.available_antennas_tx && |
2255 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2256 | !rdev->ops->set_antenna) |
2257 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2258 | |
2259 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2260 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2261 | ||
a7ffac95 | 2262 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2263 | * available antenna masks, except for the "all" mask */ |
2264 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2265 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2266 | return -EINVAL; | |
a7ffac95 | 2267 | |
7f531e03 BR |
2268 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2269 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2270 | |
e35e4d28 | 2271 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2272 | if (result) |
7f2b8562 | 2273 | return result; |
afe0cbf8 BR |
2274 | } |
2275 | ||
b9a5f8ca JM |
2276 | changed = 0; |
2277 | ||
2278 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2279 | retry_short = nla_get_u8( | |
2280 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2281 | if (retry_short == 0) |
2282 | return -EINVAL; | |
2283 | ||
b9a5f8ca JM |
2284 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2285 | } | |
2286 | ||
2287 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2288 | retry_long = nla_get_u8( | |
2289 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2290 | if (retry_long == 0) |
2291 | return -EINVAL; | |
2292 | ||
b9a5f8ca JM |
2293 | changed |= WIPHY_PARAM_RETRY_LONG; |
2294 | } | |
2295 | ||
2296 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2297 | frag_threshold = nla_get_u32( | |
2298 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2299 | if (frag_threshold < 256) |
2300 | return -EINVAL; | |
2301 | ||
b9a5f8ca JM |
2302 | if (frag_threshold != (u32) -1) { |
2303 | /* | |
2304 | * Fragments (apart from the last one) are required to | |
2305 | * have even length. Make the fragmentation code | |
2306 | * simpler by stripping LSB should someone try to use | |
2307 | * odd threshold value. | |
2308 | */ | |
2309 | frag_threshold &= ~0x1; | |
2310 | } | |
2311 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2312 | } | |
2313 | ||
2314 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2315 | rts_threshold = nla_get_u32( | |
2316 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2317 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2318 | } | |
2319 | ||
81077e82 | 2320 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
3057dbfd LB |
2321 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
2322 | return -EINVAL; | |
2323 | ||
81077e82 LT |
2324 | coverage_class = nla_get_u8( |
2325 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2326 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2327 | } | |
2328 | ||
3057dbfd LB |
2329 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
2330 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | |
2331 | return -EOPNOTSUPP; | |
2332 | ||
2333 | changed |= WIPHY_PARAM_DYN_ACK; | |
81077e82 LT |
2334 | } |
2335 | ||
b9a5f8ca JM |
2336 | if (changed) { |
2337 | u8 old_retry_short, old_retry_long; | |
2338 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2339 | u8 old_coverage_class; |
b9a5f8ca | 2340 | |
7f2b8562 YX |
2341 | if (!rdev->ops->set_wiphy_params) |
2342 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2343 | |
2344 | old_retry_short = rdev->wiphy.retry_short; | |
2345 | old_retry_long = rdev->wiphy.retry_long; | |
2346 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2347 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2348 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2349 | |
2350 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2351 | rdev->wiphy.retry_short = retry_short; | |
2352 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2353 | rdev->wiphy.retry_long = retry_long; | |
2354 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2355 | rdev->wiphy.frag_threshold = frag_threshold; | |
2356 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2357 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2358 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2359 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2360 | |
e35e4d28 | 2361 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2362 | if (result) { |
2363 | rdev->wiphy.retry_short = old_retry_short; | |
2364 | rdev->wiphy.retry_long = old_retry_long; | |
2365 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2366 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2367 | rdev->wiphy.coverage_class = old_coverage_class; |
9189ee31 | 2368 | return result; |
b9a5f8ca JM |
2369 | } |
2370 | } | |
7f2b8562 | 2371 | return 0; |
55682965 JB |
2372 | } |
2373 | ||
71bbc994 JB |
2374 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2375 | { | |
2376 | return (u64)wdev->identifier | | |
f26cbf40 | 2377 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2378 | } |
55682965 | 2379 | |
683b6d3b | 2380 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2381 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2382 | { |
601555cd JB |
2383 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
2384 | return -EINVAL; | |
3d9d1d66 | 2385 | |
683b6d3b JB |
2386 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2387 | chandef->chan->center_freq)) | |
2388 | return -ENOBUFS; | |
3d9d1d66 JB |
2389 | switch (chandef->width) { |
2390 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2391 | case NL80211_CHAN_WIDTH_20: | |
2392 | case NL80211_CHAN_WIDTH_40: | |
2393 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2394 | cfg80211_get_chandef_type(chandef))) | |
2395 | return -ENOBUFS; | |
2396 | break; | |
2397 | default: | |
2398 | break; | |
2399 | } | |
2400 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2401 | return -ENOBUFS; | |
2402 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2403 | return -ENOBUFS; | |
2404 | if (chandef->center_freq2 && | |
2405 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2406 | return -ENOBUFS; |
2407 | return 0; | |
2408 | } | |
2409 | ||
15e47304 | 2410 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2411 | struct cfg80211_registered_device *rdev, |
8f894be2 | 2412 | struct wireless_dev *wdev, bool removal) |
55682965 | 2413 | { |
72fb2abc | 2414 | struct net_device *dev = wdev->netdev; |
8f894be2 | 2415 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
55682965 JB |
2416 | void *hdr; |
2417 | ||
8f894be2 TB |
2418 | if (removal) |
2419 | cmd = NL80211_CMD_DEL_INTERFACE; | |
2420 | ||
2421 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | |
55682965 JB |
2422 | if (!hdr) |
2423 | return -1; | |
2424 | ||
72fb2abc JB |
2425 | if (dev && |
2426 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2427 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2428 | goto nla_put_failure; |
2429 | ||
2430 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2431 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2432 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2433 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2434 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2435 | rdev->devlist_generation ^ | |
2436 | (cfg80211_rdev_list_generation << 2))) | |
2437 | goto nla_put_failure; | |
f5ea9120 | 2438 | |
5b7ccaf3 | 2439 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2440 | int ret; |
2441 | struct cfg80211_chan_def chandef; | |
2442 | ||
2443 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2444 | if (ret == 0) { | |
2445 | if (nl80211_send_chandef(msg, &chandef)) | |
2446 | goto nla_put_failure; | |
2447 | } | |
d91df0e3 PF |
2448 | } |
2449 | ||
d55d0d59 RM |
2450 | if (rdev->ops->get_tx_power) { |
2451 | int dbm, ret; | |
2452 | ||
2453 | ret = rdev_get_tx_power(rdev, wdev, &dbm); | |
2454 | if (ret == 0 && | |
2455 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, | |
2456 | DBM_TO_MBM(dbm))) | |
2457 | goto nla_put_failure; | |
2458 | } | |
2459 | ||
b84e7a05 AQ |
2460 | if (wdev->ssid_len) { |
2461 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2462 | goto nla_put_failure; | |
2463 | } | |
2464 | ||
053c095a JB |
2465 | genlmsg_end(msg, hdr); |
2466 | return 0; | |
55682965 JB |
2467 | |
2468 | nla_put_failure: | |
bc3ed28c TG |
2469 | genlmsg_cancel(msg, hdr); |
2470 | return -EMSGSIZE; | |
55682965 JB |
2471 | } |
2472 | ||
2473 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2474 | { | |
2475 | int wp_idx = 0; | |
2476 | int if_idx = 0; | |
2477 | int wp_start = cb->args[0]; | |
2478 | int if_start = cb->args[1]; | |
f5ea9120 | 2479 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2480 | struct wireless_dev *wdev; |
2481 | ||
5fe231e8 | 2482 | rtnl_lock(); |
f5ea9120 JB |
2483 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2484 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2485 | continue; |
bba95fef JB |
2486 | if (wp_idx < wp_start) { |
2487 | wp_idx++; | |
55682965 | 2488 | continue; |
bba95fef | 2489 | } |
55682965 JB |
2490 | if_idx = 0; |
2491 | ||
89a54e48 | 2492 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2493 | if (if_idx < if_start) { |
2494 | if_idx++; | |
55682965 | 2495 | continue; |
bba95fef | 2496 | } |
15e47304 | 2497 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2498 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
8f894be2 | 2499 | rdev, wdev, false) < 0) { |
bba95fef JB |
2500 | goto out; |
2501 | } | |
2502 | if_idx++; | |
55682965 | 2503 | } |
bba95fef JB |
2504 | |
2505 | wp_idx++; | |
55682965 | 2506 | } |
bba95fef | 2507 | out: |
5fe231e8 | 2508 | rtnl_unlock(); |
55682965 JB |
2509 | |
2510 | cb->args[0] = wp_idx; | |
2511 | cb->args[1] = if_idx; | |
2512 | ||
2513 | return skb->len; | |
2514 | } | |
2515 | ||
2516 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2517 | { | |
2518 | struct sk_buff *msg; | |
1b8ec87a | 2519 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2520 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2521 | |
fd2120ca | 2522 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2523 | if (!msg) |
4c476991 | 2524 | return -ENOMEM; |
55682965 | 2525 | |
15e47304 | 2526 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2527 | rdev, wdev, false) < 0) { |
4c476991 JB |
2528 | nlmsg_free(msg); |
2529 | return -ENOBUFS; | |
2530 | } | |
55682965 | 2531 | |
134e6375 | 2532 | return genlmsg_reply(msg, info); |
55682965 JB |
2533 | } |
2534 | ||
66f7ac50 MW |
2535 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2536 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2537 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2538 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2539 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2540 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2541 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2542 | }; |
2543 | ||
2544 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2545 | { | |
2546 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2547 | int flag; | |
2548 | ||
2549 | *mntrflags = 0; | |
2550 | ||
2551 | if (!nla) | |
2552 | return -EINVAL; | |
2553 | ||
2554 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2555 | nla, mntr_flags_policy)) | |
2556 | return -EINVAL; | |
2557 | ||
2558 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2559 | if (flags[flag]) | |
2560 | *mntrflags |= (1<<flag); | |
2561 | ||
2562 | return 0; | |
2563 | } | |
2564 | ||
9bc383de | 2565 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2566 | struct net_device *netdev, u8 use_4addr, |
2567 | enum nl80211_iftype iftype) | |
9bc383de | 2568 | { |
ad4bb6f8 | 2569 | if (!use_4addr) { |
f350a0a8 | 2570 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2571 | return -EBUSY; |
9bc383de | 2572 | return 0; |
ad4bb6f8 | 2573 | } |
9bc383de JB |
2574 | |
2575 | switch (iftype) { | |
2576 | case NL80211_IFTYPE_AP_VLAN: | |
2577 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2578 | return 0; | |
2579 | break; | |
2580 | case NL80211_IFTYPE_STATION: | |
2581 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2582 | return 0; | |
2583 | break; | |
2584 | default: | |
2585 | break; | |
2586 | } | |
2587 | ||
2588 | return -EOPNOTSUPP; | |
2589 | } | |
2590 | ||
55682965 JB |
2591 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2592 | { | |
4c476991 | 2593 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2594 | struct vif_params params; |
e36d56b6 | 2595 | int err; |
04a773ad | 2596 | enum nl80211_iftype otype, ntype; |
4c476991 | 2597 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2598 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2599 | bool change = false; |
55682965 | 2600 | |
2ec600d6 LCC |
2601 | memset(¶ms, 0, sizeof(params)); |
2602 | ||
04a773ad | 2603 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2604 | |
723b038d | 2605 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2606 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2607 | if (otype != ntype) |
ac7f9cfa | 2608 | change = true; |
4c476991 JB |
2609 | if (ntype > NL80211_IFTYPE_MAX) |
2610 | return -EINVAL; | |
723b038d JB |
2611 | } |
2612 | ||
92ffe055 | 2613 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2614 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2615 | ||
4c476991 JB |
2616 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2617 | return -EINVAL; | |
29cbe68c JB |
2618 | if (netif_running(dev)) |
2619 | return -EBUSY; | |
2620 | ||
2621 | wdev_lock(wdev); | |
2622 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2623 | IEEE80211_MAX_MESH_ID_LEN); | |
2624 | wdev->mesh_id_up_len = | |
2625 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2626 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2627 | wdev->mesh_id_up_len); | |
2628 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2629 | } |
2630 | ||
8b787643 FF |
2631 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2632 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2633 | change = true; | |
ad4bb6f8 | 2634 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2635 | if (err) |
4c476991 | 2636 | return err; |
8b787643 FF |
2637 | } else { |
2638 | params.use_4addr = -1; | |
2639 | } | |
2640 | ||
92ffe055 | 2641 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2642 | if (ntype != NL80211_IFTYPE_MONITOR) |
2643 | return -EINVAL; | |
92ffe055 JB |
2644 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2645 | &_flags); | |
ac7f9cfa | 2646 | if (err) |
4c476991 | 2647 | return err; |
ac7f9cfa JB |
2648 | |
2649 | flags = &_flags; | |
2650 | change = true; | |
92ffe055 | 2651 | } |
3b85875a | 2652 | |
18003297 | 2653 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2654 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2655 | return -EOPNOTSUPP; | |
2656 | ||
ac7f9cfa | 2657 | if (change) |
3d54d255 | 2658 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2659 | else |
2660 | err = 0; | |
60719ffd | 2661 | |
9bc383de JB |
2662 | if (!err && params.use_4addr != -1) |
2663 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2664 | ||
55682965 JB |
2665 | return err; |
2666 | } | |
2667 | ||
2668 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2669 | { | |
4c476991 | 2670 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2671 | struct vif_params params; |
84efbb84 | 2672 | struct wireless_dev *wdev; |
8f894be2 | 2673 | struct sk_buff *msg, *event; |
55682965 JB |
2674 | int err; |
2675 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2676 | u32 flags; |
55682965 | 2677 | |
78f22b6a JB |
2678 | /* to avoid failing a new interface creation due to pending removal */ |
2679 | cfg80211_destroy_ifaces(rdev); | |
2680 | ||
2ec600d6 LCC |
2681 | memset(¶ms, 0, sizeof(params)); |
2682 | ||
55682965 JB |
2683 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2684 | return -EINVAL; | |
2685 | ||
2686 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2687 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2688 | if (type > NL80211_IFTYPE_MAX) | |
2689 | return -EINVAL; | |
2690 | } | |
2691 | ||
79c97e97 | 2692 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2693 | !(rdev->wiphy.interface_modes & (1 << type))) |
2694 | return -EOPNOTSUPP; | |
55682965 | 2695 | |
e8f479b1 BG |
2696 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
2697 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && | |
2698 | info->attrs[NL80211_ATTR_MAC]) { | |
1c18f145 AS |
2699 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
2700 | ETH_ALEN); | |
2701 | if (!is_valid_ether_addr(params.macaddr)) | |
2702 | return -EADDRNOTAVAIL; | |
2703 | } | |
2704 | ||
9bc383de | 2705 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2706 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2707 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2708 | if (err) |
4c476991 | 2709 | return err; |
9bc383de | 2710 | } |
8b787643 | 2711 | |
66f7ac50 MW |
2712 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2713 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2714 | &flags); | |
e057d3c3 | 2715 | |
18003297 | 2716 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2717 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2718 | return -EOPNOTSUPP; | |
2719 | ||
a18c7192 JB |
2720 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2721 | if (!msg) | |
2722 | return -ENOMEM; | |
2723 | ||
e35e4d28 HG |
2724 | wdev = rdev_add_virtual_intf(rdev, |
2725 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
6bab2e19 TG |
2726 | NET_NAME_USER, type, err ? NULL : &flags, |
2727 | ¶ms); | |
d687cbb7 RM |
2728 | if (WARN_ON(!wdev)) { |
2729 | nlmsg_free(msg); | |
2730 | return -EPROTO; | |
2731 | } else if (IS_ERR(wdev)) { | |
1c90f9d4 | 2732 | nlmsg_free(msg); |
84efbb84 | 2733 | return PTR_ERR(wdev); |
1c90f9d4 | 2734 | } |
2ec600d6 | 2735 | |
18e5ca65 | 2736 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
78f22b6a JB |
2737 | wdev->owner_nlportid = info->snd_portid; |
2738 | ||
98104fde JB |
2739 | switch (type) { |
2740 | case NL80211_IFTYPE_MESH_POINT: | |
2741 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2742 | break; | |
29cbe68c JB |
2743 | wdev_lock(wdev); |
2744 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2745 | IEEE80211_MAX_MESH_ID_LEN); | |
2746 | wdev->mesh_id_up_len = | |
2747 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2748 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2749 | wdev->mesh_id_up_len); | |
2750 | wdev_unlock(wdev); | |
98104fde JB |
2751 | break; |
2752 | case NL80211_IFTYPE_P2P_DEVICE: | |
2753 | /* | |
2754 | * P2P Device doesn't have a netdev, so doesn't go | |
2755 | * through the netdev notifier and must be added here | |
2756 | */ | |
2757 | mutex_init(&wdev->mtx); | |
2758 | INIT_LIST_HEAD(&wdev->event_list); | |
2759 | spin_lock_init(&wdev->event_lock); | |
2760 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2761 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2762 | ||
98104fde JB |
2763 | wdev->identifier = ++rdev->wdev_id; |
2764 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2765 | rdev->devlist_generation++; | |
98104fde JB |
2766 | break; |
2767 | default: | |
2768 | break; | |
29cbe68c JB |
2769 | } |
2770 | ||
15e47304 | 2771 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2772 | rdev, wdev, false) < 0) { |
1c90f9d4 JB |
2773 | nlmsg_free(msg); |
2774 | return -ENOBUFS; | |
2775 | } | |
2776 | ||
8f894be2 TB |
2777 | event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2778 | if (event) { | |
2779 | if (nl80211_send_iface(event, 0, 0, 0, | |
2780 | rdev, wdev, false) < 0) { | |
2781 | nlmsg_free(event); | |
2782 | goto out; | |
2783 | } | |
2784 | ||
2785 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
2786 | event, 0, NL80211_MCGRP_CONFIG, | |
2787 | GFP_KERNEL); | |
2788 | } | |
2789 | ||
2790 | out: | |
1c90f9d4 | 2791 | return genlmsg_reply(msg, info); |
55682965 JB |
2792 | } |
2793 | ||
2794 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2795 | { | |
4c476991 | 2796 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2797 | struct wireless_dev *wdev = info->user_ptr[1]; |
8f894be2 TB |
2798 | struct sk_buff *msg; |
2799 | int status; | |
55682965 | 2800 | |
4c476991 JB |
2801 | if (!rdev->ops->del_virtual_intf) |
2802 | return -EOPNOTSUPP; | |
55682965 | 2803 | |
8f894be2 TB |
2804 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2805 | if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) { | |
2806 | nlmsg_free(msg); | |
2807 | msg = NULL; | |
2808 | } | |
2809 | ||
84efbb84 JB |
2810 | /* |
2811 | * If we remove a wireless device without a netdev then clear | |
2812 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2813 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2814 | * since the wdev has been freed, unlike with a netdev where | |
2815 | * we need the dev_put() for the netdev to really be freed. | |
2816 | */ | |
2817 | if (!wdev->netdev) | |
2818 | info->user_ptr[1] = NULL; | |
2819 | ||
8f894be2 TB |
2820 | status = rdev_del_virtual_intf(rdev, wdev); |
2821 | if (status >= 0 && msg) | |
2822 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
2823 | msg, 0, NL80211_MCGRP_CONFIG, | |
2824 | GFP_KERNEL); | |
2825 | else | |
2826 | nlmsg_free(msg); | |
2827 | ||
2828 | return status; | |
55682965 JB |
2829 | } |
2830 | ||
1d9d9213 SW |
2831 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2832 | { | |
2833 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2834 | struct net_device *dev = info->user_ptr[1]; | |
2835 | u16 noack_map; | |
2836 | ||
2837 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2838 | return -EINVAL; | |
2839 | ||
2840 | if (!rdev->ops->set_noack_map) | |
2841 | return -EOPNOTSUPP; | |
2842 | ||
2843 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2844 | ||
e35e4d28 | 2845 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2846 | } |
2847 | ||
41ade00f JB |
2848 | struct get_key_cookie { |
2849 | struct sk_buff *msg; | |
2850 | int error; | |
b9454e83 | 2851 | int idx; |
41ade00f JB |
2852 | }; |
2853 | ||
2854 | static void get_key_callback(void *c, struct key_params *params) | |
2855 | { | |
b9454e83 | 2856 | struct nlattr *key; |
41ade00f JB |
2857 | struct get_key_cookie *cookie = c; |
2858 | ||
9360ffd1 DM |
2859 | if ((params->key && |
2860 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2861 | params->key_len, params->key)) || | |
2862 | (params->seq && | |
2863 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2864 | params->seq_len, params->seq)) || | |
2865 | (params->cipher && | |
2866 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2867 | params->cipher))) | |
2868 | goto nla_put_failure; | |
41ade00f | 2869 | |
b9454e83 JB |
2870 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2871 | if (!key) | |
2872 | goto nla_put_failure; | |
2873 | ||
9360ffd1 DM |
2874 | if ((params->key && |
2875 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2876 | params->key_len, params->key)) || | |
2877 | (params->seq && | |
2878 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2879 | params->seq_len, params->seq)) || | |
2880 | (params->cipher && | |
2881 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2882 | params->cipher))) | |
2883 | goto nla_put_failure; | |
b9454e83 | 2884 | |
9360ffd1 DM |
2885 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2886 | goto nla_put_failure; | |
b9454e83 JB |
2887 | |
2888 | nla_nest_end(cookie->msg, key); | |
2889 | ||
41ade00f JB |
2890 | return; |
2891 | nla_put_failure: | |
2892 | cookie->error = 1; | |
2893 | } | |
2894 | ||
2895 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2896 | { | |
4c476991 | 2897 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2898 | int err; |
4c476991 | 2899 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2900 | u8 key_idx = 0; |
e31b8213 JB |
2901 | const u8 *mac_addr = NULL; |
2902 | bool pairwise; | |
41ade00f JB |
2903 | struct get_key_cookie cookie = { |
2904 | .error = 0, | |
2905 | }; | |
2906 | void *hdr; | |
2907 | struct sk_buff *msg; | |
2908 | ||
2909 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2910 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2911 | ||
3cfcf6ac | 2912 | if (key_idx > 5) |
41ade00f JB |
2913 | return -EINVAL; |
2914 | ||
2915 | if (info->attrs[NL80211_ATTR_MAC]) | |
2916 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2917 | ||
e31b8213 JB |
2918 | pairwise = !!mac_addr; |
2919 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2920 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2921 | if (kt >= NUM_NL80211_KEYTYPES) | |
2922 | return -EINVAL; | |
2923 | if (kt != NL80211_KEYTYPE_GROUP && | |
2924 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2925 | return -EINVAL; | |
2926 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2927 | } | |
2928 | ||
4c476991 JB |
2929 | if (!rdev->ops->get_key) |
2930 | return -EOPNOTSUPP; | |
41ade00f | 2931 | |
0fa7b391 JB |
2932 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
2933 | return -ENOENT; | |
2934 | ||
fd2120ca | 2935 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2936 | if (!msg) |
2937 | return -ENOMEM; | |
41ade00f | 2938 | |
15e47304 | 2939 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2940 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 2941 | if (!hdr) |
9fe271af | 2942 | goto nla_put_failure; |
41ade00f JB |
2943 | |
2944 | cookie.msg = msg; | |
b9454e83 | 2945 | cookie.idx = key_idx; |
41ade00f | 2946 | |
9360ffd1 DM |
2947 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2948 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2949 | goto nla_put_failure; | |
2950 | if (mac_addr && | |
2951 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2952 | goto nla_put_failure; | |
41ade00f | 2953 | |
e35e4d28 HG |
2954 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2955 | get_key_callback); | |
41ade00f JB |
2956 | |
2957 | if (err) | |
6c95e2a2 | 2958 | goto free_msg; |
41ade00f JB |
2959 | |
2960 | if (cookie.error) | |
2961 | goto nla_put_failure; | |
2962 | ||
2963 | genlmsg_end(msg, hdr); | |
4c476991 | 2964 | return genlmsg_reply(msg, info); |
41ade00f JB |
2965 | |
2966 | nla_put_failure: | |
2967 | err = -ENOBUFS; | |
6c95e2a2 | 2968 | free_msg: |
41ade00f | 2969 | nlmsg_free(msg); |
41ade00f JB |
2970 | return err; |
2971 | } | |
2972 | ||
2973 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2974 | { | |
4c476991 | 2975 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2976 | struct key_parse key; |
41ade00f | 2977 | int err; |
4c476991 | 2978 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2979 | |
b9454e83 JB |
2980 | err = nl80211_parse_key(info, &key); |
2981 | if (err) | |
2982 | return err; | |
41ade00f | 2983 | |
b9454e83 | 2984 | if (key.idx < 0) |
41ade00f JB |
2985 | return -EINVAL; |
2986 | ||
b9454e83 JB |
2987 | /* only support setting default key */ |
2988 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2989 | return -EINVAL; |
2990 | ||
dbd2fd65 | 2991 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2992 | |
dbd2fd65 JB |
2993 | if (key.def) { |
2994 | if (!rdev->ops->set_default_key) { | |
2995 | err = -EOPNOTSUPP; | |
2996 | goto out; | |
2997 | } | |
41ade00f | 2998 | |
dbd2fd65 JB |
2999 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
3000 | if (err) | |
3001 | goto out; | |
3002 | ||
e35e4d28 | 3003 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
3004 | key.def_uni, key.def_multi); |
3005 | ||
3006 | if (err) | |
3007 | goto out; | |
fffd0934 | 3008 | |
3d23e349 | 3009 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
3010 | dev->ieee80211_ptr->wext.default_key = key.idx; |
3011 | #endif | |
3012 | } else { | |
3013 | if (key.def_uni || !key.def_multi) { | |
3014 | err = -EINVAL; | |
3015 | goto out; | |
3016 | } | |
3017 | ||
3018 | if (!rdev->ops->set_default_mgmt_key) { | |
3019 | err = -EOPNOTSUPP; | |
3020 | goto out; | |
3021 | } | |
3022 | ||
3023 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3024 | if (err) | |
3025 | goto out; | |
3026 | ||
e35e4d28 | 3027 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
3028 | if (err) |
3029 | goto out; | |
3030 | ||
3031 | #ifdef CONFIG_CFG80211_WEXT | |
3032 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 3033 | #endif |
dbd2fd65 JB |
3034 | } |
3035 | ||
3036 | out: | |
fffd0934 | 3037 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3038 | |
41ade00f JB |
3039 | return err; |
3040 | } | |
3041 | ||
3042 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
3043 | { | |
4c476991 | 3044 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 3045 | int err; |
4c476991 | 3046 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 3047 | struct key_parse key; |
e31b8213 | 3048 | const u8 *mac_addr = NULL; |
41ade00f | 3049 | |
b9454e83 JB |
3050 | err = nl80211_parse_key(info, &key); |
3051 | if (err) | |
3052 | return err; | |
41ade00f | 3053 | |
b9454e83 | 3054 | if (!key.p.key) |
41ade00f JB |
3055 | return -EINVAL; |
3056 | ||
41ade00f JB |
3057 | if (info->attrs[NL80211_ATTR_MAC]) |
3058 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3059 | ||
e31b8213 JB |
3060 | if (key.type == -1) { |
3061 | if (mac_addr) | |
3062 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3063 | else | |
3064 | key.type = NL80211_KEYTYPE_GROUP; | |
3065 | } | |
3066 | ||
3067 | /* for now */ | |
3068 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3069 | key.type != NL80211_KEYTYPE_GROUP) | |
3070 | return -EINVAL; | |
3071 | ||
4c476991 JB |
3072 | if (!rdev->ops->add_key) |
3073 | return -EOPNOTSUPP; | |
25e47c18 | 3074 | |
e31b8213 JB |
3075 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
3076 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3077 | mac_addr)) | |
4c476991 | 3078 | return -EINVAL; |
41ade00f | 3079 | |
fffd0934 JB |
3080 | wdev_lock(dev->ieee80211_ptr); |
3081 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3082 | if (!err) | |
e35e4d28 HG |
3083 | err = rdev_add_key(rdev, dev, key.idx, |
3084 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3085 | mac_addr, &key.p); | |
fffd0934 | 3086 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3087 | |
41ade00f JB |
3088 | return err; |
3089 | } | |
3090 | ||
3091 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
3092 | { | |
4c476991 | 3093 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3094 | int err; |
4c476991 | 3095 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3096 | u8 *mac_addr = NULL; |
b9454e83 | 3097 | struct key_parse key; |
41ade00f | 3098 | |
b9454e83 JB |
3099 | err = nl80211_parse_key(info, &key); |
3100 | if (err) | |
3101 | return err; | |
41ade00f JB |
3102 | |
3103 | if (info->attrs[NL80211_ATTR_MAC]) | |
3104 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3105 | ||
e31b8213 JB |
3106 | if (key.type == -1) { |
3107 | if (mac_addr) | |
3108 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3109 | else | |
3110 | key.type = NL80211_KEYTYPE_GROUP; | |
3111 | } | |
3112 | ||
3113 | /* for now */ | |
3114 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3115 | key.type != NL80211_KEYTYPE_GROUP) | |
3116 | return -EINVAL; | |
3117 | ||
4c476991 JB |
3118 | if (!rdev->ops->del_key) |
3119 | return -EOPNOTSUPP; | |
41ade00f | 3120 | |
fffd0934 JB |
3121 | wdev_lock(dev->ieee80211_ptr); |
3122 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 | 3123 | |
0fa7b391 | 3124 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
e31b8213 JB |
3125 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
3126 | err = -ENOENT; | |
3127 | ||
fffd0934 | 3128 | if (!err) |
e35e4d28 HG |
3129 | err = rdev_del_key(rdev, dev, key.idx, |
3130 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3131 | mac_addr); | |
41ade00f | 3132 | |
3d23e349 | 3133 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 3134 | if (!err) { |
b9454e83 | 3135 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 3136 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 3137 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
3138 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
3139 | } | |
3140 | #endif | |
fffd0934 | 3141 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 3142 | |
41ade00f JB |
3143 | return err; |
3144 | } | |
3145 | ||
77765eaf VT |
3146 | /* This function returns an error or the number of nested attributes */ |
3147 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
3148 | { | |
3149 | struct nlattr *attr; | |
3150 | int n_entries = 0, tmp; | |
3151 | ||
3152 | nla_for_each_nested(attr, nl_attr, tmp) { | |
3153 | if (nla_len(attr) != ETH_ALEN) | |
3154 | return -EINVAL; | |
3155 | ||
3156 | n_entries++; | |
3157 | } | |
3158 | ||
3159 | return n_entries; | |
3160 | } | |
3161 | ||
3162 | /* | |
3163 | * This function parses ACL information and allocates memory for ACL data. | |
3164 | * On successful return, the calling function is responsible to free the | |
3165 | * ACL buffer returned by this function. | |
3166 | */ | |
3167 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3168 | struct genl_info *info) | |
3169 | { | |
3170 | enum nl80211_acl_policy acl_policy; | |
3171 | struct nlattr *attr; | |
3172 | struct cfg80211_acl_data *acl; | |
3173 | int i = 0, n_entries, tmp; | |
3174 | ||
3175 | if (!wiphy->max_acl_mac_addrs) | |
3176 | return ERR_PTR(-EOPNOTSUPP); | |
3177 | ||
3178 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3179 | return ERR_PTR(-EINVAL); | |
3180 | ||
3181 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3182 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3183 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3184 | return ERR_PTR(-EINVAL); | |
3185 | ||
3186 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3187 | return ERR_PTR(-EINVAL); | |
3188 | ||
3189 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3190 | if (n_entries < 0) | |
3191 | return ERR_PTR(n_entries); | |
3192 | ||
3193 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3194 | return ERR_PTR(-ENOTSUPP); | |
3195 | ||
3196 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
3197 | GFP_KERNEL); | |
3198 | if (!acl) | |
3199 | return ERR_PTR(-ENOMEM); | |
3200 | ||
3201 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3202 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3203 | i++; | |
3204 | } | |
3205 | ||
3206 | acl->n_acl_entries = n_entries; | |
3207 | acl->acl_policy = acl_policy; | |
3208 | ||
3209 | return acl; | |
3210 | } | |
3211 | ||
3212 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3213 | { | |
3214 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3215 | struct net_device *dev = info->user_ptr[1]; | |
3216 | struct cfg80211_acl_data *acl; | |
3217 | int err; | |
3218 | ||
3219 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3220 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3221 | return -EOPNOTSUPP; | |
3222 | ||
3223 | if (!dev->ieee80211_ptr->beacon_interval) | |
3224 | return -EINVAL; | |
3225 | ||
3226 | acl = parse_acl_data(&rdev->wiphy, info); | |
3227 | if (IS_ERR(acl)) | |
3228 | return PTR_ERR(acl); | |
3229 | ||
3230 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3231 | ||
3232 | kfree(acl); | |
3233 | ||
3234 | return err; | |
3235 | } | |
3236 | ||
a1193be8 | 3237 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3238 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3239 | { |
8860020e | 3240 | bool haveinfo = false; |
ed1b6cc7 | 3241 | |
a1193be8 SW |
3242 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3243 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3244 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3245 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3246 | return -EINVAL; |
3247 | ||
8860020e | 3248 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3249 | |
a1193be8 SW |
3250 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3251 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3252 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3253 | if (!bcn->head_len) |
3254 | return -EINVAL; | |
3255 | haveinfo = true; | |
ed1b6cc7 JB |
3256 | } |
3257 | ||
a1193be8 SW |
3258 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3259 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3260 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3261 | haveinfo = true; |
ed1b6cc7 JB |
3262 | } |
3263 | ||
4c476991 JB |
3264 | if (!haveinfo) |
3265 | return -EINVAL; | |
3b85875a | 3266 | |
a1193be8 SW |
3267 | if (attrs[NL80211_ATTR_IE]) { |
3268 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3269 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3270 | } |
3271 | ||
a1193be8 | 3272 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3273 | bcn->proberesp_ies = |
a1193be8 | 3274 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3275 | bcn->proberesp_ies_len = |
a1193be8 | 3276 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3277 | } |
3278 | ||
a1193be8 | 3279 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3280 | bcn->assocresp_ies = |
a1193be8 | 3281 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3282 | bcn->assocresp_ies_len = |
a1193be8 | 3283 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3284 | } |
3285 | ||
a1193be8 SW |
3286 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3287 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3288 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3289 | } |
3290 | ||
8860020e JB |
3291 | return 0; |
3292 | } | |
3293 | ||
46c1dd0c FF |
3294 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3295 | struct cfg80211_ap_settings *params) | |
3296 | { | |
3297 | struct wireless_dev *wdev; | |
3298 | bool ret = false; | |
3299 | ||
89a54e48 | 3300 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3301 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3302 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3303 | continue; | |
3304 | ||
683b6d3b | 3305 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3306 | continue; |
3307 | ||
683b6d3b | 3308 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3309 | ret = true; |
3310 | break; | |
3311 | } | |
3312 | ||
46c1dd0c FF |
3313 | return ret; |
3314 | } | |
3315 | ||
e39e5b5e JM |
3316 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3317 | enum nl80211_auth_type auth_type, | |
3318 | enum nl80211_commands cmd) | |
3319 | { | |
3320 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3321 | return false; | |
3322 | ||
3323 | switch (cmd) { | |
3324 | case NL80211_CMD_AUTHENTICATE: | |
3325 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3326 | auth_type == NL80211_AUTHTYPE_SAE) | |
3327 | return false; | |
3328 | return true; | |
3329 | case NL80211_CMD_CONNECT: | |
3330 | case NL80211_CMD_START_AP: | |
3331 | /* SAE not supported yet */ | |
3332 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3333 | return false; | |
3334 | return true; | |
3335 | default: | |
3336 | return false; | |
3337 | } | |
3338 | } | |
3339 | ||
8860020e JB |
3340 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3341 | { | |
3342 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3343 | struct net_device *dev = info->user_ptr[1]; | |
3344 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3345 | struct cfg80211_ap_settings params; | |
3346 | int err; | |
3347 | ||
3348 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3349 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3350 | return -EOPNOTSUPP; | |
3351 | ||
3352 | if (!rdev->ops->start_ap) | |
3353 | return -EOPNOTSUPP; | |
3354 | ||
3355 | if (wdev->beacon_interval) | |
3356 | return -EALREADY; | |
3357 | ||
3358 | memset(¶ms, 0, sizeof(params)); | |
3359 | ||
3360 | /* these are required for START_AP */ | |
3361 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3362 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3363 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3364 | return -EINVAL; | |
3365 | ||
a1193be8 | 3366 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3367 | if (err) |
3368 | return err; | |
3369 | ||
3370 | params.beacon_interval = | |
3371 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3372 | params.dtim_period = | |
3373 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3374 | ||
3375 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3376 | if (err) | |
3377 | return err; | |
3378 | ||
3379 | /* | |
3380 | * In theory, some of these attributes should be required here | |
3381 | * but since they were not used when the command was originally | |
3382 | * added, keep them optional for old user space programs to let | |
3383 | * them continue to work with drivers that do not need the | |
3384 | * additional information -- drivers must check! | |
3385 | */ | |
3386 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3387 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3388 | params.ssid_len = | |
3389 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3390 | if (params.ssid_len == 0 || | |
3391 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3392 | return -EINVAL; | |
3393 | } | |
3394 | ||
3395 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3396 | params.hidden_ssid = nla_get_u32( | |
3397 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3398 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3399 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3400 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3401 | return -EINVAL; | |
3402 | } | |
3403 | ||
3404 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3405 | ||
3406 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3407 | params.auth_type = nla_get_u32( | |
3408 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3409 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3410 | NL80211_CMD_START_AP)) | |
8860020e JB |
3411 | return -EINVAL; |
3412 | } else | |
3413 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3414 | ||
3415 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3416 | NL80211_MAX_NR_CIPHER_SUITES); | |
3417 | if (err) | |
3418 | return err; | |
3419 | ||
1b658f11 VT |
3420 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3421 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3422 | return -EOPNOTSUPP; | |
3423 | params.inactivity_timeout = nla_get_u16( | |
3424 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3425 | } | |
3426 | ||
53cabad7 JB |
3427 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3428 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3429 | return -EINVAL; | |
3430 | params.p2p_ctwindow = | |
3431 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3432 | if (params.p2p_ctwindow > 127) | |
3433 | return -EINVAL; | |
3434 | if (params.p2p_ctwindow != 0 && | |
3435 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3436 | return -EINVAL; | |
3437 | } | |
3438 | ||
3439 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3440 | u8 tmp; | |
3441 | ||
3442 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3443 | return -EINVAL; | |
3444 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3445 | if (tmp > 1) | |
3446 | return -EINVAL; | |
3447 | params.p2p_opp_ps = tmp; | |
3448 | if (params.p2p_opp_ps != 0 && | |
3449 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3450 | return -EINVAL; | |
3451 | } | |
3452 | ||
aa430da4 | 3453 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3454 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3455 | if (err) | |
3456 | return err; | |
3457 | } else if (wdev->preset_chandef.chan) { | |
3458 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3459 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3460 | return -EINVAL; |
3461 | ||
923b352f AN |
3462 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
3463 | wdev->iftype)) | |
aa430da4 JB |
3464 | return -EINVAL; |
3465 | ||
18998c38 EP |
3466 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
3467 | params.smps_mode = | |
3468 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); | |
3469 | switch (params.smps_mode) { | |
3470 | case NL80211_SMPS_OFF: | |
3471 | break; | |
3472 | case NL80211_SMPS_STATIC: | |
3473 | if (!(rdev->wiphy.features & | |
3474 | NL80211_FEATURE_STATIC_SMPS)) | |
3475 | return -EINVAL; | |
3476 | break; | |
3477 | case NL80211_SMPS_DYNAMIC: | |
3478 | if (!(rdev->wiphy.features & | |
3479 | NL80211_FEATURE_DYNAMIC_SMPS)) | |
3480 | return -EINVAL; | |
3481 | break; | |
3482 | default: | |
3483 | return -EINVAL; | |
3484 | } | |
3485 | } else { | |
3486 | params.smps_mode = NL80211_SMPS_OFF; | |
3487 | } | |
3488 | ||
4baf6bea OO |
3489 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3490 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3491 | if (IS_ERR(params.acl)) | |
3492 | return PTR_ERR(params.acl); | |
3493 | } | |
3494 | ||
34d50519 LD |
3495 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
3496 | if (params.pbss && !rdev->wiphy.bands[IEEE80211_BAND_60GHZ]) | |
3497 | return -EOPNOTSUPP; | |
3498 | ||
c56589ed | 3499 | wdev_lock(wdev); |
e35e4d28 | 3500 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3501 | if (!err) { |
683b6d3b | 3502 | wdev->preset_chandef = params.chandef; |
8860020e | 3503 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 3504 | wdev->chandef = params.chandef; |
06e191e2 AQ |
3505 | wdev->ssid_len = params.ssid_len; |
3506 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3507 | } |
c56589ed | 3508 | wdev_unlock(wdev); |
77765eaf VT |
3509 | |
3510 | kfree(params.acl); | |
3511 | ||
56d1893d | 3512 | return err; |
ed1b6cc7 JB |
3513 | } |
3514 | ||
8860020e JB |
3515 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3516 | { | |
3517 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3518 | struct net_device *dev = info->user_ptr[1]; | |
3519 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3520 | struct cfg80211_beacon_data params; | |
3521 | int err; | |
3522 | ||
3523 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3524 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3525 | return -EOPNOTSUPP; | |
3526 | ||
3527 | if (!rdev->ops->change_beacon) | |
3528 | return -EOPNOTSUPP; | |
3529 | ||
3530 | if (!wdev->beacon_interval) | |
3531 | return -EINVAL; | |
3532 | ||
a1193be8 | 3533 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3534 | if (err) |
3535 | return err; | |
3536 | ||
c56589ed SW |
3537 | wdev_lock(wdev); |
3538 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3539 | wdev_unlock(wdev); | |
3540 | ||
3541 | return err; | |
8860020e JB |
3542 | } |
3543 | ||
3544 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3545 | { |
4c476991 JB |
3546 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3547 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3548 | |
7c8d5e03 | 3549 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
3550 | } |
3551 | ||
5727ef1b JB |
3552 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3553 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3554 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3555 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3556 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3557 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3558 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3559 | }; |
3560 | ||
eccb8e8f | 3561 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3562 | enum nl80211_iftype iftype, |
eccb8e8f | 3563 | struct station_parameters *params) |
5727ef1b JB |
3564 | { |
3565 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3566 | struct nlattr *nla; |
5727ef1b JB |
3567 | int flag; |
3568 | ||
eccb8e8f JB |
3569 | /* |
3570 | * Try parsing the new attribute first so userspace | |
3571 | * can specify both for older kernels. | |
3572 | */ | |
3573 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3574 | if (nla) { | |
3575 | struct nl80211_sta_flag_update *sta_flags; | |
3576 | ||
3577 | sta_flags = nla_data(nla); | |
3578 | params->sta_flags_mask = sta_flags->mask; | |
3579 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3580 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3581 | if ((params->sta_flags_mask | |
3582 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3583 | return -EINVAL; | |
3584 | return 0; | |
3585 | } | |
3586 | ||
3587 | /* if present, parse the old attribute */ | |
5727ef1b | 3588 | |
eccb8e8f | 3589 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3590 | if (!nla) |
3591 | return 0; | |
3592 | ||
3593 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3594 | nla, sta_flags_policy)) | |
3595 | return -EINVAL; | |
3596 | ||
bdd3ae3d JB |
3597 | /* |
3598 | * Only allow certain flags for interface types so that | |
3599 | * other attributes are silently ignored. Remember that | |
3600 | * this is backward compatibility code with old userspace | |
3601 | * and shouldn't be hit in other cases anyway. | |
3602 | */ | |
3603 | switch (iftype) { | |
3604 | case NL80211_IFTYPE_AP: | |
3605 | case NL80211_IFTYPE_AP_VLAN: | |
3606 | case NL80211_IFTYPE_P2P_GO: | |
3607 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3608 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3609 | BIT(NL80211_STA_FLAG_WME) | | |
3610 | BIT(NL80211_STA_FLAG_MFP); | |
3611 | break; | |
3612 | case NL80211_IFTYPE_P2P_CLIENT: | |
3613 | case NL80211_IFTYPE_STATION: | |
3614 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3615 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3616 | break; | |
3617 | case NL80211_IFTYPE_MESH_POINT: | |
3618 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3619 | BIT(NL80211_STA_FLAG_MFP) | | |
3620 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3621 | default: | |
3622 | return -EINVAL; | |
3623 | } | |
5727ef1b | 3624 | |
3383b5a6 JB |
3625 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3626 | if (flags[flag]) { | |
eccb8e8f | 3627 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3628 | |
3383b5a6 JB |
3629 | /* no longer support new API additions in old API */ |
3630 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3631 | return -EINVAL; | |
3632 | } | |
3633 | } | |
3634 | ||
5727ef1b JB |
3635 | return 0; |
3636 | } | |
3637 | ||
c8dcfd8a FF |
3638 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3639 | int attr) | |
3640 | { | |
3641 | struct nlattr *rate; | |
8eb41c8d VK |
3642 | u32 bitrate; |
3643 | u16 bitrate_compat; | |
b51f3bee | 3644 | enum nl80211_attrs rate_flg; |
c8dcfd8a FF |
3645 | |
3646 | rate = nla_nest_start(msg, attr); | |
3647 | if (!rate) | |
db9c64cf | 3648 | return false; |
c8dcfd8a FF |
3649 | |
3650 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3651 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3652 | /* report 16-bit bitrate only if we can */ |
3653 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3654 | if (bitrate > 0 && |
3655 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3656 | return false; | |
3657 | if (bitrate_compat > 0 && | |
3658 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3659 | return false; | |
3660 | ||
b51f3bee JB |
3661 | switch (info->bw) { |
3662 | case RATE_INFO_BW_5: | |
3663 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; | |
3664 | break; | |
3665 | case RATE_INFO_BW_10: | |
3666 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; | |
3667 | break; | |
3668 | default: | |
3669 | WARN_ON(1); | |
3670 | /* fall through */ | |
3671 | case RATE_INFO_BW_20: | |
3672 | rate_flg = 0; | |
3673 | break; | |
3674 | case RATE_INFO_BW_40: | |
3675 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; | |
3676 | break; | |
3677 | case RATE_INFO_BW_80: | |
3678 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; | |
3679 | break; | |
3680 | case RATE_INFO_BW_160: | |
3681 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; | |
3682 | break; | |
3683 | } | |
3684 | ||
3685 | if (rate_flg && nla_put_flag(msg, rate_flg)) | |
3686 | return false; | |
3687 | ||
db9c64cf JB |
3688 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
3689 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3690 | return false; | |
db9c64cf JB |
3691 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
3692 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3693 | return false; | |
3694 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3695 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3696 | return false; | |
3697 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3698 | return false; | |
db9c64cf JB |
3699 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
3700 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3701 | return false; | |
3702 | } | |
c8dcfd8a FF |
3703 | |
3704 | nla_nest_end(msg, rate); | |
3705 | return true; | |
c8dcfd8a FF |
3706 | } |
3707 | ||
119363c7 FF |
3708 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3709 | int id) | |
3710 | { | |
3711 | void *attr; | |
3712 | int i = 0; | |
3713 | ||
3714 | if (!mask) | |
3715 | return true; | |
3716 | ||
3717 | attr = nla_nest_start(msg, id); | |
3718 | if (!attr) | |
3719 | return false; | |
3720 | ||
3721 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3722 | if (!(mask & BIT(i))) | |
3723 | continue; | |
3724 | ||
3725 | if (nla_put_u8(msg, i, signal[i])) | |
3726 | return false; | |
3727 | } | |
3728 | ||
3729 | nla_nest_end(msg, attr); | |
3730 | ||
3731 | return true; | |
3732 | } | |
3733 | ||
cf5ead82 JB |
3734 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
3735 | u32 seq, int flags, | |
66266b3a JL |
3736 | struct cfg80211_registered_device *rdev, |
3737 | struct net_device *dev, | |
98b62183 | 3738 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3739 | { |
3740 | void *hdr; | |
f4263c98 | 3741 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3742 | |
cf5ead82 | 3743 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
fd5b74dc JB |
3744 | if (!hdr) |
3745 | return -1; | |
3746 | ||
9360ffd1 DM |
3747 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3748 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3749 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3750 | goto nla_put_failure; | |
f5ea9120 | 3751 | |
2ec600d6 LCC |
3752 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3753 | if (!sinfoattr) | |
fd5b74dc | 3754 | goto nla_put_failure; |
319090bf JB |
3755 | |
3756 | #define PUT_SINFO(attr, memb, type) do { \ | |
3757 | if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \ | |
3758 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ | |
3759 | sinfo->memb)) \ | |
3760 | goto nla_put_failure; \ | |
3761 | } while (0) | |
3762 | ||
3763 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); | |
3764 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); | |
3765 | ||
3766 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | | |
3767 | BIT(NL80211_STA_INFO_RX_BYTES64)) && | |
9360ffd1 | 3768 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3769 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3770 | goto nla_put_failure; |
319090bf JB |
3771 | |
3772 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | | |
3773 | BIT(NL80211_STA_INFO_TX_BYTES64)) && | |
9360ffd1 | 3774 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3775 | (u32)sinfo->tx_bytes)) |
3776 | goto nla_put_failure; | |
319090bf JB |
3777 | |
3778 | PUT_SINFO(RX_BYTES64, rx_bytes, u64); | |
3779 | PUT_SINFO(TX_BYTES64, tx_bytes, u64); | |
3780 | PUT_SINFO(LLID, llid, u16); | |
3781 | PUT_SINFO(PLID, plid, u16); | |
3782 | PUT_SINFO(PLINK_STATE, plink_state, u8); | |
3783 | ||
66266b3a JL |
3784 | switch (rdev->wiphy.signal_type) { |
3785 | case CFG80211_SIGNAL_TYPE_MBM: | |
319090bf JB |
3786 | PUT_SINFO(SIGNAL, signal, u8); |
3787 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); | |
66266b3a JL |
3788 | break; |
3789 | default: | |
3790 | break; | |
3791 | } | |
319090bf | 3792 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
119363c7 FF |
3793 | if (!nl80211_put_signal(msg, sinfo->chains, |
3794 | sinfo->chain_signal, | |
3795 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3796 | goto nla_put_failure; | |
3797 | } | |
319090bf | 3798 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
119363c7 FF |
3799 | if (!nl80211_put_signal(msg, sinfo->chains, |
3800 | sinfo->chain_signal_avg, | |
3801 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3802 | goto nla_put_failure; | |
3803 | } | |
319090bf | 3804 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
c8dcfd8a FF |
3805 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3806 | NL80211_STA_INFO_TX_BITRATE)) | |
3807 | goto nla_put_failure; | |
3808 | } | |
319090bf | 3809 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
c8dcfd8a FF |
3810 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
3811 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3812 | goto nla_put_failure; |
420e7fab | 3813 | } |
319090bf JB |
3814 | |
3815 | PUT_SINFO(RX_PACKETS, rx_packets, u32); | |
3816 | PUT_SINFO(TX_PACKETS, tx_packets, u32); | |
3817 | PUT_SINFO(TX_RETRIES, tx_retries, u32); | |
3818 | PUT_SINFO(TX_FAILED, tx_failed, u32); | |
3819 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); | |
3820 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); | |
3821 | PUT_SINFO(LOCAL_PM, local_pm, u32); | |
3822 | PUT_SINFO(PEER_PM, peer_pm, u32); | |
3823 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); | |
3824 | ||
3825 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { | |
f4263c98 PS |
3826 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
3827 | if (!bss_param) | |
3828 | goto nla_put_failure; | |
3829 | ||
9360ffd1 DM |
3830 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3831 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3832 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3833 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3834 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3835 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3836 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3837 | sinfo->bss_param.dtim_period) || | |
3838 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3839 | sinfo->bss_param.beacon_interval)) | |
3840 | goto nla_put_failure; | |
f4263c98 PS |
3841 | |
3842 | nla_nest_end(msg, bss_param); | |
3843 | } | |
319090bf | 3844 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
9360ffd1 DM |
3845 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
3846 | sizeof(struct nl80211_sta_flag_update), | |
3847 | &sinfo->sta_flags)) | |
3848 | goto nla_put_failure; | |
319090bf JB |
3849 | |
3850 | PUT_SINFO(T_OFFSET, t_offset, u64); | |
3851 | PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64); | |
a76b1942 JB |
3852 | PUT_SINFO(BEACON_RX, rx_beacon, u64); |
3853 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); | |
319090bf JB |
3854 | |
3855 | #undef PUT_SINFO | |
6de39808 JB |
3856 | |
3857 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { | |
3858 | struct nlattr *tidsattr; | |
3859 | int tid; | |
3860 | ||
3861 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); | |
3862 | if (!tidsattr) | |
3863 | goto nla_put_failure; | |
3864 | ||
3865 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { | |
3866 | struct cfg80211_tid_stats *tidstats; | |
3867 | struct nlattr *tidattr; | |
3868 | ||
3869 | tidstats = &sinfo->pertid[tid]; | |
3870 | ||
3871 | if (!tidstats->filled) | |
3872 | continue; | |
3873 | ||
3874 | tidattr = nla_nest_start(msg, tid + 1); | |
3875 | if (!tidattr) | |
3876 | goto nla_put_failure; | |
3877 | ||
3878 | #define PUT_TIDVAL(attr, memb, type) do { \ | |
3879 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ | |
3880 | nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \ | |
3881 | tidstats->memb)) \ | |
3882 | goto nla_put_failure; \ | |
3883 | } while (0) | |
3884 | ||
3885 | PUT_TIDVAL(RX_MSDU, rx_msdu, u64); | |
3886 | PUT_TIDVAL(TX_MSDU, tx_msdu, u64); | |
3887 | PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64); | |
3888 | PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64); | |
3889 | ||
3890 | #undef PUT_TIDVAL | |
3891 | nla_nest_end(msg, tidattr); | |
3892 | } | |
3893 | ||
3894 | nla_nest_end(msg, tidsattr); | |
3895 | } | |
3896 | ||
2ec600d6 | 3897 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3898 | |
319090bf | 3899 | if (sinfo->assoc_req_ies_len && |
9360ffd1 DM |
3900 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
3901 | sinfo->assoc_req_ies)) | |
3902 | goto nla_put_failure; | |
50d3dfb7 | 3903 | |
053c095a JB |
3904 | genlmsg_end(msg, hdr); |
3905 | return 0; | |
fd5b74dc JB |
3906 | |
3907 | nla_put_failure: | |
bc3ed28c TG |
3908 | genlmsg_cancel(msg, hdr); |
3909 | return -EMSGSIZE; | |
fd5b74dc JB |
3910 | } |
3911 | ||
2ec600d6 | 3912 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3913 | struct netlink_callback *cb) |
2ec600d6 | 3914 | { |
2ec600d6 | 3915 | struct station_info sinfo; |
1b8ec87a | 3916 | struct cfg80211_registered_device *rdev; |
97990a06 | 3917 | struct wireless_dev *wdev; |
2ec600d6 | 3918 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3919 | int sta_idx = cb->args[2]; |
2ec600d6 | 3920 | int err; |
2ec600d6 | 3921 | |
1b8ec87a | 3922 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
3923 | if (err) |
3924 | return err; | |
bba95fef | 3925 | |
97990a06 JB |
3926 | if (!wdev->netdev) { |
3927 | err = -EINVAL; | |
3928 | goto out_err; | |
3929 | } | |
3930 | ||
1b8ec87a | 3931 | if (!rdev->ops->dump_station) { |
eec60b03 | 3932 | err = -EOPNOTSUPP; |
bba95fef JB |
3933 | goto out_err; |
3934 | } | |
3935 | ||
bba95fef | 3936 | while (1) { |
f612cedf | 3937 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 3938 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
e35e4d28 | 3939 | mac_addr, &sinfo); |
bba95fef JB |
3940 | if (err == -ENOENT) |
3941 | break; | |
3942 | if (err) | |
3b85875a | 3943 | goto out_err; |
bba95fef | 3944 | |
cf5ead82 | 3945 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
15e47304 | 3946 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3947 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 3948 | rdev, wdev->netdev, mac_addr, |
bba95fef JB |
3949 | &sinfo) < 0) |
3950 | goto out; | |
3951 | ||
3952 | sta_idx++; | |
3953 | } | |
3954 | ||
3955 | ||
3956 | out: | |
97990a06 | 3957 | cb->args[2] = sta_idx; |
bba95fef | 3958 | err = skb->len; |
bba95fef | 3959 | out_err: |
1b8ec87a | 3960 | nl80211_finish_wdev_dump(rdev); |
bba95fef JB |
3961 | |
3962 | return err; | |
2ec600d6 | 3963 | } |
fd5b74dc | 3964 | |
5727ef1b JB |
3965 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3966 | { | |
4c476991 JB |
3967 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3968 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3969 | struct station_info sinfo; |
fd5b74dc JB |
3970 | struct sk_buff *msg; |
3971 | u8 *mac_addr = NULL; | |
4c476991 | 3972 | int err; |
fd5b74dc | 3973 | |
2ec600d6 | 3974 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3975 | |
3976 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3977 | return -EINVAL; | |
3978 | ||
3979 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3980 | ||
4c476991 JB |
3981 | if (!rdev->ops->get_station) |
3982 | return -EOPNOTSUPP; | |
3b85875a | 3983 | |
e35e4d28 | 3984 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3985 | if (err) |
4c476991 | 3986 | return err; |
2ec600d6 | 3987 | |
fd2120ca | 3988 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3989 | if (!msg) |
4c476991 | 3990 | return -ENOMEM; |
fd5b74dc | 3991 | |
cf5ead82 JB |
3992 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
3993 | info->snd_portid, info->snd_seq, 0, | |
66266b3a | 3994 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3995 | nlmsg_free(msg); |
3996 | return -ENOBUFS; | |
3997 | } | |
3b85875a | 3998 | |
4c476991 | 3999 | return genlmsg_reply(msg, info); |
5727ef1b JB |
4000 | } |
4001 | ||
77ee7c89 JB |
4002 | int cfg80211_check_station_change(struct wiphy *wiphy, |
4003 | struct station_parameters *params, | |
4004 | enum cfg80211_station_type statype) | |
4005 | { | |
e4208427 AB |
4006 | if (params->listen_interval != -1 && |
4007 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
77ee7c89 | 4008 | return -EINVAL; |
e4208427 | 4009 | |
17b94247 AB |
4010 | if (params->support_p2p_ps != -1 && |
4011 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
4012 | return -EINVAL; | |
4013 | ||
c72e1140 | 4014 | if (params->aid && |
e4208427 AB |
4015 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
4016 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
77ee7c89 JB |
4017 | return -EINVAL; |
4018 | ||
4019 | /* When you run into this, adjust the code below for the new flag */ | |
4020 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4021 | ||
4022 | switch (statype) { | |
eef941e6 TP |
4023 | case CFG80211_STA_MESH_PEER_KERNEL: |
4024 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
4025 | /* |
4026 | * No ignoring the TDLS flag here -- the userspace mesh | |
4027 | * code doesn't have the bug of including TDLS in the | |
4028 | * mask everywhere. | |
4029 | */ | |
4030 | if (params->sta_flags_mask & | |
4031 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4032 | BIT(NL80211_STA_FLAG_MFP) | | |
4033 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
4034 | return -EINVAL; | |
4035 | break; | |
4036 | case CFG80211_STA_TDLS_PEER_SETUP: | |
4037 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
4038 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4039 | return -EINVAL; | |
4040 | /* ignore since it can't change */ | |
4041 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
4042 | break; | |
4043 | default: | |
4044 | /* disallow mesh-specific things */ | |
4045 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
4046 | return -EINVAL; | |
4047 | if (params->local_pm) | |
4048 | return -EINVAL; | |
4049 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
4050 | return -EINVAL; | |
4051 | } | |
4052 | ||
4053 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
4054 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
4055 | /* TDLS can't be set, ... */ | |
4056 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4057 | return -EINVAL; | |
4058 | /* | |
4059 | * ... but don't bother the driver with it. This works around | |
4060 | * a hostapd/wpa_supplicant issue -- it always includes the | |
4061 | * TLDS_PEER flag in the mask even for AP mode. | |
4062 | */ | |
4063 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
4064 | } | |
4065 | ||
47edb11b AB |
4066 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
4067 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { | |
77ee7c89 JB |
4068 | /* reject other things that can't change */ |
4069 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
4070 | return -EINVAL; | |
4071 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
4072 | return -EINVAL; | |
4073 | if (params->supported_rates) | |
4074 | return -EINVAL; | |
4075 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
4076 | return -EINVAL; | |
4077 | } | |
4078 | ||
47edb11b AB |
4079 | if (statype != CFG80211_STA_AP_CLIENT && |
4080 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { | |
77ee7c89 JB |
4081 | if (params->vlan) |
4082 | return -EINVAL; | |
4083 | } | |
4084 | ||
4085 | switch (statype) { | |
4086 | case CFG80211_STA_AP_MLME_CLIENT: | |
4087 | /* Use this only for authorizing/unauthorizing a station */ | |
4088 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
4089 | return -EOPNOTSUPP; | |
4090 | break; | |
4091 | case CFG80211_STA_AP_CLIENT: | |
47edb11b | 4092 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
77ee7c89 JB |
4093 | /* accept only the listed bits */ |
4094 | if (params->sta_flags_mask & | |
4095 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4096 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4097 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4098 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
4099 | BIT(NL80211_STA_FLAG_WME) | | |
4100 | BIT(NL80211_STA_FLAG_MFP))) | |
4101 | return -EINVAL; | |
4102 | ||
4103 | /* but authenticated/associated only if driver handles it */ | |
4104 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4105 | params->sta_flags_mask & | |
4106 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4107 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4108 | return -EINVAL; | |
4109 | break; | |
4110 | case CFG80211_STA_IBSS: | |
4111 | case CFG80211_STA_AP_STA: | |
4112 | /* reject any changes other than AUTHORIZED */ | |
4113 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
4114 | return -EINVAL; | |
4115 | break; | |
4116 | case CFG80211_STA_TDLS_PEER_SETUP: | |
4117 | /* reject any changes other than AUTHORIZED or WME */ | |
4118 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4119 | BIT(NL80211_STA_FLAG_WME))) | |
4120 | return -EINVAL; | |
4121 | /* force (at least) rates when authorizing */ | |
4122 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
4123 | !params->supported_rates) | |
4124 | return -EINVAL; | |
4125 | break; | |
4126 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
4127 | /* reject any changes */ | |
4128 | return -EINVAL; | |
eef941e6 | 4129 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
4130 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
4131 | return -EINVAL; | |
4132 | break; | |
eef941e6 | 4133 | case CFG80211_STA_MESH_PEER_USER: |
42925040 CYY |
4134 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
4135 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) | |
77ee7c89 JB |
4136 | return -EINVAL; |
4137 | break; | |
4138 | } | |
4139 | ||
4140 | return 0; | |
4141 | } | |
4142 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
4143 | ||
5727ef1b | 4144 | /* |
c258d2de | 4145 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 4146 | */ |
80b99899 JB |
4147 | static struct net_device *get_vlan(struct genl_info *info, |
4148 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 4149 | { |
463d0183 | 4150 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
4151 | struct net_device *v; |
4152 | int ret; | |
4153 | ||
4154 | if (!vlanattr) | |
4155 | return NULL; | |
4156 | ||
4157 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
4158 | if (!v) | |
4159 | return ERR_PTR(-ENODEV); | |
4160 | ||
4161 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
4162 | ret = -EINVAL; | |
4163 | goto error; | |
5727ef1b | 4164 | } |
80b99899 | 4165 | |
77ee7c89 JB |
4166 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
4167 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4168 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
4169 | ret = -EINVAL; | |
4170 | goto error; | |
4171 | } | |
4172 | ||
80b99899 JB |
4173 | if (!netif_running(v)) { |
4174 | ret = -ENETDOWN; | |
4175 | goto error; | |
4176 | } | |
4177 | ||
4178 | return v; | |
4179 | error: | |
4180 | dev_put(v); | |
4181 | return ERR_PTR(ret); | |
5727ef1b JB |
4182 | } |
4183 | ||
94e860f1 JB |
4184 | static const struct nla_policy |
4185 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
4186 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
4187 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
4188 | }; | |
4189 | ||
ff276691 JB |
4190 | static int nl80211_parse_sta_wme(struct genl_info *info, |
4191 | struct station_parameters *params) | |
df881293 | 4192 | { |
df881293 JM |
4193 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
4194 | struct nlattr *nla; | |
4195 | int err; | |
4196 | ||
df881293 JM |
4197 | /* parse WME attributes if present */ |
4198 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
4199 | return 0; | |
4200 | ||
4201 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
4202 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
4203 | nl80211_sta_wme_policy); | |
4204 | if (err) | |
4205 | return err; | |
4206 | ||
4207 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
4208 | params->uapsd_queues = nla_get_u8( | |
4209 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4210 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
4211 | return -EINVAL; | |
4212 | ||
4213 | if (tb[NL80211_STA_WME_MAX_SP]) | |
4214 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4215 | ||
4216 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
4217 | return -EINVAL; | |
4218 | ||
4219 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
4220 | ||
4221 | return 0; | |
4222 | } | |
4223 | ||
c01fc9ad SD |
4224 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4225 | struct station_parameters *params) | |
4226 | { | |
4227 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4228 | params->supported_channels = | |
4229 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4230 | params->supported_channels_len = | |
4231 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4232 | /* | |
4233 | * Need to include at least one (first channel, number of | |
4234 | * channels) tuple for each subband, and must have proper | |
4235 | * tuples for the rest of the data as well. | |
4236 | */ | |
4237 | if (params->supported_channels_len < 2) | |
4238 | return -EINVAL; | |
4239 | if (params->supported_channels_len % 2) | |
4240 | return -EINVAL; | |
4241 | } | |
4242 | ||
4243 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4244 | params->supported_oper_classes = | |
4245 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4246 | params->supported_oper_classes_len = | |
4247 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4248 | /* | |
4249 | * The value of the Length field of the Supported Operating | |
4250 | * Classes element is between 2 and 253. | |
4251 | */ | |
4252 | if (params->supported_oper_classes_len < 2 || | |
4253 | params->supported_oper_classes_len > 253) | |
4254 | return -EINVAL; | |
4255 | } | |
4256 | return 0; | |
4257 | } | |
4258 | ||
ff276691 JB |
4259 | static int nl80211_set_station_tdls(struct genl_info *info, |
4260 | struct station_parameters *params) | |
4261 | { | |
c01fc9ad | 4262 | int err; |
ff276691 | 4263 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4264 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4265 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4266 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4267 | params->ht_capa = | |
4268 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4269 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4270 | params->vht_capa = | |
4271 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4272 | ||
c01fc9ad SD |
4273 | err = nl80211_parse_sta_channel_info(info, params); |
4274 | if (err) | |
4275 | return err; | |
4276 | ||
ff276691 JB |
4277 | return nl80211_parse_sta_wme(info, params); |
4278 | } | |
4279 | ||
5727ef1b JB |
4280 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4281 | { | |
4c476991 | 4282 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4283 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4284 | struct station_parameters params; |
77ee7c89 JB |
4285 | u8 *mac_addr; |
4286 | int err; | |
5727ef1b JB |
4287 | |
4288 | memset(¶ms, 0, sizeof(params)); | |
4289 | ||
77ee7c89 JB |
4290 | if (!rdev->ops->change_station) |
4291 | return -EOPNOTSUPP; | |
4292 | ||
e4208427 AB |
4293 | /* |
4294 | * AID and listen_interval properties can be set only for unassociated | |
4295 | * station. Include these parameters here and will check them in | |
4296 | * cfg80211_check_station_change(). | |
4297 | */ | |
a9bc31e4 AB |
4298 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4299 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
e4208427 AB |
4300 | |
4301 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | |
4302 | params.listen_interval = | |
4303 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
4304 | else | |
4305 | params.listen_interval = -1; | |
5727ef1b | 4306 | |
17b94247 AB |
4307 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
4308 | u8 tmp; | |
4309 | ||
4310 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); | |
4311 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) | |
4312 | return -EINVAL; | |
4313 | ||
4314 | params.support_p2p_ps = tmp; | |
4315 | } else { | |
4316 | params.support_p2p_ps = -1; | |
4317 | } | |
4318 | ||
5727ef1b JB |
4319 | if (!info->attrs[NL80211_ATTR_MAC]) |
4320 | return -EINVAL; | |
4321 | ||
4322 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4323 | ||
4324 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4325 | params.supported_rates = | |
4326 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4327 | params.supported_rates_len = | |
4328 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4329 | } | |
4330 | ||
9d62a986 JM |
4331 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4332 | params.capability = | |
4333 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4334 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4335 | } | |
4336 | ||
4337 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4338 | params.ext_capab = | |
4339 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4340 | params.ext_capab_len = | |
4341 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4342 | } | |
4343 | ||
bdd3ae3d | 4344 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4345 | return -EINVAL; |
4346 | ||
f8bacc21 | 4347 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4348 | params.plink_action = |
f8bacc21 JB |
4349 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4350 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4351 | return -EINVAL; | |
4352 | } | |
2ec600d6 | 4353 | |
f8bacc21 | 4354 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4355 | params.plink_state = |
f8bacc21 JB |
4356 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4357 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4358 | return -EINVAL; | |
4359 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
4360 | } | |
9c3990aa | 4361 | |
3b1c5a53 MP |
4362 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4363 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4364 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4365 | ||
4366 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4367 | pm > NL80211_MESH_POWER_MAX) | |
4368 | return -EINVAL; | |
4369 | ||
4370 | params.local_pm = pm; | |
4371 | } | |
4372 | ||
77ee7c89 JB |
4373 | /* Include parameters for TDLS peer (will check later) */ |
4374 | err = nl80211_set_station_tdls(info, ¶ms); | |
4375 | if (err) | |
4376 | return err; | |
4377 | ||
4378 | params.vlan = get_vlan(info, rdev); | |
4379 | if (IS_ERR(params.vlan)) | |
4380 | return PTR_ERR(params.vlan); | |
4381 | ||
a97f4424 JB |
4382 | switch (dev->ieee80211_ptr->iftype) { |
4383 | case NL80211_IFTYPE_AP: | |
4384 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4385 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4386 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4387 | case NL80211_IFTYPE_STATION: |
267335d6 | 4388 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4389 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4390 | break; |
4391 | default: | |
77ee7c89 JB |
4392 | err = -EOPNOTSUPP; |
4393 | goto out_put_vlan; | |
034d655e JB |
4394 | } |
4395 | ||
77ee7c89 | 4396 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4397 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4398 | |
77ee7c89 | 4399 | out_put_vlan: |
5727ef1b JB |
4400 | if (params.vlan) |
4401 | dev_put(params.vlan); | |
3b85875a | 4402 | |
5727ef1b JB |
4403 | return err; |
4404 | } | |
4405 | ||
4406 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4407 | { | |
4c476991 | 4408 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4409 | int err; |
4c476991 | 4410 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4411 | struct station_parameters params; |
4412 | u8 *mac_addr = NULL; | |
bda95eb1 JB |
4413 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
4414 | BIT(NL80211_STA_FLAG_ASSOCIATED); | |
5727ef1b JB |
4415 | |
4416 | memset(¶ms, 0, sizeof(params)); | |
4417 | ||
984c311b JB |
4418 | if (!rdev->ops->add_station) |
4419 | return -EOPNOTSUPP; | |
4420 | ||
5727ef1b JB |
4421 | if (!info->attrs[NL80211_ATTR_MAC]) |
4422 | return -EINVAL; | |
4423 | ||
5727ef1b JB |
4424 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4425 | return -EINVAL; | |
4426 | ||
4427 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4428 | return -EINVAL; | |
4429 | ||
5e4b6f56 JM |
4430 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4431 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4432 | return -EINVAL; |
4433 | ||
5727ef1b JB |
4434 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4435 | params.supported_rates = | |
4436 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4437 | params.supported_rates_len = | |
4438 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4439 | params.listen_interval = | |
4440 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4441 | |
17b94247 AB |
4442 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
4443 | u8 tmp; | |
4444 | ||
4445 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); | |
4446 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) | |
4447 | return -EINVAL; | |
4448 | ||
4449 | params.support_p2p_ps = tmp; | |
4450 | } else { | |
4451 | /* | |
4452 | * if not specified, assume it's supported for P2P GO interface, | |
4453 | * and is NOT supported for AP interface | |
4454 | */ | |
4455 | params.support_p2p_ps = | |
4456 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; | |
4457 | } | |
4458 | ||
3d124ea2 | 4459 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4460 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4461 | else |
4462 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4463 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4464 | return -EINVAL; | |
51b50fbe | 4465 | |
9d62a986 JM |
4466 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4467 | params.capability = | |
4468 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4469 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4470 | } | |
4471 | ||
4472 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4473 | params.ext_capab = | |
4474 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4475 | params.ext_capab_len = | |
4476 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4477 | } | |
4478 | ||
36aedc90 JM |
4479 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4480 | params.ht_capa = | |
4481 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4482 | |
f461be3e MP |
4483 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4484 | params.vht_capa = | |
4485 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4486 | ||
60f4a7b1 MK |
4487 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4488 | params.opmode_notif_used = true; | |
4489 | params.opmode_notif = | |
4490 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4491 | } | |
4492 | ||
f8bacc21 | 4493 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4494 | params.plink_action = |
f8bacc21 JB |
4495 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4496 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4497 | return -EINVAL; | |
4498 | } | |
96b78dff | 4499 | |
c01fc9ad SD |
4500 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4501 | if (err) | |
4502 | return err; | |
4503 | ||
ff276691 JB |
4504 | err = nl80211_parse_sta_wme(info, ¶ms); |
4505 | if (err) | |
4506 | return err; | |
bdd90d5e | 4507 | |
bdd3ae3d | 4508 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4509 | return -EINVAL; |
4510 | ||
496fcc29 JB |
4511 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
4512 | * as userspace might just pass through the capabilities from the IEs | |
4513 | * directly, rather than enforcing this restriction and returning an | |
4514 | * error in this case. | |
4515 | */ | |
4516 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { | |
4517 | params.ht_capa = NULL; | |
4518 | params.vht_capa = NULL; | |
4519 | } | |
4520 | ||
77ee7c89 JB |
4521 | /* When you run into this, adjust the code below for the new flag */ |
4522 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4523 | ||
bdd90d5e JB |
4524 | switch (dev->ieee80211_ptr->iftype) { |
4525 | case NL80211_IFTYPE_AP: | |
4526 | case NL80211_IFTYPE_AP_VLAN: | |
4527 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4528 | /* ignore WME attributes if iface/sta is not capable */ |
4529 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4530 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4531 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4532 | |
bdd90d5e | 4533 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4534 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4535 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4536 | return -EINVAL; |
bdd90d5e JB |
4537 | /* but don't bother the driver with it */ |
4538 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4539 | |
d582cffb JB |
4540 | /* allow authenticated/associated only if driver handles it */ |
4541 | if (!(rdev->wiphy.features & | |
4542 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
bda95eb1 | 4543 | params.sta_flags_mask & auth_assoc) |
d582cffb JB |
4544 | return -EINVAL; |
4545 | ||
bda95eb1 JB |
4546 | /* Older userspace, or userspace wanting to be compatible with |
4547 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth | |
4548 | * and assoc flags in the mask, but assumes the station will be | |
4549 | * added as associated anyway since this was the required driver | |
4550 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was | |
4551 | * introduced. | |
4552 | * In order to not bother drivers with this quirk in the API | |
4553 | * set the flags in both the mask and set for new stations in | |
4554 | * this case. | |
4555 | */ | |
4556 | if (!(params.sta_flags_mask & auth_assoc)) { | |
4557 | params.sta_flags_mask |= auth_assoc; | |
4558 | params.sta_flags_set |= auth_assoc; | |
4559 | } | |
4560 | ||
bdd90d5e JB |
4561 | /* must be last in here for error handling */ |
4562 | params.vlan = get_vlan(info, rdev); | |
4563 | if (IS_ERR(params.vlan)) | |
4564 | return PTR_ERR(params.vlan); | |
4565 | break; | |
4566 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4567 | /* ignore uAPSD data */ |
4568 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4569 | ||
d582cffb JB |
4570 | /* associated is disallowed */ |
4571 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4572 | return -EINVAL; | |
bdd90d5e | 4573 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4574 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4575 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4576 | return -EINVAL; |
4577 | break; | |
4578 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4579 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4580 | /* ignore uAPSD data */ |
4581 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4582 | ||
77ee7c89 JB |
4583 | /* these are disallowed */ |
4584 | if (params.sta_flags_mask & | |
4585 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4586 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4587 | return -EINVAL; |
bdd90d5e JB |
4588 | /* Only TDLS peers can be added */ |
4589 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4590 | return -EINVAL; | |
4591 | /* Can only add if TDLS ... */ | |
4592 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4593 | return -EOPNOTSUPP; | |
4594 | /* ... with external setup is supported */ | |
4595 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4596 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4597 | /* |
4598 | * Older wpa_supplicant versions always mark the TDLS peer | |
4599 | * as authorized, but it shouldn't yet be. | |
4600 | */ | |
4601 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4602 | break; |
4603 | default: | |
4604 | return -EOPNOTSUPP; | |
c75786c9 EP |
4605 | } |
4606 | ||
bdd90d5e | 4607 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4608 | |
e35e4d28 | 4609 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4610 | |
5727ef1b JB |
4611 | if (params.vlan) |
4612 | dev_put(params.vlan); | |
5727ef1b JB |
4613 | return err; |
4614 | } | |
4615 | ||
4616 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4617 | { | |
4c476991 JB |
4618 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4619 | struct net_device *dev = info->user_ptr[1]; | |
89c771e5 JM |
4620 | struct station_del_parameters params; |
4621 | ||
4622 | memset(¶ms, 0, sizeof(params)); | |
5727ef1b JB |
4623 | |
4624 | if (info->attrs[NL80211_ATTR_MAC]) | |
89c771e5 | 4625 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5727ef1b | 4626 | |
e80cf853 | 4627 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4628 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4629 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4630 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4631 | return -EINVAL; | |
5727ef1b | 4632 | |
4c476991 JB |
4633 | if (!rdev->ops->del_station) |
4634 | return -EOPNOTSUPP; | |
3b85875a | 4635 | |
98856866 JM |
4636 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
4637 | params.subtype = | |
4638 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | |
4639 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | |
4640 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | |
4641 | return -EINVAL; | |
4642 | } else { | |
4643 | /* Default to Deauthentication frame */ | |
4644 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | |
4645 | } | |
4646 | ||
4647 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | |
4648 | params.reason_code = | |
4649 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
4650 | if (params.reason_code == 0) | |
4651 | return -EINVAL; /* 0 is reserved */ | |
4652 | } else { | |
4653 | /* Default to reason code 2 */ | |
4654 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | |
4655 | } | |
4656 | ||
89c771e5 | 4657 | return rdev_del_station(rdev, dev, ¶ms); |
5727ef1b JB |
4658 | } |
4659 | ||
15e47304 | 4660 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4661 | int flags, struct net_device *dev, |
4662 | u8 *dst, u8 *next_hop, | |
4663 | struct mpath_info *pinfo) | |
4664 | { | |
4665 | void *hdr; | |
4666 | struct nlattr *pinfoattr; | |
4667 | ||
1ef4c850 | 4668 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
2ec600d6 LCC |
4669 | if (!hdr) |
4670 | return -1; | |
4671 | ||
9360ffd1 DM |
4672 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4673 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4674 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4675 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4676 | goto nla_put_failure; | |
f5ea9120 | 4677 | |
2ec600d6 LCC |
4678 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4679 | if (!pinfoattr) | |
4680 | goto nla_put_failure; | |
9360ffd1 DM |
4681 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4682 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4683 | pinfo->frame_qlen)) | |
4684 | goto nla_put_failure; | |
4685 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4686 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4687 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4688 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4689 | pinfo->metric)) || | |
4690 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4691 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4692 | pinfo->exptime)) || | |
4693 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4694 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4695 | pinfo->flags)) || | |
4696 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4697 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4698 | pinfo->discovery_timeout)) || | |
4699 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4700 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4701 | pinfo->discovery_retries))) | |
4702 | goto nla_put_failure; | |
2ec600d6 LCC |
4703 | |
4704 | nla_nest_end(msg, pinfoattr); | |
4705 | ||
053c095a JB |
4706 | genlmsg_end(msg, hdr); |
4707 | return 0; | |
2ec600d6 LCC |
4708 | |
4709 | nla_put_failure: | |
bc3ed28c TG |
4710 | genlmsg_cancel(msg, hdr); |
4711 | return -EMSGSIZE; | |
2ec600d6 LCC |
4712 | } |
4713 | ||
4714 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4715 | struct netlink_callback *cb) |
2ec600d6 | 4716 | { |
2ec600d6 | 4717 | struct mpath_info pinfo; |
1b8ec87a | 4718 | struct cfg80211_registered_device *rdev; |
97990a06 | 4719 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4720 | u8 dst[ETH_ALEN]; |
4721 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4722 | int path_idx = cb->args[2]; |
2ec600d6 | 4723 | int err; |
2ec600d6 | 4724 | |
1b8ec87a | 4725 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
4726 | if (err) |
4727 | return err; | |
bba95fef | 4728 | |
1b8ec87a | 4729 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 4730 | err = -EOPNOTSUPP; |
bba95fef JB |
4731 | goto out_err; |
4732 | } | |
4733 | ||
97990a06 | 4734 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4735 | err = -EOPNOTSUPP; |
0448b5fc | 4736 | goto out_err; |
eec60b03 JM |
4737 | } |
4738 | ||
bba95fef | 4739 | while (1) { |
1b8ec87a | 4740 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 4741 | next_hop, &pinfo); |
bba95fef | 4742 | if (err == -ENOENT) |
2ec600d6 | 4743 | break; |
bba95fef | 4744 | if (err) |
3b85875a | 4745 | goto out_err; |
2ec600d6 | 4746 | |
15e47304 | 4747 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4748 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4749 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4750 | &pinfo) < 0) |
4751 | goto out; | |
2ec600d6 | 4752 | |
bba95fef | 4753 | path_idx++; |
2ec600d6 | 4754 | } |
2ec600d6 | 4755 | |
2ec600d6 | 4756 | |
bba95fef | 4757 | out: |
97990a06 | 4758 | cb->args[2] = path_idx; |
bba95fef | 4759 | err = skb->len; |
bba95fef | 4760 | out_err: |
1b8ec87a | 4761 | nl80211_finish_wdev_dump(rdev); |
bba95fef | 4762 | return err; |
2ec600d6 LCC |
4763 | } |
4764 | ||
4765 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4766 | { | |
4c476991 | 4767 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4768 | int err; |
4c476991 | 4769 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4770 | struct mpath_info pinfo; |
4771 | struct sk_buff *msg; | |
4772 | u8 *dst = NULL; | |
4773 | u8 next_hop[ETH_ALEN]; | |
4774 | ||
4775 | memset(&pinfo, 0, sizeof(pinfo)); | |
4776 | ||
4777 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4778 | return -EINVAL; | |
4779 | ||
4780 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4781 | ||
4c476991 JB |
4782 | if (!rdev->ops->get_mpath) |
4783 | return -EOPNOTSUPP; | |
2ec600d6 | 4784 | |
4c476991 JB |
4785 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4786 | return -EOPNOTSUPP; | |
eec60b03 | 4787 | |
e35e4d28 | 4788 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4789 | if (err) |
4c476991 | 4790 | return err; |
2ec600d6 | 4791 | |
fd2120ca | 4792 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4793 | if (!msg) |
4c476991 | 4794 | return -ENOMEM; |
2ec600d6 | 4795 | |
15e47304 | 4796 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4797 | dev, dst, next_hop, &pinfo) < 0) { |
4798 | nlmsg_free(msg); | |
4799 | return -ENOBUFS; | |
4800 | } | |
3b85875a | 4801 | |
4c476991 | 4802 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4803 | } |
4804 | ||
4805 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4806 | { | |
4c476991 JB |
4807 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4808 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4809 | u8 *dst = NULL; |
4810 | u8 *next_hop = NULL; | |
4811 | ||
4812 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4813 | return -EINVAL; | |
4814 | ||
4815 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4816 | return -EINVAL; | |
4817 | ||
4818 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4819 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4820 | ||
4c476991 JB |
4821 | if (!rdev->ops->change_mpath) |
4822 | return -EOPNOTSUPP; | |
35a8efe1 | 4823 | |
4c476991 JB |
4824 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4825 | return -EOPNOTSUPP; | |
2ec600d6 | 4826 | |
e35e4d28 | 4827 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4828 | } |
4c476991 | 4829 | |
2ec600d6 LCC |
4830 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4831 | { | |
4c476991 JB |
4832 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4833 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4834 | u8 *dst = NULL; |
4835 | u8 *next_hop = NULL; | |
4836 | ||
4837 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4838 | return -EINVAL; | |
4839 | ||
4840 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4841 | return -EINVAL; | |
4842 | ||
4843 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4844 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4845 | ||
4c476991 JB |
4846 | if (!rdev->ops->add_mpath) |
4847 | return -EOPNOTSUPP; | |
35a8efe1 | 4848 | |
4c476991 JB |
4849 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4850 | return -EOPNOTSUPP; | |
2ec600d6 | 4851 | |
e35e4d28 | 4852 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4853 | } |
4854 | ||
4855 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4856 | { | |
4c476991 JB |
4857 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4858 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4859 | u8 *dst = NULL; |
4860 | ||
4861 | if (info->attrs[NL80211_ATTR_MAC]) | |
4862 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4863 | ||
4c476991 JB |
4864 | if (!rdev->ops->del_mpath) |
4865 | return -EOPNOTSUPP; | |
3b85875a | 4866 | |
e35e4d28 | 4867 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4868 | } |
4869 | ||
66be7d2b HR |
4870 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
4871 | { | |
4872 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4873 | int err; | |
4874 | struct net_device *dev = info->user_ptr[1]; | |
4875 | struct mpath_info pinfo; | |
4876 | struct sk_buff *msg; | |
4877 | u8 *dst = NULL; | |
4878 | u8 mpp[ETH_ALEN]; | |
4879 | ||
4880 | memset(&pinfo, 0, sizeof(pinfo)); | |
4881 | ||
4882 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4883 | return -EINVAL; | |
4884 | ||
4885 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4886 | ||
4887 | if (!rdev->ops->get_mpp) | |
4888 | return -EOPNOTSUPP; | |
4889 | ||
4890 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
4891 | return -EOPNOTSUPP; | |
4892 | ||
4893 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | |
4894 | if (err) | |
4895 | return err; | |
4896 | ||
4897 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4898 | if (!msg) | |
4899 | return -ENOMEM; | |
4900 | ||
4901 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | |
4902 | dev, dst, mpp, &pinfo) < 0) { | |
4903 | nlmsg_free(msg); | |
4904 | return -ENOBUFS; | |
4905 | } | |
4906 | ||
4907 | return genlmsg_reply(msg, info); | |
4908 | } | |
4909 | ||
4910 | static int nl80211_dump_mpp(struct sk_buff *skb, | |
4911 | struct netlink_callback *cb) | |
4912 | { | |
4913 | struct mpath_info pinfo; | |
4914 | struct cfg80211_registered_device *rdev; | |
4915 | struct wireless_dev *wdev; | |
4916 | u8 dst[ETH_ALEN]; | |
4917 | u8 mpp[ETH_ALEN]; | |
4918 | int path_idx = cb->args[2]; | |
4919 | int err; | |
4920 | ||
4921 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | |
4922 | if (err) | |
4923 | return err; | |
4924 | ||
4925 | if (!rdev->ops->dump_mpp) { | |
4926 | err = -EOPNOTSUPP; | |
4927 | goto out_err; | |
4928 | } | |
4929 | ||
4930 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | |
4931 | err = -EOPNOTSUPP; | |
4932 | goto out_err; | |
4933 | } | |
4934 | ||
4935 | while (1) { | |
4936 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | |
4937 | mpp, &pinfo); | |
4938 | if (err == -ENOENT) | |
4939 | break; | |
4940 | if (err) | |
4941 | goto out_err; | |
4942 | ||
4943 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | |
4944 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
4945 | wdev->netdev, dst, mpp, | |
4946 | &pinfo) < 0) | |
4947 | goto out; | |
4948 | ||
4949 | path_idx++; | |
4950 | } | |
4951 | ||
4952 | out: | |
4953 | cb->args[2] = path_idx; | |
4954 | err = skb->len; | |
4955 | out_err: | |
4956 | nl80211_finish_wdev_dump(rdev); | |
4957 | return err; | |
4958 | } | |
4959 | ||
9f1ba906 JM |
4960 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4961 | { | |
4c476991 JB |
4962 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4963 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 4964 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 4965 | struct bss_parameters params; |
c56589ed | 4966 | int err; |
9f1ba906 JM |
4967 | |
4968 | memset(¶ms, 0, sizeof(params)); | |
4969 | /* default to not changing parameters */ | |
4970 | params.use_cts_prot = -1; | |
4971 | params.use_short_preamble = -1; | |
4972 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4973 | params.ap_isolate = -1; |
50b12f59 | 4974 | params.ht_opmode = -1; |
53cabad7 JB |
4975 | params.p2p_ctwindow = -1; |
4976 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4977 | |
4978 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4979 | params.use_cts_prot = | |
4980 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4981 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4982 | params.use_short_preamble = | |
4983 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4984 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4985 | params.use_short_slot_time = | |
4986 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4987 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4988 | params.basic_rates = | |
4989 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4990 | params.basic_rates_len = | |
4991 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4992 | } | |
fd8aaaf3 FF |
4993 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4994 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4995 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4996 | params.ht_opmode = | |
4997 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4998 | |
53cabad7 JB |
4999 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
5000 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
5001 | return -EINVAL; | |
5002 | params.p2p_ctwindow = | |
5003 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
5004 | if (params.p2p_ctwindow < 0) | |
5005 | return -EINVAL; | |
5006 | if (params.p2p_ctwindow != 0 && | |
5007 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
5008 | return -EINVAL; | |
5009 | } | |
5010 | ||
5011 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
5012 | u8 tmp; | |
5013 | ||
5014 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
5015 | return -EINVAL; | |
5016 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
5017 | if (tmp > 1) | |
5018 | return -EINVAL; | |
5019 | params.p2p_opp_ps = tmp; | |
5020 | if (params.p2p_opp_ps && | |
5021 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
5022 | return -EINVAL; | |
5023 | } | |
5024 | ||
4c476991 JB |
5025 | if (!rdev->ops->change_bss) |
5026 | return -EOPNOTSUPP; | |
9f1ba906 | 5027 | |
074ac8df | 5028 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
5029 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
5030 | return -EOPNOTSUPP; | |
3b85875a | 5031 | |
c56589ed SW |
5032 | wdev_lock(wdev); |
5033 | err = rdev_change_bss(rdev, dev, ¶ms); | |
5034 | wdev_unlock(wdev); | |
5035 | ||
5036 | return err; | |
9f1ba906 JM |
5037 | } |
5038 | ||
b2e1b302 LR |
5039 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
5040 | { | |
b2e1b302 | 5041 | char *data = NULL; |
05050753 | 5042 | bool is_indoor; |
57b5ce07 | 5043 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
05050753 I |
5044 | u32 owner_nlportid; |
5045 | ||
b2e1b302 | 5046 | |
80778f18 LR |
5047 | /* |
5048 | * You should only get this when cfg80211 hasn't yet initialized | |
5049 | * completely when built-in to the kernel right between the time | |
5050 | * window between nl80211_init() and regulatory_init(), if that is | |
5051 | * even possible. | |
5052 | */ | |
458f4f9e | 5053 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 5054 | return -EINPROGRESS; |
80778f18 | 5055 | |
57b5ce07 LR |
5056 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
5057 | user_reg_hint_type = | |
5058 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
5059 | else | |
5060 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
5061 | ||
5062 | switch (user_reg_hint_type) { | |
5063 | case NL80211_USER_REG_HINT_USER: | |
5064 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
5065 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
5066 | return -EINVAL; | |
5067 | ||
5068 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5069 | return regulatory_hint_user(data, user_reg_hint_type); | |
5070 | case NL80211_USER_REG_HINT_INDOOR: | |
05050753 I |
5071 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
5072 | owner_nlportid = info->snd_portid; | |
5073 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; | |
5074 | } else { | |
5075 | owner_nlportid = 0; | |
5076 | is_indoor = true; | |
5077 | } | |
5078 | ||
5079 | return regulatory_hint_indoor(is_indoor, owner_nlportid); | |
57b5ce07 LR |
5080 | default: |
5081 | return -EINVAL; | |
5082 | } | |
b2e1b302 LR |
5083 | } |
5084 | ||
24bdd9f4 | 5085 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 5086 | struct genl_info *info) |
93da9cc1 | 5087 | { |
4c476991 | 5088 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 5089 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
5090 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5091 | struct mesh_config cur_params; | |
5092 | int err = 0; | |
93da9cc1 | 5093 | void *hdr; |
5094 | struct nlattr *pinfoattr; | |
5095 | struct sk_buff *msg; | |
5096 | ||
29cbe68c JB |
5097 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5098 | return -EOPNOTSUPP; | |
5099 | ||
24bdd9f4 | 5100 | if (!rdev->ops->get_mesh_config) |
4c476991 | 5101 | return -EOPNOTSUPP; |
f3f92586 | 5102 | |
29cbe68c JB |
5103 | wdev_lock(wdev); |
5104 | /* If not connected, get default parameters */ | |
5105 | if (!wdev->mesh_id_len) | |
5106 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
5107 | else | |
e35e4d28 | 5108 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
5109 | wdev_unlock(wdev); |
5110 | ||
93da9cc1 | 5111 | if (err) |
4c476991 | 5112 | return err; |
93da9cc1 | 5113 | |
5114 | /* Draw up a netlink message to send back */ | |
fd2120ca | 5115 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
5116 | if (!msg) |
5117 | return -ENOMEM; | |
15e47304 | 5118 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 5119 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 5120 | if (!hdr) |
efe1cf0c | 5121 | goto out; |
24bdd9f4 | 5122 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 5123 | if (!pinfoattr) |
5124 | goto nla_put_failure; | |
9360ffd1 DM |
5125 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5126 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
5127 | cur_params.dot11MeshRetryTimeout) || | |
5128 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
5129 | cur_params.dot11MeshConfirmTimeout) || | |
5130 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
5131 | cur_params.dot11MeshHoldingTimeout) || | |
5132 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
5133 | cur_params.dot11MeshMaxPeerLinks) || | |
5134 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
5135 | cur_params.dot11MeshMaxRetries) || | |
5136 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
5137 | cur_params.dot11MeshTTL) || | |
5138 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
5139 | cur_params.element_ttl) || | |
5140 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
5141 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
5142 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5143 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
5144 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5145 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
5146 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
5147 | cur_params.path_refresh_time) || | |
5148 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
5149 | cur_params.min_discovery_timeout) || | |
5150 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
5151 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
5152 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
5153 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
5154 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
5155 | cur_params.dot11MeshHWMPperrMinInterval) || | |
5156 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
5157 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
5158 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5159 | cur_params.dot11MeshHWMPRootMode) || | |
5160 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
5161 | cur_params.dot11MeshHWMPRannInterval) || | |
5162 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
5163 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
5164 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
5165 | cur_params.dot11MeshForwarding) || | |
5166 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
5167 | cur_params.rssi_threshold) || |
5168 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
5169 | cur_params.ht_opmode) || |
5170 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
5171 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
5172 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
5173 | cur_params.dot11MeshHWMProotInterval) || |
5174 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
5175 | cur_params.dot11MeshHWMPconfirmationInterval) || |
5176 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
5177 | cur_params.power_mode) || | |
5178 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
5179 | cur_params.dot11MeshAwakeWindowDuration) || |
5180 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5181 | cur_params.plink_timeout)) | |
9360ffd1 | 5182 | goto nla_put_failure; |
93da9cc1 | 5183 | nla_nest_end(msg, pinfoattr); |
5184 | genlmsg_end(msg, hdr); | |
4c476991 | 5185 | return genlmsg_reply(msg, info); |
93da9cc1 | 5186 | |
3b85875a | 5187 | nla_put_failure: |
93da9cc1 | 5188 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 5189 | out: |
d080e275 | 5190 | nlmsg_free(msg); |
4c476991 | 5191 | return -ENOBUFS; |
93da9cc1 | 5192 | } |
5193 | ||
b54452b0 | 5194 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 5195 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
5196 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
5197 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
5198 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
5199 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
5200 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 5201 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 5202 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 5203 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 5204 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
5205 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
5206 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
5207 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
5208 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 5209 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 5210 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 5211 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 5212 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 5213 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 5214 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
5215 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
5216 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
5217 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
5218 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 5219 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
5220 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
5221 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 5222 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 5223 | }; |
5224 | ||
c80d545d JC |
5225 | static const struct nla_policy |
5226 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 5227 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
5228 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
5229 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 5230 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 5231 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 5232 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 5233 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 5234 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 5235 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
5236 | }; |
5237 | ||
24bdd9f4 | 5238 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
5239 | struct mesh_config *cfg, |
5240 | u32 *mask_out) | |
93da9cc1 | 5241 | { |
93da9cc1 | 5242 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 5243 | u32 mask = 0; |
93da9cc1 | 5244 | |
ea54fba2 MP |
5245 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
5246 | do { \ | |
5247 | if (tb[attr]) { \ | |
5248 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
5249 | return -EINVAL; \ | |
5250 | cfg->param = fn(tb[attr]); \ | |
5251 | mask |= (1 << (attr - 1)); \ | |
5252 | } \ | |
5253 | } while (0) | |
bd90fdcc JB |
5254 | |
5255 | ||
24bdd9f4 | 5256 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 5257 | return -EINVAL; |
5258 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 5259 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 5260 | nl80211_meshconf_params_policy)) |
93da9cc1 | 5261 | return -EINVAL; |
5262 | ||
93da9cc1 | 5263 | /* This makes sure that there aren't more than 32 mesh config |
5264 | * parameters (otherwise our bitfield scheme would not work.) */ | |
5265 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
5266 | ||
5267 | /* Fill in the params struct */ | |
ea54fba2 | 5268 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
5269 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
5270 | nla_get_u16); | |
ea54fba2 | 5271 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
5272 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
5273 | nla_get_u16); | |
ea54fba2 | 5274 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
5275 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
5276 | nla_get_u16); | |
ea54fba2 | 5277 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
5278 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
5279 | nla_get_u16); | |
ea54fba2 | 5280 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
5281 | mask, NL80211_MESHCONF_MAX_RETRIES, |
5282 | nla_get_u8); | |
ea54fba2 | 5283 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 5284 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 5285 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
5286 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
5287 | nla_get_u8); | |
ea54fba2 | 5288 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
5289 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
5290 | nla_get_u8); | |
ea54fba2 MP |
5291 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
5292 | 1, 255, mask, | |
a4f606ea CYY |
5293 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5294 | nla_get_u32); | |
ea54fba2 | 5295 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
5296 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5297 | nla_get_u8); | |
ea54fba2 | 5298 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
5299 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
5300 | nla_get_u32); | |
ea54fba2 | 5301 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
5302 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
5303 | nla_get_u16); | |
ea54fba2 MP |
5304 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
5305 | 1, 65535, mask, | |
a4f606ea CYY |
5306 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
5307 | nla_get_u32); | |
93da9cc1 | 5308 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
5309 | 1, 65535, mask, |
5310 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 5311 | nla_get_u16); |
dca7e943 | 5312 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
5313 | 1, 65535, mask, |
5314 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 5315 | nla_get_u16); |
93da9cc1 | 5316 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5317 | dot11MeshHWMPnetDiameterTraversalTime, |
5318 | 1, 65535, mask, | |
a4f606ea CYY |
5319 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
5320 | nla_get_u16); | |
ea54fba2 MP |
5321 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
5322 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5323 | nla_get_u8); | |
5324 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
5325 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 5326 | nla_get_u16); |
63c5723b | 5327 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5328 | dot11MeshGateAnnouncementProtocol, 0, 1, |
5329 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 5330 | nla_get_u8); |
ea54fba2 | 5331 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
5332 | mask, NL80211_MESHCONF_FORWARDING, |
5333 | nla_get_u8); | |
83374fe9 | 5334 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 5335 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
83374fe9 | 5336 | nla_get_s32); |
ea54fba2 | 5337 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 5338 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
5339 | nla_get_u16); |
5340 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 5341 | 1, 65535, mask, |
ac1073a6 CYY |
5342 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
5343 | nla_get_u32); | |
ea54fba2 | 5344 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 5345 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
5346 | nla_get_u16); |
5347 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
5348 | dot11MeshHWMPconfirmationInterval, |
5349 | 1, 65535, mask, | |
728b19e5 | 5350 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 5351 | nla_get_u16); |
3b1c5a53 MP |
5352 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
5353 | NL80211_MESH_POWER_ACTIVE, | |
5354 | NL80211_MESH_POWER_MAX, | |
5355 | mask, NL80211_MESHCONF_POWER_MODE, | |
5356 | nla_get_u32); | |
5357 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
5358 | 0, 65535, mask, | |
5359 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
31f909a2 | 5360 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
8e7c0538 CT |
5361 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
5362 | nla_get_u32); | |
bd90fdcc JB |
5363 | if (mask_out) |
5364 | *mask_out = mask; | |
c80d545d | 5365 | |
bd90fdcc JB |
5366 | return 0; |
5367 | ||
5368 | #undef FILL_IN_MESH_PARAM_IF_SET | |
5369 | } | |
5370 | ||
c80d545d JC |
5371 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
5372 | struct mesh_setup *setup) | |
5373 | { | |
bb2798d4 | 5374 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
5375 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
5376 | ||
5377 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
5378 | return -EINVAL; | |
5379 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
5380 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
5381 | nl80211_mesh_setup_params_policy)) | |
5382 | return -EINVAL; | |
5383 | ||
d299a1f2 JC |
5384 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
5385 | setup->sync_method = | |
5386 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
5387 | IEEE80211_SYNC_METHOD_VENDOR : | |
5388 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
5389 | ||
c80d545d JC |
5390 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
5391 | setup->path_sel_proto = | |
5392 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5393 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5394 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5395 | ||
5396 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5397 | setup->path_metric = | |
5398 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5399 | IEEE80211_PATH_METRIC_VENDOR : | |
5400 | IEEE80211_PATH_METRIC_AIRTIME; | |
5401 | ||
581a8b0f JC |
5402 | |
5403 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 5404 | struct nlattr *ieattr = |
581a8b0f | 5405 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5406 | if (!is_valid_ie_attr(ieattr)) |
5407 | return -EINVAL; | |
581a8b0f JC |
5408 | setup->ie = nla_data(ieattr); |
5409 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5410 | } |
bb2798d4 TP |
5411 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5412 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5413 | return -EINVAL; | |
5414 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5415 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5416 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5417 | if (setup->is_secure) |
5418 | setup->user_mpm = true; | |
c80d545d | 5419 | |
6e16d90b CT |
5420 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5421 | if (!setup->user_mpm) | |
5422 | return -EINVAL; | |
5423 | setup->auth_id = | |
5424 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5425 | } | |
5426 | ||
c80d545d JC |
5427 | return 0; |
5428 | } | |
5429 | ||
24bdd9f4 | 5430 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5431 | struct genl_info *info) |
bd90fdcc JB |
5432 | { |
5433 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5434 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5435 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5436 | struct mesh_config cfg; |
5437 | u32 mask; | |
5438 | int err; | |
5439 | ||
29cbe68c JB |
5440 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5441 | return -EOPNOTSUPP; | |
5442 | ||
24bdd9f4 | 5443 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5444 | return -EOPNOTSUPP; |
5445 | ||
24bdd9f4 | 5446 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5447 | if (err) |
5448 | return err; | |
5449 | ||
29cbe68c JB |
5450 | wdev_lock(wdev); |
5451 | if (!wdev->mesh_id_len) | |
5452 | err = -ENOLINK; | |
5453 | ||
5454 | if (!err) | |
e35e4d28 | 5455 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5456 | |
5457 | wdev_unlock(wdev); | |
5458 | ||
5459 | return err; | |
93da9cc1 | 5460 | } |
5461 | ||
ad30ca2c AN |
5462 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
5463 | struct sk_buff *msg) | |
f130347c | 5464 | { |
f130347c LR |
5465 | struct nlattr *nl_reg_rules; |
5466 | unsigned int i; | |
f130347c | 5467 | |
458f4f9e JB |
5468 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
5469 | (regdom->dfs_region && | |
5470 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
ad30ca2c | 5471 | goto nla_put_failure; |
458f4f9e | 5472 | |
f130347c LR |
5473 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5474 | if (!nl_reg_rules) | |
ad30ca2c | 5475 | goto nla_put_failure; |
f130347c | 5476 | |
458f4f9e | 5477 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5478 | struct nlattr *nl_reg_rule; |
5479 | const struct ieee80211_reg_rule *reg_rule; | |
5480 | const struct ieee80211_freq_range *freq_range; | |
5481 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 5482 | unsigned int max_bandwidth_khz; |
f130347c | 5483 | |
458f4f9e | 5484 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5485 | freq_range = ®_rule->freq_range; |
5486 | power_rule = ®_rule->power_rule; | |
5487 | ||
5488 | nl_reg_rule = nla_nest_start(msg, i); | |
5489 | if (!nl_reg_rule) | |
ad30ca2c | 5490 | goto nla_put_failure; |
f130347c | 5491 | |
97524820 JD |
5492 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
5493 | if (!max_bandwidth_khz) | |
5494 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
5495 | reg_rule); | |
5496 | ||
9360ffd1 DM |
5497 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5498 | reg_rule->flags) || | |
5499 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5500 | freq_range->start_freq_khz) || | |
5501 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5502 | freq_range->end_freq_khz) || | |
5503 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 5504 | max_bandwidth_khz) || |
9360ffd1 DM |
5505 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
5506 | power_rule->max_antenna_gain) || | |
5507 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
5508 | power_rule->max_eirp) || |
5509 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
5510 | reg_rule->dfs_cac_ms)) | |
ad30ca2c | 5511 | goto nla_put_failure; |
f130347c LR |
5512 | |
5513 | nla_nest_end(msg, nl_reg_rule); | |
5514 | } | |
5515 | ||
5516 | nla_nest_end(msg, nl_reg_rules); | |
ad30ca2c AN |
5517 | return 0; |
5518 | ||
5519 | nla_put_failure: | |
5520 | return -EMSGSIZE; | |
5521 | } | |
5522 | ||
5523 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) | |
5524 | { | |
5525 | const struct ieee80211_regdomain *regdom = NULL; | |
5526 | struct cfg80211_registered_device *rdev; | |
5527 | struct wiphy *wiphy = NULL; | |
5528 | struct sk_buff *msg; | |
5529 | void *hdr; | |
5530 | ||
5531 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5532 | if (!msg) | |
5533 | return -ENOBUFS; | |
5534 | ||
5535 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
5536 | NL80211_CMD_GET_REG); | |
5537 | if (!hdr) | |
5538 | goto put_failure; | |
5539 | ||
5540 | if (info->attrs[NL80211_ATTR_WIPHY]) { | |
1bdd716c AN |
5541 | bool self_managed; |
5542 | ||
ad30ca2c AN |
5543 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
5544 | if (IS_ERR(rdev)) { | |
5545 | nlmsg_free(msg); | |
5546 | return PTR_ERR(rdev); | |
5547 | } | |
5548 | ||
5549 | wiphy = &rdev->wiphy; | |
1bdd716c AN |
5550 | self_managed = wiphy->regulatory_flags & |
5551 | REGULATORY_WIPHY_SELF_MANAGED; | |
ad30ca2c AN |
5552 | regdom = get_wiphy_regdom(wiphy); |
5553 | ||
1bdd716c AN |
5554 | /* a self-managed-reg device must have a private regdom */ |
5555 | if (WARN_ON(!regdom && self_managed)) { | |
5556 | nlmsg_free(msg); | |
5557 | return -EINVAL; | |
5558 | } | |
5559 | ||
ad30ca2c AN |
5560 | if (regdom && |
5561 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5562 | goto nla_put_failure; | |
5563 | } | |
5564 | ||
5565 | if (!wiphy && reg_last_request_cell_base() && | |
5566 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5567 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5568 | goto nla_put_failure; | |
5569 | ||
5570 | rcu_read_lock(); | |
5571 | ||
5572 | if (!regdom) | |
5573 | regdom = rcu_dereference(cfg80211_regdomain); | |
5574 | ||
5575 | if (nl80211_put_regdom(regdom, msg)) | |
5576 | goto nla_put_failure_rcu; | |
5577 | ||
5578 | rcu_read_unlock(); | |
f130347c LR |
5579 | |
5580 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5581 | return genlmsg_reply(msg, info); |
f130347c | 5582 | |
458f4f9e JB |
5583 | nla_put_failure_rcu: |
5584 | rcu_read_unlock(); | |
f130347c LR |
5585 | nla_put_failure: |
5586 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5587 | put_failure: |
d080e275 | 5588 | nlmsg_free(msg); |
5fe231e8 | 5589 | return -EMSGSIZE; |
f130347c LR |
5590 | } |
5591 | ||
ad30ca2c AN |
5592 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
5593 | u32 seq, int flags, struct wiphy *wiphy, | |
5594 | const struct ieee80211_regdomain *regdom) | |
5595 | { | |
5596 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | |
5597 | NL80211_CMD_GET_REG); | |
5598 | ||
5599 | if (!hdr) | |
5600 | return -1; | |
5601 | ||
5602 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); | |
5603 | ||
5604 | if (nl80211_put_regdom(regdom, msg)) | |
5605 | goto nla_put_failure; | |
5606 | ||
5607 | if (!wiphy && reg_last_request_cell_base() && | |
5608 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5609 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5610 | goto nla_put_failure; | |
5611 | ||
5612 | if (wiphy && | |
5613 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5614 | goto nla_put_failure; | |
5615 | ||
1bdd716c AN |
5616 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
5617 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
5618 | goto nla_put_failure; | |
5619 | ||
053c095a JB |
5620 | genlmsg_end(msg, hdr); |
5621 | return 0; | |
ad30ca2c AN |
5622 | |
5623 | nla_put_failure: | |
5624 | genlmsg_cancel(msg, hdr); | |
5625 | return -EMSGSIZE; | |
5626 | } | |
5627 | ||
5628 | static int nl80211_get_reg_dump(struct sk_buff *skb, | |
5629 | struct netlink_callback *cb) | |
5630 | { | |
5631 | const struct ieee80211_regdomain *regdom = NULL; | |
5632 | struct cfg80211_registered_device *rdev; | |
5633 | int err, reg_idx, start = cb->args[2]; | |
5634 | ||
5635 | rtnl_lock(); | |
5636 | ||
5637 | if (cfg80211_regdomain && start == 0) { | |
5638 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5639 | NLM_F_MULTI, NULL, | |
5640 | rtnl_dereference(cfg80211_regdomain)); | |
5641 | if (err < 0) | |
5642 | goto out_err; | |
5643 | } | |
5644 | ||
5645 | /* the global regdom is idx 0 */ | |
5646 | reg_idx = 1; | |
5647 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | |
5648 | regdom = get_wiphy_regdom(&rdev->wiphy); | |
5649 | if (!regdom) | |
5650 | continue; | |
5651 | ||
5652 | if (++reg_idx <= start) | |
5653 | continue; | |
5654 | ||
5655 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5656 | NLM_F_MULTI, &rdev->wiphy, regdom); | |
5657 | if (err < 0) { | |
5658 | reg_idx--; | |
5659 | break; | |
5660 | } | |
5661 | } | |
5662 | ||
5663 | cb->args[2] = reg_idx; | |
5664 | err = skb->len; | |
5665 | out_err: | |
5666 | rtnl_unlock(); | |
5667 | return err; | |
5668 | } | |
5669 | ||
b6863036 JB |
5670 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
5671 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { | |
5672 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, | |
5673 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
5674 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
5675 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
5676 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
5677 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
5678 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, | |
5679 | }; | |
5680 | ||
5681 | static int parse_reg_rule(struct nlattr *tb[], | |
5682 | struct ieee80211_reg_rule *reg_rule) | |
5683 | { | |
5684 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
5685 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
5686 | ||
5687 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
5688 | return -EINVAL; | |
5689 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
5690 | return -EINVAL; | |
5691 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
5692 | return -EINVAL; | |
5693 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
5694 | return -EINVAL; | |
5695 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
5696 | return -EINVAL; | |
5697 | ||
5698 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
5699 | ||
5700 | freq_range->start_freq_khz = | |
5701 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
5702 | freq_range->end_freq_khz = | |
5703 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
5704 | freq_range->max_bandwidth_khz = | |
5705 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
5706 | ||
5707 | power_rule->max_eirp = | |
5708 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
5709 | ||
5710 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
5711 | power_rule->max_antenna_gain = | |
5712 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
5713 | ||
5714 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) | |
5715 | reg_rule->dfs_cac_ms = | |
5716 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
5717 | ||
5718 | return 0; | |
5719 | } | |
5720 | ||
b2e1b302 LR |
5721 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5722 | { | |
5723 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5724 | struct nlattr *nl_reg_rule; | |
ea372c54 JB |
5725 | char *alpha2; |
5726 | int rem_reg_rules, r; | |
b2e1b302 | 5727 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
4c7d3982 | 5728 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
ea372c54 | 5729 | struct ieee80211_regdomain *rd; |
b2e1b302 LR |
5730 | |
5731 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5732 | return -EINVAL; | |
5733 | ||
5734 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5735 | return -EINVAL; | |
5736 | ||
5737 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5738 | ||
8b60b078 LR |
5739 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5740 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5741 | ||
b2e1b302 | 5742 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5743 | rem_reg_rules) { |
b2e1b302 LR |
5744 | num_rules++; |
5745 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5746 | return -EINVAL; |
b2e1b302 LR |
5747 | } |
5748 | ||
e438768f LR |
5749 | if (!reg_is_valid_request(alpha2)) |
5750 | return -EINVAL; | |
5751 | ||
b2e1b302 | 5752 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5753 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5754 | |
5755 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5756 | if (!rd) |
5757 | return -ENOMEM; | |
b2e1b302 LR |
5758 | |
5759 | rd->n_reg_rules = num_rules; | |
5760 | rd->alpha2[0] = alpha2[0]; | |
5761 | rd->alpha2[1] = alpha2[1]; | |
5762 | ||
8b60b078 LR |
5763 | /* |
5764 | * Disable DFS master mode if the DFS region was | |
5765 | * not supported or known on this kernel. | |
5766 | */ | |
5767 | if (reg_supported_dfs_region(dfs_region)) | |
5768 | rd->dfs_region = dfs_region; | |
5769 | ||
b2e1b302 | 5770 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5771 | rem_reg_rules) { |
ae811e21 JB |
5772 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
5773 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
5774 | reg_rule_policy); | |
5775 | if (r) | |
5776 | goto bad_reg; | |
b2e1b302 LR |
5777 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5778 | if (r) | |
5779 | goto bad_reg; | |
5780 | ||
5781 | rule_idx++; | |
5782 | ||
d0e18f83 LR |
5783 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5784 | r = -EINVAL; | |
b2e1b302 | 5785 | goto bad_reg; |
d0e18f83 | 5786 | } |
b2e1b302 LR |
5787 | } |
5788 | ||
c37722bd | 5789 | r = set_regdom(rd, REGD_SOURCE_CRDA); |
6913b49a | 5790 | /* set_regdom took ownership */ |
1a919318 | 5791 | rd = NULL; |
b2e1b302 | 5792 | |
d2372b31 | 5793 | bad_reg: |
b2e1b302 | 5794 | kfree(rd); |
d0e18f83 | 5795 | return r; |
b2e1b302 | 5796 | } |
b6863036 | 5797 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
b2e1b302 | 5798 | |
83f5e2cf JB |
5799 | static int validate_scan_freqs(struct nlattr *freqs) |
5800 | { | |
5801 | struct nlattr *attr1, *attr2; | |
5802 | int n_channels = 0, tmp1, tmp2; | |
5803 | ||
5804 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5805 | n_channels++; | |
5806 | /* | |
5807 | * Some hardware has a limited channel list for | |
5808 | * scanning, and it is pretty much nonsensical | |
5809 | * to scan for a channel twice, so disallow that | |
5810 | * and don't require drivers to check that the | |
5811 | * channel list they get isn't longer than what | |
5812 | * they can scan, as long as they can scan all | |
5813 | * the channels they registered at once. | |
5814 | */ | |
5815 | nla_for_each_nested(attr2, freqs, tmp2) | |
5816 | if (attr1 != attr2 && | |
5817 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5818 | return 0; | |
5819 | } | |
5820 | ||
5821 | return n_channels; | |
5822 | } | |
5823 | ||
38de03d2 AS |
5824 | static bool is_band_valid(struct wiphy *wiphy, enum ieee80211_band b) |
5825 | { | |
5826 | return b < IEEE80211_NUM_BANDS && wiphy->bands[b]; | |
5827 | } | |
5828 | ||
5829 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, | |
5830 | struct cfg80211_bss_selection *bss_select) | |
5831 | { | |
5832 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; | |
5833 | struct nlattr *nest; | |
5834 | int err; | |
5835 | bool found = false; | |
5836 | int i; | |
5837 | ||
5838 | /* only process one nested attribute */ | |
5839 | nest = nla_data(nla); | |
5840 | if (!nla_ok(nest, nla_len(nest))) | |
5841 | return -EINVAL; | |
5842 | ||
5843 | err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest), | |
5844 | nla_len(nest), nl80211_bss_select_policy); | |
5845 | if (err) | |
5846 | return err; | |
5847 | ||
5848 | /* only one attribute may be given */ | |
5849 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { | |
5850 | if (attr[i]) { | |
5851 | if (found) | |
5852 | return -EINVAL; | |
5853 | found = true; | |
5854 | } | |
5855 | } | |
5856 | ||
5857 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; | |
5858 | ||
5859 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) | |
5860 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; | |
5861 | ||
5862 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { | |
5863 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; | |
5864 | bss_select->param.band_pref = | |
5865 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); | |
5866 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) | |
5867 | return -EINVAL; | |
5868 | } | |
5869 | ||
5870 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { | |
5871 | struct nl80211_bss_select_rssi_adjust *adj_param; | |
5872 | ||
5873 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); | |
5874 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; | |
5875 | bss_select->param.adjust.band = adj_param->band; | |
5876 | bss_select->param.adjust.delta = adj_param->delta; | |
5877 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) | |
5878 | return -EINVAL; | |
5879 | } | |
5880 | ||
5881 | /* user-space did not provide behaviour attribute */ | |
5882 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) | |
5883 | return -EINVAL; | |
5884 | ||
5885 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) | |
5886 | return -EINVAL; | |
5887 | ||
5888 | return 0; | |
5889 | } | |
5890 | ||
ad2b26ab JB |
5891 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
5892 | u8 *mac_addr, u8 *mac_addr_mask) | |
5893 | { | |
5894 | int i; | |
5895 | ||
5896 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { | |
d2beae10 JP |
5897 | eth_zero_addr(mac_addr); |
5898 | eth_zero_addr(mac_addr_mask); | |
ad2b26ab JB |
5899 | mac_addr[0] = 0x2; |
5900 | mac_addr_mask[0] = 0x3; | |
5901 | ||
5902 | return 0; | |
5903 | } | |
5904 | ||
5905 | /* need both or none */ | |
5906 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) | |
5907 | return -EINVAL; | |
5908 | ||
5909 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); | |
5910 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); | |
5911 | ||
5912 | /* don't allow or configure an mcast address */ | |
5913 | if (!is_multicast_ether_addr(mac_addr_mask) || | |
5914 | is_multicast_ether_addr(mac_addr)) | |
5915 | return -EINVAL; | |
5916 | ||
5917 | /* | |
5918 | * allow users to pass a MAC address that has bits set outside | |
5919 | * of the mask, but don't bother drivers with having to deal | |
5920 | * with such bits | |
5921 | */ | |
5922 | for (i = 0; i < ETH_ALEN; i++) | |
5923 | mac_addr[i] &= mac_addr_mask[i]; | |
5924 | ||
5925 | return 0; | |
5926 | } | |
5927 | ||
2a519311 JB |
5928 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5929 | { | |
4c476991 | 5930 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5931 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5932 | struct cfg80211_scan_request *request; |
2a519311 JB |
5933 | struct nlattr *attr; |
5934 | struct wiphy *wiphy; | |
83f5e2cf | 5935 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5936 | size_t ie_len; |
2a519311 | 5937 | |
f4a11bb0 JB |
5938 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5939 | return -EINVAL; | |
5940 | ||
79c97e97 | 5941 | wiphy = &rdev->wiphy; |
2a519311 | 5942 | |
4c476991 JB |
5943 | if (!rdev->ops->scan) |
5944 | return -EOPNOTSUPP; | |
2a519311 | 5945 | |
f9d15d16 | 5946 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
5947 | err = -EBUSY; |
5948 | goto unlock; | |
5949 | } | |
2a519311 JB |
5950 | |
5951 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5952 | n_channels = validate_scan_freqs( |
5953 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5954 | if (!n_channels) { |
5955 | err = -EINVAL; | |
5956 | goto unlock; | |
5957 | } | |
2a519311 | 5958 | } else { |
bdfbec2d | 5959 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
5960 | } |
5961 | ||
5962 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5963 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5964 | n_ssids++; | |
5965 | ||
f9f47529 JB |
5966 | if (n_ssids > wiphy->max_scan_ssids) { |
5967 | err = -EINVAL; | |
5968 | goto unlock; | |
5969 | } | |
2a519311 | 5970 | |
70692ad2 JM |
5971 | if (info->attrs[NL80211_ATTR_IE]) |
5972 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5973 | else | |
5974 | ie_len = 0; | |
5975 | ||
f9f47529 JB |
5976 | if (ie_len > wiphy->max_scan_ie_len) { |
5977 | err = -EINVAL; | |
5978 | goto unlock; | |
5979 | } | |
18a83659 | 5980 | |
2a519311 | 5981 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5982 | + sizeof(*request->ssids) * n_ssids |
5983 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5984 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5985 | if (!request) { |
5986 | err = -ENOMEM; | |
5987 | goto unlock; | |
5988 | } | |
2a519311 | 5989 | |
2a519311 | 5990 | if (n_ssids) |
5ba63533 | 5991 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5992 | request->n_ssids = n_ssids; |
70692ad2 | 5993 | if (ie_len) { |
13874e4b | 5994 | if (n_ssids) |
70692ad2 JM |
5995 | request->ie = (void *)(request->ssids + n_ssids); |
5996 | else | |
5997 | request->ie = (void *)(request->channels + n_channels); | |
5998 | } | |
2a519311 | 5999 | |
584991dc | 6000 | i = 0; |
2a519311 JB |
6001 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
6002 | /* user specified, bail out if channel not found */ | |
2a519311 | 6003 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
6004 | struct ieee80211_channel *chan; |
6005 | ||
6006 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
6007 | ||
6008 | if (!chan) { | |
2a519311 JB |
6009 | err = -EINVAL; |
6010 | goto out_free; | |
6011 | } | |
584991dc JB |
6012 | |
6013 | /* ignore disabled channels */ | |
6014 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6015 | continue; | |
6016 | ||
6017 | request->channels[i] = chan; | |
2a519311 JB |
6018 | i++; |
6019 | } | |
6020 | } else { | |
34850ab2 JB |
6021 | enum ieee80211_band band; |
6022 | ||
2a519311 | 6023 | /* all channels */ |
2a519311 JB |
6024 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
6025 | int j; | |
6026 | if (!wiphy->bands[band]) | |
6027 | continue; | |
6028 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
6029 | struct ieee80211_channel *chan; |
6030 | ||
6031 | chan = &wiphy->bands[band]->channels[j]; | |
6032 | ||
6033 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6034 | continue; | |
6035 | ||
6036 | request->channels[i] = chan; | |
2a519311 JB |
6037 | i++; |
6038 | } | |
6039 | } | |
6040 | } | |
6041 | ||
584991dc JB |
6042 | if (!i) { |
6043 | err = -EINVAL; | |
6044 | goto out_free; | |
6045 | } | |
6046 | ||
6047 | request->n_channels = i; | |
6048 | ||
2a519311 | 6049 | i = 0; |
13874e4b | 6050 | if (n_ssids) { |
2a519311 | 6051 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
57a27e1d | 6052 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
6053 | err = -EINVAL; |
6054 | goto out_free; | |
6055 | } | |
57a27e1d | 6056 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 6057 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
6058 | i++; |
6059 | } | |
6060 | } | |
6061 | ||
70692ad2 JM |
6062 | if (info->attrs[NL80211_ATTR_IE]) { |
6063 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
6064 | memcpy((void *)request->ie, |
6065 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
6066 | request->ie_len); |
6067 | } | |
6068 | ||
34850ab2 | 6069 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
6070 | if (wiphy->bands[i]) |
6071 | request->rates[i] = | |
6072 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
6073 | |
6074 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
6075 | nla_for_each_nested(attr, | |
6076 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
6077 | tmp) { | |
6078 | enum ieee80211_band band = nla_type(attr); | |
6079 | ||
84404623 | 6080 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
6081 | err = -EINVAL; |
6082 | goto out_free; | |
6083 | } | |
1b09cd82 FF |
6084 | |
6085 | if (!wiphy->bands[band]) | |
6086 | continue; | |
6087 | ||
34850ab2 JB |
6088 | err = ieee80211_get_ratemask(wiphy->bands[band], |
6089 | nla_data(attr), | |
6090 | nla_len(attr), | |
6091 | &request->rates[band]); | |
6092 | if (err) | |
6093 | goto out_free; | |
6094 | } | |
6095 | } | |
6096 | ||
46856bbf | 6097 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
6098 | request->flags = nla_get_u32( |
6099 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
6100 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
6101 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
6102 | err = -EOPNOTSUPP; |
6103 | goto out_free; | |
6104 | } | |
ad2b26ab JB |
6105 | |
6106 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
6107 | if (!(wiphy->features & | |
6108 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { | |
6109 | err = -EOPNOTSUPP; | |
6110 | goto out_free; | |
6111 | } | |
6112 | ||
6113 | if (wdev->current_bss) { | |
6114 | err = -EOPNOTSUPP; | |
6115 | goto out_free; | |
6116 | } | |
6117 | ||
6118 | err = nl80211_parse_random_mac(info->attrs, | |
6119 | request->mac_addr, | |
6120 | request->mac_addr_mask); | |
6121 | if (err) | |
6122 | goto out_free; | |
6123 | } | |
46856bbf | 6124 | } |
ed473771 | 6125 | |
e9f935e3 RM |
6126 | request->no_cck = |
6127 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
6128 | ||
818965d3 JM |
6129 | if (info->attrs[NL80211_ATTR_MAC]) |
6130 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), | |
6131 | ETH_ALEN); | |
6132 | else | |
6133 | eth_broadcast_addr(request->bssid); | |
6134 | ||
fd014284 | 6135 | request->wdev = wdev; |
79c97e97 | 6136 | request->wiphy = &rdev->wiphy; |
15d6030b | 6137 | request->scan_start = jiffies; |
2a519311 | 6138 | |
79c97e97 | 6139 | rdev->scan_req = request; |
e35e4d28 | 6140 | err = rdev_scan(rdev, request); |
2a519311 | 6141 | |
463d0183 | 6142 | if (!err) { |
fd014284 JB |
6143 | nl80211_send_scan_start(rdev, wdev); |
6144 | if (wdev->netdev) | |
6145 | dev_hold(wdev->netdev); | |
4c476991 | 6146 | } else { |
2a519311 | 6147 | out_free: |
79c97e97 | 6148 | rdev->scan_req = NULL; |
2a519311 JB |
6149 | kfree(request); |
6150 | } | |
3b85875a | 6151 | |
f9f47529 | 6152 | unlock: |
2a519311 JB |
6153 | return err; |
6154 | } | |
6155 | ||
91d3ab46 VK |
6156 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
6157 | { | |
6158 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6159 | struct wireless_dev *wdev = info->user_ptr[1]; | |
6160 | ||
6161 | if (!rdev->ops->abort_scan) | |
6162 | return -EOPNOTSUPP; | |
6163 | ||
6164 | if (rdev->scan_msg) | |
6165 | return 0; | |
6166 | ||
6167 | if (!rdev->scan_req) | |
6168 | return -ENOENT; | |
6169 | ||
6170 | rdev_abort_scan(rdev, wdev); | |
6171 | return 0; | |
6172 | } | |
6173 | ||
3b06d277 AS |
6174 | static int |
6175 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, | |
6176 | struct cfg80211_sched_scan_request *request, | |
6177 | struct nlattr **attrs) | |
6178 | { | |
6179 | int tmp, err, i = 0; | |
6180 | struct nlattr *attr; | |
6181 | ||
6182 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { | |
6183 | u32 interval; | |
6184 | ||
6185 | /* | |
6186 | * If scan plans are not specified, | |
6187 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this | |
6188 | * case one scan plan will be set with the specified scan | |
6189 | * interval and infinite number of iterations. | |
6190 | */ | |
6191 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
6192 | return -EINVAL; | |
6193 | ||
6194 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
6195 | if (!interval) | |
6196 | return -EINVAL; | |
6197 | ||
6198 | request->scan_plans[0].interval = | |
6199 | DIV_ROUND_UP(interval, MSEC_PER_SEC); | |
6200 | if (!request->scan_plans[0].interval) | |
6201 | return -EINVAL; | |
6202 | ||
6203 | if (request->scan_plans[0].interval > | |
6204 | wiphy->max_sched_scan_plan_interval) | |
6205 | request->scan_plans[0].interval = | |
6206 | wiphy->max_sched_scan_plan_interval; | |
6207 | ||
6208 | return 0; | |
6209 | } | |
6210 | ||
6211 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { | |
6212 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; | |
6213 | ||
6214 | if (WARN_ON(i >= n_plans)) | |
6215 | return -EINVAL; | |
6216 | ||
6217 | err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX, | |
6218 | nla_data(attr), nla_len(attr), | |
6219 | nl80211_plan_policy); | |
6220 | if (err) | |
6221 | return err; | |
6222 | ||
6223 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) | |
6224 | return -EINVAL; | |
6225 | ||
6226 | request->scan_plans[i].interval = | |
6227 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); | |
6228 | if (!request->scan_plans[i].interval || | |
6229 | request->scan_plans[i].interval > | |
6230 | wiphy->max_sched_scan_plan_interval) | |
6231 | return -EINVAL; | |
6232 | ||
6233 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { | |
6234 | request->scan_plans[i].iterations = | |
6235 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); | |
6236 | if (!request->scan_plans[i].iterations || | |
6237 | (request->scan_plans[i].iterations > | |
6238 | wiphy->max_sched_scan_plan_iterations)) | |
6239 | return -EINVAL; | |
6240 | } else if (i < n_plans - 1) { | |
6241 | /* | |
6242 | * All scan plans but the last one must specify | |
6243 | * a finite number of iterations | |
6244 | */ | |
6245 | return -EINVAL; | |
6246 | } | |
6247 | ||
6248 | i++; | |
6249 | } | |
6250 | ||
6251 | /* | |
6252 | * The last scan plan must not specify the number of | |
6253 | * iterations, it is supposed to run infinitely | |
6254 | */ | |
6255 | if (request->scan_plans[n_plans - 1].iterations) | |
6256 | return -EINVAL; | |
6257 | ||
6258 | return 0; | |
6259 | } | |
6260 | ||
256da02d | 6261 | static struct cfg80211_sched_scan_request * |
ad2b26ab | 6262 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
256da02d | 6263 | struct nlattr **attrs) |
807f8a8c LC |
6264 | { |
6265 | struct cfg80211_sched_scan_request *request; | |
807f8a8c | 6266 | struct nlattr *attr; |
3b06d277 | 6267 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; |
807f8a8c LC |
6268 | enum ieee80211_band band; |
6269 | size_t ie_len; | |
a1f1c21c | 6270 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 6271 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c | 6272 | |
256da02d LC |
6273 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
6274 | return ERR_PTR(-EINVAL); | |
807f8a8c | 6275 | |
256da02d | 6276 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c | 6277 | n_channels = validate_scan_freqs( |
256da02d | 6278 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
807f8a8c | 6279 | if (!n_channels) |
256da02d | 6280 | return ERR_PTR(-EINVAL); |
807f8a8c | 6281 | } else { |
bdfbec2d | 6282 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
6283 | } |
6284 | ||
256da02d LC |
6285 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
6286 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c LC |
6287 | tmp) |
6288 | n_ssids++; | |
6289 | ||
93b6aa69 | 6290 | if (n_ssids > wiphy->max_sched_scan_ssids) |
256da02d | 6291 | return ERR_PTR(-EINVAL); |
807f8a8c | 6292 | |
ea73cbce JB |
6293 | /* |
6294 | * First, count the number of 'real' matchsets. Due to an issue with | |
6295 | * the old implementation, matchsets containing only the RSSI attribute | |
6296 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
6297 | * RSSI for all matchsets, rather than their own matchset for reporting | |
6298 | * all APs with a strong RSSI. This is needed to be compatible with | |
6299 | * older userspace that treated a matchset with only the RSSI as the | |
6300 | * global RSSI for all other matchsets - if there are other matchsets. | |
6301 | */ | |
256da02d | 6302 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 6303 | nla_for_each_nested(attr, |
256da02d | 6304 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
ea73cbce JB |
6305 | tmp) { |
6306 | struct nlattr *rssi; | |
6307 | ||
6308 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
6309 | nla_data(attr), nla_len(attr), | |
6310 | nl80211_match_policy); | |
6311 | if (err) | |
256da02d | 6312 | return ERR_PTR(err); |
ea73cbce JB |
6313 | /* add other standalone attributes here */ |
6314 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | |
6315 | n_match_sets++; | |
6316 | continue; | |
6317 | } | |
6318 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6319 | if (rssi) | |
6320 | default_match_rssi = nla_get_s32(rssi); | |
6321 | } | |
6322 | } | |
6323 | ||
6324 | /* However, if there's no other matchset, add the RSSI one */ | |
6325 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
6326 | n_match_sets = 1; | |
a1f1c21c LC |
6327 | |
6328 | if (n_match_sets > wiphy->max_match_sets) | |
256da02d | 6329 | return ERR_PTR(-EINVAL); |
a1f1c21c | 6330 | |
256da02d LC |
6331 | if (attrs[NL80211_ATTR_IE]) |
6332 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); | |
807f8a8c LC |
6333 | else |
6334 | ie_len = 0; | |
6335 | ||
5a865bad | 6336 | if (ie_len > wiphy->max_sched_scan_ie_len) |
256da02d | 6337 | return ERR_PTR(-EINVAL); |
c10841ca | 6338 | |
3b06d277 AS |
6339 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
6340 | /* | |
6341 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since | |
6342 | * each scan plan already specifies its own interval | |
6343 | */ | |
6344 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
6345 | return ERR_PTR(-EINVAL); | |
6346 | ||
6347 | nla_for_each_nested(attr, | |
6348 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) | |
6349 | n_plans++; | |
6350 | } else { | |
6351 | /* | |
6352 | * The scan interval attribute is kept for backward | |
6353 | * compatibility. If no scan plans are specified and sched scan | |
6354 | * interval is specified, one scan plan will be set with this | |
6355 | * scan interval and infinite number of iterations. | |
6356 | */ | |
6357 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
6358 | return ERR_PTR(-EINVAL); | |
6359 | ||
6360 | n_plans = 1; | |
6361 | } | |
6362 | ||
6363 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) | |
6364 | return ERR_PTR(-EINVAL); | |
6365 | ||
807f8a8c | 6366 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 6367 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 6368 | + sizeof(*request->match_sets) * n_match_sets |
3b06d277 | 6369 | + sizeof(*request->scan_plans) * n_plans |
a2cd43c5 | 6370 | + sizeof(*request->channels) * n_channels |
807f8a8c | 6371 | + ie_len, GFP_KERNEL); |
256da02d LC |
6372 | if (!request) |
6373 | return ERR_PTR(-ENOMEM); | |
807f8a8c LC |
6374 | |
6375 | if (n_ssids) | |
6376 | request->ssids = (void *)&request->channels[n_channels]; | |
6377 | request->n_ssids = n_ssids; | |
6378 | if (ie_len) { | |
13874e4b | 6379 | if (n_ssids) |
807f8a8c LC |
6380 | request->ie = (void *)(request->ssids + n_ssids); |
6381 | else | |
6382 | request->ie = (void *)(request->channels + n_channels); | |
6383 | } | |
6384 | ||
a1f1c21c LC |
6385 | if (n_match_sets) { |
6386 | if (request->ie) | |
6387 | request->match_sets = (void *)(request->ie + ie_len); | |
13874e4b | 6388 | else if (n_ssids) |
a1f1c21c LC |
6389 | request->match_sets = |
6390 | (void *)(request->ssids + n_ssids); | |
6391 | else | |
6392 | request->match_sets = | |
6393 | (void *)(request->channels + n_channels); | |
6394 | } | |
6395 | request->n_match_sets = n_match_sets; | |
6396 | ||
3b06d277 AS |
6397 | if (n_match_sets) |
6398 | request->scan_plans = (void *)(request->match_sets + | |
6399 | n_match_sets); | |
6400 | else if (request->ie) | |
6401 | request->scan_plans = (void *)(request->ie + ie_len); | |
6402 | else if (n_ssids) | |
6403 | request->scan_plans = (void *)(request->ssids + n_ssids); | |
6404 | else | |
6405 | request->scan_plans = (void *)(request->channels + n_channels); | |
6406 | ||
6407 | request->n_scan_plans = n_plans; | |
6408 | ||
807f8a8c | 6409 | i = 0; |
256da02d | 6410 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c LC |
6411 | /* user specified, bail out if channel not found */ |
6412 | nla_for_each_nested(attr, | |
256da02d | 6413 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
807f8a8c LC |
6414 | tmp) { |
6415 | struct ieee80211_channel *chan; | |
6416 | ||
6417 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
6418 | ||
6419 | if (!chan) { | |
6420 | err = -EINVAL; | |
6421 | goto out_free; | |
6422 | } | |
6423 | ||
6424 | /* ignore disabled channels */ | |
6425 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6426 | continue; | |
6427 | ||
6428 | request->channels[i] = chan; | |
6429 | i++; | |
6430 | } | |
6431 | } else { | |
6432 | /* all channels */ | |
6433 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6434 | int j; | |
6435 | if (!wiphy->bands[band]) | |
6436 | continue; | |
6437 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
6438 | struct ieee80211_channel *chan; | |
6439 | ||
6440 | chan = &wiphy->bands[band]->channels[j]; | |
6441 | ||
6442 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6443 | continue; | |
6444 | ||
6445 | request->channels[i] = chan; | |
6446 | i++; | |
6447 | } | |
6448 | } | |
6449 | } | |
6450 | ||
6451 | if (!i) { | |
6452 | err = -EINVAL; | |
6453 | goto out_free; | |
6454 | } | |
6455 | ||
6456 | request->n_channels = i; | |
6457 | ||
6458 | i = 0; | |
13874e4b | 6459 | if (n_ssids) { |
256da02d | 6460 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
807f8a8c | 6461 | tmp) { |
57a27e1d | 6462 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
6463 | err = -EINVAL; |
6464 | goto out_free; | |
6465 | } | |
57a27e1d | 6466 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
6467 | memcpy(request->ssids[i].ssid, nla_data(attr), |
6468 | nla_len(attr)); | |
807f8a8c LC |
6469 | i++; |
6470 | } | |
6471 | } | |
6472 | ||
a1f1c21c | 6473 | i = 0; |
256da02d | 6474 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 6475 | nla_for_each_nested(attr, |
256da02d | 6476 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
a1f1c21c | 6477 | tmp) { |
88e920b4 | 6478 | struct nlattr *ssid, *rssi; |
a1f1c21c | 6479 | |
ae811e21 JB |
6480 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
6481 | nla_data(attr), nla_len(attr), | |
6482 | nl80211_match_policy); | |
6483 | if (err) | |
6484 | goto out_free; | |
4a4ab0d7 | 6485 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 6486 | if (ssid) { |
ea73cbce JB |
6487 | if (WARN_ON(i >= n_match_sets)) { |
6488 | /* this indicates a programming error, | |
6489 | * the loop above should have verified | |
6490 | * things properly | |
6491 | */ | |
6492 | err = -EINVAL; | |
6493 | goto out_free; | |
6494 | } | |
6495 | ||
a1f1c21c LC |
6496 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
6497 | err = -EINVAL; | |
6498 | goto out_free; | |
6499 | } | |
6500 | memcpy(request->match_sets[i].ssid.ssid, | |
6501 | nla_data(ssid), nla_len(ssid)); | |
6502 | request->match_sets[i].ssid.ssid_len = | |
6503 | nla_len(ssid); | |
ea73cbce JB |
6504 | /* special attribute - old implemenation w/a */ |
6505 | request->match_sets[i].rssi_thold = | |
6506 | default_match_rssi; | |
6507 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6508 | if (rssi) | |
6509 | request->match_sets[i].rssi_thold = | |
6510 | nla_get_s32(rssi); | |
a1f1c21c LC |
6511 | } |
6512 | i++; | |
6513 | } | |
ea73cbce JB |
6514 | |
6515 | /* there was no other matchset, so the RSSI one is alone */ | |
f89f46cf | 6516 | if (i == 0 && n_match_sets) |
ea73cbce JB |
6517 | request->match_sets[0].rssi_thold = default_match_rssi; |
6518 | ||
6519 | request->min_rssi_thold = INT_MAX; | |
6520 | for (i = 0; i < n_match_sets; i++) | |
6521 | request->min_rssi_thold = | |
6522 | min(request->match_sets[i].rssi_thold, | |
6523 | request->min_rssi_thold); | |
6524 | } else { | |
6525 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
6526 | } |
6527 | ||
9900e484 JB |
6528 | if (ie_len) { |
6529 | request->ie_len = ie_len; | |
807f8a8c | 6530 | memcpy((void *)request->ie, |
256da02d | 6531 | nla_data(attrs[NL80211_ATTR_IE]), |
807f8a8c LC |
6532 | request->ie_len); |
6533 | } | |
6534 | ||
256da02d | 6535 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 | 6536 | request->flags = nla_get_u32( |
256da02d | 6537 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
00c3a6ed JB |
6538 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
6539 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
6540 | err = -EOPNOTSUPP; |
6541 | goto out_free; | |
6542 | } | |
ad2b26ab JB |
6543 | |
6544 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
6545 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; | |
6546 | ||
6547 | if (!wdev) /* must be net-detect */ | |
6548 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
6549 | ||
6550 | if (!(wiphy->features & flg)) { | |
6551 | err = -EOPNOTSUPP; | |
6552 | goto out_free; | |
6553 | } | |
6554 | ||
6555 | if (wdev && wdev->current_bss) { | |
6556 | err = -EOPNOTSUPP; | |
6557 | goto out_free; | |
6558 | } | |
6559 | ||
6560 | err = nl80211_parse_random_mac(attrs, request->mac_addr, | |
6561 | request->mac_addr_mask); | |
6562 | if (err) | |
6563 | goto out_free; | |
6564 | } | |
46856bbf | 6565 | } |
ed473771 | 6566 | |
9c748934 LC |
6567 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
6568 | request->delay = | |
6569 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); | |
6570 | ||
3b06d277 AS |
6571 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
6572 | if (err) | |
6573 | goto out_free; | |
6574 | ||
15d6030b | 6575 | request->scan_start = jiffies; |
807f8a8c | 6576 | |
256da02d | 6577 | return request; |
807f8a8c LC |
6578 | |
6579 | out_free: | |
6580 | kfree(request); | |
256da02d LC |
6581 | return ERR_PTR(err); |
6582 | } | |
6583 | ||
6584 | static int nl80211_start_sched_scan(struct sk_buff *skb, | |
6585 | struct genl_info *info) | |
6586 | { | |
6587 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6588 | struct net_device *dev = info->user_ptr[1]; | |
ad2b26ab | 6589 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
31a60ed1 | 6590 | struct cfg80211_sched_scan_request *sched_scan_req; |
256da02d LC |
6591 | int err; |
6592 | ||
6593 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6594 | !rdev->ops->sched_scan_start) | |
6595 | return -EOPNOTSUPP; | |
6596 | ||
6597 | if (rdev->sched_scan_req) | |
6598 | return -EINPROGRESS; | |
6599 | ||
31a60ed1 JR |
6600 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
6601 | info->attrs); | |
6602 | ||
6603 | err = PTR_ERR_OR_ZERO(sched_scan_req); | |
256da02d LC |
6604 | if (err) |
6605 | goto out_err; | |
6606 | ||
31a60ed1 | 6607 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
256da02d LC |
6608 | if (err) |
6609 | goto out_free; | |
6610 | ||
31a60ed1 JR |
6611 | sched_scan_req->dev = dev; |
6612 | sched_scan_req->wiphy = &rdev->wiphy; | |
6613 | ||
93a1e86c JR |
6614 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
6615 | sched_scan_req->owner_nlportid = info->snd_portid; | |
6616 | ||
31a60ed1 | 6617 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
256da02d LC |
6618 | |
6619 | nl80211_send_sched_scan(rdev, dev, | |
6620 | NL80211_CMD_START_SCHED_SCAN); | |
6621 | return 0; | |
6622 | ||
6623 | out_free: | |
31a60ed1 | 6624 | kfree(sched_scan_req); |
256da02d | 6625 | out_err: |
807f8a8c LC |
6626 | return err; |
6627 | } | |
6628 | ||
6629 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
6630 | struct genl_info *info) | |
6631 | { | |
6632 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6633 | ||
6634 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6635 | !rdev->ops->sched_scan_stop) | |
6636 | return -EOPNOTSUPP; | |
6637 | ||
5fe231e8 | 6638 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
6639 | } |
6640 | ||
04f39047 SW |
6641 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
6642 | struct genl_info *info) | |
6643 | { | |
6644 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6645 | struct net_device *dev = info->user_ptr[1]; | |
6646 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6647 | struct cfg80211_chan_def chandef; | |
55f7435c | 6648 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 6649 | unsigned int cac_time_ms; |
04f39047 SW |
6650 | int err; |
6651 | ||
55f7435c LR |
6652 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
6653 | if (dfs_region == NL80211_DFS_UNSET) | |
6654 | return -EINVAL; | |
6655 | ||
04f39047 SW |
6656 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6657 | if (err) | |
6658 | return err; | |
6659 | ||
ff311bc1 SW |
6660 | if (netif_carrier_ok(dev)) |
6661 | return -EBUSY; | |
6662 | ||
04f39047 SW |
6663 | if (wdev->cac_started) |
6664 | return -EBUSY; | |
6665 | ||
2beb6dab | 6666 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
00ec75fc | 6667 | wdev->iftype); |
04f39047 SW |
6668 | if (err < 0) |
6669 | return err; | |
6670 | ||
6671 | if (err == 0) | |
6672 | return -EINVAL; | |
6673 | ||
fe7c3a1f | 6674 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
6675 | return -EINVAL; |
6676 | ||
6677 | if (!rdev->ops->start_radar_detection) | |
6678 | return -EOPNOTSUPP; | |
6679 | ||
31559f35 JD |
6680 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
6681 | if (WARN_ON(!cac_time_ms)) | |
6682 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
6683 | ||
a1056b1b | 6684 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
04f39047 | 6685 | if (!err) { |
9e0e2961 | 6686 | wdev->chandef = chandef; |
04f39047 SW |
6687 | wdev->cac_started = true; |
6688 | wdev->cac_start_time = jiffies; | |
31559f35 | 6689 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 6690 | } |
04f39047 SW |
6691 | return err; |
6692 | } | |
6693 | ||
16ef1fe2 SW |
6694 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
6695 | { | |
6696 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6697 | struct net_device *dev = info->user_ptr[1]; | |
6698 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6699 | struct cfg80211_csa_settings params; | |
6700 | /* csa_attrs is defined static to avoid waste of stack size - this | |
6701 | * function is called under RTNL lock, so this should not be a problem. | |
6702 | */ | |
6703 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
16ef1fe2 | 6704 | int err; |
ee4bc9e7 | 6705 | bool need_new_beacon = false; |
9a774c78 | 6706 | int len, i; |
252e07ca | 6707 | u32 cs_count; |
16ef1fe2 SW |
6708 | |
6709 | if (!rdev->ops->channel_switch || | |
6710 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
6711 | return -EOPNOTSUPP; | |
6712 | ||
ee4bc9e7 SW |
6713 | switch (dev->ieee80211_ptr->iftype) { |
6714 | case NL80211_IFTYPE_AP: | |
6715 | case NL80211_IFTYPE_P2P_GO: | |
6716 | need_new_beacon = true; | |
6717 | ||
6718 | /* useless if AP is not running */ | |
6719 | if (!wdev->beacon_interval) | |
1ff79dfa | 6720 | return -ENOTCONN; |
ee4bc9e7 SW |
6721 | break; |
6722 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
6723 | if (!wdev->ssid_len) |
6724 | return -ENOTCONN; | |
6725 | break; | |
c6da674a | 6726 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
6727 | if (!wdev->mesh_id_len) |
6728 | return -ENOTCONN; | |
ee4bc9e7 SW |
6729 | break; |
6730 | default: | |
16ef1fe2 | 6731 | return -EOPNOTSUPP; |
ee4bc9e7 | 6732 | } |
16ef1fe2 SW |
6733 | |
6734 | memset(¶ms, 0, sizeof(params)); | |
6735 | ||
6736 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6737 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
6738 | return -EINVAL; | |
6739 | ||
6740 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 6741 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
6742 | return -EINVAL; |
6743 | ||
252e07ca LC |
6744 | /* Even though the attribute is u32, the specification says |
6745 | * u8, so let's make sure we don't overflow. | |
6746 | */ | |
6747 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
6748 | if (cs_count > 255) | |
6749 | return -EINVAL; | |
6750 | ||
6751 | params.count = cs_count; | |
16ef1fe2 | 6752 | |
ee4bc9e7 SW |
6753 | if (!need_new_beacon) |
6754 | goto skip_beacons; | |
6755 | ||
16ef1fe2 SW |
6756 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
6757 | if (err) | |
6758 | return err; | |
6759 | ||
6760 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
6761 | info->attrs[NL80211_ATTR_CSA_IES], | |
6762 | nl80211_policy); | |
6763 | if (err) | |
6764 | return err; | |
6765 | ||
6766 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
6767 | if (err) | |
6768 | return err; | |
6769 | ||
6770 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
6771 | return -EINVAL; | |
6772 | ||
9a774c78 AO |
6773 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
6774 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6775 | return -EINVAL; |
6776 | ||
9a774c78 AO |
6777 | params.n_counter_offsets_beacon = len / sizeof(u16); |
6778 | if (rdev->wiphy.max_num_csa_counters && | |
6779 | (params.n_counter_offsets_beacon > | |
6780 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
6781 | return -EINVAL; |
6782 | ||
9a774c78 AO |
6783 | params.counter_offsets_beacon = |
6784 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
6785 | ||
6786 | /* sanity checks - counters should fit and be the same */ | |
6787 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
6788 | u16 offset = params.counter_offsets_beacon[i]; | |
6789 | ||
6790 | if (offset >= params.beacon_csa.tail_len) | |
6791 | return -EINVAL; | |
6792 | ||
6793 | if (params.beacon_csa.tail[offset] != params.count) | |
6794 | return -EINVAL; | |
6795 | } | |
6796 | ||
16ef1fe2 | 6797 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
6798 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
6799 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6800 | return -EINVAL; |
6801 | ||
9a774c78 AO |
6802 | params.n_counter_offsets_presp = len / sizeof(u16); |
6803 | if (rdev->wiphy.max_num_csa_counters && | |
6804 | (params.n_counter_offsets_beacon > | |
6805 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 | 6806 | return -EINVAL; |
9a774c78 AO |
6807 | |
6808 | params.counter_offsets_presp = | |
6809 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
6810 | ||
6811 | /* sanity checks - counters should fit and be the same */ | |
6812 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
6813 | u16 offset = params.counter_offsets_presp[i]; | |
6814 | ||
6815 | if (offset >= params.beacon_csa.probe_resp_len) | |
6816 | return -EINVAL; | |
6817 | ||
6818 | if (params.beacon_csa.probe_resp[offset] != | |
6819 | params.count) | |
6820 | return -EINVAL; | |
6821 | } | |
16ef1fe2 SW |
6822 | } |
6823 | ||
ee4bc9e7 | 6824 | skip_beacons: |
16ef1fe2 SW |
6825 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
6826 | if (err) | |
6827 | return err; | |
6828 | ||
923b352f AN |
6829 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
6830 | wdev->iftype)) | |
16ef1fe2 SW |
6831 | return -EINVAL; |
6832 | ||
2beb6dab LC |
6833 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
6834 | ¶ms.chandef, | |
6835 | wdev->iftype); | |
6836 | if (err < 0) | |
6837 | return err; | |
6838 | ||
dcc6c2f5 | 6839 | if (err > 0) |
2beb6dab | 6840 | params.radar_required = true; |
16ef1fe2 | 6841 | |
16ef1fe2 SW |
6842 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
6843 | params.block_tx = true; | |
6844 | ||
c56589ed SW |
6845 | wdev_lock(wdev); |
6846 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
6847 | wdev_unlock(wdev); | |
6848 | ||
6849 | return err; | |
16ef1fe2 SW |
6850 | } |
6851 | ||
9720bb3a JB |
6852 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
6853 | u32 seq, int flags, | |
2a519311 | 6854 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
6855 | struct wireless_dev *wdev, |
6856 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 6857 | { |
48ab905d | 6858 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 6859 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
6860 | void *hdr; |
6861 | struct nlattr *bss; | |
48ab905d JB |
6862 | |
6863 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 6864 | |
15e47304 | 6865 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
6866 | NL80211_CMD_NEW_SCAN_RESULTS); |
6867 | if (!hdr) | |
6868 | return -1; | |
6869 | ||
9720bb3a JB |
6870 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
6871 | ||
97990a06 JB |
6872 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
6873 | goto nla_put_failure; | |
6874 | if (wdev->netdev && | |
9360ffd1 DM |
6875 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
6876 | goto nla_put_failure; | |
97990a06 JB |
6877 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
6878 | goto nla_put_failure; | |
2a519311 JB |
6879 | |
6880 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
6881 | if (!bss) | |
6882 | goto nla_put_failure; | |
9360ffd1 | 6883 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 6884 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 6885 | goto nla_put_failure; |
9caf0364 JB |
6886 | |
6887 | rcu_read_lock(); | |
0e227084 JB |
6888 | /* indicate whether we have probe response data or not */ |
6889 | if (rcu_access_pointer(res->proberesp_ies) && | |
6890 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
6891 | goto fail_unlock_rcu; | |
6892 | ||
6893 | /* this pointer prefers to be pointed to probe response data | |
6894 | * but is always valid | |
6895 | */ | |
9caf0364 | 6896 | ies = rcu_dereference(res->ies); |
8cef2c9d JB |
6897 | if (ies) { |
6898 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
6899 | goto fail_unlock_rcu; | |
8cef2c9d JB |
6900 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
6901 | ies->len, ies->data)) | |
6902 | goto fail_unlock_rcu; | |
9caf0364 | 6903 | } |
0e227084 JB |
6904 | |
6905 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 6906 | ies = rcu_dereference(res->beacon_ies); |
0e227084 JB |
6907 | if (ies && ies->from_beacon) { |
6908 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) | |
8cef2c9d JB |
6909 | goto fail_unlock_rcu; |
6910 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
6911 | ies->len, ies->data)) | |
6912 | goto fail_unlock_rcu; | |
9caf0364 JB |
6913 | } |
6914 | rcu_read_unlock(); | |
6915 | ||
9360ffd1 DM |
6916 | if (res->beacon_interval && |
6917 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
6918 | goto nla_put_failure; | |
6919 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
6920 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 6921 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
6922 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
6923 | jiffies_to_msecs(jiffies - intbss->ts))) | |
6924 | goto nla_put_failure; | |
2a519311 | 6925 | |
6e19bc4b DS |
6926 | if (intbss->ts_boottime && |
6927 | nla_put_u64(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, | |
6928 | intbss->ts_boottime)) | |
6929 | goto nla_put_failure; | |
6930 | ||
77965c97 | 6931 | switch (rdev->wiphy.signal_type) { |
2a519311 | 6932 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
6933 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
6934 | goto nla_put_failure; | |
2a519311 JB |
6935 | break; |
6936 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
6937 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
6938 | goto nla_put_failure; | |
2a519311 JB |
6939 | break; |
6940 | default: | |
6941 | break; | |
6942 | } | |
6943 | ||
48ab905d | 6944 | switch (wdev->iftype) { |
074ac8df | 6945 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 6946 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
6947 | if (intbss == wdev->current_bss && |
6948 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6949 | NL80211_BSS_STATUS_ASSOCIATED)) | |
6950 | goto nla_put_failure; | |
48ab905d JB |
6951 | break; |
6952 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
6953 | if (intbss == wdev->current_bss && |
6954 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6955 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
6956 | goto nla_put_failure; | |
48ab905d JB |
6957 | break; |
6958 | default: | |
6959 | break; | |
6960 | } | |
6961 | ||
2a519311 JB |
6962 | nla_nest_end(msg, bss); |
6963 | ||
053c095a JB |
6964 | genlmsg_end(msg, hdr); |
6965 | return 0; | |
2a519311 | 6966 | |
8cef2c9d JB |
6967 | fail_unlock_rcu: |
6968 | rcu_read_unlock(); | |
2a519311 JB |
6969 | nla_put_failure: |
6970 | genlmsg_cancel(msg, hdr); | |
6971 | return -EMSGSIZE; | |
6972 | } | |
6973 | ||
97990a06 | 6974 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 6975 | { |
48ab905d | 6976 | struct cfg80211_registered_device *rdev; |
2a519311 | 6977 | struct cfg80211_internal_bss *scan; |
48ab905d | 6978 | struct wireless_dev *wdev; |
97990a06 | 6979 | int start = cb->args[2], idx = 0; |
2a519311 JB |
6980 | int err; |
6981 | ||
97990a06 | 6982 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6983 | if (err) |
6984 | return err; | |
2a519311 | 6985 | |
48ab905d JB |
6986 | wdev_lock(wdev); |
6987 | spin_lock_bh(&rdev->bss_lock); | |
6988 | cfg80211_bss_expire(rdev); | |
6989 | ||
9720bb3a JB |
6990 | cb->seq = rdev->bss_generation; |
6991 | ||
48ab905d | 6992 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
6993 | if (++idx <= start) |
6994 | continue; | |
9720bb3a | 6995 | if (nl80211_send_bss(skb, cb, |
2a519311 | 6996 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 6997 | rdev, wdev, scan) < 0) { |
2a519311 | 6998 | idx--; |
67748893 | 6999 | break; |
2a519311 JB |
7000 | } |
7001 | } | |
7002 | ||
48ab905d JB |
7003 | spin_unlock_bh(&rdev->bss_lock); |
7004 | wdev_unlock(wdev); | |
2a519311 | 7005 | |
97990a06 JB |
7006 | cb->args[2] = idx; |
7007 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 7008 | |
67748893 | 7009 | return skb->len; |
2a519311 JB |
7010 | } |
7011 | ||
15e47304 | 7012 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
11f78ac3 JB |
7013 | int flags, struct net_device *dev, |
7014 | bool allow_radio_stats, | |
7015 | struct survey_info *survey) | |
61fa713c HS |
7016 | { |
7017 | void *hdr; | |
7018 | struct nlattr *infoattr; | |
7019 | ||
11f78ac3 JB |
7020 | /* skip radio stats if userspace didn't request them */ |
7021 | if (!survey->channel && !allow_radio_stats) | |
7022 | return 0; | |
7023 | ||
15e47304 | 7024 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
7025 | NL80211_CMD_NEW_SURVEY_RESULTS); |
7026 | if (!hdr) | |
7027 | return -ENOMEM; | |
7028 | ||
9360ffd1 DM |
7029 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
7030 | goto nla_put_failure; | |
61fa713c HS |
7031 | |
7032 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
7033 | if (!infoattr) | |
7034 | goto nla_put_failure; | |
7035 | ||
11f78ac3 JB |
7036 | if (survey->channel && |
7037 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
9360ffd1 DM |
7038 | survey->channel->center_freq)) |
7039 | goto nla_put_failure; | |
7040 | ||
7041 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
7042 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
7043 | goto nla_put_failure; | |
7044 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
7045 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
7046 | goto nla_put_failure; | |
4ed20beb JB |
7047 | if ((survey->filled & SURVEY_INFO_TIME) && |
7048 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME, | |
7049 | survey->time)) | |
9360ffd1 | 7050 | goto nla_put_failure; |
4ed20beb JB |
7051 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
7052 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY, | |
7053 | survey->time_busy)) | |
9360ffd1 | 7054 | goto nla_put_failure; |
4ed20beb JB |
7055 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
7056 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, | |
7057 | survey->time_ext_busy)) | |
9360ffd1 | 7058 | goto nla_put_failure; |
4ed20beb JB |
7059 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
7060 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX, | |
7061 | survey->time_rx)) | |
9360ffd1 | 7062 | goto nla_put_failure; |
4ed20beb JB |
7063 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
7064 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX, | |
7065 | survey->time_tx)) | |
9360ffd1 | 7066 | goto nla_put_failure; |
052536ab JB |
7067 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
7068 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN, | |
7069 | survey->time_scan)) | |
7070 | goto nla_put_failure; | |
61fa713c HS |
7071 | |
7072 | nla_nest_end(msg, infoattr); | |
7073 | ||
053c095a JB |
7074 | genlmsg_end(msg, hdr); |
7075 | return 0; | |
61fa713c HS |
7076 | |
7077 | nla_put_failure: | |
7078 | genlmsg_cancel(msg, hdr); | |
7079 | return -EMSGSIZE; | |
7080 | } | |
7081 | ||
11f78ac3 | 7082 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
61fa713c HS |
7083 | { |
7084 | struct survey_info survey; | |
1b8ec87a | 7085 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
7086 | struct wireless_dev *wdev; |
7087 | int survey_idx = cb->args[2]; | |
61fa713c | 7088 | int res; |
11f78ac3 | 7089 | bool radio_stats; |
61fa713c | 7090 | |
1b8ec87a | 7091 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
7092 | if (res) |
7093 | return res; | |
61fa713c | 7094 | |
11f78ac3 JB |
7095 | /* prepare_wdev_dump parsed the attributes */ |
7096 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; | |
7097 | ||
97990a06 JB |
7098 | if (!wdev->netdev) { |
7099 | res = -EINVAL; | |
7100 | goto out_err; | |
7101 | } | |
7102 | ||
1b8ec87a | 7103 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
7104 | res = -EOPNOTSUPP; |
7105 | goto out_err; | |
7106 | } | |
7107 | ||
7108 | while (1) { | |
1b8ec87a | 7109 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
7110 | if (res == -ENOENT) |
7111 | break; | |
7112 | if (res) | |
7113 | goto out_err; | |
7114 | ||
11f78ac3 JB |
7115 | /* don't send disabled channels, but do send non-channel data */ |
7116 | if (survey.channel && | |
7117 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { | |
180cdc79 LR |
7118 | survey_idx++; |
7119 | continue; | |
7120 | } | |
7121 | ||
61fa713c | 7122 | if (nl80211_send_survey(skb, |
15e47304 | 7123 | NETLINK_CB(cb->skb).portid, |
61fa713c | 7124 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
11f78ac3 | 7125 | wdev->netdev, radio_stats, &survey) < 0) |
61fa713c HS |
7126 | goto out; |
7127 | survey_idx++; | |
7128 | } | |
7129 | ||
7130 | out: | |
97990a06 | 7131 | cb->args[2] = survey_idx; |
61fa713c HS |
7132 | res = skb->len; |
7133 | out_err: | |
1b8ec87a | 7134 | nl80211_finish_wdev_dump(rdev); |
61fa713c HS |
7135 | return res; |
7136 | } | |
7137 | ||
b23aa676 SO |
7138 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
7139 | { | |
7140 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
7141 | NL80211_WPA_VERSION_2)); | |
7142 | } | |
7143 | ||
636a5d36 JM |
7144 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
7145 | { | |
4c476991 JB |
7146 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7147 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7148 | struct ieee80211_channel *chan; |
e39e5b5e JM |
7149 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
7150 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 7151 | enum nl80211_auth_type auth_type; |
fffd0934 | 7152 | struct key_parse key; |
d5cdfacb | 7153 | bool local_state_change; |
636a5d36 | 7154 | |
f4a11bb0 JB |
7155 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7156 | return -EINVAL; | |
7157 | ||
7158 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7159 | return -EINVAL; | |
7160 | ||
1778092e JM |
7161 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
7162 | return -EINVAL; | |
7163 | ||
19957bb3 JB |
7164 | if (!info->attrs[NL80211_ATTR_SSID]) |
7165 | return -EINVAL; | |
7166 | ||
7167 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
7168 | return -EINVAL; | |
7169 | ||
fffd0934 JB |
7170 | err = nl80211_parse_key(info, &key); |
7171 | if (err) | |
7172 | return err; | |
7173 | ||
7174 | if (key.idx >= 0) { | |
e31b8213 JB |
7175 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
7176 | return -EINVAL; | |
fffd0934 JB |
7177 | if (!key.p.key || !key.p.key_len) |
7178 | return -EINVAL; | |
7179 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
7180 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
7181 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
7182 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
7183 | return -EINVAL; | |
7184 | if (key.idx > 4) | |
7185 | return -EINVAL; | |
7186 | } else { | |
7187 | key.p.key_len = 0; | |
7188 | key.p.key = NULL; | |
7189 | } | |
7190 | ||
afea0b7a JB |
7191 | if (key.idx >= 0) { |
7192 | int i; | |
7193 | bool ok = false; | |
7194 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
7195 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
7196 | ok = true; | |
7197 | break; | |
7198 | } | |
7199 | } | |
4c476991 JB |
7200 | if (!ok) |
7201 | return -EINVAL; | |
afea0b7a JB |
7202 | } |
7203 | ||
4c476991 JB |
7204 | if (!rdev->ops->auth) |
7205 | return -EOPNOTSUPP; | |
636a5d36 | 7206 | |
074ac8df | 7207 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7208 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7209 | return -EOPNOTSUPP; | |
eec60b03 | 7210 | |
19957bb3 | 7211 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
7212 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
7213 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7214 | if (!chan) | |
4c476991 | 7215 | return -EINVAL; |
636a5d36 | 7216 | |
19957bb3 JB |
7217 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7218 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
7219 | |
7220 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7221 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7222 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7223 | } |
7224 | ||
19957bb3 | 7225 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 7226 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 7227 | return -EINVAL; |
636a5d36 | 7228 | |
e39e5b5e JM |
7229 | if (auth_type == NL80211_AUTHTYPE_SAE && |
7230 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
7231 | return -EINVAL; | |
7232 | ||
7233 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
7234 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
7235 | return -EINVAL; | |
7236 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
7237 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
7238 | /* need to include at least Auth Transaction and Status Code */ | |
7239 | if (sae_data_len < 4) | |
7240 | return -EINVAL; | |
7241 | } | |
7242 | ||
d5cdfacb JM |
7243 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7244 | ||
95de817b JB |
7245 | /* |
7246 | * Since we no longer track auth state, ignore | |
7247 | * requests to only change local state. | |
7248 | */ | |
7249 | if (local_state_change) | |
7250 | return 0; | |
7251 | ||
91bf9b26 JB |
7252 | wdev_lock(dev->ieee80211_ptr); |
7253 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
7254 | ssid, ssid_len, ie, ie_len, | |
7255 | key.p.key, key.p.key_len, key.idx, | |
7256 | sae_data, sae_data_len); | |
7257 | wdev_unlock(dev->ieee80211_ptr); | |
7258 | return err; | |
636a5d36 JM |
7259 | } |
7260 | ||
c0692b8f JB |
7261 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
7262 | struct genl_info *info, | |
3dc27d25 JB |
7263 | struct cfg80211_crypto_settings *settings, |
7264 | int cipher_limit) | |
b23aa676 | 7265 | { |
c0b2bbd8 JB |
7266 | memset(settings, 0, sizeof(*settings)); |
7267 | ||
b23aa676 SO |
7268 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
7269 | ||
c0692b8f JB |
7270 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
7271 | u16 proto; | |
7272 | proto = nla_get_u16( | |
7273 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
7274 | settings->control_port_ethertype = cpu_to_be16(proto); | |
7275 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
7276 | proto != ETH_P_PAE) | |
7277 | return -EINVAL; | |
7278 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
7279 | settings->control_port_no_encrypt = true; | |
7280 | } else | |
7281 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
7282 | ||
b23aa676 SO |
7283 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
7284 | void *data; | |
7285 | int len, i; | |
7286 | ||
7287 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
7288 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
7289 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
7290 | ||
7291 | if (len % sizeof(u32)) | |
7292 | return -EINVAL; | |
7293 | ||
3dc27d25 | 7294 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
7295 | return -EINVAL; |
7296 | ||
7297 | memcpy(settings->ciphers_pairwise, data, len); | |
7298 | ||
7299 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
7300 | if (!cfg80211_supported_cipher_suite( |
7301 | &rdev->wiphy, | |
b23aa676 SO |
7302 | settings->ciphers_pairwise[i])) |
7303 | return -EINVAL; | |
7304 | } | |
7305 | ||
7306 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
7307 | settings->cipher_group = | |
7308 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
7309 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
7310 | settings->cipher_group)) | |
b23aa676 SO |
7311 | return -EINVAL; |
7312 | } | |
7313 | ||
7314 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
7315 | settings->wpa_versions = | |
7316 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
7317 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
7318 | return -EINVAL; | |
7319 | } | |
7320 | ||
7321 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
7322 | void *data; | |
6d30240e | 7323 | int len; |
b23aa676 SO |
7324 | |
7325 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
7326 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
7327 | settings->n_akm_suites = len / sizeof(u32); | |
7328 | ||
7329 | if (len % sizeof(u32)) | |
7330 | return -EINVAL; | |
7331 | ||
1b9ca027 JM |
7332 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
7333 | return -EINVAL; | |
7334 | ||
b23aa676 | 7335 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
7336 | } |
7337 | ||
7338 | return 0; | |
7339 | } | |
7340 | ||
636a5d36 JM |
7341 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
7342 | { | |
4c476991 JB |
7343 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7344 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 7345 | struct ieee80211_channel *chan; |
f62fab73 JB |
7346 | struct cfg80211_assoc_request req = {}; |
7347 | const u8 *bssid, *ssid; | |
7348 | int err, ssid_len = 0; | |
636a5d36 | 7349 | |
f4a11bb0 JB |
7350 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7351 | return -EINVAL; | |
7352 | ||
7353 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
7354 | !info->attrs[NL80211_ATTR_SSID] || |
7355 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
7356 | return -EINVAL; |
7357 | ||
4c476991 JB |
7358 | if (!rdev->ops->assoc) |
7359 | return -EOPNOTSUPP; | |
636a5d36 | 7360 | |
074ac8df | 7361 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7362 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7363 | return -EOPNOTSUPP; | |
eec60b03 | 7364 | |
19957bb3 | 7365 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7366 | |
664834de JM |
7367 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
7368 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7369 | if (!chan) | |
4c476991 | 7370 | return -EINVAL; |
636a5d36 | 7371 | |
19957bb3 JB |
7372 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7373 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
7374 | |
7375 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
7376 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7377 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7378 | } |
7379 | ||
dc6382ce | 7380 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 7381 | enum nl80211_mfp mfp = |
dc6382ce | 7382 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 7383 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 7384 | req.use_mfp = true; |
4c476991 JB |
7385 | else if (mfp != NL80211_MFP_NO) |
7386 | return -EINVAL; | |
dc6382ce JM |
7387 | } |
7388 | ||
3e5d7649 | 7389 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 7390 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 7391 | |
7e7c8926 | 7392 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 7393 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
7394 | |
7395 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
7396 | memcpy(&req.ht_capa_mask, |
7397 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7398 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
7399 | |
7400 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 7401 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 7402 | return -EINVAL; |
f62fab73 JB |
7403 | memcpy(&req.ht_capa, |
7404 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7405 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
7406 | } |
7407 | ||
ee2aca34 | 7408 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 7409 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
7410 | |
7411 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
7412 | memcpy(&req.vht_capa_mask, |
7413 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7414 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
7415 | |
7416 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 7417 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 7418 | return -EINVAL; |
f62fab73 JB |
7419 | memcpy(&req.vht_capa, |
7420 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7421 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
7422 | } |
7423 | ||
bab5ab7d | 7424 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
0c9ca11b BL |
7425 | if (!((rdev->wiphy.features & |
7426 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && | |
7427 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && | |
7428 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
7429 | NL80211_EXT_FEATURE_RRM)) | |
bab5ab7d AK |
7430 | return -EINVAL; |
7431 | req.flags |= ASSOC_REQ_USE_RRM; | |
7432 | } | |
7433 | ||
f62fab73 | 7434 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
7435 | if (!err) { |
7436 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
7437 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
7438 | ssid, ssid_len, &req); | |
91bf9b26 JB |
7439 | wdev_unlock(dev->ieee80211_ptr); |
7440 | } | |
636a5d36 | 7441 | |
636a5d36 JM |
7442 | return err; |
7443 | } | |
7444 | ||
7445 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
7446 | { | |
4c476991 JB |
7447 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7448 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7449 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7450 | int ie_len = 0, err; |
19957bb3 | 7451 | u16 reason_code; |
d5cdfacb | 7452 | bool local_state_change; |
636a5d36 | 7453 | |
f4a11bb0 JB |
7454 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7455 | return -EINVAL; | |
7456 | ||
7457 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7458 | return -EINVAL; | |
7459 | ||
7460 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7461 | return -EINVAL; | |
7462 | ||
4c476991 JB |
7463 | if (!rdev->ops->deauth) |
7464 | return -EOPNOTSUPP; | |
636a5d36 | 7465 | |
074ac8df | 7466 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7467 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7468 | return -EOPNOTSUPP; | |
eec60b03 | 7469 | |
19957bb3 | 7470 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7471 | |
19957bb3 JB |
7472 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7473 | if (reason_code == 0) { | |
f4a11bb0 | 7474 | /* Reason Code 0 is reserved */ |
4c476991 | 7475 | return -EINVAL; |
255e737e | 7476 | } |
636a5d36 JM |
7477 | |
7478 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7479 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7480 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7481 | } |
7482 | ||
d5cdfacb JM |
7483 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7484 | ||
91bf9b26 JB |
7485 | wdev_lock(dev->ieee80211_ptr); |
7486 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
7487 | local_state_change); | |
7488 | wdev_unlock(dev->ieee80211_ptr); | |
7489 | return err; | |
636a5d36 JM |
7490 | } |
7491 | ||
7492 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
7493 | { | |
4c476991 JB |
7494 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7495 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7496 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7497 | int ie_len = 0, err; |
19957bb3 | 7498 | u16 reason_code; |
d5cdfacb | 7499 | bool local_state_change; |
636a5d36 | 7500 | |
f4a11bb0 JB |
7501 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7502 | return -EINVAL; | |
7503 | ||
7504 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7505 | return -EINVAL; | |
7506 | ||
7507 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7508 | return -EINVAL; | |
7509 | ||
4c476991 JB |
7510 | if (!rdev->ops->disassoc) |
7511 | return -EOPNOTSUPP; | |
636a5d36 | 7512 | |
074ac8df | 7513 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7514 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7515 | return -EOPNOTSUPP; | |
eec60b03 | 7516 | |
19957bb3 | 7517 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7518 | |
19957bb3 JB |
7519 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7520 | if (reason_code == 0) { | |
f4a11bb0 | 7521 | /* Reason Code 0 is reserved */ |
4c476991 | 7522 | return -EINVAL; |
255e737e | 7523 | } |
636a5d36 JM |
7524 | |
7525 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7526 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7527 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7528 | } |
7529 | ||
d5cdfacb JM |
7530 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7531 | ||
91bf9b26 JB |
7532 | wdev_lock(dev->ieee80211_ptr); |
7533 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
7534 | local_state_change); | |
7535 | wdev_unlock(dev->ieee80211_ptr); | |
7536 | return err; | |
636a5d36 JM |
7537 | } |
7538 | ||
dd5b4cc7 FF |
7539 | static bool |
7540 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
7541 | int mcast_rate[IEEE80211_NUM_BANDS], | |
7542 | int rateval) | |
7543 | { | |
7544 | struct wiphy *wiphy = &rdev->wiphy; | |
7545 | bool found = false; | |
7546 | int band, i; | |
7547 | ||
7548 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
7549 | struct ieee80211_supported_band *sband; | |
7550 | ||
7551 | sband = wiphy->bands[band]; | |
7552 | if (!sband) | |
7553 | continue; | |
7554 | ||
7555 | for (i = 0; i < sband->n_bitrates; i++) { | |
7556 | if (sband->bitrates[i].bitrate == rateval) { | |
7557 | mcast_rate[band] = i + 1; | |
7558 | found = true; | |
7559 | break; | |
7560 | } | |
7561 | } | |
7562 | } | |
7563 | ||
7564 | return found; | |
7565 | } | |
7566 | ||
04a773ad JB |
7567 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
7568 | { | |
4c476991 JB |
7569 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7570 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
7571 | struct cfg80211_ibss_params ibss; |
7572 | struct wiphy *wiphy; | |
fffd0934 | 7573 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
7574 | int err; |
7575 | ||
8e30bc55 JB |
7576 | memset(&ibss, 0, sizeof(ibss)); |
7577 | ||
04a773ad JB |
7578 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7579 | return -EINVAL; | |
7580 | ||
683b6d3b | 7581 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
7582 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
7583 | return -EINVAL; | |
7584 | ||
8e30bc55 JB |
7585 | ibss.beacon_interval = 100; |
7586 | ||
7587 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
7588 | ibss.beacon_interval = | |
7589 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7590 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
7591 | return -EINVAL; | |
7592 | } | |
7593 | ||
4c476991 JB |
7594 | if (!rdev->ops->join_ibss) |
7595 | return -EOPNOTSUPP; | |
04a773ad | 7596 | |
4c476991 JB |
7597 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7598 | return -EOPNOTSUPP; | |
04a773ad | 7599 | |
79c97e97 | 7600 | wiphy = &rdev->wiphy; |
04a773ad | 7601 | |
39193498 | 7602 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 7603 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
7604 | |
7605 | if (!is_valid_ether_addr(ibss.bssid)) | |
7606 | return -EINVAL; | |
7607 | } | |
04a773ad JB |
7608 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7609 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7610 | ||
7611 | if (info->attrs[NL80211_ATTR_IE]) { | |
7612 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7613 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7614 | } | |
7615 | ||
683b6d3b JB |
7616 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
7617 | if (err) | |
7618 | return err; | |
04a773ad | 7619 | |
174e0cd2 IP |
7620 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
7621 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
7622 | return -EINVAL; |
7623 | ||
2f301ab2 | 7624 | switch (ibss.chandef.width) { |
bf372645 SW |
7625 | case NL80211_CHAN_WIDTH_5: |
7626 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
7627 | case NL80211_CHAN_WIDTH_20_NOHT: |
7628 | break; | |
7629 | case NL80211_CHAN_WIDTH_20: | |
7630 | case NL80211_CHAN_WIDTH_40: | |
ffc11991 JD |
7631 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
7632 | return -EINVAL; | |
7633 | break; | |
7634 | case NL80211_CHAN_WIDTH_80: | |
7635 | case NL80211_CHAN_WIDTH_80P80: | |
7636 | case NL80211_CHAN_WIDTH_160: | |
7637 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | |
7638 | return -EINVAL; | |
7639 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
7640 | NL80211_EXT_FEATURE_VHT_IBSS)) | |
7641 | return -EINVAL; | |
7642 | break; | |
2f301ab2 | 7643 | default: |
c04d6150 | 7644 | return -EINVAL; |
2f301ab2 | 7645 | } |
db9c64cf | 7646 | |
04a773ad | 7647 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
7648 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
7649 | ||
fbd2c8dc TP |
7650 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
7651 | u8 *rates = | |
7652 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7653 | int n_rates = | |
7654 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7655 | struct ieee80211_supported_band *sband = | |
683b6d3b | 7656 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 7657 | |
34850ab2 JB |
7658 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
7659 | &ibss.basic_rates); | |
7660 | if (err) | |
7661 | return err; | |
fbd2c8dc | 7662 | } |
dd5b4cc7 | 7663 | |
803768f5 SW |
7664 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7665 | memcpy(&ibss.ht_capa_mask, | |
7666 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7667 | sizeof(ibss.ht_capa_mask)); | |
7668 | ||
7669 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
7670 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7671 | return -EINVAL; | |
7672 | memcpy(&ibss.ht_capa, | |
7673 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7674 | sizeof(ibss.ht_capa)); | |
7675 | } | |
7676 | ||
dd5b4cc7 FF |
7677 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7678 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
7679 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7680 | return -EINVAL; | |
fbd2c8dc | 7681 | |
4c476991 | 7682 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
7683 | bool no_ht = false; |
7684 | ||
4c476991 | 7685 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
7686 | info->attrs[NL80211_ATTR_KEYS], |
7687 | &no_ht); | |
4c476991 JB |
7688 | if (IS_ERR(connkeys)) |
7689 | return PTR_ERR(connkeys); | |
de7044ee | 7690 | |
3d9d1d66 JB |
7691 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
7692 | no_ht) { | |
5e950a78 | 7693 | kzfree(connkeys); |
de7044ee SM |
7694 | return -EINVAL; |
7695 | } | |
4c476991 | 7696 | } |
04a773ad | 7697 | |
267335d6 AQ |
7698 | ibss.control_port = |
7699 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
7700 | ||
5336fa88 SW |
7701 | ibss.userspace_handles_dfs = |
7702 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
7703 | ||
4c476991 | 7704 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 | 7705 | if (err) |
b47f610b | 7706 | kzfree(connkeys); |
04a773ad JB |
7707 | return err; |
7708 | } | |
7709 | ||
7710 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
7711 | { | |
4c476991 JB |
7712 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7713 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 7714 | |
4c476991 JB |
7715 | if (!rdev->ops->leave_ibss) |
7716 | return -EOPNOTSUPP; | |
04a773ad | 7717 | |
4c476991 JB |
7718 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7719 | return -EOPNOTSUPP; | |
04a773ad | 7720 | |
4c476991 | 7721 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
7722 | } |
7723 | ||
f4e583c8 AQ |
7724 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
7725 | { | |
7726 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7727 | struct net_device *dev = info->user_ptr[1]; | |
7728 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
7729 | u32 nla_rate; | |
7730 | int err; | |
7731 | ||
7732 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
876dc930 BVB |
7733 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
7734 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) | |
f4e583c8 AQ |
7735 | return -EOPNOTSUPP; |
7736 | ||
7737 | if (!rdev->ops->set_mcast_rate) | |
7738 | return -EOPNOTSUPP; | |
7739 | ||
7740 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
7741 | ||
7742 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
7743 | return -EINVAL; | |
7744 | ||
7745 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
7746 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
7747 | return -EINVAL; | |
7748 | ||
a1056b1b | 7749 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
f4e583c8 AQ |
7750 | |
7751 | return err; | |
7752 | } | |
7753 | ||
ad7e718c JB |
7754 | static struct sk_buff * |
7755 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
6c09e791 AK |
7756 | struct wireless_dev *wdev, int approxlen, |
7757 | u32 portid, u32 seq, enum nl80211_commands cmd, | |
567ffc35 JB |
7758 | enum nl80211_attrs attr, |
7759 | const struct nl80211_vendor_cmd_info *info, | |
7760 | gfp_t gfp) | |
ad7e718c JB |
7761 | { |
7762 | struct sk_buff *skb; | |
7763 | void *hdr; | |
7764 | struct nlattr *data; | |
7765 | ||
7766 | skb = nlmsg_new(approxlen + 100, gfp); | |
7767 | if (!skb) | |
7768 | return NULL; | |
7769 | ||
7770 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
7771 | if (!hdr) { | |
7772 | kfree_skb(skb); | |
7773 | return NULL; | |
7774 | } | |
7775 | ||
7776 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
7777 | goto nla_put_failure; | |
567ffc35 JB |
7778 | |
7779 | if (info) { | |
7780 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
7781 | info->vendor_id)) | |
7782 | goto nla_put_failure; | |
7783 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
7784 | info->subcmd)) | |
7785 | goto nla_put_failure; | |
7786 | } | |
7787 | ||
6c09e791 AK |
7788 | if (wdev) { |
7789 | if (nla_put_u64(skb, NL80211_ATTR_WDEV, | |
7790 | wdev_id(wdev))) | |
7791 | goto nla_put_failure; | |
7792 | if (wdev->netdev && | |
7793 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, | |
7794 | wdev->netdev->ifindex)) | |
7795 | goto nla_put_failure; | |
7796 | } | |
7797 | ||
ad7e718c JB |
7798 | data = nla_nest_start(skb, attr); |
7799 | ||
7800 | ((void **)skb->cb)[0] = rdev; | |
7801 | ((void **)skb->cb)[1] = hdr; | |
7802 | ((void **)skb->cb)[2] = data; | |
7803 | ||
7804 | return skb; | |
7805 | ||
7806 | nla_put_failure: | |
7807 | kfree_skb(skb); | |
7808 | return NULL; | |
7809 | } | |
f4e583c8 | 7810 | |
e03ad6ea | 7811 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
6c09e791 | 7812 | struct wireless_dev *wdev, |
e03ad6ea JB |
7813 | enum nl80211_commands cmd, |
7814 | enum nl80211_attrs attr, | |
7815 | int vendor_event_idx, | |
7816 | int approxlen, gfp_t gfp) | |
7817 | { | |
f26cbf40 | 7818 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
7819 | const struct nl80211_vendor_cmd_info *info; |
7820 | ||
7821 | switch (cmd) { | |
7822 | case NL80211_CMD_TESTMODE: | |
7823 | if (WARN_ON(vendor_event_idx != -1)) | |
7824 | return NULL; | |
7825 | info = NULL; | |
7826 | break; | |
7827 | case NL80211_CMD_VENDOR: | |
7828 | if (WARN_ON(vendor_event_idx < 0 || | |
7829 | vendor_event_idx >= wiphy->n_vendor_events)) | |
7830 | return NULL; | |
7831 | info = &wiphy->vendor_events[vendor_event_idx]; | |
7832 | break; | |
7833 | default: | |
7834 | WARN_ON(1); | |
7835 | return NULL; | |
7836 | } | |
7837 | ||
6c09e791 | 7838 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
e03ad6ea JB |
7839 | cmd, attr, info, gfp); |
7840 | } | |
7841 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
7842 | ||
7843 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
7844 | { | |
7845 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
7846 | void *hdr = ((void **)skb->cb)[1]; | |
7847 | struct nlattr *data = ((void **)skb->cb)[2]; | |
7848 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
7849 | ||
bd8c78e7 JB |
7850 | /* clear CB data for netlink core to own from now on */ |
7851 | memset(skb->cb, 0, sizeof(skb->cb)); | |
7852 | ||
e03ad6ea JB |
7853 | nla_nest_end(skb, data); |
7854 | genlmsg_end(skb, hdr); | |
7855 | ||
7856 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
7857 | mcgrp = NL80211_MCGRP_VENDOR; | |
7858 | ||
7859 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
7860 | mcgrp, gfp); | |
7861 | } | |
7862 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
7863 | ||
aff89a9b | 7864 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
7865 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
7866 | { | |
4c476991 | 7867 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
7868 | struct wireless_dev *wdev = |
7869 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
7870 | int err; |
7871 | ||
fc73f11f DS |
7872 | if (!rdev->ops->testmode_cmd) |
7873 | return -EOPNOTSUPP; | |
7874 | ||
7875 | if (IS_ERR(wdev)) { | |
7876 | err = PTR_ERR(wdev); | |
7877 | if (err != -EINVAL) | |
7878 | return err; | |
7879 | wdev = NULL; | |
7880 | } else if (wdev->wiphy != &rdev->wiphy) { | |
7881 | return -EINVAL; | |
7882 | } | |
7883 | ||
aff89a9b JB |
7884 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
7885 | return -EINVAL; | |
7886 | ||
ad7e718c | 7887 | rdev->cur_cmd_info = info; |
fc73f11f | 7888 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
7889 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
7890 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 7891 | rdev->cur_cmd_info = NULL; |
aff89a9b | 7892 | |
aff89a9b JB |
7893 | return err; |
7894 | } | |
7895 | ||
71063f0e WYG |
7896 | static int nl80211_testmode_dump(struct sk_buff *skb, |
7897 | struct netlink_callback *cb) | |
7898 | { | |
00918d33 | 7899 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
7900 | int err; |
7901 | long phy_idx; | |
7902 | void *data = NULL; | |
7903 | int data_len = 0; | |
7904 | ||
5fe231e8 JB |
7905 | rtnl_lock(); |
7906 | ||
71063f0e WYG |
7907 | if (cb->args[0]) { |
7908 | /* | |
7909 | * 0 is a valid index, but not valid for args[0], | |
7910 | * so we need to offset by 1. | |
7911 | */ | |
7912 | phy_idx = cb->args[0] - 1; | |
7913 | } else { | |
7914 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
7915 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
7916 | nl80211_policy); | |
7917 | if (err) | |
5fe231e8 | 7918 | goto out_err; |
00918d33 | 7919 | |
2bd7e35d JB |
7920 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
7921 | nl80211_fam.attrbuf); | |
7922 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
7923 | err = PTR_ERR(rdev); |
7924 | goto out_err; | |
00918d33 | 7925 | } |
2bd7e35d JB |
7926 | phy_idx = rdev->wiphy_idx; |
7927 | rdev = NULL; | |
2bd7e35d | 7928 | |
71063f0e WYG |
7929 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
7930 | cb->args[1] = | |
7931 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
7932 | } | |
7933 | ||
7934 | if (cb->args[1]) { | |
7935 | data = nla_data((void *)cb->args[1]); | |
7936 | data_len = nla_len((void *)cb->args[1]); | |
7937 | } | |
7938 | ||
00918d33 JB |
7939 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
7940 | if (!rdev) { | |
5fe231e8 JB |
7941 | err = -ENOENT; |
7942 | goto out_err; | |
71063f0e | 7943 | } |
71063f0e | 7944 | |
00918d33 | 7945 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
7946 | err = -EOPNOTSUPP; |
7947 | goto out_err; | |
7948 | } | |
7949 | ||
7950 | while (1) { | |
15e47304 | 7951 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
7952 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
7953 | NL80211_CMD_TESTMODE); | |
7954 | struct nlattr *tmdata; | |
7955 | ||
cb35fba3 DC |
7956 | if (!hdr) |
7957 | break; | |
7958 | ||
9360ffd1 | 7959 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
7960 | genlmsg_cancel(skb, hdr); |
7961 | break; | |
7962 | } | |
7963 | ||
7964 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
7965 | if (!tmdata) { | |
7966 | genlmsg_cancel(skb, hdr); | |
7967 | break; | |
7968 | } | |
e35e4d28 | 7969 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
7970 | nla_nest_end(skb, tmdata); |
7971 | ||
7972 | if (err == -ENOBUFS || err == -ENOENT) { | |
7973 | genlmsg_cancel(skb, hdr); | |
7974 | break; | |
7975 | } else if (err) { | |
7976 | genlmsg_cancel(skb, hdr); | |
7977 | goto out_err; | |
7978 | } | |
7979 | ||
7980 | genlmsg_end(skb, hdr); | |
7981 | } | |
7982 | ||
7983 | err = skb->len; | |
7984 | /* see above */ | |
7985 | cb->args[0] = phy_idx + 1; | |
7986 | out_err: | |
5fe231e8 | 7987 | rtnl_unlock(); |
71063f0e WYG |
7988 | return err; |
7989 | } | |
aff89a9b JB |
7990 | #endif |
7991 | ||
b23aa676 SO |
7992 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
7993 | { | |
4c476991 JB |
7994 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7995 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
7996 | struct cfg80211_connect_params connect; |
7997 | struct wiphy *wiphy; | |
fffd0934 | 7998 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
7999 | int err; |
8000 | ||
8001 | memset(&connect, 0, sizeof(connect)); | |
8002 | ||
8003 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
8004 | return -EINVAL; | |
8005 | ||
8006 | if (!info->attrs[NL80211_ATTR_SSID] || | |
8007 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
8008 | return -EINVAL; | |
8009 | ||
8010 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
8011 | connect.auth_type = | |
8012 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
8013 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
8014 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
8015 | return -EINVAL; |
8016 | } else | |
8017 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
8018 | ||
8019 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
8020 | ||
c0692b8f | 8021 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 8022 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
8023 | if (err) |
8024 | return err; | |
b23aa676 | 8025 | |
074ac8df | 8026 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8027 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8028 | return -EOPNOTSUPP; | |
b23aa676 | 8029 | |
79c97e97 | 8030 | wiphy = &rdev->wiphy; |
b23aa676 | 8031 | |
4486ea98 BS |
8032 | connect.bg_scan_period = -1; |
8033 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
8034 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
8035 | connect.bg_scan_period = | |
8036 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
8037 | } | |
8038 | ||
b23aa676 SO |
8039 | if (info->attrs[NL80211_ATTR_MAC]) |
8040 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
8041 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
8042 | connect.bssid_hint = | |
8043 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
8044 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
8045 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
8046 | ||
8047 | if (info->attrs[NL80211_ATTR_IE]) { | |
8048 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8049 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8050 | } | |
8051 | ||
cee00a95 JM |
8052 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
8053 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
8054 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
8055 | connect.mfp != NL80211_MFP_NO) | |
8056 | return -EINVAL; | |
8057 | } else { | |
8058 | connect.mfp = NL80211_MFP_NO; | |
8059 | } | |
8060 | ||
b23aa676 | 8061 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
8062 | connect.channel = nl80211_get_valid_chan( |
8063 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
8064 | if (!connect.channel) | |
1df4a510 JM |
8065 | return -EINVAL; |
8066 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
8067 | connect.channel_hint = nl80211_get_valid_chan( |
8068 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
8069 | if (!connect.channel_hint) | |
4c476991 | 8070 | return -EINVAL; |
b23aa676 SO |
8071 | } |
8072 | ||
fffd0934 JB |
8073 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
8074 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 8075 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
8076 | if (IS_ERR(connkeys)) |
8077 | return PTR_ERR(connkeys); | |
fffd0934 JB |
8078 | } |
8079 | ||
7e7c8926 BG |
8080 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
8081 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
8082 | ||
8083 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
8084 | memcpy(&connect.ht_capa_mask, | |
8085 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
8086 | sizeof(connect.ht_capa_mask)); | |
8087 | ||
8088 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e | 8089 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
b47f610b | 8090 | kzfree(connkeys); |
7e7c8926 | 8091 | return -EINVAL; |
b4e4f47e | 8092 | } |
7e7c8926 BG |
8093 | memcpy(&connect.ht_capa, |
8094 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
8095 | sizeof(connect.ht_capa)); | |
8096 | } | |
8097 | ||
ee2aca34 JB |
8098 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
8099 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
8100 | ||
8101 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
8102 | memcpy(&connect.vht_capa_mask, | |
8103 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
8104 | sizeof(connect.vht_capa_mask)); | |
8105 | ||
8106 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
8107 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
b47f610b | 8108 | kzfree(connkeys); |
ee2aca34 JB |
8109 | return -EINVAL; |
8110 | } | |
8111 | memcpy(&connect.vht_capa, | |
8112 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
8113 | sizeof(connect.vht_capa)); | |
8114 | } | |
8115 | ||
bab5ab7d | 8116 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
0c9ca11b BL |
8117 | if (!((rdev->wiphy.features & |
8118 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && | |
8119 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && | |
8120 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
8121 | NL80211_EXT_FEATURE_RRM)) { | |
707554b4 | 8122 | kzfree(connkeys); |
bab5ab7d | 8123 | return -EINVAL; |
707554b4 | 8124 | } |
bab5ab7d AK |
8125 | connect.flags |= ASSOC_REQ_USE_RRM; |
8126 | } | |
8127 | ||
34d50519 LD |
8128 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
8129 | if (connect.pbss && !rdev->wiphy.bands[IEEE80211_BAND_60GHZ]) { | |
8130 | kzfree(connkeys); | |
8131 | return -EOPNOTSUPP; | |
8132 | } | |
8133 | ||
38de03d2 AS |
8134 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
8135 | /* bss selection makes no sense if bssid is set */ | |
8136 | if (connect.bssid) { | |
8137 | kzfree(connkeys); | |
8138 | return -EINVAL; | |
8139 | } | |
8140 | ||
8141 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], | |
8142 | wiphy, &connect.bss_select); | |
8143 | if (err) { | |
8144 | kzfree(connkeys); | |
8145 | return err; | |
8146 | } | |
8147 | } | |
8148 | ||
83739b03 JB |
8149 | wdev_lock(dev->ieee80211_ptr); |
8150 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
8151 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 | 8152 | if (err) |
b47f610b | 8153 | kzfree(connkeys); |
b23aa676 SO |
8154 | return err; |
8155 | } | |
8156 | ||
8157 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
8158 | { | |
4c476991 JB |
8159 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8160 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 8161 | u16 reason; |
83739b03 | 8162 | int ret; |
b23aa676 SO |
8163 | |
8164 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
8165 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
8166 | else | |
8167 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
8168 | ||
8169 | if (reason == 0) | |
8170 | return -EINVAL; | |
8171 | ||
074ac8df | 8172 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8173 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8174 | return -EOPNOTSUPP; | |
b23aa676 | 8175 | |
83739b03 JB |
8176 | wdev_lock(dev->ieee80211_ptr); |
8177 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
8178 | wdev_unlock(dev->ieee80211_ptr); | |
8179 | return ret; | |
b23aa676 SO |
8180 | } |
8181 | ||
463d0183 JB |
8182 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
8183 | { | |
4c476991 | 8184 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
8185 | struct net *net; |
8186 | int err; | |
463d0183 | 8187 | |
4b681c82 VK |
8188 | if (info->attrs[NL80211_ATTR_PID]) { |
8189 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
8190 | ||
8191 | net = get_net_ns_by_pid(pid); | |
8192 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { | |
8193 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); | |
463d0183 | 8194 | |
4b681c82 VK |
8195 | net = get_net_ns_by_fd(fd); |
8196 | } else { | |
8197 | return -EINVAL; | |
8198 | } | |
463d0183 | 8199 | |
4c476991 JB |
8200 | if (IS_ERR(net)) |
8201 | return PTR_ERR(net); | |
463d0183 JB |
8202 | |
8203 | err = 0; | |
8204 | ||
8205 | /* check if anything to do */ | |
4c476991 JB |
8206 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
8207 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 8208 | |
463d0183 | 8209 | put_net(net); |
463d0183 JB |
8210 | return err; |
8211 | } | |
8212 | ||
67fbb16b SO |
8213 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
8214 | { | |
4c476991 | 8215 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
8216 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
8217 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 8218 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
8219 | struct cfg80211_pmksa pmksa; |
8220 | ||
8221 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
8222 | ||
8223 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8224 | return -EINVAL; | |
8225 | ||
8226 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
8227 | return -EINVAL; | |
8228 | ||
67fbb16b SO |
8229 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
8230 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8231 | ||
074ac8df | 8232 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8233 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8234 | return -EOPNOTSUPP; | |
67fbb16b SO |
8235 | |
8236 | switch (info->genlhdr->cmd) { | |
8237 | case NL80211_CMD_SET_PMKSA: | |
8238 | rdev_ops = rdev->ops->set_pmksa; | |
8239 | break; | |
8240 | case NL80211_CMD_DEL_PMKSA: | |
8241 | rdev_ops = rdev->ops->del_pmksa; | |
8242 | break; | |
8243 | default: | |
8244 | WARN_ON(1); | |
8245 | break; | |
8246 | } | |
8247 | ||
4c476991 JB |
8248 | if (!rdev_ops) |
8249 | return -EOPNOTSUPP; | |
67fbb16b | 8250 | |
4c476991 | 8251 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
8252 | } |
8253 | ||
8254 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
8255 | { | |
4c476991 JB |
8256 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8257 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 8258 | |
074ac8df | 8259 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8260 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8261 | return -EOPNOTSUPP; | |
67fbb16b | 8262 | |
4c476991 JB |
8263 | if (!rdev->ops->flush_pmksa) |
8264 | return -EOPNOTSUPP; | |
67fbb16b | 8265 | |
e35e4d28 | 8266 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
8267 | } |
8268 | ||
109086ce AN |
8269 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
8270 | { | |
8271 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8272 | struct net_device *dev = info->user_ptr[1]; | |
8273 | u8 action_code, dialog_token; | |
df942e7b | 8274 | u32 peer_capability = 0; |
109086ce AN |
8275 | u16 status_code; |
8276 | u8 *peer; | |
31fa97c5 | 8277 | bool initiator; |
109086ce AN |
8278 | |
8279 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
8280 | !rdev->ops->tdls_mgmt) | |
8281 | return -EOPNOTSUPP; | |
8282 | ||
8283 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
8284 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
8285 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
8286 | !info->attrs[NL80211_ATTR_IE] || | |
8287 | !info->attrs[NL80211_ATTR_MAC]) | |
8288 | return -EINVAL; | |
8289 | ||
8290 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8291 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
8292 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
8293 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 8294 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
8295 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
8296 | peer_capability = | |
8297 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 8298 | |
e35e4d28 | 8299 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 8300 | dialog_token, status_code, peer_capability, |
31fa97c5 | 8301 | initiator, |
e35e4d28 HG |
8302 | nla_data(info->attrs[NL80211_ATTR_IE]), |
8303 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
8304 | } |
8305 | ||
8306 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
8307 | { | |
8308 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8309 | struct net_device *dev = info->user_ptr[1]; | |
8310 | enum nl80211_tdls_operation operation; | |
8311 | u8 *peer; | |
8312 | ||
8313 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
8314 | !rdev->ops->tdls_oper) | |
8315 | return -EOPNOTSUPP; | |
8316 | ||
8317 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
8318 | !info->attrs[NL80211_ATTR_MAC]) | |
8319 | return -EINVAL; | |
8320 | ||
8321 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
8322 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8323 | ||
e35e4d28 | 8324 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
8325 | } |
8326 | ||
9588bbd5 JM |
8327 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
8328 | struct genl_info *info) | |
8329 | { | |
4c476991 | 8330 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8331 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 8332 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
8333 | struct sk_buff *msg; |
8334 | void *hdr; | |
8335 | u64 cookie; | |
683b6d3b | 8336 | u32 duration; |
9588bbd5 JM |
8337 | int err; |
8338 | ||
8339 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
8340 | !info->attrs[NL80211_ATTR_DURATION]) | |
8341 | return -EINVAL; | |
8342 | ||
8343 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
8344 | ||
ebf348fc JB |
8345 | if (!rdev->ops->remain_on_channel || |
8346 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
8347 | return -EOPNOTSUPP; | |
8348 | ||
9588bbd5 | 8349 | /* |
ebf348fc JB |
8350 | * We should be on that channel for at least a minimum amount of |
8351 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 8352 | */ |
ebf348fc | 8353 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 8354 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
8355 | return -EINVAL; |
8356 | ||
683b6d3b JB |
8357 | err = nl80211_parse_chandef(rdev, info, &chandef); |
8358 | if (err) | |
8359 | return err; | |
9588bbd5 JM |
8360 | |
8361 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
8362 | if (!msg) |
8363 | return -ENOMEM; | |
9588bbd5 | 8364 | |
15e47304 | 8365 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 8366 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
8367 | if (!hdr) { |
8368 | err = -ENOBUFS; | |
9588bbd5 JM |
8369 | goto free_msg; |
8370 | } | |
8371 | ||
683b6d3b JB |
8372 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
8373 | duration, &cookie); | |
9588bbd5 JM |
8374 | |
8375 | if (err) | |
8376 | goto free_msg; | |
8377 | ||
9360ffd1 DM |
8378 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8379 | goto nla_put_failure; | |
9588bbd5 JM |
8380 | |
8381 | genlmsg_end(msg, hdr); | |
4c476991 JB |
8382 | |
8383 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
8384 | |
8385 | nla_put_failure: | |
8386 | err = -ENOBUFS; | |
8387 | free_msg: | |
8388 | nlmsg_free(msg); | |
9588bbd5 JM |
8389 | return err; |
8390 | } | |
8391 | ||
8392 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
8393 | struct genl_info *info) | |
8394 | { | |
4c476991 | 8395 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8396 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 8397 | u64 cookie; |
9588bbd5 JM |
8398 | |
8399 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8400 | return -EINVAL; | |
8401 | ||
4c476991 JB |
8402 | if (!rdev->ops->cancel_remain_on_channel) |
8403 | return -EOPNOTSUPP; | |
9588bbd5 | 8404 | |
9588bbd5 JM |
8405 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
8406 | ||
e35e4d28 | 8407 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
8408 | } |
8409 | ||
13ae75b1 JM |
8410 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
8411 | u8 *rates, u8 rates_len) | |
8412 | { | |
8413 | u8 i; | |
8414 | u32 mask = 0; | |
8415 | ||
8416 | for (i = 0; i < rates_len; i++) { | |
8417 | int rate = (rates[i] & 0x7f) * 5; | |
8418 | int ridx; | |
8419 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
8420 | struct ieee80211_rate *srate = | |
8421 | &sband->bitrates[ridx]; | |
8422 | if (rate == srate->bitrate) { | |
8423 | mask |= 1 << ridx; | |
8424 | break; | |
8425 | } | |
8426 | } | |
8427 | if (ridx == sband->n_bitrates) | |
8428 | return 0; /* rate not found */ | |
8429 | } | |
8430 | ||
8431 | return mask; | |
8432 | } | |
8433 | ||
24db78c0 SW |
8434 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
8435 | u8 *rates, u8 rates_len, | |
8436 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
8437 | { | |
8438 | u8 i; | |
8439 | ||
8440 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
8441 | ||
8442 | for (i = 0; i < rates_len; i++) { | |
8443 | int ridx, rbit; | |
8444 | ||
8445 | ridx = rates[i] / 8; | |
8446 | rbit = BIT(rates[i] % 8); | |
8447 | ||
8448 | /* check validity */ | |
910570b5 | 8449 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
8450 | return false; |
8451 | ||
8452 | /* check availability */ | |
8453 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
8454 | mcs[ridx] |= rbit; | |
8455 | else | |
8456 | return false; | |
8457 | } | |
8458 | ||
8459 | return true; | |
8460 | } | |
8461 | ||
204e35a9 JD |
8462 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
8463 | { | |
8464 | u16 mcs_mask = 0; | |
8465 | ||
8466 | switch (vht_mcs_map) { | |
8467 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
8468 | break; | |
8469 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
8470 | mcs_mask = 0x00FF; | |
8471 | break; | |
8472 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
8473 | mcs_mask = 0x01FF; | |
8474 | break; | |
8475 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
8476 | mcs_mask = 0x03FF; | |
8477 | break; | |
8478 | default: | |
8479 | break; | |
8480 | } | |
8481 | ||
8482 | return mcs_mask; | |
8483 | } | |
8484 | ||
8485 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
8486 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
8487 | { | |
8488 | u8 nss; | |
8489 | ||
8490 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
8491 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
8492 | vht_mcs_map >>= 2; | |
8493 | } | |
8494 | } | |
8495 | ||
8496 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
8497 | struct nl80211_txrate_vht *txrate, | |
8498 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
8499 | { | |
8500 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8501 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
8502 | u8 i; | |
8503 | ||
8504 | if (!sband->vht_cap.vht_supported) | |
8505 | return false; | |
8506 | ||
8507 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
8508 | ||
8509 | /* Build vht_mcs_mask from VHT capabilities */ | |
8510 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
8511 | ||
8512 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
8513 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
8514 | mcs[i] = txrate->mcs[i]; | |
8515 | else | |
8516 | return false; | |
8517 | } | |
8518 | ||
8519 | return true; | |
8520 | } | |
8521 | ||
b54452b0 | 8522 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
8523 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
8524 | .len = NL80211_MAX_SUPP_RATES }, | |
d1e33e65 JD |
8525 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
8526 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
204e35a9 | 8527 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
0b9323f6 | 8528 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
13ae75b1 JM |
8529 | }; |
8530 | ||
8531 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
8532 | struct genl_info *info) | |
8533 | { | |
8534 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 8535 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 8536 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
8537 | int rem, i; |
8538 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
8539 | struct nlattr *tx_rates; |
8540 | struct ieee80211_supported_band *sband; | |
204e35a9 | 8541 | u16 vht_tx_mcs_map; |
13ae75b1 | 8542 | |
4c476991 JB |
8543 | if (!rdev->ops->set_bitrate_mask) |
8544 | return -EOPNOTSUPP; | |
13ae75b1 JM |
8545 | |
8546 | memset(&mask, 0, sizeof(mask)); | |
8547 | /* Default to all rates enabled */ | |
8548 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
8549 | sband = rdev->wiphy.bands[i]; | |
7869303b JD |
8550 | |
8551 | if (!sband) | |
8552 | continue; | |
8553 | ||
8554 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; | |
d1e33e65 | 8555 | memcpy(mask.control[i].ht_mcs, |
7869303b | 8556 | sband->ht_cap.mcs.rx_mask, |
d1e33e65 | 8557 | sizeof(mask.control[i].ht_mcs)); |
204e35a9 JD |
8558 | |
8559 | if (!sband->vht_cap.vht_supported) | |
8560 | continue; | |
8561 | ||
8562 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8563 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); | |
13ae75b1 JM |
8564 | } |
8565 | ||
b9243ab0 JD |
8566 | /* if no rates are given set it back to the defaults */ |
8567 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
8568 | goto out; | |
8569 | ||
13ae75b1 JM |
8570 | /* |
8571 | * The nested attribute uses enum nl80211_band as the index. This maps | |
8572 | * directly to the enum ieee80211_band values used in cfg80211. | |
8573 | */ | |
24db78c0 | 8574 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
ae811e21 | 8575 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
13ae75b1 | 8576 | enum ieee80211_band band = nla_type(tx_rates); |
ae811e21 JB |
8577 | int err; |
8578 | ||
4c476991 JB |
8579 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
8580 | return -EINVAL; | |
13ae75b1 | 8581 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
8582 | if (sband == NULL) |
8583 | return -EINVAL; | |
ae811e21 JB |
8584 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
8585 | nla_len(tx_rates), nl80211_txattr_policy); | |
8586 | if (err) | |
8587 | return err; | |
13ae75b1 JM |
8588 | if (tb[NL80211_TXRATE_LEGACY]) { |
8589 | mask.control[band].legacy = rateset_to_mask( | |
8590 | sband, | |
8591 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
8592 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
8593 | if ((mask.control[band].legacy == 0) && |
8594 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
8595 | return -EINVAL; | |
24db78c0 | 8596 | } |
d1e33e65 | 8597 | if (tb[NL80211_TXRATE_HT]) { |
24db78c0 SW |
8598 | if (!ht_rateset_to_mask( |
8599 | sband, | |
d1e33e65 JD |
8600 | nla_data(tb[NL80211_TXRATE_HT]), |
8601 | nla_len(tb[NL80211_TXRATE_HT]), | |
8602 | mask.control[band].ht_mcs)) | |
24db78c0 SW |
8603 | return -EINVAL; |
8604 | } | |
204e35a9 JD |
8605 | if (tb[NL80211_TXRATE_VHT]) { |
8606 | if (!vht_set_mcs_mask( | |
8607 | sband, | |
8608 | nla_data(tb[NL80211_TXRATE_VHT]), | |
8609 | mask.control[band].vht_mcs)) | |
8610 | return -EINVAL; | |
8611 | } | |
0b9323f6 JD |
8612 | if (tb[NL80211_TXRATE_GI]) { |
8613 | mask.control[band].gi = | |
8614 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
8615 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
8616 | return -EINVAL; | |
8617 | } | |
24db78c0 SW |
8618 | |
8619 | if (mask.control[band].legacy == 0) { | |
204e35a9 JD |
8620 | /* don't allow empty legacy rates if HT or VHT |
8621 | * are not even supported. | |
8622 | */ | |
8623 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
8624 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
24db78c0 SW |
8625 | return -EINVAL; |
8626 | ||
8627 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
d1e33e65 | 8628 | if (mask.control[band].ht_mcs[i]) |
204e35a9 JD |
8629 | goto out; |
8630 | ||
8631 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
8632 | if (mask.control[band].vht_mcs[i]) | |
8633 | goto out; | |
24db78c0 SW |
8634 | |
8635 | /* legacy and mcs rates may not be both empty */ | |
204e35a9 | 8636 | return -EINVAL; |
13ae75b1 JM |
8637 | } |
8638 | } | |
8639 | ||
b9243ab0 | 8640 | out: |
e35e4d28 | 8641 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
8642 | } |
8643 | ||
2e161f78 | 8644 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8645 | { |
4c476991 | 8646 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8647 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 8648 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
8649 | |
8650 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
8651 | return -EINVAL; | |
8652 | ||
2e161f78 JB |
8653 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
8654 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 8655 | |
71bbc994 JB |
8656 | switch (wdev->iftype) { |
8657 | case NL80211_IFTYPE_STATION: | |
8658 | case NL80211_IFTYPE_ADHOC: | |
8659 | case NL80211_IFTYPE_P2P_CLIENT: | |
8660 | case NL80211_IFTYPE_AP: | |
8661 | case NL80211_IFTYPE_AP_VLAN: | |
8662 | case NL80211_IFTYPE_MESH_POINT: | |
8663 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8664 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8665 | break; |
8666 | default: | |
4c476991 | 8667 | return -EOPNOTSUPP; |
71bbc994 | 8668 | } |
026331c4 JM |
8669 | |
8670 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
8671 | if (!rdev->ops->mgmt_tx) |
8672 | return -EOPNOTSUPP; | |
026331c4 | 8673 | |
15e47304 | 8674 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
8675 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
8676 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
8677 | } |
8678 | ||
2e161f78 | 8679 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8680 | { |
4c476991 | 8681 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8682 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 8683 | struct cfg80211_chan_def chandef; |
026331c4 | 8684 | int err; |
d64d373f | 8685 | void *hdr = NULL; |
026331c4 | 8686 | u64 cookie; |
e247bd90 | 8687 | struct sk_buff *msg = NULL; |
b176e629 AO |
8688 | struct cfg80211_mgmt_tx_params params = { |
8689 | .dont_wait_for_ack = | |
8690 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
8691 | }; | |
026331c4 | 8692 | |
683b6d3b | 8693 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
8694 | return -EINVAL; |
8695 | ||
4c476991 JB |
8696 | if (!rdev->ops->mgmt_tx) |
8697 | return -EOPNOTSUPP; | |
026331c4 | 8698 | |
71bbc994 | 8699 | switch (wdev->iftype) { |
ea141b75 AQ |
8700 | case NL80211_IFTYPE_P2P_DEVICE: |
8701 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
8702 | return -EINVAL; | |
71bbc994 JB |
8703 | case NL80211_IFTYPE_STATION: |
8704 | case NL80211_IFTYPE_ADHOC: | |
8705 | case NL80211_IFTYPE_P2P_CLIENT: | |
8706 | case NL80211_IFTYPE_AP: | |
8707 | case NL80211_IFTYPE_AP_VLAN: | |
8708 | case NL80211_IFTYPE_MESH_POINT: | |
8709 | case NL80211_IFTYPE_P2P_GO: | |
8710 | break; | |
8711 | default: | |
4c476991 | 8712 | return -EOPNOTSUPP; |
71bbc994 | 8713 | } |
026331c4 | 8714 | |
f7ca38df | 8715 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 8716 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 8717 | return -EINVAL; |
b176e629 | 8718 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
8719 | |
8720 | /* | |
8721 | * We should wait on the channel for at least a minimum amount | |
8722 | * of time (10ms) but no longer than the driver supports. | |
8723 | */ | |
b176e629 AO |
8724 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
8725 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc JB |
8726 | return -EINVAL; |
8727 | ||
f7ca38df JB |
8728 | } |
8729 | ||
b176e629 | 8730 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 8731 | |
b176e629 | 8732 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
8733 | return -EINVAL; |
8734 | ||
b176e629 | 8735 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 8736 | |
ea141b75 AQ |
8737 | /* get the channel if any has been specified, otherwise pass NULL to |
8738 | * the driver. The latter will use the current one | |
8739 | */ | |
8740 | chandef.chan = NULL; | |
8741 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
8742 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
8743 | if (err) | |
8744 | return err; | |
8745 | } | |
8746 | ||
b176e629 | 8747 | if (!chandef.chan && params.offchan) |
ea141b75 | 8748 | return -EINVAL; |
026331c4 | 8749 | |
34d22ce2 AO |
8750 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
8751 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
8752 | ||
8753 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
8754 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8755 | int i; | |
8756 | ||
8757 | if (len % sizeof(u16)) | |
8758 | return -EINVAL; | |
8759 | ||
8760 | params.n_csa_offsets = len / sizeof(u16); | |
8761 | params.csa_offsets = | |
8762 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8763 | ||
8764 | /* check that all the offsets fit the frame */ | |
8765 | for (i = 0; i < params.n_csa_offsets; i++) { | |
8766 | if (params.csa_offsets[i] >= params.len) | |
8767 | return -EINVAL; | |
8768 | } | |
8769 | } | |
8770 | ||
b176e629 | 8771 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
8772 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
8773 | if (!msg) | |
8774 | return -ENOMEM; | |
026331c4 | 8775 | |
15e47304 | 8776 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 8777 | NL80211_CMD_FRAME); |
cb35fba3 DC |
8778 | if (!hdr) { |
8779 | err = -ENOBUFS; | |
e247bd90 JB |
8780 | goto free_msg; |
8781 | } | |
026331c4 | 8782 | } |
e247bd90 | 8783 | |
b176e629 AO |
8784 | params.chan = chandef.chan; |
8785 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
8786 | if (err) |
8787 | goto free_msg; | |
8788 | ||
e247bd90 | 8789 | if (msg) { |
9360ffd1 DM |
8790 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8791 | goto nla_put_failure; | |
026331c4 | 8792 | |
e247bd90 JB |
8793 | genlmsg_end(msg, hdr); |
8794 | return genlmsg_reply(msg, info); | |
8795 | } | |
8796 | ||
8797 | return 0; | |
026331c4 JM |
8798 | |
8799 | nla_put_failure: | |
8800 | err = -ENOBUFS; | |
8801 | free_msg: | |
8802 | nlmsg_free(msg); | |
026331c4 JM |
8803 | return err; |
8804 | } | |
8805 | ||
f7ca38df JB |
8806 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
8807 | { | |
8808 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 8809 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
8810 | u64 cookie; |
8811 | ||
8812 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8813 | return -EINVAL; | |
8814 | ||
8815 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
8816 | return -EOPNOTSUPP; | |
8817 | ||
71bbc994 JB |
8818 | switch (wdev->iftype) { |
8819 | case NL80211_IFTYPE_STATION: | |
8820 | case NL80211_IFTYPE_ADHOC: | |
8821 | case NL80211_IFTYPE_P2P_CLIENT: | |
8822 | case NL80211_IFTYPE_AP: | |
8823 | case NL80211_IFTYPE_AP_VLAN: | |
8824 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8825 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8826 | break; |
8827 | default: | |
f7ca38df | 8828 | return -EOPNOTSUPP; |
71bbc994 | 8829 | } |
f7ca38df JB |
8830 | |
8831 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
8832 | ||
e35e4d28 | 8833 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
8834 | } |
8835 | ||
ffb9eb3d KV |
8836 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
8837 | { | |
4c476991 | 8838 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 8839 | struct wireless_dev *wdev; |
4c476991 | 8840 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8841 | u8 ps_state; |
8842 | bool state; | |
8843 | int err; | |
8844 | ||
4c476991 JB |
8845 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
8846 | return -EINVAL; | |
ffb9eb3d KV |
8847 | |
8848 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
8849 | ||
4c476991 JB |
8850 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
8851 | return -EINVAL; | |
ffb9eb3d KV |
8852 | |
8853 | wdev = dev->ieee80211_ptr; | |
8854 | ||
4c476991 JB |
8855 | if (!rdev->ops->set_power_mgmt) |
8856 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8857 | |
8858 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
8859 | ||
8860 | if (state == wdev->ps) | |
4c476991 | 8861 | return 0; |
ffb9eb3d | 8862 | |
e35e4d28 | 8863 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
8864 | if (!err) |
8865 | wdev->ps = state; | |
ffb9eb3d KV |
8866 | return err; |
8867 | } | |
8868 | ||
8869 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
8870 | { | |
4c476991 | 8871 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
8872 | enum nl80211_ps_state ps_state; |
8873 | struct wireless_dev *wdev; | |
4c476991 | 8874 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8875 | struct sk_buff *msg; |
8876 | void *hdr; | |
8877 | int err; | |
8878 | ||
ffb9eb3d KV |
8879 | wdev = dev->ieee80211_ptr; |
8880 | ||
4c476991 JB |
8881 | if (!rdev->ops->set_power_mgmt) |
8882 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8883 | |
8884 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
8885 | if (!msg) |
8886 | return -ENOMEM; | |
ffb9eb3d | 8887 | |
15e47304 | 8888 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
8889 | NL80211_CMD_GET_POWER_SAVE); |
8890 | if (!hdr) { | |
4c476991 | 8891 | err = -ENOBUFS; |
ffb9eb3d KV |
8892 | goto free_msg; |
8893 | } | |
8894 | ||
8895 | if (wdev->ps) | |
8896 | ps_state = NL80211_PS_ENABLED; | |
8897 | else | |
8898 | ps_state = NL80211_PS_DISABLED; | |
8899 | ||
9360ffd1 DM |
8900 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
8901 | goto nla_put_failure; | |
ffb9eb3d KV |
8902 | |
8903 | genlmsg_end(msg, hdr); | |
4c476991 | 8904 | return genlmsg_reply(msg, info); |
ffb9eb3d | 8905 | |
4c476991 | 8906 | nla_put_failure: |
ffb9eb3d | 8907 | err = -ENOBUFS; |
4c476991 | 8908 | free_msg: |
ffb9eb3d | 8909 | nlmsg_free(msg); |
ffb9eb3d KV |
8910 | return err; |
8911 | } | |
8912 | ||
94e860f1 JB |
8913 | static const struct nla_policy |
8914 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
8915 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
8916 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
8917 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
8918 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
8919 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
8920 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
8921 | }; |
8922 | ||
84f10708 | 8923 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 8924 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
8925 | { |
8926 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 8927 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8928 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 8929 | |
d9d8b019 | 8930 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
8931 | return -EINVAL; |
8932 | ||
84f10708 TP |
8933 | if (!rdev->ops->set_cqm_txe_config) |
8934 | return -EOPNOTSUPP; | |
8935 | ||
8936 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
8937 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
8938 | return -EOPNOTSUPP; | |
8939 | ||
e35e4d28 | 8940 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
8941 | } |
8942 | ||
d6dc1a38 JO |
8943 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
8944 | s32 threshold, u32 hysteresis) | |
8945 | { | |
4c476991 | 8946 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 8947 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8948 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
8949 | |
8950 | if (threshold > 0) | |
8951 | return -EINVAL; | |
8952 | ||
1da5fcc8 JB |
8953 | /* disabling - hysteresis should also be zero then */ |
8954 | if (threshold == 0) | |
8955 | hysteresis = 0; | |
d6dc1a38 | 8956 | |
4c476991 JB |
8957 | if (!rdev->ops->set_cqm_rssi_config) |
8958 | return -EOPNOTSUPP; | |
d6dc1a38 | 8959 | |
074ac8df | 8960 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8961 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8962 | return -EOPNOTSUPP; | |
d6dc1a38 | 8963 | |
e35e4d28 | 8964 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
8965 | } |
8966 | ||
8967 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
8968 | { | |
8969 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
8970 | struct nlattr *cqm; | |
8971 | int err; | |
8972 | ||
8973 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
8974 | if (!cqm) |
8975 | return -EINVAL; | |
d6dc1a38 JO |
8976 | |
8977 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
8978 | nl80211_attr_cqm_policy); | |
8979 | if (err) | |
1da5fcc8 | 8980 | return err; |
d6dc1a38 JO |
8981 | |
8982 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
8983 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
8984 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
8985 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 8986 | |
1da5fcc8 JB |
8987 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
8988 | } | |
8989 | ||
8990 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
8991 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
8992 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
8993 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
8994 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
8995 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
8996 | ||
8997 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
8998 | } | |
8999 | ||
9000 | return -EINVAL; | |
d6dc1a38 JO |
9001 | } |
9002 | ||
6e0bd6c3 RL |
9003 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
9004 | { | |
9005 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9006 | struct net_device *dev = info->user_ptr[1]; | |
9007 | struct ocb_setup setup = {}; | |
9008 | int err; | |
9009 | ||
9010 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | |
9011 | if (err) | |
9012 | return err; | |
9013 | ||
9014 | return cfg80211_join_ocb(rdev, dev, &setup); | |
9015 | } | |
9016 | ||
9017 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | |
9018 | { | |
9019 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9020 | struct net_device *dev = info->user_ptr[1]; | |
9021 | ||
9022 | return cfg80211_leave_ocb(rdev, dev); | |
9023 | } | |
9024 | ||
29cbe68c JB |
9025 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
9026 | { | |
9027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9028 | struct net_device *dev = info->user_ptr[1]; | |
9029 | struct mesh_config cfg; | |
c80d545d | 9030 | struct mesh_setup setup; |
29cbe68c JB |
9031 | int err; |
9032 | ||
9033 | /* start with default */ | |
9034 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 9035 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 9036 | |
24bdd9f4 | 9037 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 9038 | /* and parse parameters if given */ |
24bdd9f4 | 9039 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
9040 | if (err) |
9041 | return err; | |
9042 | } | |
9043 | ||
9044 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
9045 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
9046 | return -EINVAL; | |
9047 | ||
c80d545d JC |
9048 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
9049 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
9050 | ||
4bb62344 CYY |
9051 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
9052 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
9053 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
9054 | return -EINVAL; | |
9055 | ||
9bdbf04d MP |
9056 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
9057 | setup.beacon_interval = | |
9058 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
9059 | if (setup.beacon_interval < 10 || | |
9060 | setup.beacon_interval > 10000) | |
9061 | return -EINVAL; | |
9062 | } | |
9063 | ||
9064 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
9065 | setup.dtim_period = | |
9066 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
9067 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
9068 | return -EINVAL; | |
9069 | } | |
9070 | ||
c80d545d JC |
9071 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
9072 | /* parse additional setup parameters if given */ | |
9073 | err = nl80211_parse_mesh_setup(info, &setup); | |
9074 | if (err) | |
9075 | return err; | |
9076 | } | |
9077 | ||
d37bb18a TP |
9078 | if (setup.user_mpm) |
9079 | cfg.auto_open_plinks = false; | |
9080 | ||
cc1d2806 | 9081 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
9082 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
9083 | if (err) | |
9084 | return err; | |
cc1d2806 JB |
9085 | } else { |
9086 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 9087 | setup.chandef.chan = NULL; |
cc1d2806 JB |
9088 | } |
9089 | ||
ffb3cf30 AN |
9090 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
9091 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
9092 | int n_rates = | |
9093 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
9094 | struct ieee80211_supported_band *sband; | |
9095 | ||
9096 | if (!setup.chandef.chan) | |
9097 | return -EINVAL; | |
9098 | ||
9099 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
9100 | ||
9101 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
9102 | &setup.basic_rates); | |
9103 | if (err) | |
9104 | return err; | |
9105 | } | |
9106 | ||
c80d545d | 9107 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
9108 | } |
9109 | ||
9110 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
9111 | { | |
9112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9113 | struct net_device *dev = info->user_ptr[1]; | |
9114 | ||
9115 | return cfg80211_leave_mesh(rdev, dev); | |
9116 | } | |
9117 | ||
dfb89c56 | 9118 | #ifdef CONFIG_PM |
bb92d199 AK |
9119 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
9120 | struct cfg80211_registered_device *rdev) | |
9121 | { | |
6abb9cb9 | 9122 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
9123 | struct nlattr *nl_pats, *nl_pat; |
9124 | int i, pat_len; | |
9125 | ||
6abb9cb9 | 9126 | if (!wowlan->n_patterns) |
bb92d199 AK |
9127 | return 0; |
9128 | ||
9129 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
9130 | if (!nl_pats) | |
9131 | return -ENOBUFS; | |
9132 | ||
6abb9cb9 | 9133 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
9134 | nl_pat = nla_nest_start(msg, i + 1); |
9135 | if (!nl_pat) | |
9136 | return -ENOBUFS; | |
6abb9cb9 | 9137 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 9138 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 9139 | wowlan->patterns[i].mask) || |
50ac6607 AK |
9140 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
9141 | wowlan->patterns[i].pattern) || | |
9142 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 9143 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
9144 | return -ENOBUFS; |
9145 | nla_nest_end(msg, nl_pat); | |
9146 | } | |
9147 | nla_nest_end(msg, nl_pats); | |
9148 | ||
9149 | return 0; | |
9150 | } | |
9151 | ||
2a0e047e JB |
9152 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
9153 | struct cfg80211_wowlan_tcp *tcp) | |
9154 | { | |
9155 | struct nlattr *nl_tcp; | |
9156 | ||
9157 | if (!tcp) | |
9158 | return 0; | |
9159 | ||
9160 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
9161 | if (!nl_tcp) | |
9162 | return -ENOBUFS; | |
9163 | ||
930345ea JB |
9164 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
9165 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
2a0e047e JB |
9166 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
9167 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
9168 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
9169 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
9170 | tcp->payload_len, tcp->payload) || | |
9171 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
9172 | tcp->data_interval) || | |
9173 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
9174 | tcp->wake_len, tcp->wake_data) || | |
9175 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
9176 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
9177 | return -ENOBUFS; | |
9178 | ||
9179 | if (tcp->payload_seq.len && | |
9180 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
9181 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
9182 | return -ENOBUFS; | |
9183 | ||
9184 | if (tcp->payload_tok.len && | |
9185 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
9186 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
9187 | &tcp->payload_tok)) | |
9188 | return -ENOBUFS; | |
9189 | ||
e248ad30 JB |
9190 | nla_nest_end(msg, nl_tcp); |
9191 | ||
2a0e047e JB |
9192 | return 0; |
9193 | } | |
9194 | ||
75453ccb LC |
9195 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
9196 | struct cfg80211_sched_scan_request *req) | |
9197 | { | |
3b06d277 | 9198 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
75453ccb LC |
9199 | int i; |
9200 | ||
9201 | if (!req) | |
9202 | return 0; | |
9203 | ||
9204 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); | |
9205 | if (!nd) | |
9206 | return -ENOBUFS; | |
9207 | ||
3b06d277 AS |
9208 | if (req->n_scan_plans == 1 && |
9209 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, | |
9210 | req->scan_plans[0].interval * 1000)) | |
75453ccb LC |
9211 | return -ENOBUFS; |
9212 | ||
21fea567 LC |
9213 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
9214 | return -ENOBUFS; | |
9215 | ||
75453ccb LC |
9216 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
9217 | if (!freqs) | |
9218 | return -ENOBUFS; | |
9219 | ||
9220 | for (i = 0; i < req->n_channels; i++) | |
9221 | nla_put_u32(msg, i, req->channels[i]->center_freq); | |
9222 | ||
9223 | nla_nest_end(msg, freqs); | |
9224 | ||
9225 | if (req->n_match_sets) { | |
9226 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); | |
9227 | for (i = 0; i < req->n_match_sets; i++) { | |
9228 | match = nla_nest_start(msg, i); | |
9229 | nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, | |
9230 | req->match_sets[i].ssid.ssid_len, | |
9231 | req->match_sets[i].ssid.ssid); | |
9232 | nla_nest_end(msg, match); | |
9233 | } | |
9234 | nla_nest_end(msg, matches); | |
9235 | } | |
9236 | ||
3b06d277 AS |
9237 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
9238 | if (!scan_plans) | |
9239 | return -ENOBUFS; | |
9240 | ||
9241 | for (i = 0; i < req->n_scan_plans; i++) { | |
9242 | scan_plan = nla_nest_start(msg, i + 1); | |
9243 | if (!scan_plan || | |
9244 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, | |
9245 | req->scan_plans[i].interval) || | |
9246 | (req->scan_plans[i].iterations && | |
9247 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, | |
9248 | req->scan_plans[i].iterations))) | |
9249 | return -ENOBUFS; | |
9250 | nla_nest_end(msg, scan_plan); | |
9251 | } | |
9252 | nla_nest_end(msg, scan_plans); | |
9253 | ||
75453ccb LC |
9254 | nla_nest_end(msg, nd); |
9255 | ||
9256 | return 0; | |
9257 | } | |
9258 | ||
ff1b6e69 JB |
9259 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
9260 | { | |
9261 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9262 | struct sk_buff *msg; | |
9263 | void *hdr; | |
2a0e047e | 9264 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 9265 | |
964dc9e2 | 9266 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
9267 | return -EOPNOTSUPP; |
9268 | ||
6abb9cb9 | 9269 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 9270 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
9271 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
9272 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
9273 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
9274 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
9275 | } |
9276 | ||
9277 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
9278 | if (!msg) |
9279 | return -ENOMEM; | |
9280 | ||
15e47304 | 9281 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
9282 | NL80211_CMD_GET_WOWLAN); |
9283 | if (!hdr) | |
9284 | goto nla_put_failure; | |
9285 | ||
6abb9cb9 | 9286 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
9287 | struct nlattr *nl_wowlan; |
9288 | ||
9289 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
9290 | if (!nl_wowlan) | |
9291 | goto nla_put_failure; | |
9292 | ||
6abb9cb9 | 9293 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 9294 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 9295 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 9296 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 9297 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 9298 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 9299 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 9300 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 9301 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 9302 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 9303 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 9304 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 9305 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
9306 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
9307 | goto nla_put_failure; | |
2a0e047e | 9308 | |
bb92d199 AK |
9309 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
9310 | goto nla_put_failure; | |
2a0e047e | 9311 | |
6abb9cb9 JB |
9312 | if (nl80211_send_wowlan_tcp(msg, |
9313 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e | 9314 | goto nla_put_failure; |
75453ccb LC |
9315 | |
9316 | if (nl80211_send_wowlan_nd( | |
9317 | msg, | |
9318 | rdev->wiphy.wowlan_config->nd_config)) | |
9319 | goto nla_put_failure; | |
2a0e047e | 9320 | |
ff1b6e69 JB |
9321 | nla_nest_end(msg, nl_wowlan); |
9322 | } | |
9323 | ||
9324 | genlmsg_end(msg, hdr); | |
9325 | return genlmsg_reply(msg, info); | |
9326 | ||
9327 | nla_put_failure: | |
9328 | nlmsg_free(msg); | |
9329 | return -ENOBUFS; | |
9330 | } | |
9331 | ||
2a0e047e JB |
9332 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
9333 | struct nlattr *attr, | |
9334 | struct cfg80211_wowlan *trig) | |
9335 | { | |
9336 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
9337 | struct cfg80211_wowlan_tcp *cfg; | |
9338 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
9339 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
9340 | u32 size; | |
9341 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
9342 | int err, port; | |
9343 | ||
964dc9e2 | 9344 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
9345 | return -EINVAL; |
9346 | ||
9347 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
9348 | nla_data(attr), nla_len(attr), | |
9349 | nl80211_wowlan_tcp_policy); | |
9350 | if (err) | |
9351 | return err; | |
9352 | ||
9353 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
9354 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
9355 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
9356 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
9357 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
9358 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
9359 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
9360 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
9361 | return -EINVAL; | |
9362 | ||
9363 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 9364 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
9365 | return -EINVAL; |
9366 | ||
9367 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 9368 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 9369 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
9370 | return -EINVAL; |
9371 | ||
9372 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 9373 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
9374 | return -EINVAL; |
9375 | ||
9376 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
9377 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
9378 | return -EINVAL; | |
9379 | ||
9380 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
9381 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
9382 | ||
9383 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
9384 | tokens_size = tokln - sizeof(*tok); | |
9385 | ||
9386 | if (!tok->len || tokens_size % tok->len) | |
9387 | return -EINVAL; | |
964dc9e2 | 9388 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 9389 | return -EINVAL; |
964dc9e2 | 9390 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 9391 | return -EINVAL; |
964dc9e2 | 9392 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 9393 | return -EINVAL; |
964dc9e2 | 9394 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
9395 | return -EINVAL; |
9396 | if (tok->offset + tok->len > data_size) | |
9397 | return -EINVAL; | |
9398 | } | |
9399 | ||
9400 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
9401 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 9402 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
9403 | return -EINVAL; |
9404 | if (seq->len == 0 || seq->len > 4) | |
9405 | return -EINVAL; | |
9406 | if (seq->len + seq->offset > data_size) | |
9407 | return -EINVAL; | |
9408 | } | |
9409 | ||
9410 | size = sizeof(*cfg); | |
9411 | size += data_size; | |
9412 | size += wake_size + wake_mask_size; | |
9413 | size += tokens_size; | |
9414 | ||
9415 | cfg = kzalloc(size, GFP_KERNEL); | |
9416 | if (!cfg) | |
9417 | return -ENOMEM; | |
67b61f6c JB |
9418 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
9419 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
2a0e047e JB |
9420 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
9421 | ETH_ALEN); | |
9422 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
9423 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
9424 | else | |
9425 | port = 0; | |
9426 | #ifdef CONFIG_INET | |
9427 | /* allocate a socket and port for it and use it */ | |
9428 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
9429 | IPPROTO_TCP, &cfg->sock, 1); | |
9430 | if (err) { | |
9431 | kfree(cfg); | |
9432 | return err; | |
9433 | } | |
9434 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
9435 | sock_release(cfg->sock); | |
9436 | kfree(cfg); | |
9437 | return -EADDRINUSE; | |
9438 | } | |
9439 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
9440 | #else | |
9441 | if (!port) { | |
9442 | kfree(cfg); | |
9443 | return -EINVAL; | |
9444 | } | |
9445 | cfg->src_port = port; | |
9446 | #endif | |
9447 | ||
9448 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
9449 | cfg->payload_len = data_size; | |
9450 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
9451 | memcpy((void *)cfg->payload, | |
9452 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
9453 | data_size); | |
9454 | if (seq) | |
9455 | cfg->payload_seq = *seq; | |
9456 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
9457 | cfg->wake_len = wake_size; | |
9458 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
9459 | memcpy((void *)cfg->wake_data, | |
9460 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
9461 | wake_size); | |
9462 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
9463 | data_size + wake_size; | |
9464 | memcpy((void *)cfg->wake_mask, | |
9465 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
9466 | wake_mask_size); | |
9467 | if (tok) { | |
9468 | cfg->tokens_size = tokens_size; | |
9469 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
9470 | } | |
9471 | ||
9472 | trig->tcp = cfg; | |
9473 | ||
9474 | return 0; | |
9475 | } | |
9476 | ||
8cd4d456 LC |
9477 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
9478 | const struct wiphy_wowlan_support *wowlan, | |
9479 | struct nlattr *attr, | |
9480 | struct cfg80211_wowlan *trig) | |
9481 | { | |
9482 | struct nlattr **tb; | |
9483 | int err; | |
9484 | ||
9485 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); | |
9486 | if (!tb) | |
9487 | return -ENOMEM; | |
9488 | ||
9489 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | |
9490 | err = -EOPNOTSUPP; | |
9491 | goto out; | |
9492 | } | |
9493 | ||
9494 | err = nla_parse(tb, NL80211_ATTR_MAX, | |
9495 | nla_data(attr), nla_len(attr), | |
9496 | nl80211_policy); | |
9497 | if (err) | |
9498 | goto out; | |
9499 | ||
ad2b26ab | 9500 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
8cd4d456 LC |
9501 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
9502 | if (err) | |
9503 | trig->nd_config = NULL; | |
9504 | ||
9505 | out: | |
9506 | kfree(tb); | |
9507 | return err; | |
9508 | } | |
9509 | ||
ff1b6e69 JB |
9510 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
9511 | { | |
9512 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9513 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 9514 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 9515 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 9516 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 9517 | int err, i; |
6abb9cb9 | 9518 | bool prev_enabled = rdev->wiphy.wowlan_config; |
98fc4386 | 9519 | bool regular = false; |
ff1b6e69 | 9520 | |
964dc9e2 | 9521 | if (!wowlan) |
ff1b6e69 JB |
9522 | return -EOPNOTSUPP; |
9523 | ||
ae33bd81 JB |
9524 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
9525 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 9526 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
9527 | goto set_wakeup; |
9528 | } | |
ff1b6e69 JB |
9529 | |
9530 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
9531 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9532 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9533 | nl80211_wowlan_policy); | |
9534 | if (err) | |
9535 | return err; | |
9536 | ||
9537 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
9538 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
9539 | return -EINVAL; | |
9540 | new_triggers.any = true; | |
9541 | } | |
9542 | ||
9543 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
9544 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
9545 | return -EINVAL; | |
9546 | new_triggers.disconnect = true; | |
98fc4386 | 9547 | regular = true; |
ff1b6e69 JB |
9548 | } |
9549 | ||
9550 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
9551 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
9552 | return -EINVAL; | |
9553 | new_triggers.magic_pkt = true; | |
98fc4386 | 9554 | regular = true; |
ff1b6e69 JB |
9555 | } |
9556 | ||
77dbbb13 JB |
9557 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
9558 | return -EINVAL; | |
9559 | ||
9560 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
9561 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
9562 | return -EINVAL; | |
9563 | new_triggers.gtk_rekey_failure = true; | |
98fc4386 | 9564 | regular = true; |
77dbbb13 JB |
9565 | } |
9566 | ||
9567 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
9568 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
9569 | return -EINVAL; | |
9570 | new_triggers.eap_identity_req = true; | |
98fc4386 | 9571 | regular = true; |
77dbbb13 JB |
9572 | } |
9573 | ||
9574 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
9575 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
9576 | return -EINVAL; | |
9577 | new_triggers.four_way_handshake = true; | |
98fc4386 | 9578 | regular = true; |
77dbbb13 JB |
9579 | } |
9580 | ||
9581 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
9582 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
9583 | return -EINVAL; | |
9584 | new_triggers.rfkill_release = true; | |
98fc4386 | 9585 | regular = true; |
77dbbb13 JB |
9586 | } |
9587 | ||
ff1b6e69 JB |
9588 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
9589 | struct nlattr *pat; | |
9590 | int n_patterns = 0; | |
bb92d199 | 9591 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 9592 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 | 9593 | |
98fc4386 JB |
9594 | regular = true; |
9595 | ||
ff1b6e69 JB |
9596 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
9597 | rem) | |
9598 | n_patterns++; | |
9599 | if (n_patterns > wowlan->n_patterns) | |
9600 | return -EINVAL; | |
9601 | ||
9602 | new_triggers.patterns = kcalloc(n_patterns, | |
9603 | sizeof(new_triggers.patterns[0]), | |
9604 | GFP_KERNEL); | |
9605 | if (!new_triggers.patterns) | |
9606 | return -ENOMEM; | |
9607 | ||
9608 | new_triggers.n_patterns = n_patterns; | |
9609 | i = 0; | |
9610 | ||
9611 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9612 | rem) { | |
922bd80f JB |
9613 | u8 *mask_pat; |
9614 | ||
50ac6607 AK |
9615 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9616 | nla_len(pat), NULL); | |
ff1b6e69 | 9617 | err = -EINVAL; |
50ac6607 AK |
9618 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
9619 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 9620 | goto error; |
50ac6607 | 9621 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 9622 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 9623 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
9624 | goto error; |
9625 | if (pat_len > wowlan->pattern_max_len || | |
9626 | pat_len < wowlan->pattern_min_len) | |
9627 | goto error; | |
9628 | ||
50ac6607 | 9629 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
9630 | pkt_offset = 0; |
9631 | else | |
9632 | pkt_offset = nla_get_u32( | |
50ac6607 | 9633 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
9634 | if (pkt_offset > wowlan->max_pkt_offset) |
9635 | goto error; | |
9636 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
9637 | ||
922bd80f JB |
9638 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9639 | if (!mask_pat) { | |
ff1b6e69 JB |
9640 | err = -ENOMEM; |
9641 | goto error; | |
9642 | } | |
922bd80f JB |
9643 | new_triggers.patterns[i].mask = mask_pat; |
9644 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 9645 | mask_len); |
922bd80f JB |
9646 | mask_pat += mask_len; |
9647 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 9648 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 9649 | memcpy(mask_pat, |
50ac6607 | 9650 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
9651 | pat_len); |
9652 | i++; | |
9653 | } | |
9654 | } | |
9655 | ||
2a0e047e | 9656 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
98fc4386 | 9657 | regular = true; |
2a0e047e JB |
9658 | err = nl80211_parse_wowlan_tcp( |
9659 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
9660 | &new_triggers); | |
9661 | if (err) | |
9662 | goto error; | |
9663 | } | |
9664 | ||
8cd4d456 | 9665 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
98fc4386 | 9666 | regular = true; |
8cd4d456 LC |
9667 | err = nl80211_parse_wowlan_nd( |
9668 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | |
9669 | &new_triggers); | |
9670 | if (err) | |
9671 | goto error; | |
9672 | } | |
9673 | ||
98fc4386 JB |
9674 | /* The 'any' trigger means the device continues operating more or less |
9675 | * as in its normal operation mode and wakes up the host on most of the | |
9676 | * normal interrupts (like packet RX, ...) | |
9677 | * It therefore makes little sense to combine with the more constrained | |
9678 | * wakeup trigger modes. | |
9679 | */ | |
9680 | if (new_triggers.any && regular) { | |
9681 | err = -EINVAL; | |
9682 | goto error; | |
9683 | } | |
9684 | ||
ae33bd81 JB |
9685 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
9686 | if (!ntrig) { | |
9687 | err = -ENOMEM; | |
9688 | goto error; | |
ff1b6e69 | 9689 | } |
ae33bd81 | 9690 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 9691 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 9692 | |
ae33bd81 | 9693 | set_wakeup: |
6abb9cb9 JB |
9694 | if (rdev->ops->set_wakeup && |
9695 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
9696 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 9697 | |
ff1b6e69 JB |
9698 | return 0; |
9699 | error: | |
9700 | for (i = 0; i < new_triggers.n_patterns; i++) | |
9701 | kfree(new_triggers.patterns[i].mask); | |
9702 | kfree(new_triggers.patterns); | |
2a0e047e JB |
9703 | if (new_triggers.tcp && new_triggers.tcp->sock) |
9704 | sock_release(new_triggers.tcp->sock); | |
9705 | kfree(new_triggers.tcp); | |
e5dbe070 | 9706 | kfree(new_triggers.nd_config); |
ff1b6e69 JB |
9707 | return err; |
9708 | } | |
dfb89c56 | 9709 | #endif |
ff1b6e69 | 9710 | |
be29b99a AK |
9711 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
9712 | struct cfg80211_registered_device *rdev) | |
9713 | { | |
9714 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
9715 | int i, j, pat_len; | |
9716 | struct cfg80211_coalesce_rules *rule; | |
9717 | ||
9718 | if (!rdev->coalesce->n_rules) | |
9719 | return 0; | |
9720 | ||
9721 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
9722 | if (!nl_rules) | |
9723 | return -ENOBUFS; | |
9724 | ||
9725 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
9726 | nl_rule = nla_nest_start(msg, i + 1); | |
9727 | if (!nl_rule) | |
9728 | return -ENOBUFS; | |
9729 | ||
9730 | rule = &rdev->coalesce->rules[i]; | |
9731 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
9732 | rule->delay)) | |
9733 | return -ENOBUFS; | |
9734 | ||
9735 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
9736 | rule->condition)) | |
9737 | return -ENOBUFS; | |
9738 | ||
9739 | nl_pats = nla_nest_start(msg, | |
9740 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
9741 | if (!nl_pats) | |
9742 | return -ENOBUFS; | |
9743 | ||
9744 | for (j = 0; j < rule->n_patterns; j++) { | |
9745 | nl_pat = nla_nest_start(msg, j + 1); | |
9746 | if (!nl_pat) | |
9747 | return -ENOBUFS; | |
9748 | pat_len = rule->patterns[j].pattern_len; | |
9749 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
9750 | DIV_ROUND_UP(pat_len, 8), | |
9751 | rule->patterns[j].mask) || | |
9752 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
9753 | rule->patterns[j].pattern) || | |
9754 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
9755 | rule->patterns[j].pkt_offset)) | |
9756 | return -ENOBUFS; | |
9757 | nla_nest_end(msg, nl_pat); | |
9758 | } | |
9759 | nla_nest_end(msg, nl_pats); | |
9760 | nla_nest_end(msg, nl_rule); | |
9761 | } | |
9762 | nla_nest_end(msg, nl_rules); | |
9763 | ||
9764 | return 0; | |
9765 | } | |
9766 | ||
9767 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9768 | { | |
9769 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9770 | struct sk_buff *msg; | |
9771 | void *hdr; | |
9772 | ||
9773 | if (!rdev->wiphy.coalesce) | |
9774 | return -EOPNOTSUPP; | |
9775 | ||
9776 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9777 | if (!msg) | |
9778 | return -ENOMEM; | |
9779 | ||
9780 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9781 | NL80211_CMD_GET_COALESCE); | |
9782 | if (!hdr) | |
9783 | goto nla_put_failure; | |
9784 | ||
9785 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
9786 | goto nla_put_failure; | |
9787 | ||
9788 | genlmsg_end(msg, hdr); | |
9789 | return genlmsg_reply(msg, info); | |
9790 | ||
9791 | nla_put_failure: | |
9792 | nlmsg_free(msg); | |
9793 | return -ENOBUFS; | |
9794 | } | |
9795 | ||
9796 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
9797 | { | |
9798 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
9799 | int i, j; | |
9800 | struct cfg80211_coalesce_rules *rule; | |
9801 | ||
9802 | if (!coalesce) | |
9803 | return; | |
9804 | ||
9805 | for (i = 0; i < coalesce->n_rules; i++) { | |
9806 | rule = &coalesce->rules[i]; | |
9807 | for (j = 0; j < rule->n_patterns; j++) | |
9808 | kfree(rule->patterns[j].mask); | |
9809 | kfree(rule->patterns); | |
9810 | } | |
9811 | kfree(coalesce->rules); | |
9812 | kfree(coalesce); | |
9813 | rdev->coalesce = NULL; | |
9814 | } | |
9815 | ||
9816 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
9817 | struct nlattr *rule, | |
9818 | struct cfg80211_coalesce_rules *new_rule) | |
9819 | { | |
9820 | int err, i; | |
9821 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9822 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
9823 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
9824 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
9825 | ||
9826 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
9827 | nla_len(rule), nl80211_coalesce_policy); | |
9828 | if (err) | |
9829 | return err; | |
9830 | ||
9831 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
9832 | new_rule->delay = | |
9833 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
9834 | if (new_rule->delay > coalesce->max_delay) | |
9835 | return -EINVAL; | |
9836 | ||
9837 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
9838 | new_rule->condition = | |
9839 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
9840 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
9841 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
9842 | return -EINVAL; | |
9843 | ||
9844 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
9845 | return -EINVAL; | |
9846 | ||
9847 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9848 | rem) | |
9849 | n_patterns++; | |
9850 | if (n_patterns > coalesce->n_patterns) | |
9851 | return -EINVAL; | |
9852 | ||
9853 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
9854 | GFP_KERNEL); | |
9855 | if (!new_rule->patterns) | |
9856 | return -ENOMEM; | |
9857 | ||
9858 | new_rule->n_patterns = n_patterns; | |
9859 | i = 0; | |
9860 | ||
9861 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9862 | rem) { | |
922bd80f JB |
9863 | u8 *mask_pat; |
9864 | ||
be29b99a AK |
9865 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9866 | nla_len(pat), NULL); | |
9867 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
9868 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
9869 | return -EINVAL; | |
9870 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
9871 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
9872 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
9873 | return -EINVAL; | |
9874 | if (pat_len > coalesce->pattern_max_len || | |
9875 | pat_len < coalesce->pattern_min_len) | |
9876 | return -EINVAL; | |
9877 | ||
9878 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
9879 | pkt_offset = 0; | |
9880 | else | |
9881 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
9882 | if (pkt_offset > coalesce->max_pkt_offset) | |
9883 | return -EINVAL; | |
9884 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
9885 | ||
922bd80f JB |
9886 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9887 | if (!mask_pat) | |
be29b99a | 9888 | return -ENOMEM; |
922bd80f JB |
9889 | |
9890 | new_rule->patterns[i].mask = mask_pat; | |
9891 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
9892 | mask_len); | |
9893 | ||
9894 | mask_pat += mask_len; | |
9895 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 9896 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
9897 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
9898 | pat_len); | |
be29b99a AK |
9899 | i++; |
9900 | } | |
9901 | ||
9902 | return 0; | |
9903 | } | |
9904 | ||
9905 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9906 | { | |
9907 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9908 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9909 | struct cfg80211_coalesce new_coalesce = {}; | |
9910 | struct cfg80211_coalesce *n_coalesce; | |
9911 | int err, rem_rule, n_rules = 0, i, j; | |
9912 | struct nlattr *rule; | |
9913 | struct cfg80211_coalesce_rules *tmp_rule; | |
9914 | ||
9915 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
9916 | return -EOPNOTSUPP; | |
9917 | ||
9918 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
9919 | cfg80211_rdev_free_coalesce(rdev); | |
a1056b1b | 9920 | rdev_set_coalesce(rdev, NULL); |
be29b99a AK |
9921 | return 0; |
9922 | } | |
9923 | ||
9924 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9925 | rem_rule) | |
9926 | n_rules++; | |
9927 | if (n_rules > coalesce->n_rules) | |
9928 | return -EINVAL; | |
9929 | ||
9930 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
9931 | GFP_KERNEL); | |
9932 | if (!new_coalesce.rules) | |
9933 | return -ENOMEM; | |
9934 | ||
9935 | new_coalesce.n_rules = n_rules; | |
9936 | i = 0; | |
9937 | ||
9938 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9939 | rem_rule) { | |
9940 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
9941 | &new_coalesce.rules[i]); | |
9942 | if (err) | |
9943 | goto error; | |
9944 | ||
9945 | i++; | |
9946 | } | |
9947 | ||
a1056b1b | 9948 | err = rdev_set_coalesce(rdev, &new_coalesce); |
be29b99a AK |
9949 | if (err) |
9950 | goto error; | |
9951 | ||
9952 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
9953 | if (!n_coalesce) { | |
9954 | err = -ENOMEM; | |
9955 | goto error; | |
9956 | } | |
9957 | cfg80211_rdev_free_coalesce(rdev); | |
9958 | rdev->coalesce = n_coalesce; | |
9959 | ||
9960 | return 0; | |
9961 | error: | |
9962 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
9963 | tmp_rule = &new_coalesce.rules[i]; | |
9964 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
9965 | kfree(tmp_rule->patterns[j].mask); | |
9966 | kfree(tmp_rule->patterns); | |
9967 | } | |
9968 | kfree(new_coalesce.rules); | |
9969 | ||
9970 | return err; | |
9971 | } | |
9972 | ||
e5497d76 JB |
9973 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
9974 | { | |
9975 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9976 | struct net_device *dev = info->user_ptr[1]; | |
9977 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9978 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
9979 | struct cfg80211_gtk_rekey_data rekey_data; | |
9980 | int err; | |
9981 | ||
9982 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
9983 | return -EINVAL; | |
9984 | ||
9985 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
9986 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9987 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9988 | nl80211_rekey_policy); | |
9989 | if (err) | |
9990 | return err; | |
9991 | ||
9992 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
9993 | return -ERANGE; | |
9994 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
9995 | return -ERANGE; | |
9996 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
9997 | return -ERANGE; | |
9998 | ||
78f686ca JB |
9999 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
10000 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | |
10001 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | |
e5497d76 JB |
10002 | |
10003 | wdev_lock(wdev); | |
10004 | if (!wdev->current_bss) { | |
10005 | err = -ENOTCONN; | |
10006 | goto out; | |
10007 | } | |
10008 | ||
10009 | if (!rdev->ops->set_rekey_data) { | |
10010 | err = -EOPNOTSUPP; | |
10011 | goto out; | |
10012 | } | |
10013 | ||
e35e4d28 | 10014 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
10015 | out: |
10016 | wdev_unlock(wdev); | |
10017 | return err; | |
10018 | } | |
10019 | ||
28946da7 JB |
10020 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
10021 | struct genl_info *info) | |
10022 | { | |
10023 | struct net_device *dev = info->user_ptr[1]; | |
10024 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10025 | ||
10026 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
10027 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
10028 | return -EINVAL; | |
10029 | ||
15e47304 | 10030 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
10031 | return -EBUSY; |
10032 | ||
15e47304 | 10033 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
10034 | return 0; |
10035 | } | |
10036 | ||
7f6cf311 JB |
10037 | static int nl80211_probe_client(struct sk_buff *skb, |
10038 | struct genl_info *info) | |
10039 | { | |
10040 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10041 | struct net_device *dev = info->user_ptr[1]; | |
10042 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10043 | struct sk_buff *msg; | |
10044 | void *hdr; | |
10045 | const u8 *addr; | |
10046 | u64 cookie; | |
10047 | int err; | |
10048 | ||
10049 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
10050 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
10051 | return -EOPNOTSUPP; | |
10052 | ||
10053 | if (!info->attrs[NL80211_ATTR_MAC]) | |
10054 | return -EINVAL; | |
10055 | ||
10056 | if (!rdev->ops->probe_client) | |
10057 | return -EOPNOTSUPP; | |
10058 | ||
10059 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10060 | if (!msg) | |
10061 | return -ENOMEM; | |
10062 | ||
15e47304 | 10063 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 10064 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
10065 | if (!hdr) { |
10066 | err = -ENOBUFS; | |
7f6cf311 JB |
10067 | goto free_msg; |
10068 | } | |
10069 | ||
10070 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10071 | ||
e35e4d28 | 10072 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
10073 | if (err) |
10074 | goto free_msg; | |
10075 | ||
9360ffd1 DM |
10076 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
10077 | goto nla_put_failure; | |
7f6cf311 JB |
10078 | |
10079 | genlmsg_end(msg, hdr); | |
10080 | ||
10081 | return genlmsg_reply(msg, info); | |
10082 | ||
10083 | nla_put_failure: | |
10084 | err = -ENOBUFS; | |
10085 | free_msg: | |
10086 | nlmsg_free(msg); | |
10087 | return err; | |
10088 | } | |
10089 | ||
5e760230 JB |
10090 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
10091 | { | |
10092 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
10093 | struct cfg80211_beacon_registration *reg, *nreg; |
10094 | int rv; | |
5e760230 JB |
10095 | |
10096 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
10097 | return -EOPNOTSUPP; | |
10098 | ||
37c73b5f BG |
10099 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
10100 | if (!nreg) | |
10101 | return -ENOMEM; | |
10102 | ||
10103 | /* First, check if already registered. */ | |
10104 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
10105 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
10106 | if (reg->nlportid == info->snd_portid) { | |
10107 | rv = -EALREADY; | |
10108 | goto out_err; | |
10109 | } | |
10110 | } | |
10111 | /* Add it to the list */ | |
10112 | nreg->nlportid = info->snd_portid; | |
10113 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 10114 | |
37c73b5f | 10115 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
10116 | |
10117 | return 0; | |
37c73b5f BG |
10118 | out_err: |
10119 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
10120 | kfree(nreg); | |
10121 | return rv; | |
5e760230 JB |
10122 | } |
10123 | ||
98104fde JB |
10124 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
10125 | { | |
10126 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10127 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10128 | int err; | |
10129 | ||
10130 | if (!rdev->ops->start_p2p_device) | |
10131 | return -EOPNOTSUPP; | |
10132 | ||
10133 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
10134 | return -EOPNOTSUPP; | |
10135 | ||
10136 | if (wdev->p2p_started) | |
10137 | return 0; | |
10138 | ||
b6a55015 LC |
10139 | if (rfkill_blocked(rdev->rfkill)) |
10140 | return -ERFKILL; | |
98104fde | 10141 | |
eeb126e9 | 10142 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
10143 | if (err) |
10144 | return err; | |
10145 | ||
10146 | wdev->p2p_started = true; | |
98104fde | 10147 | rdev->opencount++; |
98104fde JB |
10148 | |
10149 | return 0; | |
10150 | } | |
10151 | ||
10152 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
10153 | { | |
10154 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10155 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10156 | ||
10157 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
10158 | return -EOPNOTSUPP; | |
10159 | ||
10160 | if (!rdev->ops->stop_p2p_device) | |
10161 | return -EOPNOTSUPP; | |
10162 | ||
f9f47529 | 10163 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
10164 | |
10165 | return 0; | |
10166 | } | |
10167 | ||
3713b4e3 JB |
10168 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
10169 | struct genl_info *info) | |
10170 | { | |
10171 | void *hdr; | |
10172 | struct sk_buff *msg; | |
10173 | ||
10174 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10175 | if (!msg) | |
10176 | return -ENOMEM; | |
10177 | ||
10178 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
10179 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
10180 | if (!hdr) | |
10181 | goto nla_put_failure; | |
10182 | ||
10183 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
10184 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
10185 | goto nla_put_failure; | |
10186 | ||
10187 | genlmsg_end(msg, hdr); | |
10188 | return genlmsg_reply(msg, info); | |
10189 | ||
10190 | nla_put_failure: | |
10191 | kfree_skb(msg); | |
10192 | return -ENOBUFS; | |
10193 | } | |
10194 | ||
355199e0 JM |
10195 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
10196 | { | |
10197 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10198 | struct cfg80211_update_ft_ies_params ft_params; | |
10199 | struct net_device *dev = info->user_ptr[1]; | |
10200 | ||
10201 | if (!rdev->ops->update_ft_ies) | |
10202 | return -EOPNOTSUPP; | |
10203 | ||
10204 | if (!info->attrs[NL80211_ATTR_MDID] || | |
10205 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
10206 | return -EINVAL; | |
10207 | ||
10208 | memset(&ft_params, 0, sizeof(ft_params)); | |
10209 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
10210 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
10211 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
10212 | ||
10213 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
10214 | } | |
10215 | ||
5de17984 AS |
10216 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
10217 | struct genl_info *info) | |
10218 | { | |
10219 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10220 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10221 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
10222 | u16 duration; | |
10223 | int ret; | |
10224 | ||
10225 | if (!rdev->ops->crit_proto_start) | |
10226 | return -EOPNOTSUPP; | |
10227 | ||
10228 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
10229 | return -EINVAL; | |
10230 | ||
10231 | if (rdev->crit_proto_nlportid) | |
10232 | return -EBUSY; | |
10233 | ||
10234 | /* determine protocol if provided */ | |
10235 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
10236 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
10237 | ||
10238 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
10239 | return -EINVAL; | |
10240 | ||
10241 | /* timeout must be provided */ | |
10242 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
10243 | return -EINVAL; | |
10244 | ||
10245 | duration = | |
10246 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
10247 | ||
10248 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
10249 | return -ERANGE; | |
10250 | ||
10251 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
10252 | if (!ret) | |
10253 | rdev->crit_proto_nlportid = info->snd_portid; | |
10254 | ||
10255 | return ret; | |
10256 | } | |
10257 | ||
10258 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
10259 | struct genl_info *info) | |
10260 | { | |
10261 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10262 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10263 | ||
10264 | if (!rdev->ops->crit_proto_stop) | |
10265 | return -EOPNOTSUPP; | |
10266 | ||
10267 | if (rdev->crit_proto_nlportid) { | |
10268 | rdev->crit_proto_nlportid = 0; | |
10269 | rdev_crit_proto_stop(rdev, wdev); | |
10270 | } | |
10271 | return 0; | |
10272 | } | |
10273 | ||
ad7e718c JB |
10274 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
10275 | { | |
10276 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10277 | struct wireless_dev *wdev = | |
10278 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
10279 | int i, err; | |
10280 | u32 vid, subcmd; | |
10281 | ||
10282 | if (!rdev->wiphy.vendor_commands) | |
10283 | return -EOPNOTSUPP; | |
10284 | ||
10285 | if (IS_ERR(wdev)) { | |
10286 | err = PTR_ERR(wdev); | |
10287 | if (err != -EINVAL) | |
10288 | return err; | |
10289 | wdev = NULL; | |
10290 | } else if (wdev->wiphy != &rdev->wiphy) { | |
10291 | return -EINVAL; | |
10292 | } | |
10293 | ||
10294 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
10295 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
10296 | return -EINVAL; | |
10297 | ||
10298 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
10299 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
10300 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
10301 | const struct wiphy_vendor_command *vcmd; | |
10302 | void *data = NULL; | |
10303 | int len = 0; | |
10304 | ||
10305 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
10306 | ||
10307 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
10308 | continue; | |
10309 | ||
10310 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
10311 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
10312 | if (!wdev) | |
10313 | return -EINVAL; | |
10314 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
10315 | !wdev->netdev) | |
10316 | return -EINVAL; | |
10317 | ||
10318 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
10319 | if (wdev->netdev && | |
10320 | !netif_running(wdev->netdev)) | |
10321 | return -ENETDOWN; | |
10322 | if (!wdev->netdev && !wdev->p2p_started) | |
10323 | return -ENETDOWN; | |
10324 | } | |
7bdbe400 JB |
10325 | |
10326 | if (!vcmd->doit) | |
10327 | return -EOPNOTSUPP; | |
ad7e718c JB |
10328 | } else { |
10329 | wdev = NULL; | |
10330 | } | |
10331 | ||
10332 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
10333 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
10334 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
10335 | } | |
10336 | ||
10337 | rdev->cur_cmd_info = info; | |
10338 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
10339 | data, len); | |
10340 | rdev->cur_cmd_info = NULL; | |
10341 | return err; | |
10342 | } | |
10343 | ||
10344 | return -EOPNOTSUPP; | |
10345 | } | |
10346 | ||
7bdbe400 JB |
10347 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
10348 | struct netlink_callback *cb, | |
10349 | struct cfg80211_registered_device **rdev, | |
10350 | struct wireless_dev **wdev) | |
10351 | { | |
10352 | u32 vid, subcmd; | |
10353 | unsigned int i; | |
10354 | int vcmd_idx = -1; | |
10355 | int err; | |
10356 | void *data = NULL; | |
10357 | unsigned int data_len = 0; | |
10358 | ||
10359 | rtnl_lock(); | |
10360 | ||
10361 | if (cb->args[0]) { | |
10362 | /* subtract the 1 again here */ | |
10363 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
10364 | struct wireless_dev *tmp; | |
10365 | ||
10366 | if (!wiphy) { | |
10367 | err = -ENODEV; | |
10368 | goto out_unlock; | |
10369 | } | |
10370 | *rdev = wiphy_to_rdev(wiphy); | |
10371 | *wdev = NULL; | |
10372 | ||
10373 | if (cb->args[1]) { | |
10374 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { | |
10375 | if (tmp->identifier == cb->args[1] - 1) { | |
10376 | *wdev = tmp; | |
10377 | break; | |
10378 | } | |
10379 | } | |
10380 | } | |
10381 | ||
10382 | /* keep rtnl locked in successful case */ | |
10383 | return 0; | |
10384 | } | |
10385 | ||
10386 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
10387 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
10388 | nl80211_policy); | |
10389 | if (err) | |
10390 | goto out_unlock; | |
10391 | ||
10392 | if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] || | |
10393 | !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { | |
10394 | err = -EINVAL; | |
10395 | goto out_unlock; | |
10396 | } | |
10397 | ||
10398 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), | |
10399 | nl80211_fam.attrbuf); | |
10400 | if (IS_ERR(*wdev)) | |
10401 | *wdev = NULL; | |
10402 | ||
10403 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), | |
10404 | nl80211_fam.attrbuf); | |
10405 | if (IS_ERR(*rdev)) { | |
10406 | err = PTR_ERR(*rdev); | |
10407 | goto out_unlock; | |
10408 | } | |
10409 | ||
10410 | vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]); | |
10411 | subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); | |
10412 | ||
10413 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { | |
10414 | const struct wiphy_vendor_command *vcmd; | |
10415 | ||
10416 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; | |
10417 | ||
10418 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
10419 | continue; | |
10420 | ||
10421 | if (!vcmd->dumpit) { | |
10422 | err = -EOPNOTSUPP; | |
10423 | goto out_unlock; | |
10424 | } | |
10425 | ||
10426 | vcmd_idx = i; | |
10427 | break; | |
10428 | } | |
10429 | ||
10430 | if (vcmd_idx < 0) { | |
10431 | err = -EOPNOTSUPP; | |
10432 | goto out_unlock; | |
10433 | } | |
10434 | ||
10435 | if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) { | |
10436 | data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); | |
10437 | data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); | |
10438 | } | |
10439 | ||
10440 | /* 0 is the first index - add 1 to parse only once */ | |
10441 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
10442 | /* add 1 to know if it was NULL */ | |
10443 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; | |
10444 | cb->args[2] = vcmd_idx; | |
10445 | cb->args[3] = (unsigned long)data; | |
10446 | cb->args[4] = data_len; | |
10447 | ||
10448 | /* keep rtnl locked in successful case */ | |
10449 | return 0; | |
10450 | out_unlock: | |
10451 | rtnl_unlock(); | |
10452 | return err; | |
10453 | } | |
10454 | ||
10455 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, | |
10456 | struct netlink_callback *cb) | |
10457 | { | |
10458 | struct cfg80211_registered_device *rdev; | |
10459 | struct wireless_dev *wdev; | |
10460 | unsigned int vcmd_idx; | |
10461 | const struct wiphy_vendor_command *vcmd; | |
10462 | void *data; | |
10463 | int data_len; | |
10464 | int err; | |
10465 | struct nlattr *vendor_data; | |
10466 | ||
10467 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); | |
10468 | if (err) | |
10469 | return err; | |
10470 | ||
10471 | vcmd_idx = cb->args[2]; | |
10472 | data = (void *)cb->args[3]; | |
10473 | data_len = cb->args[4]; | |
10474 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; | |
10475 | ||
10476 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
10477 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
10478 | if (!wdev) | |
10479 | return -EINVAL; | |
10480 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
10481 | !wdev->netdev) | |
10482 | return -EINVAL; | |
10483 | ||
10484 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
10485 | if (wdev->netdev && | |
10486 | !netif_running(wdev->netdev)) | |
10487 | return -ENETDOWN; | |
10488 | if (!wdev->netdev && !wdev->p2p_started) | |
10489 | return -ENETDOWN; | |
10490 | } | |
10491 | } | |
10492 | ||
10493 | while (1) { | |
10494 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, | |
10495 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
10496 | NL80211_CMD_VENDOR); | |
10497 | if (!hdr) | |
10498 | break; | |
10499 | ||
10500 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10501 | (wdev && nla_put_u64(skb, NL80211_ATTR_WDEV, | |
10502 | wdev_id(wdev)))) { | |
10503 | genlmsg_cancel(skb, hdr); | |
10504 | break; | |
10505 | } | |
10506 | ||
10507 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); | |
10508 | if (!vendor_data) { | |
10509 | genlmsg_cancel(skb, hdr); | |
10510 | break; | |
10511 | } | |
10512 | ||
10513 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, | |
10514 | (unsigned long *)&cb->args[5]); | |
10515 | nla_nest_end(skb, vendor_data); | |
10516 | ||
10517 | if (err == -ENOBUFS || err == -ENOENT) { | |
10518 | genlmsg_cancel(skb, hdr); | |
10519 | break; | |
10520 | } else if (err) { | |
10521 | genlmsg_cancel(skb, hdr); | |
10522 | goto out; | |
10523 | } | |
10524 | ||
10525 | genlmsg_end(skb, hdr); | |
10526 | } | |
10527 | ||
10528 | err = skb->len; | |
10529 | out: | |
10530 | rtnl_unlock(); | |
10531 | return err; | |
10532 | } | |
10533 | ||
ad7e718c JB |
10534 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
10535 | enum nl80211_commands cmd, | |
10536 | enum nl80211_attrs attr, | |
10537 | int approxlen) | |
10538 | { | |
f26cbf40 | 10539 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
10540 | |
10541 | if (WARN_ON(!rdev->cur_cmd_info)) | |
10542 | return NULL; | |
10543 | ||
6c09e791 | 10544 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
ad7e718c JB |
10545 | rdev->cur_cmd_info->snd_portid, |
10546 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 10547 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
10548 | } |
10549 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
10550 | ||
10551 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
10552 | { | |
10553 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
10554 | void *hdr = ((void **)skb->cb)[1]; | |
10555 | struct nlattr *data = ((void **)skb->cb)[2]; | |
10556 | ||
bd8c78e7 JB |
10557 | /* clear CB data for netlink core to own from now on */ |
10558 | memset(skb->cb, 0, sizeof(skb->cb)); | |
10559 | ||
ad7e718c JB |
10560 | if (WARN_ON(!rdev->cur_cmd_info)) { |
10561 | kfree_skb(skb); | |
10562 | return -EINVAL; | |
10563 | } | |
10564 | ||
10565 | nla_nest_end(skb, data); | |
10566 | genlmsg_end(skb, hdr); | |
10567 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
10568 | } | |
10569 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
10570 | ||
10571 | ||
fa9ffc74 KP |
10572 | static int nl80211_set_qos_map(struct sk_buff *skb, |
10573 | struct genl_info *info) | |
10574 | { | |
10575 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10576 | struct cfg80211_qos_map *qos_map = NULL; | |
10577 | struct net_device *dev = info->user_ptr[1]; | |
10578 | u8 *pos, len, num_des, des_len, des; | |
10579 | int ret; | |
10580 | ||
10581 | if (!rdev->ops->set_qos_map) | |
10582 | return -EOPNOTSUPP; | |
10583 | ||
10584 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
10585 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
10586 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
10587 | ||
10588 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
10589 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
10590 | return -EINVAL; | |
10591 | ||
10592 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
10593 | if (!qos_map) | |
10594 | return -ENOMEM; | |
10595 | ||
10596 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
10597 | if (num_des) { | |
10598 | des_len = num_des * | |
10599 | sizeof(struct cfg80211_dscp_exception); | |
10600 | memcpy(qos_map->dscp_exception, pos, des_len); | |
10601 | qos_map->num_des = num_des; | |
10602 | for (des = 0; des < num_des; des++) { | |
10603 | if (qos_map->dscp_exception[des].up > 7) { | |
10604 | kfree(qos_map); | |
10605 | return -EINVAL; | |
10606 | } | |
10607 | } | |
10608 | pos += des_len; | |
10609 | } | |
10610 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
10611 | } | |
10612 | ||
10613 | wdev_lock(dev->ieee80211_ptr); | |
10614 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
10615 | if (!ret) | |
10616 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
10617 | wdev_unlock(dev->ieee80211_ptr); | |
10618 | ||
10619 | kfree(qos_map); | |
10620 | return ret; | |
10621 | } | |
10622 | ||
960d01ac JB |
10623 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
10624 | { | |
10625 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10626 | struct net_device *dev = info->user_ptr[1]; | |
10627 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10628 | const u8 *peer; | |
10629 | u8 tsid, up; | |
10630 | u16 admitted_time = 0; | |
10631 | int err; | |
10632 | ||
723e73ac | 10633 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
960d01ac JB |
10634 | return -EOPNOTSUPP; |
10635 | ||
10636 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | |
10637 | !info->attrs[NL80211_ATTR_USER_PRIO]) | |
10638 | return -EINVAL; | |
10639 | ||
10640 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
10641 | if (tsid >= IEEE80211_NUM_TIDS) | |
10642 | return -EINVAL; | |
10643 | ||
10644 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); | |
10645 | if (up >= IEEE80211_NUM_UPS) | |
10646 | return -EINVAL; | |
10647 | ||
10648 | /* WMM uses TIDs 0-7 even for TSPEC */ | |
723e73ac | 10649 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
960d01ac | 10650 | /* TODO: handle 802.11 TSPEC/admission control |
723e73ac JB |
10651 | * need more attributes for that (e.g. BA session requirement); |
10652 | * change the WMM adminssion test above to allow both then | |
960d01ac JB |
10653 | */ |
10654 | return -EINVAL; | |
10655 | } | |
10656 | ||
10657 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10658 | ||
10659 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | |
10660 | admitted_time = | |
10661 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | |
10662 | if (!admitted_time) | |
10663 | return -EINVAL; | |
10664 | } | |
10665 | ||
10666 | wdev_lock(wdev); | |
10667 | switch (wdev->iftype) { | |
10668 | case NL80211_IFTYPE_STATION: | |
10669 | case NL80211_IFTYPE_P2P_CLIENT: | |
10670 | if (wdev->current_bss) | |
10671 | break; | |
10672 | err = -ENOTCONN; | |
10673 | goto out; | |
10674 | default: | |
10675 | err = -EOPNOTSUPP; | |
10676 | goto out; | |
10677 | } | |
10678 | ||
10679 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | |
10680 | ||
10681 | out: | |
10682 | wdev_unlock(wdev); | |
10683 | return err; | |
10684 | } | |
10685 | ||
10686 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | |
10687 | { | |
10688 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10689 | struct net_device *dev = info->user_ptr[1]; | |
10690 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10691 | const u8 *peer; | |
10692 | u8 tsid; | |
10693 | int err; | |
10694 | ||
10695 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | |
10696 | return -EINVAL; | |
10697 | ||
10698 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
10699 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10700 | ||
10701 | wdev_lock(wdev); | |
10702 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | |
10703 | wdev_unlock(wdev); | |
10704 | ||
10705 | return err; | |
10706 | } | |
10707 | ||
1057d35e AN |
10708 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
10709 | struct genl_info *info) | |
10710 | { | |
10711 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10712 | struct net_device *dev = info->user_ptr[1]; | |
10713 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10714 | struct cfg80211_chan_def chandef = {}; | |
10715 | const u8 *addr; | |
10716 | u8 oper_class; | |
10717 | int err; | |
10718 | ||
10719 | if (!rdev->ops->tdls_channel_switch || | |
10720 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
10721 | return -EOPNOTSUPP; | |
10722 | ||
10723 | switch (dev->ieee80211_ptr->iftype) { | |
10724 | case NL80211_IFTYPE_STATION: | |
10725 | case NL80211_IFTYPE_P2P_CLIENT: | |
10726 | break; | |
10727 | default: | |
10728 | return -EOPNOTSUPP; | |
10729 | } | |
10730 | ||
10731 | if (!info->attrs[NL80211_ATTR_MAC] || | |
10732 | !info->attrs[NL80211_ATTR_OPER_CLASS]) | |
10733 | return -EINVAL; | |
10734 | ||
10735 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
10736 | if (err) | |
10737 | return err; | |
10738 | ||
10739 | /* | |
10740 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | |
10741 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | |
10742 | * specification is not defined for them. | |
10743 | */ | |
10744 | if (chandef.chan->band == IEEE80211_BAND_2GHZ && | |
10745 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | |
10746 | chandef.width != NL80211_CHAN_WIDTH_20) | |
10747 | return -EINVAL; | |
10748 | ||
10749 | /* we will be active on the TDLS link */ | |
923b352f AN |
10750 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
10751 | wdev->iftype)) | |
1057d35e AN |
10752 | return -EINVAL; |
10753 | ||
10754 | /* don't allow switching to DFS channels */ | |
10755 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | |
10756 | return -EINVAL; | |
10757 | ||
10758 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10759 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | |
10760 | ||
10761 | wdev_lock(wdev); | |
10762 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | |
10763 | wdev_unlock(wdev); | |
10764 | ||
10765 | return err; | |
10766 | } | |
10767 | ||
10768 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | |
10769 | struct genl_info *info) | |
10770 | { | |
10771 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10772 | struct net_device *dev = info->user_ptr[1]; | |
10773 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10774 | const u8 *addr; | |
10775 | ||
10776 | if (!rdev->ops->tdls_channel_switch || | |
10777 | !rdev->ops->tdls_cancel_channel_switch || | |
10778 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
10779 | return -EOPNOTSUPP; | |
10780 | ||
10781 | switch (dev->ieee80211_ptr->iftype) { | |
10782 | case NL80211_IFTYPE_STATION: | |
10783 | case NL80211_IFTYPE_P2P_CLIENT: | |
10784 | break; | |
10785 | default: | |
10786 | return -EOPNOTSUPP; | |
10787 | } | |
10788 | ||
10789 | if (!info->attrs[NL80211_ATTR_MAC]) | |
10790 | return -EINVAL; | |
10791 | ||
10792 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10793 | ||
10794 | wdev_lock(wdev); | |
10795 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); | |
10796 | wdev_unlock(wdev); | |
10797 | ||
10798 | return 0; | |
10799 | } | |
10800 | ||
4c476991 JB |
10801 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
10802 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
10803 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
10804 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
10805 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
10806 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 10807 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 10808 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
10809 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
10810 | NL80211_FLAG_CHECK_NETDEV_UP) | |
5393b917 | 10811 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
4c476991 | 10812 | |
f84f771d | 10813 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10814 | struct genl_info *info) |
10815 | { | |
10816 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 10817 | struct wireless_dev *wdev; |
4c476991 | 10818 | struct net_device *dev; |
4c476991 JB |
10819 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
10820 | ||
10821 | if (rtnl) | |
10822 | rtnl_lock(); | |
10823 | ||
10824 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 10825 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
10826 | if (IS_ERR(rdev)) { |
10827 | if (rtnl) | |
10828 | rtnl_unlock(); | |
10829 | return PTR_ERR(rdev); | |
10830 | } | |
10831 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
10832 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
10833 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
10834 | ASSERT_RTNL(); |
10835 | ||
89a54e48 JB |
10836 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
10837 | info->attrs); | |
10838 | if (IS_ERR(wdev)) { | |
4c476991 JB |
10839 | if (rtnl) |
10840 | rtnl_unlock(); | |
89a54e48 | 10841 | return PTR_ERR(wdev); |
4c476991 | 10842 | } |
89a54e48 | 10843 | |
89a54e48 | 10844 | dev = wdev->netdev; |
f26cbf40 | 10845 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 10846 | |
1bf614ef JB |
10847 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
10848 | if (!dev) { | |
1bf614ef JB |
10849 | if (rtnl) |
10850 | rtnl_unlock(); | |
10851 | return -EINVAL; | |
10852 | } | |
10853 | ||
10854 | info->user_ptr[1] = dev; | |
10855 | } else { | |
10856 | info->user_ptr[1] = wdev; | |
41265714 | 10857 | } |
1bf614ef JB |
10858 | |
10859 | if (dev) { | |
10860 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
10861 | !netif_running(dev)) { | |
1bf614ef JB |
10862 | if (rtnl) |
10863 | rtnl_unlock(); | |
10864 | return -ENETDOWN; | |
10865 | } | |
10866 | ||
10867 | dev_hold(dev); | |
98104fde JB |
10868 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
10869 | if (!wdev->p2p_started) { | |
98104fde JB |
10870 | if (rtnl) |
10871 | rtnl_unlock(); | |
10872 | return -ENETDOWN; | |
10873 | } | |
41265714 | 10874 | } |
89a54e48 | 10875 | |
4c476991 | 10876 | info->user_ptr[0] = rdev; |
4c476991 JB |
10877 | } |
10878 | ||
10879 | return 0; | |
10880 | } | |
10881 | ||
f84f771d | 10882 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10883 | struct genl_info *info) |
10884 | { | |
1bf614ef JB |
10885 | if (info->user_ptr[1]) { |
10886 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
10887 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10888 | ||
10889 | if (wdev->netdev) | |
10890 | dev_put(wdev->netdev); | |
10891 | } else { | |
10892 | dev_put(info->user_ptr[1]); | |
10893 | } | |
10894 | } | |
5393b917 | 10895 | |
4c476991 JB |
10896 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
10897 | rtnl_unlock(); | |
5393b917 JB |
10898 | |
10899 | /* If needed, clear the netlink message payload from the SKB | |
10900 | * as it might contain key data that shouldn't stick around on | |
10901 | * the heap after the SKB is freed. The netlink message header | |
10902 | * is still needed for further processing, so leave it intact. | |
10903 | */ | |
10904 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | |
10905 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | |
10906 | ||
10907 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | |
10908 | } | |
4c476991 JB |
10909 | } |
10910 | ||
4534de83 | 10911 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
10912 | { |
10913 | .cmd = NL80211_CMD_GET_WIPHY, | |
10914 | .doit = nl80211_get_wiphy, | |
10915 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 10916 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
10917 | .policy = nl80211_policy, |
10918 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10919 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10920 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10921 | }, |
10922 | { | |
10923 | .cmd = NL80211_CMD_SET_WIPHY, | |
10924 | .doit = nl80211_set_wiphy, | |
10925 | .policy = nl80211_policy, | |
10926 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 10927 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
10928 | }, |
10929 | { | |
10930 | .cmd = NL80211_CMD_GET_INTERFACE, | |
10931 | .doit = nl80211_get_interface, | |
10932 | .dumpit = nl80211_dump_interface, | |
10933 | .policy = nl80211_policy, | |
10934 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10935 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
10936 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10937 | }, |
10938 | { | |
10939 | .cmd = NL80211_CMD_SET_INTERFACE, | |
10940 | .doit = nl80211_set_interface, | |
10941 | .policy = nl80211_policy, | |
10942 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10943 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10944 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10945 | }, |
10946 | { | |
10947 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
10948 | .doit = nl80211_new_interface, | |
10949 | .policy = nl80211_policy, | |
10950 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10951 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10952 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10953 | }, |
10954 | { | |
10955 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
10956 | .doit = nl80211_del_interface, | |
10957 | .policy = nl80211_policy, | |
41ade00f | 10958 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 10959 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10960 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10961 | }, |
10962 | { | |
10963 | .cmd = NL80211_CMD_GET_KEY, | |
10964 | .doit = nl80211_get_key, | |
10965 | .policy = nl80211_policy, | |
10966 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10967 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10968 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10969 | }, |
10970 | { | |
10971 | .cmd = NL80211_CMD_SET_KEY, | |
10972 | .doit = nl80211_set_key, | |
10973 | .policy = nl80211_policy, | |
10974 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10975 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10976 | NL80211_FLAG_NEED_RTNL | |
10977 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10978 | }, |
10979 | { | |
10980 | .cmd = NL80211_CMD_NEW_KEY, | |
10981 | .doit = nl80211_new_key, | |
10982 | .policy = nl80211_policy, | |
10983 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10984 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10985 | NL80211_FLAG_NEED_RTNL | |
10986 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10987 | }, |
10988 | { | |
10989 | .cmd = NL80211_CMD_DEL_KEY, | |
10990 | .doit = nl80211_del_key, | |
10991 | .policy = nl80211_policy, | |
55682965 | 10992 | .flags = GENL_ADMIN_PERM, |
41265714 | 10993 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10994 | NL80211_FLAG_NEED_RTNL, |
55682965 | 10995 | }, |
ed1b6cc7 JB |
10996 | { |
10997 | .cmd = NL80211_CMD_SET_BEACON, | |
10998 | .policy = nl80211_policy, | |
10999 | .flags = GENL_ADMIN_PERM, | |
8860020e | 11000 | .doit = nl80211_set_beacon, |
2b5f8b0b | 11001 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11002 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
11003 | }, |
11004 | { | |
8860020e | 11005 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
11006 | .policy = nl80211_policy, |
11007 | .flags = GENL_ADMIN_PERM, | |
8860020e | 11008 | .doit = nl80211_start_ap, |
2b5f8b0b | 11009 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11010 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
11011 | }, |
11012 | { | |
8860020e | 11013 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
11014 | .policy = nl80211_policy, |
11015 | .flags = GENL_ADMIN_PERM, | |
8860020e | 11016 | .doit = nl80211_stop_ap, |
2b5f8b0b | 11017 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11018 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 11019 | }, |
5727ef1b JB |
11020 | { |
11021 | .cmd = NL80211_CMD_GET_STATION, | |
11022 | .doit = nl80211_get_station, | |
2ec600d6 | 11023 | .dumpit = nl80211_dump_station, |
5727ef1b | 11024 | .policy = nl80211_policy, |
4c476991 JB |
11025 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11026 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
11027 | }, |
11028 | { | |
11029 | .cmd = NL80211_CMD_SET_STATION, | |
11030 | .doit = nl80211_set_station, | |
11031 | .policy = nl80211_policy, | |
11032 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 11033 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11034 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
11035 | }, |
11036 | { | |
11037 | .cmd = NL80211_CMD_NEW_STATION, | |
11038 | .doit = nl80211_new_station, | |
11039 | .policy = nl80211_policy, | |
11040 | .flags = GENL_ADMIN_PERM, | |
41265714 | 11041 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11042 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
11043 | }, |
11044 | { | |
11045 | .cmd = NL80211_CMD_DEL_STATION, | |
11046 | .doit = nl80211_del_station, | |
11047 | .policy = nl80211_policy, | |
2ec600d6 | 11048 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 11049 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11050 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
11051 | }, |
11052 | { | |
11053 | .cmd = NL80211_CMD_GET_MPATH, | |
11054 | .doit = nl80211_get_mpath, | |
11055 | .dumpit = nl80211_dump_mpath, | |
11056 | .policy = nl80211_policy, | |
11057 | .flags = GENL_ADMIN_PERM, | |
41265714 | 11058 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11059 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 | 11060 | }, |
66be7d2b HR |
11061 | { |
11062 | .cmd = NL80211_CMD_GET_MPP, | |
11063 | .doit = nl80211_get_mpp, | |
11064 | .dumpit = nl80211_dump_mpp, | |
11065 | .policy = nl80211_policy, | |
11066 | .flags = GENL_ADMIN_PERM, | |
11067 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11068 | NL80211_FLAG_NEED_RTNL, | |
11069 | }, | |
2ec600d6 LCC |
11070 | { |
11071 | .cmd = NL80211_CMD_SET_MPATH, | |
11072 | .doit = nl80211_set_mpath, | |
11073 | .policy = nl80211_policy, | |
11074 | .flags = GENL_ADMIN_PERM, | |
41265714 | 11075 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11076 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
11077 | }, |
11078 | { | |
11079 | .cmd = NL80211_CMD_NEW_MPATH, | |
11080 | .doit = nl80211_new_mpath, | |
11081 | .policy = nl80211_policy, | |
11082 | .flags = GENL_ADMIN_PERM, | |
41265714 | 11083 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11084 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
11085 | }, |
11086 | { | |
11087 | .cmd = NL80211_CMD_DEL_MPATH, | |
11088 | .doit = nl80211_del_mpath, | |
11089 | .policy = nl80211_policy, | |
9f1ba906 | 11090 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 11091 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11092 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
11093 | }, |
11094 | { | |
11095 | .cmd = NL80211_CMD_SET_BSS, | |
11096 | .doit = nl80211_set_bss, | |
11097 | .policy = nl80211_policy, | |
b2e1b302 | 11098 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 11099 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11100 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 11101 | }, |
f130347c LR |
11102 | { |
11103 | .cmd = NL80211_CMD_GET_REG, | |
ad30ca2c AN |
11104 | .doit = nl80211_get_reg_do, |
11105 | .dumpit = nl80211_get_reg_dump, | |
f130347c | 11106 | .policy = nl80211_policy, |
5fe231e8 | 11107 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
11108 | /* can be retrieved by unprivileged users */ |
11109 | }, | |
b6863036 | 11110 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
b2e1b302 LR |
11111 | { |
11112 | .cmd = NL80211_CMD_SET_REG, | |
11113 | .doit = nl80211_set_reg, | |
11114 | .policy = nl80211_policy, | |
11115 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 11116 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 11117 | }, |
b6863036 | 11118 | #endif |
b2e1b302 LR |
11119 | { |
11120 | .cmd = NL80211_CMD_REQ_SET_REG, | |
11121 | .doit = nl80211_req_set_reg, | |
11122 | .policy = nl80211_policy, | |
93da9cc1 | 11123 | .flags = GENL_ADMIN_PERM, |
11124 | }, | |
11125 | { | |
24bdd9f4 JC |
11126 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
11127 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 11128 | .policy = nl80211_policy, |
11129 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 11130 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11131 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 11132 | }, |
11133 | { | |
24bdd9f4 JC |
11134 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
11135 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 11136 | .policy = nl80211_policy, |
9aed3cc1 | 11137 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 11138 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11139 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 11140 | }, |
2a519311 JB |
11141 | { |
11142 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
11143 | .doit = nl80211_trigger_scan, | |
11144 | .policy = nl80211_policy, | |
11145 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 11146 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 11147 | NL80211_FLAG_NEED_RTNL, |
2a519311 | 11148 | }, |
91d3ab46 VK |
11149 | { |
11150 | .cmd = NL80211_CMD_ABORT_SCAN, | |
11151 | .doit = nl80211_abort_scan, | |
11152 | .policy = nl80211_policy, | |
11153 | .flags = GENL_ADMIN_PERM, | |
11154 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
11155 | NL80211_FLAG_NEED_RTNL, | |
11156 | }, | |
2a519311 JB |
11157 | { |
11158 | .cmd = NL80211_CMD_GET_SCAN, | |
11159 | .policy = nl80211_policy, | |
11160 | .dumpit = nl80211_dump_scan, | |
11161 | }, | |
807f8a8c LC |
11162 | { |
11163 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
11164 | .doit = nl80211_start_sched_scan, | |
11165 | .policy = nl80211_policy, | |
11166 | .flags = GENL_ADMIN_PERM, | |
11167 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11168 | NL80211_FLAG_NEED_RTNL, | |
11169 | }, | |
11170 | { | |
11171 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
11172 | .doit = nl80211_stop_sched_scan, | |
11173 | .policy = nl80211_policy, | |
11174 | .flags = GENL_ADMIN_PERM, | |
11175 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11176 | NL80211_FLAG_NEED_RTNL, | |
11177 | }, | |
636a5d36 JM |
11178 | { |
11179 | .cmd = NL80211_CMD_AUTHENTICATE, | |
11180 | .doit = nl80211_authenticate, | |
11181 | .policy = nl80211_policy, | |
11182 | .flags = GENL_ADMIN_PERM, | |
41265714 | 11183 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
11184 | NL80211_FLAG_NEED_RTNL | |
11185 | NL80211_FLAG_CLEAR_SKB, | |
636a5d36 JM |
11186 | }, |
11187 | { | |
11188 | .cmd = NL80211_CMD_ASSOCIATE, | |
11189 | .doit = nl80211_associate, | |
11190 | .policy = nl80211_policy, | |
11191 | .flags = GENL_ADMIN_PERM, | |
41265714 | 11192 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11193 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
11194 | }, |
11195 | { | |
11196 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
11197 | .doit = nl80211_deauthenticate, | |
11198 | .policy = nl80211_policy, | |
11199 | .flags = GENL_ADMIN_PERM, | |
41265714 | 11200 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11201 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
11202 | }, |
11203 | { | |
11204 | .cmd = NL80211_CMD_DISASSOCIATE, | |
11205 | .doit = nl80211_disassociate, | |
11206 | .policy = nl80211_policy, | |
11207 | .flags = GENL_ADMIN_PERM, | |
41265714 | 11208 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11209 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 11210 | }, |
04a773ad JB |
11211 | { |
11212 | .cmd = NL80211_CMD_JOIN_IBSS, | |
11213 | .doit = nl80211_join_ibss, | |
11214 | .policy = nl80211_policy, | |
11215 | .flags = GENL_ADMIN_PERM, | |
41265714 | 11216 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11217 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
11218 | }, |
11219 | { | |
11220 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
11221 | .doit = nl80211_leave_ibss, | |
11222 | .policy = nl80211_policy, | |
11223 | .flags = GENL_ADMIN_PERM, | |
41265714 | 11224 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11225 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 11226 | }, |
aff89a9b JB |
11227 | #ifdef CONFIG_NL80211_TESTMODE |
11228 | { | |
11229 | .cmd = NL80211_CMD_TESTMODE, | |
11230 | .doit = nl80211_testmode_do, | |
71063f0e | 11231 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
11232 | .policy = nl80211_policy, |
11233 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
11234 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11235 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
11236 | }, |
11237 | #endif | |
b23aa676 SO |
11238 | { |
11239 | .cmd = NL80211_CMD_CONNECT, | |
11240 | .doit = nl80211_connect, | |
11241 | .policy = nl80211_policy, | |
11242 | .flags = GENL_ADMIN_PERM, | |
41265714 | 11243 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11244 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
11245 | }, |
11246 | { | |
11247 | .cmd = NL80211_CMD_DISCONNECT, | |
11248 | .doit = nl80211_disconnect, | |
11249 | .policy = nl80211_policy, | |
11250 | .flags = GENL_ADMIN_PERM, | |
41265714 | 11251 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11252 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 11253 | }, |
463d0183 JB |
11254 | { |
11255 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
11256 | .doit = nl80211_wiphy_netns, | |
11257 | .policy = nl80211_policy, | |
11258 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
11259 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11260 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 11261 | }, |
61fa713c HS |
11262 | { |
11263 | .cmd = NL80211_CMD_GET_SURVEY, | |
11264 | .policy = nl80211_policy, | |
11265 | .dumpit = nl80211_dump_survey, | |
11266 | }, | |
67fbb16b SO |
11267 | { |
11268 | .cmd = NL80211_CMD_SET_PMKSA, | |
11269 | .doit = nl80211_setdel_pmksa, | |
11270 | .policy = nl80211_policy, | |
11271 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 11272 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11273 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
11274 | }, |
11275 | { | |
11276 | .cmd = NL80211_CMD_DEL_PMKSA, | |
11277 | .doit = nl80211_setdel_pmksa, | |
11278 | .policy = nl80211_policy, | |
11279 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 11280 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11281 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
11282 | }, |
11283 | { | |
11284 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
11285 | .doit = nl80211_flush_pmksa, | |
11286 | .policy = nl80211_policy, | |
11287 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 11288 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11289 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 11290 | }, |
9588bbd5 JM |
11291 | { |
11292 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
11293 | .doit = nl80211_remain_on_channel, | |
11294 | .policy = nl80211_policy, | |
11295 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 11296 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 11297 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
11298 | }, |
11299 | { | |
11300 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
11301 | .doit = nl80211_cancel_remain_on_channel, | |
11302 | .policy = nl80211_policy, | |
11303 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 11304 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 11305 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 11306 | }, |
13ae75b1 JM |
11307 | { |
11308 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
11309 | .doit = nl80211_set_tx_bitrate_mask, | |
11310 | .policy = nl80211_policy, | |
11311 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
11312 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11313 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 11314 | }, |
026331c4 | 11315 | { |
2e161f78 JB |
11316 | .cmd = NL80211_CMD_REGISTER_FRAME, |
11317 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
11318 | .policy = nl80211_policy, |
11319 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 11320 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 11321 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
11322 | }, |
11323 | { | |
2e161f78 JB |
11324 | .cmd = NL80211_CMD_FRAME, |
11325 | .doit = nl80211_tx_mgmt, | |
026331c4 | 11326 | .policy = nl80211_policy, |
f7ca38df | 11327 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 11328 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
11329 | NL80211_FLAG_NEED_RTNL, |
11330 | }, | |
11331 | { | |
11332 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
11333 | .doit = nl80211_tx_mgmt_cancel_wait, | |
11334 | .policy = nl80211_policy, | |
026331c4 | 11335 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 11336 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 11337 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 11338 | }, |
ffb9eb3d KV |
11339 | { |
11340 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
11341 | .doit = nl80211_set_power_save, | |
11342 | .policy = nl80211_policy, | |
11343 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
11344 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11345 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
11346 | }, |
11347 | { | |
11348 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
11349 | .doit = nl80211_get_power_save, | |
11350 | .policy = nl80211_policy, | |
11351 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
11352 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11353 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 11354 | }, |
d6dc1a38 JO |
11355 | { |
11356 | .cmd = NL80211_CMD_SET_CQM, | |
11357 | .doit = nl80211_set_cqm, | |
11358 | .policy = nl80211_policy, | |
11359 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
11360 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11361 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 11362 | }, |
f444de05 JB |
11363 | { |
11364 | .cmd = NL80211_CMD_SET_CHANNEL, | |
11365 | .doit = nl80211_set_channel, | |
11366 | .policy = nl80211_policy, | |
11367 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
11368 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11369 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 11370 | }, |
e8347eba BJ |
11371 | { |
11372 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
11373 | .doit = nl80211_set_wds_peer, | |
11374 | .policy = nl80211_policy, | |
11375 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
11376 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11377 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 11378 | }, |
29cbe68c JB |
11379 | { |
11380 | .cmd = NL80211_CMD_JOIN_MESH, | |
11381 | .doit = nl80211_join_mesh, | |
11382 | .policy = nl80211_policy, | |
11383 | .flags = GENL_ADMIN_PERM, | |
11384 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11385 | NL80211_FLAG_NEED_RTNL, | |
11386 | }, | |
11387 | { | |
11388 | .cmd = NL80211_CMD_LEAVE_MESH, | |
11389 | .doit = nl80211_leave_mesh, | |
11390 | .policy = nl80211_policy, | |
11391 | .flags = GENL_ADMIN_PERM, | |
11392 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11393 | NL80211_FLAG_NEED_RTNL, | |
11394 | }, | |
6e0bd6c3 RL |
11395 | { |
11396 | .cmd = NL80211_CMD_JOIN_OCB, | |
11397 | .doit = nl80211_join_ocb, | |
11398 | .policy = nl80211_policy, | |
11399 | .flags = GENL_ADMIN_PERM, | |
11400 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11401 | NL80211_FLAG_NEED_RTNL, | |
11402 | }, | |
11403 | { | |
11404 | .cmd = NL80211_CMD_LEAVE_OCB, | |
11405 | .doit = nl80211_leave_ocb, | |
11406 | .policy = nl80211_policy, | |
11407 | .flags = GENL_ADMIN_PERM, | |
11408 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11409 | NL80211_FLAG_NEED_RTNL, | |
11410 | }, | |
dfb89c56 | 11411 | #ifdef CONFIG_PM |
ff1b6e69 JB |
11412 | { |
11413 | .cmd = NL80211_CMD_GET_WOWLAN, | |
11414 | .doit = nl80211_get_wowlan, | |
11415 | .policy = nl80211_policy, | |
11416 | /* can be retrieved by unprivileged users */ | |
11417 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
11418 | NL80211_FLAG_NEED_RTNL, | |
11419 | }, | |
11420 | { | |
11421 | .cmd = NL80211_CMD_SET_WOWLAN, | |
11422 | .doit = nl80211_set_wowlan, | |
11423 | .policy = nl80211_policy, | |
11424 | .flags = GENL_ADMIN_PERM, | |
11425 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
11426 | NL80211_FLAG_NEED_RTNL, | |
11427 | }, | |
dfb89c56 | 11428 | #endif |
e5497d76 JB |
11429 | { |
11430 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
11431 | .doit = nl80211_set_rekey_data, | |
11432 | .policy = nl80211_policy, | |
11433 | .flags = GENL_ADMIN_PERM, | |
11434 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
5393b917 JB |
11435 | NL80211_FLAG_NEED_RTNL | |
11436 | NL80211_FLAG_CLEAR_SKB, | |
e5497d76 | 11437 | }, |
109086ce AN |
11438 | { |
11439 | .cmd = NL80211_CMD_TDLS_MGMT, | |
11440 | .doit = nl80211_tdls_mgmt, | |
11441 | .policy = nl80211_policy, | |
11442 | .flags = GENL_ADMIN_PERM, | |
11443 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11444 | NL80211_FLAG_NEED_RTNL, | |
11445 | }, | |
11446 | { | |
11447 | .cmd = NL80211_CMD_TDLS_OPER, | |
11448 | .doit = nl80211_tdls_oper, | |
11449 | .policy = nl80211_policy, | |
11450 | .flags = GENL_ADMIN_PERM, | |
11451 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11452 | NL80211_FLAG_NEED_RTNL, | |
11453 | }, | |
28946da7 JB |
11454 | { |
11455 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
11456 | .doit = nl80211_register_unexpected_frame, | |
11457 | .policy = nl80211_policy, | |
11458 | .flags = GENL_ADMIN_PERM, | |
11459 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
11460 | NL80211_FLAG_NEED_RTNL, | |
11461 | }, | |
7f6cf311 JB |
11462 | { |
11463 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
11464 | .doit = nl80211_probe_client, | |
11465 | .policy = nl80211_policy, | |
11466 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 11467 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
11468 | NL80211_FLAG_NEED_RTNL, |
11469 | }, | |
5e760230 JB |
11470 | { |
11471 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
11472 | .doit = nl80211_register_beacons, | |
11473 | .policy = nl80211_policy, | |
11474 | .flags = GENL_ADMIN_PERM, | |
11475 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
11476 | NL80211_FLAG_NEED_RTNL, | |
11477 | }, | |
1d9d9213 SW |
11478 | { |
11479 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
11480 | .doit = nl80211_set_noack_map, | |
11481 | .policy = nl80211_policy, | |
11482 | .flags = GENL_ADMIN_PERM, | |
11483 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
11484 | NL80211_FLAG_NEED_RTNL, | |
11485 | }, | |
98104fde JB |
11486 | { |
11487 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
11488 | .doit = nl80211_start_p2p_device, | |
11489 | .policy = nl80211_policy, | |
11490 | .flags = GENL_ADMIN_PERM, | |
11491 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
11492 | NL80211_FLAG_NEED_RTNL, | |
11493 | }, | |
11494 | { | |
11495 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
11496 | .doit = nl80211_stop_p2p_device, | |
11497 | .policy = nl80211_policy, | |
11498 | .flags = GENL_ADMIN_PERM, | |
11499 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
11500 | NL80211_FLAG_NEED_RTNL, | |
11501 | }, | |
f4e583c8 AQ |
11502 | { |
11503 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
11504 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
11505 | .policy = nl80211_policy, |
11506 | .flags = GENL_ADMIN_PERM, | |
11507 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
11508 | NL80211_FLAG_NEED_RTNL, | |
11509 | }, | |
11510 | { | |
11511 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
11512 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
11513 | .policy = nl80211_policy, |
11514 | .flags = GENL_ADMIN_PERM, | |
11515 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
11516 | NL80211_FLAG_NEED_RTNL, | |
11517 | }, | |
04f39047 SW |
11518 | { |
11519 | .cmd = NL80211_CMD_RADAR_DETECT, | |
11520 | .doit = nl80211_start_radar_detection, | |
11521 | .policy = nl80211_policy, | |
11522 | .flags = GENL_ADMIN_PERM, | |
11523 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11524 | NL80211_FLAG_NEED_RTNL, | |
11525 | }, | |
3713b4e3 JB |
11526 | { |
11527 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
11528 | .doit = nl80211_get_protocol_features, | |
11529 | .policy = nl80211_policy, | |
11530 | }, | |
355199e0 JM |
11531 | { |
11532 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
11533 | .doit = nl80211_update_ft_ies, | |
11534 | .policy = nl80211_policy, | |
11535 | .flags = GENL_ADMIN_PERM, | |
11536 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11537 | NL80211_FLAG_NEED_RTNL, | |
11538 | }, | |
5de17984 AS |
11539 | { |
11540 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
11541 | .doit = nl80211_crit_protocol_start, | |
11542 | .policy = nl80211_policy, | |
11543 | .flags = GENL_ADMIN_PERM, | |
11544 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
11545 | NL80211_FLAG_NEED_RTNL, | |
11546 | }, | |
11547 | { | |
11548 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
11549 | .doit = nl80211_crit_protocol_stop, | |
11550 | .policy = nl80211_policy, | |
11551 | .flags = GENL_ADMIN_PERM, | |
11552 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
11553 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
11554 | }, |
11555 | { | |
11556 | .cmd = NL80211_CMD_GET_COALESCE, | |
11557 | .doit = nl80211_get_coalesce, | |
11558 | .policy = nl80211_policy, | |
11559 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
11560 | NL80211_FLAG_NEED_RTNL, | |
11561 | }, | |
11562 | { | |
11563 | .cmd = NL80211_CMD_SET_COALESCE, | |
11564 | .doit = nl80211_set_coalesce, | |
11565 | .policy = nl80211_policy, | |
11566 | .flags = GENL_ADMIN_PERM, | |
11567 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
11568 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
11569 | }, |
11570 | { | |
11571 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
11572 | .doit = nl80211_channel_switch, | |
11573 | .policy = nl80211_policy, | |
11574 | .flags = GENL_ADMIN_PERM, | |
11575 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11576 | NL80211_FLAG_NEED_RTNL, | |
11577 | }, | |
ad7e718c JB |
11578 | { |
11579 | .cmd = NL80211_CMD_VENDOR, | |
11580 | .doit = nl80211_vendor_cmd, | |
7bdbe400 | 11581 | .dumpit = nl80211_vendor_cmd_dump, |
ad7e718c JB |
11582 | .policy = nl80211_policy, |
11583 | .flags = GENL_ADMIN_PERM, | |
11584 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
11585 | NL80211_FLAG_NEED_RTNL, | |
11586 | }, | |
fa9ffc74 KP |
11587 | { |
11588 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
11589 | .doit = nl80211_set_qos_map, | |
11590 | .policy = nl80211_policy, | |
11591 | .flags = GENL_ADMIN_PERM, | |
11592 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11593 | NL80211_FLAG_NEED_RTNL, | |
11594 | }, | |
960d01ac JB |
11595 | { |
11596 | .cmd = NL80211_CMD_ADD_TX_TS, | |
11597 | .doit = nl80211_add_tx_ts, | |
11598 | .policy = nl80211_policy, | |
11599 | .flags = GENL_ADMIN_PERM, | |
11600 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11601 | NL80211_FLAG_NEED_RTNL, | |
11602 | }, | |
11603 | { | |
11604 | .cmd = NL80211_CMD_DEL_TX_TS, | |
11605 | .doit = nl80211_del_tx_ts, | |
11606 | .policy = nl80211_policy, | |
11607 | .flags = GENL_ADMIN_PERM, | |
11608 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11609 | NL80211_FLAG_NEED_RTNL, | |
11610 | }, | |
1057d35e AN |
11611 | { |
11612 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | |
11613 | .doit = nl80211_tdls_channel_switch, | |
11614 | .policy = nl80211_policy, | |
11615 | .flags = GENL_ADMIN_PERM, | |
11616 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11617 | NL80211_FLAG_NEED_RTNL, | |
11618 | }, | |
11619 | { | |
11620 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | |
11621 | .doit = nl80211_tdls_cancel_channel_switch, | |
11622 | .policy = nl80211_policy, | |
11623 | .flags = GENL_ADMIN_PERM, | |
11624 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11625 | NL80211_FLAG_NEED_RTNL, | |
11626 | }, | |
55682965 | 11627 | }; |
9588bbd5 | 11628 | |
55682965 JB |
11629 | /* notification functions */ |
11630 | ||
3bb20556 JB |
11631 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
11632 | enum nl80211_commands cmd) | |
55682965 JB |
11633 | { |
11634 | struct sk_buff *msg; | |
86e8cf98 | 11635 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 11636 | |
3bb20556 JB |
11637 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
11638 | cmd != NL80211_CMD_DEL_WIPHY); | |
11639 | ||
fd2120ca | 11640 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
11641 | if (!msg) |
11642 | return; | |
11643 | ||
3bb20556 | 11644 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
11645 | nlmsg_free(msg); |
11646 | return; | |
11647 | } | |
11648 | ||
68eb5503 | 11649 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11650 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
11651 | } |
11652 | ||
362a415d JB |
11653 | static int nl80211_add_scan_req(struct sk_buff *msg, |
11654 | struct cfg80211_registered_device *rdev) | |
11655 | { | |
11656 | struct cfg80211_scan_request *req = rdev->scan_req; | |
11657 | struct nlattr *nest; | |
11658 | int i; | |
11659 | ||
11660 | if (WARN_ON(!req)) | |
11661 | return 0; | |
11662 | ||
11663 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
11664 | if (!nest) | |
11665 | goto nla_put_failure; | |
9360ffd1 DM |
11666 | for (i = 0; i < req->n_ssids; i++) { |
11667 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
11668 | goto nla_put_failure; | |
11669 | } | |
362a415d JB |
11670 | nla_nest_end(msg, nest); |
11671 | ||
11672 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
11673 | if (!nest) | |
11674 | goto nla_put_failure; | |
9360ffd1 DM |
11675 | for (i = 0; i < req->n_channels; i++) { |
11676 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
11677 | goto nla_put_failure; | |
11678 | } | |
362a415d JB |
11679 | nla_nest_end(msg, nest); |
11680 | ||
9360ffd1 DM |
11681 | if (req->ie && |
11682 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
11683 | goto nla_put_failure; | |
362a415d | 11684 | |
ae917c9f JB |
11685 | if (req->flags && |
11686 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
11687 | goto nla_put_failure; | |
ed473771 | 11688 | |
362a415d JB |
11689 | return 0; |
11690 | nla_put_failure: | |
11691 | return -ENOBUFS; | |
11692 | } | |
11693 | ||
a538e2d5 JB |
11694 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
11695 | struct cfg80211_registered_device *rdev, | |
fd014284 | 11696 | struct wireless_dev *wdev, |
15e47304 | 11697 | u32 portid, u32 seq, int flags, |
a538e2d5 | 11698 | u32 cmd) |
2a519311 JB |
11699 | { |
11700 | void *hdr; | |
11701 | ||
15e47304 | 11702 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
11703 | if (!hdr) |
11704 | return -1; | |
11705 | ||
9360ffd1 | 11706 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
11707 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11708 | wdev->netdev->ifindex)) || | |
11709 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 11710 | goto nla_put_failure; |
2a519311 | 11711 | |
362a415d JB |
11712 | /* ignore errors and send incomplete event anyway */ |
11713 | nl80211_add_scan_req(msg, rdev); | |
2a519311 | 11714 | |
053c095a JB |
11715 | genlmsg_end(msg, hdr); |
11716 | return 0; | |
2a519311 JB |
11717 | |
11718 | nla_put_failure: | |
11719 | genlmsg_cancel(msg, hdr); | |
11720 | return -EMSGSIZE; | |
11721 | } | |
11722 | ||
807f8a8c LC |
11723 | static int |
11724 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
11725 | struct cfg80211_registered_device *rdev, | |
11726 | struct net_device *netdev, | |
15e47304 | 11727 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
11728 | { |
11729 | void *hdr; | |
11730 | ||
15e47304 | 11731 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
11732 | if (!hdr) |
11733 | return -1; | |
11734 | ||
9360ffd1 DM |
11735 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11736 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
11737 | goto nla_put_failure; | |
807f8a8c | 11738 | |
053c095a JB |
11739 | genlmsg_end(msg, hdr); |
11740 | return 0; | |
807f8a8c LC |
11741 | |
11742 | nla_put_failure: | |
11743 | genlmsg_cancel(msg, hdr); | |
11744 | return -EMSGSIZE; | |
11745 | } | |
11746 | ||
a538e2d5 | 11747 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 11748 | struct wireless_dev *wdev) |
a538e2d5 JB |
11749 | { |
11750 | struct sk_buff *msg; | |
11751 | ||
58050fce | 11752 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
11753 | if (!msg) |
11754 | return; | |
11755 | ||
fd014284 | 11756 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
11757 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
11758 | nlmsg_free(msg); | |
11759 | return; | |
11760 | } | |
11761 | ||
68eb5503 | 11762 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11763 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
11764 | } |
11765 | ||
f9d15d16 JB |
11766 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
11767 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
11768 | { |
11769 | struct sk_buff *msg; | |
11770 | ||
fd2120ca | 11771 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 11772 | if (!msg) |
f9d15d16 | 11773 | return NULL; |
2a519311 | 11774 | |
fd014284 | 11775 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
11776 | aborted ? NL80211_CMD_SCAN_ABORTED : |
11777 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 11778 | nlmsg_free(msg); |
f9d15d16 | 11779 | return NULL; |
2a519311 JB |
11780 | } |
11781 | ||
f9d15d16 | 11782 | return msg; |
2a519311 JB |
11783 | } |
11784 | ||
f9d15d16 JB |
11785 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
11786 | struct sk_buff *msg) | |
2a519311 | 11787 | { |
2a519311 JB |
11788 | if (!msg) |
11789 | return; | |
11790 | ||
68eb5503 | 11791 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11792 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
11793 | } |
11794 | ||
807f8a8c LC |
11795 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
11796 | struct net_device *netdev) | |
11797 | { | |
11798 | struct sk_buff *msg; | |
11799 | ||
11800 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11801 | if (!msg) | |
11802 | return; | |
11803 | ||
11804 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
11805 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
11806 | nlmsg_free(msg); | |
11807 | return; | |
11808 | } | |
11809 | ||
68eb5503 | 11810 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11811 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11812 | } |
11813 | ||
11814 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
11815 | struct net_device *netdev, u32 cmd) | |
11816 | { | |
11817 | struct sk_buff *msg; | |
11818 | ||
58050fce | 11819 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
11820 | if (!msg) |
11821 | return; | |
11822 | ||
11823 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
11824 | nlmsg_free(msg); | |
11825 | return; | |
11826 | } | |
11827 | ||
68eb5503 | 11828 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11829 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11830 | } |
11831 | ||
b0d7aa59 JD |
11832 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
11833 | struct regulatory_request *request) | |
73d54c9e | 11834 | { |
73d54c9e | 11835 | /* Userspace can always count this one always being set */ |
9360ffd1 DM |
11836 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
11837 | goto nla_put_failure; | |
11838 | ||
11839 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
11840 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11841 | NL80211_REGDOM_TYPE_WORLD)) | |
11842 | goto nla_put_failure; | |
11843 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
11844 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11845 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
11846 | goto nla_put_failure; | |
11847 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
11848 | request->intersect) { | |
11849 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11850 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
11851 | goto nla_put_failure; | |
11852 | } else { | |
11853 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11854 | NL80211_REGDOM_TYPE_COUNTRY) || | |
11855 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
11856 | request->alpha2)) | |
11857 | goto nla_put_failure; | |
11858 | } | |
11859 | ||
ad30ca2c AN |
11860 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
11861 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); | |
11862 | ||
11863 | if (wiphy && | |
11864 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | |
11865 | goto nla_put_failure; | |
1bdd716c AN |
11866 | |
11867 | if (wiphy && | |
11868 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | |
11869 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
11870 | goto nla_put_failure; | |
ad30ca2c | 11871 | } |
73d54c9e | 11872 | |
b0d7aa59 JD |
11873 | return true; |
11874 | ||
11875 | nla_put_failure: | |
11876 | return false; | |
11877 | } | |
11878 | ||
11879 | /* | |
11880 | * This can happen on global regulatory changes or device specific settings | |
11881 | * based on custom regulatory domains. | |
11882 | */ | |
11883 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, | |
11884 | struct regulatory_request *request) | |
11885 | { | |
11886 | struct sk_buff *msg; | |
11887 | void *hdr; | |
11888 | ||
11889 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11890 | if (!msg) | |
11891 | return; | |
11892 | ||
11893 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); | |
11894 | if (!hdr) { | |
11895 | nlmsg_free(msg); | |
11896 | return; | |
11897 | } | |
11898 | ||
11899 | if (nl80211_reg_change_event_fill(msg, request) == false) | |
11900 | goto nla_put_failure; | |
11901 | ||
3b7b72ee | 11902 | genlmsg_end(msg, hdr); |
73d54c9e | 11903 | |
bc43b28c | 11904 | rcu_read_lock(); |
68eb5503 | 11905 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11906 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 11907 | rcu_read_unlock(); |
73d54c9e LR |
11908 | |
11909 | return; | |
11910 | ||
11911 | nla_put_failure: | |
11912 | genlmsg_cancel(msg, hdr); | |
11913 | nlmsg_free(msg); | |
11914 | } | |
11915 | ||
6039f6d2 JM |
11916 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
11917 | struct net_device *netdev, | |
11918 | const u8 *buf, size_t len, | |
b0b6aa2c EP |
11919 | enum nl80211_commands cmd, gfp_t gfp, |
11920 | int uapsd_queues) | |
6039f6d2 JM |
11921 | { |
11922 | struct sk_buff *msg; | |
11923 | void *hdr; | |
11924 | ||
e6d6e342 | 11925 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
11926 | if (!msg) |
11927 | return; | |
11928 | ||
11929 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11930 | if (!hdr) { | |
11931 | nlmsg_free(msg); | |
11932 | return; | |
11933 | } | |
11934 | ||
9360ffd1 DM |
11935 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11936 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11937 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
11938 | goto nla_put_failure; | |
6039f6d2 | 11939 | |
b0b6aa2c EP |
11940 | if (uapsd_queues >= 0) { |
11941 | struct nlattr *nla_wmm = | |
11942 | nla_nest_start(msg, NL80211_ATTR_STA_WME); | |
11943 | if (!nla_wmm) | |
11944 | goto nla_put_failure; | |
11945 | ||
11946 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
11947 | uapsd_queues)) | |
11948 | goto nla_put_failure; | |
11949 | ||
11950 | nla_nest_end(msg, nla_wmm); | |
11951 | } | |
11952 | ||
3b7b72ee | 11953 | genlmsg_end(msg, hdr); |
6039f6d2 | 11954 | |
68eb5503 | 11955 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11956 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
11957 | return; |
11958 | ||
11959 | nla_put_failure: | |
11960 | genlmsg_cancel(msg, hdr); | |
11961 | nlmsg_free(msg); | |
11962 | } | |
11963 | ||
11964 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11965 | struct net_device *netdev, const u8 *buf, |
11966 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11967 | { |
11968 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11969 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11970 | } |
11971 | ||
11972 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
11973 | struct net_device *netdev, const u8 *buf, | |
b0b6aa2c | 11974 | size_t len, gfp_t gfp, int uapsd_queues) |
6039f6d2 | 11975 | { |
e6d6e342 | 11976 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
b0b6aa2c | 11977 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
6039f6d2 JM |
11978 | } |
11979 | ||
53b46b84 | 11980 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
11981 | struct net_device *netdev, const u8 *buf, |
11982 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11983 | { |
11984 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11985 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11986 | } |
11987 | ||
53b46b84 JM |
11988 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
11989 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 11990 | size_t len, gfp_t gfp) |
6039f6d2 JM |
11991 | { |
11992 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11993 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
6039f6d2 JM |
11994 | } |
11995 | ||
6ff57cf8 JB |
11996 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
11997 | size_t len) | |
cf4e594e | 11998 | { |
947add36 JB |
11999 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
12000 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12001 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
12002 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
12003 | u32 cmd; | |
947add36 | 12004 | |
6ff57cf8 JB |
12005 | if (WARN_ON(len < 2)) |
12006 | return; | |
cf4e594e | 12007 | |
6ff57cf8 JB |
12008 | if (ieee80211_is_deauth(mgmt->frame_control)) |
12009 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
12010 | else | |
12011 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 12012 | |
6ff57cf8 | 12013 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
b0b6aa2c | 12014 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
cf4e594e | 12015 | } |
6ff57cf8 | 12016 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 12017 | |
1b06bb40 LR |
12018 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
12019 | struct net_device *netdev, int cmd, | |
e6d6e342 | 12020 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
12021 | { |
12022 | struct sk_buff *msg; | |
12023 | void *hdr; | |
12024 | ||
e6d6e342 | 12025 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
12026 | if (!msg) |
12027 | return; | |
12028 | ||
12029 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
12030 | if (!hdr) { | |
12031 | nlmsg_free(msg); | |
12032 | return; | |
12033 | } | |
12034 | ||
9360ffd1 DM |
12035 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12036 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12037 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
12038 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
12039 | goto nla_put_failure; | |
1965c853 | 12040 | |
3b7b72ee | 12041 | genlmsg_end(msg, hdr); |
1965c853 | 12042 | |
68eb5503 | 12043 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12044 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
12045 | return; |
12046 | ||
12047 | nla_put_failure: | |
12048 | genlmsg_cancel(msg, hdr); | |
12049 | nlmsg_free(msg); | |
12050 | } | |
12051 | ||
12052 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
12053 | struct net_device *netdev, const u8 *addr, |
12054 | gfp_t gfp) | |
1965c853 JM |
12055 | { |
12056 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 12057 | addr, gfp); |
1965c853 JM |
12058 | } |
12059 | ||
12060 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
12061 | struct net_device *netdev, const u8 *addr, |
12062 | gfp_t gfp) | |
1965c853 | 12063 | { |
e6d6e342 JB |
12064 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
12065 | addr, gfp); | |
1965c853 JM |
12066 | } |
12067 | ||
b23aa676 SO |
12068 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
12069 | struct net_device *netdev, const u8 *bssid, | |
12070 | const u8 *req_ie, size_t req_ie_len, | |
12071 | const u8 *resp_ie, size_t resp_ie_len, | |
12072 | u16 status, gfp_t gfp) | |
12073 | { | |
12074 | struct sk_buff *msg; | |
12075 | void *hdr; | |
12076 | ||
58050fce | 12077 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
12078 | if (!msg) |
12079 | return; | |
12080 | ||
12081 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
12082 | if (!hdr) { | |
12083 | nlmsg_free(msg); | |
12084 | return; | |
12085 | } | |
12086 | ||
9360ffd1 DM |
12087 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12088 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12089 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
12090 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
12091 | (req_ie && | |
12092 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
12093 | (resp_ie && | |
12094 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
12095 | goto nla_put_failure; | |
b23aa676 | 12096 | |
3b7b72ee | 12097 | genlmsg_end(msg, hdr); |
b23aa676 | 12098 | |
68eb5503 | 12099 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12100 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
12101 | return; |
12102 | ||
12103 | nla_put_failure: | |
12104 | genlmsg_cancel(msg, hdr); | |
12105 | nlmsg_free(msg); | |
12106 | ||
12107 | } | |
12108 | ||
12109 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
12110 | struct net_device *netdev, const u8 *bssid, | |
12111 | const u8 *req_ie, size_t req_ie_len, | |
12112 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
12113 | { | |
12114 | struct sk_buff *msg; | |
12115 | void *hdr; | |
12116 | ||
58050fce | 12117 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
12118 | if (!msg) |
12119 | return; | |
12120 | ||
12121 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
12122 | if (!hdr) { | |
12123 | nlmsg_free(msg); | |
12124 | return; | |
12125 | } | |
12126 | ||
9360ffd1 DM |
12127 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12128 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12129 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
12130 | (req_ie && | |
12131 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
12132 | (resp_ie && | |
12133 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
12134 | goto nla_put_failure; | |
b23aa676 | 12135 | |
3b7b72ee | 12136 | genlmsg_end(msg, hdr); |
b23aa676 | 12137 | |
68eb5503 | 12138 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12139 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
12140 | return; |
12141 | ||
12142 | nla_put_failure: | |
12143 | genlmsg_cancel(msg, hdr); | |
12144 | nlmsg_free(msg); | |
12145 | ||
12146 | } | |
12147 | ||
12148 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
12149 | struct net_device *netdev, u16 reason, | |
667503dd | 12150 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
12151 | { |
12152 | struct sk_buff *msg; | |
12153 | void *hdr; | |
12154 | ||
58050fce | 12155 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
12156 | if (!msg) |
12157 | return; | |
12158 | ||
12159 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
12160 | if (!hdr) { | |
12161 | nlmsg_free(msg); | |
12162 | return; | |
12163 | } | |
12164 | ||
9360ffd1 DM |
12165 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12166 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12167 | (from_ap && reason && | |
12168 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
12169 | (from_ap && | |
12170 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
12171 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
12172 | goto nla_put_failure; | |
b23aa676 | 12173 | |
3b7b72ee | 12174 | genlmsg_end(msg, hdr); |
b23aa676 | 12175 | |
68eb5503 | 12176 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12177 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
12178 | return; |
12179 | ||
12180 | nla_put_failure: | |
12181 | genlmsg_cancel(msg, hdr); | |
12182 | nlmsg_free(msg); | |
12183 | ||
12184 | } | |
12185 | ||
04a773ad JB |
12186 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
12187 | struct net_device *netdev, const u8 *bssid, | |
12188 | gfp_t gfp) | |
12189 | { | |
12190 | struct sk_buff *msg; | |
12191 | void *hdr; | |
12192 | ||
fd2120ca | 12193 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
12194 | if (!msg) |
12195 | return; | |
12196 | ||
12197 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
12198 | if (!hdr) { | |
12199 | nlmsg_free(msg); | |
12200 | return; | |
12201 | } | |
12202 | ||
9360ffd1 DM |
12203 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12204 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12205 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
12206 | goto nla_put_failure; | |
04a773ad | 12207 | |
3b7b72ee | 12208 | genlmsg_end(msg, hdr); |
04a773ad | 12209 | |
68eb5503 | 12210 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12211 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
12212 | return; |
12213 | ||
12214 | nla_put_failure: | |
12215 | genlmsg_cancel(msg, hdr); | |
12216 | nlmsg_free(msg); | |
12217 | } | |
12218 | ||
947add36 JB |
12219 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
12220 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 12221 | { |
947add36 | 12222 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 12223 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
12224 | struct sk_buff *msg; |
12225 | void *hdr; | |
12226 | ||
947add36 JB |
12227 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
12228 | return; | |
12229 | ||
12230 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
12231 | ||
c93b5e71 JC |
12232 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
12233 | if (!msg) | |
12234 | return; | |
12235 | ||
12236 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
12237 | if (!hdr) { | |
12238 | nlmsg_free(msg); | |
12239 | return; | |
12240 | } | |
12241 | ||
9360ffd1 | 12242 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
12243 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
12244 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
12245 | (ie_len && ie && |
12246 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
12247 | goto nla_put_failure; | |
c93b5e71 | 12248 | |
3b7b72ee | 12249 | genlmsg_end(msg, hdr); |
c93b5e71 | 12250 | |
68eb5503 | 12251 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12252 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
12253 | return; |
12254 | ||
12255 | nla_put_failure: | |
12256 | genlmsg_cancel(msg, hdr); | |
12257 | nlmsg_free(msg); | |
12258 | } | |
947add36 | 12259 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 12260 | |
a3b8b056 JM |
12261 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
12262 | struct net_device *netdev, const u8 *addr, | |
12263 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 12264 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
12265 | { |
12266 | struct sk_buff *msg; | |
12267 | void *hdr; | |
12268 | ||
e6d6e342 | 12269 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
12270 | if (!msg) |
12271 | return; | |
12272 | ||
12273 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
12274 | if (!hdr) { | |
12275 | nlmsg_free(msg); | |
12276 | return; | |
12277 | } | |
12278 | ||
9360ffd1 DM |
12279 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12280 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12281 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
12282 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
12283 | (key_id != -1 && | |
12284 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
12285 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
12286 | goto nla_put_failure; | |
a3b8b056 | 12287 | |
3b7b72ee | 12288 | genlmsg_end(msg, hdr); |
a3b8b056 | 12289 | |
68eb5503 | 12290 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12291 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
12292 | return; |
12293 | ||
12294 | nla_put_failure: | |
12295 | genlmsg_cancel(msg, hdr); | |
12296 | nlmsg_free(msg); | |
12297 | } | |
12298 | ||
6bad8766 LR |
12299 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
12300 | struct ieee80211_channel *channel_before, | |
12301 | struct ieee80211_channel *channel_after) | |
12302 | { | |
12303 | struct sk_buff *msg; | |
12304 | void *hdr; | |
12305 | struct nlattr *nl_freq; | |
12306 | ||
fd2120ca | 12307 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
12308 | if (!msg) |
12309 | return; | |
12310 | ||
12311 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
12312 | if (!hdr) { | |
12313 | nlmsg_free(msg); | |
12314 | return; | |
12315 | } | |
12316 | ||
12317 | /* | |
12318 | * Since we are applying the beacon hint to a wiphy we know its | |
12319 | * wiphy_idx is valid | |
12320 | */ | |
9360ffd1 DM |
12321 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
12322 | goto nla_put_failure; | |
6bad8766 LR |
12323 | |
12324 | /* Before */ | |
12325 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
12326 | if (!nl_freq) | |
12327 | goto nla_put_failure; | |
cdc89b97 | 12328 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
12329 | goto nla_put_failure; |
12330 | nla_nest_end(msg, nl_freq); | |
12331 | ||
12332 | /* After */ | |
12333 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
12334 | if (!nl_freq) | |
12335 | goto nla_put_failure; | |
cdc89b97 | 12336 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
12337 | goto nla_put_failure; |
12338 | nla_nest_end(msg, nl_freq); | |
12339 | ||
3b7b72ee | 12340 | genlmsg_end(msg, hdr); |
6bad8766 | 12341 | |
463d0183 | 12342 | rcu_read_lock(); |
68eb5503 | 12343 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 12344 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 12345 | rcu_read_unlock(); |
6bad8766 LR |
12346 | |
12347 | return; | |
12348 | ||
12349 | nla_put_failure: | |
12350 | genlmsg_cancel(msg, hdr); | |
12351 | nlmsg_free(msg); | |
12352 | } | |
12353 | ||
9588bbd5 JM |
12354 | static void nl80211_send_remain_on_chan_event( |
12355 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 12356 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 12357 | struct ieee80211_channel *chan, |
9588bbd5 JM |
12358 | unsigned int duration, gfp_t gfp) |
12359 | { | |
12360 | struct sk_buff *msg; | |
12361 | void *hdr; | |
12362 | ||
12363 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12364 | if (!msg) | |
12365 | return; | |
12366 | ||
12367 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
12368 | if (!hdr) { | |
12369 | nlmsg_free(msg); | |
12370 | return; | |
12371 | } | |
12372 | ||
9360ffd1 | 12373 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
12374 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
12375 | wdev->netdev->ifindex)) || | |
00f53350 | 12376 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 12377 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
12378 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
12379 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
12380 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
12381 | goto nla_put_failure; | |
9588bbd5 | 12382 | |
9360ffd1 DM |
12383 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
12384 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
12385 | goto nla_put_failure; | |
9588bbd5 | 12386 | |
3b7b72ee | 12387 | genlmsg_end(msg, hdr); |
9588bbd5 | 12388 | |
68eb5503 | 12389 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12390 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
12391 | return; |
12392 | ||
12393 | nla_put_failure: | |
12394 | genlmsg_cancel(msg, hdr); | |
12395 | nlmsg_free(msg); | |
12396 | } | |
12397 | ||
947add36 JB |
12398 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
12399 | struct ieee80211_channel *chan, | |
12400 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 12401 | { |
947add36 | 12402 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 12403 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12404 | |
12405 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 12406 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 12407 | rdev, wdev, cookie, chan, |
42d97a59 | 12408 | duration, gfp); |
9588bbd5 | 12409 | } |
947add36 | 12410 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 12411 | |
947add36 JB |
12412 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
12413 | struct ieee80211_channel *chan, | |
12414 | gfp_t gfp) | |
9588bbd5 | 12415 | { |
947add36 | 12416 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 12417 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12418 | |
12419 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 12420 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 12421 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 12422 | } |
947add36 | 12423 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 12424 | |
947add36 JB |
12425 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
12426 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 12427 | { |
947add36 | 12428 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 12429 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
12430 | struct sk_buff *msg; |
12431 | ||
947add36 JB |
12432 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
12433 | ||
58050fce | 12434 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
12435 | if (!msg) |
12436 | return; | |
12437 | ||
cf5ead82 | 12438 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
66266b3a | 12439 | rdev, dev, mac_addr, sinfo) < 0) { |
98b62183 JB |
12440 | nlmsg_free(msg); |
12441 | return; | |
12442 | } | |
12443 | ||
68eb5503 | 12444 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12445 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 12446 | } |
947add36 | 12447 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 12448 | |
cf5ead82 JB |
12449 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
12450 | struct station_info *sinfo, gfp_t gfp) | |
ec15e68b | 12451 | { |
947add36 | 12452 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 12453 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b | 12454 | struct sk_buff *msg; |
cf5ead82 JB |
12455 | struct station_info empty_sinfo = {}; |
12456 | ||
12457 | if (!sinfo) | |
12458 | sinfo = &empty_sinfo; | |
ec15e68b | 12459 | |
947add36 JB |
12460 | trace_cfg80211_del_sta(dev, mac_addr); |
12461 | ||
58050fce | 12462 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
12463 | if (!msg) |
12464 | return; | |
12465 | ||
cf5ead82 | 12466 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
57007121 | 12467 | rdev, dev, mac_addr, sinfo) < 0) { |
ec15e68b JM |
12468 | nlmsg_free(msg); |
12469 | return; | |
12470 | } | |
12471 | ||
68eb5503 | 12472 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12473 | NL80211_MCGRP_MLME, gfp); |
ec15e68b | 12474 | } |
cf5ead82 | 12475 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
ec15e68b | 12476 | |
947add36 JB |
12477 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
12478 | enum nl80211_connect_failed_reason reason, | |
12479 | gfp_t gfp) | |
ed44a951 | 12480 | { |
947add36 | 12481 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 12482 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
12483 | struct sk_buff *msg; |
12484 | void *hdr; | |
12485 | ||
12486 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
12487 | if (!msg) | |
12488 | return; | |
12489 | ||
12490 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
12491 | if (!hdr) { | |
12492 | nlmsg_free(msg); | |
12493 | return; | |
12494 | } | |
12495 | ||
12496 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12497 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
12498 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
12499 | goto nla_put_failure; | |
12500 | ||
12501 | genlmsg_end(msg, hdr); | |
12502 | ||
68eb5503 | 12503 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12504 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
12505 | return; |
12506 | ||
12507 | nla_put_failure: | |
12508 | genlmsg_cancel(msg, hdr); | |
12509 | nlmsg_free(msg); | |
12510 | } | |
947add36 | 12511 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 12512 | |
b92ab5d8 JB |
12513 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
12514 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
12515 | { |
12516 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12517 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
12518 | struct sk_buff *msg; |
12519 | void *hdr; | |
15e47304 | 12520 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 12521 | |
15e47304 | 12522 | if (!nlportid) |
28946da7 JB |
12523 | return false; |
12524 | ||
12525 | msg = nlmsg_new(100, gfp); | |
12526 | if (!msg) | |
12527 | return true; | |
12528 | ||
b92ab5d8 | 12529 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
12530 | if (!hdr) { |
12531 | nlmsg_free(msg); | |
12532 | return true; | |
12533 | } | |
12534 | ||
9360ffd1 DM |
12535 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12536 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12537 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
12538 | goto nla_put_failure; | |
28946da7 | 12539 | |
9c90a9f6 | 12540 | genlmsg_end(msg, hdr); |
15e47304 | 12541 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
12542 | return true; |
12543 | ||
12544 | nla_put_failure: | |
12545 | genlmsg_cancel(msg, hdr); | |
12546 | nlmsg_free(msg); | |
12547 | return true; | |
12548 | } | |
12549 | ||
947add36 JB |
12550 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
12551 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 12552 | { |
947add36 JB |
12553 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
12554 | bool ret; | |
12555 | ||
12556 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
12557 | ||
12558 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
12559 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
12560 | trace_cfg80211_return_bool(false); | |
12561 | return false; | |
12562 | } | |
12563 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
12564 | addr, gfp); | |
12565 | trace_cfg80211_return_bool(ret); | |
12566 | return ret; | |
b92ab5d8 | 12567 | } |
947add36 | 12568 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 12569 | |
947add36 JB |
12570 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
12571 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 12572 | { |
947add36 JB |
12573 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
12574 | bool ret; | |
12575 | ||
12576 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
12577 | ||
12578 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
12579 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
12580 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
12581 | trace_cfg80211_return_bool(false); | |
12582 | return false; | |
12583 | } | |
12584 | ret = __nl80211_unexpected_frame(dev, | |
12585 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
12586 | addr, gfp); | |
12587 | trace_cfg80211_return_bool(ret); | |
12588 | return ret; | |
b92ab5d8 | 12589 | } |
947add36 | 12590 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 12591 | |
2e161f78 | 12592 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 12593 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 12594 | int freq, int sig_dbm, |
19504cf5 | 12595 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 12596 | { |
71bbc994 | 12597 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
12598 | struct sk_buff *msg; |
12599 | void *hdr; | |
026331c4 JM |
12600 | |
12601 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12602 | if (!msg) | |
12603 | return -ENOMEM; | |
12604 | ||
2e161f78 | 12605 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
12606 | if (!hdr) { |
12607 | nlmsg_free(msg); | |
12608 | return -ENOMEM; | |
12609 | } | |
12610 | ||
9360ffd1 | 12611 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
12612 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
12613 | netdev->ifindex)) || | |
a838490b | 12614 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
12615 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
12616 | (sig_dbm && | |
12617 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
12618 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
12619 | (flags && | |
12620 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 12621 | goto nla_put_failure; |
026331c4 | 12622 | |
3b7b72ee | 12623 | genlmsg_end(msg, hdr); |
026331c4 | 12624 | |
15e47304 | 12625 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
12626 | |
12627 | nla_put_failure: | |
12628 | genlmsg_cancel(msg, hdr); | |
12629 | nlmsg_free(msg); | |
12630 | return -ENOBUFS; | |
12631 | } | |
12632 | ||
947add36 JB |
12633 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
12634 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 12635 | { |
947add36 | 12636 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 12637 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 12638 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
12639 | struct sk_buff *msg; |
12640 | void *hdr; | |
12641 | ||
947add36 JB |
12642 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
12643 | ||
026331c4 JM |
12644 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
12645 | if (!msg) | |
12646 | return; | |
12647 | ||
2e161f78 | 12648 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
12649 | if (!hdr) { |
12650 | nlmsg_free(msg); | |
12651 | return; | |
12652 | } | |
12653 | ||
9360ffd1 | 12654 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
12655 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
12656 | netdev->ifindex)) || | |
a838490b | 12657 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
12658 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
12659 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
12660 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
12661 | goto nla_put_failure; | |
026331c4 | 12662 | |
3b7b72ee | 12663 | genlmsg_end(msg, hdr); |
026331c4 | 12664 | |
68eb5503 | 12665 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12666 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
12667 | return; |
12668 | ||
12669 | nla_put_failure: | |
12670 | genlmsg_cancel(msg, hdr); | |
12671 | nlmsg_free(msg); | |
12672 | } | |
947add36 | 12673 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 12674 | |
5b97f49d JB |
12675 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
12676 | const char *mac, gfp_t gfp) | |
d6dc1a38 | 12677 | { |
947add36 | 12678 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5b97f49d JB |
12679 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
12680 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12681 | void **cb; | |
947add36 | 12682 | |
d6dc1a38 | 12683 | if (!msg) |
5b97f49d | 12684 | return NULL; |
d6dc1a38 | 12685 | |
5b97f49d JB |
12686 | cb = (void **)msg->cb; |
12687 | ||
12688 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
12689 | if (!cb[0]) { | |
d6dc1a38 | 12690 | nlmsg_free(msg); |
5b97f49d | 12691 | return NULL; |
d6dc1a38 JO |
12692 | } |
12693 | ||
9360ffd1 | 12694 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 12695 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 12696 | goto nla_put_failure; |
d6dc1a38 | 12697 | |
5b97f49d | 12698 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
d6dc1a38 JO |
12699 | goto nla_put_failure; |
12700 | ||
5b97f49d JB |
12701 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
12702 | if (!cb[1]) | |
9360ffd1 | 12703 | goto nla_put_failure; |
d6dc1a38 | 12704 | |
5b97f49d | 12705 | cb[2] = rdev; |
d6dc1a38 | 12706 | |
5b97f49d JB |
12707 | return msg; |
12708 | nla_put_failure: | |
12709 | nlmsg_free(msg); | |
12710 | return NULL; | |
12711 | } | |
12712 | ||
12713 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) | |
12714 | { | |
12715 | void **cb = (void **)msg->cb; | |
12716 | struct cfg80211_registered_device *rdev = cb[2]; | |
12717 | ||
12718 | nla_nest_end(msg, cb[1]); | |
12719 | genlmsg_end(msg, cb[0]); | |
12720 | ||
12721 | memset(msg->cb, 0, sizeof(msg->cb)); | |
d6dc1a38 | 12722 | |
68eb5503 | 12723 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12724 | NL80211_MCGRP_MLME, gfp); |
5b97f49d JB |
12725 | } |
12726 | ||
12727 | void cfg80211_cqm_rssi_notify(struct net_device *dev, | |
12728 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
12729 | gfp_t gfp) | |
12730 | { | |
12731 | struct sk_buff *msg; | |
12732 | ||
12733 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); | |
12734 | ||
98f03342 JB |
12735 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
12736 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) | |
12737 | return; | |
12738 | ||
5b97f49d JB |
12739 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
12740 | if (!msg) | |
12741 | return; | |
12742 | ||
12743 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
12744 | rssi_event)) | |
12745 | goto nla_put_failure; | |
12746 | ||
12747 | cfg80211_send_cqm(msg, gfp); | |
12748 | ||
d6dc1a38 JO |
12749 | return; |
12750 | ||
12751 | nla_put_failure: | |
d6dc1a38 JO |
12752 | nlmsg_free(msg); |
12753 | } | |
947add36 | 12754 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 12755 | |
5b97f49d JB |
12756 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
12757 | const u8 *peer, u32 num_packets, | |
12758 | u32 rate, u32 intvl, gfp_t gfp) | |
12759 | { | |
12760 | struct sk_buff *msg; | |
12761 | ||
12762 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12763 | if (!msg) | |
12764 | return; | |
12765 | ||
12766 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
12767 | goto nla_put_failure; | |
12768 | ||
12769 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
12770 | goto nla_put_failure; | |
12771 | ||
12772 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
12773 | goto nla_put_failure; | |
12774 | ||
12775 | cfg80211_send_cqm(msg, gfp); | |
12776 | return; | |
12777 | ||
12778 | nla_put_failure: | |
12779 | nlmsg_free(msg); | |
12780 | } | |
12781 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); | |
12782 | ||
12783 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, | |
12784 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
12785 | { | |
12786 | struct sk_buff *msg; | |
12787 | ||
12788 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); | |
12789 | ||
12790 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12791 | if (!msg) | |
12792 | return; | |
12793 | ||
12794 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) | |
12795 | goto nla_put_failure; | |
12796 | ||
12797 | cfg80211_send_cqm(msg, gfp); | |
12798 | return; | |
12799 | ||
12800 | nla_put_failure: | |
12801 | nlmsg_free(msg); | |
12802 | } | |
12803 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); | |
12804 | ||
98f03342 JB |
12805 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
12806 | { | |
12807 | struct sk_buff *msg; | |
12808 | ||
12809 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); | |
12810 | if (!msg) | |
12811 | return; | |
12812 | ||
12813 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) | |
12814 | goto nla_put_failure; | |
12815 | ||
12816 | cfg80211_send_cqm(msg, gfp); | |
12817 | return; | |
12818 | ||
12819 | nla_put_failure: | |
12820 | nlmsg_free(msg); | |
12821 | } | |
12822 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); | |
12823 | ||
947add36 JB |
12824 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
12825 | struct net_device *netdev, const u8 *bssid, | |
12826 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
12827 | { |
12828 | struct sk_buff *msg; | |
12829 | struct nlattr *rekey_attr; | |
12830 | void *hdr; | |
12831 | ||
58050fce | 12832 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
12833 | if (!msg) |
12834 | return; | |
12835 | ||
12836 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
12837 | if (!hdr) { | |
12838 | nlmsg_free(msg); | |
12839 | return; | |
12840 | } | |
12841 | ||
9360ffd1 DM |
12842 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12843 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12844 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
12845 | goto nla_put_failure; | |
e5497d76 JB |
12846 | |
12847 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
12848 | if (!rekey_attr) | |
12849 | goto nla_put_failure; | |
12850 | ||
9360ffd1 DM |
12851 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
12852 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
12853 | goto nla_put_failure; | |
e5497d76 JB |
12854 | |
12855 | nla_nest_end(msg, rekey_attr); | |
12856 | ||
3b7b72ee | 12857 | genlmsg_end(msg, hdr); |
e5497d76 | 12858 | |
68eb5503 | 12859 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12860 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
12861 | return; |
12862 | ||
12863 | nla_put_failure: | |
12864 | genlmsg_cancel(msg, hdr); | |
12865 | nlmsg_free(msg); | |
12866 | } | |
12867 | ||
947add36 JB |
12868 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
12869 | const u8 *replay_ctr, gfp_t gfp) | |
12870 | { | |
12871 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12872 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12873 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12874 | |
12875 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
12876 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
12877 | } | |
12878 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
12879 | ||
12880 | static void | |
12881 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
12882 | struct net_device *netdev, int index, | |
12883 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
12884 | { |
12885 | struct sk_buff *msg; | |
12886 | struct nlattr *attr; | |
12887 | void *hdr; | |
12888 | ||
58050fce | 12889 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
12890 | if (!msg) |
12891 | return; | |
12892 | ||
12893 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
12894 | if (!hdr) { | |
12895 | nlmsg_free(msg); | |
12896 | return; | |
12897 | } | |
12898 | ||
9360ffd1 DM |
12899 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12900 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
12901 | goto nla_put_failure; | |
c9df56b4 JM |
12902 | |
12903 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
12904 | if (!attr) | |
12905 | goto nla_put_failure; | |
12906 | ||
9360ffd1 DM |
12907 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
12908 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
12909 | (preauth && | |
12910 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
12911 | goto nla_put_failure; | |
c9df56b4 JM |
12912 | |
12913 | nla_nest_end(msg, attr); | |
12914 | ||
3b7b72ee | 12915 | genlmsg_end(msg, hdr); |
c9df56b4 | 12916 | |
68eb5503 | 12917 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12918 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
12919 | return; |
12920 | ||
12921 | nla_put_failure: | |
12922 | genlmsg_cancel(msg, hdr); | |
12923 | nlmsg_free(msg); | |
12924 | } | |
12925 | ||
947add36 JB |
12926 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
12927 | const u8 *bssid, bool preauth, gfp_t gfp) | |
12928 | { | |
12929 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12930 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12931 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12932 | |
12933 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
12934 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
12935 | } | |
12936 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
12937 | ||
12938 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
12939 | struct net_device *netdev, | |
12940 | struct cfg80211_chan_def *chandef, | |
f8d7552e LC |
12941 | gfp_t gfp, |
12942 | enum nl80211_commands notif, | |
12943 | u8 count) | |
5314526b TP |
12944 | { |
12945 | struct sk_buff *msg; | |
12946 | void *hdr; | |
12947 | ||
58050fce | 12948 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
12949 | if (!msg) |
12950 | return; | |
12951 | ||
f8d7552e | 12952 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
5314526b TP |
12953 | if (!hdr) { |
12954 | nlmsg_free(msg); | |
12955 | return; | |
12956 | } | |
12957 | ||
683b6d3b JB |
12958 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
12959 | goto nla_put_failure; | |
12960 | ||
12961 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 12962 | goto nla_put_failure; |
5314526b | 12963 | |
f8d7552e LC |
12964 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
12965 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) | |
12966 | goto nla_put_failure; | |
12967 | ||
5314526b TP |
12968 | genlmsg_end(msg, hdr); |
12969 | ||
68eb5503 | 12970 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12971 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
12972 | return; |
12973 | ||
12974 | nla_put_failure: | |
12975 | genlmsg_cancel(msg, hdr); | |
12976 | nlmsg_free(msg); | |
12977 | } | |
12978 | ||
947add36 JB |
12979 | void cfg80211_ch_switch_notify(struct net_device *dev, |
12980 | struct cfg80211_chan_def *chandef) | |
84f10708 | 12981 | { |
947add36 JB |
12982 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
12983 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12984 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 12985 | |
e487eaeb | 12986 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 12987 | |
e487eaeb | 12988 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 | 12989 | |
9e0e2961 | 12990 | wdev->chandef = *chandef; |
96f55f12 | 12991 | wdev->preset_chandef = *chandef; |
f8d7552e LC |
12992 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
12993 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); | |
947add36 JB |
12994 | } |
12995 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
12996 | ||
f8d7552e LC |
12997 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
12998 | struct cfg80211_chan_def *chandef, | |
12999 | u8 count) | |
13000 | { | |
13001 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13002 | struct wiphy *wiphy = wdev->wiphy; | |
13003 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
13004 | ||
13005 | trace_cfg80211_ch_switch_started_notify(dev, chandef); | |
13006 | ||
13007 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | |
13008 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); | |
13009 | } | |
13010 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | |
13011 | ||
04f39047 SW |
13012 | void |
13013 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 13014 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
13015 | enum nl80211_radar_event event, |
13016 | struct net_device *netdev, gfp_t gfp) | |
13017 | { | |
13018 | struct sk_buff *msg; | |
13019 | void *hdr; | |
13020 | ||
13021 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
13022 | if (!msg) | |
13023 | return; | |
13024 | ||
13025 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
13026 | if (!hdr) { | |
13027 | nlmsg_free(msg); | |
13028 | return; | |
13029 | } | |
13030 | ||
13031 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
13032 | goto nla_put_failure; | |
13033 | ||
13034 | /* NOP and radar events don't need a netdev parameter */ | |
13035 | if (netdev) { | |
13036 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
13037 | ||
13038 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13039 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
13040 | goto nla_put_failure; | |
13041 | } | |
13042 | ||
13043 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
13044 | goto nla_put_failure; | |
13045 | ||
13046 | if (nl80211_send_chandef(msg, chandef)) | |
13047 | goto nla_put_failure; | |
13048 | ||
9c90a9f6 | 13049 | genlmsg_end(msg, hdr); |
04f39047 | 13050 | |
68eb5503 | 13051 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13052 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
13053 | return; |
13054 | ||
13055 | nla_put_failure: | |
13056 | genlmsg_cancel(msg, hdr); | |
13057 | nlmsg_free(msg); | |
13058 | } | |
13059 | ||
7f6cf311 JB |
13060 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
13061 | u64 cookie, bool acked, gfp_t gfp) | |
13062 | { | |
13063 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 13064 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
13065 | struct sk_buff *msg; |
13066 | void *hdr; | |
7f6cf311 | 13067 | |
4ee3e063 BL |
13068 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
13069 | ||
58050fce | 13070 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 13071 | |
7f6cf311 JB |
13072 | if (!msg) |
13073 | return; | |
13074 | ||
13075 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
13076 | if (!hdr) { | |
13077 | nlmsg_free(msg); | |
13078 | return; | |
13079 | } | |
13080 | ||
9360ffd1 DM |
13081 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13082 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
13083 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
13084 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
13085 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
13086 | goto nla_put_failure; | |
7f6cf311 | 13087 | |
9c90a9f6 | 13088 | genlmsg_end(msg, hdr); |
7f6cf311 | 13089 | |
68eb5503 | 13090 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13091 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
13092 | return; |
13093 | ||
13094 | nla_put_failure: | |
13095 | genlmsg_cancel(msg, hdr); | |
13096 | nlmsg_free(msg); | |
13097 | } | |
13098 | EXPORT_SYMBOL(cfg80211_probe_status); | |
13099 | ||
5e760230 JB |
13100 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
13101 | const u8 *frame, size_t len, | |
37c73b5f | 13102 | int freq, int sig_dbm) |
5e760230 | 13103 | { |
f26cbf40 | 13104 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
13105 | struct sk_buff *msg; |
13106 | void *hdr; | |
37c73b5f | 13107 | struct cfg80211_beacon_registration *reg; |
5e760230 | 13108 | |
4ee3e063 BL |
13109 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
13110 | ||
37c73b5f BG |
13111 | spin_lock_bh(&rdev->beacon_registrations_lock); |
13112 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
13113 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
13114 | if (!msg) { | |
13115 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
13116 | return; | |
13117 | } | |
5e760230 | 13118 | |
37c73b5f BG |
13119 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
13120 | if (!hdr) | |
13121 | goto nla_put_failure; | |
5e760230 | 13122 | |
37c73b5f BG |
13123 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13124 | (freq && | |
13125 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
13126 | (sig_dbm && | |
13127 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
13128 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
13129 | goto nla_put_failure; | |
5e760230 | 13130 | |
37c73b5f | 13131 | genlmsg_end(msg, hdr); |
5e760230 | 13132 | |
37c73b5f BG |
13133 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
13134 | } | |
13135 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
13136 | return; |
13137 | ||
13138 | nla_put_failure: | |
37c73b5f BG |
13139 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
13140 | if (hdr) | |
13141 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
13142 | nlmsg_free(msg); |
13143 | } | |
13144 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
13145 | ||
cd8f7cb4 | 13146 | #ifdef CONFIG_PM |
8cd4d456 LC |
13147 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
13148 | struct cfg80211_wowlan_wakeup *wakeup) | |
13149 | { | |
13150 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | |
13151 | struct nlattr *nl_results, *nl_match, *nl_freqs; | |
13152 | int i, j; | |
13153 | ||
13154 | nl_results = nla_nest_start( | |
13155 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | |
13156 | if (!nl_results) | |
13157 | return -EMSGSIZE; | |
13158 | ||
13159 | for (i = 0; i < nd->n_matches; i++) { | |
13160 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | |
13161 | ||
13162 | nl_match = nla_nest_start(msg, i); | |
13163 | if (!nl_match) | |
13164 | break; | |
13165 | ||
13166 | /* The SSID attribute is optional in nl80211, but for | |
13167 | * simplicity reasons it's always present in the | |
13168 | * cfg80211 structure. If a driver can't pass the | |
13169 | * SSID, that needs to be changed. A zero length SSID | |
13170 | * is still a valid SSID (wildcard), so it cannot be | |
13171 | * used for this purpose. | |
13172 | */ | |
13173 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | |
13174 | match->ssid.ssid)) { | |
13175 | nla_nest_cancel(msg, nl_match); | |
13176 | goto out; | |
13177 | } | |
13178 | ||
13179 | if (match->n_channels) { | |
13180 | nl_freqs = nla_nest_start( | |
13181 | msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
13182 | if (!nl_freqs) { | |
13183 | nla_nest_cancel(msg, nl_match); | |
13184 | goto out; | |
13185 | } | |
13186 | ||
13187 | for (j = 0; j < match->n_channels; j++) { | |
5528fae8 | 13188 | if (nla_put_u32(msg, j, match->channels[j])) { |
8cd4d456 LC |
13189 | nla_nest_cancel(msg, nl_freqs); |
13190 | nla_nest_cancel(msg, nl_match); | |
13191 | goto out; | |
13192 | } | |
13193 | } | |
13194 | ||
13195 | nla_nest_end(msg, nl_freqs); | |
13196 | } | |
13197 | ||
13198 | nla_nest_end(msg, nl_match); | |
13199 | } | |
13200 | ||
13201 | out: | |
13202 | nla_nest_end(msg, nl_results); | |
13203 | return 0; | |
13204 | } | |
13205 | ||
cd8f7cb4 JB |
13206 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
13207 | struct cfg80211_wowlan_wakeup *wakeup, | |
13208 | gfp_t gfp) | |
13209 | { | |
f26cbf40 | 13210 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
13211 | struct sk_buff *msg; |
13212 | void *hdr; | |
9c90a9f6 | 13213 | int size = 200; |
cd8f7cb4 JB |
13214 | |
13215 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
13216 | ||
13217 | if (wakeup) | |
13218 | size += wakeup->packet_present_len; | |
13219 | ||
13220 | msg = nlmsg_new(size, gfp); | |
13221 | if (!msg) | |
13222 | return; | |
13223 | ||
13224 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
13225 | if (!hdr) | |
13226 | goto free_msg; | |
13227 | ||
13228 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
13229 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
13230 | goto free_msg; | |
13231 | ||
13232 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
13233 | wdev->netdev->ifindex)) | |
13234 | goto free_msg; | |
13235 | ||
13236 | if (wakeup) { | |
13237 | struct nlattr *reasons; | |
13238 | ||
13239 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
13240 | if (!reasons) |
13241 | goto free_msg; | |
cd8f7cb4 JB |
13242 | |
13243 | if (wakeup->disconnect && | |
13244 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
13245 | goto free_msg; | |
13246 | if (wakeup->magic_pkt && | |
13247 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
13248 | goto free_msg; | |
13249 | if (wakeup->gtk_rekey_failure && | |
13250 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
13251 | goto free_msg; | |
13252 | if (wakeup->eap_identity_req && | |
13253 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
13254 | goto free_msg; | |
13255 | if (wakeup->four_way_handshake && | |
13256 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
13257 | goto free_msg; | |
13258 | if (wakeup->rfkill_release && | |
13259 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
13260 | goto free_msg; | |
13261 | ||
13262 | if (wakeup->pattern_idx >= 0 && | |
13263 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
13264 | wakeup->pattern_idx)) | |
13265 | goto free_msg; | |
13266 | ||
ae917c9f JB |
13267 | if (wakeup->tcp_match && |
13268 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
13269 | goto free_msg; | |
2a0e047e | 13270 | |
ae917c9f JB |
13271 | if (wakeup->tcp_connlost && |
13272 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
13273 | goto free_msg; | |
2a0e047e | 13274 | |
ae917c9f JB |
13275 | if (wakeup->tcp_nomoretokens && |
13276 | nla_put_flag(msg, | |
13277 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
13278 | goto free_msg; | |
2a0e047e | 13279 | |
cd8f7cb4 JB |
13280 | if (wakeup->packet) { |
13281 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
13282 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
13283 | ||
13284 | if (!wakeup->packet_80211) { | |
13285 | pkt_attr = | |
13286 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
13287 | len_attr = | |
13288 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
13289 | } | |
13290 | ||
13291 | if (wakeup->packet_len && | |
13292 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
13293 | goto free_msg; | |
13294 | ||
13295 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
13296 | wakeup->packet)) | |
13297 | goto free_msg; | |
13298 | } | |
13299 | ||
8cd4d456 LC |
13300 | if (wakeup->net_detect && |
13301 | cfg80211_net_detect_results(msg, wakeup)) | |
13302 | goto free_msg; | |
13303 | ||
cd8f7cb4 JB |
13304 | nla_nest_end(msg, reasons); |
13305 | } | |
13306 | ||
9c90a9f6 | 13307 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 13308 | |
68eb5503 | 13309 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13310 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
13311 | return; |
13312 | ||
13313 | free_msg: | |
13314 | nlmsg_free(msg); | |
13315 | } | |
13316 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
13317 | #endif | |
13318 | ||
3475b094 JM |
13319 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
13320 | enum nl80211_tdls_operation oper, | |
13321 | u16 reason_code, gfp_t gfp) | |
13322 | { | |
13323 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 13324 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
13325 | struct sk_buff *msg; |
13326 | void *hdr; | |
3475b094 JM |
13327 | |
13328 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
13329 | reason_code); | |
13330 | ||
13331 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
13332 | if (!msg) | |
13333 | return; | |
13334 | ||
13335 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
13336 | if (!hdr) { | |
13337 | nlmsg_free(msg); | |
13338 | return; | |
13339 | } | |
13340 | ||
13341 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
13342 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
13343 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
13344 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
13345 | (reason_code > 0 && | |
13346 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
13347 | goto nla_put_failure; | |
13348 | ||
9c90a9f6 | 13349 | genlmsg_end(msg, hdr); |
3475b094 | 13350 | |
68eb5503 | 13351 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13352 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
13353 | return; |
13354 | ||
13355 | nla_put_failure: | |
13356 | genlmsg_cancel(msg, hdr); | |
13357 | nlmsg_free(msg); | |
13358 | } | |
13359 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
13360 | ||
026331c4 JM |
13361 | static int nl80211_netlink_notify(struct notifier_block * nb, |
13362 | unsigned long state, | |
13363 | void *_notify) | |
13364 | { | |
13365 | struct netlink_notify *notify = _notify; | |
13366 | struct cfg80211_registered_device *rdev; | |
13367 | struct wireless_dev *wdev; | |
37c73b5f | 13368 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
13369 | |
13370 | if (state != NETLINK_URELEASE) | |
13371 | return NOTIFY_DONE; | |
13372 | ||
13373 | rcu_read_lock(); | |
13374 | ||
5e760230 | 13375 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
78f22b6a | 13376 | bool schedule_destroy_work = false; |
93a1e86c JR |
13377 | bool schedule_scan_stop = false; |
13378 | struct cfg80211_sched_scan_request *sched_scan_req = | |
13379 | rcu_dereference(rdev->sched_scan_req); | |
13380 | ||
13381 | if (sched_scan_req && notify->portid && | |
13382 | sched_scan_req->owner_nlportid == notify->portid) | |
13383 | schedule_scan_stop = true; | |
78f22b6a JB |
13384 | |
13385 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { | |
15e47304 | 13386 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 13387 | |
78f22b6a JB |
13388 | if (wdev->owner_nlportid == notify->portid) |
13389 | schedule_destroy_work = true; | |
13390 | } | |
13391 | ||
37c73b5f BG |
13392 | spin_lock_bh(&rdev->beacon_registrations_lock); |
13393 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
13394 | list) { | |
13395 | if (reg->nlportid == notify->portid) { | |
13396 | list_del(®->list); | |
13397 | kfree(reg); | |
13398 | break; | |
13399 | } | |
13400 | } | |
13401 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
78f22b6a JB |
13402 | |
13403 | if (schedule_destroy_work) { | |
13404 | struct cfg80211_iface_destroy *destroy; | |
13405 | ||
13406 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | |
13407 | if (destroy) { | |
13408 | destroy->nlportid = notify->portid; | |
13409 | spin_lock(&rdev->destroy_list_lock); | |
13410 | list_add(&destroy->list, &rdev->destroy_list); | |
13411 | spin_unlock(&rdev->destroy_list_lock); | |
13412 | schedule_work(&rdev->destroy_work); | |
13413 | } | |
93a1e86c JR |
13414 | } else if (schedule_scan_stop) { |
13415 | sched_scan_req->owner_nlportid = 0; | |
13416 | ||
13417 | if (rdev->ops->sched_scan_stop && | |
13418 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
13419 | schedule_work(&rdev->sched_scan_stop_wk); | |
78f22b6a | 13420 | } |
5e760230 | 13421 | } |
026331c4 JM |
13422 | |
13423 | rcu_read_unlock(); | |
13424 | ||
05050753 I |
13425 | /* |
13426 | * It is possible that the user space process that is controlling the | |
13427 | * indoor setting disappeared, so notify the regulatory core. | |
13428 | */ | |
13429 | regulatory_netlink_notify(notify->portid); | |
6784c7db | 13430 | return NOTIFY_OK; |
026331c4 JM |
13431 | } |
13432 | ||
13433 | static struct notifier_block nl80211_netlink_notifier = { | |
13434 | .notifier_call = nl80211_netlink_notify, | |
13435 | }; | |
13436 | ||
355199e0 JM |
13437 | void cfg80211_ft_event(struct net_device *netdev, |
13438 | struct cfg80211_ft_event_params *ft_event) | |
13439 | { | |
13440 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 13441 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
13442 | struct sk_buff *msg; |
13443 | void *hdr; | |
355199e0 JM |
13444 | |
13445 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
13446 | ||
13447 | if (!ft_event->target_ap) | |
13448 | return; | |
13449 | ||
13450 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
13451 | if (!msg) | |
13452 | return; | |
13453 | ||
13454 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
13455 | if (!hdr) |
13456 | goto out; | |
355199e0 | 13457 | |
ae917c9f JB |
13458 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13459 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13460 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
13461 | goto out; | |
355199e0 | 13462 | |
ae917c9f JB |
13463 | if (ft_event->ies && |
13464 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
13465 | goto out; | |
13466 | if (ft_event->ric_ies && | |
13467 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
13468 | ft_event->ric_ies)) | |
13469 | goto out; | |
355199e0 | 13470 | |
9c90a9f6 | 13471 | genlmsg_end(msg, hdr); |
355199e0 | 13472 | |
68eb5503 | 13473 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13474 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
13475 | return; |
13476 | out: | |
13477 | nlmsg_free(msg); | |
355199e0 JM |
13478 | } |
13479 | EXPORT_SYMBOL(cfg80211_ft_event); | |
13480 | ||
5de17984 AS |
13481 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
13482 | { | |
13483 | struct cfg80211_registered_device *rdev; | |
13484 | struct sk_buff *msg; | |
13485 | void *hdr; | |
13486 | u32 nlportid; | |
13487 | ||
f26cbf40 | 13488 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
13489 | if (!rdev->crit_proto_nlportid) |
13490 | return; | |
13491 | ||
13492 | nlportid = rdev->crit_proto_nlportid; | |
13493 | rdev->crit_proto_nlportid = 0; | |
13494 | ||
13495 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
13496 | if (!msg) | |
13497 | return; | |
13498 | ||
13499 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
13500 | if (!hdr) | |
13501 | goto nla_put_failure; | |
13502 | ||
13503 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
13504 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
13505 | goto nla_put_failure; | |
13506 | ||
13507 | genlmsg_end(msg, hdr); | |
13508 | ||
13509 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
13510 | return; | |
13511 | ||
13512 | nla_put_failure: | |
13513 | if (hdr) | |
13514 | genlmsg_cancel(msg, hdr); | |
13515 | nlmsg_free(msg); | |
13516 | ||
13517 | } | |
13518 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
13519 | ||
348baf0e JB |
13520 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
13521 | { | |
13522 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 13523 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
13524 | struct sk_buff *msg; |
13525 | void *hdr; | |
13526 | ||
13527 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
13528 | if (!msg) | |
13529 | return; | |
13530 | ||
13531 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
13532 | if (!hdr) | |
13533 | goto out; | |
13534 | ||
13535 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
13536 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
13537 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
13538 | goto out; | |
13539 | ||
13540 | genlmsg_end(msg, hdr); | |
13541 | ||
13542 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
13543 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
13544 | return; | |
13545 | out: | |
13546 | nlmsg_free(msg); | |
13547 | } | |
13548 | ||
55682965 JB |
13549 | /* initialisation/exit functions */ |
13550 | ||
13551 | int nl80211_init(void) | |
13552 | { | |
0d63cbb5 | 13553 | int err; |
55682965 | 13554 | |
2a94fe48 JB |
13555 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
13556 | nl80211_mcgrps); | |
55682965 JB |
13557 | if (err) |
13558 | return err; | |
13559 | ||
026331c4 JM |
13560 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
13561 | if (err) | |
13562 | goto err_out; | |
13563 | ||
55682965 JB |
13564 | return 0; |
13565 | err_out: | |
13566 | genl_unregister_family(&nl80211_fam); | |
13567 | return err; | |
13568 | } | |
13569 | ||
13570 | void nl80211_exit(void) | |
13571 | { | |
026331c4 | 13572 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
13573 | genl_unregister_family(&nl80211_fam); |
13574 | } |