]>
Commit | Line | Data |
---|---|---|
55682965 JB |
1 | /* |
2 | * This is the new netlink-based wireless configuration interface. | |
3 | * | |
026331c4 | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
2740f0cf | 5 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
55682965 JB |
6 | */ |
7 | ||
8 | #include <linux/if.h> | |
9 | #include <linux/module.h> | |
10 | #include <linux/err.h> | |
5a0e3ad6 | 11 | #include <linux/slab.h> |
55682965 JB |
12 | #include <linux/list.h> |
13 | #include <linux/if_ether.h> | |
14 | #include <linux/ieee80211.h> | |
15 | #include <linux/nl80211.h> | |
16 | #include <linux/rtnetlink.h> | |
17 | #include <linux/netlink.h> | |
2a519311 | 18 | #include <linux/etherdevice.h> |
463d0183 | 19 | #include <net/net_namespace.h> |
55682965 JB |
20 | #include <net/genetlink.h> |
21 | #include <net/cfg80211.h> | |
463d0183 | 22 | #include <net/sock.h> |
2a0e047e | 23 | #include <net/inet_connection_sock.h> |
55682965 JB |
24 | #include "core.h" |
25 | #include "nl80211.h" | |
b2e1b302 | 26 | #include "reg.h" |
e35e4d28 | 27 | #include "rdev-ops.h" |
55682965 | 28 | |
5fb628e9 JM |
29 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
30 | struct genl_info *info, | |
31 | struct cfg80211_crypto_settings *settings, | |
32 | int cipher_limit); | |
33 | ||
f84f771d | 34 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 | 35 | struct genl_info *info); |
f84f771d | 36 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
37 | struct genl_info *info); |
38 | ||
55682965 JB |
39 | /* the netlink family */ |
40 | static struct genl_family nl80211_fam = { | |
fb4e1568 MH |
41 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
42 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ | |
43 | .hdrsize = 0, /* no private header */ | |
44 | .version = 1, /* no particular meaning now */ | |
55682965 | 45 | .maxattr = NL80211_ATTR_MAX, |
463d0183 | 46 | .netnsok = true, |
4c476991 JB |
47 | .pre_doit = nl80211_pre_doit, |
48 | .post_doit = nl80211_post_doit, | |
55682965 JB |
49 | }; |
50 | ||
2a94fe48 JB |
51 | /* multicast groups */ |
52 | enum nl80211_multicast_groups { | |
53 | NL80211_MCGRP_CONFIG, | |
54 | NL80211_MCGRP_SCAN, | |
55 | NL80211_MCGRP_REGULATORY, | |
56 | NL80211_MCGRP_MLME, | |
567ffc35 | 57 | NL80211_MCGRP_VENDOR, |
2a94fe48 JB |
58 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
59 | }; | |
60 | ||
61 | static const struct genl_multicast_group nl80211_mcgrps[] = { | |
62 | [NL80211_MCGRP_CONFIG] = { .name = "config", }, | |
63 | [NL80211_MCGRP_SCAN] = { .name = "scan", }, | |
64 | [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", }, | |
65 | [NL80211_MCGRP_MLME] = { .name = "mlme", }, | |
567ffc35 | 66 | [NL80211_MCGRP_VENDOR] = { .name = "vendor", }, |
2a94fe48 JB |
67 | #ifdef CONFIG_NL80211_TESTMODE |
68 | [NL80211_MCGRP_TESTMODE] = { .name = "testmode", } | |
69 | #endif | |
70 | }; | |
71 | ||
89a54e48 JB |
72 | /* returns ERR_PTR values */ |
73 | static struct wireless_dev * | |
74 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 75 | { |
89a54e48 JB |
76 | struct cfg80211_registered_device *rdev; |
77 | struct wireless_dev *result = NULL; | |
78 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
79 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
80 | u64 wdev_id; | |
81 | int wiphy_idx = -1; | |
82 | int ifidx = -1; | |
55682965 | 83 | |
5fe231e8 | 84 | ASSERT_RTNL(); |
55682965 | 85 | |
89a54e48 JB |
86 | if (!have_ifidx && !have_wdev_id) |
87 | return ERR_PTR(-EINVAL); | |
55682965 | 88 | |
89a54e48 JB |
89 | if (have_ifidx) |
90 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
91 | if (have_wdev_id) { | |
92 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
93 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
94 | } |
95 | ||
89a54e48 JB |
96 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
97 | struct wireless_dev *wdev; | |
98 | ||
99 | if (wiphy_net(&rdev->wiphy) != netns) | |
100 | continue; | |
101 | ||
102 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
103 | continue; | |
104 | ||
89a54e48 JB |
105 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
106 | if (have_ifidx && wdev->netdev && | |
107 | wdev->netdev->ifindex == ifidx) { | |
108 | result = wdev; | |
109 | break; | |
110 | } | |
111 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
112 | result = wdev; | |
113 | break; | |
114 | } | |
115 | } | |
89a54e48 JB |
116 | |
117 | if (result) | |
118 | break; | |
119 | } | |
120 | ||
121 | if (result) | |
122 | return result; | |
123 | return ERR_PTR(-ENODEV); | |
55682965 JB |
124 | } |
125 | ||
a9455408 | 126 | static struct cfg80211_registered_device * |
878d9ec7 | 127 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 128 | { |
7fee4778 JB |
129 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
130 | struct net_device *netdev; | |
a9455408 | 131 | |
5fe231e8 | 132 | ASSERT_RTNL(); |
a9455408 | 133 | |
878d9ec7 | 134 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
135 | !attrs[NL80211_ATTR_IFINDEX] && |
136 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
137 | return ERR_PTR(-EINVAL); |
138 | ||
878d9ec7 | 139 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 140 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 141 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 142 | |
89a54e48 JB |
143 | if (attrs[NL80211_ATTR_WDEV]) { |
144 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
145 | struct wireless_dev *wdev; | |
146 | bool found = false; | |
147 | ||
148 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
149 | if (tmp) { | |
150 | /* make sure wdev exists */ | |
89a54e48 JB |
151 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
152 | if (wdev->identifier != (u32)wdev_id) | |
153 | continue; | |
154 | found = true; | |
155 | break; | |
156 | } | |
89a54e48 JB |
157 | |
158 | if (!found) | |
159 | tmp = NULL; | |
160 | ||
161 | if (rdev && tmp != rdev) | |
162 | return ERR_PTR(-EINVAL); | |
163 | rdev = tmp; | |
164 | } | |
165 | } | |
166 | ||
878d9ec7 JB |
167 | if (attrs[NL80211_ATTR_IFINDEX]) { |
168 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
7f2b8562 | 169 | netdev = __dev_get_by_index(netns, ifindex); |
7fee4778 JB |
170 | if (netdev) { |
171 | if (netdev->ieee80211_ptr) | |
f26cbf40 ZG |
172 | tmp = wiphy_to_rdev( |
173 | netdev->ieee80211_ptr->wiphy); | |
7fee4778 JB |
174 | else |
175 | tmp = NULL; | |
176 | ||
7fee4778 JB |
177 | /* not wireless device -- return error */ |
178 | if (!tmp) | |
179 | return ERR_PTR(-EINVAL); | |
180 | ||
181 | /* mismatch -- return error */ | |
182 | if (rdev && tmp != rdev) | |
183 | return ERR_PTR(-EINVAL); | |
184 | ||
185 | rdev = tmp; | |
a9455408 | 186 | } |
a9455408 | 187 | } |
a9455408 | 188 | |
4f7eff10 JB |
189 | if (!rdev) |
190 | return ERR_PTR(-ENODEV); | |
a9455408 | 191 | |
4f7eff10 JB |
192 | if (netns != wiphy_net(&rdev->wiphy)) |
193 | return ERR_PTR(-ENODEV); | |
194 | ||
195 | return rdev; | |
a9455408 JB |
196 | } |
197 | ||
198 | /* | |
199 | * This function returns a pointer to the driver | |
200 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
201 | * |
202 | * The result of this can be a PTR_ERR and hence must | |
203 | * be checked with IS_ERR() for errors. | |
204 | */ | |
205 | static struct cfg80211_registered_device * | |
4f7eff10 | 206 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 207 | { |
5fe231e8 | 208 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
209 | } |
210 | ||
55682965 | 211 | /* policy for the attributes */ |
b54452b0 | 212 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
55682965 JB |
213 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
214 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 215 | .len = 20-1 }, |
31888487 | 216 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 217 | |
72bdcf34 | 218 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 219 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
220 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
221 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
222 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
223 | ||
b9a5f8ca JM |
224 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
225 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
226 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
227 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 228 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
55682965 JB |
229 | |
230 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
231 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
232 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 233 | |
e007b857 EP |
234 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
235 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 236 | |
b9454e83 | 237 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
238 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
239 | .len = WLAN_MAX_KEY_LEN }, | |
240 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
241 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
242 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 243 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 244 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
245 | |
246 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
247 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
248 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
249 | .len = IEEE80211_MAX_DATA_LEN }, | |
250 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
251 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
252 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
253 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
254 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
255 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
256 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 257 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 258 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 259 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 260 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 261 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 262 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 263 | |
b2e1b302 LR |
264 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
265 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
266 | ||
9f1ba906 JM |
267 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
268 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
269 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
270 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
271 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 272 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 273 | |
24bdd9f4 | 274 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 275 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 276 | |
6c739419 | 277 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
278 | |
279 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
280 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
281 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
282 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
283 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
284 | |
285 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
286 | .len = IEEE80211_MAX_SSID_LEN }, | |
287 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
288 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 289 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 290 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 291 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
292 | [NL80211_ATTR_STA_FLAGS2] = { |
293 | .len = sizeof(struct nl80211_sta_flag_update), | |
294 | }, | |
3f77316c | 295 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
296 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
297 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
298 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
299 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
300 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 301 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 302 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
303 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
304 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
305 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
306 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 307 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
308 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
309 | .len = IEEE80211_MAX_DATA_LEN }, | |
310 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 311 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 312 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 313 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 314 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
315 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
316 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 317 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
318 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
319 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 320 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 321 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 322 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 323 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 324 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 325 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 326 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 327 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 328 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
329 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
330 | .len = IEEE80211_MAX_DATA_LEN }, | |
331 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
332 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 333 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 334 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 335 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
336 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
337 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
338 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
339 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
340 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
31fa97c5 | 341 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
e247bd90 | 342 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
343 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
344 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 345 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
346 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
347 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
348 | .len = NL80211_HT_CAPABILITY_LEN | |
349 | }, | |
1d9d9213 | 350 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 351 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 352 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 353 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 354 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
e39e5b5e | 355 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
f461be3e | 356 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
ed473771 | 357 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
53cabad7 JB |
358 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
359 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | |
77765eaf VT |
360 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
361 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
362 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
363 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 364 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
365 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
366 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
367 | .len = NL80211_VHT_CAPABILITY_LEN, | |
368 | }, | |
355199e0 JM |
369 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
370 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
371 | .len = IEEE80211_MAX_DATA_LEN }, | |
5e4b6f56 | 372 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
16ef1fe2 SW |
373 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
374 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | |
375 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | |
9a774c78 AO |
376 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
377 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, | |
c01fc9ad SD |
378 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
379 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, | |
5336fa88 | 380 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
60f4a7b1 | 381 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
ad7e718c JB |
382 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
383 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, | |
384 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, | |
fa9ffc74 KP |
385 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
386 | .len = IEEE80211_QOS_MAP_LEN_MAX }, | |
1df4a510 JM |
387 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
388 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, | |
df942e7b | 389 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
78f22b6a | 390 | [NL80211_ATTR_IFACE_SOCKET_OWNER] = { .type = NLA_FLAG }, |
34d22ce2 | 391 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
55682965 JB |
392 | }; |
393 | ||
e31b8213 | 394 | /* policy for the key attributes */ |
b54452b0 | 395 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 396 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
397 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
398 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 399 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
400 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
401 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 402 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
403 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
404 | }; | |
405 | ||
406 | /* policy for the key default flags */ | |
407 | static const struct nla_policy | |
408 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
409 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
410 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
411 | }; |
412 | ||
ff1b6e69 JB |
413 | /* policy for WoWLAN attributes */ |
414 | static const struct nla_policy | |
415 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
416 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
417 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
418 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
419 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
420 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
421 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
422 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
423 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e JB |
424 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
425 | }; | |
426 | ||
427 | static const struct nla_policy | |
428 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
429 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
430 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
431 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
432 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
433 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
434 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
435 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
436 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
437 | }, | |
438 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
439 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
440 | }, | |
441 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
442 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
443 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
444 | }; |
445 | ||
be29b99a AK |
446 | /* policy for coalesce rule attributes */ |
447 | static const struct nla_policy | |
448 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
449 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
450 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
451 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
452 | }; | |
453 | ||
e5497d76 JB |
454 | /* policy for GTK rekey offload attributes */ |
455 | static const struct nla_policy | |
456 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
457 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
458 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
459 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
460 | }; | |
461 | ||
a1f1c21c LC |
462 | static const struct nla_policy |
463 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 464 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 465 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 466 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
467 | }; |
468 | ||
97990a06 JB |
469 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
470 | struct netlink_callback *cb, | |
471 | struct cfg80211_registered_device **rdev, | |
472 | struct wireless_dev **wdev) | |
a043897a | 473 | { |
97990a06 | 474 | int err; |
a043897a | 475 | |
97990a06 | 476 | rtnl_lock(); |
a043897a | 477 | |
97990a06 JB |
478 | if (!cb->args[0]) { |
479 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
480 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
481 | nl80211_policy); | |
482 | if (err) | |
483 | goto out_unlock; | |
67748893 | 484 | |
97990a06 JB |
485 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
486 | nl80211_fam.attrbuf); | |
487 | if (IS_ERR(*wdev)) { | |
488 | err = PTR_ERR(*wdev); | |
489 | goto out_unlock; | |
490 | } | |
f26cbf40 | 491 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
492 | /* 0 is the first index - add 1 to parse only once */ |
493 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
494 | cb->args[1] = (*wdev)->identifier; |
495 | } else { | |
c319d50b JB |
496 | /* subtract the 1 again here */ |
497 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 498 | struct wireless_dev *tmp; |
67748893 | 499 | |
97990a06 JB |
500 | if (!wiphy) { |
501 | err = -ENODEV; | |
502 | goto out_unlock; | |
503 | } | |
f26cbf40 | 504 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 505 | *wdev = NULL; |
67748893 | 506 | |
97990a06 JB |
507 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
508 | if (tmp->identifier == cb->args[1]) { | |
509 | *wdev = tmp; | |
510 | break; | |
511 | } | |
512 | } | |
67748893 | 513 | |
97990a06 JB |
514 | if (!*wdev) { |
515 | err = -ENODEV; | |
516 | goto out_unlock; | |
517 | } | |
67748893 JB |
518 | } |
519 | ||
67748893 | 520 | return 0; |
97990a06 | 521 | out_unlock: |
67748893 JB |
522 | rtnl_unlock(); |
523 | return err; | |
524 | } | |
525 | ||
97990a06 | 526 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 527 | { |
67748893 JB |
528 | rtnl_unlock(); |
529 | } | |
530 | ||
f4a11bb0 JB |
531 | /* IE validation */ |
532 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
533 | { | |
534 | const u8 *pos; | |
535 | int len; | |
536 | ||
537 | if (!attr) | |
538 | return true; | |
539 | ||
540 | pos = nla_data(attr); | |
541 | len = nla_len(attr); | |
542 | ||
543 | while (len) { | |
544 | u8 elemlen; | |
545 | ||
546 | if (len < 2) | |
547 | return false; | |
548 | len -= 2; | |
549 | ||
550 | elemlen = pos[1]; | |
551 | if (elemlen > len) | |
552 | return false; | |
553 | ||
554 | len -= elemlen; | |
555 | pos += 2 + elemlen; | |
556 | } | |
557 | ||
558 | return true; | |
559 | } | |
560 | ||
55682965 | 561 | /* message building helper */ |
15e47304 | 562 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
563 | int flags, u8 cmd) |
564 | { | |
565 | /* since there is no private header just add the generic one */ | |
15e47304 | 566 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
567 | } |
568 | ||
5dab3b8a | 569 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
570 | struct ieee80211_channel *chan, |
571 | bool large) | |
5dab3b8a | 572 | { |
ea077c1c RL |
573 | /* Some channels must be completely excluded from the |
574 | * list to protect old user-space tools from breaking | |
575 | */ | |
576 | if (!large && chan->flags & | |
577 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
578 | return 0; | |
579 | ||
9360ffd1 DM |
580 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
581 | chan->center_freq)) | |
582 | goto nla_put_failure; | |
5dab3b8a | 583 | |
9360ffd1 DM |
584 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
585 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
586 | goto nla_put_failure; | |
8fe02e16 LR |
587 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
588 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
589 | goto nla_put_failure; | |
590 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
591 | goto nla_put_failure; | |
592 | } | |
cdc89b97 JB |
593 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
594 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
595 | goto nla_put_failure; | |
596 | if (large) { | |
597 | u32 time; | |
598 | ||
599 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
600 | ||
601 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
602 | chan->dfs_state)) | |
603 | goto nla_put_failure; | |
604 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
605 | time)) | |
606 | goto nla_put_failure; | |
089027e5 JD |
607 | if (nla_put_u32(msg, |
608 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
609 | chan->dfs_cac_ms)) | |
610 | goto nla_put_failure; | |
cdc89b97 JB |
611 | } |
612 | } | |
5dab3b8a | 613 | |
fe1abafd JB |
614 | if (large) { |
615 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
616 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
617 | goto nla_put_failure; | |
618 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
619 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
620 | goto nla_put_failure; | |
621 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
622 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
623 | goto nla_put_failure; | |
624 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
625 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
626 | goto nla_put_failure; | |
570dbde1 DS |
627 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
628 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
629 | goto nla_put_failure; | |
630 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && | |
631 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) | |
632 | goto nla_put_failure; | |
ea077c1c RL |
633 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
634 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
635 | goto nla_put_failure; | |
636 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
637 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
638 | goto nla_put_failure; | |
fe1abafd JB |
639 | } |
640 | ||
9360ffd1 DM |
641 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
642 | DBM_TO_MBM(chan->max_power))) | |
643 | goto nla_put_failure; | |
5dab3b8a LR |
644 | |
645 | return 0; | |
646 | ||
647 | nla_put_failure: | |
648 | return -ENOBUFS; | |
649 | } | |
650 | ||
55682965 JB |
651 | /* netlink command implementations */ |
652 | ||
b9454e83 JB |
653 | struct key_parse { |
654 | struct key_params p; | |
655 | int idx; | |
e31b8213 | 656 | int type; |
b9454e83 | 657 | bool def, defmgmt; |
dbd2fd65 | 658 | bool def_uni, def_multi; |
b9454e83 JB |
659 | }; |
660 | ||
661 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
662 | { | |
663 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
664 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
665 | nl80211_key_policy); | |
666 | if (err) | |
667 | return err; | |
668 | ||
669 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
670 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
671 | ||
dbd2fd65 JB |
672 | if (k->def) { |
673 | k->def_uni = true; | |
674 | k->def_multi = true; | |
675 | } | |
676 | if (k->defmgmt) | |
677 | k->def_multi = true; | |
678 | ||
b9454e83 JB |
679 | if (tb[NL80211_KEY_IDX]) |
680 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
681 | ||
682 | if (tb[NL80211_KEY_DATA]) { | |
683 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
684 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
685 | } | |
686 | ||
687 | if (tb[NL80211_KEY_SEQ]) { | |
688 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
689 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
690 | } | |
691 | ||
692 | if (tb[NL80211_KEY_CIPHER]) | |
693 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
694 | ||
e31b8213 JB |
695 | if (tb[NL80211_KEY_TYPE]) { |
696 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
697 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
698 | return -EINVAL; | |
699 | } | |
700 | ||
dbd2fd65 JB |
701 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
702 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
703 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
704 | tb[NL80211_KEY_DEFAULT_TYPES], | |
705 | nl80211_key_default_policy); | |
dbd2fd65 JB |
706 | if (err) |
707 | return err; | |
708 | ||
709 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
710 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
711 | } | |
712 | ||
b9454e83 JB |
713 | return 0; |
714 | } | |
715 | ||
716 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
717 | { | |
718 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
719 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
720 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
721 | } | |
722 | ||
723 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
724 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
725 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
726 | } | |
727 | ||
728 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
729 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
730 | ||
731 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
732 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
733 | ||
734 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
735 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
736 | ||
dbd2fd65 JB |
737 | if (k->def) { |
738 | k->def_uni = true; | |
739 | k->def_multi = true; | |
740 | } | |
741 | if (k->defmgmt) | |
742 | k->def_multi = true; | |
743 | ||
e31b8213 JB |
744 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
745 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
746 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
747 | return -EINVAL; | |
748 | } | |
749 | ||
dbd2fd65 JB |
750 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
751 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
752 | int err = nla_parse_nested( | |
753 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
754 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
755 | nl80211_key_default_policy); | |
756 | if (err) | |
757 | return err; | |
758 | ||
759 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
760 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
761 | } | |
762 | ||
b9454e83 JB |
763 | return 0; |
764 | } | |
765 | ||
766 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
767 | { | |
768 | int err; | |
769 | ||
770 | memset(k, 0, sizeof(*k)); | |
771 | k->idx = -1; | |
e31b8213 | 772 | k->type = -1; |
b9454e83 JB |
773 | |
774 | if (info->attrs[NL80211_ATTR_KEY]) | |
775 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
776 | else | |
777 | err = nl80211_parse_key_old(info, k); | |
778 | ||
779 | if (err) | |
780 | return err; | |
781 | ||
782 | if (k->def && k->defmgmt) | |
783 | return -EINVAL; | |
784 | ||
dbd2fd65 JB |
785 | if (k->defmgmt) { |
786 | if (k->def_uni || !k->def_multi) | |
787 | return -EINVAL; | |
788 | } | |
789 | ||
b9454e83 JB |
790 | if (k->idx != -1) { |
791 | if (k->defmgmt) { | |
792 | if (k->idx < 4 || k->idx > 5) | |
793 | return -EINVAL; | |
794 | } else if (k->def) { | |
795 | if (k->idx < 0 || k->idx > 3) | |
796 | return -EINVAL; | |
797 | } else { | |
798 | if (k->idx < 0 || k->idx > 5) | |
799 | return -EINVAL; | |
800 | } | |
801 | } | |
802 | ||
803 | return 0; | |
804 | } | |
805 | ||
fffd0934 JB |
806 | static struct cfg80211_cached_keys * |
807 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 808 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
809 | { |
810 | struct key_parse parse; | |
811 | struct nlattr *key; | |
812 | struct cfg80211_cached_keys *result; | |
813 | int rem, err, def = 0; | |
814 | ||
815 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
816 | if (!result) | |
817 | return ERR_PTR(-ENOMEM); | |
818 | ||
819 | result->def = -1; | |
820 | result->defmgmt = -1; | |
821 | ||
822 | nla_for_each_nested(key, keys, rem) { | |
823 | memset(&parse, 0, sizeof(parse)); | |
824 | parse.idx = -1; | |
825 | ||
826 | err = nl80211_parse_key_new(key, &parse); | |
827 | if (err) | |
828 | goto error; | |
829 | err = -EINVAL; | |
830 | if (!parse.p.key) | |
831 | goto error; | |
832 | if (parse.idx < 0 || parse.idx > 4) | |
833 | goto error; | |
834 | if (parse.def) { | |
835 | if (def) | |
836 | goto error; | |
837 | def = 1; | |
838 | result->def = parse.idx; | |
dbd2fd65 JB |
839 | if (!parse.def_uni || !parse.def_multi) |
840 | goto error; | |
fffd0934 JB |
841 | } else if (parse.defmgmt) |
842 | goto error; | |
843 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 844 | parse.idx, false, NULL); |
fffd0934 JB |
845 | if (err) |
846 | goto error; | |
847 | result->params[parse.idx].cipher = parse.p.cipher; | |
848 | result->params[parse.idx].key_len = parse.p.key_len; | |
849 | result->params[parse.idx].key = result->data[parse.idx]; | |
850 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
851 | |
852 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
853 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
854 | if (no_ht) | |
855 | *no_ht = true; | |
856 | } | |
fffd0934 JB |
857 | } |
858 | ||
859 | return result; | |
860 | error: | |
861 | kfree(result); | |
862 | return ERR_PTR(err); | |
863 | } | |
864 | ||
865 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
866 | { | |
867 | ASSERT_WDEV_LOCK(wdev); | |
868 | ||
fffd0934 JB |
869 | switch (wdev->iftype) { |
870 | case NL80211_IFTYPE_AP: | |
871 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 872 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 873 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
874 | break; |
875 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 876 | case NL80211_IFTYPE_STATION: |
074ac8df | 877 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 878 | if (!wdev->current_bss) |
fffd0934 JB |
879 | return -ENOLINK; |
880 | break; | |
881 | default: | |
882 | return -EINVAL; | |
883 | } | |
884 | ||
885 | return 0; | |
886 | } | |
887 | ||
664834de JM |
888 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
889 | struct nlattr *tb) | |
890 | { | |
891 | struct ieee80211_channel *chan; | |
892 | ||
893 | if (tb == NULL) | |
894 | return NULL; | |
895 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
896 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
897 | return NULL; | |
898 | return chan; | |
899 | } | |
900 | ||
7527a782 JB |
901 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
902 | { | |
903 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
904 | int i; | |
905 | ||
906 | if (!nl_modes) | |
907 | goto nla_put_failure; | |
908 | ||
909 | i = 0; | |
910 | while (ifmodes) { | |
9360ffd1 DM |
911 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
912 | goto nla_put_failure; | |
7527a782 JB |
913 | ifmodes >>= 1; |
914 | i++; | |
915 | } | |
916 | ||
917 | nla_nest_end(msg, nl_modes); | |
918 | return 0; | |
919 | ||
920 | nla_put_failure: | |
921 | return -ENOBUFS; | |
922 | } | |
923 | ||
924 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
925 | struct sk_buff *msg, |
926 | bool large) | |
7527a782 JB |
927 | { |
928 | struct nlattr *nl_combis; | |
929 | int i, j; | |
930 | ||
931 | nl_combis = nla_nest_start(msg, | |
932 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
933 | if (!nl_combis) | |
934 | goto nla_put_failure; | |
935 | ||
936 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
937 | const struct ieee80211_iface_combination *c; | |
938 | struct nlattr *nl_combi, *nl_limits; | |
939 | ||
940 | c = &wiphy->iface_combinations[i]; | |
941 | ||
942 | nl_combi = nla_nest_start(msg, i + 1); | |
943 | if (!nl_combi) | |
944 | goto nla_put_failure; | |
945 | ||
946 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
947 | if (!nl_limits) | |
948 | goto nla_put_failure; | |
949 | ||
950 | for (j = 0; j < c->n_limits; j++) { | |
951 | struct nlattr *nl_limit; | |
952 | ||
953 | nl_limit = nla_nest_start(msg, j + 1); | |
954 | if (!nl_limit) | |
955 | goto nla_put_failure; | |
9360ffd1 DM |
956 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
957 | c->limits[j].max)) | |
958 | goto nla_put_failure; | |
7527a782 JB |
959 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
960 | c->limits[j].types)) | |
961 | goto nla_put_failure; | |
962 | nla_nest_end(msg, nl_limit); | |
963 | } | |
964 | ||
965 | nla_nest_end(msg, nl_limits); | |
966 | ||
9360ffd1 DM |
967 | if (c->beacon_int_infra_match && |
968 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
969 | goto nla_put_failure; | |
970 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
971 | c->num_different_channels) || | |
972 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
973 | c->max_interfaces)) | |
974 | goto nla_put_failure; | |
cdc89b97 | 975 | if (large && |
8c48b50a FF |
976 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
977 | c->radar_detect_widths) || | |
978 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
979 | c->radar_detect_regions))) | |
cdc89b97 | 980 | goto nla_put_failure; |
7527a782 JB |
981 | |
982 | nla_nest_end(msg, nl_combi); | |
983 | } | |
984 | ||
985 | nla_nest_end(msg, nl_combis); | |
986 | ||
987 | return 0; | |
988 | nla_put_failure: | |
989 | return -ENOBUFS; | |
990 | } | |
991 | ||
3713b4e3 | 992 | #ifdef CONFIG_PM |
b56cf720 JB |
993 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
994 | struct sk_buff *msg) | |
995 | { | |
964dc9e2 | 996 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
997 | struct nlattr *nl_tcp; |
998 | ||
999 | if (!tcp) | |
1000 | return 0; | |
1001 | ||
1002 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
1003 | if (!nl_tcp) | |
1004 | return -ENOBUFS; | |
1005 | ||
1006 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1007 | tcp->data_payload_max)) | |
1008 | return -ENOBUFS; | |
1009 | ||
1010 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1011 | tcp->data_payload_max)) | |
1012 | return -ENOBUFS; | |
1013 | ||
1014 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1015 | return -ENOBUFS; | |
1016 | ||
1017 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1018 | sizeof(*tcp->tok), tcp->tok)) | |
1019 | return -ENOBUFS; | |
1020 | ||
1021 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1022 | tcp->data_interval_max)) | |
1023 | return -ENOBUFS; | |
1024 | ||
1025 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1026 | tcp->wake_payload_max)) | |
1027 | return -ENOBUFS; | |
1028 | ||
1029 | nla_nest_end(msg, nl_tcp); | |
1030 | return 0; | |
1031 | } | |
1032 | ||
3713b4e3 | 1033 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1034 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1035 | bool large) |
55682965 | 1036 | { |
3713b4e3 | 1037 | struct nlattr *nl_wowlan; |
55682965 | 1038 | |
1b8ec87a | 1039 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1040 | return 0; |
55682965 | 1041 | |
3713b4e3 JB |
1042 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1043 | if (!nl_wowlan) | |
1044 | return -ENOBUFS; | |
9360ffd1 | 1045 | |
1b8ec87a | 1046 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1047 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1048 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1049 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1050 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1051 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1052 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1053 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1054 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1055 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1056 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1057 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1058 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1059 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1060 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1061 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1062 | return -ENOBUFS; | |
9360ffd1 | 1063 | |
1b8ec87a | 1064 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1065 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1066 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1067 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1068 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1069 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1070 | }; |
9360ffd1 | 1071 | |
3713b4e3 JB |
1072 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1073 | sizeof(pat), &pat)) | |
1074 | return -ENOBUFS; | |
1075 | } | |
9360ffd1 | 1076 | |
1b8ec87a | 1077 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1078 | return -ENOBUFS; |
1079 | ||
3713b4e3 | 1080 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1081 | |
3713b4e3 JB |
1082 | return 0; |
1083 | } | |
1084 | #endif | |
9360ffd1 | 1085 | |
be29b99a | 1086 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1087 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1088 | { |
1089 | struct nl80211_coalesce_rule_support rule; | |
1090 | ||
1b8ec87a | 1091 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1092 | return 0; |
1093 | ||
1b8ec87a ZG |
1094 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1095 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1096 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1097 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1098 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1099 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1100 | |
1101 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1102 | return -ENOBUFS; | |
1103 | ||
1104 | return 0; | |
1105 | } | |
1106 | ||
3713b4e3 JB |
1107 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1108 | struct ieee80211_supported_band *sband) | |
1109 | { | |
1110 | struct nlattr *nl_rates, *nl_rate; | |
1111 | struct ieee80211_rate *rate; | |
1112 | int i; | |
87bbbe22 | 1113 | |
3713b4e3 JB |
1114 | /* add HT info */ |
1115 | if (sband->ht_cap.ht_supported && | |
1116 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1117 | sizeof(sband->ht_cap.mcs), | |
1118 | &sband->ht_cap.mcs) || | |
1119 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1120 | sband->ht_cap.cap) || | |
1121 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1122 | sband->ht_cap.ampdu_factor) || | |
1123 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1124 | sband->ht_cap.ampdu_density))) | |
1125 | return -ENOBUFS; | |
afe0cbf8 | 1126 | |
3713b4e3 JB |
1127 | /* add VHT info */ |
1128 | if (sband->vht_cap.vht_supported && | |
1129 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1130 | sizeof(sband->vht_cap.vht_mcs), | |
1131 | &sband->vht_cap.vht_mcs) || | |
1132 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1133 | sband->vht_cap.cap))) | |
1134 | return -ENOBUFS; | |
f59ac048 | 1135 | |
3713b4e3 JB |
1136 | /* add bitrates */ |
1137 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1138 | if (!nl_rates) | |
1139 | return -ENOBUFS; | |
ee688b00 | 1140 | |
3713b4e3 JB |
1141 | for (i = 0; i < sband->n_bitrates; i++) { |
1142 | nl_rate = nla_nest_start(msg, i); | |
1143 | if (!nl_rate) | |
1144 | return -ENOBUFS; | |
ee688b00 | 1145 | |
3713b4e3 JB |
1146 | rate = &sband->bitrates[i]; |
1147 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1148 | rate->bitrate)) | |
1149 | return -ENOBUFS; | |
1150 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1151 | nla_put_flag(msg, | |
1152 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1153 | return -ENOBUFS; | |
ee688b00 | 1154 | |
3713b4e3 JB |
1155 | nla_nest_end(msg, nl_rate); |
1156 | } | |
d51626df | 1157 | |
3713b4e3 | 1158 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1159 | |
3713b4e3 JB |
1160 | return 0; |
1161 | } | |
ee688b00 | 1162 | |
3713b4e3 JB |
1163 | static int |
1164 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1165 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1166 | { | |
1167 | u16 stypes; | |
1168 | struct nlattr *nl_ftypes, *nl_ifs; | |
1169 | enum nl80211_iftype ift; | |
1170 | int i; | |
ee688b00 | 1171 | |
3713b4e3 JB |
1172 | if (!mgmt_stypes) |
1173 | return 0; | |
5dab3b8a | 1174 | |
3713b4e3 JB |
1175 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1176 | if (!nl_ifs) | |
1177 | return -ENOBUFS; | |
e2f367f2 | 1178 | |
3713b4e3 JB |
1179 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1180 | nl_ftypes = nla_nest_start(msg, ift); | |
1181 | if (!nl_ftypes) | |
1182 | return -ENOBUFS; | |
1183 | i = 0; | |
1184 | stypes = mgmt_stypes[ift].tx; | |
1185 | while (stypes) { | |
1186 | if ((stypes & 1) && | |
1187 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1188 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1189 | return -ENOBUFS; | |
1190 | stypes >>= 1; | |
1191 | i++; | |
ee688b00 | 1192 | } |
3713b4e3 JB |
1193 | nla_nest_end(msg, nl_ftypes); |
1194 | } | |
ee688b00 | 1195 | |
3713b4e3 | 1196 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1197 | |
3713b4e3 JB |
1198 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1199 | if (!nl_ifs) | |
1200 | return -ENOBUFS; | |
ee688b00 | 1201 | |
3713b4e3 JB |
1202 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1203 | nl_ftypes = nla_nest_start(msg, ift); | |
1204 | if (!nl_ftypes) | |
1205 | return -ENOBUFS; | |
1206 | i = 0; | |
1207 | stypes = mgmt_stypes[ift].rx; | |
1208 | while (stypes) { | |
1209 | if ((stypes & 1) && | |
1210 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1211 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1212 | return -ENOBUFS; | |
1213 | stypes >>= 1; | |
1214 | i++; | |
1215 | } | |
1216 | nla_nest_end(msg, nl_ftypes); | |
1217 | } | |
1218 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1219 | |
3713b4e3 JB |
1220 | return 0; |
1221 | } | |
ee688b00 | 1222 | |
86e8cf98 JB |
1223 | struct nl80211_dump_wiphy_state { |
1224 | s64 filter_wiphy; | |
1225 | long start; | |
1226 | long split_start, band_start, chan_start; | |
1227 | bool split; | |
1228 | }; | |
1229 | ||
1b8ec87a | 1230 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 1231 | enum nl80211_commands cmd, |
3713b4e3 | 1232 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1233 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1234 | { |
1235 | void *hdr; | |
1236 | struct nlattr *nl_bands, *nl_band; | |
1237 | struct nlattr *nl_freqs, *nl_freq; | |
1238 | struct nlattr *nl_cmds; | |
1239 | enum ieee80211_band band; | |
1240 | struct ieee80211_channel *chan; | |
1241 | int i; | |
1242 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1243 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1244 | u32 features; |
ee688b00 | 1245 | |
3bb20556 | 1246 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
1247 | if (!hdr) |
1248 | return -ENOBUFS; | |
ee688b00 | 1249 | |
86e8cf98 JB |
1250 | if (WARN_ON(!state)) |
1251 | return -EINVAL; | |
ee688b00 | 1252 | |
1b8ec87a | 1253 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1254 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1255 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1256 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1257 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1258 | goto nla_put_failure; |
1259 | ||
3bb20556 JB |
1260 | if (cmd != NL80211_CMD_NEW_WIPHY) |
1261 | goto finish; | |
1262 | ||
86e8cf98 | 1263 | switch (state->split_start) { |
3713b4e3 JB |
1264 | case 0: |
1265 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1266 | rdev->wiphy.retry_short) || |
3713b4e3 | 1267 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1268 | rdev->wiphy.retry_long) || |
3713b4e3 | 1269 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1270 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1271 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1272 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1273 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1274 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1275 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1276 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1277 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1278 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1279 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1280 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1281 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1282 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1283 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
1b8ec87a | 1284 | rdev->wiphy.max_match_sets)) |
9360ffd1 | 1285 | goto nla_put_failure; |
3713b4e3 | 1286 | |
1b8ec87a | 1287 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1288 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1289 | goto nla_put_failure; |
1b8ec87a | 1290 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1291 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1292 | goto nla_put_failure; | |
1b8ec87a | 1293 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1294 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1295 | goto nla_put_failure; | |
1b8ec87a | 1296 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1297 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1298 | goto nla_put_failure; | |
1b8ec87a | 1299 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1300 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1301 | goto nla_put_failure; | |
1b8ec87a | 1302 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1303 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1304 | goto nla_put_failure; |
86e8cf98 JB |
1305 | state->split_start++; |
1306 | if (state->split) | |
3713b4e3 JB |
1307 | break; |
1308 | case 1: | |
1309 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1310 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1311 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1312 | goto nla_put_failure; |
4745fc09 | 1313 | |
3713b4e3 | 1314 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1315 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1316 | goto nla_put_failure; |
b23aa676 | 1317 | |
1b8ec87a | 1318 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1319 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1320 | goto nla_put_failure; |
b23aa676 | 1321 | |
3713b4e3 | 1322 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1323 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1324 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1325 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1326 | goto nla_put_failure; |
b23aa676 | 1327 | |
1b8ec87a | 1328 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1329 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1330 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1331 | goto nla_put_failure; |
8fdc621d | 1332 | |
1b8ec87a ZG |
1333 | if ((rdev->wiphy.available_antennas_tx || |
1334 | rdev->wiphy.available_antennas_rx) && | |
1335 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1336 | u32 tx_ant = 0, rx_ant = 0; |
1337 | int res; | |
1b8ec87a | 1338 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1339 | if (!res) { |
1340 | if (nla_put_u32(msg, | |
1341 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1342 | tx_ant) || | |
1343 | nla_put_u32(msg, | |
1344 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1345 | rx_ant)) | |
1346 | goto nla_put_failure; | |
1347 | } | |
1348 | } | |
a293911d | 1349 | |
86e8cf98 JB |
1350 | state->split_start++; |
1351 | if (state->split) | |
3713b4e3 JB |
1352 | break; |
1353 | case 2: | |
1354 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1355 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1356 | goto nla_put_failure; |
86e8cf98 JB |
1357 | state->split_start++; |
1358 | if (state->split) | |
3713b4e3 JB |
1359 | break; |
1360 | case 3: | |
1361 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1362 | if (!nl_bands) | |
1363 | goto nla_put_failure; | |
f7ca38df | 1364 | |
86e8cf98 JB |
1365 | for (band = state->band_start; |
1366 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1367 | struct ieee80211_supported_band *sband; |
2e161f78 | 1368 | |
1b8ec87a | 1369 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1370 | |
3713b4e3 JB |
1371 | if (!sband) |
1372 | continue; | |
1373 | ||
1374 | nl_band = nla_nest_start(msg, band); | |
1375 | if (!nl_band) | |
2e161f78 | 1376 | goto nla_put_failure; |
3713b4e3 | 1377 | |
86e8cf98 | 1378 | switch (state->chan_start) { |
3713b4e3 JB |
1379 | case 0: |
1380 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1381 | goto nla_put_failure; |
86e8cf98 JB |
1382 | state->chan_start++; |
1383 | if (state->split) | |
3713b4e3 JB |
1384 | break; |
1385 | default: | |
1386 | /* add frequencies */ | |
1387 | nl_freqs = nla_nest_start( | |
1388 | msg, NL80211_BAND_ATTR_FREQS); | |
1389 | if (!nl_freqs) | |
1390 | goto nla_put_failure; | |
1391 | ||
86e8cf98 | 1392 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1393 | i < sband->n_channels; |
1394 | i++) { | |
1395 | nl_freq = nla_nest_start(msg, i); | |
1396 | if (!nl_freq) | |
1397 | goto nla_put_failure; | |
1398 | ||
1399 | chan = &sband->channels[i]; | |
1400 | ||
86e8cf98 JB |
1401 | if (nl80211_msg_put_channel( |
1402 | msg, chan, | |
1403 | state->split)) | |
3713b4e3 JB |
1404 | goto nla_put_failure; |
1405 | ||
1406 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1407 | if (state->split) |
3713b4e3 JB |
1408 | break; |
1409 | } | |
1410 | if (i < sband->n_channels) | |
86e8cf98 | 1411 | state->chan_start = i + 2; |
3713b4e3 | 1412 | else |
86e8cf98 | 1413 | state->chan_start = 0; |
3713b4e3 JB |
1414 | nla_nest_end(msg, nl_freqs); |
1415 | } | |
1416 | ||
1417 | nla_nest_end(msg, nl_band); | |
1418 | ||
86e8cf98 | 1419 | if (state->split) { |
3713b4e3 | 1420 | /* start again here */ |
86e8cf98 | 1421 | if (state->chan_start) |
3713b4e3 JB |
1422 | band--; |
1423 | break; | |
2e161f78 | 1424 | } |
2e161f78 | 1425 | } |
3713b4e3 | 1426 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1427 | |
3713b4e3 | 1428 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1429 | state->band_start = band + 1; |
3713b4e3 | 1430 | else |
86e8cf98 | 1431 | state->band_start = 0; |
74b70a4e | 1432 | |
3713b4e3 | 1433 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1434 | if (state->band_start == 0 && state->chan_start == 0) |
1435 | state->split_start++; | |
1436 | if (state->split) | |
3713b4e3 JB |
1437 | break; |
1438 | case 4: | |
1439 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1440 | if (!nl_cmds) | |
2e161f78 JB |
1441 | goto nla_put_failure; |
1442 | ||
3713b4e3 JB |
1443 | i = 0; |
1444 | #define CMD(op, n) \ | |
1445 | do { \ | |
1b8ec87a | 1446 | if (rdev->ops->op) { \ |
3713b4e3 JB |
1447 | i++; \ |
1448 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1449 | goto nla_put_failure; \ | |
1450 | } \ | |
1451 | } while (0) | |
1452 | ||
1453 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1454 | CMD(change_virtual_intf, SET_INTERFACE); | |
1455 | CMD(add_key, NEW_KEY); | |
1456 | CMD(start_ap, START_AP); | |
1457 | CMD(add_station, NEW_STATION); | |
1458 | CMD(add_mpath, NEW_MPATH); | |
1459 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1460 | CMD(change_bss, SET_BSS); | |
1461 | CMD(auth, AUTHENTICATE); | |
1462 | CMD(assoc, ASSOCIATE); | |
1463 | CMD(deauth, DEAUTHENTICATE); | |
1464 | CMD(disassoc, DISASSOCIATE); | |
1465 | CMD(join_ibss, JOIN_IBSS); | |
1466 | CMD(join_mesh, JOIN_MESH); | |
1467 | CMD(set_pmksa, SET_PMKSA); | |
1468 | CMD(del_pmksa, DEL_PMKSA); | |
1469 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1b8ec87a | 1470 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
3713b4e3 JB |
1471 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
1472 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1473 | CMD(mgmt_tx, FRAME); | |
1474 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1b8ec87a | 1475 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
3713b4e3 JB |
1476 | i++; |
1477 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1478 | goto nla_put_failure; |
2e161f78 | 1479 | } |
1b8ec87a ZG |
1480 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
1481 | rdev->ops->join_mesh) { | |
3713b4e3 JB |
1482 | i++; |
1483 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1484 | goto nla_put_failure; | |
1485 | } | |
1486 | CMD(set_wds_peer, SET_WDS_PEER); | |
1b8ec87a | 1487 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
3713b4e3 JB |
1488 | CMD(tdls_mgmt, TDLS_MGMT); |
1489 | CMD(tdls_oper, TDLS_OPER); | |
1490 | } | |
1b8ec87a | 1491 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
3713b4e3 JB |
1492 | CMD(sched_scan_start, START_SCHED_SCAN); |
1493 | CMD(probe_client, PROBE_CLIENT); | |
1494 | CMD(set_noack_map, SET_NOACK_MAP); | |
1b8ec87a | 1495 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
3713b4e3 JB |
1496 | i++; |
1497 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1498 | goto nla_put_failure; | |
1499 | } | |
1500 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1501 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
02df00eb JB |
1502 | #ifdef CONFIG_NL80211_TESTMODE |
1503 | CMD(testmode_cmd, TESTMODE); | |
1504 | #endif | |
86e8cf98 | 1505 | if (state->split) { |
5de17984 AS |
1506 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1507 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 1508 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 1509 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 1510 | CMD(set_qos_map, SET_QOS_MAP); |
5de17984 | 1511 | } |
02df00eb | 1512 | /* add into the if now */ |
3713b4e3 | 1513 | #undef CMD |
ff1b6e69 | 1514 | |
1b8ec87a | 1515 | if (rdev->ops->connect || rdev->ops->auth) { |
3713b4e3 JB |
1516 | i++; |
1517 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1518 | goto nla_put_failure; |
ff1b6e69 JB |
1519 | } |
1520 | ||
1b8ec87a | 1521 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
3713b4e3 JB |
1522 | i++; |
1523 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1524 | goto nla_put_failure; | |
1525 | } | |
1526 | ||
1527 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1528 | state->split_start++; |
1529 | if (state->split) | |
3713b4e3 JB |
1530 | break; |
1531 | case 5: | |
1b8ec87a ZG |
1532 | if (rdev->ops->remain_on_channel && |
1533 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
1534 | nla_put_u32(msg, |
1535 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 1536 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
1537 | goto nla_put_failure; |
1538 | ||
1b8ec87a | 1539 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
1540 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
1541 | goto nla_put_failure; | |
1542 | ||
1543 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1544 | goto nla_put_failure; | |
86e8cf98 JB |
1545 | state->split_start++; |
1546 | if (state->split) | |
3713b4e3 JB |
1547 | break; |
1548 | case 6: | |
1549 | #ifdef CONFIG_PM | |
1b8ec87a | 1550 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 1551 | goto nla_put_failure; |
86e8cf98 JB |
1552 | state->split_start++; |
1553 | if (state->split) | |
3713b4e3 JB |
1554 | break; |
1555 | #else | |
86e8cf98 | 1556 | state->split_start++; |
dfb89c56 | 1557 | #endif |
3713b4e3 JB |
1558 | case 7: |
1559 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 1560 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 1561 | goto nla_put_failure; |
ff1b6e69 | 1562 | |
1b8ec87a | 1563 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 1564 | state->split)) |
3713b4e3 | 1565 | goto nla_put_failure; |
7527a782 | 1566 | |
86e8cf98 JB |
1567 | state->split_start++; |
1568 | if (state->split) | |
3713b4e3 JB |
1569 | break; |
1570 | case 8: | |
1b8ec87a | 1571 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 1572 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 1573 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 1574 | goto nla_put_failure; |
7527a782 | 1575 | |
1b8ec87a | 1576 | features = rdev->wiphy.features; |
fe1abafd JB |
1577 | /* |
1578 | * We can only add the per-channel limit information if the | |
1579 | * dump is split, otherwise it makes it too big. Therefore | |
1580 | * only advertise it in that case. | |
1581 | */ | |
86e8cf98 | 1582 | if (state->split) |
fe1abafd JB |
1583 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1584 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1585 | goto nla_put_failure; |
562a7480 | 1586 | |
1b8ec87a | 1587 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 1588 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
1589 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
1590 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 1591 | goto nla_put_failure; |
1f074bd8 | 1592 | |
1b8ec87a ZG |
1593 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1594 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 1595 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 1596 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 1597 | goto nla_put_failure; |
7e7c8926 | 1598 | |
3713b4e3 JB |
1599 | /* |
1600 | * Any information below this point is only available to | |
1601 | * applications that can deal with it being split. This | |
1602 | * helps ensure that newly added capabilities don't break | |
1603 | * older tools by overrunning their buffers. | |
1604 | * | |
1605 | * We still increment split_start so that in the split | |
1606 | * case we'll continue with more data in the next round, | |
1607 | * but break unconditionally so unsplit data stops here. | |
1608 | */ | |
86e8cf98 | 1609 | state->split_start++; |
3713b4e3 JB |
1610 | break; |
1611 | case 9: | |
1b8ec87a | 1612 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 1613 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
1614 | rdev->wiphy.extended_capabilities_len, |
1615 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 1616 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
1617 | rdev->wiphy.extended_capabilities_len, |
1618 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 1619 | goto nla_put_failure; |
a50df0c4 | 1620 | |
1b8ec87a | 1621 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 1622 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
1623 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
1624 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
1625 | goto nla_put_failure; |
1626 | ||
be29b99a AK |
1627 | state->split_start++; |
1628 | break; | |
1629 | case 10: | |
1b8ec87a | 1630 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
1631 | goto nla_put_failure; |
1632 | ||
1b8ec87a | 1633 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
1634 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
1635 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1636 | goto nla_put_failure; | |
b43504cf | 1637 | |
1b8ec87a | 1638 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 1639 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 1640 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
1641 | goto nla_put_failure; |
1642 | ||
ad7e718c JB |
1643 | state->split_start++; |
1644 | break; | |
1645 | case 11: | |
1b8ec87a | 1646 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
1647 | const struct nl80211_vendor_cmd_info *info; |
1648 | struct nlattr *nested; | |
1649 | ||
1650 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1651 | if (!nested) | |
1652 | goto nla_put_failure; | |
1653 | ||
1b8ec87a ZG |
1654 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
1655 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
1656 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1657 | goto nla_put_failure; | |
1658 | } | |
1659 | nla_nest_end(msg, nested); | |
1660 | } | |
1661 | ||
1b8ec87a | 1662 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
1663 | const struct nl80211_vendor_cmd_info *info; |
1664 | struct nlattr *nested; | |
ad7e718c | 1665 | |
567ffc35 JB |
1666 | nested = nla_nest_start(msg, |
1667 | NL80211_ATTR_VENDOR_EVENTS); | |
1668 | if (!nested) | |
ad7e718c | 1669 | goto nla_put_failure; |
567ffc35 | 1670 | |
1b8ec87a ZG |
1671 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
1672 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
1673 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1674 | goto nla_put_failure; | |
1675 | } | |
1676 | nla_nest_end(msg, nested); | |
1677 | } | |
9a774c78 AO |
1678 | state->split_start++; |
1679 | break; | |
1680 | case 12: | |
1681 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
1682 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
1683 | rdev->wiphy.max_num_csa_counters)) | |
1684 | goto nla_put_failure; | |
01e0daa4 | 1685 | |
3713b4e3 | 1686 | /* done */ |
86e8cf98 | 1687 | state->split_start = 0; |
3713b4e3 JB |
1688 | break; |
1689 | } | |
3bb20556 | 1690 | finish: |
55682965 JB |
1691 | return genlmsg_end(msg, hdr); |
1692 | ||
1693 | nla_put_failure: | |
bc3ed28c TG |
1694 | genlmsg_cancel(msg, hdr); |
1695 | return -EMSGSIZE; | |
55682965 JB |
1696 | } |
1697 | ||
86e8cf98 JB |
1698 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1699 | struct netlink_callback *cb, | |
1700 | struct nl80211_dump_wiphy_state *state) | |
1701 | { | |
1702 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1703 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1704 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1705 | /* ignore parse errors for backward compatibility */ | |
1706 | if (ret) | |
1707 | return 0; | |
1708 | ||
1709 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1710 | if (tb[NL80211_ATTR_WIPHY]) | |
1711 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1712 | if (tb[NL80211_ATTR_WDEV]) | |
1713 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1714 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1715 | struct net_device *netdev; | |
1716 | struct cfg80211_registered_device *rdev; | |
1717 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1718 | ||
7f2b8562 | 1719 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1720 | if (!netdev) |
1721 | return -ENODEV; | |
1722 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1723 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1724 | netdev->ieee80211_ptr->wiphy); |
1725 | state->filter_wiphy = rdev->wiphy_idx; | |
1726 | } | |
86e8cf98 JB |
1727 | } |
1728 | ||
1729 | return 0; | |
1730 | } | |
1731 | ||
55682965 JB |
1732 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1733 | { | |
645e77de | 1734 | int idx = 0, ret; |
86e8cf98 | 1735 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1736 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1737 | |
5fe231e8 | 1738 | rtnl_lock(); |
86e8cf98 JB |
1739 | if (!state) { |
1740 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1741 | if (!state) { |
1742 | rtnl_unlock(); | |
86e8cf98 | 1743 | return -ENOMEM; |
3713b4e3 | 1744 | } |
86e8cf98 JB |
1745 | state->filter_wiphy = -1; |
1746 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1747 | if (ret) { | |
1748 | kfree(state); | |
1749 | rtnl_unlock(); | |
1750 | return ret; | |
3713b4e3 | 1751 | } |
86e8cf98 | 1752 | cb->args[0] = (long)state; |
3713b4e3 JB |
1753 | } |
1754 | ||
1b8ec87a ZG |
1755 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1756 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1757 | continue; |
86e8cf98 | 1758 | if (++idx <= state->start) |
55682965 | 1759 | continue; |
86e8cf98 | 1760 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1761 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1762 | continue; |
1763 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1764 | do { | |
3bb20556 JB |
1765 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
1766 | skb, | |
3713b4e3 JB |
1767 | NETLINK_CB(cb->skb).portid, |
1768 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1769 | NLM_F_MULTI, state); |
3713b4e3 JB |
1770 | if (ret < 0) { |
1771 | /* | |
1772 | * If sending the wiphy data didn't fit (ENOBUFS | |
1773 | * or EMSGSIZE returned), this SKB is still | |
1774 | * empty (so it's not too big because another | |
1775 | * wiphy dataset is already in the skb) and | |
1776 | * we've not tried to adjust the dump allocation | |
1777 | * yet ... then adjust the alloc size to be | |
1778 | * bigger, and return 1 but with the empty skb. | |
1779 | * This results in an empty message being RX'ed | |
1780 | * in userspace, but that is ignored. | |
1781 | * | |
1782 | * We can then retry with the larger buffer. | |
1783 | */ | |
1784 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1785 | !skb->len && !state->split && |
3713b4e3 JB |
1786 | cb->min_dump_alloc < 4096) { |
1787 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1788 | state->split_start = 0; |
d98cae64 | 1789 | rtnl_unlock(); |
3713b4e3 JB |
1790 | return 1; |
1791 | } | |
1792 | idx--; | |
1793 | break; | |
645e77de | 1794 | } |
86e8cf98 | 1795 | } while (state->split_start > 0); |
3713b4e3 | 1796 | break; |
55682965 | 1797 | } |
5fe231e8 | 1798 | rtnl_unlock(); |
55682965 | 1799 | |
86e8cf98 | 1800 | state->start = idx; |
55682965 JB |
1801 | |
1802 | return skb->len; | |
1803 | } | |
1804 | ||
86e8cf98 JB |
1805 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1806 | { | |
1807 | kfree((void *)cb->args[0]); | |
1808 | return 0; | |
1809 | } | |
1810 | ||
55682965 JB |
1811 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1812 | { | |
1813 | struct sk_buff *msg; | |
1b8ec87a | 1814 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 1815 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1816 | |
645e77de | 1817 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1818 | if (!msg) |
4c476991 | 1819 | return -ENOMEM; |
55682965 | 1820 | |
3bb20556 JB |
1821 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
1822 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 1823 | &state) < 0) { |
4c476991 JB |
1824 | nlmsg_free(msg); |
1825 | return -ENOBUFS; | |
1826 | } | |
55682965 | 1827 | |
134e6375 | 1828 | return genlmsg_reply(msg, info); |
55682965 JB |
1829 | } |
1830 | ||
31888487 JM |
1831 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1832 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1833 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1834 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1835 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1836 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1837 | }; | |
1838 | ||
1839 | static int parse_txq_params(struct nlattr *tb[], | |
1840 | struct ieee80211_txq_params *txq_params) | |
1841 | { | |
a3304b0a | 1842 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1843 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1844 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1845 | return -EINVAL; | |
1846 | ||
a3304b0a | 1847 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1848 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1849 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1850 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1851 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1852 | ||
a3304b0a JB |
1853 | if (txq_params->ac >= NL80211_NUM_ACS) |
1854 | return -EINVAL; | |
1855 | ||
31888487 JM |
1856 | return 0; |
1857 | } | |
1858 | ||
f444de05 JB |
1859 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1860 | { | |
1861 | /* | |
cc1d2806 JB |
1862 | * You can only set the channel explicitly for WDS interfaces, |
1863 | * all others have their channel managed via their respective | |
1864 | * "establish a connection" command (connect, join, ...) | |
1865 | * | |
1866 | * For AP/GO and mesh mode, the channel can be set with the | |
1867 | * channel userspace API, but is only stored and passed to the | |
1868 | * low-level driver when the AP starts or the mesh is joined. | |
1869 | * This is for backward compatibility, userspace can also give | |
1870 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1871 | * |
1872 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1873 | * whatever else is going on, so they have their own special |
1874 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1875 | */ |
1876 | return !wdev || | |
1877 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1878 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1879 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1880 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1881 | } |
1882 | ||
683b6d3b JB |
1883 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1884 | struct genl_info *info, | |
1885 | struct cfg80211_chan_def *chandef) | |
1886 | { | |
dbeca2ea | 1887 | u32 control_freq; |
683b6d3b JB |
1888 | |
1889 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1890 | return -EINVAL; | |
1891 | ||
1892 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1893 | ||
1894 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1895 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1896 | chandef->center_freq1 = control_freq; | |
1897 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1898 | |
1899 | /* Primary channel not allowed */ | |
1900 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1901 | return -EINVAL; | |
1902 | ||
3d9d1d66 JB |
1903 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1904 | enum nl80211_channel_type chantype; | |
1905 | ||
1906 | chantype = nla_get_u32( | |
1907 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1908 | ||
1909 | switch (chantype) { | |
1910 | case NL80211_CHAN_NO_HT: | |
1911 | case NL80211_CHAN_HT20: | |
1912 | case NL80211_CHAN_HT40PLUS: | |
1913 | case NL80211_CHAN_HT40MINUS: | |
1914 | cfg80211_chandef_create(chandef, chandef->chan, | |
1915 | chantype); | |
1916 | break; | |
1917 | default: | |
1918 | return -EINVAL; | |
1919 | } | |
1920 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1921 | chandef->width = | |
1922 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1923 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1924 | chandef->center_freq1 = | |
1925 | nla_get_u32( | |
1926 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1927 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1928 | chandef->center_freq2 = | |
1929 | nla_get_u32( | |
1930 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1931 | } | |
1932 | ||
9f5e8f6e | 1933 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1934 | return -EINVAL; |
1935 | ||
9f5e8f6e JB |
1936 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1937 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1938 | return -EINVAL; |
1939 | ||
2f301ab2 SW |
1940 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1941 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1942 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1943 | return -EINVAL; | |
1944 | ||
683b6d3b JB |
1945 | return 0; |
1946 | } | |
1947 | ||
f444de05 | 1948 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 1949 | struct net_device *dev, |
f444de05 JB |
1950 | struct genl_info *info) |
1951 | { | |
683b6d3b | 1952 | struct cfg80211_chan_def chandef; |
f444de05 | 1953 | int result; |
e8c9bd5b | 1954 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 1955 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 1956 | |
e16821bc JM |
1957 | if (dev) |
1958 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
1959 | if (!nl80211_can_set_dev_channel(wdev)) |
1960 | return -EOPNOTSUPP; | |
e16821bc JM |
1961 | if (wdev) |
1962 | iftype = wdev->iftype; | |
f444de05 | 1963 | |
683b6d3b JB |
1964 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1965 | if (result) | |
1966 | return result; | |
f444de05 | 1967 | |
e8c9bd5b | 1968 | switch (iftype) { |
aa430da4 JB |
1969 | case NL80211_IFTYPE_AP: |
1970 | case NL80211_IFTYPE_P2P_GO: | |
174e0cd2 | 1971 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
aa430da4 JB |
1972 | result = -EINVAL; |
1973 | break; | |
1974 | } | |
e16821bc JM |
1975 | if (wdev->beacon_interval) { |
1976 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
1977 | !(rdev->wiphy.features & | |
1978 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
1979 | result = -EBUSY; | |
1980 | break; | |
1981 | } | |
1982 | ||
1983 | /* Only allow dynamic channel width changes */ | |
1984 | if (chandef.chan != wdev->preset_chandef.chan) { | |
1985 | result = -EBUSY; | |
1986 | break; | |
1987 | } | |
1988 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
1989 | if (result) | |
1990 | break; | |
1991 | } | |
683b6d3b | 1992 | wdev->preset_chandef = chandef; |
aa430da4 JB |
1993 | result = 0; |
1994 | break; | |
cc1d2806 | 1995 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 1996 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 1997 | break; |
e8c9bd5b | 1998 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 1999 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 2000 | break; |
aa430da4 | 2001 | default: |
e8c9bd5b | 2002 | result = -EINVAL; |
f444de05 | 2003 | } |
f444de05 JB |
2004 | |
2005 | return result; | |
2006 | } | |
2007 | ||
2008 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2009 | { | |
4c476991 JB |
2010 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2011 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2012 | |
e16821bc | 2013 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2014 | } |
2015 | ||
e8347eba BJ |
2016 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2017 | { | |
43b19952 JB |
2018 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2019 | struct net_device *dev = info->user_ptr[1]; | |
2020 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2021 | const u8 *bssid; |
e8347eba BJ |
2022 | |
2023 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2024 | return -EINVAL; | |
2025 | ||
43b19952 JB |
2026 | if (netif_running(dev)) |
2027 | return -EBUSY; | |
e8347eba | 2028 | |
43b19952 JB |
2029 | if (!rdev->ops->set_wds_peer) |
2030 | return -EOPNOTSUPP; | |
e8347eba | 2031 | |
43b19952 JB |
2032 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2033 | return -EOPNOTSUPP; | |
e8347eba BJ |
2034 | |
2035 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2036 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2037 | } |
2038 | ||
2039 | ||
55682965 JB |
2040 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2041 | { | |
2042 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2043 | struct net_device *netdev = NULL; |
2044 | struct wireless_dev *wdev; | |
a1e567c8 | 2045 | int result = 0, rem_txq_params = 0; |
31888487 | 2046 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2047 | u32 changed; |
2048 | u8 retry_short = 0, retry_long = 0; | |
2049 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2050 | u8 coverage_class = 0; |
55682965 | 2051 | |
5fe231e8 JB |
2052 | ASSERT_RTNL(); |
2053 | ||
f444de05 JB |
2054 | /* |
2055 | * Try to find the wiphy and netdev. Normally this | |
2056 | * function shouldn't need the netdev, but this is | |
2057 | * done for backward compatibility -- previously | |
2058 | * setting the channel was done per wiphy, but now | |
2059 | * it is per netdev. Previous userland like hostapd | |
2060 | * also passed a netdev to set_wiphy, so that it is | |
2061 | * possible to let that go to the right netdev! | |
2062 | */ | |
4bbf4d56 | 2063 | |
f444de05 JB |
2064 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2065 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2066 | ||
7f2b8562 | 2067 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2068 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2069 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2070 | else |
f444de05 | 2071 | netdev = NULL; |
4bbf4d56 JB |
2072 | } |
2073 | ||
f444de05 | 2074 | if (!netdev) { |
878d9ec7 JB |
2075 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2076 | info->attrs); | |
5fe231e8 | 2077 | if (IS_ERR(rdev)) |
4c476991 | 2078 | return PTR_ERR(rdev); |
f444de05 JB |
2079 | wdev = NULL; |
2080 | netdev = NULL; | |
2081 | result = 0; | |
71fe96bf | 2082 | } else |
f444de05 | 2083 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2084 | |
2085 | /* | |
2086 | * end workaround code, by now the rdev is available | |
2087 | * and locked, and wdev may or may not be NULL. | |
2088 | */ | |
4bbf4d56 JB |
2089 | |
2090 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2091 | result = cfg80211_dev_rename( |
2092 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2093 | |
4bbf4d56 | 2094 | if (result) |
7f2b8562 | 2095 | return result; |
31888487 JM |
2096 | |
2097 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2098 | struct ieee80211_txq_params txq_params; | |
2099 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2100 | ||
7f2b8562 YX |
2101 | if (!rdev->ops->set_txq_params) |
2102 | return -EOPNOTSUPP; | |
31888487 | 2103 | |
7f2b8562 YX |
2104 | if (!netdev) |
2105 | return -EINVAL; | |
f70f01c2 | 2106 | |
133a3ff2 | 2107 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2108 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2109 | return -EINVAL; | |
133a3ff2 | 2110 | |
7f2b8562 YX |
2111 | if (!netif_running(netdev)) |
2112 | return -ENETDOWN; | |
2b5f8b0b | 2113 | |
31888487 JM |
2114 | nla_for_each_nested(nl_txq_params, |
2115 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2116 | rem_txq_params) { | |
ae811e21 JB |
2117 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2118 | nla_data(nl_txq_params), | |
2119 | nla_len(nl_txq_params), | |
2120 | txq_params_policy); | |
2121 | if (result) | |
2122 | return result; | |
31888487 JM |
2123 | result = parse_txq_params(tb, &txq_params); |
2124 | if (result) | |
7f2b8562 | 2125 | return result; |
31888487 | 2126 | |
e35e4d28 HG |
2127 | result = rdev_set_txq_params(rdev, netdev, |
2128 | &txq_params); | |
31888487 | 2129 | if (result) |
7f2b8562 | 2130 | return result; |
31888487 JM |
2131 | } |
2132 | } | |
55682965 | 2133 | |
72bdcf34 | 2134 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2135 | result = __nl80211_set_channel( |
2136 | rdev, | |
2137 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2138 | info); | |
72bdcf34 | 2139 | if (result) |
7f2b8562 | 2140 | return result; |
72bdcf34 JM |
2141 | } |
2142 | ||
98d2ff8b | 2143 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2144 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2145 | enum nl80211_tx_power_setting type; |
2146 | int idx, mbm = 0; | |
2147 | ||
c8442118 JB |
2148 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2149 | txp_wdev = NULL; | |
2150 | ||
7f2b8562 YX |
2151 | if (!rdev->ops->set_tx_power) |
2152 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2153 | |
2154 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2155 | type = nla_get_u32(info->attrs[idx]); | |
2156 | ||
2157 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2158 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2159 | return -EINVAL; | |
98d2ff8b JO |
2160 | |
2161 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2162 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2163 | mbm = nla_get_u32(info->attrs[idx]); | |
2164 | } | |
2165 | ||
c8442118 | 2166 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2167 | if (result) |
7f2b8562 | 2168 | return result; |
98d2ff8b JO |
2169 | } |
2170 | ||
afe0cbf8 BR |
2171 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2172 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2173 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2174 | if ((!rdev->wiphy.available_antennas_tx && |
2175 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2176 | !rdev->ops->set_antenna) |
2177 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2178 | |
2179 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2180 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2181 | ||
a7ffac95 | 2182 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2183 | * available antenna masks, except for the "all" mask */ |
2184 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2185 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2186 | return -EINVAL; | |
a7ffac95 | 2187 | |
7f531e03 BR |
2188 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2189 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2190 | |
e35e4d28 | 2191 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2192 | if (result) |
7f2b8562 | 2193 | return result; |
afe0cbf8 BR |
2194 | } |
2195 | ||
b9a5f8ca JM |
2196 | changed = 0; |
2197 | ||
2198 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2199 | retry_short = nla_get_u8( | |
2200 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2201 | if (retry_short == 0) |
2202 | return -EINVAL; | |
2203 | ||
b9a5f8ca JM |
2204 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2205 | } | |
2206 | ||
2207 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2208 | retry_long = nla_get_u8( | |
2209 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2210 | if (retry_long == 0) |
2211 | return -EINVAL; | |
2212 | ||
b9a5f8ca JM |
2213 | changed |= WIPHY_PARAM_RETRY_LONG; |
2214 | } | |
2215 | ||
2216 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2217 | frag_threshold = nla_get_u32( | |
2218 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2219 | if (frag_threshold < 256) |
2220 | return -EINVAL; | |
2221 | ||
b9a5f8ca JM |
2222 | if (frag_threshold != (u32) -1) { |
2223 | /* | |
2224 | * Fragments (apart from the last one) are required to | |
2225 | * have even length. Make the fragmentation code | |
2226 | * simpler by stripping LSB should someone try to use | |
2227 | * odd threshold value. | |
2228 | */ | |
2229 | frag_threshold &= ~0x1; | |
2230 | } | |
2231 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2232 | } | |
2233 | ||
2234 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2235 | rts_threshold = nla_get_u32( | |
2236 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2237 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2238 | } | |
2239 | ||
81077e82 LT |
2240 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
2241 | coverage_class = nla_get_u8( | |
2242 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2243 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2244 | } | |
2245 | ||
b9a5f8ca JM |
2246 | if (changed) { |
2247 | u8 old_retry_short, old_retry_long; | |
2248 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2249 | u8 old_coverage_class; |
b9a5f8ca | 2250 | |
7f2b8562 YX |
2251 | if (!rdev->ops->set_wiphy_params) |
2252 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2253 | |
2254 | old_retry_short = rdev->wiphy.retry_short; | |
2255 | old_retry_long = rdev->wiphy.retry_long; | |
2256 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2257 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2258 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2259 | |
2260 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2261 | rdev->wiphy.retry_short = retry_short; | |
2262 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2263 | rdev->wiphy.retry_long = retry_long; | |
2264 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2265 | rdev->wiphy.frag_threshold = frag_threshold; | |
2266 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2267 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2268 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2269 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2270 | |
e35e4d28 | 2271 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2272 | if (result) { |
2273 | rdev->wiphy.retry_short = old_retry_short; | |
2274 | rdev->wiphy.retry_long = old_retry_long; | |
2275 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2276 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2277 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2278 | } |
2279 | } | |
7f2b8562 | 2280 | return 0; |
55682965 JB |
2281 | } |
2282 | ||
71bbc994 JB |
2283 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2284 | { | |
2285 | return (u64)wdev->identifier | | |
f26cbf40 | 2286 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2287 | } |
55682965 | 2288 | |
683b6d3b | 2289 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2290 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2291 | { |
9f5e8f6e | 2292 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
3d9d1d66 | 2293 | |
683b6d3b JB |
2294 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2295 | chandef->chan->center_freq)) | |
2296 | return -ENOBUFS; | |
3d9d1d66 JB |
2297 | switch (chandef->width) { |
2298 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2299 | case NL80211_CHAN_WIDTH_20: | |
2300 | case NL80211_CHAN_WIDTH_40: | |
2301 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2302 | cfg80211_get_chandef_type(chandef))) | |
2303 | return -ENOBUFS; | |
2304 | break; | |
2305 | default: | |
2306 | break; | |
2307 | } | |
2308 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2309 | return -ENOBUFS; | |
2310 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2311 | return -ENOBUFS; | |
2312 | if (chandef->center_freq2 && | |
2313 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2314 | return -ENOBUFS; |
2315 | return 0; | |
2316 | } | |
2317 | ||
15e47304 | 2318 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2319 | struct cfg80211_registered_device *rdev, |
72fb2abc | 2320 | struct wireless_dev *wdev) |
55682965 | 2321 | { |
72fb2abc | 2322 | struct net_device *dev = wdev->netdev; |
55682965 JB |
2323 | void *hdr; |
2324 | ||
15e47304 | 2325 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
55682965 JB |
2326 | if (!hdr) |
2327 | return -1; | |
2328 | ||
72fb2abc JB |
2329 | if (dev && |
2330 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2331 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2332 | goto nla_put_failure; |
2333 | ||
2334 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2335 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2336 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2337 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2338 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2339 | rdev->devlist_generation ^ | |
2340 | (cfg80211_rdev_list_generation << 2))) | |
2341 | goto nla_put_failure; | |
f5ea9120 | 2342 | |
5b7ccaf3 | 2343 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2344 | int ret; |
2345 | struct cfg80211_chan_def chandef; | |
2346 | ||
2347 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2348 | if (ret == 0) { | |
2349 | if (nl80211_send_chandef(msg, &chandef)) | |
2350 | goto nla_put_failure; | |
2351 | } | |
d91df0e3 PF |
2352 | } |
2353 | ||
b84e7a05 AQ |
2354 | if (wdev->ssid_len) { |
2355 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2356 | goto nla_put_failure; | |
2357 | } | |
2358 | ||
55682965 JB |
2359 | return genlmsg_end(msg, hdr); |
2360 | ||
2361 | nla_put_failure: | |
bc3ed28c TG |
2362 | genlmsg_cancel(msg, hdr); |
2363 | return -EMSGSIZE; | |
55682965 JB |
2364 | } |
2365 | ||
2366 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2367 | { | |
2368 | int wp_idx = 0; | |
2369 | int if_idx = 0; | |
2370 | int wp_start = cb->args[0]; | |
2371 | int if_start = cb->args[1]; | |
f5ea9120 | 2372 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2373 | struct wireless_dev *wdev; |
2374 | ||
5fe231e8 | 2375 | rtnl_lock(); |
f5ea9120 JB |
2376 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2377 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2378 | continue; |
bba95fef JB |
2379 | if (wp_idx < wp_start) { |
2380 | wp_idx++; | |
55682965 | 2381 | continue; |
bba95fef | 2382 | } |
55682965 JB |
2383 | if_idx = 0; |
2384 | ||
89a54e48 | 2385 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2386 | if (if_idx < if_start) { |
2387 | if_idx++; | |
55682965 | 2388 | continue; |
bba95fef | 2389 | } |
15e47304 | 2390 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2391 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
72fb2abc | 2392 | rdev, wdev) < 0) { |
bba95fef JB |
2393 | goto out; |
2394 | } | |
2395 | if_idx++; | |
55682965 | 2396 | } |
bba95fef JB |
2397 | |
2398 | wp_idx++; | |
55682965 | 2399 | } |
bba95fef | 2400 | out: |
5fe231e8 | 2401 | rtnl_unlock(); |
55682965 JB |
2402 | |
2403 | cb->args[0] = wp_idx; | |
2404 | cb->args[1] = if_idx; | |
2405 | ||
2406 | return skb->len; | |
2407 | } | |
2408 | ||
2409 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2410 | { | |
2411 | struct sk_buff *msg; | |
1b8ec87a | 2412 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2413 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2414 | |
fd2120ca | 2415 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2416 | if (!msg) |
4c476991 | 2417 | return -ENOMEM; |
55682965 | 2418 | |
15e47304 | 2419 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1b8ec87a | 2420 | rdev, wdev) < 0) { |
4c476991 JB |
2421 | nlmsg_free(msg); |
2422 | return -ENOBUFS; | |
2423 | } | |
55682965 | 2424 | |
134e6375 | 2425 | return genlmsg_reply(msg, info); |
55682965 JB |
2426 | } |
2427 | ||
66f7ac50 MW |
2428 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2429 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2430 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2431 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2432 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2433 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2434 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2435 | }; |
2436 | ||
2437 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2438 | { | |
2439 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2440 | int flag; | |
2441 | ||
2442 | *mntrflags = 0; | |
2443 | ||
2444 | if (!nla) | |
2445 | return -EINVAL; | |
2446 | ||
2447 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2448 | nla, mntr_flags_policy)) | |
2449 | return -EINVAL; | |
2450 | ||
2451 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2452 | if (flags[flag]) | |
2453 | *mntrflags |= (1<<flag); | |
2454 | ||
2455 | return 0; | |
2456 | } | |
2457 | ||
9bc383de | 2458 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2459 | struct net_device *netdev, u8 use_4addr, |
2460 | enum nl80211_iftype iftype) | |
9bc383de | 2461 | { |
ad4bb6f8 | 2462 | if (!use_4addr) { |
f350a0a8 | 2463 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2464 | return -EBUSY; |
9bc383de | 2465 | return 0; |
ad4bb6f8 | 2466 | } |
9bc383de JB |
2467 | |
2468 | switch (iftype) { | |
2469 | case NL80211_IFTYPE_AP_VLAN: | |
2470 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2471 | return 0; | |
2472 | break; | |
2473 | case NL80211_IFTYPE_STATION: | |
2474 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2475 | return 0; | |
2476 | break; | |
2477 | default: | |
2478 | break; | |
2479 | } | |
2480 | ||
2481 | return -EOPNOTSUPP; | |
2482 | } | |
2483 | ||
55682965 JB |
2484 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2485 | { | |
4c476991 | 2486 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2487 | struct vif_params params; |
e36d56b6 | 2488 | int err; |
04a773ad | 2489 | enum nl80211_iftype otype, ntype; |
4c476991 | 2490 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2491 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2492 | bool change = false; |
55682965 | 2493 | |
2ec600d6 LCC |
2494 | memset(¶ms, 0, sizeof(params)); |
2495 | ||
04a773ad | 2496 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2497 | |
723b038d | 2498 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2499 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2500 | if (otype != ntype) |
ac7f9cfa | 2501 | change = true; |
4c476991 JB |
2502 | if (ntype > NL80211_IFTYPE_MAX) |
2503 | return -EINVAL; | |
723b038d JB |
2504 | } |
2505 | ||
92ffe055 | 2506 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2507 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2508 | ||
4c476991 JB |
2509 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2510 | return -EINVAL; | |
29cbe68c JB |
2511 | if (netif_running(dev)) |
2512 | return -EBUSY; | |
2513 | ||
2514 | wdev_lock(wdev); | |
2515 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2516 | IEEE80211_MAX_MESH_ID_LEN); | |
2517 | wdev->mesh_id_up_len = | |
2518 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2519 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2520 | wdev->mesh_id_up_len); | |
2521 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2522 | } |
2523 | ||
8b787643 FF |
2524 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2525 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2526 | change = true; | |
ad4bb6f8 | 2527 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2528 | if (err) |
4c476991 | 2529 | return err; |
8b787643 FF |
2530 | } else { |
2531 | params.use_4addr = -1; | |
2532 | } | |
2533 | ||
92ffe055 | 2534 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2535 | if (ntype != NL80211_IFTYPE_MONITOR) |
2536 | return -EINVAL; | |
92ffe055 JB |
2537 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2538 | &_flags); | |
ac7f9cfa | 2539 | if (err) |
4c476991 | 2540 | return err; |
ac7f9cfa JB |
2541 | |
2542 | flags = &_flags; | |
2543 | change = true; | |
92ffe055 | 2544 | } |
3b85875a | 2545 | |
18003297 | 2546 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2547 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2548 | return -EOPNOTSUPP; | |
2549 | ||
ac7f9cfa | 2550 | if (change) |
3d54d255 | 2551 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2552 | else |
2553 | err = 0; | |
60719ffd | 2554 | |
9bc383de JB |
2555 | if (!err && params.use_4addr != -1) |
2556 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2557 | ||
55682965 JB |
2558 | return err; |
2559 | } | |
2560 | ||
2561 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2562 | { | |
4c476991 | 2563 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2564 | struct vif_params params; |
84efbb84 | 2565 | struct wireless_dev *wdev; |
1c90f9d4 | 2566 | struct sk_buff *msg; |
55682965 JB |
2567 | int err; |
2568 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2569 | u32 flags; |
55682965 | 2570 | |
78f22b6a JB |
2571 | /* to avoid failing a new interface creation due to pending removal */ |
2572 | cfg80211_destroy_ifaces(rdev); | |
2573 | ||
2ec600d6 LCC |
2574 | memset(¶ms, 0, sizeof(params)); |
2575 | ||
55682965 JB |
2576 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2577 | return -EINVAL; | |
2578 | ||
2579 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2580 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2581 | if (type > NL80211_IFTYPE_MAX) | |
2582 | return -EINVAL; | |
2583 | } | |
2584 | ||
79c97e97 | 2585 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2586 | !(rdev->wiphy.interface_modes & (1 << type))) |
2587 | return -EOPNOTSUPP; | |
55682965 | 2588 | |
1c18f145 AS |
2589 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
2590 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], | |
2591 | ETH_ALEN); | |
2592 | if (!is_valid_ether_addr(params.macaddr)) | |
2593 | return -EADDRNOTAVAIL; | |
2594 | } | |
2595 | ||
9bc383de | 2596 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2597 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2598 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2599 | if (err) |
4c476991 | 2600 | return err; |
9bc383de | 2601 | } |
8b787643 | 2602 | |
1c90f9d4 JB |
2603 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2604 | if (!msg) | |
2605 | return -ENOMEM; | |
2606 | ||
66f7ac50 MW |
2607 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2608 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2609 | &flags); | |
e057d3c3 | 2610 | |
18003297 | 2611 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2612 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2613 | return -EOPNOTSUPP; | |
2614 | ||
e35e4d28 HG |
2615 | wdev = rdev_add_virtual_intf(rdev, |
2616 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2617 | type, err ? NULL : &flags, ¶ms); | |
1c90f9d4 JB |
2618 | if (IS_ERR(wdev)) { |
2619 | nlmsg_free(msg); | |
84efbb84 | 2620 | return PTR_ERR(wdev); |
1c90f9d4 | 2621 | } |
2ec600d6 | 2622 | |
78f22b6a JB |
2623 | if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER]) |
2624 | wdev->owner_nlportid = info->snd_portid; | |
2625 | ||
98104fde JB |
2626 | switch (type) { |
2627 | case NL80211_IFTYPE_MESH_POINT: | |
2628 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2629 | break; | |
29cbe68c JB |
2630 | wdev_lock(wdev); |
2631 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2632 | IEEE80211_MAX_MESH_ID_LEN); | |
2633 | wdev->mesh_id_up_len = | |
2634 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2635 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2636 | wdev->mesh_id_up_len); | |
2637 | wdev_unlock(wdev); | |
98104fde JB |
2638 | break; |
2639 | case NL80211_IFTYPE_P2P_DEVICE: | |
2640 | /* | |
2641 | * P2P Device doesn't have a netdev, so doesn't go | |
2642 | * through the netdev notifier and must be added here | |
2643 | */ | |
2644 | mutex_init(&wdev->mtx); | |
2645 | INIT_LIST_HEAD(&wdev->event_list); | |
2646 | spin_lock_init(&wdev->event_lock); | |
2647 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2648 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2649 | ||
98104fde JB |
2650 | wdev->identifier = ++rdev->wdev_id; |
2651 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2652 | rdev->devlist_generation++; | |
98104fde JB |
2653 | break; |
2654 | default: | |
2655 | break; | |
29cbe68c JB |
2656 | } |
2657 | ||
15e47304 | 2658 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1c90f9d4 JB |
2659 | rdev, wdev) < 0) { |
2660 | nlmsg_free(msg); | |
2661 | return -ENOBUFS; | |
2662 | } | |
2663 | ||
2664 | return genlmsg_reply(msg, info); | |
55682965 JB |
2665 | } |
2666 | ||
2667 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2668 | { | |
4c476991 | 2669 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2670 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2671 | |
4c476991 JB |
2672 | if (!rdev->ops->del_virtual_intf) |
2673 | return -EOPNOTSUPP; | |
55682965 | 2674 | |
84efbb84 JB |
2675 | /* |
2676 | * If we remove a wireless device without a netdev then clear | |
2677 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2678 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2679 | * since the wdev has been freed, unlike with a netdev where | |
2680 | * we need the dev_put() for the netdev to really be freed. | |
2681 | */ | |
2682 | if (!wdev->netdev) | |
2683 | info->user_ptr[1] = NULL; | |
2684 | ||
e35e4d28 | 2685 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2686 | } |
2687 | ||
1d9d9213 SW |
2688 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2689 | { | |
2690 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2691 | struct net_device *dev = info->user_ptr[1]; | |
2692 | u16 noack_map; | |
2693 | ||
2694 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2695 | return -EINVAL; | |
2696 | ||
2697 | if (!rdev->ops->set_noack_map) | |
2698 | return -EOPNOTSUPP; | |
2699 | ||
2700 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2701 | ||
e35e4d28 | 2702 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2703 | } |
2704 | ||
41ade00f JB |
2705 | struct get_key_cookie { |
2706 | struct sk_buff *msg; | |
2707 | int error; | |
b9454e83 | 2708 | int idx; |
41ade00f JB |
2709 | }; |
2710 | ||
2711 | static void get_key_callback(void *c, struct key_params *params) | |
2712 | { | |
b9454e83 | 2713 | struct nlattr *key; |
41ade00f JB |
2714 | struct get_key_cookie *cookie = c; |
2715 | ||
9360ffd1 DM |
2716 | if ((params->key && |
2717 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2718 | params->key_len, params->key)) || | |
2719 | (params->seq && | |
2720 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2721 | params->seq_len, params->seq)) || | |
2722 | (params->cipher && | |
2723 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2724 | params->cipher))) | |
2725 | goto nla_put_failure; | |
41ade00f | 2726 | |
b9454e83 JB |
2727 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2728 | if (!key) | |
2729 | goto nla_put_failure; | |
2730 | ||
9360ffd1 DM |
2731 | if ((params->key && |
2732 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2733 | params->key_len, params->key)) || | |
2734 | (params->seq && | |
2735 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2736 | params->seq_len, params->seq)) || | |
2737 | (params->cipher && | |
2738 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2739 | params->cipher))) | |
2740 | goto nla_put_failure; | |
b9454e83 | 2741 | |
9360ffd1 DM |
2742 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2743 | goto nla_put_failure; | |
b9454e83 JB |
2744 | |
2745 | nla_nest_end(cookie->msg, key); | |
2746 | ||
41ade00f JB |
2747 | return; |
2748 | nla_put_failure: | |
2749 | cookie->error = 1; | |
2750 | } | |
2751 | ||
2752 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2753 | { | |
4c476991 | 2754 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2755 | int err; |
4c476991 | 2756 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2757 | u8 key_idx = 0; |
e31b8213 JB |
2758 | const u8 *mac_addr = NULL; |
2759 | bool pairwise; | |
41ade00f JB |
2760 | struct get_key_cookie cookie = { |
2761 | .error = 0, | |
2762 | }; | |
2763 | void *hdr; | |
2764 | struct sk_buff *msg; | |
2765 | ||
2766 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2767 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2768 | ||
3cfcf6ac | 2769 | if (key_idx > 5) |
41ade00f JB |
2770 | return -EINVAL; |
2771 | ||
2772 | if (info->attrs[NL80211_ATTR_MAC]) | |
2773 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2774 | ||
e31b8213 JB |
2775 | pairwise = !!mac_addr; |
2776 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2777 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2778 | if (kt >= NUM_NL80211_KEYTYPES) | |
2779 | return -EINVAL; | |
2780 | if (kt != NL80211_KEYTYPE_GROUP && | |
2781 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2782 | return -EINVAL; | |
2783 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2784 | } | |
2785 | ||
4c476991 JB |
2786 | if (!rdev->ops->get_key) |
2787 | return -EOPNOTSUPP; | |
41ade00f | 2788 | |
fd2120ca | 2789 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2790 | if (!msg) |
2791 | return -ENOMEM; | |
41ade00f | 2792 | |
15e47304 | 2793 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2794 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 2795 | if (!hdr) |
9fe271af | 2796 | goto nla_put_failure; |
41ade00f JB |
2797 | |
2798 | cookie.msg = msg; | |
b9454e83 | 2799 | cookie.idx = key_idx; |
41ade00f | 2800 | |
9360ffd1 DM |
2801 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2802 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2803 | goto nla_put_failure; | |
2804 | if (mac_addr && | |
2805 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2806 | goto nla_put_failure; | |
41ade00f | 2807 | |
e31b8213 JB |
2808 | if (pairwise && mac_addr && |
2809 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2810 | return -ENOENT; | |
2811 | ||
e35e4d28 HG |
2812 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2813 | get_key_callback); | |
41ade00f JB |
2814 | |
2815 | if (err) | |
6c95e2a2 | 2816 | goto free_msg; |
41ade00f JB |
2817 | |
2818 | if (cookie.error) | |
2819 | goto nla_put_failure; | |
2820 | ||
2821 | genlmsg_end(msg, hdr); | |
4c476991 | 2822 | return genlmsg_reply(msg, info); |
41ade00f JB |
2823 | |
2824 | nla_put_failure: | |
2825 | err = -ENOBUFS; | |
6c95e2a2 | 2826 | free_msg: |
41ade00f | 2827 | nlmsg_free(msg); |
41ade00f JB |
2828 | return err; |
2829 | } | |
2830 | ||
2831 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2832 | { | |
4c476991 | 2833 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2834 | struct key_parse key; |
41ade00f | 2835 | int err; |
4c476991 | 2836 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2837 | |
b9454e83 JB |
2838 | err = nl80211_parse_key(info, &key); |
2839 | if (err) | |
2840 | return err; | |
41ade00f | 2841 | |
b9454e83 | 2842 | if (key.idx < 0) |
41ade00f JB |
2843 | return -EINVAL; |
2844 | ||
b9454e83 JB |
2845 | /* only support setting default key */ |
2846 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2847 | return -EINVAL; |
2848 | ||
dbd2fd65 | 2849 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2850 | |
dbd2fd65 JB |
2851 | if (key.def) { |
2852 | if (!rdev->ops->set_default_key) { | |
2853 | err = -EOPNOTSUPP; | |
2854 | goto out; | |
2855 | } | |
41ade00f | 2856 | |
dbd2fd65 JB |
2857 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2858 | if (err) | |
2859 | goto out; | |
2860 | ||
e35e4d28 | 2861 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2862 | key.def_uni, key.def_multi); |
2863 | ||
2864 | if (err) | |
2865 | goto out; | |
fffd0934 | 2866 | |
3d23e349 | 2867 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2868 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2869 | #endif | |
2870 | } else { | |
2871 | if (key.def_uni || !key.def_multi) { | |
2872 | err = -EINVAL; | |
2873 | goto out; | |
2874 | } | |
2875 | ||
2876 | if (!rdev->ops->set_default_mgmt_key) { | |
2877 | err = -EOPNOTSUPP; | |
2878 | goto out; | |
2879 | } | |
2880 | ||
2881 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2882 | if (err) | |
2883 | goto out; | |
2884 | ||
e35e4d28 | 2885 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2886 | if (err) |
2887 | goto out; | |
2888 | ||
2889 | #ifdef CONFIG_CFG80211_WEXT | |
2890 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2891 | #endif |
dbd2fd65 JB |
2892 | } |
2893 | ||
2894 | out: | |
fffd0934 | 2895 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2896 | |
41ade00f JB |
2897 | return err; |
2898 | } | |
2899 | ||
2900 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2901 | { | |
4c476991 | 2902 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2903 | int err; |
4c476991 | 2904 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2905 | struct key_parse key; |
e31b8213 | 2906 | const u8 *mac_addr = NULL; |
41ade00f | 2907 | |
b9454e83 JB |
2908 | err = nl80211_parse_key(info, &key); |
2909 | if (err) | |
2910 | return err; | |
41ade00f | 2911 | |
b9454e83 | 2912 | if (!key.p.key) |
41ade00f JB |
2913 | return -EINVAL; |
2914 | ||
41ade00f JB |
2915 | if (info->attrs[NL80211_ATTR_MAC]) |
2916 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2917 | ||
e31b8213 JB |
2918 | if (key.type == -1) { |
2919 | if (mac_addr) | |
2920 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2921 | else | |
2922 | key.type = NL80211_KEYTYPE_GROUP; | |
2923 | } | |
2924 | ||
2925 | /* for now */ | |
2926 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2927 | key.type != NL80211_KEYTYPE_GROUP) | |
2928 | return -EINVAL; | |
2929 | ||
4c476991 JB |
2930 | if (!rdev->ops->add_key) |
2931 | return -EOPNOTSUPP; | |
25e47c18 | 2932 | |
e31b8213 JB |
2933 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2934 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2935 | mac_addr)) | |
4c476991 | 2936 | return -EINVAL; |
41ade00f | 2937 | |
fffd0934 JB |
2938 | wdev_lock(dev->ieee80211_ptr); |
2939 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2940 | if (!err) | |
e35e4d28 HG |
2941 | err = rdev_add_key(rdev, dev, key.idx, |
2942 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2943 | mac_addr, &key.p); | |
fffd0934 | 2944 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2945 | |
41ade00f JB |
2946 | return err; |
2947 | } | |
2948 | ||
2949 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2950 | { | |
4c476991 | 2951 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2952 | int err; |
4c476991 | 2953 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2954 | u8 *mac_addr = NULL; |
b9454e83 | 2955 | struct key_parse key; |
41ade00f | 2956 | |
b9454e83 JB |
2957 | err = nl80211_parse_key(info, &key); |
2958 | if (err) | |
2959 | return err; | |
41ade00f JB |
2960 | |
2961 | if (info->attrs[NL80211_ATTR_MAC]) | |
2962 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2963 | ||
e31b8213 JB |
2964 | if (key.type == -1) { |
2965 | if (mac_addr) | |
2966 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2967 | else | |
2968 | key.type = NL80211_KEYTYPE_GROUP; | |
2969 | } | |
2970 | ||
2971 | /* for now */ | |
2972 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2973 | key.type != NL80211_KEYTYPE_GROUP) | |
2974 | return -EINVAL; | |
2975 | ||
4c476991 JB |
2976 | if (!rdev->ops->del_key) |
2977 | return -EOPNOTSUPP; | |
41ade00f | 2978 | |
fffd0934 JB |
2979 | wdev_lock(dev->ieee80211_ptr); |
2980 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
2981 | |
2982 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
2983 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2984 | err = -ENOENT; | |
2985 | ||
fffd0934 | 2986 | if (!err) |
e35e4d28 HG |
2987 | err = rdev_del_key(rdev, dev, key.idx, |
2988 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2989 | mac_addr); | |
41ade00f | 2990 | |
3d23e349 | 2991 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 2992 | if (!err) { |
b9454e83 | 2993 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 2994 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 2995 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
2996 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
2997 | } | |
2998 | #endif | |
fffd0934 | 2999 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 3000 | |
41ade00f JB |
3001 | return err; |
3002 | } | |
3003 | ||
77765eaf VT |
3004 | /* This function returns an error or the number of nested attributes */ |
3005 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
3006 | { | |
3007 | struct nlattr *attr; | |
3008 | int n_entries = 0, tmp; | |
3009 | ||
3010 | nla_for_each_nested(attr, nl_attr, tmp) { | |
3011 | if (nla_len(attr) != ETH_ALEN) | |
3012 | return -EINVAL; | |
3013 | ||
3014 | n_entries++; | |
3015 | } | |
3016 | ||
3017 | return n_entries; | |
3018 | } | |
3019 | ||
3020 | /* | |
3021 | * This function parses ACL information and allocates memory for ACL data. | |
3022 | * On successful return, the calling function is responsible to free the | |
3023 | * ACL buffer returned by this function. | |
3024 | */ | |
3025 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3026 | struct genl_info *info) | |
3027 | { | |
3028 | enum nl80211_acl_policy acl_policy; | |
3029 | struct nlattr *attr; | |
3030 | struct cfg80211_acl_data *acl; | |
3031 | int i = 0, n_entries, tmp; | |
3032 | ||
3033 | if (!wiphy->max_acl_mac_addrs) | |
3034 | return ERR_PTR(-EOPNOTSUPP); | |
3035 | ||
3036 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3037 | return ERR_PTR(-EINVAL); | |
3038 | ||
3039 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3040 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3041 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3042 | return ERR_PTR(-EINVAL); | |
3043 | ||
3044 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3045 | return ERR_PTR(-EINVAL); | |
3046 | ||
3047 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3048 | if (n_entries < 0) | |
3049 | return ERR_PTR(n_entries); | |
3050 | ||
3051 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3052 | return ERR_PTR(-ENOTSUPP); | |
3053 | ||
3054 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
3055 | GFP_KERNEL); | |
3056 | if (!acl) | |
3057 | return ERR_PTR(-ENOMEM); | |
3058 | ||
3059 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3060 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3061 | i++; | |
3062 | } | |
3063 | ||
3064 | acl->n_acl_entries = n_entries; | |
3065 | acl->acl_policy = acl_policy; | |
3066 | ||
3067 | return acl; | |
3068 | } | |
3069 | ||
3070 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3071 | { | |
3072 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3073 | struct net_device *dev = info->user_ptr[1]; | |
3074 | struct cfg80211_acl_data *acl; | |
3075 | int err; | |
3076 | ||
3077 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3078 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3079 | return -EOPNOTSUPP; | |
3080 | ||
3081 | if (!dev->ieee80211_ptr->beacon_interval) | |
3082 | return -EINVAL; | |
3083 | ||
3084 | acl = parse_acl_data(&rdev->wiphy, info); | |
3085 | if (IS_ERR(acl)) | |
3086 | return PTR_ERR(acl); | |
3087 | ||
3088 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3089 | ||
3090 | kfree(acl); | |
3091 | ||
3092 | return err; | |
3093 | } | |
3094 | ||
a1193be8 | 3095 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3096 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3097 | { |
8860020e | 3098 | bool haveinfo = false; |
ed1b6cc7 | 3099 | |
a1193be8 SW |
3100 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3101 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3102 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3103 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3104 | return -EINVAL; |
3105 | ||
8860020e | 3106 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3107 | |
a1193be8 SW |
3108 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3109 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3110 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3111 | if (!bcn->head_len) |
3112 | return -EINVAL; | |
3113 | haveinfo = true; | |
ed1b6cc7 JB |
3114 | } |
3115 | ||
a1193be8 SW |
3116 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3117 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3118 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3119 | haveinfo = true; |
ed1b6cc7 JB |
3120 | } |
3121 | ||
4c476991 JB |
3122 | if (!haveinfo) |
3123 | return -EINVAL; | |
3b85875a | 3124 | |
a1193be8 SW |
3125 | if (attrs[NL80211_ATTR_IE]) { |
3126 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3127 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3128 | } |
3129 | ||
a1193be8 | 3130 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3131 | bcn->proberesp_ies = |
a1193be8 | 3132 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3133 | bcn->proberesp_ies_len = |
a1193be8 | 3134 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3135 | } |
3136 | ||
a1193be8 | 3137 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3138 | bcn->assocresp_ies = |
a1193be8 | 3139 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3140 | bcn->assocresp_ies_len = |
a1193be8 | 3141 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3142 | } |
3143 | ||
a1193be8 SW |
3144 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3145 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3146 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3147 | } |
3148 | ||
8860020e JB |
3149 | return 0; |
3150 | } | |
3151 | ||
46c1dd0c FF |
3152 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3153 | struct cfg80211_ap_settings *params) | |
3154 | { | |
3155 | struct wireless_dev *wdev; | |
3156 | bool ret = false; | |
3157 | ||
89a54e48 | 3158 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3159 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3160 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3161 | continue; | |
3162 | ||
683b6d3b | 3163 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3164 | continue; |
3165 | ||
683b6d3b | 3166 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3167 | ret = true; |
3168 | break; | |
3169 | } | |
3170 | ||
46c1dd0c FF |
3171 | return ret; |
3172 | } | |
3173 | ||
e39e5b5e JM |
3174 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3175 | enum nl80211_auth_type auth_type, | |
3176 | enum nl80211_commands cmd) | |
3177 | { | |
3178 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3179 | return false; | |
3180 | ||
3181 | switch (cmd) { | |
3182 | case NL80211_CMD_AUTHENTICATE: | |
3183 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3184 | auth_type == NL80211_AUTHTYPE_SAE) | |
3185 | return false; | |
3186 | return true; | |
3187 | case NL80211_CMD_CONNECT: | |
3188 | case NL80211_CMD_START_AP: | |
3189 | /* SAE not supported yet */ | |
3190 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3191 | return false; | |
3192 | return true; | |
3193 | default: | |
3194 | return false; | |
3195 | } | |
3196 | } | |
3197 | ||
8860020e JB |
3198 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3199 | { | |
3200 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3201 | struct net_device *dev = info->user_ptr[1]; | |
3202 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3203 | struct cfg80211_ap_settings params; | |
3204 | int err; | |
3205 | ||
3206 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3207 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3208 | return -EOPNOTSUPP; | |
3209 | ||
3210 | if (!rdev->ops->start_ap) | |
3211 | return -EOPNOTSUPP; | |
3212 | ||
3213 | if (wdev->beacon_interval) | |
3214 | return -EALREADY; | |
3215 | ||
3216 | memset(¶ms, 0, sizeof(params)); | |
3217 | ||
3218 | /* these are required for START_AP */ | |
3219 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3220 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3221 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3222 | return -EINVAL; | |
3223 | ||
a1193be8 | 3224 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3225 | if (err) |
3226 | return err; | |
3227 | ||
3228 | params.beacon_interval = | |
3229 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3230 | params.dtim_period = | |
3231 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3232 | ||
3233 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3234 | if (err) | |
3235 | return err; | |
3236 | ||
3237 | /* | |
3238 | * In theory, some of these attributes should be required here | |
3239 | * but since they were not used when the command was originally | |
3240 | * added, keep them optional for old user space programs to let | |
3241 | * them continue to work with drivers that do not need the | |
3242 | * additional information -- drivers must check! | |
3243 | */ | |
3244 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3245 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3246 | params.ssid_len = | |
3247 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3248 | if (params.ssid_len == 0 || | |
3249 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3250 | return -EINVAL; | |
3251 | } | |
3252 | ||
3253 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3254 | params.hidden_ssid = nla_get_u32( | |
3255 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3256 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3257 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3258 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3259 | return -EINVAL; | |
3260 | } | |
3261 | ||
3262 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3263 | ||
3264 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3265 | params.auth_type = nla_get_u32( | |
3266 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3267 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3268 | NL80211_CMD_START_AP)) | |
8860020e JB |
3269 | return -EINVAL; |
3270 | } else | |
3271 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3272 | ||
3273 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3274 | NL80211_MAX_NR_CIPHER_SUITES); | |
3275 | if (err) | |
3276 | return err; | |
3277 | ||
1b658f11 VT |
3278 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3279 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3280 | return -EOPNOTSUPP; | |
3281 | params.inactivity_timeout = nla_get_u16( | |
3282 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3283 | } | |
3284 | ||
53cabad7 JB |
3285 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3286 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3287 | return -EINVAL; | |
3288 | params.p2p_ctwindow = | |
3289 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3290 | if (params.p2p_ctwindow > 127) | |
3291 | return -EINVAL; | |
3292 | if (params.p2p_ctwindow != 0 && | |
3293 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3294 | return -EINVAL; | |
3295 | } | |
3296 | ||
3297 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3298 | u8 tmp; | |
3299 | ||
3300 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3301 | return -EINVAL; | |
3302 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3303 | if (tmp > 1) | |
3304 | return -EINVAL; | |
3305 | params.p2p_opp_ps = tmp; | |
3306 | if (params.p2p_opp_ps != 0 && | |
3307 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3308 | return -EINVAL; | |
3309 | } | |
3310 | ||
aa430da4 | 3311 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3312 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3313 | if (err) | |
3314 | return err; | |
3315 | } else if (wdev->preset_chandef.chan) { | |
3316 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3317 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3318 | return -EINVAL; |
3319 | ||
174e0cd2 IP |
3320 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
3321 | wdev->iftype)) | |
aa430da4 JB |
3322 | return -EINVAL; |
3323 | ||
77765eaf VT |
3324 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3325 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3326 | if (IS_ERR(params.acl)) | |
3327 | return PTR_ERR(params.acl); | |
3328 | } | |
3329 | ||
c56589ed | 3330 | wdev_lock(wdev); |
e35e4d28 | 3331 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3332 | if (!err) { |
683b6d3b | 3333 | wdev->preset_chandef = params.chandef; |
8860020e | 3334 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 3335 | wdev->chandef = params.chandef; |
06e191e2 AQ |
3336 | wdev->ssid_len = params.ssid_len; |
3337 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3338 | } |
c56589ed | 3339 | wdev_unlock(wdev); |
77765eaf VT |
3340 | |
3341 | kfree(params.acl); | |
3342 | ||
56d1893d | 3343 | return err; |
ed1b6cc7 JB |
3344 | } |
3345 | ||
8860020e JB |
3346 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3347 | { | |
3348 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3349 | struct net_device *dev = info->user_ptr[1]; | |
3350 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3351 | struct cfg80211_beacon_data params; | |
3352 | int err; | |
3353 | ||
3354 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3355 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3356 | return -EOPNOTSUPP; | |
3357 | ||
3358 | if (!rdev->ops->change_beacon) | |
3359 | return -EOPNOTSUPP; | |
3360 | ||
3361 | if (!wdev->beacon_interval) | |
3362 | return -EINVAL; | |
3363 | ||
a1193be8 | 3364 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3365 | if (err) |
3366 | return err; | |
3367 | ||
c56589ed SW |
3368 | wdev_lock(wdev); |
3369 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3370 | wdev_unlock(wdev); | |
3371 | ||
3372 | return err; | |
8860020e JB |
3373 | } |
3374 | ||
3375 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3376 | { |
4c476991 JB |
3377 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3378 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3379 | |
7c8d5e03 | 3380 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
3381 | } |
3382 | ||
5727ef1b JB |
3383 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3384 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3385 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3386 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3387 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3388 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3389 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3390 | }; |
3391 | ||
eccb8e8f | 3392 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3393 | enum nl80211_iftype iftype, |
eccb8e8f | 3394 | struct station_parameters *params) |
5727ef1b JB |
3395 | { |
3396 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3397 | struct nlattr *nla; |
5727ef1b JB |
3398 | int flag; |
3399 | ||
eccb8e8f JB |
3400 | /* |
3401 | * Try parsing the new attribute first so userspace | |
3402 | * can specify both for older kernels. | |
3403 | */ | |
3404 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3405 | if (nla) { | |
3406 | struct nl80211_sta_flag_update *sta_flags; | |
3407 | ||
3408 | sta_flags = nla_data(nla); | |
3409 | params->sta_flags_mask = sta_flags->mask; | |
3410 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3411 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3412 | if ((params->sta_flags_mask | |
3413 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3414 | return -EINVAL; | |
3415 | return 0; | |
3416 | } | |
3417 | ||
3418 | /* if present, parse the old attribute */ | |
5727ef1b | 3419 | |
eccb8e8f | 3420 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3421 | if (!nla) |
3422 | return 0; | |
3423 | ||
3424 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3425 | nla, sta_flags_policy)) | |
3426 | return -EINVAL; | |
3427 | ||
bdd3ae3d JB |
3428 | /* |
3429 | * Only allow certain flags for interface types so that | |
3430 | * other attributes are silently ignored. Remember that | |
3431 | * this is backward compatibility code with old userspace | |
3432 | * and shouldn't be hit in other cases anyway. | |
3433 | */ | |
3434 | switch (iftype) { | |
3435 | case NL80211_IFTYPE_AP: | |
3436 | case NL80211_IFTYPE_AP_VLAN: | |
3437 | case NL80211_IFTYPE_P2P_GO: | |
3438 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3439 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3440 | BIT(NL80211_STA_FLAG_WME) | | |
3441 | BIT(NL80211_STA_FLAG_MFP); | |
3442 | break; | |
3443 | case NL80211_IFTYPE_P2P_CLIENT: | |
3444 | case NL80211_IFTYPE_STATION: | |
3445 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3446 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3447 | break; | |
3448 | case NL80211_IFTYPE_MESH_POINT: | |
3449 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3450 | BIT(NL80211_STA_FLAG_MFP) | | |
3451 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3452 | default: | |
3453 | return -EINVAL; | |
3454 | } | |
5727ef1b | 3455 | |
3383b5a6 JB |
3456 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3457 | if (flags[flag]) { | |
eccb8e8f | 3458 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3459 | |
3383b5a6 JB |
3460 | /* no longer support new API additions in old API */ |
3461 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3462 | return -EINVAL; | |
3463 | } | |
3464 | } | |
3465 | ||
5727ef1b JB |
3466 | return 0; |
3467 | } | |
3468 | ||
c8dcfd8a FF |
3469 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3470 | int attr) | |
3471 | { | |
3472 | struct nlattr *rate; | |
8eb41c8d VK |
3473 | u32 bitrate; |
3474 | u16 bitrate_compat; | |
c8dcfd8a FF |
3475 | |
3476 | rate = nla_nest_start(msg, attr); | |
3477 | if (!rate) | |
db9c64cf | 3478 | return false; |
c8dcfd8a FF |
3479 | |
3480 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3481 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3482 | /* report 16-bit bitrate only if we can */ |
3483 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3484 | if (bitrate > 0 && |
3485 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3486 | return false; | |
3487 | if (bitrate_compat > 0 && | |
3488 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3489 | return false; | |
3490 | ||
3491 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3492 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3493 | return false; | |
3494 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3495 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3496 | return false; | |
3497 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3498 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3499 | return false; | |
3500 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3501 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3502 | return false; | |
3503 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3504 | return false; | |
3505 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3506 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3507 | return false; | |
3508 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3509 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3510 | return false; | |
3511 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3512 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3513 | return false; | |
3514 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3515 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3516 | return false; | |
3517 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3518 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3519 | return false; | |
3520 | } | |
c8dcfd8a FF |
3521 | |
3522 | nla_nest_end(msg, rate); | |
3523 | return true; | |
c8dcfd8a FF |
3524 | } |
3525 | ||
119363c7 FF |
3526 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3527 | int id) | |
3528 | { | |
3529 | void *attr; | |
3530 | int i = 0; | |
3531 | ||
3532 | if (!mask) | |
3533 | return true; | |
3534 | ||
3535 | attr = nla_nest_start(msg, id); | |
3536 | if (!attr) | |
3537 | return false; | |
3538 | ||
3539 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3540 | if (!(mask & BIT(i))) | |
3541 | continue; | |
3542 | ||
3543 | if (nla_put_u8(msg, i, signal[i])) | |
3544 | return false; | |
3545 | } | |
3546 | ||
3547 | nla_nest_end(msg, attr); | |
3548 | ||
3549 | return true; | |
3550 | } | |
3551 | ||
15e47304 | 3552 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3553 | int flags, |
3554 | struct cfg80211_registered_device *rdev, | |
3555 | struct net_device *dev, | |
98b62183 | 3556 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3557 | { |
3558 | void *hdr; | |
f4263c98 | 3559 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3560 | |
15e47304 | 3561 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3562 | if (!hdr) |
3563 | return -1; | |
3564 | ||
9360ffd1 DM |
3565 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3566 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3567 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3568 | goto nla_put_failure; | |
f5ea9120 | 3569 | |
2ec600d6 LCC |
3570 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3571 | if (!sinfoattr) | |
fd5b74dc | 3572 | goto nla_put_failure; |
9360ffd1 DM |
3573 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3574 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3575 | sinfo->connected_time)) | |
3576 | goto nla_put_failure; | |
3577 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3578 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3579 | sinfo->inactive_time)) | |
3580 | goto nla_put_failure; | |
42745e03 VK |
3581 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3582 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3583 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3584 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3585 | goto nla_put_failure; |
42745e03 | 3586 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
4325d724 | 3587 | STATION_INFO_TX_BYTES64)) && |
9360ffd1 | 3588 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3589 | (u32)sinfo->tx_bytes)) |
3590 | goto nla_put_failure; | |
3591 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3592 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3593 | sinfo->rx_bytes)) | |
3594 | goto nla_put_failure; | |
3595 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3596 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3597 | sinfo->tx_bytes)) |
3598 | goto nla_put_failure; | |
3599 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3600 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3601 | goto nla_put_failure; | |
3602 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3603 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3604 | goto nla_put_failure; | |
3605 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3606 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3607 | sinfo->plink_state)) | |
3608 | goto nla_put_failure; | |
66266b3a JL |
3609 | switch (rdev->wiphy.signal_type) { |
3610 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3611 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3612 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3613 | sinfo->signal)) | |
3614 | goto nla_put_failure; | |
3615 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3616 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3617 | sinfo->signal_avg)) | |
3618 | goto nla_put_failure; | |
66266b3a JL |
3619 | break; |
3620 | default: | |
3621 | break; | |
3622 | } | |
119363c7 FF |
3623 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
3624 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3625 | sinfo->chain_signal, | |
3626 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3627 | goto nla_put_failure; | |
3628 | } | |
3629 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { | |
3630 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3631 | sinfo->chain_signal_avg, | |
3632 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3633 | goto nla_put_failure; | |
3634 | } | |
420e7fab | 3635 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3636 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3637 | NL80211_STA_INFO_TX_BITRATE)) | |
3638 | goto nla_put_failure; | |
3639 | } | |
3640 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3641 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3642 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3643 | goto nla_put_failure; |
420e7fab | 3644 | } |
9360ffd1 DM |
3645 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3646 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3647 | sinfo->rx_packets)) | |
3648 | goto nla_put_failure; | |
3649 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3650 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3651 | sinfo->tx_packets)) | |
3652 | goto nla_put_failure; | |
3653 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3654 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3655 | sinfo->tx_retries)) | |
3656 | goto nla_put_failure; | |
3657 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3658 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3659 | sinfo->tx_failed)) | |
3660 | goto nla_put_failure; | |
867d849f AQ |
3661 | if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) && |
3662 | nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT, | |
3663 | sinfo->expected_throughput)) | |
3664 | goto nla_put_failure; | |
9360ffd1 DM |
3665 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
3666 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3667 | sinfo->beacon_loss_count)) | |
3668 | goto nla_put_failure; | |
3b1c5a53 MP |
3669 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3670 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3671 | sinfo->local_pm)) | |
3672 | goto nla_put_failure; | |
3673 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3674 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3675 | sinfo->peer_pm)) | |
3676 | goto nla_put_failure; | |
3677 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3678 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3679 | sinfo->nonpeer_pm)) | |
3680 | goto nla_put_failure; | |
f4263c98 PS |
3681 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3682 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3683 | if (!bss_param) | |
3684 | goto nla_put_failure; | |
3685 | ||
9360ffd1 DM |
3686 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3687 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3688 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3689 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3690 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3691 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3692 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3693 | sinfo->bss_param.dtim_period) || | |
3694 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3695 | sinfo->bss_param.beacon_interval)) | |
3696 | goto nla_put_failure; | |
f4263c98 PS |
3697 | |
3698 | nla_nest_end(msg, bss_param); | |
3699 | } | |
9360ffd1 DM |
3700 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3701 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3702 | sizeof(struct nl80211_sta_flag_update), | |
3703 | &sinfo->sta_flags)) | |
3704 | goto nla_put_failure; | |
7eab0f64 JL |
3705 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3706 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3707 | sinfo->t_offset)) | |
3708 | goto nla_put_failure; | |
2ec600d6 | 3709 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3710 | |
9360ffd1 DM |
3711 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3712 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3713 | sinfo->assoc_req_ies)) | |
3714 | goto nla_put_failure; | |
50d3dfb7 | 3715 | |
fd5b74dc JB |
3716 | return genlmsg_end(msg, hdr); |
3717 | ||
3718 | nla_put_failure: | |
bc3ed28c TG |
3719 | genlmsg_cancel(msg, hdr); |
3720 | return -EMSGSIZE; | |
fd5b74dc JB |
3721 | } |
3722 | ||
2ec600d6 | 3723 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3724 | struct netlink_callback *cb) |
2ec600d6 | 3725 | { |
2ec600d6 | 3726 | struct station_info sinfo; |
1b8ec87a | 3727 | struct cfg80211_registered_device *rdev; |
97990a06 | 3728 | struct wireless_dev *wdev; |
2ec600d6 | 3729 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3730 | int sta_idx = cb->args[2]; |
2ec600d6 | 3731 | int err; |
2ec600d6 | 3732 | |
1b8ec87a | 3733 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
3734 | if (err) |
3735 | return err; | |
bba95fef | 3736 | |
97990a06 JB |
3737 | if (!wdev->netdev) { |
3738 | err = -EINVAL; | |
3739 | goto out_err; | |
3740 | } | |
3741 | ||
1b8ec87a | 3742 | if (!rdev->ops->dump_station) { |
eec60b03 | 3743 | err = -EOPNOTSUPP; |
bba95fef JB |
3744 | goto out_err; |
3745 | } | |
3746 | ||
bba95fef | 3747 | while (1) { |
f612cedf | 3748 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 3749 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
e35e4d28 | 3750 | mac_addr, &sinfo); |
bba95fef JB |
3751 | if (err == -ENOENT) |
3752 | break; | |
3753 | if (err) | |
3b85875a | 3754 | goto out_err; |
bba95fef JB |
3755 | |
3756 | if (nl80211_send_station(skb, | |
15e47304 | 3757 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3758 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 3759 | rdev, wdev->netdev, mac_addr, |
bba95fef JB |
3760 | &sinfo) < 0) |
3761 | goto out; | |
3762 | ||
3763 | sta_idx++; | |
3764 | } | |
3765 | ||
3766 | ||
3767 | out: | |
97990a06 | 3768 | cb->args[2] = sta_idx; |
bba95fef | 3769 | err = skb->len; |
bba95fef | 3770 | out_err: |
1b8ec87a | 3771 | nl80211_finish_wdev_dump(rdev); |
bba95fef JB |
3772 | |
3773 | return err; | |
2ec600d6 | 3774 | } |
fd5b74dc | 3775 | |
5727ef1b JB |
3776 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3777 | { | |
4c476991 JB |
3778 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3779 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3780 | struct station_info sinfo; |
fd5b74dc JB |
3781 | struct sk_buff *msg; |
3782 | u8 *mac_addr = NULL; | |
4c476991 | 3783 | int err; |
fd5b74dc | 3784 | |
2ec600d6 | 3785 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3786 | |
3787 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3788 | return -EINVAL; | |
3789 | ||
3790 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3791 | ||
4c476991 JB |
3792 | if (!rdev->ops->get_station) |
3793 | return -EOPNOTSUPP; | |
3b85875a | 3794 | |
e35e4d28 | 3795 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3796 | if (err) |
4c476991 | 3797 | return err; |
2ec600d6 | 3798 | |
fd2120ca | 3799 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3800 | if (!msg) |
4c476991 | 3801 | return -ENOMEM; |
fd5b74dc | 3802 | |
15e47304 | 3803 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3804 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3805 | nlmsg_free(msg); |
3806 | return -ENOBUFS; | |
3807 | } | |
3b85875a | 3808 | |
4c476991 | 3809 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3810 | } |
3811 | ||
77ee7c89 JB |
3812 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3813 | struct station_parameters *params, | |
3814 | enum cfg80211_station_type statype) | |
3815 | { | |
3816 | if (params->listen_interval != -1) | |
3817 | return -EINVAL; | |
c72e1140 AN |
3818 | if (params->aid && |
3819 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
77ee7c89 JB |
3820 | return -EINVAL; |
3821 | ||
3822 | /* When you run into this, adjust the code below for the new flag */ | |
3823 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3824 | ||
3825 | switch (statype) { | |
eef941e6 TP |
3826 | case CFG80211_STA_MESH_PEER_KERNEL: |
3827 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3828 | /* |
3829 | * No ignoring the TDLS flag here -- the userspace mesh | |
3830 | * code doesn't have the bug of including TDLS in the | |
3831 | * mask everywhere. | |
3832 | */ | |
3833 | if (params->sta_flags_mask & | |
3834 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3835 | BIT(NL80211_STA_FLAG_MFP) | | |
3836 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3837 | return -EINVAL; | |
3838 | break; | |
3839 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3840 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3841 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3842 | return -EINVAL; | |
3843 | /* ignore since it can't change */ | |
3844 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3845 | break; | |
3846 | default: | |
3847 | /* disallow mesh-specific things */ | |
3848 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3849 | return -EINVAL; | |
3850 | if (params->local_pm) | |
3851 | return -EINVAL; | |
3852 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3853 | return -EINVAL; | |
3854 | } | |
3855 | ||
3856 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3857 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3858 | /* TDLS can't be set, ... */ | |
3859 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3860 | return -EINVAL; | |
3861 | /* | |
3862 | * ... but don't bother the driver with it. This works around | |
3863 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3864 | * TLDS_PEER flag in the mask even for AP mode. | |
3865 | */ | |
3866 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3867 | } | |
3868 | ||
3869 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3870 | /* reject other things that can't change */ | |
3871 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3872 | return -EINVAL; | |
3873 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3874 | return -EINVAL; | |
3875 | if (params->supported_rates) | |
3876 | return -EINVAL; | |
3877 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3878 | return -EINVAL; | |
3879 | } | |
3880 | ||
3881 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3882 | if (params->vlan) | |
3883 | return -EINVAL; | |
3884 | } | |
3885 | ||
3886 | switch (statype) { | |
3887 | case CFG80211_STA_AP_MLME_CLIENT: | |
3888 | /* Use this only for authorizing/unauthorizing a station */ | |
3889 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3890 | return -EOPNOTSUPP; | |
3891 | break; | |
3892 | case CFG80211_STA_AP_CLIENT: | |
3893 | /* accept only the listed bits */ | |
3894 | if (params->sta_flags_mask & | |
3895 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3896 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3897 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
3898 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3899 | BIT(NL80211_STA_FLAG_WME) | | |
3900 | BIT(NL80211_STA_FLAG_MFP))) | |
3901 | return -EINVAL; | |
3902 | ||
3903 | /* but authenticated/associated only if driver handles it */ | |
3904 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3905 | params->sta_flags_mask & | |
3906 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3907 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3908 | return -EINVAL; | |
3909 | break; | |
3910 | case CFG80211_STA_IBSS: | |
3911 | case CFG80211_STA_AP_STA: | |
3912 | /* reject any changes other than AUTHORIZED */ | |
3913 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3914 | return -EINVAL; | |
3915 | break; | |
3916 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3917 | /* reject any changes other than AUTHORIZED or WME */ | |
3918 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3919 | BIT(NL80211_STA_FLAG_WME))) | |
3920 | return -EINVAL; | |
3921 | /* force (at least) rates when authorizing */ | |
3922 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
3923 | !params->supported_rates) | |
3924 | return -EINVAL; | |
3925 | break; | |
3926 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3927 | /* reject any changes */ | |
3928 | return -EINVAL; | |
eef941e6 | 3929 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
3930 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
3931 | return -EINVAL; | |
3932 | break; | |
eef941e6 | 3933 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
3934 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
3935 | return -EINVAL; | |
3936 | break; | |
3937 | } | |
3938 | ||
3939 | return 0; | |
3940 | } | |
3941 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
3942 | ||
5727ef1b | 3943 | /* |
c258d2de | 3944 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 3945 | */ |
80b99899 JB |
3946 | static struct net_device *get_vlan(struct genl_info *info, |
3947 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 3948 | { |
463d0183 | 3949 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
3950 | struct net_device *v; |
3951 | int ret; | |
3952 | ||
3953 | if (!vlanattr) | |
3954 | return NULL; | |
3955 | ||
3956 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
3957 | if (!v) | |
3958 | return ERR_PTR(-ENODEV); | |
3959 | ||
3960 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
3961 | ret = -EINVAL; | |
3962 | goto error; | |
5727ef1b | 3963 | } |
80b99899 | 3964 | |
77ee7c89 JB |
3965 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
3966 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3967 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
3968 | ret = -EINVAL; | |
3969 | goto error; | |
3970 | } | |
3971 | ||
80b99899 JB |
3972 | if (!netif_running(v)) { |
3973 | ret = -ENETDOWN; | |
3974 | goto error; | |
3975 | } | |
3976 | ||
3977 | return v; | |
3978 | error: | |
3979 | dev_put(v); | |
3980 | return ERR_PTR(ret); | |
5727ef1b JB |
3981 | } |
3982 | ||
94e860f1 JB |
3983 | static const struct nla_policy |
3984 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
3985 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
3986 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
3987 | }; | |
3988 | ||
ff276691 JB |
3989 | static int nl80211_parse_sta_wme(struct genl_info *info, |
3990 | struct station_parameters *params) | |
df881293 | 3991 | { |
df881293 JM |
3992 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
3993 | struct nlattr *nla; | |
3994 | int err; | |
3995 | ||
df881293 JM |
3996 | /* parse WME attributes if present */ |
3997 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
3998 | return 0; | |
3999 | ||
4000 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
4001 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
4002 | nl80211_sta_wme_policy); | |
4003 | if (err) | |
4004 | return err; | |
4005 | ||
4006 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
4007 | params->uapsd_queues = nla_get_u8( | |
4008 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4009 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
4010 | return -EINVAL; | |
4011 | ||
4012 | if (tb[NL80211_STA_WME_MAX_SP]) | |
4013 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4014 | ||
4015 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
4016 | return -EINVAL; | |
4017 | ||
4018 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
4019 | ||
4020 | return 0; | |
4021 | } | |
4022 | ||
c01fc9ad SD |
4023 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4024 | struct station_parameters *params) | |
4025 | { | |
4026 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4027 | params->supported_channels = | |
4028 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4029 | params->supported_channels_len = | |
4030 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4031 | /* | |
4032 | * Need to include at least one (first channel, number of | |
4033 | * channels) tuple for each subband, and must have proper | |
4034 | * tuples for the rest of the data as well. | |
4035 | */ | |
4036 | if (params->supported_channels_len < 2) | |
4037 | return -EINVAL; | |
4038 | if (params->supported_channels_len % 2) | |
4039 | return -EINVAL; | |
4040 | } | |
4041 | ||
4042 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4043 | params->supported_oper_classes = | |
4044 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4045 | params->supported_oper_classes_len = | |
4046 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4047 | /* | |
4048 | * The value of the Length field of the Supported Operating | |
4049 | * Classes element is between 2 and 253. | |
4050 | */ | |
4051 | if (params->supported_oper_classes_len < 2 || | |
4052 | params->supported_oper_classes_len > 253) | |
4053 | return -EINVAL; | |
4054 | } | |
4055 | return 0; | |
4056 | } | |
4057 | ||
ff276691 JB |
4058 | static int nl80211_set_station_tdls(struct genl_info *info, |
4059 | struct station_parameters *params) | |
4060 | { | |
c01fc9ad | 4061 | int err; |
ff276691 | 4062 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4063 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4064 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4065 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4066 | params->ht_capa = | |
4067 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4068 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4069 | params->vht_capa = | |
4070 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4071 | ||
c01fc9ad SD |
4072 | err = nl80211_parse_sta_channel_info(info, params); |
4073 | if (err) | |
4074 | return err; | |
4075 | ||
ff276691 JB |
4076 | return nl80211_parse_sta_wme(info, params); |
4077 | } | |
4078 | ||
5727ef1b JB |
4079 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4080 | { | |
4c476991 | 4081 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4082 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4083 | struct station_parameters params; |
77ee7c89 JB |
4084 | u8 *mac_addr; |
4085 | int err; | |
5727ef1b JB |
4086 | |
4087 | memset(¶ms, 0, sizeof(params)); | |
4088 | ||
4089 | params.listen_interval = -1; | |
4090 | ||
77ee7c89 JB |
4091 | if (!rdev->ops->change_station) |
4092 | return -EOPNOTSUPP; | |
4093 | ||
5727ef1b JB |
4094 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4095 | return -EINVAL; | |
4096 | ||
4097 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4098 | return -EINVAL; | |
4099 | ||
4100 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4101 | ||
4102 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4103 | params.supported_rates = | |
4104 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4105 | params.supported_rates_len = | |
4106 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4107 | } | |
4108 | ||
9d62a986 JM |
4109 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4110 | params.capability = | |
4111 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4112 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4113 | } | |
4114 | ||
4115 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4116 | params.ext_capab = | |
4117 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4118 | params.ext_capab_len = | |
4119 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4120 | } | |
4121 | ||
df881293 | 4122 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 4123 | return -EINVAL; |
36aedc90 | 4124 | |
bdd3ae3d | 4125 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4126 | return -EINVAL; |
4127 | ||
f8bacc21 | 4128 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4129 | params.plink_action = |
f8bacc21 JB |
4130 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4131 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4132 | return -EINVAL; | |
4133 | } | |
2ec600d6 | 4134 | |
f8bacc21 | 4135 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4136 | params.plink_state = |
f8bacc21 JB |
4137 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4138 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4139 | return -EINVAL; | |
4140 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
4141 | } | |
9c3990aa | 4142 | |
3b1c5a53 MP |
4143 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4144 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4145 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4146 | ||
4147 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4148 | pm > NL80211_MESH_POWER_MAX) | |
4149 | return -EINVAL; | |
4150 | ||
4151 | params.local_pm = pm; | |
4152 | } | |
4153 | ||
77ee7c89 JB |
4154 | /* Include parameters for TDLS peer (will check later) */ |
4155 | err = nl80211_set_station_tdls(info, ¶ms); | |
4156 | if (err) | |
4157 | return err; | |
4158 | ||
4159 | params.vlan = get_vlan(info, rdev); | |
4160 | if (IS_ERR(params.vlan)) | |
4161 | return PTR_ERR(params.vlan); | |
4162 | ||
a97f4424 JB |
4163 | switch (dev->ieee80211_ptr->iftype) { |
4164 | case NL80211_IFTYPE_AP: | |
4165 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4166 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4167 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4168 | case NL80211_IFTYPE_STATION: |
267335d6 | 4169 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4170 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4171 | break; |
4172 | default: | |
77ee7c89 JB |
4173 | err = -EOPNOTSUPP; |
4174 | goto out_put_vlan; | |
034d655e JB |
4175 | } |
4176 | ||
77ee7c89 | 4177 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4178 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4179 | |
77ee7c89 | 4180 | out_put_vlan: |
5727ef1b JB |
4181 | if (params.vlan) |
4182 | dev_put(params.vlan); | |
3b85875a | 4183 | |
5727ef1b JB |
4184 | return err; |
4185 | } | |
4186 | ||
4187 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4188 | { | |
4c476991 | 4189 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4190 | int err; |
4c476991 | 4191 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4192 | struct station_parameters params; |
4193 | u8 *mac_addr = NULL; | |
4194 | ||
4195 | memset(¶ms, 0, sizeof(params)); | |
4196 | ||
984c311b JB |
4197 | if (!rdev->ops->add_station) |
4198 | return -EOPNOTSUPP; | |
4199 | ||
5727ef1b JB |
4200 | if (!info->attrs[NL80211_ATTR_MAC]) |
4201 | return -EINVAL; | |
4202 | ||
5727ef1b JB |
4203 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4204 | return -EINVAL; | |
4205 | ||
4206 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4207 | return -EINVAL; | |
4208 | ||
5e4b6f56 JM |
4209 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4210 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4211 | return -EINVAL; |
4212 | ||
5727ef1b JB |
4213 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4214 | params.supported_rates = | |
4215 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4216 | params.supported_rates_len = | |
4217 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4218 | params.listen_interval = | |
4219 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4220 | |
3d124ea2 | 4221 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4222 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4223 | else |
4224 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4225 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4226 | return -EINVAL; | |
51b50fbe | 4227 | |
9d62a986 JM |
4228 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4229 | params.capability = | |
4230 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4231 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4232 | } | |
4233 | ||
4234 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4235 | params.ext_capab = | |
4236 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4237 | params.ext_capab_len = | |
4238 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4239 | } | |
4240 | ||
36aedc90 JM |
4241 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4242 | params.ht_capa = | |
4243 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4244 | |
f461be3e MP |
4245 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4246 | params.vht_capa = | |
4247 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4248 | ||
60f4a7b1 MK |
4249 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4250 | params.opmode_notif_used = true; | |
4251 | params.opmode_notif = | |
4252 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4253 | } | |
4254 | ||
f8bacc21 | 4255 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4256 | params.plink_action = |
f8bacc21 JB |
4257 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4258 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4259 | return -EINVAL; | |
4260 | } | |
96b78dff | 4261 | |
c01fc9ad SD |
4262 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4263 | if (err) | |
4264 | return err; | |
4265 | ||
ff276691 JB |
4266 | err = nl80211_parse_sta_wme(info, ¶ms); |
4267 | if (err) | |
4268 | return err; | |
bdd90d5e | 4269 | |
bdd3ae3d | 4270 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4271 | return -EINVAL; |
4272 | ||
77ee7c89 JB |
4273 | /* When you run into this, adjust the code below for the new flag */ |
4274 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4275 | ||
bdd90d5e JB |
4276 | switch (dev->ieee80211_ptr->iftype) { |
4277 | case NL80211_IFTYPE_AP: | |
4278 | case NL80211_IFTYPE_AP_VLAN: | |
4279 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4280 | /* ignore WME attributes if iface/sta is not capable */ |
4281 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4282 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4283 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4284 | |
bdd90d5e | 4285 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4286 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4287 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4288 | return -EINVAL; |
bdd90d5e JB |
4289 | /* but don't bother the driver with it */ |
4290 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4291 | |
d582cffb JB |
4292 | /* allow authenticated/associated only if driver handles it */ |
4293 | if (!(rdev->wiphy.features & | |
4294 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4295 | params.sta_flags_mask & | |
4296 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4297 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4298 | return -EINVAL; | |
4299 | ||
bdd90d5e JB |
4300 | /* must be last in here for error handling */ |
4301 | params.vlan = get_vlan(info, rdev); | |
4302 | if (IS_ERR(params.vlan)) | |
4303 | return PTR_ERR(params.vlan); | |
4304 | break; | |
4305 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4306 | /* ignore uAPSD data */ |
4307 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4308 | ||
d582cffb JB |
4309 | /* associated is disallowed */ |
4310 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4311 | return -EINVAL; | |
bdd90d5e | 4312 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4313 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4314 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4315 | return -EINVAL; |
4316 | break; | |
4317 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4318 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4319 | /* ignore uAPSD data */ |
4320 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4321 | ||
77ee7c89 JB |
4322 | /* these are disallowed */ |
4323 | if (params.sta_flags_mask & | |
4324 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4325 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4326 | return -EINVAL; |
bdd90d5e JB |
4327 | /* Only TDLS peers can be added */ |
4328 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4329 | return -EINVAL; | |
4330 | /* Can only add if TDLS ... */ | |
4331 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4332 | return -EOPNOTSUPP; | |
4333 | /* ... with external setup is supported */ | |
4334 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4335 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4336 | /* |
4337 | * Older wpa_supplicant versions always mark the TDLS peer | |
4338 | * as authorized, but it shouldn't yet be. | |
4339 | */ | |
4340 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4341 | break; |
4342 | default: | |
4343 | return -EOPNOTSUPP; | |
c75786c9 EP |
4344 | } |
4345 | ||
bdd90d5e | 4346 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4347 | |
e35e4d28 | 4348 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4349 | |
5727ef1b JB |
4350 | if (params.vlan) |
4351 | dev_put(params.vlan); | |
5727ef1b JB |
4352 | return err; |
4353 | } | |
4354 | ||
4355 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4356 | { | |
4c476991 JB |
4357 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4358 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
4359 | u8 *mac_addr = NULL; |
4360 | ||
4361 | if (info->attrs[NL80211_ATTR_MAC]) | |
4362 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4363 | ||
e80cf853 | 4364 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4365 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4366 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4367 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4368 | return -EINVAL; | |
5727ef1b | 4369 | |
4c476991 JB |
4370 | if (!rdev->ops->del_station) |
4371 | return -EOPNOTSUPP; | |
3b85875a | 4372 | |
e35e4d28 | 4373 | return rdev_del_station(rdev, dev, mac_addr); |
5727ef1b JB |
4374 | } |
4375 | ||
15e47304 | 4376 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4377 | int flags, struct net_device *dev, |
4378 | u8 *dst, u8 *next_hop, | |
4379 | struct mpath_info *pinfo) | |
4380 | { | |
4381 | void *hdr; | |
4382 | struct nlattr *pinfoattr; | |
4383 | ||
15e47304 | 4384 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
2ec600d6 LCC |
4385 | if (!hdr) |
4386 | return -1; | |
4387 | ||
9360ffd1 DM |
4388 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4389 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4390 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4391 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4392 | goto nla_put_failure; | |
f5ea9120 | 4393 | |
2ec600d6 LCC |
4394 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4395 | if (!pinfoattr) | |
4396 | goto nla_put_failure; | |
9360ffd1 DM |
4397 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4398 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4399 | pinfo->frame_qlen)) | |
4400 | goto nla_put_failure; | |
4401 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4402 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4403 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4404 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4405 | pinfo->metric)) || | |
4406 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4407 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4408 | pinfo->exptime)) || | |
4409 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4410 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4411 | pinfo->flags)) || | |
4412 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4413 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4414 | pinfo->discovery_timeout)) || | |
4415 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4416 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4417 | pinfo->discovery_retries))) | |
4418 | goto nla_put_failure; | |
2ec600d6 LCC |
4419 | |
4420 | nla_nest_end(msg, pinfoattr); | |
4421 | ||
4422 | return genlmsg_end(msg, hdr); | |
4423 | ||
4424 | nla_put_failure: | |
bc3ed28c TG |
4425 | genlmsg_cancel(msg, hdr); |
4426 | return -EMSGSIZE; | |
2ec600d6 LCC |
4427 | } |
4428 | ||
4429 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4430 | struct netlink_callback *cb) |
2ec600d6 | 4431 | { |
2ec600d6 | 4432 | struct mpath_info pinfo; |
1b8ec87a | 4433 | struct cfg80211_registered_device *rdev; |
97990a06 | 4434 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4435 | u8 dst[ETH_ALEN]; |
4436 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4437 | int path_idx = cb->args[2]; |
2ec600d6 | 4438 | int err; |
2ec600d6 | 4439 | |
1b8ec87a | 4440 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
4441 | if (err) |
4442 | return err; | |
bba95fef | 4443 | |
1b8ec87a | 4444 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 4445 | err = -EOPNOTSUPP; |
bba95fef JB |
4446 | goto out_err; |
4447 | } | |
4448 | ||
97990a06 | 4449 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4450 | err = -EOPNOTSUPP; |
0448b5fc | 4451 | goto out_err; |
eec60b03 JM |
4452 | } |
4453 | ||
bba95fef | 4454 | while (1) { |
1b8ec87a | 4455 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 4456 | next_hop, &pinfo); |
bba95fef | 4457 | if (err == -ENOENT) |
2ec600d6 | 4458 | break; |
bba95fef | 4459 | if (err) |
3b85875a | 4460 | goto out_err; |
2ec600d6 | 4461 | |
15e47304 | 4462 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4463 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4464 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4465 | &pinfo) < 0) |
4466 | goto out; | |
2ec600d6 | 4467 | |
bba95fef | 4468 | path_idx++; |
2ec600d6 | 4469 | } |
2ec600d6 | 4470 | |
2ec600d6 | 4471 | |
bba95fef | 4472 | out: |
97990a06 | 4473 | cb->args[2] = path_idx; |
bba95fef | 4474 | err = skb->len; |
bba95fef | 4475 | out_err: |
1b8ec87a | 4476 | nl80211_finish_wdev_dump(rdev); |
bba95fef | 4477 | return err; |
2ec600d6 LCC |
4478 | } |
4479 | ||
4480 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4481 | { | |
4c476991 | 4482 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4483 | int err; |
4c476991 | 4484 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4485 | struct mpath_info pinfo; |
4486 | struct sk_buff *msg; | |
4487 | u8 *dst = NULL; | |
4488 | u8 next_hop[ETH_ALEN]; | |
4489 | ||
4490 | memset(&pinfo, 0, sizeof(pinfo)); | |
4491 | ||
4492 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4493 | return -EINVAL; | |
4494 | ||
4495 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4496 | ||
4c476991 JB |
4497 | if (!rdev->ops->get_mpath) |
4498 | return -EOPNOTSUPP; | |
2ec600d6 | 4499 | |
4c476991 JB |
4500 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4501 | return -EOPNOTSUPP; | |
eec60b03 | 4502 | |
e35e4d28 | 4503 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4504 | if (err) |
4c476991 | 4505 | return err; |
2ec600d6 | 4506 | |
fd2120ca | 4507 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4508 | if (!msg) |
4c476991 | 4509 | return -ENOMEM; |
2ec600d6 | 4510 | |
15e47304 | 4511 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4512 | dev, dst, next_hop, &pinfo) < 0) { |
4513 | nlmsg_free(msg); | |
4514 | return -ENOBUFS; | |
4515 | } | |
3b85875a | 4516 | |
4c476991 | 4517 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4518 | } |
4519 | ||
4520 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4521 | { | |
4c476991 JB |
4522 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4523 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4524 | u8 *dst = NULL; |
4525 | u8 *next_hop = NULL; | |
4526 | ||
4527 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4528 | return -EINVAL; | |
4529 | ||
4530 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4531 | return -EINVAL; | |
4532 | ||
4533 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4534 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4535 | ||
4c476991 JB |
4536 | if (!rdev->ops->change_mpath) |
4537 | return -EOPNOTSUPP; | |
35a8efe1 | 4538 | |
4c476991 JB |
4539 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4540 | return -EOPNOTSUPP; | |
2ec600d6 | 4541 | |
e35e4d28 | 4542 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4543 | } |
4c476991 | 4544 | |
2ec600d6 LCC |
4545 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4546 | { | |
4c476991 JB |
4547 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4548 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4549 | u8 *dst = NULL; |
4550 | u8 *next_hop = NULL; | |
4551 | ||
4552 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4553 | return -EINVAL; | |
4554 | ||
4555 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4556 | return -EINVAL; | |
4557 | ||
4558 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4559 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4560 | ||
4c476991 JB |
4561 | if (!rdev->ops->add_mpath) |
4562 | return -EOPNOTSUPP; | |
35a8efe1 | 4563 | |
4c476991 JB |
4564 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4565 | return -EOPNOTSUPP; | |
2ec600d6 | 4566 | |
e35e4d28 | 4567 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4568 | } |
4569 | ||
4570 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4571 | { | |
4c476991 JB |
4572 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4573 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4574 | u8 *dst = NULL; |
4575 | ||
4576 | if (info->attrs[NL80211_ATTR_MAC]) | |
4577 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4578 | ||
4c476991 JB |
4579 | if (!rdev->ops->del_mpath) |
4580 | return -EOPNOTSUPP; | |
3b85875a | 4581 | |
e35e4d28 | 4582 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4583 | } |
4584 | ||
9f1ba906 JM |
4585 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4586 | { | |
4c476991 JB |
4587 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4588 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 4589 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 4590 | struct bss_parameters params; |
c56589ed | 4591 | int err; |
9f1ba906 JM |
4592 | |
4593 | memset(¶ms, 0, sizeof(params)); | |
4594 | /* default to not changing parameters */ | |
4595 | params.use_cts_prot = -1; | |
4596 | params.use_short_preamble = -1; | |
4597 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4598 | params.ap_isolate = -1; |
50b12f59 | 4599 | params.ht_opmode = -1; |
53cabad7 JB |
4600 | params.p2p_ctwindow = -1; |
4601 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4602 | |
4603 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4604 | params.use_cts_prot = | |
4605 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4606 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4607 | params.use_short_preamble = | |
4608 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4609 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4610 | params.use_short_slot_time = | |
4611 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4612 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4613 | params.basic_rates = | |
4614 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4615 | params.basic_rates_len = | |
4616 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4617 | } | |
fd8aaaf3 FF |
4618 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4619 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4620 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4621 | params.ht_opmode = | |
4622 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4623 | |
53cabad7 JB |
4624 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4625 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4626 | return -EINVAL; | |
4627 | params.p2p_ctwindow = | |
4628 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4629 | if (params.p2p_ctwindow < 0) | |
4630 | return -EINVAL; | |
4631 | if (params.p2p_ctwindow != 0 && | |
4632 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4633 | return -EINVAL; | |
4634 | } | |
4635 | ||
4636 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4637 | u8 tmp; | |
4638 | ||
4639 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4640 | return -EINVAL; | |
4641 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4642 | if (tmp > 1) | |
4643 | return -EINVAL; | |
4644 | params.p2p_opp_ps = tmp; | |
4645 | if (params.p2p_opp_ps && | |
4646 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4647 | return -EINVAL; | |
4648 | } | |
4649 | ||
4c476991 JB |
4650 | if (!rdev->ops->change_bss) |
4651 | return -EOPNOTSUPP; | |
9f1ba906 | 4652 | |
074ac8df | 4653 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4654 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4655 | return -EOPNOTSUPP; | |
3b85875a | 4656 | |
c56589ed SW |
4657 | wdev_lock(wdev); |
4658 | err = rdev_change_bss(rdev, dev, ¶ms); | |
4659 | wdev_unlock(wdev); | |
4660 | ||
4661 | return err; | |
9f1ba906 JM |
4662 | } |
4663 | ||
b54452b0 | 4664 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4665 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4666 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4667 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4668 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4669 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4670 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
089027e5 | 4671 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
b2e1b302 LR |
4672 | }; |
4673 | ||
4674 | static int parse_reg_rule(struct nlattr *tb[], | |
4675 | struct ieee80211_reg_rule *reg_rule) | |
4676 | { | |
4677 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4678 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4679 | ||
4680 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4681 | return -EINVAL; | |
4682 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4683 | return -EINVAL; | |
4684 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4685 | return -EINVAL; | |
b0dfd2ea JD |
4686 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
4687 | return -EINVAL; | |
b2e1b302 LR |
4688 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
4689 | return -EINVAL; | |
4690 | ||
4691 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4692 | ||
4693 | freq_range->start_freq_khz = | |
4694 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4695 | freq_range->end_freq_khz = | |
4696 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
b0dfd2ea JD |
4697 | freq_range->max_bandwidth_khz = |
4698 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
b2e1b302 LR |
4699 | |
4700 | power_rule->max_eirp = | |
4701 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4702 | ||
4703 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4704 | power_rule->max_antenna_gain = | |
4705 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4706 | ||
089027e5 JD |
4707 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
4708 | reg_rule->dfs_cac_ms = | |
4709 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
4710 | ||
b2e1b302 LR |
4711 | return 0; |
4712 | } | |
4713 | ||
4714 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4715 | { | |
b2e1b302 | 4716 | char *data = NULL; |
57b5ce07 | 4717 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4718 | |
80778f18 LR |
4719 | /* |
4720 | * You should only get this when cfg80211 hasn't yet initialized | |
4721 | * completely when built-in to the kernel right between the time | |
4722 | * window between nl80211_init() and regulatory_init(), if that is | |
4723 | * even possible. | |
4724 | */ | |
458f4f9e | 4725 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4726 | return -EINPROGRESS; |
80778f18 | 4727 | |
57b5ce07 LR |
4728 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4729 | user_reg_hint_type = | |
4730 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4731 | else | |
4732 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4733 | ||
4734 | switch (user_reg_hint_type) { | |
4735 | case NL80211_USER_REG_HINT_USER: | |
4736 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
4737 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4738 | return -EINVAL; | |
4739 | ||
4740 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4741 | return regulatory_hint_user(data, user_reg_hint_type); | |
4742 | case NL80211_USER_REG_HINT_INDOOR: | |
4743 | return regulatory_hint_indoor_user(); | |
57b5ce07 LR |
4744 | default: |
4745 | return -EINVAL; | |
4746 | } | |
b2e1b302 LR |
4747 | } |
4748 | ||
24bdd9f4 | 4749 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4750 | struct genl_info *info) |
93da9cc1 | 4751 | { |
4c476991 | 4752 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4753 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4754 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4755 | struct mesh_config cur_params; | |
4756 | int err = 0; | |
93da9cc1 | 4757 | void *hdr; |
4758 | struct nlattr *pinfoattr; | |
4759 | struct sk_buff *msg; | |
4760 | ||
29cbe68c JB |
4761 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4762 | return -EOPNOTSUPP; | |
4763 | ||
24bdd9f4 | 4764 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4765 | return -EOPNOTSUPP; |
f3f92586 | 4766 | |
29cbe68c JB |
4767 | wdev_lock(wdev); |
4768 | /* If not connected, get default parameters */ | |
4769 | if (!wdev->mesh_id_len) | |
4770 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4771 | else | |
e35e4d28 | 4772 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4773 | wdev_unlock(wdev); |
4774 | ||
93da9cc1 | 4775 | if (err) |
4c476991 | 4776 | return err; |
93da9cc1 | 4777 | |
4778 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4779 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4780 | if (!msg) |
4781 | return -ENOMEM; | |
15e47304 | 4782 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4783 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4784 | if (!hdr) |
efe1cf0c | 4785 | goto out; |
24bdd9f4 | 4786 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 4787 | if (!pinfoattr) |
4788 | goto nla_put_failure; | |
9360ffd1 DM |
4789 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4790 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
4791 | cur_params.dot11MeshRetryTimeout) || | |
4792 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
4793 | cur_params.dot11MeshConfirmTimeout) || | |
4794 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
4795 | cur_params.dot11MeshHoldingTimeout) || | |
4796 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
4797 | cur_params.dot11MeshMaxPeerLinks) || | |
4798 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
4799 | cur_params.dot11MeshMaxRetries) || | |
4800 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
4801 | cur_params.dot11MeshTTL) || | |
4802 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
4803 | cur_params.element_ttl) || | |
4804 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
4805 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
4806 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4807 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
4808 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4809 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
4810 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
4811 | cur_params.path_refresh_time) || | |
4812 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
4813 | cur_params.min_discovery_timeout) || | |
4814 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
4815 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
4816 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
4817 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
4818 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
4819 | cur_params.dot11MeshHWMPperrMinInterval) || | |
4820 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
4821 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
4822 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4823 | cur_params.dot11MeshHWMPRootMode) || | |
4824 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
4825 | cur_params.dot11MeshHWMPRannInterval) || | |
4826 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
4827 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
4828 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
4829 | cur_params.dot11MeshForwarding) || | |
4830 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
4831 | cur_params.rssi_threshold) || |
4832 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
4833 | cur_params.ht_opmode) || |
4834 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
4835 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
4836 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
4837 | cur_params.dot11MeshHWMProotInterval) || |
4838 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
4839 | cur_params.dot11MeshHWMPconfirmationInterval) || |
4840 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
4841 | cur_params.power_mode) || | |
4842 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
4843 | cur_params.dot11MeshAwakeWindowDuration) || |
4844 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4845 | cur_params.plink_timeout)) | |
9360ffd1 | 4846 | goto nla_put_failure; |
93da9cc1 | 4847 | nla_nest_end(msg, pinfoattr); |
4848 | genlmsg_end(msg, hdr); | |
4c476991 | 4849 | return genlmsg_reply(msg, info); |
93da9cc1 | 4850 | |
3b85875a | 4851 | nla_put_failure: |
93da9cc1 | 4852 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 4853 | out: |
d080e275 | 4854 | nlmsg_free(msg); |
4c476991 | 4855 | return -ENOBUFS; |
93da9cc1 | 4856 | } |
4857 | ||
b54452b0 | 4858 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 4859 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
4860 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
4861 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
4862 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
4863 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
4864 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 4865 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 4866 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 4867 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 4868 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
4869 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
4870 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
4871 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
4872 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 4873 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 4874 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 4875 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 4876 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 4877 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 4878 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
4879 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
4880 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
4881 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
4882 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 4883 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
4884 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
4885 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 4886 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 4887 | }; |
4888 | ||
c80d545d JC |
4889 | static const struct nla_policy |
4890 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 4891 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
4892 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
4893 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 4894 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 4895 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 4896 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 4897 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 4898 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 4899 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
4900 | }; |
4901 | ||
24bdd9f4 | 4902 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
4903 | struct mesh_config *cfg, |
4904 | u32 *mask_out) | |
93da9cc1 | 4905 | { |
93da9cc1 | 4906 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 4907 | u32 mask = 0; |
93da9cc1 | 4908 | |
ea54fba2 MP |
4909 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
4910 | do { \ | |
4911 | if (tb[attr]) { \ | |
4912 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
4913 | return -EINVAL; \ | |
4914 | cfg->param = fn(tb[attr]); \ | |
4915 | mask |= (1 << (attr - 1)); \ | |
4916 | } \ | |
4917 | } while (0) | |
bd90fdcc JB |
4918 | |
4919 | ||
24bdd9f4 | 4920 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 4921 | return -EINVAL; |
4922 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 4923 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 4924 | nl80211_meshconf_params_policy)) |
93da9cc1 | 4925 | return -EINVAL; |
4926 | ||
93da9cc1 | 4927 | /* This makes sure that there aren't more than 32 mesh config |
4928 | * parameters (otherwise our bitfield scheme would not work.) */ | |
4929 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
4930 | ||
4931 | /* Fill in the params struct */ | |
ea54fba2 | 4932 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
4933 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
4934 | nla_get_u16); | |
ea54fba2 | 4935 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
4936 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
4937 | nla_get_u16); | |
ea54fba2 | 4938 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
4939 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
4940 | nla_get_u16); | |
ea54fba2 | 4941 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
4942 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
4943 | nla_get_u16); | |
ea54fba2 | 4944 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
4945 | mask, NL80211_MESHCONF_MAX_RETRIES, |
4946 | nla_get_u8); | |
ea54fba2 | 4947 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 4948 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 4949 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
4950 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
4951 | nla_get_u8); | |
ea54fba2 | 4952 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
4953 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
4954 | nla_get_u8); | |
ea54fba2 MP |
4955 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
4956 | 1, 255, mask, | |
a4f606ea CYY |
4957 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4958 | nla_get_u32); | |
ea54fba2 | 4959 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
4960 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4961 | nla_get_u8); | |
ea54fba2 | 4962 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
4963 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
4964 | nla_get_u32); | |
ea54fba2 | 4965 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
4966 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
4967 | nla_get_u16); | |
ea54fba2 MP |
4968 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
4969 | 1, 65535, mask, | |
a4f606ea CYY |
4970 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
4971 | nla_get_u32); | |
93da9cc1 | 4972 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
4973 | 1, 65535, mask, |
4974 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 4975 | nla_get_u16); |
dca7e943 | 4976 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
4977 | 1, 65535, mask, |
4978 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 4979 | nla_get_u16); |
93da9cc1 | 4980 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4981 | dot11MeshHWMPnetDiameterTraversalTime, |
4982 | 1, 65535, mask, | |
a4f606ea CYY |
4983 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
4984 | nla_get_u16); | |
ea54fba2 MP |
4985 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
4986 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4987 | nla_get_u8); | |
4988 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
4989 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 4990 | nla_get_u16); |
63c5723b | 4991 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4992 | dot11MeshGateAnnouncementProtocol, 0, 1, |
4993 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 4994 | nla_get_u8); |
ea54fba2 | 4995 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
4996 | mask, NL80211_MESHCONF_FORWARDING, |
4997 | nla_get_u8); | |
83374fe9 | 4998 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 4999 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
83374fe9 | 5000 | nla_get_s32); |
ea54fba2 | 5001 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 5002 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
5003 | nla_get_u16); |
5004 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 5005 | 1, 65535, mask, |
ac1073a6 CYY |
5006 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
5007 | nla_get_u32); | |
ea54fba2 | 5008 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 5009 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
5010 | nla_get_u16); |
5011 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
5012 | dot11MeshHWMPconfirmationInterval, |
5013 | 1, 65535, mask, | |
728b19e5 | 5014 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 5015 | nla_get_u16); |
3b1c5a53 MP |
5016 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
5017 | NL80211_MESH_POWER_ACTIVE, | |
5018 | NL80211_MESH_POWER_MAX, | |
5019 | mask, NL80211_MESHCONF_POWER_MODE, | |
5020 | nla_get_u32); | |
5021 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
5022 | 0, 65535, mask, | |
5023 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
8e7c0538 CT |
5024 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
5025 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5026 | nla_get_u32); | |
bd90fdcc JB |
5027 | if (mask_out) |
5028 | *mask_out = mask; | |
c80d545d | 5029 | |
bd90fdcc JB |
5030 | return 0; |
5031 | ||
5032 | #undef FILL_IN_MESH_PARAM_IF_SET | |
5033 | } | |
5034 | ||
c80d545d JC |
5035 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
5036 | struct mesh_setup *setup) | |
5037 | { | |
bb2798d4 | 5038 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
5039 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
5040 | ||
5041 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
5042 | return -EINVAL; | |
5043 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
5044 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
5045 | nl80211_mesh_setup_params_policy)) | |
5046 | return -EINVAL; | |
5047 | ||
d299a1f2 JC |
5048 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
5049 | setup->sync_method = | |
5050 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
5051 | IEEE80211_SYNC_METHOD_VENDOR : | |
5052 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
5053 | ||
c80d545d JC |
5054 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
5055 | setup->path_sel_proto = | |
5056 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5057 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5058 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5059 | ||
5060 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5061 | setup->path_metric = | |
5062 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5063 | IEEE80211_PATH_METRIC_VENDOR : | |
5064 | IEEE80211_PATH_METRIC_AIRTIME; | |
5065 | ||
581a8b0f JC |
5066 | |
5067 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 5068 | struct nlattr *ieattr = |
581a8b0f | 5069 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5070 | if (!is_valid_ie_attr(ieattr)) |
5071 | return -EINVAL; | |
581a8b0f JC |
5072 | setup->ie = nla_data(ieattr); |
5073 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5074 | } |
bb2798d4 TP |
5075 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5076 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5077 | return -EINVAL; | |
5078 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5079 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5080 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5081 | if (setup->is_secure) |
5082 | setup->user_mpm = true; | |
c80d545d | 5083 | |
6e16d90b CT |
5084 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5085 | if (!setup->user_mpm) | |
5086 | return -EINVAL; | |
5087 | setup->auth_id = | |
5088 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5089 | } | |
5090 | ||
c80d545d JC |
5091 | return 0; |
5092 | } | |
5093 | ||
24bdd9f4 | 5094 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5095 | struct genl_info *info) |
bd90fdcc JB |
5096 | { |
5097 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5098 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5099 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5100 | struct mesh_config cfg; |
5101 | u32 mask; | |
5102 | int err; | |
5103 | ||
29cbe68c JB |
5104 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5105 | return -EOPNOTSUPP; | |
5106 | ||
24bdd9f4 | 5107 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5108 | return -EOPNOTSUPP; |
5109 | ||
24bdd9f4 | 5110 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5111 | if (err) |
5112 | return err; | |
5113 | ||
29cbe68c JB |
5114 | wdev_lock(wdev); |
5115 | if (!wdev->mesh_id_len) | |
5116 | err = -ENOLINK; | |
5117 | ||
5118 | if (!err) | |
e35e4d28 | 5119 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5120 | |
5121 | wdev_unlock(wdev); | |
5122 | ||
5123 | return err; | |
93da9cc1 | 5124 | } |
5125 | ||
f130347c LR |
5126 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
5127 | { | |
458f4f9e | 5128 | const struct ieee80211_regdomain *regdom; |
f130347c LR |
5129 | struct sk_buff *msg; |
5130 | void *hdr = NULL; | |
5131 | struct nlattr *nl_reg_rules; | |
5132 | unsigned int i; | |
f130347c LR |
5133 | |
5134 | if (!cfg80211_regdomain) | |
5fe231e8 | 5135 | return -EINVAL; |
f130347c | 5136 | |
fd2120ca | 5137 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
5fe231e8 JB |
5138 | if (!msg) |
5139 | return -ENOBUFS; | |
f130347c | 5140 | |
15e47304 | 5141 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
f130347c LR |
5142 | NL80211_CMD_GET_REG); |
5143 | if (!hdr) | |
efe1cf0c | 5144 | goto put_failure; |
f130347c | 5145 | |
57b5ce07 LR |
5146 | if (reg_last_request_cell_base() && |
5147 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5148 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5149 | goto nla_put_failure; | |
5150 | ||
458f4f9e JB |
5151 | rcu_read_lock(); |
5152 | regdom = rcu_dereference(cfg80211_regdomain); | |
5153 | ||
5154 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | |
5155 | (regdom->dfs_region && | |
5156 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
5157 | goto nla_put_failure_rcu; | |
5158 | ||
f130347c LR |
5159 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5160 | if (!nl_reg_rules) | |
458f4f9e | 5161 | goto nla_put_failure_rcu; |
f130347c | 5162 | |
458f4f9e | 5163 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5164 | struct nlattr *nl_reg_rule; |
5165 | const struct ieee80211_reg_rule *reg_rule; | |
5166 | const struct ieee80211_freq_range *freq_range; | |
5167 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 5168 | unsigned int max_bandwidth_khz; |
f130347c | 5169 | |
458f4f9e | 5170 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5171 | freq_range = ®_rule->freq_range; |
5172 | power_rule = ®_rule->power_rule; | |
5173 | ||
5174 | nl_reg_rule = nla_nest_start(msg, i); | |
5175 | if (!nl_reg_rule) | |
458f4f9e | 5176 | goto nla_put_failure_rcu; |
f130347c | 5177 | |
97524820 JD |
5178 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
5179 | if (!max_bandwidth_khz) | |
5180 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
5181 | reg_rule); | |
5182 | ||
9360ffd1 DM |
5183 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5184 | reg_rule->flags) || | |
5185 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5186 | freq_range->start_freq_khz) || | |
5187 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5188 | freq_range->end_freq_khz) || | |
5189 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 5190 | max_bandwidth_khz) || |
9360ffd1 DM |
5191 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
5192 | power_rule->max_antenna_gain) || | |
5193 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
5194 | power_rule->max_eirp) || |
5195 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
5196 | reg_rule->dfs_cac_ms)) | |
458f4f9e | 5197 | goto nla_put_failure_rcu; |
f130347c LR |
5198 | |
5199 | nla_nest_end(msg, nl_reg_rule); | |
5200 | } | |
458f4f9e | 5201 | rcu_read_unlock(); |
f130347c LR |
5202 | |
5203 | nla_nest_end(msg, nl_reg_rules); | |
5204 | ||
5205 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5206 | return genlmsg_reply(msg, info); |
f130347c | 5207 | |
458f4f9e JB |
5208 | nla_put_failure_rcu: |
5209 | rcu_read_unlock(); | |
f130347c LR |
5210 | nla_put_failure: |
5211 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5212 | put_failure: |
d080e275 | 5213 | nlmsg_free(msg); |
5fe231e8 | 5214 | return -EMSGSIZE; |
f130347c LR |
5215 | } |
5216 | ||
b2e1b302 LR |
5217 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5218 | { | |
5219 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5220 | struct nlattr *nl_reg_rule; | |
5221 | char *alpha2 = NULL; | |
5222 | int rem_reg_rules = 0, r = 0; | |
5223 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
4c7d3982 | 5224 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
b2e1b302 LR |
5225 | struct ieee80211_regdomain *rd = NULL; |
5226 | ||
5227 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5228 | return -EINVAL; | |
5229 | ||
5230 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5231 | return -EINVAL; | |
5232 | ||
5233 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5234 | ||
8b60b078 LR |
5235 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5236 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5237 | ||
b2e1b302 | 5238 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5239 | rem_reg_rules) { |
b2e1b302 LR |
5240 | num_rules++; |
5241 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5242 | return -EINVAL; |
b2e1b302 LR |
5243 | } |
5244 | ||
e438768f LR |
5245 | if (!reg_is_valid_request(alpha2)) |
5246 | return -EINVAL; | |
5247 | ||
b2e1b302 | 5248 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5249 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5250 | |
5251 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5252 | if (!rd) |
5253 | return -ENOMEM; | |
b2e1b302 LR |
5254 | |
5255 | rd->n_reg_rules = num_rules; | |
5256 | rd->alpha2[0] = alpha2[0]; | |
5257 | rd->alpha2[1] = alpha2[1]; | |
5258 | ||
8b60b078 LR |
5259 | /* |
5260 | * Disable DFS master mode if the DFS region was | |
5261 | * not supported or known on this kernel. | |
5262 | */ | |
5263 | if (reg_supported_dfs_region(dfs_region)) | |
5264 | rd->dfs_region = dfs_region; | |
5265 | ||
b2e1b302 | 5266 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5267 | rem_reg_rules) { |
ae811e21 JB |
5268 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
5269 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
5270 | reg_rule_policy); | |
5271 | if (r) | |
5272 | goto bad_reg; | |
b2e1b302 LR |
5273 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5274 | if (r) | |
5275 | goto bad_reg; | |
5276 | ||
5277 | rule_idx++; | |
5278 | ||
d0e18f83 LR |
5279 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5280 | r = -EINVAL; | |
b2e1b302 | 5281 | goto bad_reg; |
d0e18f83 | 5282 | } |
b2e1b302 LR |
5283 | } |
5284 | ||
b2e1b302 | 5285 | r = set_regdom(rd); |
6913b49a | 5286 | /* set_regdom took ownership */ |
1a919318 | 5287 | rd = NULL; |
b2e1b302 | 5288 | |
d2372b31 | 5289 | bad_reg: |
b2e1b302 | 5290 | kfree(rd); |
d0e18f83 | 5291 | return r; |
b2e1b302 LR |
5292 | } |
5293 | ||
83f5e2cf JB |
5294 | static int validate_scan_freqs(struct nlattr *freqs) |
5295 | { | |
5296 | struct nlattr *attr1, *attr2; | |
5297 | int n_channels = 0, tmp1, tmp2; | |
5298 | ||
5299 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5300 | n_channels++; | |
5301 | /* | |
5302 | * Some hardware has a limited channel list for | |
5303 | * scanning, and it is pretty much nonsensical | |
5304 | * to scan for a channel twice, so disallow that | |
5305 | * and don't require drivers to check that the | |
5306 | * channel list they get isn't longer than what | |
5307 | * they can scan, as long as they can scan all | |
5308 | * the channels they registered at once. | |
5309 | */ | |
5310 | nla_for_each_nested(attr2, freqs, tmp2) | |
5311 | if (attr1 != attr2 && | |
5312 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5313 | return 0; | |
5314 | } | |
5315 | ||
5316 | return n_channels; | |
5317 | } | |
5318 | ||
2a519311 JB |
5319 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5320 | { | |
4c476991 | 5321 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5322 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5323 | struct cfg80211_scan_request *request; |
2a519311 JB |
5324 | struct nlattr *attr; |
5325 | struct wiphy *wiphy; | |
83f5e2cf | 5326 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5327 | size_t ie_len; |
2a519311 | 5328 | |
f4a11bb0 JB |
5329 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5330 | return -EINVAL; | |
5331 | ||
79c97e97 | 5332 | wiphy = &rdev->wiphy; |
2a519311 | 5333 | |
4c476991 JB |
5334 | if (!rdev->ops->scan) |
5335 | return -EOPNOTSUPP; | |
2a519311 | 5336 | |
f9d15d16 | 5337 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
5338 | err = -EBUSY; |
5339 | goto unlock; | |
5340 | } | |
2a519311 JB |
5341 | |
5342 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5343 | n_channels = validate_scan_freqs( |
5344 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5345 | if (!n_channels) { |
5346 | err = -EINVAL; | |
5347 | goto unlock; | |
5348 | } | |
2a519311 | 5349 | } else { |
bdfbec2d | 5350 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
5351 | } |
5352 | ||
5353 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5354 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5355 | n_ssids++; | |
5356 | ||
f9f47529 JB |
5357 | if (n_ssids > wiphy->max_scan_ssids) { |
5358 | err = -EINVAL; | |
5359 | goto unlock; | |
5360 | } | |
2a519311 | 5361 | |
70692ad2 JM |
5362 | if (info->attrs[NL80211_ATTR_IE]) |
5363 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5364 | else | |
5365 | ie_len = 0; | |
5366 | ||
f9f47529 JB |
5367 | if (ie_len > wiphy->max_scan_ie_len) { |
5368 | err = -EINVAL; | |
5369 | goto unlock; | |
5370 | } | |
18a83659 | 5371 | |
2a519311 | 5372 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5373 | + sizeof(*request->ssids) * n_ssids |
5374 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5375 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5376 | if (!request) { |
5377 | err = -ENOMEM; | |
5378 | goto unlock; | |
5379 | } | |
2a519311 | 5380 | |
2a519311 | 5381 | if (n_ssids) |
5ba63533 | 5382 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5383 | request->n_ssids = n_ssids; |
70692ad2 JM |
5384 | if (ie_len) { |
5385 | if (request->ssids) | |
5386 | request->ie = (void *)(request->ssids + n_ssids); | |
5387 | else | |
5388 | request->ie = (void *)(request->channels + n_channels); | |
5389 | } | |
2a519311 | 5390 | |
584991dc | 5391 | i = 0; |
2a519311 JB |
5392 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5393 | /* user specified, bail out if channel not found */ | |
2a519311 | 5394 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5395 | struct ieee80211_channel *chan; |
5396 | ||
5397 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5398 | ||
5399 | if (!chan) { | |
2a519311 JB |
5400 | err = -EINVAL; |
5401 | goto out_free; | |
5402 | } | |
584991dc JB |
5403 | |
5404 | /* ignore disabled channels */ | |
5405 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5406 | continue; | |
5407 | ||
5408 | request->channels[i] = chan; | |
2a519311 JB |
5409 | i++; |
5410 | } | |
5411 | } else { | |
34850ab2 JB |
5412 | enum ieee80211_band band; |
5413 | ||
2a519311 | 5414 | /* all channels */ |
2a519311 JB |
5415 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5416 | int j; | |
5417 | if (!wiphy->bands[band]) | |
5418 | continue; | |
5419 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5420 | struct ieee80211_channel *chan; |
5421 | ||
5422 | chan = &wiphy->bands[band]->channels[j]; | |
5423 | ||
5424 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5425 | continue; | |
5426 | ||
5427 | request->channels[i] = chan; | |
2a519311 JB |
5428 | i++; |
5429 | } | |
5430 | } | |
5431 | } | |
5432 | ||
584991dc JB |
5433 | if (!i) { |
5434 | err = -EINVAL; | |
5435 | goto out_free; | |
5436 | } | |
5437 | ||
5438 | request->n_channels = i; | |
5439 | ||
2a519311 JB |
5440 | i = 0; |
5441 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5442 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5443 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5444 | err = -EINVAL; |
5445 | goto out_free; | |
5446 | } | |
57a27e1d | 5447 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5448 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5449 | i++; |
5450 | } | |
5451 | } | |
5452 | ||
70692ad2 JM |
5453 | if (info->attrs[NL80211_ATTR_IE]) { |
5454 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5455 | memcpy((void *)request->ie, |
5456 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5457 | request->ie_len); |
5458 | } | |
5459 | ||
34850ab2 | 5460 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5461 | if (wiphy->bands[i]) |
5462 | request->rates[i] = | |
5463 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5464 | |
5465 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5466 | nla_for_each_nested(attr, | |
5467 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5468 | tmp) { | |
5469 | enum ieee80211_band band = nla_type(attr); | |
5470 | ||
84404623 | 5471 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5472 | err = -EINVAL; |
5473 | goto out_free; | |
5474 | } | |
1b09cd82 FF |
5475 | |
5476 | if (!wiphy->bands[band]) | |
5477 | continue; | |
5478 | ||
34850ab2 JB |
5479 | err = ieee80211_get_ratemask(wiphy->bands[band], |
5480 | nla_data(attr), | |
5481 | nla_len(attr), | |
5482 | &request->rates[band]); | |
5483 | if (err) | |
5484 | goto out_free; | |
5485 | } | |
5486 | } | |
5487 | ||
46856bbf | 5488 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5489 | request->flags = nla_get_u32( |
5490 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5491 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5492 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5493 | err = -EOPNOTSUPP; |
5494 | goto out_free; | |
5495 | } | |
5496 | } | |
ed473771 | 5497 | |
e9f935e3 RM |
5498 | request->no_cck = |
5499 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5500 | ||
fd014284 | 5501 | request->wdev = wdev; |
79c97e97 | 5502 | request->wiphy = &rdev->wiphy; |
15d6030b | 5503 | request->scan_start = jiffies; |
2a519311 | 5504 | |
79c97e97 | 5505 | rdev->scan_req = request; |
e35e4d28 | 5506 | err = rdev_scan(rdev, request); |
2a519311 | 5507 | |
463d0183 | 5508 | if (!err) { |
fd014284 JB |
5509 | nl80211_send_scan_start(rdev, wdev); |
5510 | if (wdev->netdev) | |
5511 | dev_hold(wdev->netdev); | |
4c476991 | 5512 | } else { |
2a519311 | 5513 | out_free: |
79c97e97 | 5514 | rdev->scan_req = NULL; |
2a519311 JB |
5515 | kfree(request); |
5516 | } | |
3b85875a | 5517 | |
f9f47529 | 5518 | unlock: |
2a519311 JB |
5519 | return err; |
5520 | } | |
5521 | ||
807f8a8c LC |
5522 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
5523 | struct genl_info *info) | |
5524 | { | |
5525 | struct cfg80211_sched_scan_request *request; | |
5526 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5527 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
5528 | struct nlattr *attr; |
5529 | struct wiphy *wiphy; | |
a1f1c21c | 5530 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5531 | u32 interval; |
807f8a8c LC |
5532 | enum ieee80211_band band; |
5533 | size_t ie_len; | |
a1f1c21c | 5534 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 5535 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c LC |
5536 | |
5537 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5538 | !rdev->ops->sched_scan_start) | |
5539 | return -EOPNOTSUPP; | |
5540 | ||
5541 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
5542 | return -EINVAL; | |
5543 | ||
bbe6ad6d LC |
5544 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5545 | return -EINVAL; | |
5546 | ||
5547 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
5548 | if (interval == 0) | |
5549 | return -EINVAL; | |
5550 | ||
807f8a8c LC |
5551 | wiphy = &rdev->wiphy; |
5552 | ||
5553 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5554 | n_channels = validate_scan_freqs( | |
5555 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
5556 | if (!n_channels) | |
5557 | return -EINVAL; | |
5558 | } else { | |
bdfbec2d | 5559 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
5560 | } |
5561 | ||
5562 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5563 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5564 | tmp) | |
5565 | n_ssids++; | |
5566 | ||
93b6aa69 | 5567 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
5568 | return -EINVAL; |
5569 | ||
ea73cbce JB |
5570 | /* |
5571 | * First, count the number of 'real' matchsets. Due to an issue with | |
5572 | * the old implementation, matchsets containing only the RSSI attribute | |
5573 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
5574 | * RSSI for all matchsets, rather than their own matchset for reporting | |
5575 | * all APs with a strong RSSI. This is needed to be compatible with | |
5576 | * older userspace that treated a matchset with only the RSSI as the | |
5577 | * global RSSI for all other matchsets - if there are other matchsets. | |
5578 | */ | |
5579 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
a1f1c21c LC |
5580 | nla_for_each_nested(attr, |
5581 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
ea73cbce JB |
5582 | tmp) { |
5583 | struct nlattr *rssi; | |
5584 | ||
5585 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5586 | nla_data(attr), nla_len(attr), | |
5587 | nl80211_match_policy); | |
5588 | if (err) | |
5589 | return err; | |
5590 | /* add other standalone attributes here */ | |
5591 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | |
5592 | n_match_sets++; | |
5593 | continue; | |
5594 | } | |
5595 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
5596 | if (rssi) | |
5597 | default_match_rssi = nla_get_s32(rssi); | |
5598 | } | |
5599 | } | |
5600 | ||
5601 | /* However, if there's no other matchset, add the RSSI one */ | |
5602 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
5603 | n_match_sets = 1; | |
a1f1c21c LC |
5604 | |
5605 | if (n_match_sets > wiphy->max_match_sets) | |
5606 | return -EINVAL; | |
5607 | ||
807f8a8c LC |
5608 | if (info->attrs[NL80211_ATTR_IE]) |
5609 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5610 | else | |
5611 | ie_len = 0; | |
5612 | ||
5a865bad | 5613 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
5614 | return -EINVAL; |
5615 | ||
c10841ca LC |
5616 | if (rdev->sched_scan_req) { |
5617 | err = -EINPROGRESS; | |
5618 | goto out; | |
5619 | } | |
5620 | ||
807f8a8c | 5621 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 5622 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 5623 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 5624 | + sizeof(*request->channels) * n_channels |
807f8a8c | 5625 | + ie_len, GFP_KERNEL); |
c10841ca LC |
5626 | if (!request) { |
5627 | err = -ENOMEM; | |
5628 | goto out; | |
5629 | } | |
807f8a8c LC |
5630 | |
5631 | if (n_ssids) | |
5632 | request->ssids = (void *)&request->channels[n_channels]; | |
5633 | request->n_ssids = n_ssids; | |
5634 | if (ie_len) { | |
5635 | if (request->ssids) | |
5636 | request->ie = (void *)(request->ssids + n_ssids); | |
5637 | else | |
5638 | request->ie = (void *)(request->channels + n_channels); | |
5639 | } | |
5640 | ||
a1f1c21c LC |
5641 | if (n_match_sets) { |
5642 | if (request->ie) | |
5643 | request->match_sets = (void *)(request->ie + ie_len); | |
5644 | else if (request->ssids) | |
5645 | request->match_sets = | |
5646 | (void *)(request->ssids + n_ssids); | |
5647 | else | |
5648 | request->match_sets = | |
5649 | (void *)(request->channels + n_channels); | |
5650 | } | |
5651 | request->n_match_sets = n_match_sets; | |
5652 | ||
807f8a8c LC |
5653 | i = 0; |
5654 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5655 | /* user specified, bail out if channel not found */ | |
5656 | nla_for_each_nested(attr, | |
5657 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
5658 | tmp) { | |
5659 | struct ieee80211_channel *chan; | |
5660 | ||
5661 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5662 | ||
5663 | if (!chan) { | |
5664 | err = -EINVAL; | |
5665 | goto out_free; | |
5666 | } | |
5667 | ||
5668 | /* ignore disabled channels */ | |
5669 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5670 | continue; | |
5671 | ||
5672 | request->channels[i] = chan; | |
5673 | i++; | |
5674 | } | |
5675 | } else { | |
5676 | /* all channels */ | |
5677 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5678 | int j; | |
5679 | if (!wiphy->bands[band]) | |
5680 | continue; | |
5681 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
5682 | struct ieee80211_channel *chan; | |
5683 | ||
5684 | chan = &wiphy->bands[band]->channels[j]; | |
5685 | ||
5686 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5687 | continue; | |
5688 | ||
5689 | request->channels[i] = chan; | |
5690 | i++; | |
5691 | } | |
5692 | } | |
5693 | } | |
5694 | ||
5695 | if (!i) { | |
5696 | err = -EINVAL; | |
5697 | goto out_free; | |
5698 | } | |
5699 | ||
5700 | request->n_channels = i; | |
5701 | ||
5702 | i = 0; | |
5703 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5704 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5705 | tmp) { | |
57a27e1d | 5706 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
5707 | err = -EINVAL; |
5708 | goto out_free; | |
5709 | } | |
57a27e1d | 5710 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
5711 | memcpy(request->ssids[i].ssid, nla_data(attr), |
5712 | nla_len(attr)); | |
807f8a8c LC |
5713 | i++; |
5714 | } | |
5715 | } | |
5716 | ||
a1f1c21c LC |
5717 | i = 0; |
5718 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
5719 | nla_for_each_nested(attr, | |
5720 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5721 | tmp) { | |
88e920b4 | 5722 | struct nlattr *ssid, *rssi; |
a1f1c21c | 5723 | |
ae811e21 JB |
5724 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
5725 | nla_data(attr), nla_len(attr), | |
5726 | nl80211_match_policy); | |
5727 | if (err) | |
5728 | goto out_free; | |
4a4ab0d7 | 5729 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 5730 | if (ssid) { |
ea73cbce JB |
5731 | if (WARN_ON(i >= n_match_sets)) { |
5732 | /* this indicates a programming error, | |
5733 | * the loop above should have verified | |
5734 | * things properly | |
5735 | */ | |
5736 | err = -EINVAL; | |
5737 | goto out_free; | |
5738 | } | |
5739 | ||
a1f1c21c LC |
5740 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
5741 | err = -EINVAL; | |
5742 | goto out_free; | |
5743 | } | |
5744 | memcpy(request->match_sets[i].ssid.ssid, | |
5745 | nla_data(ssid), nla_len(ssid)); | |
5746 | request->match_sets[i].ssid.ssid_len = | |
5747 | nla_len(ssid); | |
ea73cbce JB |
5748 | /* special attribute - old implemenation w/a */ |
5749 | request->match_sets[i].rssi_thold = | |
5750 | default_match_rssi; | |
5751 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
5752 | if (rssi) | |
5753 | request->match_sets[i].rssi_thold = | |
5754 | nla_get_s32(rssi); | |
a1f1c21c LC |
5755 | } |
5756 | i++; | |
5757 | } | |
ea73cbce JB |
5758 | |
5759 | /* there was no other matchset, so the RSSI one is alone */ | |
5760 | if (i == 0) | |
5761 | request->match_sets[0].rssi_thold = default_match_rssi; | |
5762 | ||
5763 | request->min_rssi_thold = INT_MAX; | |
5764 | for (i = 0; i < n_match_sets; i++) | |
5765 | request->min_rssi_thold = | |
5766 | min(request->match_sets[i].rssi_thold, | |
5767 | request->min_rssi_thold); | |
5768 | } else { | |
5769 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
5770 | } |
5771 | ||
9900e484 JB |
5772 | if (ie_len) { |
5773 | request->ie_len = ie_len; | |
807f8a8c LC |
5774 | memcpy((void *)request->ie, |
5775 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5776 | request->ie_len); | |
5777 | } | |
5778 | ||
46856bbf | 5779 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5780 | request->flags = nla_get_u32( |
5781 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5782 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5783 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5784 | err = -EOPNOTSUPP; |
5785 | goto out_free; | |
5786 | } | |
5787 | } | |
ed473771 | 5788 | |
807f8a8c LC |
5789 | request->dev = dev; |
5790 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 5791 | request->interval = interval; |
15d6030b | 5792 | request->scan_start = jiffies; |
807f8a8c | 5793 | |
e35e4d28 | 5794 | err = rdev_sched_scan_start(rdev, dev, request); |
807f8a8c LC |
5795 | if (!err) { |
5796 | rdev->sched_scan_req = request; | |
5797 | nl80211_send_sched_scan(rdev, dev, | |
5798 | NL80211_CMD_START_SCHED_SCAN); | |
5799 | goto out; | |
5800 | } | |
5801 | ||
5802 | out_free: | |
5803 | kfree(request); | |
5804 | out: | |
5805 | return err; | |
5806 | } | |
5807 | ||
5808 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
5809 | struct genl_info *info) | |
5810 | { | |
5811 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5812 | ||
5813 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5814 | !rdev->ops->sched_scan_stop) | |
5815 | return -EOPNOTSUPP; | |
5816 | ||
5fe231e8 | 5817 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
5818 | } |
5819 | ||
04f39047 SW |
5820 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
5821 | struct genl_info *info) | |
5822 | { | |
5823 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5824 | struct net_device *dev = info->user_ptr[1]; | |
5825 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5826 | struct cfg80211_chan_def chandef; | |
55f7435c | 5827 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 5828 | unsigned int cac_time_ms; |
04f39047 SW |
5829 | int err; |
5830 | ||
55f7435c LR |
5831 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
5832 | if (dfs_region == NL80211_DFS_UNSET) | |
5833 | return -EINVAL; | |
5834 | ||
04f39047 SW |
5835 | err = nl80211_parse_chandef(rdev, info, &chandef); |
5836 | if (err) | |
5837 | return err; | |
5838 | ||
ff311bc1 SW |
5839 | if (netif_carrier_ok(dev)) |
5840 | return -EBUSY; | |
5841 | ||
04f39047 SW |
5842 | if (wdev->cac_started) |
5843 | return -EBUSY; | |
5844 | ||
2beb6dab | 5845 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
00ec75fc | 5846 | wdev->iftype); |
04f39047 SW |
5847 | if (err < 0) |
5848 | return err; | |
5849 | ||
5850 | if (err == 0) | |
5851 | return -EINVAL; | |
5852 | ||
fe7c3a1f | 5853 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
5854 | return -EINVAL; |
5855 | ||
5856 | if (!rdev->ops->start_radar_detection) | |
5857 | return -EOPNOTSUPP; | |
5858 | ||
31559f35 JD |
5859 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
5860 | if (WARN_ON(!cac_time_ms)) | |
5861 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
5862 | ||
5863 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, | |
5864 | cac_time_ms); | |
04f39047 | 5865 | if (!err) { |
9e0e2961 | 5866 | wdev->chandef = chandef; |
04f39047 SW |
5867 | wdev->cac_started = true; |
5868 | wdev->cac_start_time = jiffies; | |
31559f35 | 5869 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 5870 | } |
04f39047 SW |
5871 | return err; |
5872 | } | |
5873 | ||
16ef1fe2 SW |
5874 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
5875 | { | |
5876 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5877 | struct net_device *dev = info->user_ptr[1]; | |
5878 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5879 | struct cfg80211_csa_settings params; | |
5880 | /* csa_attrs is defined static to avoid waste of stack size - this | |
5881 | * function is called under RTNL lock, so this should not be a problem. | |
5882 | */ | |
5883 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
5884 | u8 radar_detect_width = 0; | |
5885 | int err; | |
ee4bc9e7 | 5886 | bool need_new_beacon = false; |
9a774c78 | 5887 | int len, i; |
16ef1fe2 SW |
5888 | |
5889 | if (!rdev->ops->channel_switch || | |
5890 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
5891 | return -EOPNOTSUPP; | |
5892 | ||
ee4bc9e7 SW |
5893 | switch (dev->ieee80211_ptr->iftype) { |
5894 | case NL80211_IFTYPE_AP: | |
5895 | case NL80211_IFTYPE_P2P_GO: | |
5896 | need_new_beacon = true; | |
5897 | ||
5898 | /* useless if AP is not running */ | |
5899 | if (!wdev->beacon_interval) | |
1ff79dfa | 5900 | return -ENOTCONN; |
ee4bc9e7 SW |
5901 | break; |
5902 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
5903 | if (!wdev->ssid_len) |
5904 | return -ENOTCONN; | |
5905 | break; | |
c6da674a | 5906 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
5907 | if (!wdev->mesh_id_len) |
5908 | return -ENOTCONN; | |
ee4bc9e7 SW |
5909 | break; |
5910 | default: | |
16ef1fe2 | 5911 | return -EOPNOTSUPP; |
ee4bc9e7 | 5912 | } |
16ef1fe2 SW |
5913 | |
5914 | memset(¶ms, 0, sizeof(params)); | |
5915 | ||
5916 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
5917 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
5918 | return -EINVAL; | |
5919 | ||
5920 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 5921 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
5922 | return -EINVAL; |
5923 | ||
5924 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
5925 | ||
ee4bc9e7 SW |
5926 | if (!need_new_beacon) |
5927 | goto skip_beacons; | |
5928 | ||
16ef1fe2 SW |
5929 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
5930 | if (err) | |
5931 | return err; | |
5932 | ||
5933 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
5934 | info->attrs[NL80211_ATTR_CSA_IES], | |
5935 | nl80211_policy); | |
5936 | if (err) | |
5937 | return err; | |
5938 | ||
5939 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
5940 | if (err) | |
5941 | return err; | |
5942 | ||
5943 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
5944 | return -EINVAL; | |
5945 | ||
9a774c78 AO |
5946 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
5947 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
5948 | return -EINVAL; |
5949 | ||
9a774c78 AO |
5950 | params.n_counter_offsets_beacon = len / sizeof(u16); |
5951 | if (rdev->wiphy.max_num_csa_counters && | |
5952 | (params.n_counter_offsets_beacon > | |
5953 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
5954 | return -EINVAL; |
5955 | ||
9a774c78 AO |
5956 | params.counter_offsets_beacon = |
5957 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
5958 | ||
5959 | /* sanity checks - counters should fit and be the same */ | |
5960 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
5961 | u16 offset = params.counter_offsets_beacon[i]; | |
5962 | ||
5963 | if (offset >= params.beacon_csa.tail_len) | |
5964 | return -EINVAL; | |
5965 | ||
5966 | if (params.beacon_csa.tail[offset] != params.count) | |
5967 | return -EINVAL; | |
5968 | } | |
5969 | ||
16ef1fe2 | 5970 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
5971 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
5972 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
5973 | return -EINVAL; |
5974 | ||
9a774c78 AO |
5975 | params.n_counter_offsets_presp = len / sizeof(u16); |
5976 | if (rdev->wiphy.max_num_csa_counters && | |
5977 | (params.n_counter_offsets_beacon > | |
5978 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 | 5979 | return -EINVAL; |
9a774c78 AO |
5980 | |
5981 | params.counter_offsets_presp = | |
5982 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
5983 | ||
5984 | /* sanity checks - counters should fit and be the same */ | |
5985 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
5986 | u16 offset = params.counter_offsets_presp[i]; | |
5987 | ||
5988 | if (offset >= params.beacon_csa.probe_resp_len) | |
5989 | return -EINVAL; | |
5990 | ||
5991 | if (params.beacon_csa.probe_resp[offset] != | |
5992 | params.count) | |
5993 | return -EINVAL; | |
5994 | } | |
16ef1fe2 SW |
5995 | } |
5996 | ||
ee4bc9e7 | 5997 | skip_beacons: |
16ef1fe2 SW |
5998 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
5999 | if (err) | |
6000 | return err; | |
6001 | ||
174e0cd2 IP |
6002 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
6003 | wdev->iftype)) | |
16ef1fe2 SW |
6004 | return -EINVAL; |
6005 | ||
2beb6dab LC |
6006 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
6007 | ¶ms.chandef, | |
6008 | wdev->iftype); | |
6009 | if (err < 0) | |
6010 | return err; | |
6011 | ||
6012 | if (err > 0) { | |
6013 | radar_detect_width = BIT(params.chandef.width); | |
6014 | params.radar_required = true; | |
16ef1fe2 SW |
6015 | } |
6016 | ||
16ef1fe2 SW |
6017 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
6018 | params.block_tx = true; | |
6019 | ||
c56589ed SW |
6020 | wdev_lock(wdev); |
6021 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
6022 | wdev_unlock(wdev); | |
6023 | ||
6024 | return err; | |
16ef1fe2 SW |
6025 | } |
6026 | ||
9720bb3a JB |
6027 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
6028 | u32 seq, int flags, | |
2a519311 | 6029 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
6030 | struct wireless_dev *wdev, |
6031 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 6032 | { |
48ab905d | 6033 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 6034 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
6035 | void *hdr; |
6036 | struct nlattr *bss; | |
48ab905d JB |
6037 | |
6038 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 6039 | |
15e47304 | 6040 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
6041 | NL80211_CMD_NEW_SCAN_RESULTS); |
6042 | if (!hdr) | |
6043 | return -1; | |
6044 | ||
9720bb3a JB |
6045 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
6046 | ||
97990a06 JB |
6047 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
6048 | goto nla_put_failure; | |
6049 | if (wdev->netdev && | |
9360ffd1 DM |
6050 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
6051 | goto nla_put_failure; | |
97990a06 JB |
6052 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
6053 | goto nla_put_failure; | |
2a519311 JB |
6054 | |
6055 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
6056 | if (!bss) | |
6057 | goto nla_put_failure; | |
9360ffd1 | 6058 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 6059 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 6060 | goto nla_put_failure; |
9caf0364 JB |
6061 | |
6062 | rcu_read_lock(); | |
0e227084 JB |
6063 | /* indicate whether we have probe response data or not */ |
6064 | if (rcu_access_pointer(res->proberesp_ies) && | |
6065 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
6066 | goto fail_unlock_rcu; | |
6067 | ||
6068 | /* this pointer prefers to be pointed to probe response data | |
6069 | * but is always valid | |
6070 | */ | |
9caf0364 | 6071 | ies = rcu_dereference(res->ies); |
8cef2c9d JB |
6072 | if (ies) { |
6073 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
6074 | goto fail_unlock_rcu; | |
8cef2c9d JB |
6075 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
6076 | ies->len, ies->data)) | |
6077 | goto fail_unlock_rcu; | |
9caf0364 | 6078 | } |
0e227084 JB |
6079 | |
6080 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 6081 | ies = rcu_dereference(res->beacon_ies); |
0e227084 JB |
6082 | if (ies && ies->from_beacon) { |
6083 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) | |
8cef2c9d JB |
6084 | goto fail_unlock_rcu; |
6085 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
6086 | ies->len, ies->data)) | |
6087 | goto fail_unlock_rcu; | |
9caf0364 JB |
6088 | } |
6089 | rcu_read_unlock(); | |
6090 | ||
9360ffd1 DM |
6091 | if (res->beacon_interval && |
6092 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
6093 | goto nla_put_failure; | |
6094 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
6095 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 6096 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
6097 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
6098 | jiffies_to_msecs(jiffies - intbss->ts))) | |
6099 | goto nla_put_failure; | |
2a519311 | 6100 | |
77965c97 | 6101 | switch (rdev->wiphy.signal_type) { |
2a519311 | 6102 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
6103 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
6104 | goto nla_put_failure; | |
2a519311 JB |
6105 | break; |
6106 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
6107 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
6108 | goto nla_put_failure; | |
2a519311 JB |
6109 | break; |
6110 | default: | |
6111 | break; | |
6112 | } | |
6113 | ||
48ab905d | 6114 | switch (wdev->iftype) { |
074ac8df | 6115 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 6116 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
6117 | if (intbss == wdev->current_bss && |
6118 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6119 | NL80211_BSS_STATUS_ASSOCIATED)) | |
6120 | goto nla_put_failure; | |
48ab905d JB |
6121 | break; |
6122 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
6123 | if (intbss == wdev->current_bss && |
6124 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6125 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
6126 | goto nla_put_failure; | |
48ab905d JB |
6127 | break; |
6128 | default: | |
6129 | break; | |
6130 | } | |
6131 | ||
2a519311 JB |
6132 | nla_nest_end(msg, bss); |
6133 | ||
6134 | return genlmsg_end(msg, hdr); | |
6135 | ||
8cef2c9d JB |
6136 | fail_unlock_rcu: |
6137 | rcu_read_unlock(); | |
2a519311 JB |
6138 | nla_put_failure: |
6139 | genlmsg_cancel(msg, hdr); | |
6140 | return -EMSGSIZE; | |
6141 | } | |
6142 | ||
97990a06 | 6143 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 6144 | { |
48ab905d | 6145 | struct cfg80211_registered_device *rdev; |
2a519311 | 6146 | struct cfg80211_internal_bss *scan; |
48ab905d | 6147 | struct wireless_dev *wdev; |
97990a06 | 6148 | int start = cb->args[2], idx = 0; |
2a519311 JB |
6149 | int err; |
6150 | ||
97990a06 | 6151 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6152 | if (err) |
6153 | return err; | |
2a519311 | 6154 | |
48ab905d JB |
6155 | wdev_lock(wdev); |
6156 | spin_lock_bh(&rdev->bss_lock); | |
6157 | cfg80211_bss_expire(rdev); | |
6158 | ||
9720bb3a JB |
6159 | cb->seq = rdev->bss_generation; |
6160 | ||
48ab905d | 6161 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
6162 | if (++idx <= start) |
6163 | continue; | |
9720bb3a | 6164 | if (nl80211_send_bss(skb, cb, |
2a519311 | 6165 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 6166 | rdev, wdev, scan) < 0) { |
2a519311 | 6167 | idx--; |
67748893 | 6168 | break; |
2a519311 JB |
6169 | } |
6170 | } | |
6171 | ||
48ab905d JB |
6172 | spin_unlock_bh(&rdev->bss_lock); |
6173 | wdev_unlock(wdev); | |
2a519311 | 6174 | |
97990a06 JB |
6175 | cb->args[2] = idx; |
6176 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 6177 | |
67748893 | 6178 | return skb->len; |
2a519311 JB |
6179 | } |
6180 | ||
15e47304 | 6181 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
6182 | int flags, struct net_device *dev, |
6183 | struct survey_info *survey) | |
6184 | { | |
6185 | void *hdr; | |
6186 | struct nlattr *infoattr; | |
6187 | ||
15e47304 | 6188 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
6189 | NL80211_CMD_NEW_SURVEY_RESULTS); |
6190 | if (!hdr) | |
6191 | return -ENOMEM; | |
6192 | ||
9360ffd1 DM |
6193 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
6194 | goto nla_put_failure; | |
61fa713c HS |
6195 | |
6196 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
6197 | if (!infoattr) | |
6198 | goto nla_put_failure; | |
6199 | ||
9360ffd1 DM |
6200 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
6201 | survey->channel->center_freq)) | |
6202 | goto nla_put_failure; | |
6203 | ||
6204 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
6205 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
6206 | goto nla_put_failure; | |
6207 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
6208 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
6209 | goto nla_put_failure; | |
6210 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
6211 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
6212 | survey->channel_time)) | |
6213 | goto nla_put_failure; | |
6214 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
6215 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
6216 | survey->channel_time_busy)) | |
6217 | goto nla_put_failure; | |
6218 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
6219 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
6220 | survey->channel_time_ext_busy)) | |
6221 | goto nla_put_failure; | |
6222 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
6223 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
6224 | survey->channel_time_rx)) | |
6225 | goto nla_put_failure; | |
6226 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
6227 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
6228 | survey->channel_time_tx)) | |
6229 | goto nla_put_failure; | |
61fa713c HS |
6230 | |
6231 | nla_nest_end(msg, infoattr); | |
6232 | ||
6233 | return genlmsg_end(msg, hdr); | |
6234 | ||
6235 | nla_put_failure: | |
6236 | genlmsg_cancel(msg, hdr); | |
6237 | return -EMSGSIZE; | |
6238 | } | |
6239 | ||
6240 | static int nl80211_dump_survey(struct sk_buff *skb, | |
6241 | struct netlink_callback *cb) | |
6242 | { | |
6243 | struct survey_info survey; | |
1b8ec87a | 6244 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
6245 | struct wireless_dev *wdev; |
6246 | int survey_idx = cb->args[2]; | |
61fa713c HS |
6247 | int res; |
6248 | ||
1b8ec87a | 6249 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6250 | if (res) |
6251 | return res; | |
61fa713c | 6252 | |
97990a06 JB |
6253 | if (!wdev->netdev) { |
6254 | res = -EINVAL; | |
6255 | goto out_err; | |
6256 | } | |
6257 | ||
1b8ec87a | 6258 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
6259 | res = -EOPNOTSUPP; |
6260 | goto out_err; | |
6261 | } | |
6262 | ||
6263 | while (1) { | |
180cdc79 LR |
6264 | struct ieee80211_channel *chan; |
6265 | ||
1b8ec87a | 6266 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
6267 | if (res == -ENOENT) |
6268 | break; | |
6269 | if (res) | |
6270 | goto out_err; | |
6271 | ||
180cdc79 LR |
6272 | /* Survey without a channel doesn't make sense */ |
6273 | if (!survey.channel) { | |
6274 | res = -EINVAL; | |
6275 | goto out; | |
6276 | } | |
6277 | ||
1b8ec87a | 6278 | chan = ieee80211_get_channel(&rdev->wiphy, |
180cdc79 LR |
6279 | survey.channel->center_freq); |
6280 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
6281 | survey_idx++; | |
6282 | continue; | |
6283 | } | |
6284 | ||
61fa713c | 6285 | if (nl80211_send_survey(skb, |
15e47304 | 6286 | NETLINK_CB(cb->skb).portid, |
61fa713c | 6287 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 6288 | wdev->netdev, &survey) < 0) |
61fa713c HS |
6289 | goto out; |
6290 | survey_idx++; | |
6291 | } | |
6292 | ||
6293 | out: | |
97990a06 | 6294 | cb->args[2] = survey_idx; |
61fa713c HS |
6295 | res = skb->len; |
6296 | out_err: | |
1b8ec87a | 6297 | nl80211_finish_wdev_dump(rdev); |
61fa713c HS |
6298 | return res; |
6299 | } | |
6300 | ||
b23aa676 SO |
6301 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
6302 | { | |
6303 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
6304 | NL80211_WPA_VERSION_2)); | |
6305 | } | |
6306 | ||
636a5d36 JM |
6307 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
6308 | { | |
4c476991 JB |
6309 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6310 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6311 | struct ieee80211_channel *chan; |
e39e5b5e JM |
6312 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
6313 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 6314 | enum nl80211_auth_type auth_type; |
fffd0934 | 6315 | struct key_parse key; |
d5cdfacb | 6316 | bool local_state_change; |
636a5d36 | 6317 | |
f4a11bb0 JB |
6318 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6319 | return -EINVAL; | |
6320 | ||
6321 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6322 | return -EINVAL; | |
6323 | ||
1778092e JM |
6324 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
6325 | return -EINVAL; | |
6326 | ||
19957bb3 JB |
6327 | if (!info->attrs[NL80211_ATTR_SSID]) |
6328 | return -EINVAL; | |
6329 | ||
6330 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
6331 | return -EINVAL; | |
6332 | ||
fffd0934 JB |
6333 | err = nl80211_parse_key(info, &key); |
6334 | if (err) | |
6335 | return err; | |
6336 | ||
6337 | if (key.idx >= 0) { | |
e31b8213 JB |
6338 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
6339 | return -EINVAL; | |
fffd0934 JB |
6340 | if (!key.p.key || !key.p.key_len) |
6341 | return -EINVAL; | |
6342 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
6343 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
6344 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
6345 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
6346 | return -EINVAL; | |
6347 | if (key.idx > 4) | |
6348 | return -EINVAL; | |
6349 | } else { | |
6350 | key.p.key_len = 0; | |
6351 | key.p.key = NULL; | |
6352 | } | |
6353 | ||
afea0b7a JB |
6354 | if (key.idx >= 0) { |
6355 | int i; | |
6356 | bool ok = false; | |
6357 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
6358 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
6359 | ok = true; | |
6360 | break; | |
6361 | } | |
6362 | } | |
4c476991 JB |
6363 | if (!ok) |
6364 | return -EINVAL; | |
afea0b7a JB |
6365 | } |
6366 | ||
4c476991 JB |
6367 | if (!rdev->ops->auth) |
6368 | return -EOPNOTSUPP; | |
636a5d36 | 6369 | |
074ac8df | 6370 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6371 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6372 | return -EOPNOTSUPP; | |
eec60b03 | 6373 | |
19957bb3 | 6374 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
6375 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6376 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6377 | if (!chan) | |
4c476991 | 6378 | return -EINVAL; |
636a5d36 | 6379 | |
19957bb3 JB |
6380 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6381 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6382 | |
6383 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6384 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6385 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6386 | } |
6387 | ||
19957bb3 | 6388 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 6389 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 6390 | return -EINVAL; |
636a5d36 | 6391 | |
e39e5b5e JM |
6392 | if (auth_type == NL80211_AUTHTYPE_SAE && |
6393 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
6394 | return -EINVAL; | |
6395 | ||
6396 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
6397 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
6398 | return -EINVAL; | |
6399 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6400 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6401 | /* need to include at least Auth Transaction and Status Code */ | |
6402 | if (sae_data_len < 4) | |
6403 | return -EINVAL; | |
6404 | } | |
6405 | ||
d5cdfacb JM |
6406 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6407 | ||
95de817b JB |
6408 | /* |
6409 | * Since we no longer track auth state, ignore | |
6410 | * requests to only change local state. | |
6411 | */ | |
6412 | if (local_state_change) | |
6413 | return 0; | |
6414 | ||
91bf9b26 JB |
6415 | wdev_lock(dev->ieee80211_ptr); |
6416 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
6417 | ssid, ssid_len, ie, ie_len, | |
6418 | key.p.key, key.p.key_len, key.idx, | |
6419 | sae_data, sae_data_len); | |
6420 | wdev_unlock(dev->ieee80211_ptr); | |
6421 | return err; | |
636a5d36 JM |
6422 | } |
6423 | ||
c0692b8f JB |
6424 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6425 | struct genl_info *info, | |
3dc27d25 JB |
6426 | struct cfg80211_crypto_settings *settings, |
6427 | int cipher_limit) | |
b23aa676 | 6428 | { |
c0b2bbd8 JB |
6429 | memset(settings, 0, sizeof(*settings)); |
6430 | ||
b23aa676 SO |
6431 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6432 | ||
c0692b8f JB |
6433 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6434 | u16 proto; | |
6435 | proto = nla_get_u16( | |
6436 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6437 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6438 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6439 | proto != ETH_P_PAE) | |
6440 | return -EINVAL; | |
6441 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6442 | settings->control_port_no_encrypt = true; | |
6443 | } else | |
6444 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6445 | ||
b23aa676 SO |
6446 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6447 | void *data; | |
6448 | int len, i; | |
6449 | ||
6450 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6451 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6452 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6453 | ||
6454 | if (len % sizeof(u32)) | |
6455 | return -EINVAL; | |
6456 | ||
3dc27d25 | 6457 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6458 | return -EINVAL; |
6459 | ||
6460 | memcpy(settings->ciphers_pairwise, data, len); | |
6461 | ||
6462 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6463 | if (!cfg80211_supported_cipher_suite( |
6464 | &rdev->wiphy, | |
b23aa676 SO |
6465 | settings->ciphers_pairwise[i])) |
6466 | return -EINVAL; | |
6467 | } | |
6468 | ||
6469 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6470 | settings->cipher_group = | |
6471 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6472 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6473 | settings->cipher_group)) | |
b23aa676 SO |
6474 | return -EINVAL; |
6475 | } | |
6476 | ||
6477 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6478 | settings->wpa_versions = | |
6479 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6480 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6481 | return -EINVAL; | |
6482 | } | |
6483 | ||
6484 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6485 | void *data; | |
6d30240e | 6486 | int len; |
b23aa676 SO |
6487 | |
6488 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6489 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6490 | settings->n_akm_suites = len / sizeof(u32); | |
6491 | ||
6492 | if (len % sizeof(u32)) | |
6493 | return -EINVAL; | |
6494 | ||
1b9ca027 JM |
6495 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6496 | return -EINVAL; | |
6497 | ||
b23aa676 | 6498 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6499 | } |
6500 | ||
6501 | return 0; | |
6502 | } | |
6503 | ||
636a5d36 JM |
6504 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6505 | { | |
4c476991 JB |
6506 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6507 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6508 | struct ieee80211_channel *chan; |
f62fab73 JB |
6509 | struct cfg80211_assoc_request req = {}; |
6510 | const u8 *bssid, *ssid; | |
6511 | int err, ssid_len = 0; | |
636a5d36 | 6512 | |
f4a11bb0 JB |
6513 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6514 | return -EINVAL; | |
6515 | ||
6516 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6517 | !info->attrs[NL80211_ATTR_SSID] || |
6518 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6519 | return -EINVAL; |
6520 | ||
4c476991 JB |
6521 | if (!rdev->ops->assoc) |
6522 | return -EOPNOTSUPP; | |
636a5d36 | 6523 | |
074ac8df | 6524 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6525 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6526 | return -EOPNOTSUPP; | |
eec60b03 | 6527 | |
19957bb3 | 6528 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6529 | |
664834de JM |
6530 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6531 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6532 | if (!chan) | |
4c476991 | 6533 | return -EINVAL; |
636a5d36 | 6534 | |
19957bb3 JB |
6535 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6536 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6537 | |
6538 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6539 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6540 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6541 | } |
6542 | ||
dc6382ce | 6543 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6544 | enum nl80211_mfp mfp = |
dc6382ce | 6545 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6546 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6547 | req.use_mfp = true; |
4c476991 JB |
6548 | else if (mfp != NL80211_MFP_NO) |
6549 | return -EINVAL; | |
dc6382ce JM |
6550 | } |
6551 | ||
3e5d7649 | 6552 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 6553 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 6554 | |
7e7c8926 | 6555 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 6556 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
6557 | |
6558 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
6559 | memcpy(&req.ht_capa_mask, |
6560 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6561 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
6562 | |
6563 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 6564 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 6565 | return -EINVAL; |
f62fab73 JB |
6566 | memcpy(&req.ht_capa, |
6567 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6568 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
6569 | } |
6570 | ||
ee2aca34 | 6571 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 6572 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
6573 | |
6574 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
6575 | memcpy(&req.vht_capa_mask, |
6576 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6577 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
6578 | |
6579 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 6580 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 6581 | return -EINVAL; |
f62fab73 JB |
6582 | memcpy(&req.vht_capa, |
6583 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6584 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
6585 | } |
6586 | ||
f62fab73 | 6587 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
6588 | if (!err) { |
6589 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
6590 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
6591 | ssid, ssid_len, &req); | |
91bf9b26 JB |
6592 | wdev_unlock(dev->ieee80211_ptr); |
6593 | } | |
636a5d36 | 6594 | |
636a5d36 JM |
6595 | return err; |
6596 | } | |
6597 | ||
6598 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
6599 | { | |
4c476991 JB |
6600 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6601 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6602 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6603 | int ie_len = 0, err; |
19957bb3 | 6604 | u16 reason_code; |
d5cdfacb | 6605 | bool local_state_change; |
636a5d36 | 6606 | |
f4a11bb0 JB |
6607 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6608 | return -EINVAL; | |
6609 | ||
6610 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6611 | return -EINVAL; | |
6612 | ||
6613 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6614 | return -EINVAL; | |
6615 | ||
4c476991 JB |
6616 | if (!rdev->ops->deauth) |
6617 | return -EOPNOTSUPP; | |
636a5d36 | 6618 | |
074ac8df | 6619 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6620 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6621 | return -EOPNOTSUPP; | |
eec60b03 | 6622 | |
19957bb3 | 6623 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6624 | |
19957bb3 JB |
6625 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6626 | if (reason_code == 0) { | |
f4a11bb0 | 6627 | /* Reason Code 0 is reserved */ |
4c476991 | 6628 | return -EINVAL; |
255e737e | 6629 | } |
636a5d36 JM |
6630 | |
6631 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6632 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6633 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6634 | } |
6635 | ||
d5cdfacb JM |
6636 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6637 | ||
91bf9b26 JB |
6638 | wdev_lock(dev->ieee80211_ptr); |
6639 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
6640 | local_state_change); | |
6641 | wdev_unlock(dev->ieee80211_ptr); | |
6642 | return err; | |
636a5d36 JM |
6643 | } |
6644 | ||
6645 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
6646 | { | |
4c476991 JB |
6647 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6648 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6649 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6650 | int ie_len = 0, err; |
19957bb3 | 6651 | u16 reason_code; |
d5cdfacb | 6652 | bool local_state_change; |
636a5d36 | 6653 | |
f4a11bb0 JB |
6654 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6655 | return -EINVAL; | |
6656 | ||
6657 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6658 | return -EINVAL; | |
6659 | ||
6660 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6661 | return -EINVAL; | |
6662 | ||
4c476991 JB |
6663 | if (!rdev->ops->disassoc) |
6664 | return -EOPNOTSUPP; | |
636a5d36 | 6665 | |
074ac8df | 6666 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6667 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6668 | return -EOPNOTSUPP; | |
eec60b03 | 6669 | |
19957bb3 | 6670 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6671 | |
19957bb3 JB |
6672 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6673 | if (reason_code == 0) { | |
f4a11bb0 | 6674 | /* Reason Code 0 is reserved */ |
4c476991 | 6675 | return -EINVAL; |
255e737e | 6676 | } |
636a5d36 JM |
6677 | |
6678 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6679 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6680 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6681 | } |
6682 | ||
d5cdfacb JM |
6683 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6684 | ||
91bf9b26 JB |
6685 | wdev_lock(dev->ieee80211_ptr); |
6686 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
6687 | local_state_change); | |
6688 | wdev_unlock(dev->ieee80211_ptr); | |
6689 | return err; | |
636a5d36 JM |
6690 | } |
6691 | ||
dd5b4cc7 FF |
6692 | static bool |
6693 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
6694 | int mcast_rate[IEEE80211_NUM_BANDS], | |
6695 | int rateval) | |
6696 | { | |
6697 | struct wiphy *wiphy = &rdev->wiphy; | |
6698 | bool found = false; | |
6699 | int band, i; | |
6700 | ||
6701 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6702 | struct ieee80211_supported_band *sband; | |
6703 | ||
6704 | sband = wiphy->bands[band]; | |
6705 | if (!sband) | |
6706 | continue; | |
6707 | ||
6708 | for (i = 0; i < sband->n_bitrates; i++) { | |
6709 | if (sband->bitrates[i].bitrate == rateval) { | |
6710 | mcast_rate[band] = i + 1; | |
6711 | found = true; | |
6712 | break; | |
6713 | } | |
6714 | } | |
6715 | } | |
6716 | ||
6717 | return found; | |
6718 | } | |
6719 | ||
04a773ad JB |
6720 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
6721 | { | |
4c476991 JB |
6722 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6723 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
6724 | struct cfg80211_ibss_params ibss; |
6725 | struct wiphy *wiphy; | |
fffd0934 | 6726 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
6727 | int err; |
6728 | ||
8e30bc55 JB |
6729 | memset(&ibss, 0, sizeof(ibss)); |
6730 | ||
04a773ad JB |
6731 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6732 | return -EINVAL; | |
6733 | ||
683b6d3b | 6734 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
6735 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
6736 | return -EINVAL; | |
6737 | ||
8e30bc55 JB |
6738 | ibss.beacon_interval = 100; |
6739 | ||
6740 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
6741 | ibss.beacon_interval = | |
6742 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
6743 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
6744 | return -EINVAL; | |
6745 | } | |
6746 | ||
4c476991 JB |
6747 | if (!rdev->ops->join_ibss) |
6748 | return -EOPNOTSUPP; | |
04a773ad | 6749 | |
4c476991 JB |
6750 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6751 | return -EOPNOTSUPP; | |
04a773ad | 6752 | |
79c97e97 | 6753 | wiphy = &rdev->wiphy; |
04a773ad | 6754 | |
39193498 | 6755 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 6756 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
6757 | |
6758 | if (!is_valid_ether_addr(ibss.bssid)) | |
6759 | return -EINVAL; | |
6760 | } | |
04a773ad JB |
6761 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6762 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6763 | ||
6764 | if (info->attrs[NL80211_ATTR_IE]) { | |
6765 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6766 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6767 | } | |
6768 | ||
683b6d3b JB |
6769 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
6770 | if (err) | |
6771 | return err; | |
04a773ad | 6772 | |
174e0cd2 IP |
6773 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
6774 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
6775 | return -EINVAL; |
6776 | ||
2f301ab2 | 6777 | switch (ibss.chandef.width) { |
bf372645 SW |
6778 | case NL80211_CHAN_WIDTH_5: |
6779 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
6780 | case NL80211_CHAN_WIDTH_20_NOHT: |
6781 | break; | |
6782 | case NL80211_CHAN_WIDTH_20: | |
6783 | case NL80211_CHAN_WIDTH_40: | |
6784 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | |
6785 | break; | |
6786 | default: | |
c04d6150 | 6787 | return -EINVAL; |
2f301ab2 | 6788 | } |
db9c64cf | 6789 | |
04a773ad | 6790 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
6791 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
6792 | ||
fbd2c8dc TP |
6793 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6794 | u8 *rates = | |
6795 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6796 | int n_rates = | |
6797 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6798 | struct ieee80211_supported_band *sband = | |
683b6d3b | 6799 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 6800 | |
34850ab2 JB |
6801 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
6802 | &ibss.basic_rates); | |
6803 | if (err) | |
6804 | return err; | |
fbd2c8dc | 6805 | } |
dd5b4cc7 | 6806 | |
803768f5 SW |
6807 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
6808 | memcpy(&ibss.ht_capa_mask, | |
6809 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6810 | sizeof(ibss.ht_capa_mask)); | |
6811 | ||
6812 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
6813 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6814 | return -EINVAL; | |
6815 | memcpy(&ibss.ht_capa, | |
6816 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6817 | sizeof(ibss.ht_capa)); | |
6818 | } | |
6819 | ||
dd5b4cc7 FF |
6820 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
6821 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
6822 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6823 | return -EINVAL; | |
fbd2c8dc | 6824 | |
4c476991 | 6825 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
6826 | bool no_ht = false; |
6827 | ||
4c476991 | 6828 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
6829 | info->attrs[NL80211_ATTR_KEYS], |
6830 | &no_ht); | |
4c476991 JB |
6831 | if (IS_ERR(connkeys)) |
6832 | return PTR_ERR(connkeys); | |
de7044ee | 6833 | |
3d9d1d66 JB |
6834 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
6835 | no_ht) { | |
de7044ee SM |
6836 | kfree(connkeys); |
6837 | return -EINVAL; | |
6838 | } | |
4c476991 | 6839 | } |
04a773ad | 6840 | |
267335d6 AQ |
6841 | ibss.control_port = |
6842 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
6843 | ||
5336fa88 SW |
6844 | ibss.userspace_handles_dfs = |
6845 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
6846 | ||
4c476991 | 6847 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
6848 | if (err) |
6849 | kfree(connkeys); | |
04a773ad JB |
6850 | return err; |
6851 | } | |
6852 | ||
6853 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
6854 | { | |
4c476991 JB |
6855 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6856 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 6857 | |
4c476991 JB |
6858 | if (!rdev->ops->leave_ibss) |
6859 | return -EOPNOTSUPP; | |
04a773ad | 6860 | |
4c476991 JB |
6861 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6862 | return -EOPNOTSUPP; | |
04a773ad | 6863 | |
4c476991 | 6864 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
6865 | } |
6866 | ||
f4e583c8 AQ |
6867 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
6868 | { | |
6869 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6870 | struct net_device *dev = info->user_ptr[1]; | |
6871 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
6872 | u32 nla_rate; | |
6873 | int err; | |
6874 | ||
6875 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
6876 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
6877 | return -EOPNOTSUPP; | |
6878 | ||
6879 | if (!rdev->ops->set_mcast_rate) | |
6880 | return -EOPNOTSUPP; | |
6881 | ||
6882 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
6883 | ||
6884 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
6885 | return -EINVAL; | |
6886 | ||
6887 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
6888 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
6889 | return -EINVAL; | |
6890 | ||
6891 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
6892 | ||
6893 | return err; | |
6894 | } | |
6895 | ||
ad7e718c JB |
6896 | static struct sk_buff * |
6897 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
6898 | int approxlen, u32 portid, u32 seq, | |
6899 | enum nl80211_commands cmd, | |
567ffc35 JB |
6900 | enum nl80211_attrs attr, |
6901 | const struct nl80211_vendor_cmd_info *info, | |
6902 | gfp_t gfp) | |
ad7e718c JB |
6903 | { |
6904 | struct sk_buff *skb; | |
6905 | void *hdr; | |
6906 | struct nlattr *data; | |
6907 | ||
6908 | skb = nlmsg_new(approxlen + 100, gfp); | |
6909 | if (!skb) | |
6910 | return NULL; | |
6911 | ||
6912 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
6913 | if (!hdr) { | |
6914 | kfree_skb(skb); | |
6915 | return NULL; | |
6916 | } | |
6917 | ||
6918 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
6919 | goto nla_put_failure; | |
567ffc35 JB |
6920 | |
6921 | if (info) { | |
6922 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
6923 | info->vendor_id)) | |
6924 | goto nla_put_failure; | |
6925 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
6926 | info->subcmd)) | |
6927 | goto nla_put_failure; | |
6928 | } | |
6929 | ||
ad7e718c JB |
6930 | data = nla_nest_start(skb, attr); |
6931 | ||
6932 | ((void **)skb->cb)[0] = rdev; | |
6933 | ((void **)skb->cb)[1] = hdr; | |
6934 | ((void **)skb->cb)[2] = data; | |
6935 | ||
6936 | return skb; | |
6937 | ||
6938 | nla_put_failure: | |
6939 | kfree_skb(skb); | |
6940 | return NULL; | |
6941 | } | |
f4e583c8 | 6942 | |
e03ad6ea JB |
6943 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
6944 | enum nl80211_commands cmd, | |
6945 | enum nl80211_attrs attr, | |
6946 | int vendor_event_idx, | |
6947 | int approxlen, gfp_t gfp) | |
6948 | { | |
f26cbf40 | 6949 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
6950 | const struct nl80211_vendor_cmd_info *info; |
6951 | ||
6952 | switch (cmd) { | |
6953 | case NL80211_CMD_TESTMODE: | |
6954 | if (WARN_ON(vendor_event_idx != -1)) | |
6955 | return NULL; | |
6956 | info = NULL; | |
6957 | break; | |
6958 | case NL80211_CMD_VENDOR: | |
6959 | if (WARN_ON(vendor_event_idx < 0 || | |
6960 | vendor_event_idx >= wiphy->n_vendor_events)) | |
6961 | return NULL; | |
6962 | info = &wiphy->vendor_events[vendor_event_idx]; | |
6963 | break; | |
6964 | default: | |
6965 | WARN_ON(1); | |
6966 | return NULL; | |
6967 | } | |
6968 | ||
6969 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, | |
6970 | cmd, attr, info, gfp); | |
6971 | } | |
6972 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
6973 | ||
6974 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
6975 | { | |
6976 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
6977 | void *hdr = ((void **)skb->cb)[1]; | |
6978 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6979 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
6980 | ||
6981 | nla_nest_end(skb, data); | |
6982 | genlmsg_end(skb, hdr); | |
6983 | ||
6984 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
6985 | mcgrp = NL80211_MCGRP_VENDOR; | |
6986 | ||
6987 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
6988 | mcgrp, gfp); | |
6989 | } | |
6990 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
6991 | ||
aff89a9b | 6992 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
6993 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
6994 | { | |
4c476991 | 6995 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
6996 | struct wireless_dev *wdev = |
6997 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
6998 | int err; |
6999 | ||
fc73f11f DS |
7000 | if (!rdev->ops->testmode_cmd) |
7001 | return -EOPNOTSUPP; | |
7002 | ||
7003 | if (IS_ERR(wdev)) { | |
7004 | err = PTR_ERR(wdev); | |
7005 | if (err != -EINVAL) | |
7006 | return err; | |
7007 | wdev = NULL; | |
7008 | } else if (wdev->wiphy != &rdev->wiphy) { | |
7009 | return -EINVAL; | |
7010 | } | |
7011 | ||
aff89a9b JB |
7012 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
7013 | return -EINVAL; | |
7014 | ||
ad7e718c | 7015 | rdev->cur_cmd_info = info; |
fc73f11f | 7016 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
7017 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
7018 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 7019 | rdev->cur_cmd_info = NULL; |
aff89a9b | 7020 | |
aff89a9b JB |
7021 | return err; |
7022 | } | |
7023 | ||
71063f0e WYG |
7024 | static int nl80211_testmode_dump(struct sk_buff *skb, |
7025 | struct netlink_callback *cb) | |
7026 | { | |
00918d33 | 7027 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
7028 | int err; |
7029 | long phy_idx; | |
7030 | void *data = NULL; | |
7031 | int data_len = 0; | |
7032 | ||
5fe231e8 JB |
7033 | rtnl_lock(); |
7034 | ||
71063f0e WYG |
7035 | if (cb->args[0]) { |
7036 | /* | |
7037 | * 0 is a valid index, but not valid for args[0], | |
7038 | * so we need to offset by 1. | |
7039 | */ | |
7040 | phy_idx = cb->args[0] - 1; | |
7041 | } else { | |
7042 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
7043 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
7044 | nl80211_policy); | |
7045 | if (err) | |
5fe231e8 | 7046 | goto out_err; |
00918d33 | 7047 | |
2bd7e35d JB |
7048 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
7049 | nl80211_fam.attrbuf); | |
7050 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
7051 | err = PTR_ERR(rdev); |
7052 | goto out_err; | |
00918d33 | 7053 | } |
2bd7e35d JB |
7054 | phy_idx = rdev->wiphy_idx; |
7055 | rdev = NULL; | |
2bd7e35d | 7056 | |
71063f0e WYG |
7057 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
7058 | cb->args[1] = | |
7059 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
7060 | } | |
7061 | ||
7062 | if (cb->args[1]) { | |
7063 | data = nla_data((void *)cb->args[1]); | |
7064 | data_len = nla_len((void *)cb->args[1]); | |
7065 | } | |
7066 | ||
00918d33 JB |
7067 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
7068 | if (!rdev) { | |
5fe231e8 JB |
7069 | err = -ENOENT; |
7070 | goto out_err; | |
71063f0e | 7071 | } |
71063f0e | 7072 | |
00918d33 | 7073 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
7074 | err = -EOPNOTSUPP; |
7075 | goto out_err; | |
7076 | } | |
7077 | ||
7078 | while (1) { | |
15e47304 | 7079 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
7080 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
7081 | NL80211_CMD_TESTMODE); | |
7082 | struct nlattr *tmdata; | |
7083 | ||
cb35fba3 DC |
7084 | if (!hdr) |
7085 | break; | |
7086 | ||
9360ffd1 | 7087 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
7088 | genlmsg_cancel(skb, hdr); |
7089 | break; | |
7090 | } | |
7091 | ||
7092 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
7093 | if (!tmdata) { | |
7094 | genlmsg_cancel(skb, hdr); | |
7095 | break; | |
7096 | } | |
e35e4d28 | 7097 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
7098 | nla_nest_end(skb, tmdata); |
7099 | ||
7100 | if (err == -ENOBUFS || err == -ENOENT) { | |
7101 | genlmsg_cancel(skb, hdr); | |
7102 | break; | |
7103 | } else if (err) { | |
7104 | genlmsg_cancel(skb, hdr); | |
7105 | goto out_err; | |
7106 | } | |
7107 | ||
7108 | genlmsg_end(skb, hdr); | |
7109 | } | |
7110 | ||
7111 | err = skb->len; | |
7112 | /* see above */ | |
7113 | cb->args[0] = phy_idx + 1; | |
7114 | out_err: | |
5fe231e8 | 7115 | rtnl_unlock(); |
71063f0e WYG |
7116 | return err; |
7117 | } | |
aff89a9b JB |
7118 | #endif |
7119 | ||
b23aa676 SO |
7120 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
7121 | { | |
4c476991 JB |
7122 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7123 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
7124 | struct cfg80211_connect_params connect; |
7125 | struct wiphy *wiphy; | |
fffd0934 | 7126 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
7127 | int err; |
7128 | ||
7129 | memset(&connect, 0, sizeof(connect)); | |
7130 | ||
7131 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
7132 | return -EINVAL; | |
7133 | ||
7134 | if (!info->attrs[NL80211_ATTR_SSID] || | |
7135 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
7136 | return -EINVAL; | |
7137 | ||
7138 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
7139 | connect.auth_type = | |
7140 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
7141 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
7142 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
7143 | return -EINVAL; |
7144 | } else | |
7145 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
7146 | ||
7147 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
7148 | ||
c0692b8f | 7149 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 7150 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
7151 | if (err) |
7152 | return err; | |
b23aa676 | 7153 | |
074ac8df | 7154 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7155 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7156 | return -EOPNOTSUPP; | |
b23aa676 | 7157 | |
79c97e97 | 7158 | wiphy = &rdev->wiphy; |
b23aa676 | 7159 | |
4486ea98 BS |
7160 | connect.bg_scan_period = -1; |
7161 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
7162 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
7163 | connect.bg_scan_period = | |
7164 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
7165 | } | |
7166 | ||
b23aa676 SO |
7167 | if (info->attrs[NL80211_ATTR_MAC]) |
7168 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
7169 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
7170 | connect.bssid_hint = | |
7171 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
7172 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7173 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7174 | ||
7175 | if (info->attrs[NL80211_ATTR_IE]) { | |
7176 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7177 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7178 | } | |
7179 | ||
cee00a95 JM |
7180 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
7181 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
7182 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
7183 | connect.mfp != NL80211_MFP_NO) | |
7184 | return -EINVAL; | |
7185 | } else { | |
7186 | connect.mfp = NL80211_MFP_NO; | |
7187 | } | |
7188 | ||
b23aa676 | 7189 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
7190 | connect.channel = nl80211_get_valid_chan( |
7191 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7192 | if (!connect.channel) | |
1df4a510 JM |
7193 | return -EINVAL; |
7194 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
7195 | connect.channel_hint = nl80211_get_valid_chan( |
7196 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
7197 | if (!connect.channel_hint) | |
4c476991 | 7198 | return -EINVAL; |
b23aa676 SO |
7199 | } |
7200 | ||
fffd0934 JB |
7201 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
7202 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 7203 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
7204 | if (IS_ERR(connkeys)) |
7205 | return PTR_ERR(connkeys); | |
fffd0934 JB |
7206 | } |
7207 | ||
7e7c8926 BG |
7208 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
7209 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
7210 | ||
7211 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7212 | memcpy(&connect.ht_capa_mask, | |
7213 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7214 | sizeof(connect.ht_capa_mask)); | |
7215 | ||
7216 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e WY |
7217 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
7218 | kfree(connkeys); | |
7e7c8926 | 7219 | return -EINVAL; |
b4e4f47e | 7220 | } |
7e7c8926 BG |
7221 | memcpy(&connect.ht_capa, |
7222 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7223 | sizeof(connect.ht_capa)); | |
7224 | } | |
7225 | ||
ee2aca34 JB |
7226 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
7227 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
7228 | ||
7229 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
7230 | memcpy(&connect.vht_capa_mask, | |
7231 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7232 | sizeof(connect.vht_capa_mask)); | |
7233 | ||
7234 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
7235 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
7236 | kfree(connkeys); | |
7237 | return -EINVAL; | |
7238 | } | |
7239 | memcpy(&connect.vht_capa, | |
7240 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7241 | sizeof(connect.vht_capa)); | |
7242 | } | |
7243 | ||
83739b03 JB |
7244 | wdev_lock(dev->ieee80211_ptr); |
7245 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
7246 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 JB |
7247 | if (err) |
7248 | kfree(connkeys); | |
b23aa676 SO |
7249 | return err; |
7250 | } | |
7251 | ||
7252 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
7253 | { | |
4c476991 JB |
7254 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7255 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 7256 | u16 reason; |
83739b03 | 7257 | int ret; |
b23aa676 SO |
7258 | |
7259 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7260 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
7261 | else | |
7262 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
7263 | ||
7264 | if (reason == 0) | |
7265 | return -EINVAL; | |
7266 | ||
074ac8df | 7267 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7268 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7269 | return -EOPNOTSUPP; | |
b23aa676 | 7270 | |
83739b03 JB |
7271 | wdev_lock(dev->ieee80211_ptr); |
7272 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
7273 | wdev_unlock(dev->ieee80211_ptr); | |
7274 | return ret; | |
b23aa676 SO |
7275 | } |
7276 | ||
463d0183 JB |
7277 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
7278 | { | |
4c476991 | 7279 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
7280 | struct net *net; |
7281 | int err; | |
7282 | u32 pid; | |
7283 | ||
7284 | if (!info->attrs[NL80211_ATTR_PID]) | |
7285 | return -EINVAL; | |
7286 | ||
7287 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
7288 | ||
463d0183 | 7289 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
7290 | if (IS_ERR(net)) |
7291 | return PTR_ERR(net); | |
463d0183 JB |
7292 | |
7293 | err = 0; | |
7294 | ||
7295 | /* check if anything to do */ | |
4c476991 JB |
7296 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
7297 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 7298 | |
463d0183 | 7299 | put_net(net); |
463d0183 JB |
7300 | return err; |
7301 | } | |
7302 | ||
67fbb16b SO |
7303 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
7304 | { | |
4c476991 | 7305 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
7306 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
7307 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 7308 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
7309 | struct cfg80211_pmksa pmksa; |
7310 | ||
7311 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
7312 | ||
7313 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7314 | return -EINVAL; | |
7315 | ||
7316 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
7317 | return -EINVAL; | |
7318 | ||
67fbb16b SO |
7319 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
7320 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7321 | ||
074ac8df | 7322 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7323 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7324 | return -EOPNOTSUPP; | |
67fbb16b SO |
7325 | |
7326 | switch (info->genlhdr->cmd) { | |
7327 | case NL80211_CMD_SET_PMKSA: | |
7328 | rdev_ops = rdev->ops->set_pmksa; | |
7329 | break; | |
7330 | case NL80211_CMD_DEL_PMKSA: | |
7331 | rdev_ops = rdev->ops->del_pmksa; | |
7332 | break; | |
7333 | default: | |
7334 | WARN_ON(1); | |
7335 | break; | |
7336 | } | |
7337 | ||
4c476991 JB |
7338 | if (!rdev_ops) |
7339 | return -EOPNOTSUPP; | |
67fbb16b | 7340 | |
4c476991 | 7341 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
7342 | } |
7343 | ||
7344 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
7345 | { | |
4c476991 JB |
7346 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7347 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 7348 | |
074ac8df | 7349 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7350 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7351 | return -EOPNOTSUPP; | |
67fbb16b | 7352 | |
4c476991 JB |
7353 | if (!rdev->ops->flush_pmksa) |
7354 | return -EOPNOTSUPP; | |
67fbb16b | 7355 | |
e35e4d28 | 7356 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
7357 | } |
7358 | ||
109086ce AN |
7359 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
7360 | { | |
7361 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7362 | struct net_device *dev = info->user_ptr[1]; | |
7363 | u8 action_code, dialog_token; | |
df942e7b | 7364 | u32 peer_capability = 0; |
109086ce AN |
7365 | u16 status_code; |
7366 | u8 *peer; | |
31fa97c5 | 7367 | bool initiator; |
109086ce AN |
7368 | |
7369 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7370 | !rdev->ops->tdls_mgmt) | |
7371 | return -EOPNOTSUPP; | |
7372 | ||
7373 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
7374 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
7375 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
7376 | !info->attrs[NL80211_ATTR_IE] || | |
7377 | !info->attrs[NL80211_ATTR_MAC]) | |
7378 | return -EINVAL; | |
7379 | ||
7380 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7381 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
7382 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
7383 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 7384 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
7385 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
7386 | peer_capability = | |
7387 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 7388 | |
e35e4d28 | 7389 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 7390 | dialog_token, status_code, peer_capability, |
31fa97c5 | 7391 | initiator, |
e35e4d28 HG |
7392 | nla_data(info->attrs[NL80211_ATTR_IE]), |
7393 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
7394 | } |
7395 | ||
7396 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
7397 | { | |
7398 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7399 | struct net_device *dev = info->user_ptr[1]; | |
7400 | enum nl80211_tdls_operation operation; | |
7401 | u8 *peer; | |
7402 | ||
7403 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7404 | !rdev->ops->tdls_oper) | |
7405 | return -EOPNOTSUPP; | |
7406 | ||
7407 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
7408 | !info->attrs[NL80211_ATTR_MAC]) | |
7409 | return -EINVAL; | |
7410 | ||
7411 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
7412 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7413 | ||
e35e4d28 | 7414 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
7415 | } |
7416 | ||
9588bbd5 JM |
7417 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
7418 | struct genl_info *info) | |
7419 | { | |
4c476991 | 7420 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7421 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7422 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
7423 | struct sk_buff *msg; |
7424 | void *hdr; | |
7425 | u64 cookie; | |
683b6d3b | 7426 | u32 duration; |
9588bbd5 JM |
7427 | int err; |
7428 | ||
7429 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7430 | !info->attrs[NL80211_ATTR_DURATION]) | |
7431 | return -EINVAL; | |
7432 | ||
7433 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
7434 | ||
ebf348fc JB |
7435 | if (!rdev->ops->remain_on_channel || |
7436 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
7437 | return -EOPNOTSUPP; | |
7438 | ||
9588bbd5 | 7439 | /* |
ebf348fc JB |
7440 | * We should be on that channel for at least a minimum amount of |
7441 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 7442 | */ |
ebf348fc | 7443 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 7444 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
7445 | return -EINVAL; |
7446 | ||
683b6d3b JB |
7447 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7448 | if (err) | |
7449 | return err; | |
9588bbd5 JM |
7450 | |
7451 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7452 | if (!msg) |
7453 | return -ENOMEM; | |
9588bbd5 | 7454 | |
15e47304 | 7455 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 7456 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
7457 | if (!hdr) { |
7458 | err = -ENOBUFS; | |
9588bbd5 JM |
7459 | goto free_msg; |
7460 | } | |
7461 | ||
683b6d3b JB |
7462 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7463 | duration, &cookie); | |
9588bbd5 JM |
7464 | |
7465 | if (err) | |
7466 | goto free_msg; | |
7467 | ||
9360ffd1 DM |
7468 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7469 | goto nla_put_failure; | |
9588bbd5 JM |
7470 | |
7471 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7472 | |
7473 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7474 | |
7475 | nla_put_failure: | |
7476 | err = -ENOBUFS; | |
7477 | free_msg: | |
7478 | nlmsg_free(msg); | |
9588bbd5 JM |
7479 | return err; |
7480 | } | |
7481 | ||
7482 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
7483 | struct genl_info *info) | |
7484 | { | |
4c476991 | 7485 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7486 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 7487 | u64 cookie; |
9588bbd5 JM |
7488 | |
7489 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7490 | return -EINVAL; | |
7491 | ||
4c476991 JB |
7492 | if (!rdev->ops->cancel_remain_on_channel) |
7493 | return -EOPNOTSUPP; | |
9588bbd5 | 7494 | |
9588bbd5 JM |
7495 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
7496 | ||
e35e4d28 | 7497 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
7498 | } |
7499 | ||
13ae75b1 JM |
7500 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
7501 | u8 *rates, u8 rates_len) | |
7502 | { | |
7503 | u8 i; | |
7504 | u32 mask = 0; | |
7505 | ||
7506 | for (i = 0; i < rates_len; i++) { | |
7507 | int rate = (rates[i] & 0x7f) * 5; | |
7508 | int ridx; | |
7509 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
7510 | struct ieee80211_rate *srate = | |
7511 | &sband->bitrates[ridx]; | |
7512 | if (rate == srate->bitrate) { | |
7513 | mask |= 1 << ridx; | |
7514 | break; | |
7515 | } | |
7516 | } | |
7517 | if (ridx == sband->n_bitrates) | |
7518 | return 0; /* rate not found */ | |
7519 | } | |
7520 | ||
7521 | return mask; | |
7522 | } | |
7523 | ||
24db78c0 SW |
7524 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
7525 | u8 *rates, u8 rates_len, | |
7526 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
7527 | { | |
7528 | u8 i; | |
7529 | ||
7530 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
7531 | ||
7532 | for (i = 0; i < rates_len; i++) { | |
7533 | int ridx, rbit; | |
7534 | ||
7535 | ridx = rates[i] / 8; | |
7536 | rbit = BIT(rates[i] % 8); | |
7537 | ||
7538 | /* check validity */ | |
910570b5 | 7539 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
7540 | return false; |
7541 | ||
7542 | /* check availability */ | |
7543 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
7544 | mcs[ridx] |= rbit; | |
7545 | else | |
7546 | return false; | |
7547 | } | |
7548 | ||
7549 | return true; | |
7550 | } | |
7551 | ||
204e35a9 JD |
7552 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
7553 | { | |
7554 | u16 mcs_mask = 0; | |
7555 | ||
7556 | switch (vht_mcs_map) { | |
7557 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
7558 | break; | |
7559 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
7560 | mcs_mask = 0x00FF; | |
7561 | break; | |
7562 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
7563 | mcs_mask = 0x01FF; | |
7564 | break; | |
7565 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
7566 | mcs_mask = 0x03FF; | |
7567 | break; | |
7568 | default: | |
7569 | break; | |
7570 | } | |
7571 | ||
7572 | return mcs_mask; | |
7573 | } | |
7574 | ||
7575 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
7576 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
7577 | { | |
7578 | u8 nss; | |
7579 | ||
7580 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
7581 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
7582 | vht_mcs_map >>= 2; | |
7583 | } | |
7584 | } | |
7585 | ||
7586 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
7587 | struct nl80211_txrate_vht *txrate, | |
7588 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
7589 | { | |
7590 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
7591 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
7592 | u8 i; | |
7593 | ||
7594 | if (!sband->vht_cap.vht_supported) | |
7595 | return false; | |
7596 | ||
7597 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
7598 | ||
7599 | /* Build vht_mcs_mask from VHT capabilities */ | |
7600 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
7601 | ||
7602 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
7603 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
7604 | mcs[i] = txrate->mcs[i]; | |
7605 | else | |
7606 | return false; | |
7607 | } | |
7608 | ||
7609 | return true; | |
7610 | } | |
7611 | ||
b54452b0 | 7612 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
7613 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
7614 | .len = NL80211_MAX_SUPP_RATES }, | |
d1e33e65 JD |
7615 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
7616 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
204e35a9 | 7617 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
0b9323f6 | 7618 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
13ae75b1 JM |
7619 | }; |
7620 | ||
7621 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
7622 | struct genl_info *info) | |
7623 | { | |
7624 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 7625 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 7626 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
7627 | int rem, i; |
7628 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
7629 | struct nlattr *tx_rates; |
7630 | struct ieee80211_supported_band *sband; | |
204e35a9 | 7631 | u16 vht_tx_mcs_map; |
13ae75b1 | 7632 | |
4c476991 JB |
7633 | if (!rdev->ops->set_bitrate_mask) |
7634 | return -EOPNOTSUPP; | |
13ae75b1 JM |
7635 | |
7636 | memset(&mask, 0, sizeof(mask)); | |
7637 | /* Default to all rates enabled */ | |
7638 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
7639 | sband = rdev->wiphy.bands[i]; | |
7869303b JD |
7640 | |
7641 | if (!sband) | |
7642 | continue; | |
7643 | ||
7644 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; | |
d1e33e65 | 7645 | memcpy(mask.control[i].ht_mcs, |
7869303b | 7646 | sband->ht_cap.mcs.rx_mask, |
d1e33e65 | 7647 | sizeof(mask.control[i].ht_mcs)); |
204e35a9 JD |
7648 | |
7649 | if (!sband->vht_cap.vht_supported) | |
7650 | continue; | |
7651 | ||
7652 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
7653 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); | |
13ae75b1 JM |
7654 | } |
7655 | ||
b9243ab0 JD |
7656 | /* if no rates are given set it back to the defaults */ |
7657 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
7658 | goto out; | |
7659 | ||
13ae75b1 JM |
7660 | /* |
7661 | * The nested attribute uses enum nl80211_band as the index. This maps | |
7662 | * directly to the enum ieee80211_band values used in cfg80211. | |
7663 | */ | |
24db78c0 | 7664 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
ae811e21 | 7665 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
13ae75b1 | 7666 | enum ieee80211_band band = nla_type(tx_rates); |
ae811e21 JB |
7667 | int err; |
7668 | ||
4c476991 JB |
7669 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
7670 | return -EINVAL; | |
13ae75b1 | 7671 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
7672 | if (sband == NULL) |
7673 | return -EINVAL; | |
ae811e21 JB |
7674 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
7675 | nla_len(tx_rates), nl80211_txattr_policy); | |
7676 | if (err) | |
7677 | return err; | |
13ae75b1 JM |
7678 | if (tb[NL80211_TXRATE_LEGACY]) { |
7679 | mask.control[band].legacy = rateset_to_mask( | |
7680 | sband, | |
7681 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
7682 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
7683 | if ((mask.control[band].legacy == 0) && |
7684 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
7685 | return -EINVAL; | |
24db78c0 | 7686 | } |
d1e33e65 | 7687 | if (tb[NL80211_TXRATE_HT]) { |
24db78c0 SW |
7688 | if (!ht_rateset_to_mask( |
7689 | sband, | |
d1e33e65 JD |
7690 | nla_data(tb[NL80211_TXRATE_HT]), |
7691 | nla_len(tb[NL80211_TXRATE_HT]), | |
7692 | mask.control[band].ht_mcs)) | |
24db78c0 SW |
7693 | return -EINVAL; |
7694 | } | |
204e35a9 JD |
7695 | if (tb[NL80211_TXRATE_VHT]) { |
7696 | if (!vht_set_mcs_mask( | |
7697 | sband, | |
7698 | nla_data(tb[NL80211_TXRATE_VHT]), | |
7699 | mask.control[band].vht_mcs)) | |
7700 | return -EINVAL; | |
7701 | } | |
0b9323f6 JD |
7702 | if (tb[NL80211_TXRATE_GI]) { |
7703 | mask.control[band].gi = | |
7704 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
7705 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
7706 | return -EINVAL; | |
7707 | } | |
24db78c0 SW |
7708 | |
7709 | if (mask.control[band].legacy == 0) { | |
204e35a9 JD |
7710 | /* don't allow empty legacy rates if HT or VHT |
7711 | * are not even supported. | |
7712 | */ | |
7713 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
7714 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
24db78c0 SW |
7715 | return -EINVAL; |
7716 | ||
7717 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
d1e33e65 | 7718 | if (mask.control[band].ht_mcs[i]) |
204e35a9 JD |
7719 | goto out; |
7720 | ||
7721 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
7722 | if (mask.control[band].vht_mcs[i]) | |
7723 | goto out; | |
24db78c0 SW |
7724 | |
7725 | /* legacy and mcs rates may not be both empty */ | |
204e35a9 | 7726 | return -EINVAL; |
13ae75b1 JM |
7727 | } |
7728 | } | |
7729 | ||
b9243ab0 | 7730 | out: |
e35e4d28 | 7731 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
7732 | } |
7733 | ||
2e161f78 | 7734 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7735 | { |
4c476991 | 7736 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7737 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 7738 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
7739 | |
7740 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
7741 | return -EINVAL; | |
7742 | ||
2e161f78 JB |
7743 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
7744 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 7745 | |
71bbc994 JB |
7746 | switch (wdev->iftype) { |
7747 | case NL80211_IFTYPE_STATION: | |
7748 | case NL80211_IFTYPE_ADHOC: | |
7749 | case NL80211_IFTYPE_P2P_CLIENT: | |
7750 | case NL80211_IFTYPE_AP: | |
7751 | case NL80211_IFTYPE_AP_VLAN: | |
7752 | case NL80211_IFTYPE_MESH_POINT: | |
7753 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7754 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7755 | break; |
7756 | default: | |
4c476991 | 7757 | return -EOPNOTSUPP; |
71bbc994 | 7758 | } |
026331c4 JM |
7759 | |
7760 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
7761 | if (!rdev->ops->mgmt_tx) |
7762 | return -EOPNOTSUPP; | |
026331c4 | 7763 | |
15e47304 | 7764 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
7765 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
7766 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
7767 | } |
7768 | ||
2e161f78 | 7769 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7770 | { |
4c476991 | 7771 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7772 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7773 | struct cfg80211_chan_def chandef; |
026331c4 | 7774 | int err; |
d64d373f | 7775 | void *hdr = NULL; |
026331c4 | 7776 | u64 cookie; |
e247bd90 | 7777 | struct sk_buff *msg = NULL; |
b176e629 AO |
7778 | struct cfg80211_mgmt_tx_params params = { |
7779 | .dont_wait_for_ack = | |
7780 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
7781 | }; | |
026331c4 | 7782 | |
683b6d3b | 7783 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
7784 | return -EINVAL; |
7785 | ||
4c476991 JB |
7786 | if (!rdev->ops->mgmt_tx) |
7787 | return -EOPNOTSUPP; | |
026331c4 | 7788 | |
71bbc994 | 7789 | switch (wdev->iftype) { |
ea141b75 AQ |
7790 | case NL80211_IFTYPE_P2P_DEVICE: |
7791 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
7792 | return -EINVAL; | |
71bbc994 JB |
7793 | case NL80211_IFTYPE_STATION: |
7794 | case NL80211_IFTYPE_ADHOC: | |
7795 | case NL80211_IFTYPE_P2P_CLIENT: | |
7796 | case NL80211_IFTYPE_AP: | |
7797 | case NL80211_IFTYPE_AP_VLAN: | |
7798 | case NL80211_IFTYPE_MESH_POINT: | |
7799 | case NL80211_IFTYPE_P2P_GO: | |
7800 | break; | |
7801 | default: | |
4c476991 | 7802 | return -EOPNOTSUPP; |
71bbc994 | 7803 | } |
026331c4 | 7804 | |
f7ca38df | 7805 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 7806 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 7807 | return -EINVAL; |
b176e629 | 7808 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
7809 | |
7810 | /* | |
7811 | * We should wait on the channel for at least a minimum amount | |
7812 | * of time (10ms) but no longer than the driver supports. | |
7813 | */ | |
b176e629 AO |
7814 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
7815 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc JB |
7816 | return -EINVAL; |
7817 | ||
f7ca38df JB |
7818 | } |
7819 | ||
b176e629 | 7820 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 7821 | |
b176e629 | 7822 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
7823 | return -EINVAL; |
7824 | ||
b176e629 | 7825 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 7826 | |
ea141b75 AQ |
7827 | /* get the channel if any has been specified, otherwise pass NULL to |
7828 | * the driver. The latter will use the current one | |
7829 | */ | |
7830 | chandef.chan = NULL; | |
7831 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
7832 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
7833 | if (err) | |
7834 | return err; | |
7835 | } | |
7836 | ||
b176e629 | 7837 | if (!chandef.chan && params.offchan) |
ea141b75 | 7838 | return -EINVAL; |
026331c4 | 7839 | |
34d22ce2 AO |
7840 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
7841 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
7842 | ||
7843 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
7844 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
7845 | int i; | |
7846 | ||
7847 | if (len % sizeof(u16)) | |
7848 | return -EINVAL; | |
7849 | ||
7850 | params.n_csa_offsets = len / sizeof(u16); | |
7851 | params.csa_offsets = | |
7852 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
7853 | ||
7854 | /* check that all the offsets fit the frame */ | |
7855 | for (i = 0; i < params.n_csa_offsets; i++) { | |
7856 | if (params.csa_offsets[i] >= params.len) | |
7857 | return -EINVAL; | |
7858 | } | |
7859 | } | |
7860 | ||
b176e629 | 7861 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
7862 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
7863 | if (!msg) | |
7864 | return -ENOMEM; | |
026331c4 | 7865 | |
15e47304 | 7866 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 7867 | NL80211_CMD_FRAME); |
cb35fba3 DC |
7868 | if (!hdr) { |
7869 | err = -ENOBUFS; | |
e247bd90 JB |
7870 | goto free_msg; |
7871 | } | |
026331c4 | 7872 | } |
e247bd90 | 7873 | |
b176e629 AO |
7874 | params.chan = chandef.chan; |
7875 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
7876 | if (err) |
7877 | goto free_msg; | |
7878 | ||
e247bd90 | 7879 | if (msg) { |
9360ffd1 DM |
7880 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7881 | goto nla_put_failure; | |
026331c4 | 7882 | |
e247bd90 JB |
7883 | genlmsg_end(msg, hdr); |
7884 | return genlmsg_reply(msg, info); | |
7885 | } | |
7886 | ||
7887 | return 0; | |
026331c4 JM |
7888 | |
7889 | nla_put_failure: | |
7890 | err = -ENOBUFS; | |
7891 | free_msg: | |
7892 | nlmsg_free(msg); | |
026331c4 JM |
7893 | return err; |
7894 | } | |
7895 | ||
f7ca38df JB |
7896 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
7897 | { | |
7898 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 7899 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
7900 | u64 cookie; |
7901 | ||
7902 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7903 | return -EINVAL; | |
7904 | ||
7905 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
7906 | return -EOPNOTSUPP; | |
7907 | ||
71bbc994 JB |
7908 | switch (wdev->iftype) { |
7909 | case NL80211_IFTYPE_STATION: | |
7910 | case NL80211_IFTYPE_ADHOC: | |
7911 | case NL80211_IFTYPE_P2P_CLIENT: | |
7912 | case NL80211_IFTYPE_AP: | |
7913 | case NL80211_IFTYPE_AP_VLAN: | |
7914 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7915 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7916 | break; |
7917 | default: | |
f7ca38df | 7918 | return -EOPNOTSUPP; |
71bbc994 | 7919 | } |
f7ca38df JB |
7920 | |
7921 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
7922 | ||
e35e4d28 | 7923 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
7924 | } |
7925 | ||
ffb9eb3d KV |
7926 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
7927 | { | |
4c476991 | 7928 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 7929 | struct wireless_dev *wdev; |
4c476991 | 7930 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7931 | u8 ps_state; |
7932 | bool state; | |
7933 | int err; | |
7934 | ||
4c476991 JB |
7935 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
7936 | return -EINVAL; | |
ffb9eb3d KV |
7937 | |
7938 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
7939 | ||
4c476991 JB |
7940 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
7941 | return -EINVAL; | |
ffb9eb3d KV |
7942 | |
7943 | wdev = dev->ieee80211_ptr; | |
7944 | ||
4c476991 JB |
7945 | if (!rdev->ops->set_power_mgmt) |
7946 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7947 | |
7948 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
7949 | ||
7950 | if (state == wdev->ps) | |
4c476991 | 7951 | return 0; |
ffb9eb3d | 7952 | |
e35e4d28 | 7953 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
7954 | if (!err) |
7955 | wdev->ps = state; | |
ffb9eb3d KV |
7956 | return err; |
7957 | } | |
7958 | ||
7959 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
7960 | { | |
4c476991 | 7961 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
7962 | enum nl80211_ps_state ps_state; |
7963 | struct wireless_dev *wdev; | |
4c476991 | 7964 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7965 | struct sk_buff *msg; |
7966 | void *hdr; | |
7967 | int err; | |
7968 | ||
ffb9eb3d KV |
7969 | wdev = dev->ieee80211_ptr; |
7970 | ||
4c476991 JB |
7971 | if (!rdev->ops->set_power_mgmt) |
7972 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7973 | |
7974 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7975 | if (!msg) |
7976 | return -ENOMEM; | |
ffb9eb3d | 7977 | |
15e47304 | 7978 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
7979 | NL80211_CMD_GET_POWER_SAVE); |
7980 | if (!hdr) { | |
4c476991 | 7981 | err = -ENOBUFS; |
ffb9eb3d KV |
7982 | goto free_msg; |
7983 | } | |
7984 | ||
7985 | if (wdev->ps) | |
7986 | ps_state = NL80211_PS_ENABLED; | |
7987 | else | |
7988 | ps_state = NL80211_PS_DISABLED; | |
7989 | ||
9360ffd1 DM |
7990 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
7991 | goto nla_put_failure; | |
ffb9eb3d KV |
7992 | |
7993 | genlmsg_end(msg, hdr); | |
4c476991 | 7994 | return genlmsg_reply(msg, info); |
ffb9eb3d | 7995 | |
4c476991 | 7996 | nla_put_failure: |
ffb9eb3d | 7997 | err = -ENOBUFS; |
4c476991 | 7998 | free_msg: |
ffb9eb3d | 7999 | nlmsg_free(msg); |
ffb9eb3d KV |
8000 | return err; |
8001 | } | |
8002 | ||
94e860f1 JB |
8003 | static const struct nla_policy |
8004 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
8005 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
8006 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
8007 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
8008 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
8009 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
8010 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
8011 | }; |
8012 | ||
84f10708 | 8013 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 8014 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
8015 | { |
8016 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 8017 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8018 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 8019 | |
d9d8b019 | 8020 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
8021 | return -EINVAL; |
8022 | ||
84f10708 TP |
8023 | if (!rdev->ops->set_cqm_txe_config) |
8024 | return -EOPNOTSUPP; | |
8025 | ||
8026 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
8027 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
8028 | return -EOPNOTSUPP; | |
8029 | ||
e35e4d28 | 8030 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
8031 | } |
8032 | ||
d6dc1a38 JO |
8033 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
8034 | s32 threshold, u32 hysteresis) | |
8035 | { | |
4c476991 | 8036 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 8037 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8038 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
8039 | |
8040 | if (threshold > 0) | |
8041 | return -EINVAL; | |
8042 | ||
1da5fcc8 JB |
8043 | /* disabling - hysteresis should also be zero then */ |
8044 | if (threshold == 0) | |
8045 | hysteresis = 0; | |
d6dc1a38 | 8046 | |
4c476991 JB |
8047 | if (!rdev->ops->set_cqm_rssi_config) |
8048 | return -EOPNOTSUPP; | |
d6dc1a38 | 8049 | |
074ac8df | 8050 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8051 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8052 | return -EOPNOTSUPP; | |
d6dc1a38 | 8053 | |
e35e4d28 | 8054 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
8055 | } |
8056 | ||
8057 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
8058 | { | |
8059 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
8060 | struct nlattr *cqm; | |
8061 | int err; | |
8062 | ||
8063 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
8064 | if (!cqm) |
8065 | return -EINVAL; | |
d6dc1a38 JO |
8066 | |
8067 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
8068 | nl80211_attr_cqm_policy); | |
8069 | if (err) | |
1da5fcc8 | 8070 | return err; |
d6dc1a38 JO |
8071 | |
8072 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
8073 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
8074 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
8075 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 8076 | |
1da5fcc8 JB |
8077 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
8078 | } | |
8079 | ||
8080 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
8081 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
8082 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
8083 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
8084 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
8085 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
8086 | ||
8087 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
8088 | } | |
8089 | ||
8090 | return -EINVAL; | |
d6dc1a38 JO |
8091 | } |
8092 | ||
29cbe68c JB |
8093 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
8094 | { | |
8095 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8096 | struct net_device *dev = info->user_ptr[1]; | |
8097 | struct mesh_config cfg; | |
c80d545d | 8098 | struct mesh_setup setup; |
29cbe68c JB |
8099 | int err; |
8100 | ||
8101 | /* start with default */ | |
8102 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 8103 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 8104 | |
24bdd9f4 | 8105 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 8106 | /* and parse parameters if given */ |
24bdd9f4 | 8107 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
8108 | if (err) |
8109 | return err; | |
8110 | } | |
8111 | ||
8112 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
8113 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
8114 | return -EINVAL; | |
8115 | ||
c80d545d JC |
8116 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
8117 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
8118 | ||
4bb62344 CYY |
8119 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8120 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
8121 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8122 | return -EINVAL; | |
8123 | ||
9bdbf04d MP |
8124 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
8125 | setup.beacon_interval = | |
8126 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
8127 | if (setup.beacon_interval < 10 || | |
8128 | setup.beacon_interval > 10000) | |
8129 | return -EINVAL; | |
8130 | } | |
8131 | ||
8132 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
8133 | setup.dtim_period = | |
8134 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
8135 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
8136 | return -EINVAL; | |
8137 | } | |
8138 | ||
c80d545d JC |
8139 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
8140 | /* parse additional setup parameters if given */ | |
8141 | err = nl80211_parse_mesh_setup(info, &setup); | |
8142 | if (err) | |
8143 | return err; | |
8144 | } | |
8145 | ||
d37bb18a TP |
8146 | if (setup.user_mpm) |
8147 | cfg.auto_open_plinks = false; | |
8148 | ||
cc1d2806 | 8149 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
8150 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
8151 | if (err) | |
8152 | return err; | |
cc1d2806 JB |
8153 | } else { |
8154 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 8155 | setup.chandef.chan = NULL; |
cc1d2806 JB |
8156 | } |
8157 | ||
ffb3cf30 AN |
8158 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8159 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8160 | int n_rates = | |
8161 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8162 | struct ieee80211_supported_band *sband; | |
8163 | ||
8164 | if (!setup.chandef.chan) | |
8165 | return -EINVAL; | |
8166 | ||
8167 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
8168 | ||
8169 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
8170 | &setup.basic_rates); | |
8171 | if (err) | |
8172 | return err; | |
8173 | } | |
8174 | ||
c80d545d | 8175 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
8176 | } |
8177 | ||
8178 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
8179 | { | |
8180 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8181 | struct net_device *dev = info->user_ptr[1]; | |
8182 | ||
8183 | return cfg80211_leave_mesh(rdev, dev); | |
8184 | } | |
8185 | ||
dfb89c56 | 8186 | #ifdef CONFIG_PM |
bb92d199 AK |
8187 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
8188 | struct cfg80211_registered_device *rdev) | |
8189 | { | |
6abb9cb9 | 8190 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
8191 | struct nlattr *nl_pats, *nl_pat; |
8192 | int i, pat_len; | |
8193 | ||
6abb9cb9 | 8194 | if (!wowlan->n_patterns) |
bb92d199 AK |
8195 | return 0; |
8196 | ||
8197 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
8198 | if (!nl_pats) | |
8199 | return -ENOBUFS; | |
8200 | ||
6abb9cb9 | 8201 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
8202 | nl_pat = nla_nest_start(msg, i + 1); |
8203 | if (!nl_pat) | |
8204 | return -ENOBUFS; | |
6abb9cb9 | 8205 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 8206 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 8207 | wowlan->patterns[i].mask) || |
50ac6607 AK |
8208 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
8209 | wowlan->patterns[i].pattern) || | |
8210 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 8211 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
8212 | return -ENOBUFS; |
8213 | nla_nest_end(msg, nl_pat); | |
8214 | } | |
8215 | nla_nest_end(msg, nl_pats); | |
8216 | ||
8217 | return 0; | |
8218 | } | |
8219 | ||
2a0e047e JB |
8220 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
8221 | struct cfg80211_wowlan_tcp *tcp) | |
8222 | { | |
8223 | struct nlattr *nl_tcp; | |
8224 | ||
8225 | if (!tcp) | |
8226 | return 0; | |
8227 | ||
8228 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
8229 | if (!nl_tcp) | |
8230 | return -ENOBUFS; | |
8231 | ||
8232 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
8233 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
8234 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
8235 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
8236 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
8237 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
8238 | tcp->payload_len, tcp->payload) || | |
8239 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
8240 | tcp->data_interval) || | |
8241 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
8242 | tcp->wake_len, tcp->wake_data) || | |
8243 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
8244 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
8245 | return -ENOBUFS; | |
8246 | ||
8247 | if (tcp->payload_seq.len && | |
8248 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
8249 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
8250 | return -ENOBUFS; | |
8251 | ||
8252 | if (tcp->payload_tok.len && | |
8253 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
8254 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
8255 | &tcp->payload_tok)) | |
8256 | return -ENOBUFS; | |
8257 | ||
e248ad30 JB |
8258 | nla_nest_end(msg, nl_tcp); |
8259 | ||
2a0e047e JB |
8260 | return 0; |
8261 | } | |
8262 | ||
ff1b6e69 JB |
8263 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
8264 | { | |
8265 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8266 | struct sk_buff *msg; | |
8267 | void *hdr; | |
2a0e047e | 8268 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 8269 | |
964dc9e2 | 8270 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
8271 | return -EOPNOTSUPP; |
8272 | ||
6abb9cb9 | 8273 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 8274 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
8275 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
8276 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
8277 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
8278 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
8279 | } |
8280 | ||
8281 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
8282 | if (!msg) |
8283 | return -ENOMEM; | |
8284 | ||
15e47304 | 8285 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
8286 | NL80211_CMD_GET_WOWLAN); |
8287 | if (!hdr) | |
8288 | goto nla_put_failure; | |
8289 | ||
6abb9cb9 | 8290 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
8291 | struct nlattr *nl_wowlan; |
8292 | ||
8293 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
8294 | if (!nl_wowlan) | |
8295 | goto nla_put_failure; | |
8296 | ||
6abb9cb9 | 8297 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 8298 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 8299 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 8300 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 8301 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 8302 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 8303 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 8304 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 8305 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 8306 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 8307 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 8308 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 8309 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
8310 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
8311 | goto nla_put_failure; | |
2a0e047e | 8312 | |
bb92d199 AK |
8313 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
8314 | goto nla_put_failure; | |
2a0e047e | 8315 | |
6abb9cb9 JB |
8316 | if (nl80211_send_wowlan_tcp(msg, |
8317 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e JB |
8318 | goto nla_put_failure; |
8319 | ||
ff1b6e69 JB |
8320 | nla_nest_end(msg, nl_wowlan); |
8321 | } | |
8322 | ||
8323 | genlmsg_end(msg, hdr); | |
8324 | return genlmsg_reply(msg, info); | |
8325 | ||
8326 | nla_put_failure: | |
8327 | nlmsg_free(msg); | |
8328 | return -ENOBUFS; | |
8329 | } | |
8330 | ||
2a0e047e JB |
8331 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
8332 | struct nlattr *attr, | |
8333 | struct cfg80211_wowlan *trig) | |
8334 | { | |
8335 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
8336 | struct cfg80211_wowlan_tcp *cfg; | |
8337 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
8338 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
8339 | u32 size; | |
8340 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
8341 | int err, port; | |
8342 | ||
964dc9e2 | 8343 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
8344 | return -EINVAL; |
8345 | ||
8346 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
8347 | nla_data(attr), nla_len(attr), | |
8348 | nl80211_wowlan_tcp_policy); | |
8349 | if (err) | |
8350 | return err; | |
8351 | ||
8352 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
8353 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
8354 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
8355 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
8356 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
8357 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
8358 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
8359 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
8360 | return -EINVAL; | |
8361 | ||
8362 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 8363 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
8364 | return -EINVAL; |
8365 | ||
8366 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 8367 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 8368 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
8369 | return -EINVAL; |
8370 | ||
8371 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 8372 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
8373 | return -EINVAL; |
8374 | ||
8375 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
8376 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
8377 | return -EINVAL; | |
8378 | ||
8379 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
8380 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8381 | ||
8382 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8383 | tokens_size = tokln - sizeof(*tok); | |
8384 | ||
8385 | if (!tok->len || tokens_size % tok->len) | |
8386 | return -EINVAL; | |
964dc9e2 | 8387 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 8388 | return -EINVAL; |
964dc9e2 | 8389 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 8390 | return -EINVAL; |
964dc9e2 | 8391 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 8392 | return -EINVAL; |
964dc9e2 | 8393 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
8394 | return -EINVAL; |
8395 | if (tok->offset + tok->len > data_size) | |
8396 | return -EINVAL; | |
8397 | } | |
8398 | ||
8399 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
8400 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 8401 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
8402 | return -EINVAL; |
8403 | if (seq->len == 0 || seq->len > 4) | |
8404 | return -EINVAL; | |
8405 | if (seq->len + seq->offset > data_size) | |
8406 | return -EINVAL; | |
8407 | } | |
8408 | ||
8409 | size = sizeof(*cfg); | |
8410 | size += data_size; | |
8411 | size += wake_size + wake_mask_size; | |
8412 | size += tokens_size; | |
8413 | ||
8414 | cfg = kzalloc(size, GFP_KERNEL); | |
8415 | if (!cfg) | |
8416 | return -ENOMEM; | |
8417 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
8418 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
8419 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
8420 | ETH_ALEN); | |
8421 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
8422 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
8423 | else | |
8424 | port = 0; | |
8425 | #ifdef CONFIG_INET | |
8426 | /* allocate a socket and port for it and use it */ | |
8427 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
8428 | IPPROTO_TCP, &cfg->sock, 1); | |
8429 | if (err) { | |
8430 | kfree(cfg); | |
8431 | return err; | |
8432 | } | |
8433 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
8434 | sock_release(cfg->sock); | |
8435 | kfree(cfg); | |
8436 | return -EADDRINUSE; | |
8437 | } | |
8438 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
8439 | #else | |
8440 | if (!port) { | |
8441 | kfree(cfg); | |
8442 | return -EINVAL; | |
8443 | } | |
8444 | cfg->src_port = port; | |
8445 | #endif | |
8446 | ||
8447 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
8448 | cfg->payload_len = data_size; | |
8449 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
8450 | memcpy((void *)cfg->payload, | |
8451 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
8452 | data_size); | |
8453 | if (seq) | |
8454 | cfg->payload_seq = *seq; | |
8455 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
8456 | cfg->wake_len = wake_size; | |
8457 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
8458 | memcpy((void *)cfg->wake_data, | |
8459 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
8460 | wake_size); | |
8461 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
8462 | data_size + wake_size; | |
8463 | memcpy((void *)cfg->wake_mask, | |
8464 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
8465 | wake_mask_size); | |
8466 | if (tok) { | |
8467 | cfg->tokens_size = tokens_size; | |
8468 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
8469 | } | |
8470 | ||
8471 | trig->tcp = cfg; | |
8472 | ||
8473 | return 0; | |
8474 | } | |
8475 | ||
ff1b6e69 JB |
8476 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
8477 | { | |
8478 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8479 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 8480 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 8481 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 8482 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 8483 | int err, i; |
6abb9cb9 | 8484 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 8485 | |
964dc9e2 | 8486 | if (!wowlan) |
ff1b6e69 JB |
8487 | return -EOPNOTSUPP; |
8488 | ||
ae33bd81 JB |
8489 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
8490 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 8491 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
8492 | goto set_wakeup; |
8493 | } | |
ff1b6e69 JB |
8494 | |
8495 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
8496 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8497 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8498 | nl80211_wowlan_policy); | |
8499 | if (err) | |
8500 | return err; | |
8501 | ||
8502 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
8503 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
8504 | return -EINVAL; | |
8505 | new_triggers.any = true; | |
8506 | } | |
8507 | ||
8508 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
8509 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
8510 | return -EINVAL; | |
8511 | new_triggers.disconnect = true; | |
8512 | } | |
8513 | ||
8514 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
8515 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
8516 | return -EINVAL; | |
8517 | new_triggers.magic_pkt = true; | |
8518 | } | |
8519 | ||
77dbbb13 JB |
8520 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
8521 | return -EINVAL; | |
8522 | ||
8523 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
8524 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
8525 | return -EINVAL; | |
8526 | new_triggers.gtk_rekey_failure = true; | |
8527 | } | |
8528 | ||
8529 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
8530 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
8531 | return -EINVAL; | |
8532 | new_triggers.eap_identity_req = true; | |
8533 | } | |
8534 | ||
8535 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
8536 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
8537 | return -EINVAL; | |
8538 | new_triggers.four_way_handshake = true; | |
8539 | } | |
8540 | ||
8541 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
8542 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
8543 | return -EINVAL; | |
8544 | new_triggers.rfkill_release = true; | |
8545 | } | |
8546 | ||
ff1b6e69 JB |
8547 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
8548 | struct nlattr *pat; | |
8549 | int n_patterns = 0; | |
bb92d199 | 8550 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 8551 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 JB |
8552 | |
8553 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8554 | rem) | |
8555 | n_patterns++; | |
8556 | if (n_patterns > wowlan->n_patterns) | |
8557 | return -EINVAL; | |
8558 | ||
8559 | new_triggers.patterns = kcalloc(n_patterns, | |
8560 | sizeof(new_triggers.patterns[0]), | |
8561 | GFP_KERNEL); | |
8562 | if (!new_triggers.patterns) | |
8563 | return -ENOMEM; | |
8564 | ||
8565 | new_triggers.n_patterns = n_patterns; | |
8566 | i = 0; | |
8567 | ||
8568 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8569 | rem) { | |
922bd80f JB |
8570 | u8 *mask_pat; |
8571 | ||
50ac6607 AK |
8572 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
8573 | nla_len(pat), NULL); | |
ff1b6e69 | 8574 | err = -EINVAL; |
50ac6607 AK |
8575 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
8576 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 8577 | goto error; |
50ac6607 | 8578 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 8579 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 8580 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
8581 | goto error; |
8582 | if (pat_len > wowlan->pattern_max_len || | |
8583 | pat_len < wowlan->pattern_min_len) | |
8584 | goto error; | |
8585 | ||
50ac6607 | 8586 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
8587 | pkt_offset = 0; |
8588 | else | |
8589 | pkt_offset = nla_get_u32( | |
50ac6607 | 8590 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
8591 | if (pkt_offset > wowlan->max_pkt_offset) |
8592 | goto error; | |
8593 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
8594 | ||
922bd80f JB |
8595 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
8596 | if (!mask_pat) { | |
ff1b6e69 JB |
8597 | err = -ENOMEM; |
8598 | goto error; | |
8599 | } | |
922bd80f JB |
8600 | new_triggers.patterns[i].mask = mask_pat; |
8601 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 8602 | mask_len); |
922bd80f JB |
8603 | mask_pat += mask_len; |
8604 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 8605 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 8606 | memcpy(mask_pat, |
50ac6607 | 8607 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
8608 | pat_len); |
8609 | i++; | |
8610 | } | |
8611 | } | |
8612 | ||
2a0e047e JB |
8613 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
8614 | err = nl80211_parse_wowlan_tcp( | |
8615 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
8616 | &new_triggers); | |
8617 | if (err) | |
8618 | goto error; | |
8619 | } | |
8620 | ||
ae33bd81 JB |
8621 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
8622 | if (!ntrig) { | |
8623 | err = -ENOMEM; | |
8624 | goto error; | |
ff1b6e69 | 8625 | } |
ae33bd81 | 8626 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 8627 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 8628 | |
ae33bd81 | 8629 | set_wakeup: |
6abb9cb9 JB |
8630 | if (rdev->ops->set_wakeup && |
8631 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
8632 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 8633 | |
ff1b6e69 JB |
8634 | return 0; |
8635 | error: | |
8636 | for (i = 0; i < new_triggers.n_patterns; i++) | |
8637 | kfree(new_triggers.patterns[i].mask); | |
8638 | kfree(new_triggers.patterns); | |
2a0e047e JB |
8639 | if (new_triggers.tcp && new_triggers.tcp->sock) |
8640 | sock_release(new_triggers.tcp->sock); | |
8641 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
8642 | return err; |
8643 | } | |
dfb89c56 | 8644 | #endif |
ff1b6e69 | 8645 | |
be29b99a AK |
8646 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
8647 | struct cfg80211_registered_device *rdev) | |
8648 | { | |
8649 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
8650 | int i, j, pat_len; | |
8651 | struct cfg80211_coalesce_rules *rule; | |
8652 | ||
8653 | if (!rdev->coalesce->n_rules) | |
8654 | return 0; | |
8655 | ||
8656 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
8657 | if (!nl_rules) | |
8658 | return -ENOBUFS; | |
8659 | ||
8660 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
8661 | nl_rule = nla_nest_start(msg, i + 1); | |
8662 | if (!nl_rule) | |
8663 | return -ENOBUFS; | |
8664 | ||
8665 | rule = &rdev->coalesce->rules[i]; | |
8666 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
8667 | rule->delay)) | |
8668 | return -ENOBUFS; | |
8669 | ||
8670 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
8671 | rule->condition)) | |
8672 | return -ENOBUFS; | |
8673 | ||
8674 | nl_pats = nla_nest_start(msg, | |
8675 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
8676 | if (!nl_pats) | |
8677 | return -ENOBUFS; | |
8678 | ||
8679 | for (j = 0; j < rule->n_patterns; j++) { | |
8680 | nl_pat = nla_nest_start(msg, j + 1); | |
8681 | if (!nl_pat) | |
8682 | return -ENOBUFS; | |
8683 | pat_len = rule->patterns[j].pattern_len; | |
8684 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
8685 | DIV_ROUND_UP(pat_len, 8), | |
8686 | rule->patterns[j].mask) || | |
8687 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
8688 | rule->patterns[j].pattern) || | |
8689 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
8690 | rule->patterns[j].pkt_offset)) | |
8691 | return -ENOBUFS; | |
8692 | nla_nest_end(msg, nl_pat); | |
8693 | } | |
8694 | nla_nest_end(msg, nl_pats); | |
8695 | nla_nest_end(msg, nl_rule); | |
8696 | } | |
8697 | nla_nest_end(msg, nl_rules); | |
8698 | ||
8699 | return 0; | |
8700 | } | |
8701 | ||
8702 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8703 | { | |
8704 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8705 | struct sk_buff *msg; | |
8706 | void *hdr; | |
8707 | ||
8708 | if (!rdev->wiphy.coalesce) | |
8709 | return -EOPNOTSUPP; | |
8710 | ||
8711 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8712 | if (!msg) | |
8713 | return -ENOMEM; | |
8714 | ||
8715 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8716 | NL80211_CMD_GET_COALESCE); | |
8717 | if (!hdr) | |
8718 | goto nla_put_failure; | |
8719 | ||
8720 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
8721 | goto nla_put_failure; | |
8722 | ||
8723 | genlmsg_end(msg, hdr); | |
8724 | return genlmsg_reply(msg, info); | |
8725 | ||
8726 | nla_put_failure: | |
8727 | nlmsg_free(msg); | |
8728 | return -ENOBUFS; | |
8729 | } | |
8730 | ||
8731 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
8732 | { | |
8733 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
8734 | int i, j; | |
8735 | struct cfg80211_coalesce_rules *rule; | |
8736 | ||
8737 | if (!coalesce) | |
8738 | return; | |
8739 | ||
8740 | for (i = 0; i < coalesce->n_rules; i++) { | |
8741 | rule = &coalesce->rules[i]; | |
8742 | for (j = 0; j < rule->n_patterns; j++) | |
8743 | kfree(rule->patterns[j].mask); | |
8744 | kfree(rule->patterns); | |
8745 | } | |
8746 | kfree(coalesce->rules); | |
8747 | kfree(coalesce); | |
8748 | rdev->coalesce = NULL; | |
8749 | } | |
8750 | ||
8751 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
8752 | struct nlattr *rule, | |
8753 | struct cfg80211_coalesce_rules *new_rule) | |
8754 | { | |
8755 | int err, i; | |
8756 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8757 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
8758 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
8759 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
8760 | ||
8761 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
8762 | nla_len(rule), nl80211_coalesce_policy); | |
8763 | if (err) | |
8764 | return err; | |
8765 | ||
8766 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
8767 | new_rule->delay = | |
8768 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
8769 | if (new_rule->delay > coalesce->max_delay) | |
8770 | return -EINVAL; | |
8771 | ||
8772 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
8773 | new_rule->condition = | |
8774 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
8775 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
8776 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
8777 | return -EINVAL; | |
8778 | ||
8779 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
8780 | return -EINVAL; | |
8781 | ||
8782 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8783 | rem) | |
8784 | n_patterns++; | |
8785 | if (n_patterns > coalesce->n_patterns) | |
8786 | return -EINVAL; | |
8787 | ||
8788 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
8789 | GFP_KERNEL); | |
8790 | if (!new_rule->patterns) | |
8791 | return -ENOMEM; | |
8792 | ||
8793 | new_rule->n_patterns = n_patterns; | |
8794 | i = 0; | |
8795 | ||
8796 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8797 | rem) { | |
922bd80f JB |
8798 | u8 *mask_pat; |
8799 | ||
be29b99a AK |
8800 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
8801 | nla_len(pat), NULL); | |
8802 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
8803 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
8804 | return -EINVAL; | |
8805 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
8806 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
8807 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
8808 | return -EINVAL; | |
8809 | if (pat_len > coalesce->pattern_max_len || | |
8810 | pat_len < coalesce->pattern_min_len) | |
8811 | return -EINVAL; | |
8812 | ||
8813 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
8814 | pkt_offset = 0; | |
8815 | else | |
8816 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
8817 | if (pkt_offset > coalesce->max_pkt_offset) | |
8818 | return -EINVAL; | |
8819 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
8820 | ||
922bd80f JB |
8821 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
8822 | if (!mask_pat) | |
be29b99a | 8823 | return -ENOMEM; |
922bd80f JB |
8824 | |
8825 | new_rule->patterns[i].mask = mask_pat; | |
8826 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
8827 | mask_len); | |
8828 | ||
8829 | mask_pat += mask_len; | |
8830 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 8831 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
8832 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
8833 | pat_len); | |
be29b99a AK |
8834 | i++; |
8835 | } | |
8836 | ||
8837 | return 0; | |
8838 | } | |
8839 | ||
8840 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8841 | { | |
8842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8843 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8844 | struct cfg80211_coalesce new_coalesce = {}; | |
8845 | struct cfg80211_coalesce *n_coalesce; | |
8846 | int err, rem_rule, n_rules = 0, i, j; | |
8847 | struct nlattr *rule; | |
8848 | struct cfg80211_coalesce_rules *tmp_rule; | |
8849 | ||
8850 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
8851 | return -EOPNOTSUPP; | |
8852 | ||
8853 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
8854 | cfg80211_rdev_free_coalesce(rdev); | |
8855 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
8856 | return 0; | |
8857 | } | |
8858 | ||
8859 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8860 | rem_rule) | |
8861 | n_rules++; | |
8862 | if (n_rules > coalesce->n_rules) | |
8863 | return -EINVAL; | |
8864 | ||
8865 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
8866 | GFP_KERNEL); | |
8867 | if (!new_coalesce.rules) | |
8868 | return -ENOMEM; | |
8869 | ||
8870 | new_coalesce.n_rules = n_rules; | |
8871 | i = 0; | |
8872 | ||
8873 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8874 | rem_rule) { | |
8875 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
8876 | &new_coalesce.rules[i]); | |
8877 | if (err) | |
8878 | goto error; | |
8879 | ||
8880 | i++; | |
8881 | } | |
8882 | ||
8883 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
8884 | if (err) | |
8885 | goto error; | |
8886 | ||
8887 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
8888 | if (!n_coalesce) { | |
8889 | err = -ENOMEM; | |
8890 | goto error; | |
8891 | } | |
8892 | cfg80211_rdev_free_coalesce(rdev); | |
8893 | rdev->coalesce = n_coalesce; | |
8894 | ||
8895 | return 0; | |
8896 | error: | |
8897 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
8898 | tmp_rule = &new_coalesce.rules[i]; | |
8899 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
8900 | kfree(tmp_rule->patterns[j].mask); | |
8901 | kfree(tmp_rule->patterns); | |
8902 | } | |
8903 | kfree(new_coalesce.rules); | |
8904 | ||
8905 | return err; | |
8906 | } | |
8907 | ||
e5497d76 JB |
8908 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
8909 | { | |
8910 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8911 | struct net_device *dev = info->user_ptr[1]; | |
8912 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8913 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
8914 | struct cfg80211_gtk_rekey_data rekey_data; | |
8915 | int err; | |
8916 | ||
8917 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
8918 | return -EINVAL; | |
8919 | ||
8920 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
8921 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8922 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8923 | nl80211_rekey_policy); | |
8924 | if (err) | |
8925 | return err; | |
8926 | ||
8927 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
8928 | return -ERANGE; | |
8929 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
8930 | return -ERANGE; | |
8931 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
8932 | return -ERANGE; | |
8933 | ||
8934 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
8935 | NL80211_KEK_LEN); | |
8936 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
8937 | NL80211_KCK_LEN); | |
8938 | memcpy(rekey_data.replay_ctr, | |
8939 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
8940 | NL80211_REPLAY_CTR_LEN); | |
8941 | ||
8942 | wdev_lock(wdev); | |
8943 | if (!wdev->current_bss) { | |
8944 | err = -ENOTCONN; | |
8945 | goto out; | |
8946 | } | |
8947 | ||
8948 | if (!rdev->ops->set_rekey_data) { | |
8949 | err = -EOPNOTSUPP; | |
8950 | goto out; | |
8951 | } | |
8952 | ||
e35e4d28 | 8953 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
8954 | out: |
8955 | wdev_unlock(wdev); | |
8956 | return err; | |
8957 | } | |
8958 | ||
28946da7 JB |
8959 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
8960 | struct genl_info *info) | |
8961 | { | |
8962 | struct net_device *dev = info->user_ptr[1]; | |
8963 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8964 | ||
8965 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8966 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8967 | return -EINVAL; | |
8968 | ||
15e47304 | 8969 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
8970 | return -EBUSY; |
8971 | ||
15e47304 | 8972 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
8973 | return 0; |
8974 | } | |
8975 | ||
7f6cf311 JB |
8976 | static int nl80211_probe_client(struct sk_buff *skb, |
8977 | struct genl_info *info) | |
8978 | { | |
8979 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8980 | struct net_device *dev = info->user_ptr[1]; | |
8981 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8982 | struct sk_buff *msg; | |
8983 | void *hdr; | |
8984 | const u8 *addr; | |
8985 | u64 cookie; | |
8986 | int err; | |
8987 | ||
8988 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8989 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8990 | return -EOPNOTSUPP; | |
8991 | ||
8992 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8993 | return -EINVAL; | |
8994 | ||
8995 | if (!rdev->ops->probe_client) | |
8996 | return -EOPNOTSUPP; | |
8997 | ||
8998 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8999 | if (!msg) | |
9000 | return -ENOMEM; | |
9001 | ||
15e47304 | 9002 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 9003 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
9004 | if (!hdr) { |
9005 | err = -ENOBUFS; | |
7f6cf311 JB |
9006 | goto free_msg; |
9007 | } | |
9008 | ||
9009 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9010 | ||
e35e4d28 | 9011 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
9012 | if (err) |
9013 | goto free_msg; | |
9014 | ||
9360ffd1 DM |
9015 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9016 | goto nla_put_failure; | |
7f6cf311 JB |
9017 | |
9018 | genlmsg_end(msg, hdr); | |
9019 | ||
9020 | return genlmsg_reply(msg, info); | |
9021 | ||
9022 | nla_put_failure: | |
9023 | err = -ENOBUFS; | |
9024 | free_msg: | |
9025 | nlmsg_free(msg); | |
9026 | return err; | |
9027 | } | |
9028 | ||
5e760230 JB |
9029 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
9030 | { | |
9031 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
9032 | struct cfg80211_beacon_registration *reg, *nreg; |
9033 | int rv; | |
5e760230 JB |
9034 | |
9035 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
9036 | return -EOPNOTSUPP; | |
9037 | ||
37c73b5f BG |
9038 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
9039 | if (!nreg) | |
9040 | return -ENOMEM; | |
9041 | ||
9042 | /* First, check if already registered. */ | |
9043 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
9044 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
9045 | if (reg->nlportid == info->snd_portid) { | |
9046 | rv = -EALREADY; | |
9047 | goto out_err; | |
9048 | } | |
9049 | } | |
9050 | /* Add it to the list */ | |
9051 | nreg->nlportid = info->snd_portid; | |
9052 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 9053 | |
37c73b5f | 9054 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
9055 | |
9056 | return 0; | |
37c73b5f BG |
9057 | out_err: |
9058 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
9059 | kfree(nreg); | |
9060 | return rv; | |
5e760230 JB |
9061 | } |
9062 | ||
98104fde JB |
9063 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
9064 | { | |
9065 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9066 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9067 | int err; | |
9068 | ||
9069 | if (!rdev->ops->start_p2p_device) | |
9070 | return -EOPNOTSUPP; | |
9071 | ||
9072 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9073 | return -EOPNOTSUPP; | |
9074 | ||
9075 | if (wdev->p2p_started) | |
9076 | return 0; | |
9077 | ||
b6a55015 LC |
9078 | if (rfkill_blocked(rdev->rfkill)) |
9079 | return -ERFKILL; | |
98104fde | 9080 | |
eeb126e9 | 9081 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
9082 | if (err) |
9083 | return err; | |
9084 | ||
9085 | wdev->p2p_started = true; | |
98104fde | 9086 | rdev->opencount++; |
98104fde JB |
9087 | |
9088 | return 0; | |
9089 | } | |
9090 | ||
9091 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
9092 | { | |
9093 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9094 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9095 | ||
9096 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9097 | return -EOPNOTSUPP; | |
9098 | ||
9099 | if (!rdev->ops->stop_p2p_device) | |
9100 | return -EOPNOTSUPP; | |
9101 | ||
f9f47529 | 9102 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
9103 | |
9104 | return 0; | |
9105 | } | |
9106 | ||
3713b4e3 JB |
9107 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
9108 | struct genl_info *info) | |
9109 | { | |
9110 | void *hdr; | |
9111 | struct sk_buff *msg; | |
9112 | ||
9113 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9114 | if (!msg) | |
9115 | return -ENOMEM; | |
9116 | ||
9117 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9118 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
9119 | if (!hdr) | |
9120 | goto nla_put_failure; | |
9121 | ||
9122 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
9123 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
9124 | goto nla_put_failure; | |
9125 | ||
9126 | genlmsg_end(msg, hdr); | |
9127 | return genlmsg_reply(msg, info); | |
9128 | ||
9129 | nla_put_failure: | |
9130 | kfree_skb(msg); | |
9131 | return -ENOBUFS; | |
9132 | } | |
9133 | ||
355199e0 JM |
9134 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
9135 | { | |
9136 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9137 | struct cfg80211_update_ft_ies_params ft_params; | |
9138 | struct net_device *dev = info->user_ptr[1]; | |
9139 | ||
9140 | if (!rdev->ops->update_ft_ies) | |
9141 | return -EOPNOTSUPP; | |
9142 | ||
9143 | if (!info->attrs[NL80211_ATTR_MDID] || | |
9144 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
9145 | return -EINVAL; | |
9146 | ||
9147 | memset(&ft_params, 0, sizeof(ft_params)); | |
9148 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
9149 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
9150 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9151 | ||
9152 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
9153 | } | |
9154 | ||
5de17984 AS |
9155 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
9156 | struct genl_info *info) | |
9157 | { | |
9158 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9159 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9160 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
9161 | u16 duration; | |
9162 | int ret; | |
9163 | ||
9164 | if (!rdev->ops->crit_proto_start) | |
9165 | return -EOPNOTSUPP; | |
9166 | ||
9167 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
9168 | return -EINVAL; | |
9169 | ||
9170 | if (rdev->crit_proto_nlportid) | |
9171 | return -EBUSY; | |
9172 | ||
9173 | /* determine protocol if provided */ | |
9174 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
9175 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
9176 | ||
9177 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
9178 | return -EINVAL; | |
9179 | ||
9180 | /* timeout must be provided */ | |
9181 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
9182 | return -EINVAL; | |
9183 | ||
9184 | duration = | |
9185 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
9186 | ||
9187 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
9188 | return -ERANGE; | |
9189 | ||
9190 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
9191 | if (!ret) | |
9192 | rdev->crit_proto_nlportid = info->snd_portid; | |
9193 | ||
9194 | return ret; | |
9195 | } | |
9196 | ||
9197 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
9198 | struct genl_info *info) | |
9199 | { | |
9200 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9201 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9202 | ||
9203 | if (!rdev->ops->crit_proto_stop) | |
9204 | return -EOPNOTSUPP; | |
9205 | ||
9206 | if (rdev->crit_proto_nlportid) { | |
9207 | rdev->crit_proto_nlportid = 0; | |
9208 | rdev_crit_proto_stop(rdev, wdev); | |
9209 | } | |
9210 | return 0; | |
9211 | } | |
9212 | ||
ad7e718c JB |
9213 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
9214 | { | |
9215 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9216 | struct wireless_dev *wdev = | |
9217 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
9218 | int i, err; | |
9219 | u32 vid, subcmd; | |
9220 | ||
9221 | if (!rdev->wiphy.vendor_commands) | |
9222 | return -EOPNOTSUPP; | |
9223 | ||
9224 | if (IS_ERR(wdev)) { | |
9225 | err = PTR_ERR(wdev); | |
9226 | if (err != -EINVAL) | |
9227 | return err; | |
9228 | wdev = NULL; | |
9229 | } else if (wdev->wiphy != &rdev->wiphy) { | |
9230 | return -EINVAL; | |
9231 | } | |
9232 | ||
9233 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
9234 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
9235 | return -EINVAL; | |
9236 | ||
9237 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
9238 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
9239 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
9240 | const struct wiphy_vendor_command *vcmd; | |
9241 | void *data = NULL; | |
9242 | int len = 0; | |
9243 | ||
9244 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
9245 | ||
9246 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
9247 | continue; | |
9248 | ||
9249 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
9250 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
9251 | if (!wdev) | |
9252 | return -EINVAL; | |
9253 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
9254 | !wdev->netdev) | |
9255 | return -EINVAL; | |
9256 | ||
9257 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
9258 | if (wdev->netdev && | |
9259 | !netif_running(wdev->netdev)) | |
9260 | return -ENETDOWN; | |
9261 | if (!wdev->netdev && !wdev->p2p_started) | |
9262 | return -ENETDOWN; | |
9263 | } | |
9264 | } else { | |
9265 | wdev = NULL; | |
9266 | } | |
9267 | ||
9268 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
9269 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9270 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9271 | } | |
9272 | ||
9273 | rdev->cur_cmd_info = info; | |
9274 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
9275 | data, len); | |
9276 | rdev->cur_cmd_info = NULL; | |
9277 | return err; | |
9278 | } | |
9279 | ||
9280 | return -EOPNOTSUPP; | |
9281 | } | |
9282 | ||
9283 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | |
9284 | enum nl80211_commands cmd, | |
9285 | enum nl80211_attrs attr, | |
9286 | int approxlen) | |
9287 | { | |
f26cbf40 | 9288 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
9289 | |
9290 | if (WARN_ON(!rdev->cur_cmd_info)) | |
9291 | return NULL; | |
9292 | ||
9293 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, | |
9294 | rdev->cur_cmd_info->snd_portid, | |
9295 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 9296 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
9297 | } |
9298 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
9299 | ||
9300 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
9301 | { | |
9302 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
9303 | void *hdr = ((void **)skb->cb)[1]; | |
9304 | struct nlattr *data = ((void **)skb->cb)[2]; | |
9305 | ||
9306 | if (WARN_ON(!rdev->cur_cmd_info)) { | |
9307 | kfree_skb(skb); | |
9308 | return -EINVAL; | |
9309 | } | |
9310 | ||
9311 | nla_nest_end(skb, data); | |
9312 | genlmsg_end(skb, hdr); | |
9313 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
9314 | } | |
9315 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
9316 | ||
9317 | ||
fa9ffc74 KP |
9318 | static int nl80211_set_qos_map(struct sk_buff *skb, |
9319 | struct genl_info *info) | |
9320 | { | |
9321 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9322 | struct cfg80211_qos_map *qos_map = NULL; | |
9323 | struct net_device *dev = info->user_ptr[1]; | |
9324 | u8 *pos, len, num_des, des_len, des; | |
9325 | int ret; | |
9326 | ||
9327 | if (!rdev->ops->set_qos_map) | |
9328 | return -EOPNOTSUPP; | |
9329 | ||
9330 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
9331 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9332 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9333 | ||
9334 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
9335 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
9336 | return -EINVAL; | |
9337 | ||
9338 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
9339 | if (!qos_map) | |
9340 | return -ENOMEM; | |
9341 | ||
9342 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
9343 | if (num_des) { | |
9344 | des_len = num_des * | |
9345 | sizeof(struct cfg80211_dscp_exception); | |
9346 | memcpy(qos_map->dscp_exception, pos, des_len); | |
9347 | qos_map->num_des = num_des; | |
9348 | for (des = 0; des < num_des; des++) { | |
9349 | if (qos_map->dscp_exception[des].up > 7) { | |
9350 | kfree(qos_map); | |
9351 | return -EINVAL; | |
9352 | } | |
9353 | } | |
9354 | pos += des_len; | |
9355 | } | |
9356 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
9357 | } | |
9358 | ||
9359 | wdev_lock(dev->ieee80211_ptr); | |
9360 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
9361 | if (!ret) | |
9362 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
9363 | wdev_unlock(dev->ieee80211_ptr); | |
9364 | ||
9365 | kfree(qos_map); | |
9366 | return ret; | |
9367 | } | |
9368 | ||
4c476991 JB |
9369 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
9370 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
9371 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
9372 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
9373 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
9374 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 9375 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 9376 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
9377 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
9378 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 | 9379 | |
f84f771d | 9380 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
9381 | struct genl_info *info) |
9382 | { | |
9383 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 9384 | struct wireless_dev *wdev; |
4c476991 | 9385 | struct net_device *dev; |
4c476991 JB |
9386 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
9387 | ||
9388 | if (rtnl) | |
9389 | rtnl_lock(); | |
9390 | ||
9391 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 9392 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
9393 | if (IS_ERR(rdev)) { |
9394 | if (rtnl) | |
9395 | rtnl_unlock(); | |
9396 | return PTR_ERR(rdev); | |
9397 | } | |
9398 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
9399 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
9400 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
9401 | ASSERT_RTNL(); |
9402 | ||
89a54e48 JB |
9403 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
9404 | info->attrs); | |
9405 | if (IS_ERR(wdev)) { | |
4c476991 JB |
9406 | if (rtnl) |
9407 | rtnl_unlock(); | |
89a54e48 | 9408 | return PTR_ERR(wdev); |
4c476991 | 9409 | } |
89a54e48 | 9410 | |
89a54e48 | 9411 | dev = wdev->netdev; |
f26cbf40 | 9412 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 9413 | |
1bf614ef JB |
9414 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
9415 | if (!dev) { | |
1bf614ef JB |
9416 | if (rtnl) |
9417 | rtnl_unlock(); | |
9418 | return -EINVAL; | |
9419 | } | |
9420 | ||
9421 | info->user_ptr[1] = dev; | |
9422 | } else { | |
9423 | info->user_ptr[1] = wdev; | |
41265714 | 9424 | } |
1bf614ef JB |
9425 | |
9426 | if (dev) { | |
9427 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
9428 | !netif_running(dev)) { | |
1bf614ef JB |
9429 | if (rtnl) |
9430 | rtnl_unlock(); | |
9431 | return -ENETDOWN; | |
9432 | } | |
9433 | ||
9434 | dev_hold(dev); | |
98104fde JB |
9435 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
9436 | if (!wdev->p2p_started) { | |
98104fde JB |
9437 | if (rtnl) |
9438 | rtnl_unlock(); | |
9439 | return -ENETDOWN; | |
9440 | } | |
41265714 | 9441 | } |
89a54e48 | 9442 | |
4c476991 | 9443 | info->user_ptr[0] = rdev; |
4c476991 JB |
9444 | } |
9445 | ||
9446 | return 0; | |
9447 | } | |
9448 | ||
f84f771d | 9449 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
9450 | struct genl_info *info) |
9451 | { | |
1bf614ef JB |
9452 | if (info->user_ptr[1]) { |
9453 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
9454 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9455 | ||
9456 | if (wdev->netdev) | |
9457 | dev_put(wdev->netdev); | |
9458 | } else { | |
9459 | dev_put(info->user_ptr[1]); | |
9460 | } | |
9461 | } | |
4c476991 JB |
9462 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
9463 | rtnl_unlock(); | |
9464 | } | |
9465 | ||
4534de83 | 9466 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
9467 | { |
9468 | .cmd = NL80211_CMD_GET_WIPHY, | |
9469 | .doit = nl80211_get_wiphy, | |
9470 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 9471 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
9472 | .policy = nl80211_policy, |
9473 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
9474 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9475 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9476 | }, |
9477 | { | |
9478 | .cmd = NL80211_CMD_SET_WIPHY, | |
9479 | .doit = nl80211_set_wiphy, | |
9480 | .policy = nl80211_policy, | |
9481 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 9482 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
9483 | }, |
9484 | { | |
9485 | .cmd = NL80211_CMD_GET_INTERFACE, | |
9486 | .doit = nl80211_get_interface, | |
9487 | .dumpit = nl80211_dump_interface, | |
9488 | .policy = nl80211_policy, | |
9489 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
9490 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
9491 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9492 | }, |
9493 | { | |
9494 | .cmd = NL80211_CMD_SET_INTERFACE, | |
9495 | .doit = nl80211_set_interface, | |
9496 | .policy = nl80211_policy, | |
9497 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9498 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9499 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9500 | }, |
9501 | { | |
9502 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
9503 | .doit = nl80211_new_interface, | |
9504 | .policy = nl80211_policy, | |
9505 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9506 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9507 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9508 | }, |
9509 | { | |
9510 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
9511 | .doit = nl80211_del_interface, | |
9512 | .policy = nl80211_policy, | |
41ade00f | 9513 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 9514 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 9515 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9516 | }, |
9517 | { | |
9518 | .cmd = NL80211_CMD_GET_KEY, | |
9519 | .doit = nl80211_get_key, | |
9520 | .policy = nl80211_policy, | |
9521 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9522 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9523 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9524 | }, |
9525 | { | |
9526 | .cmd = NL80211_CMD_SET_KEY, | |
9527 | .doit = nl80211_set_key, | |
9528 | .policy = nl80211_policy, | |
9529 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9530 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9531 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9532 | }, |
9533 | { | |
9534 | .cmd = NL80211_CMD_NEW_KEY, | |
9535 | .doit = nl80211_new_key, | |
9536 | .policy = nl80211_policy, | |
9537 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9538 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9539 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9540 | }, |
9541 | { | |
9542 | .cmd = NL80211_CMD_DEL_KEY, | |
9543 | .doit = nl80211_del_key, | |
9544 | .policy = nl80211_policy, | |
55682965 | 9545 | .flags = GENL_ADMIN_PERM, |
41265714 | 9546 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9547 | NL80211_FLAG_NEED_RTNL, |
55682965 | 9548 | }, |
ed1b6cc7 JB |
9549 | { |
9550 | .cmd = NL80211_CMD_SET_BEACON, | |
9551 | .policy = nl80211_policy, | |
9552 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9553 | .doit = nl80211_set_beacon, |
2b5f8b0b | 9554 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9555 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
9556 | }, |
9557 | { | |
8860020e | 9558 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
9559 | .policy = nl80211_policy, |
9560 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9561 | .doit = nl80211_start_ap, |
2b5f8b0b | 9562 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9563 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
9564 | }, |
9565 | { | |
8860020e | 9566 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
9567 | .policy = nl80211_policy, |
9568 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9569 | .doit = nl80211_stop_ap, |
2b5f8b0b | 9570 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9571 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 9572 | }, |
5727ef1b JB |
9573 | { |
9574 | .cmd = NL80211_CMD_GET_STATION, | |
9575 | .doit = nl80211_get_station, | |
2ec600d6 | 9576 | .dumpit = nl80211_dump_station, |
5727ef1b | 9577 | .policy = nl80211_policy, |
4c476991 JB |
9578 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9579 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
9580 | }, |
9581 | { | |
9582 | .cmd = NL80211_CMD_SET_STATION, | |
9583 | .doit = nl80211_set_station, | |
9584 | .policy = nl80211_policy, | |
9585 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9586 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9587 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
9588 | }, |
9589 | { | |
9590 | .cmd = NL80211_CMD_NEW_STATION, | |
9591 | .doit = nl80211_new_station, | |
9592 | .policy = nl80211_policy, | |
9593 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9594 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9595 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
9596 | }, |
9597 | { | |
9598 | .cmd = NL80211_CMD_DEL_STATION, | |
9599 | .doit = nl80211_del_station, | |
9600 | .policy = nl80211_policy, | |
2ec600d6 | 9601 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9602 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9603 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9604 | }, |
9605 | { | |
9606 | .cmd = NL80211_CMD_GET_MPATH, | |
9607 | .doit = nl80211_get_mpath, | |
9608 | .dumpit = nl80211_dump_mpath, | |
9609 | .policy = nl80211_policy, | |
9610 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9611 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9612 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9613 | }, |
9614 | { | |
9615 | .cmd = NL80211_CMD_SET_MPATH, | |
9616 | .doit = nl80211_set_mpath, | |
9617 | .policy = nl80211_policy, | |
9618 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9619 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9620 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9621 | }, |
9622 | { | |
9623 | .cmd = NL80211_CMD_NEW_MPATH, | |
9624 | .doit = nl80211_new_mpath, | |
9625 | .policy = nl80211_policy, | |
9626 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9627 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9628 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9629 | }, |
9630 | { | |
9631 | .cmd = NL80211_CMD_DEL_MPATH, | |
9632 | .doit = nl80211_del_mpath, | |
9633 | .policy = nl80211_policy, | |
9f1ba906 | 9634 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9635 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9636 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
9637 | }, |
9638 | { | |
9639 | .cmd = NL80211_CMD_SET_BSS, | |
9640 | .doit = nl80211_set_bss, | |
9641 | .policy = nl80211_policy, | |
b2e1b302 | 9642 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9643 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9644 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 9645 | }, |
f130347c LR |
9646 | { |
9647 | .cmd = NL80211_CMD_GET_REG, | |
9648 | .doit = nl80211_get_reg, | |
9649 | .policy = nl80211_policy, | |
5fe231e8 | 9650 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
9651 | /* can be retrieved by unprivileged users */ |
9652 | }, | |
b2e1b302 LR |
9653 | { |
9654 | .cmd = NL80211_CMD_SET_REG, | |
9655 | .doit = nl80211_set_reg, | |
9656 | .policy = nl80211_policy, | |
9657 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 9658 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
9659 | }, |
9660 | { | |
9661 | .cmd = NL80211_CMD_REQ_SET_REG, | |
9662 | .doit = nl80211_req_set_reg, | |
9663 | .policy = nl80211_policy, | |
93da9cc1 | 9664 | .flags = GENL_ADMIN_PERM, |
9665 | }, | |
9666 | { | |
24bdd9f4 JC |
9667 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
9668 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 9669 | .policy = nl80211_policy, |
9670 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 9671 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9672 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 9673 | }, |
9674 | { | |
24bdd9f4 JC |
9675 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
9676 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 9677 | .policy = nl80211_policy, |
9aed3cc1 | 9678 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 9679 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9680 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 9681 | }, |
2a519311 JB |
9682 | { |
9683 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
9684 | .doit = nl80211_trigger_scan, | |
9685 | .policy = nl80211_policy, | |
9686 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 9687 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9688 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
9689 | }, |
9690 | { | |
9691 | .cmd = NL80211_CMD_GET_SCAN, | |
9692 | .policy = nl80211_policy, | |
9693 | .dumpit = nl80211_dump_scan, | |
9694 | }, | |
807f8a8c LC |
9695 | { |
9696 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
9697 | .doit = nl80211_start_sched_scan, | |
9698 | .policy = nl80211_policy, | |
9699 | .flags = GENL_ADMIN_PERM, | |
9700 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9701 | NL80211_FLAG_NEED_RTNL, | |
9702 | }, | |
9703 | { | |
9704 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
9705 | .doit = nl80211_stop_sched_scan, | |
9706 | .policy = nl80211_policy, | |
9707 | .flags = GENL_ADMIN_PERM, | |
9708 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9709 | NL80211_FLAG_NEED_RTNL, | |
9710 | }, | |
636a5d36 JM |
9711 | { |
9712 | .cmd = NL80211_CMD_AUTHENTICATE, | |
9713 | .doit = nl80211_authenticate, | |
9714 | .policy = nl80211_policy, | |
9715 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9716 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9717 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9718 | }, |
9719 | { | |
9720 | .cmd = NL80211_CMD_ASSOCIATE, | |
9721 | .doit = nl80211_associate, | |
9722 | .policy = nl80211_policy, | |
9723 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9724 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9725 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9726 | }, |
9727 | { | |
9728 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
9729 | .doit = nl80211_deauthenticate, | |
9730 | .policy = nl80211_policy, | |
9731 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9732 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9733 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9734 | }, |
9735 | { | |
9736 | .cmd = NL80211_CMD_DISASSOCIATE, | |
9737 | .doit = nl80211_disassociate, | |
9738 | .policy = nl80211_policy, | |
9739 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9740 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9741 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 9742 | }, |
04a773ad JB |
9743 | { |
9744 | .cmd = NL80211_CMD_JOIN_IBSS, | |
9745 | .doit = nl80211_join_ibss, | |
9746 | .policy = nl80211_policy, | |
9747 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9748 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9749 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
9750 | }, |
9751 | { | |
9752 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
9753 | .doit = nl80211_leave_ibss, | |
9754 | .policy = nl80211_policy, | |
9755 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9756 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9757 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 9758 | }, |
aff89a9b JB |
9759 | #ifdef CONFIG_NL80211_TESTMODE |
9760 | { | |
9761 | .cmd = NL80211_CMD_TESTMODE, | |
9762 | .doit = nl80211_testmode_do, | |
71063f0e | 9763 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
9764 | .policy = nl80211_policy, |
9765 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9766 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9767 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
9768 | }, |
9769 | #endif | |
b23aa676 SO |
9770 | { |
9771 | .cmd = NL80211_CMD_CONNECT, | |
9772 | .doit = nl80211_connect, | |
9773 | .policy = nl80211_policy, | |
9774 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9775 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9776 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
9777 | }, |
9778 | { | |
9779 | .cmd = NL80211_CMD_DISCONNECT, | |
9780 | .doit = nl80211_disconnect, | |
9781 | .policy = nl80211_policy, | |
9782 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9783 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9784 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 9785 | }, |
463d0183 JB |
9786 | { |
9787 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
9788 | .doit = nl80211_wiphy_netns, | |
9789 | .policy = nl80211_policy, | |
9790 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9791 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9792 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 9793 | }, |
61fa713c HS |
9794 | { |
9795 | .cmd = NL80211_CMD_GET_SURVEY, | |
9796 | .policy = nl80211_policy, | |
9797 | .dumpit = nl80211_dump_survey, | |
9798 | }, | |
67fbb16b SO |
9799 | { |
9800 | .cmd = NL80211_CMD_SET_PMKSA, | |
9801 | .doit = nl80211_setdel_pmksa, | |
9802 | .policy = nl80211_policy, | |
9803 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9804 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9805 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9806 | }, |
9807 | { | |
9808 | .cmd = NL80211_CMD_DEL_PMKSA, | |
9809 | .doit = nl80211_setdel_pmksa, | |
9810 | .policy = nl80211_policy, | |
9811 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9812 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9813 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9814 | }, |
9815 | { | |
9816 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
9817 | .doit = nl80211_flush_pmksa, | |
9818 | .policy = nl80211_policy, | |
9819 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9820 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9821 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 9822 | }, |
9588bbd5 JM |
9823 | { |
9824 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
9825 | .doit = nl80211_remain_on_channel, | |
9826 | .policy = nl80211_policy, | |
9827 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9828 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9829 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
9830 | }, |
9831 | { | |
9832 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
9833 | .doit = nl80211_cancel_remain_on_channel, | |
9834 | .policy = nl80211_policy, | |
9835 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9836 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9837 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 9838 | }, |
13ae75b1 JM |
9839 | { |
9840 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
9841 | .doit = nl80211_set_tx_bitrate_mask, | |
9842 | .policy = nl80211_policy, | |
9843 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9844 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9845 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 9846 | }, |
026331c4 | 9847 | { |
2e161f78 JB |
9848 | .cmd = NL80211_CMD_REGISTER_FRAME, |
9849 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
9850 | .policy = nl80211_policy, |
9851 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9852 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 9853 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
9854 | }, |
9855 | { | |
2e161f78 JB |
9856 | .cmd = NL80211_CMD_FRAME, |
9857 | .doit = nl80211_tx_mgmt, | |
026331c4 | 9858 | .policy = nl80211_policy, |
f7ca38df | 9859 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9860 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
9861 | NL80211_FLAG_NEED_RTNL, |
9862 | }, | |
9863 | { | |
9864 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
9865 | .doit = nl80211_tx_mgmt_cancel_wait, | |
9866 | .policy = nl80211_policy, | |
026331c4 | 9867 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9868 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9869 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 9870 | }, |
ffb9eb3d KV |
9871 | { |
9872 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
9873 | .doit = nl80211_set_power_save, | |
9874 | .policy = nl80211_policy, | |
9875 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9876 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9877 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
9878 | }, |
9879 | { | |
9880 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
9881 | .doit = nl80211_get_power_save, | |
9882 | .policy = nl80211_policy, | |
9883 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
9884 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9885 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 9886 | }, |
d6dc1a38 JO |
9887 | { |
9888 | .cmd = NL80211_CMD_SET_CQM, | |
9889 | .doit = nl80211_set_cqm, | |
9890 | .policy = nl80211_policy, | |
9891 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9892 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9893 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 9894 | }, |
f444de05 JB |
9895 | { |
9896 | .cmd = NL80211_CMD_SET_CHANNEL, | |
9897 | .doit = nl80211_set_channel, | |
9898 | .policy = nl80211_policy, | |
9899 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9900 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9901 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 9902 | }, |
e8347eba BJ |
9903 | { |
9904 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
9905 | .doit = nl80211_set_wds_peer, | |
9906 | .policy = nl80211_policy, | |
9907 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
9908 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9909 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 9910 | }, |
29cbe68c JB |
9911 | { |
9912 | .cmd = NL80211_CMD_JOIN_MESH, | |
9913 | .doit = nl80211_join_mesh, | |
9914 | .policy = nl80211_policy, | |
9915 | .flags = GENL_ADMIN_PERM, | |
9916 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9917 | NL80211_FLAG_NEED_RTNL, | |
9918 | }, | |
9919 | { | |
9920 | .cmd = NL80211_CMD_LEAVE_MESH, | |
9921 | .doit = nl80211_leave_mesh, | |
9922 | .policy = nl80211_policy, | |
9923 | .flags = GENL_ADMIN_PERM, | |
9924 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9925 | NL80211_FLAG_NEED_RTNL, | |
9926 | }, | |
dfb89c56 | 9927 | #ifdef CONFIG_PM |
ff1b6e69 JB |
9928 | { |
9929 | .cmd = NL80211_CMD_GET_WOWLAN, | |
9930 | .doit = nl80211_get_wowlan, | |
9931 | .policy = nl80211_policy, | |
9932 | /* can be retrieved by unprivileged users */ | |
9933 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9934 | NL80211_FLAG_NEED_RTNL, | |
9935 | }, | |
9936 | { | |
9937 | .cmd = NL80211_CMD_SET_WOWLAN, | |
9938 | .doit = nl80211_set_wowlan, | |
9939 | .policy = nl80211_policy, | |
9940 | .flags = GENL_ADMIN_PERM, | |
9941 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9942 | NL80211_FLAG_NEED_RTNL, | |
9943 | }, | |
dfb89c56 | 9944 | #endif |
e5497d76 JB |
9945 | { |
9946 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
9947 | .doit = nl80211_set_rekey_data, | |
9948 | .policy = nl80211_policy, | |
9949 | .flags = GENL_ADMIN_PERM, | |
9950 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9951 | NL80211_FLAG_NEED_RTNL, | |
9952 | }, | |
109086ce AN |
9953 | { |
9954 | .cmd = NL80211_CMD_TDLS_MGMT, | |
9955 | .doit = nl80211_tdls_mgmt, | |
9956 | .policy = nl80211_policy, | |
9957 | .flags = GENL_ADMIN_PERM, | |
9958 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9959 | NL80211_FLAG_NEED_RTNL, | |
9960 | }, | |
9961 | { | |
9962 | .cmd = NL80211_CMD_TDLS_OPER, | |
9963 | .doit = nl80211_tdls_oper, | |
9964 | .policy = nl80211_policy, | |
9965 | .flags = GENL_ADMIN_PERM, | |
9966 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9967 | NL80211_FLAG_NEED_RTNL, | |
9968 | }, | |
28946da7 JB |
9969 | { |
9970 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
9971 | .doit = nl80211_register_unexpected_frame, | |
9972 | .policy = nl80211_policy, | |
9973 | .flags = GENL_ADMIN_PERM, | |
9974 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9975 | NL80211_FLAG_NEED_RTNL, | |
9976 | }, | |
7f6cf311 JB |
9977 | { |
9978 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
9979 | .doit = nl80211_probe_client, | |
9980 | .policy = nl80211_policy, | |
9981 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9982 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
9983 | NL80211_FLAG_NEED_RTNL, |
9984 | }, | |
5e760230 JB |
9985 | { |
9986 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
9987 | .doit = nl80211_register_beacons, | |
9988 | .policy = nl80211_policy, | |
9989 | .flags = GENL_ADMIN_PERM, | |
9990 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9991 | NL80211_FLAG_NEED_RTNL, | |
9992 | }, | |
1d9d9213 SW |
9993 | { |
9994 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
9995 | .doit = nl80211_set_noack_map, | |
9996 | .policy = nl80211_policy, | |
9997 | .flags = GENL_ADMIN_PERM, | |
9998 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9999 | NL80211_FLAG_NEED_RTNL, | |
10000 | }, | |
98104fde JB |
10001 | { |
10002 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
10003 | .doit = nl80211_start_p2p_device, | |
10004 | .policy = nl80211_policy, | |
10005 | .flags = GENL_ADMIN_PERM, | |
10006 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
10007 | NL80211_FLAG_NEED_RTNL, | |
10008 | }, | |
10009 | { | |
10010 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
10011 | .doit = nl80211_stop_p2p_device, | |
10012 | .policy = nl80211_policy, | |
10013 | .flags = GENL_ADMIN_PERM, | |
10014 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10015 | NL80211_FLAG_NEED_RTNL, | |
10016 | }, | |
f4e583c8 AQ |
10017 | { |
10018 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
10019 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
10020 | .policy = nl80211_policy, |
10021 | .flags = GENL_ADMIN_PERM, | |
10022 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10023 | NL80211_FLAG_NEED_RTNL, | |
10024 | }, | |
10025 | { | |
10026 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
10027 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
10028 | .policy = nl80211_policy, |
10029 | .flags = GENL_ADMIN_PERM, | |
10030 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10031 | NL80211_FLAG_NEED_RTNL, | |
10032 | }, | |
04f39047 SW |
10033 | { |
10034 | .cmd = NL80211_CMD_RADAR_DETECT, | |
10035 | .doit = nl80211_start_radar_detection, | |
10036 | .policy = nl80211_policy, | |
10037 | .flags = GENL_ADMIN_PERM, | |
10038 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10039 | NL80211_FLAG_NEED_RTNL, | |
10040 | }, | |
3713b4e3 JB |
10041 | { |
10042 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
10043 | .doit = nl80211_get_protocol_features, | |
10044 | .policy = nl80211_policy, | |
10045 | }, | |
355199e0 JM |
10046 | { |
10047 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
10048 | .doit = nl80211_update_ft_ies, | |
10049 | .policy = nl80211_policy, | |
10050 | .flags = GENL_ADMIN_PERM, | |
10051 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10052 | NL80211_FLAG_NEED_RTNL, | |
10053 | }, | |
5de17984 AS |
10054 | { |
10055 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
10056 | .doit = nl80211_crit_protocol_start, | |
10057 | .policy = nl80211_policy, | |
10058 | .flags = GENL_ADMIN_PERM, | |
10059 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10060 | NL80211_FLAG_NEED_RTNL, | |
10061 | }, | |
10062 | { | |
10063 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
10064 | .doit = nl80211_crit_protocol_stop, | |
10065 | .policy = nl80211_policy, | |
10066 | .flags = GENL_ADMIN_PERM, | |
10067 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10068 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
10069 | }, |
10070 | { | |
10071 | .cmd = NL80211_CMD_GET_COALESCE, | |
10072 | .doit = nl80211_get_coalesce, | |
10073 | .policy = nl80211_policy, | |
10074 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10075 | NL80211_FLAG_NEED_RTNL, | |
10076 | }, | |
10077 | { | |
10078 | .cmd = NL80211_CMD_SET_COALESCE, | |
10079 | .doit = nl80211_set_coalesce, | |
10080 | .policy = nl80211_policy, | |
10081 | .flags = GENL_ADMIN_PERM, | |
10082 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10083 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
10084 | }, |
10085 | { | |
10086 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
10087 | .doit = nl80211_channel_switch, | |
10088 | .policy = nl80211_policy, | |
10089 | .flags = GENL_ADMIN_PERM, | |
10090 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10091 | NL80211_FLAG_NEED_RTNL, | |
10092 | }, | |
ad7e718c JB |
10093 | { |
10094 | .cmd = NL80211_CMD_VENDOR, | |
10095 | .doit = nl80211_vendor_cmd, | |
10096 | .policy = nl80211_policy, | |
10097 | .flags = GENL_ADMIN_PERM, | |
10098 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10099 | NL80211_FLAG_NEED_RTNL, | |
10100 | }, | |
fa9ffc74 KP |
10101 | { |
10102 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
10103 | .doit = nl80211_set_qos_map, | |
10104 | .policy = nl80211_policy, | |
10105 | .flags = GENL_ADMIN_PERM, | |
10106 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10107 | NL80211_FLAG_NEED_RTNL, | |
10108 | }, | |
55682965 | 10109 | }; |
9588bbd5 | 10110 | |
55682965 JB |
10111 | /* notification functions */ |
10112 | ||
3bb20556 JB |
10113 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
10114 | enum nl80211_commands cmd) | |
55682965 JB |
10115 | { |
10116 | struct sk_buff *msg; | |
86e8cf98 | 10117 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 10118 | |
3bb20556 JB |
10119 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
10120 | cmd != NL80211_CMD_DEL_WIPHY); | |
10121 | ||
fd2120ca | 10122 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
10123 | if (!msg) |
10124 | return; | |
10125 | ||
3bb20556 | 10126 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
10127 | nlmsg_free(msg); |
10128 | return; | |
10129 | } | |
10130 | ||
68eb5503 | 10131 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10132 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
10133 | } |
10134 | ||
362a415d JB |
10135 | static int nl80211_add_scan_req(struct sk_buff *msg, |
10136 | struct cfg80211_registered_device *rdev) | |
10137 | { | |
10138 | struct cfg80211_scan_request *req = rdev->scan_req; | |
10139 | struct nlattr *nest; | |
10140 | int i; | |
10141 | ||
10142 | if (WARN_ON(!req)) | |
10143 | return 0; | |
10144 | ||
10145 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
10146 | if (!nest) | |
10147 | goto nla_put_failure; | |
9360ffd1 DM |
10148 | for (i = 0; i < req->n_ssids; i++) { |
10149 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
10150 | goto nla_put_failure; | |
10151 | } | |
362a415d JB |
10152 | nla_nest_end(msg, nest); |
10153 | ||
10154 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
10155 | if (!nest) | |
10156 | goto nla_put_failure; | |
9360ffd1 DM |
10157 | for (i = 0; i < req->n_channels; i++) { |
10158 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
10159 | goto nla_put_failure; | |
10160 | } | |
362a415d JB |
10161 | nla_nest_end(msg, nest); |
10162 | ||
9360ffd1 DM |
10163 | if (req->ie && |
10164 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
10165 | goto nla_put_failure; | |
362a415d | 10166 | |
ae917c9f JB |
10167 | if (req->flags && |
10168 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
10169 | goto nla_put_failure; | |
ed473771 | 10170 | |
362a415d JB |
10171 | return 0; |
10172 | nla_put_failure: | |
10173 | return -ENOBUFS; | |
10174 | } | |
10175 | ||
a538e2d5 JB |
10176 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
10177 | struct cfg80211_registered_device *rdev, | |
fd014284 | 10178 | struct wireless_dev *wdev, |
15e47304 | 10179 | u32 portid, u32 seq, int flags, |
a538e2d5 | 10180 | u32 cmd) |
2a519311 JB |
10181 | { |
10182 | void *hdr; | |
10183 | ||
15e47304 | 10184 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
10185 | if (!hdr) |
10186 | return -1; | |
10187 | ||
9360ffd1 | 10188 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
10189 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10190 | wdev->netdev->ifindex)) || | |
10191 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 10192 | goto nla_put_failure; |
2a519311 | 10193 | |
362a415d JB |
10194 | /* ignore errors and send incomplete event anyway */ |
10195 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
10196 | |
10197 | return genlmsg_end(msg, hdr); | |
10198 | ||
10199 | nla_put_failure: | |
10200 | genlmsg_cancel(msg, hdr); | |
10201 | return -EMSGSIZE; | |
10202 | } | |
10203 | ||
807f8a8c LC |
10204 | static int |
10205 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
10206 | struct cfg80211_registered_device *rdev, | |
10207 | struct net_device *netdev, | |
15e47304 | 10208 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
10209 | { |
10210 | void *hdr; | |
10211 | ||
15e47304 | 10212 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
10213 | if (!hdr) |
10214 | return -1; | |
10215 | ||
9360ffd1 DM |
10216 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10217 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
10218 | goto nla_put_failure; | |
807f8a8c LC |
10219 | |
10220 | return genlmsg_end(msg, hdr); | |
10221 | ||
10222 | nla_put_failure: | |
10223 | genlmsg_cancel(msg, hdr); | |
10224 | return -EMSGSIZE; | |
10225 | } | |
10226 | ||
a538e2d5 | 10227 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 10228 | struct wireless_dev *wdev) |
a538e2d5 JB |
10229 | { |
10230 | struct sk_buff *msg; | |
10231 | ||
58050fce | 10232 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
10233 | if (!msg) |
10234 | return; | |
10235 | ||
fd014284 | 10236 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
10237 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
10238 | nlmsg_free(msg); | |
10239 | return; | |
10240 | } | |
10241 | ||
68eb5503 | 10242 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10243 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
10244 | } |
10245 | ||
f9d15d16 JB |
10246 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
10247 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
10248 | { |
10249 | struct sk_buff *msg; | |
10250 | ||
fd2120ca | 10251 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 10252 | if (!msg) |
f9d15d16 | 10253 | return NULL; |
2a519311 | 10254 | |
fd014284 | 10255 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
10256 | aborted ? NL80211_CMD_SCAN_ABORTED : |
10257 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 10258 | nlmsg_free(msg); |
f9d15d16 | 10259 | return NULL; |
2a519311 JB |
10260 | } |
10261 | ||
f9d15d16 | 10262 | return msg; |
2a519311 JB |
10263 | } |
10264 | ||
f9d15d16 JB |
10265 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
10266 | struct sk_buff *msg) | |
2a519311 | 10267 | { |
2a519311 JB |
10268 | if (!msg) |
10269 | return; | |
10270 | ||
68eb5503 | 10271 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10272 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
10273 | } |
10274 | ||
807f8a8c LC |
10275 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
10276 | struct net_device *netdev) | |
10277 | { | |
10278 | struct sk_buff *msg; | |
10279 | ||
10280 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10281 | if (!msg) | |
10282 | return; | |
10283 | ||
10284 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
10285 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
10286 | nlmsg_free(msg); | |
10287 | return; | |
10288 | } | |
10289 | ||
68eb5503 | 10290 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10291 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
10292 | } |
10293 | ||
10294 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
10295 | struct net_device *netdev, u32 cmd) | |
10296 | { | |
10297 | struct sk_buff *msg; | |
10298 | ||
58050fce | 10299 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
10300 | if (!msg) |
10301 | return; | |
10302 | ||
10303 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
10304 | nlmsg_free(msg); | |
10305 | return; | |
10306 | } | |
10307 | ||
68eb5503 | 10308 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10309 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
10310 | } |
10311 | ||
73d54c9e LR |
10312 | /* |
10313 | * This can happen on global regulatory changes or device specific settings | |
10314 | * based on custom world regulatory domains. | |
10315 | */ | |
10316 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
10317 | { | |
10318 | struct sk_buff *msg; | |
10319 | void *hdr; | |
10320 | ||
fd2120ca | 10321 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
10322 | if (!msg) |
10323 | return; | |
10324 | ||
10325 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
10326 | if (!hdr) { | |
10327 | nlmsg_free(msg); | |
10328 | return; | |
10329 | } | |
10330 | ||
10331 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
10332 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
10333 | goto nla_put_failure; | |
10334 | ||
10335 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
10336 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10337 | NL80211_REGDOM_TYPE_WORLD)) | |
10338 | goto nla_put_failure; | |
10339 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
10340 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10341 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
10342 | goto nla_put_failure; | |
10343 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
10344 | request->intersect) { | |
10345 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10346 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
10347 | goto nla_put_failure; | |
10348 | } else { | |
10349 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10350 | NL80211_REGDOM_TYPE_COUNTRY) || | |
10351 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
10352 | request->alpha2)) | |
10353 | goto nla_put_failure; | |
10354 | } | |
10355 | ||
f4173766 | 10356 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
10357 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
10358 | goto nla_put_failure; | |
73d54c9e | 10359 | |
3b7b72ee | 10360 | genlmsg_end(msg, hdr); |
73d54c9e | 10361 | |
bc43b28c | 10362 | rcu_read_lock(); |
68eb5503 | 10363 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 10364 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 10365 | rcu_read_unlock(); |
73d54c9e LR |
10366 | |
10367 | return; | |
10368 | ||
10369 | nla_put_failure: | |
10370 | genlmsg_cancel(msg, hdr); | |
10371 | nlmsg_free(msg); | |
10372 | } | |
10373 | ||
6039f6d2 JM |
10374 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
10375 | struct net_device *netdev, | |
10376 | const u8 *buf, size_t len, | |
e6d6e342 | 10377 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
10378 | { |
10379 | struct sk_buff *msg; | |
10380 | void *hdr; | |
10381 | ||
e6d6e342 | 10382 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
10383 | if (!msg) |
10384 | return; | |
10385 | ||
10386 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10387 | if (!hdr) { | |
10388 | nlmsg_free(msg); | |
10389 | return; | |
10390 | } | |
10391 | ||
9360ffd1 DM |
10392 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10393 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10394 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
10395 | goto nla_put_failure; | |
6039f6d2 | 10396 | |
3b7b72ee | 10397 | genlmsg_end(msg, hdr); |
6039f6d2 | 10398 | |
68eb5503 | 10399 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10400 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
10401 | return; |
10402 | ||
10403 | nla_put_failure: | |
10404 | genlmsg_cancel(msg, hdr); | |
10405 | nlmsg_free(msg); | |
10406 | } | |
10407 | ||
10408 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10409 | struct net_device *netdev, const u8 *buf, |
10410 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
10411 | { |
10412 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 10413 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
10414 | } |
10415 | ||
10416 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
10417 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 10418 | size_t len, gfp_t gfp) |
6039f6d2 | 10419 | { |
e6d6e342 JB |
10420 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
10421 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
10422 | } |
10423 | ||
53b46b84 | 10424 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
10425 | struct net_device *netdev, const u8 *buf, |
10426 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
10427 | { |
10428 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 10429 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
10430 | } |
10431 | ||
53b46b84 JM |
10432 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
10433 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 10434 | size_t len, gfp_t gfp) |
6039f6d2 JM |
10435 | { |
10436 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 10437 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
10438 | } |
10439 | ||
6ff57cf8 JB |
10440 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
10441 | size_t len) | |
cf4e594e | 10442 | { |
947add36 JB |
10443 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10444 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 10445 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
10446 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
10447 | u32 cmd; | |
947add36 | 10448 | |
6ff57cf8 JB |
10449 | if (WARN_ON(len < 2)) |
10450 | return; | |
cf4e594e | 10451 | |
6ff57cf8 JB |
10452 | if (ieee80211_is_deauth(mgmt->frame_control)) |
10453 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
10454 | else | |
10455 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 10456 | |
6ff57cf8 JB |
10457 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
10458 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); | |
cf4e594e | 10459 | } |
6ff57cf8 | 10460 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 10461 | |
1b06bb40 LR |
10462 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
10463 | struct net_device *netdev, int cmd, | |
e6d6e342 | 10464 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
10465 | { |
10466 | struct sk_buff *msg; | |
10467 | void *hdr; | |
10468 | ||
e6d6e342 | 10469 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
10470 | if (!msg) |
10471 | return; | |
10472 | ||
10473 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10474 | if (!hdr) { | |
10475 | nlmsg_free(msg); | |
10476 | return; | |
10477 | } | |
10478 | ||
9360ffd1 DM |
10479 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10480 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10481 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
10482 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
10483 | goto nla_put_failure; | |
1965c853 | 10484 | |
3b7b72ee | 10485 | genlmsg_end(msg, hdr); |
1965c853 | 10486 | |
68eb5503 | 10487 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10488 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
10489 | return; |
10490 | ||
10491 | nla_put_failure: | |
10492 | genlmsg_cancel(msg, hdr); | |
10493 | nlmsg_free(msg); | |
10494 | } | |
10495 | ||
10496 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10497 | struct net_device *netdev, const u8 *addr, |
10498 | gfp_t gfp) | |
1965c853 JM |
10499 | { |
10500 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 10501 | addr, gfp); |
1965c853 JM |
10502 | } |
10503 | ||
10504 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10505 | struct net_device *netdev, const u8 *addr, |
10506 | gfp_t gfp) | |
1965c853 | 10507 | { |
e6d6e342 JB |
10508 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
10509 | addr, gfp); | |
1965c853 JM |
10510 | } |
10511 | ||
b23aa676 SO |
10512 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
10513 | struct net_device *netdev, const u8 *bssid, | |
10514 | const u8 *req_ie, size_t req_ie_len, | |
10515 | const u8 *resp_ie, size_t resp_ie_len, | |
10516 | u16 status, gfp_t gfp) | |
10517 | { | |
10518 | struct sk_buff *msg; | |
10519 | void *hdr; | |
10520 | ||
58050fce | 10521 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
10522 | if (!msg) |
10523 | return; | |
10524 | ||
10525 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
10526 | if (!hdr) { | |
10527 | nlmsg_free(msg); | |
10528 | return; | |
10529 | } | |
10530 | ||
9360ffd1 DM |
10531 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10532 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10533 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
10534 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
10535 | (req_ie && | |
10536 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
10537 | (resp_ie && | |
10538 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
10539 | goto nla_put_failure; | |
b23aa676 | 10540 | |
3b7b72ee | 10541 | genlmsg_end(msg, hdr); |
b23aa676 | 10542 | |
68eb5503 | 10543 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10544 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
10545 | return; |
10546 | ||
10547 | nla_put_failure: | |
10548 | genlmsg_cancel(msg, hdr); | |
10549 | nlmsg_free(msg); | |
10550 | ||
10551 | } | |
10552 | ||
10553 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
10554 | struct net_device *netdev, const u8 *bssid, | |
10555 | const u8 *req_ie, size_t req_ie_len, | |
10556 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
10557 | { | |
10558 | struct sk_buff *msg; | |
10559 | void *hdr; | |
10560 | ||
58050fce | 10561 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
10562 | if (!msg) |
10563 | return; | |
10564 | ||
10565 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
10566 | if (!hdr) { | |
10567 | nlmsg_free(msg); | |
10568 | return; | |
10569 | } | |
10570 | ||
9360ffd1 DM |
10571 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10572 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10573 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
10574 | (req_ie && | |
10575 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
10576 | (resp_ie && | |
10577 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
10578 | goto nla_put_failure; | |
b23aa676 | 10579 | |
3b7b72ee | 10580 | genlmsg_end(msg, hdr); |
b23aa676 | 10581 | |
68eb5503 | 10582 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10583 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
10584 | return; |
10585 | ||
10586 | nla_put_failure: | |
10587 | genlmsg_cancel(msg, hdr); | |
10588 | nlmsg_free(msg); | |
10589 | ||
10590 | } | |
10591 | ||
10592 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
10593 | struct net_device *netdev, u16 reason, | |
667503dd | 10594 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
10595 | { |
10596 | struct sk_buff *msg; | |
10597 | void *hdr; | |
10598 | ||
58050fce | 10599 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
10600 | if (!msg) |
10601 | return; | |
10602 | ||
10603 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
10604 | if (!hdr) { | |
10605 | nlmsg_free(msg); | |
10606 | return; | |
10607 | } | |
10608 | ||
9360ffd1 DM |
10609 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10610 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10611 | (from_ap && reason && | |
10612 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
10613 | (from_ap && | |
10614 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
10615 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
10616 | goto nla_put_failure; | |
b23aa676 | 10617 | |
3b7b72ee | 10618 | genlmsg_end(msg, hdr); |
b23aa676 | 10619 | |
68eb5503 | 10620 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10621 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
10622 | return; |
10623 | ||
10624 | nla_put_failure: | |
10625 | genlmsg_cancel(msg, hdr); | |
10626 | nlmsg_free(msg); | |
10627 | ||
10628 | } | |
10629 | ||
04a773ad JB |
10630 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
10631 | struct net_device *netdev, const u8 *bssid, | |
10632 | gfp_t gfp) | |
10633 | { | |
10634 | struct sk_buff *msg; | |
10635 | void *hdr; | |
10636 | ||
fd2120ca | 10637 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
10638 | if (!msg) |
10639 | return; | |
10640 | ||
10641 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
10642 | if (!hdr) { | |
10643 | nlmsg_free(msg); | |
10644 | return; | |
10645 | } | |
10646 | ||
9360ffd1 DM |
10647 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10648 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10649 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10650 | goto nla_put_failure; | |
04a773ad | 10651 | |
3b7b72ee | 10652 | genlmsg_end(msg, hdr); |
04a773ad | 10653 | |
68eb5503 | 10654 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10655 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
10656 | return; |
10657 | ||
10658 | nla_put_failure: | |
10659 | genlmsg_cancel(msg, hdr); | |
10660 | nlmsg_free(msg); | |
10661 | } | |
10662 | ||
947add36 JB |
10663 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
10664 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 10665 | { |
947add36 | 10666 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 10667 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
10668 | struct sk_buff *msg; |
10669 | void *hdr; | |
10670 | ||
947add36 JB |
10671 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
10672 | return; | |
10673 | ||
10674 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
10675 | ||
c93b5e71 JC |
10676 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
10677 | if (!msg) | |
10678 | return; | |
10679 | ||
10680 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
10681 | if (!hdr) { | |
10682 | nlmsg_free(msg); | |
10683 | return; | |
10684 | } | |
10685 | ||
9360ffd1 | 10686 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
10687 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
10688 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
10689 | (ie_len && ie && |
10690 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
10691 | goto nla_put_failure; | |
c93b5e71 | 10692 | |
3b7b72ee | 10693 | genlmsg_end(msg, hdr); |
c93b5e71 | 10694 | |
68eb5503 | 10695 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10696 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
10697 | return; |
10698 | ||
10699 | nla_put_failure: | |
10700 | genlmsg_cancel(msg, hdr); | |
10701 | nlmsg_free(msg); | |
10702 | } | |
947add36 | 10703 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 10704 | |
a3b8b056 JM |
10705 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
10706 | struct net_device *netdev, const u8 *addr, | |
10707 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 10708 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
10709 | { |
10710 | struct sk_buff *msg; | |
10711 | void *hdr; | |
10712 | ||
e6d6e342 | 10713 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
10714 | if (!msg) |
10715 | return; | |
10716 | ||
10717 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
10718 | if (!hdr) { | |
10719 | nlmsg_free(msg); | |
10720 | return; | |
10721 | } | |
10722 | ||
9360ffd1 DM |
10723 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10724 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10725 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
10726 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
10727 | (key_id != -1 && | |
10728 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
10729 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
10730 | goto nla_put_failure; | |
a3b8b056 | 10731 | |
3b7b72ee | 10732 | genlmsg_end(msg, hdr); |
a3b8b056 | 10733 | |
68eb5503 | 10734 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10735 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
10736 | return; |
10737 | ||
10738 | nla_put_failure: | |
10739 | genlmsg_cancel(msg, hdr); | |
10740 | nlmsg_free(msg); | |
10741 | } | |
10742 | ||
6bad8766 LR |
10743 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
10744 | struct ieee80211_channel *channel_before, | |
10745 | struct ieee80211_channel *channel_after) | |
10746 | { | |
10747 | struct sk_buff *msg; | |
10748 | void *hdr; | |
10749 | struct nlattr *nl_freq; | |
10750 | ||
fd2120ca | 10751 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
10752 | if (!msg) |
10753 | return; | |
10754 | ||
10755 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
10756 | if (!hdr) { | |
10757 | nlmsg_free(msg); | |
10758 | return; | |
10759 | } | |
10760 | ||
10761 | /* | |
10762 | * Since we are applying the beacon hint to a wiphy we know its | |
10763 | * wiphy_idx is valid | |
10764 | */ | |
9360ffd1 DM |
10765 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
10766 | goto nla_put_failure; | |
6bad8766 LR |
10767 | |
10768 | /* Before */ | |
10769 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
10770 | if (!nl_freq) | |
10771 | goto nla_put_failure; | |
cdc89b97 | 10772 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
10773 | goto nla_put_failure; |
10774 | nla_nest_end(msg, nl_freq); | |
10775 | ||
10776 | /* After */ | |
10777 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
10778 | if (!nl_freq) | |
10779 | goto nla_put_failure; | |
cdc89b97 | 10780 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
10781 | goto nla_put_failure; |
10782 | nla_nest_end(msg, nl_freq); | |
10783 | ||
3b7b72ee | 10784 | genlmsg_end(msg, hdr); |
6bad8766 | 10785 | |
463d0183 | 10786 | rcu_read_lock(); |
68eb5503 | 10787 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 10788 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 10789 | rcu_read_unlock(); |
6bad8766 LR |
10790 | |
10791 | return; | |
10792 | ||
10793 | nla_put_failure: | |
10794 | genlmsg_cancel(msg, hdr); | |
10795 | nlmsg_free(msg); | |
10796 | } | |
10797 | ||
9588bbd5 JM |
10798 | static void nl80211_send_remain_on_chan_event( |
10799 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 10800 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 10801 | struct ieee80211_channel *chan, |
9588bbd5 JM |
10802 | unsigned int duration, gfp_t gfp) |
10803 | { | |
10804 | struct sk_buff *msg; | |
10805 | void *hdr; | |
10806 | ||
10807 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10808 | if (!msg) | |
10809 | return; | |
10810 | ||
10811 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10812 | if (!hdr) { | |
10813 | nlmsg_free(msg); | |
10814 | return; | |
10815 | } | |
10816 | ||
9360ffd1 | 10817 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10818 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10819 | wdev->netdev->ifindex)) || | |
00f53350 | 10820 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 10821 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
10822 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
10823 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
10824 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
10825 | goto nla_put_failure; | |
9588bbd5 | 10826 | |
9360ffd1 DM |
10827 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
10828 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
10829 | goto nla_put_failure; | |
9588bbd5 | 10830 | |
3b7b72ee | 10831 | genlmsg_end(msg, hdr); |
9588bbd5 | 10832 | |
68eb5503 | 10833 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10834 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
10835 | return; |
10836 | ||
10837 | nla_put_failure: | |
10838 | genlmsg_cancel(msg, hdr); | |
10839 | nlmsg_free(msg); | |
10840 | } | |
10841 | ||
947add36 JB |
10842 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
10843 | struct ieee80211_channel *chan, | |
10844 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 10845 | { |
947add36 | 10846 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 10847 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
10848 | |
10849 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 10850 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 10851 | rdev, wdev, cookie, chan, |
42d97a59 | 10852 | duration, gfp); |
9588bbd5 | 10853 | } |
947add36 | 10854 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 10855 | |
947add36 JB |
10856 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
10857 | struct ieee80211_channel *chan, | |
10858 | gfp_t gfp) | |
9588bbd5 | 10859 | { |
947add36 | 10860 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 10861 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
10862 | |
10863 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 10864 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 10865 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 10866 | } |
947add36 | 10867 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 10868 | |
947add36 JB |
10869 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
10870 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 10871 | { |
947add36 | 10872 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 10873 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
10874 | struct sk_buff *msg; |
10875 | ||
947add36 JB |
10876 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
10877 | ||
58050fce | 10878 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
10879 | if (!msg) |
10880 | return; | |
10881 | ||
66266b3a JL |
10882 | if (nl80211_send_station(msg, 0, 0, 0, |
10883 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
10884 | nlmsg_free(msg); |
10885 | return; | |
10886 | } | |
10887 | ||
68eb5503 | 10888 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10889 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 10890 | } |
947add36 | 10891 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 10892 | |
947add36 | 10893 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 10894 | { |
947add36 | 10895 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 10896 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b JM |
10897 | struct sk_buff *msg; |
10898 | void *hdr; | |
10899 | ||
947add36 JB |
10900 | trace_cfg80211_del_sta(dev, mac_addr); |
10901 | ||
58050fce | 10902 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
10903 | if (!msg) |
10904 | return; | |
10905 | ||
10906 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
10907 | if (!hdr) { | |
10908 | nlmsg_free(msg); | |
10909 | return; | |
10910 | } | |
10911 | ||
9360ffd1 DM |
10912 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
10913 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
10914 | goto nla_put_failure; | |
ec15e68b | 10915 | |
3b7b72ee | 10916 | genlmsg_end(msg, hdr); |
ec15e68b | 10917 | |
68eb5503 | 10918 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10919 | NL80211_MCGRP_MLME, gfp); |
ec15e68b JM |
10920 | return; |
10921 | ||
10922 | nla_put_failure: | |
10923 | genlmsg_cancel(msg, hdr); | |
10924 | nlmsg_free(msg); | |
10925 | } | |
947add36 | 10926 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 10927 | |
947add36 JB |
10928 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
10929 | enum nl80211_connect_failed_reason reason, | |
10930 | gfp_t gfp) | |
ed44a951 | 10931 | { |
947add36 | 10932 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 10933 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
10934 | struct sk_buff *msg; |
10935 | void *hdr; | |
10936 | ||
10937 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10938 | if (!msg) | |
10939 | return; | |
10940 | ||
10941 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
10942 | if (!hdr) { | |
10943 | nlmsg_free(msg); | |
10944 | return; | |
10945 | } | |
10946 | ||
10947 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10948 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
10949 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
10950 | goto nla_put_failure; | |
10951 | ||
10952 | genlmsg_end(msg, hdr); | |
10953 | ||
68eb5503 | 10954 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10955 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
10956 | return; |
10957 | ||
10958 | nla_put_failure: | |
10959 | genlmsg_cancel(msg, hdr); | |
10960 | nlmsg_free(msg); | |
10961 | } | |
947add36 | 10962 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 10963 | |
b92ab5d8 JB |
10964 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
10965 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
10966 | { |
10967 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 10968 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
10969 | struct sk_buff *msg; |
10970 | void *hdr; | |
15e47304 | 10971 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 10972 | |
15e47304 | 10973 | if (!nlportid) |
28946da7 JB |
10974 | return false; |
10975 | ||
10976 | msg = nlmsg_new(100, gfp); | |
10977 | if (!msg) | |
10978 | return true; | |
10979 | ||
b92ab5d8 | 10980 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
10981 | if (!hdr) { |
10982 | nlmsg_free(msg); | |
10983 | return true; | |
10984 | } | |
10985 | ||
9360ffd1 DM |
10986 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10987 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10988 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
10989 | goto nla_put_failure; | |
28946da7 | 10990 | |
9c90a9f6 | 10991 | genlmsg_end(msg, hdr); |
15e47304 | 10992 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
10993 | return true; |
10994 | ||
10995 | nla_put_failure: | |
10996 | genlmsg_cancel(msg, hdr); | |
10997 | nlmsg_free(msg); | |
10998 | return true; | |
10999 | } | |
11000 | ||
947add36 JB |
11001 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
11002 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11003 | { |
947add36 JB |
11004 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11005 | bool ret; | |
11006 | ||
11007 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
11008 | ||
11009 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11010 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
11011 | trace_cfg80211_return_bool(false); | |
11012 | return false; | |
11013 | } | |
11014 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
11015 | addr, gfp); | |
11016 | trace_cfg80211_return_bool(ret); | |
11017 | return ret; | |
b92ab5d8 | 11018 | } |
947add36 | 11019 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 11020 | |
947add36 JB |
11021 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
11022 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11023 | { |
947add36 JB |
11024 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11025 | bool ret; | |
11026 | ||
11027 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
11028 | ||
11029 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11030 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
11031 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
11032 | trace_cfg80211_return_bool(false); | |
11033 | return false; | |
11034 | } | |
11035 | ret = __nl80211_unexpected_frame(dev, | |
11036 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
11037 | addr, gfp); | |
11038 | trace_cfg80211_return_bool(ret); | |
11039 | return ret; | |
b92ab5d8 | 11040 | } |
947add36 | 11041 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 11042 | |
2e161f78 | 11043 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 11044 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 11045 | int freq, int sig_dbm, |
19504cf5 | 11046 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 11047 | { |
71bbc994 | 11048 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11049 | struct sk_buff *msg; |
11050 | void *hdr; | |
026331c4 JM |
11051 | |
11052 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11053 | if (!msg) | |
11054 | return -ENOMEM; | |
11055 | ||
2e161f78 | 11056 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
11057 | if (!hdr) { |
11058 | nlmsg_free(msg); | |
11059 | return -ENOMEM; | |
11060 | } | |
11061 | ||
9360ffd1 | 11062 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11063 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11064 | netdev->ifindex)) || | |
a838490b | 11065 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11066 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
11067 | (sig_dbm && | |
11068 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
11069 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11070 | (flags && | |
11071 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 11072 | goto nla_put_failure; |
026331c4 | 11073 | |
3b7b72ee | 11074 | genlmsg_end(msg, hdr); |
026331c4 | 11075 | |
15e47304 | 11076 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
11077 | |
11078 | nla_put_failure: | |
11079 | genlmsg_cancel(msg, hdr); | |
11080 | nlmsg_free(msg); | |
11081 | return -ENOBUFS; | |
11082 | } | |
11083 | ||
947add36 JB |
11084 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
11085 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 11086 | { |
947add36 | 11087 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11088 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 11089 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11090 | struct sk_buff *msg; |
11091 | void *hdr; | |
11092 | ||
947add36 JB |
11093 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
11094 | ||
026331c4 JM |
11095 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11096 | if (!msg) | |
11097 | return; | |
11098 | ||
2e161f78 | 11099 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
11100 | if (!hdr) { |
11101 | nlmsg_free(msg); | |
11102 | return; | |
11103 | } | |
11104 | ||
9360ffd1 | 11105 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11106 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11107 | netdev->ifindex)) || | |
a838490b | 11108 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11109 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11110 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
11111 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
11112 | goto nla_put_failure; | |
026331c4 | 11113 | |
3b7b72ee | 11114 | genlmsg_end(msg, hdr); |
026331c4 | 11115 | |
68eb5503 | 11116 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11117 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
11118 | return; |
11119 | ||
11120 | nla_put_failure: | |
11121 | genlmsg_cancel(msg, hdr); | |
11122 | nlmsg_free(msg); | |
11123 | } | |
947add36 | 11124 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 11125 | |
947add36 JB |
11126 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
11127 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
11128 | gfp_t gfp) | |
d6dc1a38 | 11129 | { |
947add36 JB |
11130 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11131 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11132 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
d6dc1a38 JO |
11133 | struct sk_buff *msg; |
11134 | struct nlattr *pinfoattr; | |
11135 | void *hdr; | |
11136 | ||
947add36 JB |
11137 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
11138 | ||
58050fce | 11139 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
11140 | if (!msg) |
11141 | return; | |
11142 | ||
11143 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11144 | if (!hdr) { | |
11145 | nlmsg_free(msg); | |
11146 | return; | |
11147 | } | |
11148 | ||
9360ffd1 | 11149 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 11150 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 11151 | goto nla_put_failure; |
d6dc1a38 JO |
11152 | |
11153 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11154 | if (!pinfoattr) | |
11155 | goto nla_put_failure; | |
11156 | ||
9360ffd1 DM |
11157 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
11158 | rssi_event)) | |
11159 | goto nla_put_failure; | |
d6dc1a38 JO |
11160 | |
11161 | nla_nest_end(msg, pinfoattr); | |
11162 | ||
3b7b72ee | 11163 | genlmsg_end(msg, hdr); |
d6dc1a38 | 11164 | |
68eb5503 | 11165 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11166 | NL80211_MCGRP_MLME, gfp); |
d6dc1a38 JO |
11167 | return; |
11168 | ||
11169 | nla_put_failure: | |
11170 | genlmsg_cancel(msg, hdr); | |
11171 | nlmsg_free(msg); | |
11172 | } | |
947add36 | 11173 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 11174 | |
947add36 JB |
11175 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
11176 | struct net_device *netdev, const u8 *bssid, | |
11177 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
11178 | { |
11179 | struct sk_buff *msg; | |
11180 | struct nlattr *rekey_attr; | |
11181 | void *hdr; | |
11182 | ||
58050fce | 11183 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
11184 | if (!msg) |
11185 | return; | |
11186 | ||
11187 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
11188 | if (!hdr) { | |
11189 | nlmsg_free(msg); | |
11190 | return; | |
11191 | } | |
11192 | ||
9360ffd1 DM |
11193 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11194 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11195 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
11196 | goto nla_put_failure; | |
e5497d76 JB |
11197 | |
11198 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
11199 | if (!rekey_attr) | |
11200 | goto nla_put_failure; | |
11201 | ||
9360ffd1 DM |
11202 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
11203 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
11204 | goto nla_put_failure; | |
e5497d76 JB |
11205 | |
11206 | nla_nest_end(msg, rekey_attr); | |
11207 | ||
3b7b72ee | 11208 | genlmsg_end(msg, hdr); |
e5497d76 | 11209 | |
68eb5503 | 11210 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11211 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
11212 | return; |
11213 | ||
11214 | nla_put_failure: | |
11215 | genlmsg_cancel(msg, hdr); | |
11216 | nlmsg_free(msg); | |
11217 | } | |
11218 | ||
947add36 JB |
11219 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
11220 | const u8 *replay_ctr, gfp_t gfp) | |
11221 | { | |
11222 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11223 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11224 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11225 | |
11226 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
11227 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
11228 | } | |
11229 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
11230 | ||
11231 | static void | |
11232 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
11233 | struct net_device *netdev, int index, | |
11234 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
11235 | { |
11236 | struct sk_buff *msg; | |
11237 | struct nlattr *attr; | |
11238 | void *hdr; | |
11239 | ||
58050fce | 11240 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
11241 | if (!msg) |
11242 | return; | |
11243 | ||
11244 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
11245 | if (!hdr) { | |
11246 | nlmsg_free(msg); | |
11247 | return; | |
11248 | } | |
11249 | ||
9360ffd1 DM |
11250 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11251 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
11252 | goto nla_put_failure; | |
c9df56b4 JM |
11253 | |
11254 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
11255 | if (!attr) | |
11256 | goto nla_put_failure; | |
11257 | ||
9360ffd1 DM |
11258 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
11259 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
11260 | (preauth && | |
11261 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
11262 | goto nla_put_failure; | |
c9df56b4 JM |
11263 | |
11264 | nla_nest_end(msg, attr); | |
11265 | ||
3b7b72ee | 11266 | genlmsg_end(msg, hdr); |
c9df56b4 | 11267 | |
68eb5503 | 11268 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11269 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
11270 | return; |
11271 | ||
11272 | nla_put_failure: | |
11273 | genlmsg_cancel(msg, hdr); | |
11274 | nlmsg_free(msg); | |
11275 | } | |
11276 | ||
947add36 JB |
11277 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
11278 | const u8 *bssid, bool preauth, gfp_t gfp) | |
11279 | { | |
11280 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11281 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11282 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11283 | |
11284 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
11285 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
11286 | } | |
11287 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
11288 | ||
11289 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
11290 | struct net_device *netdev, | |
11291 | struct cfg80211_chan_def *chandef, | |
11292 | gfp_t gfp) | |
5314526b TP |
11293 | { |
11294 | struct sk_buff *msg; | |
11295 | void *hdr; | |
11296 | ||
58050fce | 11297 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
11298 | if (!msg) |
11299 | return; | |
11300 | ||
11301 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
11302 | if (!hdr) { | |
11303 | nlmsg_free(msg); | |
11304 | return; | |
11305 | } | |
11306 | ||
683b6d3b JB |
11307 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
11308 | goto nla_put_failure; | |
11309 | ||
11310 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 11311 | goto nla_put_failure; |
5314526b TP |
11312 | |
11313 | genlmsg_end(msg, hdr); | |
11314 | ||
68eb5503 | 11315 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11316 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
11317 | return; |
11318 | ||
11319 | nla_put_failure: | |
11320 | genlmsg_cancel(msg, hdr); | |
11321 | nlmsg_free(msg); | |
11322 | } | |
11323 | ||
947add36 JB |
11324 | void cfg80211_ch_switch_notify(struct net_device *dev, |
11325 | struct cfg80211_chan_def *chandef) | |
84f10708 | 11326 | { |
947add36 JB |
11327 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11328 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11329 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 11330 | |
e487eaeb | 11331 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 11332 | |
e487eaeb | 11333 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 JB |
11334 | |
11335 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
ee4bc9e7 | 11336 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
b8456a14 CYY |
11337 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
11338 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) | |
e487eaeb | 11339 | return; |
947add36 | 11340 | |
9e0e2961 | 11341 | wdev->chandef = *chandef; |
96f55f12 | 11342 | wdev->preset_chandef = *chandef; |
947add36 | 11343 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
947add36 JB |
11344 | } |
11345 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
11346 | ||
11347 | void cfg80211_cqm_txe_notify(struct net_device *dev, | |
11348 | const u8 *peer, u32 num_packets, | |
11349 | u32 rate, u32 intvl, gfp_t gfp) | |
11350 | { | |
11351 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11352 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11353 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
84f10708 TP |
11354 | struct sk_buff *msg; |
11355 | struct nlattr *pinfoattr; | |
11356 | void *hdr; | |
11357 | ||
11358 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
11359 | if (!msg) | |
11360 | return; | |
11361 | ||
11362 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11363 | if (!hdr) { | |
11364 | nlmsg_free(msg); | |
11365 | return; | |
11366 | } | |
11367 | ||
11368 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
947add36 | 11369 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
84f10708 TP |
11370 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
11371 | goto nla_put_failure; | |
11372 | ||
11373 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11374 | if (!pinfoattr) | |
11375 | goto nla_put_failure; | |
11376 | ||
11377 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
11378 | goto nla_put_failure; | |
11379 | ||
11380 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
11381 | goto nla_put_failure; | |
11382 | ||
11383 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
11384 | goto nla_put_failure; | |
11385 | ||
11386 | nla_nest_end(msg, pinfoattr); | |
11387 | ||
11388 | genlmsg_end(msg, hdr); | |
11389 | ||
68eb5503 | 11390 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11391 | NL80211_MCGRP_MLME, gfp); |
84f10708 TP |
11392 | return; |
11393 | ||
11394 | nla_put_failure: | |
11395 | genlmsg_cancel(msg, hdr); | |
11396 | nlmsg_free(msg); | |
11397 | } | |
947add36 | 11398 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
84f10708 | 11399 | |
04f39047 SW |
11400 | void |
11401 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 11402 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
11403 | enum nl80211_radar_event event, |
11404 | struct net_device *netdev, gfp_t gfp) | |
11405 | { | |
11406 | struct sk_buff *msg; | |
11407 | void *hdr; | |
11408 | ||
11409 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11410 | if (!msg) | |
11411 | return; | |
11412 | ||
11413 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
11414 | if (!hdr) { | |
11415 | nlmsg_free(msg); | |
11416 | return; | |
11417 | } | |
11418 | ||
11419 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
11420 | goto nla_put_failure; | |
11421 | ||
11422 | /* NOP and radar events don't need a netdev parameter */ | |
11423 | if (netdev) { | |
11424 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
11425 | ||
11426 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11427 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11428 | goto nla_put_failure; | |
11429 | } | |
11430 | ||
11431 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
11432 | goto nla_put_failure; | |
11433 | ||
11434 | if (nl80211_send_chandef(msg, chandef)) | |
11435 | goto nla_put_failure; | |
11436 | ||
9c90a9f6 | 11437 | genlmsg_end(msg, hdr); |
04f39047 | 11438 | |
68eb5503 | 11439 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11440 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
11441 | return; |
11442 | ||
11443 | nla_put_failure: | |
11444 | genlmsg_cancel(msg, hdr); | |
11445 | nlmsg_free(msg); | |
11446 | } | |
11447 | ||
947add36 JB |
11448 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
11449 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
c063dbf5 | 11450 | { |
947add36 JB |
11451 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11452 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11453 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
c063dbf5 JB |
11454 | struct sk_buff *msg; |
11455 | struct nlattr *pinfoattr; | |
11456 | void *hdr; | |
11457 | ||
947add36 JB |
11458 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
11459 | ||
58050fce | 11460 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
11461 | if (!msg) |
11462 | return; | |
11463 | ||
11464 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11465 | if (!hdr) { | |
11466 | nlmsg_free(msg); | |
11467 | return; | |
11468 | } | |
11469 | ||
9360ffd1 | 11470 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 11471 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9360ffd1 DM |
11472 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
11473 | goto nla_put_failure; | |
c063dbf5 JB |
11474 | |
11475 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11476 | if (!pinfoattr) | |
11477 | goto nla_put_failure; | |
11478 | ||
9360ffd1 DM |
11479 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
11480 | goto nla_put_failure; | |
c063dbf5 JB |
11481 | |
11482 | nla_nest_end(msg, pinfoattr); | |
11483 | ||
3b7b72ee | 11484 | genlmsg_end(msg, hdr); |
c063dbf5 | 11485 | |
68eb5503 | 11486 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11487 | NL80211_MCGRP_MLME, gfp); |
c063dbf5 JB |
11488 | return; |
11489 | ||
11490 | nla_put_failure: | |
11491 | genlmsg_cancel(msg, hdr); | |
11492 | nlmsg_free(msg); | |
11493 | } | |
947add36 | 11494 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
c063dbf5 | 11495 | |
7f6cf311 JB |
11496 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
11497 | u64 cookie, bool acked, gfp_t gfp) | |
11498 | { | |
11499 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 11500 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
11501 | struct sk_buff *msg; |
11502 | void *hdr; | |
7f6cf311 | 11503 | |
4ee3e063 BL |
11504 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
11505 | ||
58050fce | 11506 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 11507 | |
7f6cf311 JB |
11508 | if (!msg) |
11509 | return; | |
11510 | ||
11511 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
11512 | if (!hdr) { | |
11513 | nlmsg_free(msg); | |
11514 | return; | |
11515 | } | |
11516 | ||
9360ffd1 DM |
11517 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11518 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11519 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
11520 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
11521 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
11522 | goto nla_put_failure; | |
7f6cf311 | 11523 | |
9c90a9f6 | 11524 | genlmsg_end(msg, hdr); |
7f6cf311 | 11525 | |
68eb5503 | 11526 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11527 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
11528 | return; |
11529 | ||
11530 | nla_put_failure: | |
11531 | genlmsg_cancel(msg, hdr); | |
11532 | nlmsg_free(msg); | |
11533 | } | |
11534 | EXPORT_SYMBOL(cfg80211_probe_status); | |
11535 | ||
5e760230 JB |
11536 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
11537 | const u8 *frame, size_t len, | |
37c73b5f | 11538 | int freq, int sig_dbm) |
5e760230 | 11539 | { |
f26cbf40 | 11540 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
11541 | struct sk_buff *msg; |
11542 | void *hdr; | |
37c73b5f | 11543 | struct cfg80211_beacon_registration *reg; |
5e760230 | 11544 | |
4ee3e063 BL |
11545 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
11546 | ||
37c73b5f BG |
11547 | spin_lock_bh(&rdev->beacon_registrations_lock); |
11548 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
11549 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
11550 | if (!msg) { | |
11551 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
11552 | return; | |
11553 | } | |
5e760230 | 11554 | |
37c73b5f BG |
11555 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
11556 | if (!hdr) | |
11557 | goto nla_put_failure; | |
5e760230 | 11558 | |
37c73b5f BG |
11559 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11560 | (freq && | |
11561 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
11562 | (sig_dbm && | |
11563 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
11564 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
11565 | goto nla_put_failure; | |
5e760230 | 11566 | |
37c73b5f | 11567 | genlmsg_end(msg, hdr); |
5e760230 | 11568 | |
37c73b5f BG |
11569 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
11570 | } | |
11571 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
11572 | return; |
11573 | ||
11574 | nla_put_failure: | |
37c73b5f BG |
11575 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
11576 | if (hdr) | |
11577 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
11578 | nlmsg_free(msg); |
11579 | } | |
11580 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
11581 | ||
cd8f7cb4 JB |
11582 | #ifdef CONFIG_PM |
11583 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | |
11584 | struct cfg80211_wowlan_wakeup *wakeup, | |
11585 | gfp_t gfp) | |
11586 | { | |
f26cbf40 | 11587 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
11588 | struct sk_buff *msg; |
11589 | void *hdr; | |
9c90a9f6 | 11590 | int size = 200; |
cd8f7cb4 JB |
11591 | |
11592 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
11593 | ||
11594 | if (wakeup) | |
11595 | size += wakeup->packet_present_len; | |
11596 | ||
11597 | msg = nlmsg_new(size, gfp); | |
11598 | if (!msg) | |
11599 | return; | |
11600 | ||
11601 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
11602 | if (!hdr) | |
11603 | goto free_msg; | |
11604 | ||
11605 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11606 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11607 | goto free_msg; | |
11608 | ||
11609 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
11610 | wdev->netdev->ifindex)) | |
11611 | goto free_msg; | |
11612 | ||
11613 | if (wakeup) { | |
11614 | struct nlattr *reasons; | |
11615 | ||
11616 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
11617 | if (!reasons) |
11618 | goto free_msg; | |
cd8f7cb4 JB |
11619 | |
11620 | if (wakeup->disconnect && | |
11621 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
11622 | goto free_msg; | |
11623 | if (wakeup->magic_pkt && | |
11624 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
11625 | goto free_msg; | |
11626 | if (wakeup->gtk_rekey_failure && | |
11627 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
11628 | goto free_msg; | |
11629 | if (wakeup->eap_identity_req && | |
11630 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
11631 | goto free_msg; | |
11632 | if (wakeup->four_way_handshake && | |
11633 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
11634 | goto free_msg; | |
11635 | if (wakeup->rfkill_release && | |
11636 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
11637 | goto free_msg; | |
11638 | ||
11639 | if (wakeup->pattern_idx >= 0 && | |
11640 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
11641 | wakeup->pattern_idx)) | |
11642 | goto free_msg; | |
11643 | ||
ae917c9f JB |
11644 | if (wakeup->tcp_match && |
11645 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
11646 | goto free_msg; | |
2a0e047e | 11647 | |
ae917c9f JB |
11648 | if (wakeup->tcp_connlost && |
11649 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
11650 | goto free_msg; | |
2a0e047e | 11651 | |
ae917c9f JB |
11652 | if (wakeup->tcp_nomoretokens && |
11653 | nla_put_flag(msg, | |
11654 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
11655 | goto free_msg; | |
2a0e047e | 11656 | |
cd8f7cb4 JB |
11657 | if (wakeup->packet) { |
11658 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
11659 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
11660 | ||
11661 | if (!wakeup->packet_80211) { | |
11662 | pkt_attr = | |
11663 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
11664 | len_attr = | |
11665 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
11666 | } | |
11667 | ||
11668 | if (wakeup->packet_len && | |
11669 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
11670 | goto free_msg; | |
11671 | ||
11672 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
11673 | wakeup->packet)) | |
11674 | goto free_msg; | |
11675 | } | |
11676 | ||
11677 | nla_nest_end(msg, reasons); | |
11678 | } | |
11679 | ||
9c90a9f6 | 11680 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 11681 | |
68eb5503 | 11682 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11683 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
11684 | return; |
11685 | ||
11686 | free_msg: | |
11687 | nlmsg_free(msg); | |
11688 | } | |
11689 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
11690 | #endif | |
11691 | ||
3475b094 JM |
11692 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
11693 | enum nl80211_tdls_operation oper, | |
11694 | u16 reason_code, gfp_t gfp) | |
11695 | { | |
11696 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 11697 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
11698 | struct sk_buff *msg; |
11699 | void *hdr; | |
3475b094 JM |
11700 | |
11701 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
11702 | reason_code); | |
11703 | ||
11704 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11705 | if (!msg) | |
11706 | return; | |
11707 | ||
11708 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
11709 | if (!hdr) { | |
11710 | nlmsg_free(msg); | |
11711 | return; | |
11712 | } | |
11713 | ||
11714 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11715 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11716 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
11717 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
11718 | (reason_code > 0 && | |
11719 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
11720 | goto nla_put_failure; | |
11721 | ||
9c90a9f6 | 11722 | genlmsg_end(msg, hdr); |
3475b094 | 11723 | |
68eb5503 | 11724 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11725 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
11726 | return; |
11727 | ||
11728 | nla_put_failure: | |
11729 | genlmsg_cancel(msg, hdr); | |
11730 | nlmsg_free(msg); | |
11731 | } | |
11732 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
11733 | ||
026331c4 JM |
11734 | static int nl80211_netlink_notify(struct notifier_block * nb, |
11735 | unsigned long state, | |
11736 | void *_notify) | |
11737 | { | |
11738 | struct netlink_notify *notify = _notify; | |
11739 | struct cfg80211_registered_device *rdev; | |
11740 | struct wireless_dev *wdev; | |
37c73b5f | 11741 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
11742 | |
11743 | if (state != NETLINK_URELEASE) | |
11744 | return NOTIFY_DONE; | |
11745 | ||
11746 | rcu_read_lock(); | |
11747 | ||
5e760230 | 11748 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
78f22b6a JB |
11749 | bool schedule_destroy_work = false; |
11750 | ||
11751 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { | |
15e47304 | 11752 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 11753 | |
78f22b6a JB |
11754 | if (wdev->owner_nlportid == notify->portid) |
11755 | schedule_destroy_work = true; | |
11756 | } | |
11757 | ||
37c73b5f BG |
11758 | spin_lock_bh(&rdev->beacon_registrations_lock); |
11759 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
11760 | list) { | |
11761 | if (reg->nlportid == notify->portid) { | |
11762 | list_del(®->list); | |
11763 | kfree(reg); | |
11764 | break; | |
11765 | } | |
11766 | } | |
11767 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
78f22b6a JB |
11768 | |
11769 | if (schedule_destroy_work) { | |
11770 | struct cfg80211_iface_destroy *destroy; | |
11771 | ||
11772 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | |
11773 | if (destroy) { | |
11774 | destroy->nlportid = notify->portid; | |
11775 | spin_lock(&rdev->destroy_list_lock); | |
11776 | list_add(&destroy->list, &rdev->destroy_list); | |
11777 | spin_unlock(&rdev->destroy_list_lock); | |
11778 | schedule_work(&rdev->destroy_work); | |
11779 | } | |
11780 | } | |
5e760230 | 11781 | } |
026331c4 JM |
11782 | |
11783 | rcu_read_unlock(); | |
11784 | ||
6784c7db | 11785 | return NOTIFY_OK; |
026331c4 JM |
11786 | } |
11787 | ||
11788 | static struct notifier_block nl80211_netlink_notifier = { | |
11789 | .notifier_call = nl80211_netlink_notify, | |
11790 | }; | |
11791 | ||
355199e0 JM |
11792 | void cfg80211_ft_event(struct net_device *netdev, |
11793 | struct cfg80211_ft_event_params *ft_event) | |
11794 | { | |
11795 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 11796 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
11797 | struct sk_buff *msg; |
11798 | void *hdr; | |
355199e0 JM |
11799 | |
11800 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
11801 | ||
11802 | if (!ft_event->target_ap) | |
11803 | return; | |
11804 | ||
11805 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11806 | if (!msg) | |
11807 | return; | |
11808 | ||
11809 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
11810 | if (!hdr) |
11811 | goto out; | |
355199e0 | 11812 | |
ae917c9f JB |
11813 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11814 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11815 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
11816 | goto out; | |
355199e0 | 11817 | |
ae917c9f JB |
11818 | if (ft_event->ies && |
11819 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
11820 | goto out; | |
11821 | if (ft_event->ric_ies && | |
11822 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
11823 | ft_event->ric_ies)) | |
11824 | goto out; | |
355199e0 | 11825 | |
9c90a9f6 | 11826 | genlmsg_end(msg, hdr); |
355199e0 | 11827 | |
68eb5503 | 11828 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11829 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
11830 | return; |
11831 | out: | |
11832 | nlmsg_free(msg); | |
355199e0 JM |
11833 | } |
11834 | EXPORT_SYMBOL(cfg80211_ft_event); | |
11835 | ||
5de17984 AS |
11836 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
11837 | { | |
11838 | struct cfg80211_registered_device *rdev; | |
11839 | struct sk_buff *msg; | |
11840 | void *hdr; | |
11841 | u32 nlportid; | |
11842 | ||
f26cbf40 | 11843 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
11844 | if (!rdev->crit_proto_nlportid) |
11845 | return; | |
11846 | ||
11847 | nlportid = rdev->crit_proto_nlportid; | |
11848 | rdev->crit_proto_nlportid = 0; | |
11849 | ||
11850 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11851 | if (!msg) | |
11852 | return; | |
11853 | ||
11854 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
11855 | if (!hdr) | |
11856 | goto nla_put_failure; | |
11857 | ||
11858 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11859 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11860 | goto nla_put_failure; | |
11861 | ||
11862 | genlmsg_end(msg, hdr); | |
11863 | ||
11864 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
11865 | return; | |
11866 | ||
11867 | nla_put_failure: | |
11868 | if (hdr) | |
11869 | genlmsg_cancel(msg, hdr); | |
11870 | nlmsg_free(msg); | |
11871 | ||
11872 | } | |
11873 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
11874 | ||
348baf0e JB |
11875 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
11876 | { | |
11877 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11878 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
11879 | struct sk_buff *msg; |
11880 | void *hdr; | |
11881 | ||
11882 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11883 | if (!msg) | |
11884 | return; | |
11885 | ||
11886 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
11887 | if (!hdr) | |
11888 | goto out; | |
11889 | ||
11890 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11891 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
11892 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11893 | goto out; | |
11894 | ||
11895 | genlmsg_end(msg, hdr); | |
11896 | ||
11897 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
11898 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
11899 | return; | |
11900 | out: | |
11901 | nlmsg_free(msg); | |
11902 | } | |
11903 | ||
55682965 JB |
11904 | /* initialisation/exit functions */ |
11905 | ||
11906 | int nl80211_init(void) | |
11907 | { | |
0d63cbb5 | 11908 | int err; |
55682965 | 11909 | |
2a94fe48 JB |
11910 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
11911 | nl80211_mcgrps); | |
55682965 JB |
11912 | if (err) |
11913 | return err; | |
11914 | ||
026331c4 JM |
11915 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
11916 | if (err) | |
11917 | goto err_out; | |
11918 | ||
55682965 JB |
11919 | return 0; |
11920 | err_out: | |
11921 | genl_unregister_family(&nl80211_fam); | |
11922 | return err; | |
11923 | } | |
11924 | ||
11925 | void nl80211_exit(void) | |
11926 | { | |
026331c4 | 11927 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
11928 | genl_unregister_family(&nl80211_fam); |
11929 | } |